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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
chensuCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mike_marquetAuthor Commented:
OK, When there is no other way.
0
chensuCommented:
Please grade the answer if it has answered your question.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.