Use the CBitmapButton class to create pushbutton controls labeled with bitmapped images instead of text. CBitmapButton objects contain up to four bitmaps, which contain images for the different states a button can assume: up (or normal), down (or selected), focused, and disabled. Only the first bitmap is required; the others are optional.
Bitmap-button images include the border around the image as well as the image itself. The border typically plays a part in showing the state of the button. For example, the bitmap for the focused state usually is like the one for the up state but with a dashed rectangle inset from the border or a thick solid line at the border. The bitmap for the disabled state usually resembles the one for the up state but has lower contrast (like a dimmed or grayed menu selection).
These bitmaps can be of any size, but all are treated as if they were the same size as the bitmap for the up state.
Various applications demand different combinations of bitmap images:
Up | Down | Focused | Disabled | Application |
× | Bitmap | |||
× | × | Button without WS_TABSTOP style | ||
× | × | × | × | Dialog button with all states |
× | × | × | Dialog button with WS_TABSTOP style |
When creating a bitmap-button control, set the BS_OWNERDRAW style to specify that the button is owner-drawn. This causes Windows to send the WM_MEASUREITEM and WM_DRAWITEM messages for the button; the framework handles these messages and manages the appearance of the button for you.
To create a bitmap-button control in a window’s client area, follow these steps:
To include a bitmap-button control in a dialog box, follow these steps:
If you want to handle Windows notification messages, such as BN_CLICKED, sent by a bitmap-button control to its parent (usually a class derived from CDialog), add to the CDialog-derived object a message-map entry and message-handler member function for each message. The notifications sent by a CBitmapButton object are the same as those sent by a CButton object.
The class CToolBar takes a different approach to bitmap buttons.
For more information on CBitmapButton, see Control Topics in Visual C++ Programmer's Guide.
#include <afxext.h>
Class Members | Base Class | Hierarchy Chart
Sample MFC Sample CTRLTEST