MFC: hiding a toolbar button
I'm currently disable certain buttons by handling ON_UPDATE_COMMAND_UI
and calling ->Enable( TRUE / FALSE )
.
What would be the best way to completely hide the button instead?
I've tried using HideButton
and that makes the button imag开发者_如何学运维e invisible, but it still takes up space so there is a blank area between visible buttons.
Thanks.
If You want to hide the toolbar specific button use this code.
m_wndToolBar.GetToolBarCtrl().HideButton(ID_TOOLBAR1,TRUE);
here m_wndToolBar is a ToolBar Object. ID_TOOLBAR1 is a which button you want to hide that button control.
Try to call toolbar.SendMessage(TB_AUTOSIZE);
after the HideButton();
I would recommend to show/hide those buttons elsewhere than OnUpdateCommandUI because these occur too often and may cause flicker. Although not MFC I have a similar code that works:
void HideToolbarButton(HWND toolbar, UINT command_id)
{
TBBUTTONINFO tbinfo;
tbinfo.cbSize = sizeof(tbinfo);
tbinfo.dwMask = TBIF_STATE;
tbinfo.state = TBSTATE_HIDDEN;
SendMessage(toolbar, TB_SETBUTTONINFO, command_id, (LPARAM)&tbinfo );
}
精彩评论