| | |
changing color of a pushbutton on a dialog box
![]() |
•
•
Join Date: Jun 2005
Posts: 1
Reputation:
Solved Threads: 0
Hi,
I want to change the color of my button during runtime..
i am writing the following code inthe OnCtlColor of my dialog box
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
I want to change the color of my button during runtime..
i am writing the following code inthe OnCtlColor of my dialog box
C Syntax (Toggle Plain Text)
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
•
•
Join Date: Jul 2005
Posts: 1
Reputation:
Solved Threads: 0
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,"
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
C Syntax (Toggle Plain Text)
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
![]() |
Similar Threads
- Windows GUI - problem with dialog box (C++)
- How to display dialog box items? (C)
- Opening a .pdf file at the clientside without the open/save dialog box (ASP.NET)
- WIN32 GUI application - Problem popping up dialog box (C++)
- Dialog box wrong size (Windows NT / 2000 / XP)
- Common Open dialog box (C++)
- Dialog Box alongwith Form (Visual Basic 4 / 5 / 6)
Other Threads in the C Forum
- Previous Thread: variable length array may not be initialized: error
- Next Thread: Controlling Floppy Disk Head using C
| Thread Tools | Search this Thread |
* adobe ansi api array asterisks binarysearch calculate centimeter char character cm convert copyanyfile copyimagefile copypdffile cprogramme createcopyoffile createprocess() csyntax directory feet fflush fgets file floatingpointvalidation fork frequency function givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking highest homework i/o inches infiniteloop interest intmain() iso keyboard kilometer km linked linkedlist linux linuxsegmentationfault list locate lowest match meter microsoft mqqueue mysql number oddnumber odf open opendocumentformat openwebfoundation owf pattern pdf performance posix power probleminc program programming pyramidusingturboccodes read recv recvblocked repetition reversing scanf scheduling segmentationfault send single socketprograming socketprogramming stack standard string suggestions systemcall unix urboc user variable voidmain() wab whythiscodecausesegmentationfault win32api windows.h





