Add public to the DLG header file:
Cbrush m_bkbrush;
Afx_msg hbrush onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor );
// In oninitdialog ()
Create a yellow background brush
M_bkbrush.createsolidbrush (RGB (255,180,100 ));
Set dialog box transparency
: Setwindowlong (m_hwnd, gwl_exstyle, getwindowlong (m_hwnd, gwl_exstyle) | ws_ex_layered );
: Setlayeredwindowattributes (m_hwnd, 0,200, lwa_alpha); // 120 is the transparency in the range of 0 ~ 255
Edit the onctlcolor Function
Hbrush c changes the background color and transparency of the dialog box. DLG: onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor)
{
Hbrush HBr = cdialogex: onctlcolor (PDC, pwnd, nctlcolor );
If (nctlcolor = ctlcolor_dlg) // determines whether the dialog box is displayed.
{
Return m_bkbrush; // return the background brush you just created
}
// Todo: if the default paint brush is not required, another paint brush is returned.
Return HBr;
}
To add a background, in the else in the onpaint Function
The method for adding bitmap is mentioned in the previous blog.
// Cdialogex: onpaint (); // comment out when adding a background
//// // Add a background
Cpaintdc DC (this );
Crect rect;
Getclientrect (& rect );
CDC dcmem;
Dcmem. createcompatibledc (& DC );
Cbitmap BMP background;
BMP background. loadbitmap (idb_bitmap1 );
// Idb_bitmap1 is the ID of your own Graph
Bitmap bitmap;
BMP background. getbitmap (& Bitmap );
Cbitmap * pbmpold = dcmem. SelectObject (& BMP background );
DC. stretchblt (0, 0, rect. Width (), rect. Height (), & dcmem, 0, 0,
Bitmap. bmwidth, bitmap. bmheight, srccopy );
Vs2012 make the dialog box transparent and change the background color or image background of the dialog box