Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C++ Libraries / November 2004

Tip: Looking for answers? Try searching our database.

how to change the dialog background color by clicking a button?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark - 28 Nov 2004 12:23 GMT
i can change the dialog background color by calling the
function----SetDialogBkColor(RGB(0,0,255),RGB(255,0,0))-----in the function
InitInstance(), but i want to change the background color only by clicking a
button on the dialog. what should i do? thanks!!
Ashok K Kumar - 30 Nov 2004 17:21 GMT
Hi,

There is no direct method to set the background color of a dialog box.

However, you can do by the following method,

Create a CBrush member variable for the CDialog derived class
   CBrush m_pbkBrush;

in OnInitDialog create the brush with a suitable color
   m_pbkBrush.CreateSolidBrush(RGB(255,0,0));

add WM_CTLCOLOR message map and make the following changes in the message
handler function

HBRUSH CMFCTabDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
   HBRUSH hbr;
   if (nCtlColor == CTLCOLOR_DLG)
       hbr = (HBRUSH)m_pbkBrush.GetSafeHandle();
   else
       hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
   return hbr;
}

and whereever you want the background to be changed like your button click,
delete the old brush object and recreate with the new color and call
Invalidate()

m_pbkBrush.DeleteObject();
m_pbkBrush.CreateSolidBrush(RGB(0,255,0));
Invalidate();

------------------------------
Ashok K Kumar

> i can change the dialog background color by calling the
> function----SetDialogBkColor(RGB(0,0,255),RGB(255,0,0))-----in the function
> InitInstance(), but i want to change the background color only by clicking a
> button on the dialog. what should i do? thanks!!

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.