changing color of a pushbutton on a dialog box

Reply

Join Date: Jun 2005
Posts: 1
Reputation: rangalo is an unknown quantity at this point 
Solved Threads: 0
rangalo rangalo is offline Offline
Newbie Poster

changing color of a pushbutton on a dialog box

 
0
  #1
Jun 20th, 2005
Hi,

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

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

  1. HBRUSH CPIVSyncDlg::OnCtlColor(CDC *pdc,CWnd *pwnd,UINT nCtlColor)
  2. {
  3. HBRUSH hbr = CDialog::OnCtlColor(pdc,pwnd,nCtlColor);
  4.  
  5. switch(nCtlColor)
  6. {
  7. case CTLCOLOR_BTN:
  8. if(pwnd->GetDlgCtrlID() == IDC_STARTSTOP)
  9. pdc->SetBkColor(RGB(255,0,0));
  10. return (HBRUSH)m_btbrush.GetSafeHandle();
  11. case CTLCOLOR_DLG:
  12. pdc->SetBkColor(RGB(255,255,255));
  13. pdc->SetBkMode(TRANSPARENT);
  14. return (HBRUSH)m_hbrush.GetSafeHandle();
  15. case CTLCOLOR_EDIT:
  16. pdc->SetBkColor(RGB(0,0,0));
  17. pdc->SetBkMode(TRANSPARENT);
  18. return (HBRUSH)m_hbrush.GetSafeHandle();
  19. default:
  20. return CDialog::OnCtlColor(pdc,pwnd,nCtlColor);
  21. }
  22. return hbr;
  23. //return (HBRUSH)m_hbrush.GetSafeHandle();
  24. }

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
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1
Reputation: gobigred is an unknown quantity at this point 
Solved Threads: 0
gobigred gobigred is offline Offline
Newbie Poster

Re: changing color of a pushbutton on a dialog box

 
0
  #2
Jul 19th, 2005
the method in "How do I change the background color of a control?" will not work for buttons!

If you want to change the color of a dialog button, you have to use an owner-draw button. (You can use bitmap buttons.) Changing the color through OnCtlColor() will not work for buttons. The following Knowledge Base articles may be of help to you: Q32685, "Using the WM_CTLCOLOR Message,"



Originally Posted by rangalo
Hi,

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

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

  1. HBRUSH CPIVSyncDlg::OnCtlColor(CDC *pdc,CWnd *pwnd,UINT nCtlColor)
  2. {
  3. HBRUSH hbr = CDialog::OnCtlColor(pdc,pwnd,nCtlColor);
  4.  
  5. switch(nCtlColor)
  6. {
  7. case CTLCOLOR_BTN:
  8. if(pwnd->GetDlgCtrlID() == IDC_STARTSTOP)
  9. pdc->SetBkColor(RGB(255,0,0));
  10. return (HBRUSH)m_btbrush.GetSafeHandle();
  11. case CTLCOLOR_DLG:
  12. pdc->SetBkColor(RGB(255,255,255));
  13. pdc->SetBkMode(TRANSPARENT);
  14. return (HBRUSH)m_hbrush.GetSafeHandle();
  15. case CTLCOLOR_EDIT:
  16. pdc->SetBkColor(RGB(0,0,0));
  17. pdc->SetBkMode(TRANSPARENT);
  18. return (HBRUSH)m_hbrush.GetSafeHandle();
  19. default:
  20. return CDialog::OnCtlColor(pdc,pwnd,nCtlColor);
  21. }
  22. return hbr;
  23. //return (HBRUSH)m_hbrush.GetSafeHandle();
  24. }

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
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 3
Reputation: mitulgolakiya is an unknown quantity at this point 
Solved Threads: 0
mitulgolakiya's Avatar
mitulgolakiya mitulgolakiya is offline Offline
Newbie Poster

Re: changing color of a pushbutton on a dialog box

 
0
  #3
Jan 3rd, 2009
What is here m_btbrush and m_hbrush ?

I got an error with this code like this :

error C2228: left of '.GetSafeHandle' must have class/struct/union
With Regards,
Mitul Golakiya
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC