How do I set dialog based window background to any other color
in run time ?
I noticed that background is set onInitialize ,
is there a way to change the color just like for other control as CEdit?:mad: :mad:
Printable View
How do I set dialog based window background to any other color
in run time ?
I noticed that background is set onInitialize ,
is there a way to change the color just like for other control as CEdit?:mad: :mad:
Here is how you could change the backcolor of a dialog:
PHP Code:HBRUSH g_hbrBackground = CreateSolidBrush(RGB(0,255,0));
case WM_CTLCOLORDLG:
return (LON)g_hbrBackGround;
case WM_CTLCOLORSTATIC:
{
HDC hdcStatic = (HDC)wParam;
SetTextColor(hdcStatic, RGB(255,255,255));
SetBkMode(hdcStatic,TRANSPARENT);
return (LONG)g_hbrBackground;
}
break;
Where do I insert this code in Dialog based window?
Does it have to be in window message hanling function?
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)?
:confused:
Yes.
Here is an example:
PHP Code:#include <windows.h>
#include "resource.h"
HBRUSH g_hbrBackground = NULL;
BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
g_hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(NULL,
MAKEINTRESOURCE(IDI_APPLICATION)));
SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(NULL,
MAKEINTRESOURCE(IDI_APPLICATION)));
break;
case WM_CLOSE:
EndDialog(hwnd, 0);
break;
case WM_CTLCOLORDLG:
return (LONG)g_hbrBackground;
case WM_CTLCOLORSTATIC:
{
HDC hdcStatic = (HDC)wParam;
SetTextColor(hdcStatic, RGB(255, 255, 255));
SetBkMode(hdcStatic, TRANSPARENT);
return (LONG)g_hbrBackground;
}
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hwnd, 0);
break;
}
break;
case WM_DESTROY:
DeleteObject(g_hbrBackground);
break;
default:
return FALSE;
}
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);
}