我有同样的问题。解决方案是将DefWindowProc()从默认值移到WndProc()的末尾。
前:
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
static HBITMAP hBitMap;
static int cxSizeBitMap;
static int cySizeBitMap;
static int cxClient;
static int cyClient;
HDC hdc;
BITMAP bitMap;
PAINTSTRUCT ps;
HDC hMem;
HINSTANCE hInstance ;
switch( message )
{
case WM_CREATE:
hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
hBitMap = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BRICK ) );
GetObject( hBitMap, sizeof(BITMAP), &bitMap );
cxSizeBitMap = bitMap.bmWidth;
cySizeBitMap = bitMap.bmHeight;
break;
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
break;
case WM_PAINT:
hdc = BeginPaint( hWnd, &ps );
hMem = CreateCompatibleDC( hdc );
SelectObject( hMem, hBitMap );
for (int y = 0 ; y < cyClient ; y += cySizeBitMap)
for (int x = 0 ; x < cxClient ; x += cxSizeBitMap)
{
BitBlt (hdc, x, y, cxSizeBitMap, cySizeBitMap, hMem, 0, 0, SRCCOPY) ;
}
DeleteDC( hMem );
EndPaint( hWnd, &ps );
break;
case WM_DESTROY:
DeleteObject( hBitMap );
PostQuitMessage( 0 );
break;
default:
// In this cast ShowWindow() will return 1400.
DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
后:
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
static HBITMAP hBitMap;
static int cxSizeBitMap;
static int cySizeBitMap;
static int cxClient;
static int cyClient;
HDC hdc;
BITMAP bitMap;
PAINTSTRUCT ps;
HDC hMem;
HINSTANCE hInstance ;
switch( message )
{
case WM_CREATE:
hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
hBitMap = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BRICK ) );
GetObject( hBitMap, sizeof(BITMAP), &bitMap );
cxSizeBitMap = bitMap.bmWidth;
cySizeBitMap = bitMap.bmHeight;
break;
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
break;
case WM_PAINT:
hdc = BeginPaint( hWnd, &ps );
hMem = CreateCompatibleDC( hdc );
// Было SelectObject( hdc, hMem );
SelectObject( hMem, hBitMap );
// Было BitBlt( hdc, 0, 0, cxSize, cySize, hMem, 0, 0, DIB_RGB_COLORS);
for (int y = 0 ; y < cyClient ; y += cySizeBitMap)
for (int x = 0 ; x < cxClient ; x += cxSizeBitMap)
{
BitBlt (hdc, x, y, cxSizeBitMap, cySizeBitMap, hMem, 0, 0, SRCCOPY) ;
}
DeleteDC( hMem );
EndPaint( hWnd, &ps );
break;
case WM_DESTROY:
DeleteObject( hBitMap );
PostQuitMessage( 0 );
break;
}
// In this case ShowWindow() will show the window.
return DefWindowProc(hWnd, message, wParam, lParam);;
}