INFO: Sample Draws a Bitmap in a Foundation Class Dialog BoxLast reviewed: July 18, 1997Article ID: Q107765 |
The information in this article applies to:
This is the 16-bit version of this sample. There is an equivalent 32-bit sample available under the name BDLG32.
SUMMARYIn a Microsoft Foundation Class (MFC) Libraries application for Windows, it is occasionally useful to be able to display a bitmap larger than a normal icon in a dialog box. You cannot automatically add a bitmap to a dialog box template using a dialog box editor or App Studio without using a third-party custom control, such as a VBX picture control. To have a bitmap larger or smaller than an icon display on a dialog box without such a control, the bitmap must be painted on the dialog box at run time using some other method. Four possible methods for doing this are:
MORE INFORMATIONThe following four methods, implemented in the BDLG sample, demonstrate some possible ways to display a bitmap in a dialog box using the Microsoft Foundation Classes.
Method 1: BitBlt() in OnDraw()The first method uses a simple BitBlt(), when the dialog box receives a WM_PAINT message, to paint a bitmap in a hard-coded location on a dialog box. This method demonstrates the following:
Method 2: BitBlt() or StretchBlt() in "Static" Frame ControlThe second method uses StretchBlt() and, using techniques similar to those in the "Paint" dialog box, draws the bitmap in the client area of a "static" picture frame control. The BDLG sample uses Class Wizard to associate a CStatic member variable with the static control using its "Edit Variables" capability. Besides the above techniques, it demonstrates calculating the client area of a child control. Note that subclassing the CStatic member (after using Class Wizard to associate the control, just change the type in the header from CStatic to a class you've derived from CStatic) would allow you to have the subclassed control paint a bitmap in its client area when it itself received a WM_PAINT.
Method 3: BitBlt() or StretchBlt() in OnEraseBkgnd()The third method StretchBlt's the bitmap onto the background of a dialog box in the dialog box's WM_ERASEBKGND handler, OnEraseBkgnd(). It also demonstrates handling WM_CTLCOLOR messages and returning background brushes from that handler (transparent in this case).
Method 4: CBitmapButton as Picture ControlThe fourth and last method uses a CBitmapButton class to CBitmapButton::AutoLoad() a bitmap into a disabled owner-draw button on a dialog box. It is probably the simplest method of the four, although it does not allow for much flexibility or changing of what is being painted to reflect changes in the dialog box. Please note the following when creating your resources for using a CBitmapButton class. When you add the button to your dialog box template, which you will later be associating with a CBitmapButton, the ID is relatively unimportant, but the button must be set as owner-draw and the caption text will be used to load your bitmap. If your button caption text is "BITB", you should create your bitmap and give it an ID of "BITBU". Your bitmap ID MUST have the double quotation marks or it will be saved as just a numeric ID and fail to load when you use CBitmapButton::AutoLoad(). See the documentation for CBitmapButton for more information.
|
Additional query words: StretchBlt BDLG32
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |