I'd like to choose a different background color for my dialog box? Is there any way to do that? Any suggestion is thankful.
Printable View
I'd like to choose a different background color for my dialog box? Is there any way to do that? Any suggestion is thankful.
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?
>>If you want to change background color of 1 dialog box, declare a member variable
and override the WM_CTCOLOR method ...
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
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!
Thanks a million to all who helped. It works great. Thanks again.