使用如下函数包含所需绘图的所有函数
void CXXXXXDlg::PaintAll()
{
CDC *dcPicBox;
dcPicBox = m_picBox1.GetDC();//获取绘图区域的DC,m_picBox1视自己所用的绘图区变量改变
m_picBox1.UpdateWindow();//刷新绘图区域
m_picBox1.GetClientRect(&rectPicBox);//获取绘图区域的rect存入rectPicBox
CDC memDC;
memDC.CreateCompatibleDC(NULL);
CBitmap cMemBitmap;
CBitmap *pOldBitmap;
cMemBitmap.CreateCompatibleBitmap(dcPicBox, rectPicBox.Width(), rectPicBox.Height());
pOldBitmap = memDC.SelectObject(&cMemBitmap);
/*---------绘图函数区,如----------------*/
PaintBackGround(&memDC, rectPicBox);
PaintWave(&memDC, rectPicBox);
/*-------------------------------------*/
dcPicBox->BitBlt(rectPicBox.left, rectPicBox.top, rectPicBox.Width(), rectPicBox.Height(), &memDC, 0, 0, SRCCOPY);
cMemBitmap.DeleteObject();
memDC.DeleteDC();
ReleaseDC(dcPicBox);
}
附一个绘图函数的例子
void CXXXXXDlg::PaintBackGround(CDC *dcPicBox,CRect rectPicBox)
{
LOGBRUSH logBrush;
logBrush.lbColor = RGB(0,0,0);
logBrush.lbStyle = HS_CROSS;
brushPicBox.CreateBrushIndirect(&logBrush);
dcPicBox->FillRect(&rectPicBox, &brushPicBox);//用获取到的DC将获取到的区域用brushPicBox填充
CPen newPen, *pOldPen;
newPen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
pOldPen = dcPicBox->SelectObject(&newPen);
dcPicBox->MoveTo(rectPicBox.left, rectPicBox.top);
dcPicBox->LineTo(rectPicBox.right, rectPicBox.bottom);
dcPicBox->SelectObject(pOldPen);
newPen.DeleteObject();
}
原理可参考http://mingsuper.blog.51cto.com/8269088/1384425 双缓冲技术的介绍