19,469
社区成员
发帖
与我相关
我的任务
分享
void CXXDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
if (IsIconic())
{
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CBitmap bmp;
CRect rc;
GetClientRect(rc);
bmp.CreateCompatibleBitmap(&dc,rc.Width(),rc.Height());
CDC memDC;
memDC.CreateCompatibleDC(&dc);
memDC.SelectObject(&bmp);
CPoint pt(rc.CenterPoint());
const int WIDTH = 300;
const int HEIGHT = 300;
const int WIDTH2 = 100;
const int HEIGHT2 = 100;
int x1 = pt.x - WIDTH / 2;
int y1 = pt.y - HEIGHT / 2;
int x2 = pt.x + WIDTH / 2;
int y2 = pt.y + HEIGHT / 2;
CPen pen;
pen.CreatePen(PS_SOLID,2,RGB(0,0,255));
CPen *oldpen=(CPen *)memDC.SelectObject(&pen);
CBrush brush;
brush.CreateSolidBrush(RGB(255,0,0));
CBrush *oldbrush=(CBrush *)memDC.SelectObject(&brush);
memDC.FillSolidRect(0, 0, rc.Width(), rc.Height(), GetSysColor(COLOR_3DFACE));
memDC.Ellipse(x1,y1,x2,y2);
int x3 = pt.x - WIDTH2 / 2;
int y3 = pt.y - HEIGHT2 / 2;
int x4 = pt.x + WIDTH2 / 2;
int y4 = pt.y + HEIGHT2 / 2;
pen.DeleteObject();
pen.CreatePen(PS_SOLID, 2, RGB(255, 255, 128));
oldpen = (CPen*)memDC.SelectObject(&pen);
brush.DeleteObject();
brush.CreateSolidBrush(RGB(0, 255, 0));
oldbrush=(CBrush *)memDC.SelectObject(&brush);
memDC.Ellipse(x3, y3, x4, y4);
dc.BitBlt(0,0,rc.Width(),rc.Height(),&memDC,0,0,SRCCOPY);
memDC.SelectObject(oldpen);
memDC.SelectObject(oldbrush);
bmp.DeleteObject();
memDC.DeleteDC();
//CDialog::OnPaint();
}
}