MFC CToolBar 帮助/链接?
我找不到一个简单的 CToolBar 示例。
我在资源编辑器中创建了一个工具栏,并在我的代码中加载了该工具栏,如下所示:
toolbar = new CToolBar;
toolbar->CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP, CRect(0, 0, 0, 0), AFX_IDW_TOOLBAR);
toolbar->LoadToolBar(IDR_TOOLBAR);
我还在消息映射中处理了 WM_LBUTTONDOWN。
现在,所有按钮都变灰了..我是否错过了某个步骤?
感谢您的任何帮助/链接=)
I can't find a simple CToolBar example of all things..
I created a toolbar in the resource editor, and loaded the toolbar in my code like this:
toolbar = new CToolBar;
toolbar->CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP, CRect(0, 0, 0, 0), AFX_IDW_TOOLBAR);
toolbar->LoadToolBar(IDR_TOOLBAR);
I have also handled WM_LBUTTONDOWN in the message map.
Now, all the buttons are grayed out.. am I missing a step somewhere?
Thanks for any help/links =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,MFC 中工具栏中的按钮是禁用的。对于应与命令 ID 关联的每个按钮,您需要有一个
ON_UPDATE_COMMAND_UI
宏。只要应用程序空闲,就会调用您在此宏中使用的处理函数。该函数可以调用CCmdUI<的成员函数/code>
传递给函数的指针,例如
启用
方法。The buttons in a toolbar are disabled in MFC by default. For each button, which should be associated with a command ID, you need to have an
ON_UPDATE_COMMAND_UI
macro in your message map. The handler function you use in this macro will be called whenever the app is idle. This function can call the member functions of theCCmdUI
pointer that is passed to the function, such as theEnable
method.您是否在消息映射中提供了 ON_COMMAND 处理程序?应该看起来像
ON_COMMAND(SOME_BUTTON_ID, OnSomeButton) 其中 SOME_BUTTON_ID 对应于工具栏上的按钮之一。
Have you supplied an ON_COMMAND handler in the message map? Should look something like
ON_COMMAND(SOME_BUTTON_ID, OnSomeButton) where SOME_BUTTON_ID corresponds to one of the buttons on your toolbar.