Author: Zhu Jincan
Source:Http://www.cnblogs.com/clever101
Compile a small video at nightProgramIt involves how to set the background color and static text color of the dialog box. This was done in a single sentence in vc6.0. In the Application classInitinstance ()Function addition:
// Set the background and text color of the dialog box
Setdialogbkcolor (RGB ( 160 , 180 , 220 ), RGB ( 0 , 0 , 0 ));
Who knows this does not work in VS 2005? Check it on the network. The setdialogbkcolor function is no longer supported in vs 2003. We have to find another way. The other way is to respondWm_ctlcolorMessage, add the following in the message ing function:
Hbrush cfilespltdlg: onctlcolor (CDC*PDC, cwnd*Pwnd, uint nctlcolor)
{
Hbrush HBr=Cdialog: onctlcolor (PDC, pwnd, nctlcolor );
//Todo: change any properties of DC here
//Todo: if the default paint brush is not required, another paint brush is returned.
//Determine if drawing a dialog box. If we are, return + handle
//Our own background brush. Otherwise let windows//Handle it.
Switch (Nctlcolor)
{
Case Ctlcolor_static: // Settings for all static text controls
{
// Set the background to transparent
PDC -> Setbkmode (transparent );
PDC -> Settextcolor (RGB ( 0 , 0 , 0 )); // Set Font color
Break ;
}
Case Ctlcolor_dlg:
{
Return (Hbrush) m_brush. getsafehandle ();
Break ;
}
Default :
Break ;
}
Return HBr;
}
In this way, in addition to static text control, buttons and text editing boxes can control the background color, because I see the following macros
Hbrush cfilespltdlg: onctlcolor (CDC*PDC, cwnd*Pwnd, uint nctlcolor)
{
Hbrush HBr=Cdialog: onctlcolor (PDC, pwnd, nctlcolor );
//Todo: change any properties of DC here
//Todo: if the default paint brush is not required, another paint brush is returned.
//Determine if drawing a dialog box. If we are, return + handle
//Our own background brush. Otherwise let windows//Handle it.
Switch (Nctlcolor)
{
Case Ctlcolor_static: // Settings for all static text controls
{
// Set the background to transparent
PDC -> Setbkmode (transparent );
PDC -> Settextcolor (RGB ( 0 , 0 , 0 )); // Set Font color
Break ;
}
Case Ctlcolor_dlg:
{
Return (Hbrush) m_brush. getsafehandle ();
Break ;
}
Default :
Break ;
}
Return HBr;
}