|
//申明
CDC m_dcBack;
CBitmap m_bmpBack;
//初始化
CClientDC dc(this);
// CBrush brushBack;
CRect rect;
GetClientRect(rect);
//创建画线设备环境以及创建相应缓冲区
if (m_dcBack.GetSafeHdc() == NULL)
{
m_dcBack.CreateCompatibleDC(&dc) ;
m_bmpBack.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height()) ;
m_dcBack.SelectObject(&m_bmpBack) ;
}
m_dcBack.SetBkColor (CL_MAIN_BACK);
m_dcBack.SetTextColor(CL_MAIN_TEXT);
//Onpaint
void *****::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rectClient;
GetClientRect(rectClient);
CDC memDC ;
CBitmap memBitmap ;
CBitmap* oldBitmap ;
memDC.CreateCompatibleDC(&dc) ;
memBitmap.CreateCompatibleBitmap(&dc, rectClient.Width(), rectClient.Height()) ;
oldBitmap = (CBitmap *)memDC.SelectObject(&memBitmap) ;
//将m_dcCoor和m_dcLine绘制到控件上
if (memDC.GetSafeHdc() != NULL)
{
memDC.BitBlt(0, 0, rectClient.Width(), rectClient.Height(),
&m_dcBack, 0, 0, SRCCOPY) ;
dc.BitBlt(0, 0, rectClient.Width(), rectClient.Height(),
&memDC, 0, 0, SRCCOPY) ;
}
memDC.SelectObject(oldBitmap) ;
//删除内存位图GDI对象
memBitmap.DeleteObject();
//删除内存绘图环境
memDC.DeleteDC();
// Do not call CWnd::OnPaint() for painting messages
}
//调用时,直接调用
Invalidate(FALSE); //最好还是用InvalidateRect的方式 |
|