我编写了一个应用程序来在客户区画线、矩形、椭圆。当我画任何东西时,我需要保存客户区的图像。当出现 WM_PAINT 消息时,我会恢复它。
我使用 HBITMAP 保存和恢复
节省
RECT rc;
GetClientRect(hMain, &rc); // hMain: handle main window
hdc = GetDC(hMain);
HDC hdcMem = CreateCompatibleDC(hdc);
// hbm: handle bitmap to save and restore
hbm = CreateCompatibleBitmap(hdc, rc.right - rc.left, rc.bottom - rc.top);
SelectObject(hdcMem, hbm);
BitBlt(hdcMem, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
hdc, rc.right - rc.left, rc.bottom - rc.top, SRCCOPY);
ReleaseDC(hMain, hdc);
恢复
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hMain, &ps);
FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));
HDC hdcMem = CreateCompatibleDC(hdc);
SelectObject(hdcMem, hbm);
BitBlt(hdc, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
hdcMem, rc.right - rc.left, rc.bottom - rc.top, SRCCOPY);
ReleaseDC(hMain, hdc);
EndPaint(hMain, &ps);
但它不起作用。请帮我。