开发者

MFC: hiding a toolbar button

开发者 https://www.devze.com 2023-01-16 08:44 出处:网络
I\'m currently disable certain buttons by handling ON_UPDATE_COMMAND_UI and calling ->Enable( TRUE / FALSE ).

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 );
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号