MFC基于单文档中,怎么加工具条?要具体些

不好意思,是基于对话框,
2024-12-04 17:09:33
推荐回答(2个)
回答1:

MFC但文档是有工具栏的,当然你也可以手动添加:
CToolBarCtrl m_toobar;
m_imagelist.Create(32,32,ILC_COLOR32 |ILC_MASK,0,0);
m_imagelist.Add(::AfxGetApp()->LoadIcon(IDI_ICON1));
m_imagelist.Add(::AfxGetApp()->LoadIcon(IDI_ICON2));
m_imagelist.Add(::AfxGetApp()->LoadIcon(IDI_ICON3));
m_imagelist.Add(::AfxGetApp()->LoadIcon(IDI_ICON4));
m_imagelist.Add(::AfxGetApp()->LoadIcon(IDI_ICON5));

m_toolbar.Create(WS_CHILD |WS_VISIBLE,CRect(0,0,0,0),this,0);
m_toolbar.SetImageList(&m_imagelist);

TBBUTTON tbButton[5] = {0};
for (int i = 0; i< 5; i++)
{
tbButton[i].dwData = NULL;
tbButton[i].fsState = TBSTATE_ENABLED;
tbButton[i].fsStyle = (BYTE)TBSTYLE_FLAT;
tbButton[i].iBitmap = i;
}

tbButton[0].idCommand = ID_101;
tbButton[1].idCommand = ID_102;
tbButton[2].idCommand = ID_103;
tbButton[3].idCommand = ID_104;
tbButton[4].idCommand =ID_105;
m_toolbar.AddButtons(5,tbButton);
m_toolbar.AutoSize();
m_toolbar.SetStyle(CCS_TOP|TBSTYLE_FLAT);

回答2:

创建工程的时候,默认就有工具条的。
如果你还要加的话,
资源编辑器中编辑,在oncreate函数中,添加代码挂接资源即可。