Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Change color of button

Posted on 1999-09-29
9
Medium Priority
?
382 Views
Last Modified: 2013-12-03
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
0
Comment
Question by:redhat092798
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 5

Accepted Solution

by:
Wyn earned 90 total points
ID: 2086761
HBRUSH hb=0;
COLORREF cr = RGB(0,0,0);

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

}
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2086763
Sorry, it should be this:

   hb = CreateSolidBrush(cr);
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2086764
Sorry, it should be this:

   hb = CreateSolidBrush(cr);
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

Author Comment

by:redhat092798
ID: 2091837
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
 
LVL 5

Expert Comment

by:Wyn
ID: 2092920
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
 

Author Comment

by:redhat092798
ID: 2093084
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
 
LVL 5

Expert Comment

by:Wyn
ID: 2093127
Sure it works,I will mail you later.
0
 

Author Comment

by:redhat092798
ID: 2100743
My e-mail is falsagoff@hotmail.com
0
 

Author Comment

by:redhat092798
ID: 2109621
I was hoping for a non MFC example. But its ok. Thanks anyway.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question