VC + + dialog box (CDialog) Add background image

Source: Internet
Author: User

In the dialog box (CDialog) program, in order to make the program look beautiful, we can add a nice background image for the dialog box, to achieve this goal, you can take advantage of afx_msg BOOLonerasebkgnd (cdc* PDC) this function.

The following is a sample description (the instance can be downloaded in my CSDN resource: http://download.csdn.net/detail/margin1988/8337225):

(1) Find a suitable BMP format background image, put it in the project Res directory, and then in the program's resource view, the picture is imported (assuming that after the import of its ID: IDB_BITMAP1).

(2) Add a function declaration in the. h file of the dialog box:

afx_msg BOOL OnEraseBkgnd (cdc* PDC);

(3) Add its message map macro in the. cpp file of the dialog box:

Begin_message_map (Cpoint22dlg, CDialog) on_wm_erasebkgnd ()//message map Macro End_message_map ()

(4) Implement the function function in the. cpp file of the dialog box:

BOOL Cpoint22dlg::onerasebkgnd (cdc* PDC)//Add background picture {CDIALOG::ONERASEBKGND (PDC) to the dialog box; CBitmap M_bitmap;m_bitmap. LoadBitmap (IDB_BITMAP1); if (!m_bitmap.m_hobject) return true; CRect rect; GetClientRect (&rect); CDC DC;DC. CreateCompatibleDC (PDC); cbitmap* Poldbitmap = DC. SelectObject (&m_bitmap); int BMW, BMH; BITMAP Bmap;m_bitmap. Getbitmap (&bmap); bmw = BMAP.BMWIDTH;BMH = Bmap.bmheight;int xo=0, yo=0;        The/* function copies a bitmap from the source rectangle to the target rectangle and, if necessary, stretches or compresses the image according to the mode currently set by the target device. */pdc->stretchblt (XO, Yo, rect.) Width (), Rect. Height (), &dc,0, 0,BMW,BMH, srccopy);d c. SelectObject (Poldbitmap); return true;}

VC + + dialog box (CDialog) Add background image

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.