MFC dialog box modifies background color or add background picture, control background, and font color modification

Source: Internet
Author: User

MFC dialog box to modify the background color:

In Cxxxdlg::oninitdialog (), add the following:
Cdialogex::setbackgroundcolor (RGB (155,170,190));
The effect is as follows:

MFC dialog box to add a background image:

In Cxxxdlg::oninitdialog (), add the following:

Cdialogex::setbackgroundimage (IDB_BITMAP1);

The effect is as follows:

MFC controls are consistent with the background: static controls

Add the OnCtlColor () function to the dialog box:
Effect:

You can see that only text boxes with the static ID are consistent with the background. Button controls
Insert the code:

UINT id = pwnd->getdlgctrlid ();
    if (id = = IDC_RADIO1 | | id = = IDC_CHECK1)
    {
        pdc->setbkmode (TRANSPARENT);

        CRect RC;
        Pwnd->getwindowrect (&RC);
        ScreenToClient (&RC);

        cdc* DC = GetDC ();

        Pdc->bitblt (0,0,RC. Width (), RC. Height (), dc,rc.left,rc.top,srccopy);  Draw the parent window background picture first to the button

        ReleaseDC (DC);

        HBR = (hbrush):: Getstockobject (Null_brush);
    }

Effect:
To modify the control font color:
Add code:

if (nCtlColor = = ctlcolor_static)
    {
        Pdc->settextcolor ((+ 0));
    }

Note: This experience is from an instance code on CSDN download, easy to understand and practical, O (∩_∩) O.

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.