http://hi.baidu.com/zll2117/blog/item/80792e0fe5ce3ad87bcbe1c9.html 如何在CMFCToolBar工具栏中加入组合框等控件,且先看在线MSDN上怎么说的: To add a combo box button to a toolbar, follow these steps: 1. Reserve a dummy resource ID for the button in the parent toolbar resource. 2. Construct a CMFCToolBarComboBoxButton object. 3. In the message handler that processes the AFX_WM_RESETTOOLBAR message, replace the dummy button with the new combo box button by using CMFCToolBar::ReplaceButton. 具体过程如下: 1.在工具栏资源编辑器中加入id为IDR_COM的空白工具栏, 2.在头文件中定义组合框 CMFCToolBarComboBoxButton* m_ComboButton; 3.BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)中添加消息响应 ON_REGISTERED_MESSAGE(AFX_WM_RESETTOOLBAR, OnToolbarReset) 在头文件中声明消息函数: afx_msg LRESULT OnToolbarReset(WPARAM,LPARAM); 在CMainFram中定义处理函数: LRESULT CMainFrame::OnToolbarReset(WPARAM wp,LPARAM lp) m_ComboButton->EnableWindow(true); 2、添加组合框的事件消息响应函数 消息映射: ON_COMMAND(IDR_COM, &CMainFrame::OnClickComboBox) 消息声明: afx_msg void OnSelChangeClick(); 消息处理函数: void CMainFrame::OnSelChangeClick() void CMainFrame::OnClickComboBox() } (注意:一定要GetByCmd;OnClickComboBox没有做任何处理,但是如果去掉的话,组合框将编程灰色,无法使用)。 注:更新工具栏: 1.工具栏的右侧向下的小箭头->添加或删除按钮->标准->重置工具栏 2.运行regedit打开注册表->HKEY_CURRENT_USER->Software->工程名,找到工程名将其从注册表中删之。 |