I write an application to draw line, rect, ellipse in client area. I need save image of client area when i draw any thing. And I restore it when message WM_PAINT occur.
I use HBITMAP to save and restore
SAVE
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);
RESTORE
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);
But it doesn't work. Please help me.