/************************************************************ Description: Set the background color or background image for the dialog box in vc++6.0 * Note: Test Code dialog box program name: BJ * Principle: Add code to OnPaint () ***********************************************************///Note: The code takes effect void after removing the comment symbol corresponding TO/* * * * Cbjdlg::onpaint () {if (Isiconic ()) {CPAINTDC DC (this),//device context for painting SendMessage (W M_iconerasebkgnd, (WPARAM) DC. GETSAFEHDC (), 0); Center icon in client rectangle 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 {//cdialog::onpaint ();//This line is the original code/* Set Background color: CRect RC; GetClientRect (&RC);//Get client Area CPaintDC DC (this); dc. Fillsolidrect (&RC, RGB (0,160,0)); Fill customer Area color cdialog::onpaint (); */* Set background Image://cdialog::onpaint ();//To disallow this call CPaintDC DC (this); CRect rect; GetClientRect (&rect); CDC Dcmem; Dcmem.createcompatibledc (&DC); CBitmap Bmpbackground; Bmpbackground.loadbitmap (IDB_BITMAP3); IDB_BITMAP3 is a bitmap resource BITMAP BITMAP; Bmpbackground.getbitmap (&BITMAP); CBitmap *pbmpold=dcmem.selectobject (&bmpbackground); dc. StretchBlt (0,0,rect. Width (), Rect. Height (), &dcmem,0,0, bitmap.bmwidth,bitmap.bmheight,srccopy); */ } }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Set the background color or background image for the dialog box in vc++6.0