Does the MFC program add to the dialog box? Background Image

Source: Internet
Author: User

1. Insert a bitmap resource image. If the Resource Name Is idc_bitmap1

2. In cxxxdialog: onpaint (), implement:

Void cmydialogdlg: onpaint () {If (isiconic () {cpaintdc DC (this); // The device context sendmessage (wm_iconerasebkgnd, reinterpret_cast <wparam> (DC. getsafehdc (), 0); // center the icon in the rectangle of the workspace int cxicon = getsystemmetrics (sm_cxicon); int cyicon = getsystemmetrics (sm_cyicon); crect rect; getclientrect (& rect); int x = (rect. width ()-cxicon + 1)/2; int y = (rect. height ()-cyicon + 1)/2; // draw the icon DC. drawicon (x, y, M_hicon);} else {// Add to the window? Background // cpaintdc DC (this); crect RC; getclientrect (& rc); CDC dcmem; dcmem. createcompatibledc (& DC); cbitmap BMP background; BMP background. loadbitmap (idb_bitmap1); Bitmap bitmap; BMP background. getbitmap (& Bitmap); cbitmap * pbmppri = dcmem. selectObject (& BMP background); DC. stretchblt (0, 0, RC. width (), RC. height (), & dcmem, 0, bitmap. bmwidth, bitmap. bmheight, srccopy );}}

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: 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.