Thread: VC++ setting text color of a button

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663

    VC++ setting text color of a button

    Hi,

    I searched around in MSDN for a few days, and I finally came up with the following code to set the text color of a radio button in a dialog box. Unfortunately, it doesn't work. I added the OnCtlColor() handler to my Dialog box class(CCodeProject_Dialog2Dlg). My dialog box has radio buttons, check boxes, combo boxes, list boxes and I tried substituting several of their ID's in the code, and none of the text changed color. Can anyone tell me how do change the text color on a button?

    Code:
    HBRUSH CCodeProject_Dialog2Dlg::OnCtlColor(CDC *pDC, CWnd *pWnd, UINT nCtlColor)
    {
    	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    	 
    	if(pWnd->GetDlgCtrlID() == IDC_WIN98)
    	{
    		pDC->SetTextColor(RGB(255,0,0));
    		pDC->SetBkMode(TRANSPARENT);
    		
    	}
    
    	return hbr;
    
    }
    Last edited by 7stud; 10-11-2004 at 06:25 AM.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You don't, short of owner-draw or subclassing and drawing it yourself. Please search this board for more information as this has been asked and answered many times in the past.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    here's an old thread i once started on that subject:

    http://cboard.cprogramming.com/showt...ghlight=button
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Hi,

    Thanks for the responses. I've read several posts by people on several forums that say you can't change the text color of a radio button. I'm not sure why people believe that because if you attach the handler function I posted above to the WM_CTLCOLOR message, it will change the text color of a radio button. I'm a beginner, and the mistake I made was to add the handler function without attaching it to WM_CTLCOLOR.

    Now, from what I gather, you cannot easily change the text color of a push button. I guess I would like to learn how to do that now, but it seems like it may be too complex.

    I figured out a how to use bitmap buttons, but I would like to learn how to change the text color on a push button--thanks for the link.
    Last edited by 7stud; 10-13-2004 at 08:26 PM.

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Shame on me: I read 'color' and 'button' and dismissed your question as yet another 'how do I change the colour of a button' question requiring a stock 'search the board' response.

    Still, I'm glad that you have managed to find a solution for yourself and did not accept the misinformation of others (see disclaimer in my sig ).
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  6. #6
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    well... i as far i now you can't change the color of a push button...
    so you will have you draw it yourself, to owner draw it.

    the link above points you to the right location where you can learn how to draw your own buttons and control them.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  2. Setting Text simple
    By Nor in forum Windows Programming
    Replies: 5
    Last Post: 04-22-2002, 08:03 AM
  3. Setting static text color -- I know I'm doing something wrong
    By Garfield in forum Windows Programming
    Replies: 4
    Last Post: 01-26-2002, 01:59 PM
  4. Setting text colour
    By JamMan in forum C++ Programming
    Replies: 1
    Last Post: 11-19-2001, 11:43 AM
  5. Setting ListBox text
    By BubbleMan in forum Windows Programming
    Replies: 5
    Last Post: 09-19-2001, 07:09 AM