Discussion:
CToolBar button with text.
(too old to reply)
armistad
2008-02-17 07:25:51 UTC
Permalink
In my CMainFrame::OnCreate(...), I have:

...
TBBUTTONINFO buttonInfo;

buttonInfo.cbSize = sizeof(TBBUTTONINFO);
buttonInfo.dwMask = TBIF_TEXT | TBIF_STYLE;
buttonInfo.fsStyle = TBSTYLE_AUTOSIZE;
buttonInfo.pszText =
m_csButtonText.GetBuffer(m_csButtonText.GetLength());

CToolBarCtrl& toolBarCtrl = m_wndToolBar.GetToolBarCtrl();
toolBarCtrl.SetButtonInfo(ID_BTN_CLOSE, &buttonInfo);

(after the m_wndToolBar member is created) which I was hoping would
set text on one of my buttons, but it doesn't appear to do anything. I
would appreciate if someone could point out what more I would need to
do so that I can get text to display on one of my buttons (I want the
other buttons to retain their image and size).
Ajay Kalra
2008-02-17 13:24:30 UTC
Permalink
This article by Paul Dilascia shows how to do this:

http://www.microsoft.com/msj/0199/c/c0199.aspx

Here he replaces a menu by a toolbar by adding buttons with text. Here is
the code which does what you want:

for (UINT i=0; i < n; i++) {
TBBUTTON tbb;
tbb.idCommand = ::GetMenuItemID(hmenu,i);
tbb.iString = // item name, see below
tbb.fsState = TBSTATE_ENABLED;
tbb.fsStyle = TBSTYLE_AUTOSIZE;
tbb.iBitmap = -1; // no icon
tbb.idCommand = i;
VERIFY(AddButtons(1, &tbb));
}

Hopefully it will be of some help.

---
Ajay
Post by armistad
...
TBBUTTONINFO buttonInfo;
buttonInfo.cbSize = sizeof(TBBUTTONINFO);
buttonInfo.dwMask = TBIF_TEXT | TBIF_STYLE;
buttonInfo.fsStyle = TBSTYLE_AUTOSIZE;
buttonInfo.pszText =
m_csButtonText.GetBuffer(m_csButtonText.GetLength());
CToolBarCtrl& toolBarCtrl = m_wndToolBar.GetToolBarCtrl();
toolBarCtrl.SetButtonInfo(ID_BTN_CLOSE, &buttonInfo);
(after the m_wndToolBar member is created) which I was hoping would
set text on one of my buttons, but it doesn't appear to do anything. I
would appreciate if someone could point out what more I would need to
do so that I can get text to display on one of my buttons (I want the
other buttons to retain their image and size).
Loading...