Part of the issue is that the window has changed size and the memDC may now be too small/large.
You need to resize the DC, unless you created it the size of the full screen.
This is (similar) to how I do this.....
Code:
case WM_SIZE:
{
GetClientRect(hwnd, &ctRect);//I use the lParam and fill in a RECT
//add check for wParam==SIZE_MINIMISED ie has a size
DrawScreen(hwnd,ctRect):
return 0;
}
//a fast PAINT does nothing but a single BitBlt(), IMO it should NEVER do anything else
case WM_PAINT:
{
hdc = BeginPaint(hwnd, &pntS);
BitBlt(hdc, pntS.rcPaint.left, pntS.rcPaint.top, pntS.rcPaint.right-pntS.rcPaint.left, pntS.rcPaint.bottom-pntS.rcPaint.top, memDC, pntS.rcPaint.left, pntS.rcPaint.top, SRCCOPY);
EndPaint(hwnd, &pntS);
return 0;
}
void DrawScreen(HWND hwnd,RECT ctRect)
{
//TODO
//add check of OLD size to NEW size
//if the new size is not the same as the old size
//clearup the current HDC and BMP
//create a new one the right size
if(rectOLD!=ctRect)//NOTE: this is a placeholder, will not work
CreateBuffer(hwnd,ctRect);
// Paint screen background grey
hBrush = CreateSolidBrush( RGB(0xD3, 0xD3, 0xD3) );
FillRect(memDC, &ctRect, hBrush);
DeleteObject(hBrush);
//call for paint
InvalidateRect(hwnd,ctRect);
UpdateWindow(hwnd);
return;
}
//other methods, also used in WM_CREATE and WM_DESTROY
void CreateBuffer(HWND , RECT);
{
if(memDC)
KillBuffers();
//TODO
//create new HDC and BMP based on HWND and RECT
//remember to catch the original 1x1 monochrom bmp created in the HDC
//as BMPs are not 100% of deleting if still selected into a DC
}
void KillBuffers()
{
//check that DC has been created
if(!memDC)
return;
SelectObject(memDC, hOriginalBMP);
DeleteObject(hNewBMP);
DeleteDC(memDC);
memDC=NULL;//so our error check works
}