MFC工具栏增加EditBox和Button

柔情痞子 提交于 2020-08-10 17:00:56

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()
{
	
}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!