CToolbar的按钮启用与禁用(enable/disable)

当前我使用到的有效的方式是:

通过发消息的方式

 

禁用某个Toolbar中的按钮,例如ID为 IDC_BUTTON_ADD,Toolbar对像为m_wndToolBar,设置fsState为TBSTATE_INDETERMINATE

 TBBUTTONINFO tbinfo;
 tbinfo.cbSize = sizeof(TBBUTTONINFO);
 tbinfo.dwMask = TBIF_STATE;
 <span style="color:#000099;"><strong>tbinfo.fsState = TBSTATE_INDETERMINATE;
</strong></span> ::SendMessage(<strong><span style="color:#000099;">m_wndToolBar.GetSafeHwnd()</span></strong>, TB_SETBUTTONINFO,<strong><span style="color:#000099;">(WPARAM)IDC_BUTTON_ADD</span></strong>,(LPARAM)&tbinfo);

启用某个Toolar按钮,设置fsState为TBSTATE_ENABLED 

 TBBUTTONINFO tbinfo;
 tbinfo.cbSize = sizeof(TBBUTTONINFO);
 tbinfo.dwMask = TBIF_STATE;
 <span style="color:#000099;"><strong>tbinfo.fsState = TBSTATE_ENABLED;
</strong></span> ::SendMessage(<strong><span style="color:#000099;">m_wndToolBar.GetSafeHwnd()</span></strong>, TB_SETBUTTONINFO,<strong><span style="color:#000099;">(WPARAM)IDC_BUTTON_ADD</span></strong>,(LPARAM)&tbinfo);

 

参见MSDN中,fsState的说明,还可以设置其它的状态,例如 HIDDEN

TBSTATE_CHECKED
The button has the TBSTYLE_CHECK style and is being clicked.

TBSTATE_ELLIPSES
Version 4.70. The button's text is cut off and an ellipsis is displayed.

TBSTATE_ENABLED
The button accepts user input. A button that doesn't have this state is grayed.

TBSTATE_HIDDEN
The button is not visible and cannot receive user input.

TBSTATE_INDETERMINATE
The button is grayed.

TBSTATE_MARKED
Version 4.71. The button is marked. The interpretation of a marked item is dependent upon the application.

TBSTATE_PRESSED
The button is being clicked.

TBSTATE_WRAP
The button is followed by a line break. The button must also have the TBSTATE_ENABLED state.

 

Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu  转载请标明来源 

 

你可能感兴趣的:(Toolbar按钮状态)