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?
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.

WynCommented:
HBRUSH hb=0;
COLORREF cr = RGB(0,0,0);

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

}
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
WynCommented:
Sorry, it should be this:

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

   hb = CreateSolidBrush(cr);
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

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
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.