Partager via


Creating a CToolBarCtrl Object

CToolBarCtrl objects contain several internal data structures — a list of button image bitmaps, a list of button label strings, and a list of TBBUTTON structures — that associate an image and/or string with the position, style, state, and command ID of the button. Each of the elements of these data structures is referred to by a zero-based index. Before you can use a CToolBarCtrl object, you must set up these data structures. For a list of the data structures, see Toolbar Controls in the Windows SDK. The list of strings can only be used for button labels; you cannot retrieve strings from the toolbar.

To use a CToolBarCtrl object, you will typically follow these steps:

To use a CToolBarCtrl object

  1. Construct the CToolBarCtrl object.

  2. Call Create to create the Windows toolbar common control and attach it to the CToolBarCtrl object. If you want bitmap images for buttons, add the button bitmaps to the toolbar by calling AddBitmap. If you want string labels for buttons, add the strings to the toolbar by calling AddString and/or AddStrings. After calling AddString and/or AddStrings, you should call AutoSize in order to get the string or strings to appear.

  3. Add button structures to the toolbar by calling AddButtons.

  4. If you want tool tips, handle TTN_NEEDTEXT messages in the toolbar's owner window as described in Handling Tool Tip Notifications.

  5. If you want your user to be able to customize the toolbar, handle customization notification messages in the owner window as described in Handling Customization Notifications.

See Also

Reference

Using CToolBarCtrl

Concepts

Controls (MFC)