まずは,変数のスコープを狭める。さらに,変数は宣言と同時に値を代入するように変更。
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HBITMAP hBitmap;
switch (message)
{
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
int wmEvent = HIWORD(wParam);
// 選択されたメニューの解析 :
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
}
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
HDC hBufdc = CreateCompatibleDC(hdc);
SelectObject(hBufdc, hBitmap);
BITMAP bmp;
GetObject(hBitmap, sizeof(BITMAP), &bmp);
BitBlt(hdc, 0, 0, (int)bmp.bmWidth, (int)bmp.bmHeight, hBufdc, 0, 0, SRCCOPY);
DeleteDC(hBufdc);
EndPaint(hWnd, &ps);
break;
}
case WM_CREATE:
hBitmap = (HBITMAP)LoadImage(hInst,
MAKEINTRESOURCE(IDB_BITMAP1),
IMAGE_BITMAP,
0, 0,
LR_DEFAULTCOLOR);
break;
case WM_DESTROY:
DeleteObject(hBitmap);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}