|
-
June 23rd, 1999, 09:21 PM
#1
How to change the background color of a dialog?
I'd like to choose a different background color for my dialog box? Is there any way to do that? Any suggestion is thankful.
-
June 23rd, 1999, 11:10 PM
#2
Re: How to change the background color of a dialog?
To set default background and text color for dialog and message boxes, you can call
CWinApp::SetDialogBkColor(COLORREF clrCtlBk, COLORREF clrCtlText)
The first argument is background color, second is text color. Call this member function from within the InitInstance member function. For example, the following code sets all application's dialogs to display a red backgroun and green text.
BOOL CTextEditApp::InitInstance()
{
SetDialogBkColor(RGB(255,0,0), RGB(0,255,0));
...
If you want to change background color of 1 dialog box, declare a member variable
protected:
CBrush m_brush;
Then add this line in the OnInitDialog function
BOOL CTestDlg::OnInitDialog()
{
m_brush.CreateSolidBrush(RGB(255,255,255));
...
Does this help?
-
June 24th, 1999, 03:41 AM
#3
Re: How to change the background color of a dialog?
>>If you want to change background color of 1 dialog box, declare a member variable
and override the WM_CTCOLOR method ...
-
June 24th, 1999, 12:27 PM
#4
Re: How to change the background color of a dialog?
The first method works fine. In second method, I followed your instructions and refered to the reply by olivier, i.e. initializing the m_brush in OnInitDialog:
m_brush.CreateSolidBrush(RGB(255,0,0));
and overiding the OnCtlColor as follows
HBRUSH CCatchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
pDC->SelectObject(&m_brush);
return hbr;
}
The color was not changed. Any mistakes here?
Regards,
Zenger Huang
-
June 24th, 1999, 09:48 PM
#5
Re: How to change the background color of a dialog?
Try this:
HBRUSH CCatchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
//HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
//pDC->SelectObject(&m_brush);
return m_brush;
}
Hope this helps.
the Fresh! 
Heaven is a Playground!
-
June 26th, 1999, 12:22 AM
#6
Re: How to change the background color of a dialog?
Thanks a million to all who helped. It works great. Thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|