Putting a pleasing bitmap (or a GradientFill wipe) in a dialog's background is a common request (should be in the FAQ). The bottom line is that there is no way to do this reliably using composition tricks, screen scraping, or layers. The problem is that controls like to scribble on their backgrounds willy-nilly and there is just no reliable way to handle all scenarios and all types of controls (with XP themes, without XP themes, with Aero, without Aero, with driver/desktop bitmaps, without dk bitmaps, etc).
The only reliable method I know of is to handle WM_CTLCOLORxxx messages (MFC WM_ON_CTLCOLOR). In your handler return the background brush. The trick is to observe that a brush is no longer limited to 8x8 pixels; in Windows 2000 or later it can be as large as memory allows. Use CreatePatternBrush to convert your bitmap into a brush and pass it via WM_CTLCOLORxxx. As a bonus you get free tiling if the dialog is resized for large DPI (same as a web page using <BODY BACKGROUND="MyBItmap.gif">)
The second trick is to align the brush so that the origin (0,0) of the brush on the dialog is correctly offset for the position of the control in the client area. Adjust the brush origin using SetBrushOrg. This is an attribute of the DC (not of the brush), so apply it in your WM_CTLCOLORxxx handler. As a bonus this auto-adjusts the background if the control(s) are moved or resized.
The result is that all of the backgrounds of the controls overlay the main dialog bitmap in the spots and the whole thing looks like a beautiful background bitmap.
You still have to handle some edge cases. Notably you need to call pDc->SetBkMode(TRANSPARENT)
I've asked around about this a lot, and tried a lot of techniques and hacks (some pretty nasty), but all of my attempts failed except the one I just described.
Good luck!





by: itsmeandnobodyelsePosted on 2009-02-03 at 06:13:28ID: 23537226
Where did you do the painting? If I remember rightly you have to put it into the YourDialog::OnPaint() so that your drawings are not overwritten by the normal refresh.
For the buttons, you need to make owner drawn buttons and provide the DrawItem callback handler. You also need a member of the button (CButton) in your dialog and change the CButton with your CImageButton in the class header. That way the button was sub-classed and can receive messages via message map.