-
August 24th, 2010, 12:30 PM
#1
Changing the color of a static control (Win32)
I'm trying to change the color of a static control from blue to purple.
I managed to change it to blue in the dialog initialization but I can't change it to purple after.
Here's the working blue color code:
Code:
switch(uMsg)
{
case WM_CTLCOLORSTATIC://wParam: Handle to the device context for the static control window.
//lParam: Handle to the static control.
{
if ((HWND)lParam == GetDlgItem(hwndDlg,IDC_STATIC3))
{
SetBkMode((HDC)wParam,TRANSPARENT);
SetTextColor((HDC)wParam, RGB(0,0,255));
return (BOOL)CreateSolidBrush (GetSysColor(COLOR_MENU));
}
}
}
And here's the not working purple color code:
Code:
switch(uMsg)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_STATIC3:
{
SetTextColor((HDC)GetDC(GetDlgItem(hwndDlg, IDC_STATIC3)), RGB(145,25,139));
return (BOOL)CreateSolidBrush (GetSysColor(COLOR_MENU));//is this needed?
}
}
thanks
-
August 25th, 2010, 11:55 PM
#2
Re: Changing the color of a static control (Win32)
You have to handle this as part of the WM_CTLCOLORSTATIC message.
In the WM_COMMAND handler set a flag and invalidate the control.
In the WM_CTLCOLORSTATIC handler check the flag and return the required brush.
-
August 27th, 2010, 04:13 AM
#3
Re: Changing the color of a static control (Win32)
Code:
return (BOOL)CreateSolidBrush (GetSysColor(COLOR_MENU));
Really bad idea. You create a new brush before each return and never destroy the one created last time. This is called 'GDI resource leak'. Sooner or later you run off the GDI resources, and your app stops paint.
You have to create a brush once and return that one whenever it's needed.
Best regards,
Igor
-
August 27th, 2010, 09:02 AM
#4
Re: Changing the color of a static control (Win32)
You're right.
You got to figure out some magic to delete unused brushes.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|