Problem with WM_CTLCOLORBTN

I have make this

HBRUSH g_hBrush = CreateSolidBrush(RGB(255,255,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
mike_marquetAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
chensuConnect With a Mentor Commented:
Unfortunately,

"WM_CTLCOLORBTN
Sent By: command buttons (regular and default)

Changes made during this message have no effect on command buttons. Command buttons always use system colors for drawing themselves."

See

INFO: WM_CTLCOLORxxx Message Changes
http://support.microsoft.com/support/kb/articles/q130/9/52.asp


Colored buttons
http://codeguru.developer.com/buttonctrl/color_button.shtml
http://codeguru.developer.com/mfc/comments/10575.shtml

The sample code can be easily adapted to non-MFC.
0
 
WxWCommented:
Check if your application agrees with the following remarks :

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.
0
 
azamiCommented:
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.
0
 
mike_marquetAuthor Commented:
OK, When there is no other way.
0
 
chensuCommented:
Please grade the answer if it has answered your question.
0
All Courses

From novice to tech pro — start learning today.