Export (0) Print
Expand All
5 out of 9 rated this helpful - Rate this topic

CBitmapButton Class 

This topic has been updated for Visual Studio 2005 SP1.

Creates pushbutton controls labeled with bitmapped images instead of text.


class CBitmapButton : public CButton

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

  1. Create one to four bitmap images for the button.

  2. Construct the CBitmapButton object.

  3. Call the Create function to create the Windows button control and attach it to the CBitmapButton object.

  4. Call the LoadBitmaps member function to load the bitmap resources after the bitmap button is constructed.

To include a bitmap-button control in a dialog box

  1. Create one to four bitmap images for the button.

  2. Create a dialog template with an owner-draw button positioned where you want the bitmap button. The size of the button in the template does not matter.

  3. Set the button's caption to a value such as "MYIMAGE" and define a symbol for the button such as IDC_MYIMAGE.

  4. In your application's resource script, give each of the images created for the button an ID constructed by appending one of the letters "U," "D," "F," or "X" (for up, down, focused, and disabled) to the string used for the button caption in step 3. For the button caption "MYIMAGE," for example, the IDs would be "MYIMAGEU," "MYIMAGED," "MYIMAGEF," and "MYIMAGEX." You must specify the ID of your bitmaps within double quotes. Otherwise the resource editor will assign an integer to the resource and MFC will fail when loading the image.

  5. In your application's dialog class (derived from CDialog), add a CBitmapButton member object.

  6. In the CDialog object's OnInitDialog routine, call the CBitmapButton object's AutoLoad function, using as parameters the button's control ID and the CDialog object's this pointer.

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, seeControls.

Header: afxext.h

This section has been updated for Visual Studio 2005 SP1.

Starting in Visual Studio 2005 SP1, this class is supported in Smart Device projects.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.