How to Dynamically Label Toolbar Buttons

How to Dynamically Label Toolbar Buttons

You can assign text to an existing button by using the TB_SETBUTTONINFO message.

What you need to know



  • C/C++
  • Windows User Interface Programming


Dynamically Label a Toolbar Button

The following example demonstrates how to change the text of the third button in the previous examples from Save to Save As.

LRESULT RelabelButton(HWND hWndToolbar)
    tbInfo.cbSize  = sizeof(TBBUTTONINFO);
    tbInfo.dwMask  = TBIF_TEXT;
    tbInfo.pszText = L"Save As";
    return SendMessage(hWndToolbar, TB_SETBUTTONINFO, (WPARAM)IDM_SAVE, (LPARAM)&tbInfo);


Changing a button's text by using TB_SETBUTTONINFO does not affect the string that is assigned to that button in the internal string list.

If you add a toolbar button string to the internal text list, you cannot retrieve the index of that string by calling TBN_GETBUTTONINFO—you must use the TB_GETBUTTON message instead.

Related topics

Using Toolbar Controls
Windows common controls demo (CppWindowsCommonControls)



© 2016 Microsoft