Written some cool source code? Upload it to Programmer's Heaven.

C and C++

Moderators: Lundin
Number of threads: 27657
Number of posts: 92785

This Forum Only
Post New Thread

Edit Report
How to color a button ? : Need help like MAD! Posted by Bikram on 26 Mar 2000 at 12:23 PM
This is a bit lengthy. But I'm sure you would like to know what I want to know if you already don't know.<br>
<br>
I have a major problem.<br>
<br>
I need to change the color of a Button. Foreground and the Background(Button Face).<br>
I think I have to trap the WM_CTLCOLORBTN message. I tried it - it worked somewhat in that I had to make the button style OWNERDRAW. But then it wouldn't show anything. So I trapped the WM_CTLCOLORBTN message in the parent window and it worked - somewhat. It colored the entire area of the button. No 3D effect, just a solid, flat, colored rectangle ! I am now totally confused.<br>
In MSDN I read (can't recall where in MSDN) that "unlike other controls, the button control has no pre-defined visual apperance when the OWNERDRAW style is set. The application and not the system, is responsible for all painting."<br>
<br>
Is there an easier way than this :<br>
1. Fill button area with solid, colored rectangle.<br>
2. Draw your own 3D lines around the button.<br>
3. Handle the click/button down events to simulate the pressing/depressing :) of the button.<br>
<br>
I was trying the above using MFC. I am using VC++ 5 and VC++ 6. I don't think the two versions have that major a difference as far as this problem is concerned ?<br>
<br>
<br>
Here are some of the things I tried :<br>
(I saw that CALC.EXE uses colored text on it's buttons)<br>
1. Used Spy++ to monitor messages on a button in CALC.EXE.<br>
2. Used Spy++ to monitor messages on the main dialog of CALC.EXE.<br>
The dialog did send the WM_CTLCOLORBTN message to the buttons.<br>
<br>
<br>
Here is a quirk I noticed :<br>
In a normal command button such as the Start button, when you do a mousedown on it, the button gets depressed. Also, the button's text changes position to reflect the down state.<br>
In CALC.EXE, no such thing ! The text stays where it is ! I thought maybe the button text was a Static text control. No such thing. I couldn't get a handle for it using Spy++.<br>
<br>
<br>
<br>
I'd REALLY appreciate ANY input from you.<br>
<br>
Thanks in advance !<br>
<br>
cIAo<br>
Bikram<br>
<br>
<br>
<br>
<br>
BTW, it is possible to change the color of a Static control, Dialog box, Edit control etc. using MFC. Thanks to Xotor for his help.<br>
<br>



Edit Report
Re: How to color a button ? : Need help like MAD! Posted by Brent Marinelli on 28 Mar 2000 at 7:21 AM
: This is a bit lengthy. But I'm sure you would like to know what I want to know if you already don't know.<br>
: <br>
: I have a major problem.<br>
: <br>
: I need to change the color of a Button. Foreground and the Background(Button Face).<br>
: I think I have to trap the WM_CTLCOLORBTN message. I tried it - it worked somewhat in that I had to make the button style OWNERDRAW. But then it wouldn't show anything. So I trapped the WM_CTLCOLORBTN message in the parent window and it worked - somewhat. It colored the entire area of the button. No 3D effect, just a solid, flat, colored rectangle ! I am now totally confused.<br>
: In MSDN I read (can't recall where in MSDN) that "unlike other controls, the button control has no pre-defined visual apperance when the OWNERDRAW style is set. The application and not the system, is responsible for all painting."<br>
: <br>
: Is there an easier way than this :<br>
: 1. Fill button area with solid, colored rectangle.<br>
: 2. Draw your own 3D lines around the button.<br>
: 3. Handle the click/button down events to simulate the pressing/depressing :) of the button.<br>
: <br>
: I was trying the above using MFC. I am using VC++ 5 and VC++ 6. I don't think the two versions have that major a difference as far as this problem is concerned ?<br>
: <br>
: <br>
: Here are some of the things I tried :<br>
: (I saw that CALC.EXE uses colored text on it's buttons)<br>
: 1. Used Spy++ to monitor messages on a button in CALC.EXE.<br>
: 2. Used Spy++ to monitor messages on the main dialog of CALC.EXE.<br>
: The dialog did send the WM_CTLCOLORBTN message to the buttons.<br>
: <br>
: <br>
: Here is a quirk I noticed :<br>
: In a normal command button such as the Start button, when you do a mousedown on it, the button gets depressed. Also, the button's text changes position to reflect the down state.<br>
: In CALC.EXE, no such thing ! The text stays where it is ! I thought maybe the button text was a Static text control. No such thing. I couldn't get a handle for it using Spy++.<br>
: <br>
: <br>
: <br>
: I'd REALLY appreciate ANY input from you.<br>
: <br>
: Thanks in advance !<br>
: <br>
: cIAo<br>
: Bikram<br>
: <br>
: <br>
: <br>
: <br>
: BTW, it is possible to change the color of a Static control, Dialog box, Edit control etc. using MFC. Thanks to Xotor for his help.<br>
: <br>
: <br>
: <br>
<br>
<br>
I have found that when attempting to create a button with a specialized look such as a color variation or even containing specialized characters, pictures, etc it is easiest to just create my own. <br>
<br>
The first step is to create the UpButton and DownButton as bitmap resources.<br>
Next you create a CbitmapButton and load the bitmaps into it.<br>
<br>
Like this<br>
****************************************************************************************************<br>
Examp.h<br>
<br>
CBitmapButton * m_pAdjustButton;<br>
<br>
Examp.cpp<br>
<br>
m_pAdjustButton = new CBitmapButton;<br>
m_pAdjustButton->Create ("", WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,<br>
brect, this, IDC_ADJUST _BUTTON);<br>
m_pAdjustButton->LoadBitmaps(IDB_ARROW _UP, IDB_ARROW_DOWN);<br>
<br>
<br>
controls.h<br>
<br>
#define IDC_ADJUST_UP_BUTTON 3000<br>
<br>
***************************************************************************************************<br>
<br>
I create a controls.h file for defining all of my custom controls ie, IDC_ADJUST _BUTTON.<br>
<br>
IDB_ARROW_UP and IDB_ARROW_DOWN are the bitmap resources you created and brect is used to place the button wherever on a dialog you wish.<br>
<br>
Now you can rock and roll the buttons text color, if you want pictures on your buttons whatever floats your boat. <br>



URL:home.earthlink.net/~nuclei




 
Popular resources and forums for programmers on Programmersheaven.com
Assembly, Basic, C, C#, C++, Delphi, Java, JavaScript, Pascal, Perl, PHP, Python, Ruby, Visual Basic
© Copyright 2009 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Publisher: Lars Hagelin. Read the latest words from the publisher here.
Be the first to sign up for Lars Hagelin’s In-depth Outsourcing Newsletter here.
bootstrapLabs Logo A bootstrapLabs project.