Reputation: 2661
I can set the back color when i am registering the class, e.g.:
wincl.hbrBackground = CreateSolidBrush(RGB(202, 238, 255));
RegisterClassEx(&wincl);
But how would i do it to any window i have created with the CreateWindow function? like a button on my main window, i have visual styles enabled, and i can notice the windows default gray back color behind the button.
Don't tell me i have to SetWindowLong for the window procedure on allllllll my controls and intercept the WM_PAINT :(
Upvotes: 1
Views: 6019
Reputation: 36016
All the windows controls send a message to their parent to get the brush to use to fill their background. Assuming you save a copy of the brush handle somewhere, you can do the following in your WindowProc, or DialogProc, to ensure everything draws with the correct background brush.
case WM_CTLCOLORSTATIC:
case WM_CTLCOLORBTN:
HDC hdc;
HWND hwndCtl;
POINT pt;
hdc = (HDC)wParam;
hwndCtl = (HWND)lParam;
pt.x = 0;
pt.y = 0;
MapWindowPoints(hwndCtl,_hwnd,&pt,1);
x = -pt.x;
y = -pt.y;
SetBrushOrgEx(hdc,x,y,NULL);
return (INT_PTR)_skinBrush;
Upvotes: 2
Reputation: 14441
If you want a customized window you can create your own window class to draw that type of window. Implement a handler for wm_paint and draw whatever you want for the window. There are a lot of tutorials available.
Upvotes: 0