创建临时画布
CDC* pDC = GetDC(); CDC memdc; memdc.CreateCompatibleDC(pDC);
向临时画布添加一个位图资源
CBitmap bitmap; bitmap.LoadBitmap(IDB_BITMAP_BK); memdc.SelectObject(&bitmap);
获取客户区域
CRect rect; GetClientRect(&rect);
使用DC绘制在临时画布绘制
//选择画笔 CPen pen(PS_SOLID,2,RGB(0,0,0)); memdc.SelectObject(&pen); //绘制 int x = rect.Width()/2; int y = rect.Height()/2; memdc.MoveTo(x,y); memdc.LineTo(x+50,y+50); //删除画笔 pen.DeleteObject();
复制临时画布内容到客户区
pDC->BitBlt(10,10,rect.right,rect.bottom,&memdc,0,0,SRCCOPY); memdc.DeleteDC();
清除
bitmap.DeleteObject(); ReleaseDC(pDC);