How does VC/mfc set the background color of the dialog box?

Source: Internet
Author: User

VC/mfc how to set the background color of the dialog box

1.

Overload onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor), that is, wm_ctlcolor message.
---- ① Add a member variable of cbrush to the header file of cexampledlgdlg:
Class cexampledlgdlg: Public cdialog
{...
Protected:
Cbrush m_brush;
...
};
---- ② Add the following to the oninitdialog () function: Code :
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)
{
/*
** No code is required here!
** The downstream code should be commented out.
** Hbrush HBr = cdialog: onctlcolor (PDC, pwnd, nctlcolor );
*/
Return m_brush; // Add a green brush
}

2.

Modify onpaint in the dialog box and add the following code to else:
Cpaintdc DC (this );
Crect rect;
Getclientrect (rect );
DC. fillsolidrect (rect, RGB (0, 0 ));
Cdialog: onpaint ();

3.

Add the code to the initinstance () of. cpp of the application class (APP) in the dialog box:
// Add int nresponse = DLG. domodal ();
Set the background color for the previous RGB image and the font color for the second image.
Setdialogbkcolor (RGB (255, 0,255), RGB (, 0 ));

4.

1. Add member variables in the dialog box class:
Public:
Cbrush m_brushblue;

2. Add the code in oninitdialog () of the dialog box class:
M_brushblue.createsolidbrush (RGB (0, 0, 255 ));

3. Use classwizard to add the onctlcollor () member function to the dialog box class and add the code in it:
If (nctlcolor = ctlcolor_dlg)
Return m_brushblue;

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.