User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 429,779 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,939 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 5547 | Replies: 1
Reply
Join Date: Jun 2005
Posts: 1
Reputation: rangalo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
rangalo rangalo is offline Offline
Newbie Poster

changing color of a pushbutton on a dialog box

  #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

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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Posts: 1
Reputation: gobigred is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gobigred gobigred is offline Offline
Newbie Poster

Re: changing color of a pushbutton on a dialog box

  #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

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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 4:04 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC