mike_marquet
asked on
Problem with WM_CTLCOLORBTN
I have make this
HBRUSH g_hBrush = CreateSolidBrush(RGB(255,2 55,0));
BOOL CALLBACK DialogWndProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_CTLCOLORBTN :
SetBkMode((HDC)wParam, TRANSPARENT);
SetTextColor((HDC)wParam, RGB(255,0,0));
SetBkColor((HDC)wParam, RGB(255,255,0));
return (BOOL)g_hBrush;
}
return FALSE;
}
to paint the bakcground of my button, but it doesn't work. Why ?
When I do the same for the WM_CTLCOLORDLG, WM_CTLCOLORSTATIC, WM_CTLCOLOREDIT, ... it works. Only for WM_CTLCOLORBTN it doesn't work.
Help
HBRUSH g_hBrush = CreateSolidBrush(RGB(255,2
BOOL CALLBACK DialogWndProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_CTLCOLORBTN :
SetBkMode((HDC)wParam, TRANSPARENT);
SetTextColor((HDC)wParam, RGB(255,0,0));
SetBkColor((HDC)wParam, RGB(255,255,0));
return (BOOL)g_hBrush;
}
return FALSE;
}
to paint the bakcground of my button, but it doesn't work. Why ?
When I do the same for the WM_CTLCOLORDLG, WM_CTLCOLORSTATIC, WM_CTLCOLOREDIT, ... it works. Only for WM_CTLCOLORBTN it doesn't work.
Help
Is g_hBrush successfully created? If not, return (BOOL)g_hBrush; could return false, and result in default processing (use the button face color).
Is it possible the message isn't being sent here? Use a debugger (or a MessageBeep() call) to be sure your code is being called.
I couldn't find any information on this in current documentation, but I vaguely recall having similar trouble at the time the Windows API was changing the way control color messages were sent. IIRC, it used to be passed as a notification, a WM_COMMAND plus a control id plus a command id that indicated it needed the color things set up. I wish I could remember more about it, but I can't find anything in the VC++6 help about it.
As an evil workaround, you could set the system button face color.
Is it possible the message isn't being sent here? Use a debugger (or a MessageBeep() call) to be sure your code is being called.
I couldn't find any information on this in current documentation, but I vaguely recall having similar trouble at the time the Windows API was changing the way control color messages were sent. IIRC, it used to be passed as a notification, a WM_COMMAND plus a control id plus a command id that indicated it needed the color things set up. I wish I could remember more about it, but I can't find anything in the VC++6 help about it.
As an evil workaround, you could set the system button face color.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK, When there is no other way.
Please grade the answer if it has answered your question.
Remarks
The WM_CTLCOLORBTN message is never sent between threads. It is sent only within one thread.
The text color of a check box or radio button applies to the box or button, its check mark, and the text. The focus rectangle for these buttons remains the system default color (typically black). The text color of a group box applies to the text but not to the line that defines the box. The text color of a push button applies only to its focus rectangle; it does not affect the color of the text.