How to set the background color and static text color of the dialog box in VC Programming

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.