次の例が役立つ場合があります。
//Setting the background color of a window during window class registration
WNDCLASS wc = { 0 } ( or WNDCLASS wc; memset(&wc, 0, sizeof(wc)); )
...
...
...
wc.hbrBackground = CreateSolidBrush(0x000000ff); // a red window class background
...
...
RegisterClass(&wc);
// Setting the background during WM_ERASEBKGND
LRESULT CALLBACK YourWndProc(HWND hwnd, UINT umsg, WPARAM,LPARAM)
{
switch( umsg )
{
case WM_ERASEBKGND:
{
RECT rc;
GetClientRect(hwnd, &rc);
SetBkColor((HDC)wParam, 0x000000ff); // red
ExtTextOut((HDC)wParam, 0, 0, ETO_OPAQUE, &rc, 0, 0, 0);
return 1;
}
// or in WM_PAINT
case WM_PAINT:
{
PAINTSTRUCT ps;
RECT rc;
HDC hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rc);
SetBkColor(hdc, 0x000000ff); // red
ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, 0, 0, 0);
EndPaint(hwnd, &ps);
break;
}
...
...
...
default:
return DefWindowProc(...);
}
return 0;
}