Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mfc 工具栏按钮启用/禁用问题_Mfc - Fatal编程技术网

Mfc 工具栏按钮启用/禁用问题

Mfc 工具栏按钮启用/禁用问题,mfc,Mfc,我创建了基于MFC的应用程序Visual Studio 2010 Professional Edition,在该版本中,我创建了自己的类(CMToolBar),该类派生自CToolbar,我正在基于对话框的应用程序中使用CMToolBar类对象 在其创建功能中,默认情况下,我尝试禁用几个按钮的状态,但我使用的代码如下:- GetToolBarCtrl().EnableButton(ID_ONE,false); GetToolBarCtrl().SetState(ID_TWO,TBSTATE_

我创建了基于MFC的应用程序Visual Studio 2010 Professional Edition,在该版本中,我创建了自己的类(CMToolBar),该类派生自CToolbar,我正在基于对话框的应用程序中使用CMToolBar类对象

在其创建功能中,默认情况下,我尝试禁用几个按钮的状态,但我使用的代码如下:-

 GetToolBarCtrl().EnableButton(ID_ONE,false);
GetToolBarCtrl().SetState(ID_TWO,TBSTATE_PRESSED); //  where ID_TWO is the id of second button

在这两种情况下,它都将禁用按钮,包括图标未显示,图标图像应灰显

第二,如果用户单击第二个工具栏按钮,我将调用如下代码:-

 GetToolBarCtrl().EnableButton(ID_ONE,false);
GetToolBarCtrl().SetState(ID_TWO,TBSTATE_PRESSED); //  where ID_TWO is the id of second button

根据上述功能,按钮应处于按下状态,但在我的情况下,它也不会改变按钮的状态。

通常您不会像MFC那样直接修改工具栏按钮。相反,您应该为工具栏按钮使用的菜单命令id添加onUpdate命令消息处理程序。在该处理程序中,您可以对作为参数获取的pCmdUI对象调用Enable()和SetCheck()

以下是MS文档中的一个起点:


在“更新”命令上,在“文档/视图”应用程序中,该命令不适用于基于对话框的应用程序。有人能告诉我在基于对话框的应用程序中禁用CToolbar中特定按钮的方法吗?我可以通过加载两个图像列表active和disable image set来解决这个问题