www.pudn.com > DrawTrend.zip > CyPaintBox.cpp
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "CyPaintBox.h"
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
//---------------------------------------------------------------------------
TCyPaintBox::TCyPaintBox()
{
m_hDC = NULL;
m_pstFont = NULL;
m_hPen = NULL;
m_hBrush = NULL;
m_pstFont = new CFont;
// m_pstFont->Name = "system";
// m_pstFont->Color = clYellow;
// m_pstFont->Size = 8;
// SetTextFont(m_pstFont);
}
//---------------------------------------------------------------------------
TCyPaintBox::~TCyPaintBox()
{
if(m_pstFont)
{
delete m_pstFont;
m_pstFont = NULL;
}
}
//---------------------------------------------------------------------------
COLORREF TCyPaintBox::GetXBackColor()
{
return XBackColor;
}
//---------------------------------------------------------------------------
void TCyPaintBox::SetXBackColor(COLORREF color)
{
CPoint start(m_iLeft, m_iTop), end(m_iLeft + m_iWidth, m_iTop + m_iHeight);
XBackColor = color;
SetBkColor(m_hDC, color);
Rect(start, end, true, XBackColor);
}
//---------------------------------------------------------------------------
void TCyPaintBox::Line(CPoint start, CPoint end, COLORREF color)
{
m_hPen = CreatePen(PS_SOLID, 0, color);
SelectObject(m_hDC, m_hPen);
MoveToEx(m_hDC, start.x, start.y, NULL);
::LineTo(m_hDC, end.x, end.y);
SelectObject(m_hDC, GetStockObject(NULL_PEN));
DeleteObject(m_hPen);
m_hPen = NULL;
}
//---------------------------------------------------------------------------
void TCyPaintBox::LineTo(CPoint end, COLORREF color)
{
m_hPen = CreatePen(PS_SOLID, 0, color);
SelectObject(m_hDC, m_hPen);
::LineTo(m_hDC, end.x, end.y);
SelectObject(m_hDC, GetStockObject(NULL_PEN));
DeleteObject(m_hPen);
m_hPen = NULL;
//ReleaseDCPen(m_hPen);
}
//---------------------------------------------------------------------------
void TCyPaintBox::Rect(RECT rect, bool filled, COLORREF color)
{
int temp;
CPoint start, end;
if(rect.left > rect.right)
{
temp = rect.left;
rect.left = rect.right;
rect.right = temp;
}
if(rect.top > rect.bottom)
{
temp = rect.top;
rect.top = rect.bottom;
rect.bottom = temp;
}
if(filled)
{
//SelectObject(m_hDC, GetStockObject(DC_BRUSH));
/*
SetDCBrushColor(m_hDC, color);
*/
m_hBrush = CreateSolidBrush(color);
SelectObject(m_hDC, m_hBrush);
FillRect(m_hDC, &rect, m_hBrush);
SelectObject(m_hDC, GetStockObject(BLACK_BRUSH));
DeleteObject(m_hBrush);
m_hBrush = NULL;
//ReleaseDCBrush(m_hBrush);
}
else
{
//SelectObject(m_hDC, GetStockObject(DC_PEN));
/*
SetDCPenColor(m_hDC, color);
*/
m_hPen = CreatePen(PS_SOLID, 0, color);
SelectObject(m_hDC, m_hPen);
::MoveToEx(m_hDC, rect.left, rect.top, NULL);
::LineTo(m_hDC, rect.right, rect.top);
::LineTo(m_hDC, rect.right, rect.bottom);
::LineTo(m_hDC, rect.left, rect.bottom);
::LineTo(m_hDC, rect.left, rect.top);
SelectObject(m_hDC, GetStockObject(NULL_PEN));
DeleteObject(m_hPen);
m_hPen = NULL;
//ReleaseDCPen(m_hPen);
//Rectangle(m_hDC, rect.left, rect.top, rect.right, rect.bottom);
}
}
//---------------------------------------------------------------------------
void TCyPaintBox::Rect(CPoint start, CPoint end, bool filled, COLORREF color)
{
RECT rect;
rect.top = start.y;
rect.left = start.x;
rect.bottom = end.y;
rect.right = end.x;
Rect(rect, filled, color);
}
//---------------------------------------------------------------------------
void TCyPaintBox::Rect(int left, int top, int width, int height, bool filled, COLORREF color)
{
CPoint start(left, top), end(left + width, top + height);
Rect(start, end, filled, color);
}
//---------------------------------------------------------------------------
void TCyPaintBox::SetTextFont(CFont * font)
{
/*
HFONT hf;
m_pstFont = font;
hf = CreateFont(font->Height, font->Size, GM_COMPATIBLE, 0,
false, false, false, false, font->Charset,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
0, font->Name.c_str());
SelectObject(m_hDC, hf);
DeleteObject(hf);
*/
}
//---------------------------------------------------------------------------
void TCyPaintBox::TextOut(int x, int y, char * str, COLORREF color)
{
COLORREF old_color = ::GetTextColor(m_hDC);
::SetTextColor(m_hDC, color);
::TextOut(m_hDC, x, y, str, strlen(str));
::SetTextColor(m_hDC, old_color);
//DeleteObject(old_color);
}
//---------------------------------------------------------------------------
void TCyPaintBox::TextOut(int x, int y, char * str, COLORREF color, char * szFontName, int iFontSize)
{
// char szOldFontName[255];
COLORREF old_color = ::GetTextColor(m_hDC);
// int iOldFontSize = m_pstFont->Size ;
// strcpy(szOldFontName, m_pstFont->Name.c_str());
// m_pstFont->Size = iFontSize;
// m_pstFont->Name = szFontName;
// SetTextFont(m_pstFont);
::SetTextColor(m_hDC, color);
::TextOut(m_hDC, x, y, str, strlen(str));
::SetTextColor(m_hDC, old_color);
// m_pstFont->Size = iOldFontSize;
// m_pstFont->Name = szOldFontName;
// SetTextFont(m_pstFont);
//DeleteObject(old_color);
}
//---------------------------------------------------------------------------
void TCyPaintBox::TextOut(CPoint start, char * str, COLORREF color)
{
COLORREF old_color = ::GetTextColor(m_hDC);
::SetTextColor(m_hDC, color);
::TextOut(m_hDC, start.x, start.y, str, strlen(str));
::SetTextColor(m_hDC, old_color);
//DeleteObject(old_color);
}
//---------------------------------------------------------------------------