Hi Srishti,
>And if I have to use OnCtlColor, then as I said earlier all the other
>controls (static text etc.)had a white background on a say, red dialog,
>I would like to have the controls come up in the same background
>color as the dialog.
OK, if you want a red background About dialogbox with black static text
controls on it, you may declare a CBrush m_brush member varible in the
CAboutDlg class first, and in its constructor function create the red brush:
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
m_brush .CreateSolidBrush(RGB (255, 0, 0 )) ;
}
then in its OnCtlColor handler function:
HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if (nCtlColor == CTLCOLOR_DLG )
return (HBRUSH) m_brush .GetSafeHandle ( ) ; //set the dialog's
background brush
if (pWnd->GetDlgCtrlID() == IDC_STATIC)
{
// Set the text color to red
pDC->SetTextColor(RGB(0, 0, 0));
// Set the background mode for text to transparent
// so background will show thru.
pDC->SetBkMode(TRANSPARENT);
// Return handle to our CBrush object
hbr = m_brush;
}
//for other kinds of the dialog's child controls, set their foreground
color and make their background mode to transparent as the above
return hbr;
}
>Do I have to do the OnCtlColor for every Dialog box in my application
>or there is a better way.
AFAIK, there is no better way than the OnCtlColor in MFC 7. If all the
dialog box has the same background color and text color in your
application, I suggest you can customize a dialog class(from the CDialog)
as the above sample CAboutDlg, then use this customized dialog class as the
base class of all the other dialog classes in your project.
Thanks!
Best regards,
Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn
This posting is provided "AS IS" with no warranties, and confers no rights.
Sonu - 07 Jun 2005 18:35 GMT
Thanks a lot Gary, that was really helpful!
Regards
Srishti
> Hi Srishti,
>
[quoted text clipped - 62 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
"Gary Chang[MSFT]" - 08 Jun 2005 02:56 GMT
It's OK, Srishti, we are glad to help you on this issue:)
Good Luck!
Best regards,
Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn
This posting is provided "AS IS" with no warranties, and confers no rights.