How does vc6.0 change the background color of the dialog box?

Source: Internet
Author: User

Vc6.0How to change the background color of a dialog box

Method 1: Call the member function setdialogbkcolor of the cwinapp class.

The first parameter of the function specifies the background color, and the second parameter specifies the text color. The following example shows how to set the application dialog box to blue background and red text:

① Create a dialog-based MFC Appwizard application exampledlg.

② Add the following code to cexampledlgapp: initinstance:

Bool cexampledlgapp: initinstance ()
{
...
Cexampledlgdlg DLG;
M_pmainwnd = & DLG;

// Call domodal () to set the dialog box to blue background and red text
Setdialogbkcolor (RGB (255,), RGB (, 0 ));
Int nresponse = DLG. domodal ();
...
}

Compile and run. The background color and text color of the dialog box have changed. It is worth noting that setdialogbkcolor must be called before domodal () is called, and this method will change the color of all the dialogs in the application and cannot target a specified dialog box.
Method 2: Reload onpaint (), that is, the message wm_paint. The Code is as follows (the above example project prevails ):

Void cexampledlgdlg: onpaint ()
{
If (isiconic ())
...
Else
{
Crect rect;
Cpaintdc DC (this );
Getclientrect (rect );
DC. fillsolidrect (rect, RGB (0,255, 0); // set it to a green background

Cdialog: onpaint ();
}

Method 3: overload onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor), that is, wm_ctlcolor message. The specific steps are as follows (the above project prevails ):

① In the header file of cexampledlgdlg, add a member variable of cbrush:

Class cexampledlgdlg: Public cdialog
{
...
Protected:
Cbrush m_brush;
...
};

② Add the following code to the oninitdialog () function:
Bool cexampledlgdlg: oninitdialog ()
{
...
// Todo: add extra initialization here
M_brush.createsolidbrush (RGB (0,255, 0); // generate a green brush
...
}

③ Use classwizard to overload onctlcolor (...), That is, wm_ctlcolor message:
Hbrush cexampledlgdlg: onctlcolor
(CDC * PDC, cwnd * pwnd, uint nctlcolor)
{

Return m_brush; // Add a green brush
}

Method 4: Reload the onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor) message, that is, the wm_ctlcolor message. The specific steps are as follows (the above project prevails ):
Steps ① and ② are described in steps ① and ② above.

Step ③ use classwizard to overload onctlcolor (...) (Wm_ctlcolor message) is somewhat different:

Hbrush cexampledlgdlg: onctlcolor
(CDC * PDC, cwnd * pwnd, uint nctlcolor)
{
Hbrush HBr = cdialog: onctlcolor (PDC, pwnd, nctlcolor );

// Add a judgment statement in the dialog box
If (nctlcolor = ctlcolor_dlg)
Return m_brush; // Add a green brush
Return HBr;
}

Compile and run.

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.