Adds one or more buttons to a toolbar control.

BOOL AddButtons( 
   int nNumButtons, 
   LPTBBUTTON lpButtons  


Number of buttons to add.


Address of an array of TBBUTTON structures that contains information about the buttons to add. There must be the same number of elements in the array as buttons specified by nNumButtons.

Nonzero if successful; otherwise zero.

The lpButtons pointer points to an array of TBBUTTON structures. Each TBBUTTON structure associates the button being added with the button's style, image and/or string, command ID, state, and user-defined data:

typedef struct _TBBUTTON {

int iBitmap;// zero-based index of button image

int idCommand; // command to be sent when button pressed

BYTE fsState; // button state--see below

BYTE fsStyle; // button style--see below

DWORD dwData; // application-defined value

int iString;// zero-based index of button label string


The members are as follows:


Zero-based index of button image, -1 if no image for this button.


Command identifier associated with the button. This identifier is sent in a WM_COMMAND message when the button is chosen. If the fsStyle member has the TBSTYLE_SEP value, this member must be zero.


Button state flags. It can be a combination of the values listed below:

  • TBSTATE_CHECKED   The button has the TBSTYLE_CHECKED style and is being pressed.

  • TBSTATE_ENABLED   The button accepts user input. A button that does not have this state does not accept user input and is grayed.

  • TBSTATE_HIDDEN   The button is not visible and cannot receive user input.

  • TBSTATE_INDETERMINATE   The button is grayed.

  • TBSTATE_PRESSED   The button is being pressed.

  • TBSTATE_WRAP   A line break follows the button. The button must also have the TBSTATE_ENABLED state.


Button style. It can be a combination of the values listed below:

  • TBSTYLE_BUTTON   Creates a standard push button.

  • TBSTYLE_CHECK   Creates a button that toggles between the pressed and unpressed states each time the user clicks it. The button has a different background color when it is in the pressed state.

  • TBSTYLE_CHECKGROUP   Creates a check button that stays pressed until another button in the group is pressed.

  • TBSTYLE_GROUP   Creates a button that stays pressed until another button in the group is pressed.

  • TBSTYLE_SEP   Creates a separator, providing a small gap between button groups. A button that has this style does not receive user input.


User-defined data.


Zero-based index of the string to use as the button's label, -1 if there is no string for this button.

The image and/or string whose index you provide must have previously been added to the toolbar control's list using AddBitmap, AddString, and/or AddStrings.

Header: afxcmn.h