Click here to Skip to main content
12,691,637 members (32,575 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: MFC VisualC++
how to change color of button in vc++ mfc for vs2008

Sorry Its not working please give details please
Your code is not working please give me details please please,Its urget
Posted 31-Jan-13 3:51am
debarunb1.2K
Updated 12-Feb-13 21:13pm
v3
Comments
Maximilien 31-Jan-13 9:26am
   
What have you tried so far ? what did your google searches returned ?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

1. Place Button with Resource Editor
2. Add Variable for Button (for example m_StopButton ) with Wizard
3. Rename
CButton  m_StopButtonto;

to
CMFCButton  m_StopButton;

4. Change some visible features

// Set the background color for the button text.
  m_StopButton.SetFaceColor(RGB(255,0,0),true);
  m_StopButton.SetTextColor(RGB(0,0,255));
  // Set the tooltip of the button.
  m_StopButton.SetTooltip(_T("This is my Stop Button!"));
  Permalink  
v3
Comments
Gbenbam 3-Aug-15 10:33am
   
I used this code on VS2010 but id did not seem to work.

I added an MFC button from the resource editor and wrote.

CMFCButton *pButton = (CMFCButton *)GetDlgItem(IDC_MFCBUTTON1);
pButton->StFaceColor(RGB(255,0,0),true);
pButton->SetTextColor(RGB(0,0,255));

I wonder why the code doesn't seem to work.


merano 3-Aug-15 13:35pm
   
(1)Note that the background is not filled when the CMFCButton::m_bTransparent member variable is TRUE.
https://msdn.microsoft.com/de-de/library/Bb983413.aspx


(2)SetFaceColor() is ignored by modern theme engines. The wizard greates something like:

CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));

You can comment this line out to disable custom MFC themes. This works, but the button
will not look good because of classic theme.

Possibly you can Load a Color-Bitmap to get the color you want.

Another solution would be to do an ownerdraw button - handling the OnDrawItem() or WM_DRAWITEM
message and do the painting yourself.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

It is also needed to include the header afxbutton.h, i.e. #include "afxbutton.h"
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170117.1 | Last Updated 17 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100