Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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

Technologies

Prerequisites

  • C/C++
  • Windows User Interface Programming

Instructions

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)
{
    TBBUTTONINFO tbInfo;
    
    tbInfo.cbSize  = sizeof(TBBUTTONINFO);
    tbInfo.dwMask  = TBIF_TEXT;
    tbInfo.pszText = L"Save As";
    
    return SendMessage(hWndToolbar, TB_SETBUTTONINFO, (WPARAM)IDM_SAVE, (LPARAM)&tbInfo);
}


Remarks

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)

 

 

Community Additions

ADD
Show:
© 2015 Microsoft