Toolbar Messages and Member Functions

Table 1-4 lists the messages sent to toolbars and the member functions MFC provides for the CToolBarCtrl class. For details about each message, its parameters, and possible return values, refer to the Win32 SDK documentation.

Message Member Function Description
TB_ADDBITMAP AddBitmap Adds a new bitmap to the list of bitmaps available for a toolbar.
TB_ADDBUTTONS AddButtons Adds one or more buttons to a toolbar.
TB_ADDSTRING AddString Adds a new string to the list of strings available for a toolbar.
TB_AUTOSIZE AutoSize Forces a toolbar to be resized. An application sends this message when it changes a toolbar's size (for example, by setting the button size or adding strings).
TB_BUTTONCOUNT ButtonCount Retrieves a count of the buttons currently on a toolbar.
TB_BUTTONSTRUCTSIZE SetButtonStructSize Specifies the TBBUTTON structure's size, which Windows uses to determine which version of COMMCTRL.DLL is in use. If an application uses CreateWindow to create the toolbar, it must send this message before adding any buttons. The CreateToolbarEx function automatically sends this message, and the size of the TBBUTTON structure is a parameter to CreateToolbarEx.

Table 1-4. (continued)

Toolbar messages and member functions.

Message Member Function Description
TB_CHANGEBITMAP   Changes the bitmap for a button.
TB_CHECKBUTTON CheckButton Checks or unchecks a given button. (When a button is checked, it appears “pressed.”)
TB_COMMANDTOINDEX CommandToIndex Retrieves the zero-based index for the button associated with the specified command identifier.
TB_CUSTOMIZE Customize Displays the Customize Toolbar dialog box.
TB_DELETEBUTTON DeleteButton Deletes a button from a toolbar.
TB_ENABLEBUTTON EnableButton Enables or disables the specified button. When a button has been enabled, it can be checked (“pressed”).
TB_GETBITMAP   Retrieves the index of the bitmap associated with a toolbar button.
  GetBitmapFlags Returns TBBF_LARGE if the display can support large toolbar bitmaps.
TB_GETBUTTON GetButton Retrieves information about the given button.
TB_GETBUTTONTEXT   Retrieves the text of a button.
TB_GETITEMRECT GetItemRect Retrieves the bounding rectangle of a button on a toolbar (unless the button's state is set to TBSTATE_HIDDEN).
TB_GETROWS GetRows Retrieves the number of rows of toolbar buttons.
TB_GETSTATE GetState Retrieves information about the state of a button, such as whether it is enabled or checked.
TB_GETTOOLTIPS GetToolTips Retrieves the handle to a ToolTip control associated with a toolbar.
TB_HIDEBUTTON HideButton Hides or shows a specified button.
TB_INDETERMINATE Indeterminate Sets or clears the indeterminate state of the specified button.
TB_INSERTBUTTON InsertButton Inserts a button in the specified location on a toolbar.
TB_ISBUTTONCHECKED IsButtonChecked Determines whether the given button is checked.
TB_ISBUTTONENABLED IsButtonEnabled Determines whether the given button is enabled.
TB_ISBUTTONHIDDEN IsButtonHidden Determines whether the given button is hidden.
TB_ISBUTTON- INDETERMINATE IsButton- Indeterminate Determines whether the given button is indeterminate.
TB_ISBUTTONPRESSED IsButtonPressed Determines whether the given button is “pressed.”
TB_PRESSBUTTON PressButton “Presses” or “releases” the given button.
TB_SAVERESTORE SaveState or Saves or restores the state of a RestoreStatetoolbar.
TB_SETBITMAPSIZE SetBitmapSize Sets the size of the bitmapped images to be added to a toolbar. The size can be set only before you add any bitmaps to the toolbar. If an application does not explicitly set the bitmap size, the size defaults to 16-by-16 pixels.
TB_SETBUTTONSIZE SetButtonSize Sets the size of the buttons to be added to a toolbar. You can set the button size only before you add any buttons to the toolbar. If an application does not explicitly set the button size, the size defaults to 24-by-22 pixels.
TB_SETCMDID SetCmdID Sets the command ID of a button.
  SetOwner Sets the owner window of a toolbar.
TB_SETPARENT   Sets the parent window of a toolbar.
TB_SETROWS SetRows Sets the number of rows of buttons in a toolbar.
TB_SETSTATE SetState Sets the state for the given button.
TB_SETTOOLTIPS SetToolTips Sets the handle to a ToolTip control associated with a toolbar.