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