Change color of button

I want to change the color of a button on my dialog.
I know I have to check WM_CTLCOLORBTN. But I need some code snippet please. The HWND of my button is BUT. Ok thanks
redhat092798Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
WynConnect With a Mentor Commented:
HBRUSH hb=0;
COLORREF cr = RGB(0,0,0);

case WM_CTLCOLOTBTN:
{
   
   DeleteObject(hb);
   
   hb = CreateSolidBrush();
   
   return (LRESULT)hb;

}
0
 
WynCommented:
Sorry, it should be this:

   hb = CreateSolidBrush(cr);
0
 
WynCommented:
Sorry, it should be this:

   hb = CreateSolidBrush(cr);
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
redhat092798Author Commented:
1. I put this in the WndProc() as usual , right ?
2. Is this for all the buttons on the window cause I don't see anything referring to a specific button handle.
0
 
WynCommented:
Oops,I forget to add this before DeleteObject():

   DefWindowProc(hWnd,Msg,wParam,lParam);
this function use the brush you create to redraw the button
1:Yes
2:because the DefWindowProc() know which one to draw,it gets the information from the lParam which is meant to be the handle of the button in  question.

sorry for my negligence.
0
 
redhat092798Author Commented:
It does not work . I just read an article that button colors cannot be change. I'm confused now. It does not work when I try . Can you send me an example. ? Just a window and and a red button or any color.  My e-mail is falsagoff@hotmail.com
0
 
WynCommented:
Sure it works,I will mail you later.
0
 
redhat092798Author Commented:
My e-mail is falsagoff@hotmail.com
0
 
redhat092798Author Commented:
I was hoping for a non MFC example. But its ok. Thanks anyway.
0
All Courses

From novice to tech pro — start learning today.