1. 在资源视图中增加EditBox, Button控件,ID分别为ID_EDIT_SEED, ID_BTN_SEED
2. 在CMainFrame中增加成员变量
CMFCToolBarEditBoxButton *m_editSeed;
CMFCToolBarButton *m_btnSeed;
3. 在CMainFrame::OnCreate中创建控件
m_editSeed = new CMFCToolBarEditBoxButton(ID_EDIT_SEED, GetCmdMgr()->GetCmdImage(ID_EDIT_SEED, FALSE));
m_editSeed->EnableWindow(true);
m_editSeed->SetContents("0");
//m_editSeed->CanBeStretched();
//m_editSeed->HaveHotBorder();
//m_editSeed->SetFlatMode();
//m_editSeed->OnSize(65);
m_btnSeed = new CMFCToolBarButton(ID_BTN_SEED, GetCmdMgr()->GetCmdImage(ID_BTN_SEED, FALSE), "SEED");
m_btnSeed->EnableWindow(true);
m_btnSeed->m_bText = true;
m_btnSeed->m_strText = "NUM";
4. 增加工具栏控件替换函数
afx_msg LRESULT OnToolbarReset(WPARAM, LPARAM);
ON_REGISTERED_MESSAGE(AFX_WM_RESETTOOLBAR, OnToolbarReset)
LRESULT CMainFrame::OnToolbarReset(WPARAM wp, LPARAM lp)
{
m_wndToolBar.ReplaceButton(ID_EDIT_SEED, *m_editSeed);
m_wndToolBar.ReplaceButton(ID_BTN_SEED, *m_btnSeed);
return 0;
}
5. 增加控件事件函数,否则控件没有enable
afx_msg void OnUpdateEditSeed(CCmdUI *pCmdUI);
afx_msg void OnBnClickedButtonSeed();
ON_UPDATE_COMMAND_UI(ID_EDIT_SEED, &CMainFrame::OnUpdateEditSeed)
ON_BN_CLICKED(ID_BTN_SEED, &CMainFrame::OnBnClickedButtonSeed)
void CMainFrame::OnUpdateEditSeed(CCmdUI *pCmdUI)
{
int index = m_wndToolBar.CommandToIndex(ID_EDIT_SEED);
CMFCToolBarEditBoxButton* editSeed = (CMFCToolBarEditBoxButton*)m_wndToolBar.GetButton(index);
editSeed->EnableWindow(TRUE);
}
void CMainFrame::OnBnClickedButtonSeed()
{
}
来源:oschina
链接:https://my.oschina.net/u/4367225/blog/4403290