PAINTSTRUCT ps;
g_hDC=BeginPaint(g_hWnd,&ps);
HBRUSH hbrScr=CreateSolidBrush(RGB(0,0,255));
HDC hMemDC=CreateCompatibleDC(g_hDC);
RECT rect;
GetClientRect(hwnd,&rect);
HBITMAP hBitmap=CreateCompatibleBitmap(g_hDC,rect.right,rect.bottom);//A
HBITMAP oldBmp=(HBITMAP)SelectObject(hMemDC,hBitmap);//B
FillRect(hMemDC,&g_rWindow,hbrScr);
Render(hMemDC);
BitBlt(g_hDC,0,0,1024,768,hMemDC,0,0,SRCCOPY);
SelectObject(oldBmp);
DeleteObject(hBitmap);
DeleteObject(oldBmp);
DeleteObject(hbrScr);
DeleteDC(hMemDC);
EndPaint(g_hWnd, &ps);
A行和B行:在對內存DC畫圖之前要先往內存DC裏選入壹張空白位圖,然後再在上面作圖。因為CreateCompatibleDC()函數創建內存DC時為內存DC選入的默認位圖只有壹個像素,沒有實際用處,得用戶自己重新創建壹張才行