Changing color of a pushbutton in a dialog box

This is a discussion on Changing color of a pushbutton in a dialog box within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I want to change the color of my button during runtime.. i am writing the following code inthe OnCtlColor ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    3

    Changing color of a pushbutton in a dialog box

    Hi,

    I want to change the color of my button during runtime..

    i am writing the following code inthe OnCtlColor of my dialog box

    Code:
    HBRUSH CPIVSyncDlg::OnCtlColor(CDC *pdc,CWnd *pwnd,UINT nCtlColor)
    {
    	HBRUSH hbr = CDialog::OnCtlColor(pdc,pwnd,nCtlColor);
    
    	switch(nCtlColor)
    	{
    		case CTLCOLOR_BTN:
    			if(pwnd->GetDlgCtrlID() == IDC_STARTSTOP)
    				pdc->SetBkColor(RGB(255,0,0));
    			return (HBRUSH)m_btbrush.GetSafeHandle();
    		case CTLCOLOR_DLG:
    			pdc->SetBkColor(RGB(255,255,255));
    			pdc->SetBkMode(TRANSPARENT);
    			return (HBRUSH)m_hbrush.GetSafeHandle();
    		case CTLCOLOR_EDIT:
    			pdc->SetBkColor(RGB(0,0,0));
    			pdc->SetBkMode(TRANSPARENT);
    			return (HBRUSH)m_hbrush.GetSafeHandle();
    		default:
    			return CDialog::OnCtlColor(pdc,pwnd,nCtlColor);		
    	}
    	return hbr;
    	//return (HBRUSH)m_hbrush.GetSafeHandle();
    }
    the button is IDC_STARTSTOP i want to turn it red..but the interesting thing is the whole dialog box turns red except the buttons...

    i have searched the msdn library and I am following all the instruction given in example ...all in vein... any suggestion would be helpful..

    thanks,
    Hardik

  2. #2
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    instead of
    return (HBRUSH)m_btbrush.GetSafeHandle(); after each case
    just break; so that
    return hbr; gets returned, otherwise, it never reaches that line.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 02:59 PM
  2. Parent of a BrowseForFolder dialog box
    By @nthony in forum Windows Programming
    Replies: 4
    Last Post: 01-08-2007, 02:54 PM
  3. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM
  4. changing dialog box in the middle
    By Devil Panther in forum Windows Programming
    Replies: 2
    Last Post: 03-16-2004, 02:38 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21