如何使用MFC创建工具栏? [英] How to create a toolbar using MFC?
本文介绍了如何使用MFC创建工具栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用MFC创建工具栏?
:confused:
How to create a toolbar using MFC?
:confused:
推荐答案
以下步骤适用于VS 2008中"MFC扩展包"之前的SDI或MDI项目.之后,还有更多选择. br/>
1.在资源视图中创建工具栏资源,为其提供一个ID,例如ID_TOOLBAR
2.添加您想要的按钮.
3.如果要在主框架窗口或子框架窗口中使用工具栏,请创建CToolbar类的实例,例如CMainFrame或CChildFrame类中的CToolBar m_toolbar;
.
4.在框架OnCreate成员(如
)中创建工具栏窗口
The following steps are for a SDI or MDI project prior to the "MFC Extension Pack" in VS 2008. After that there are more options.
1. Create a Toolbar resource in the Resource View, give it an ID, e.g. ID_TOOLBAR
2. Add the buttons you''d like.
3. If you want the toolbar in your main frame window or in a child frame window, create an instance of a CToolbar class, e.g.CToolBar m_toolbar;
in CMainFrame or CChildFrame class.
4. Create the toolbar window in the frames OnCreate member like
if (!m_toolbar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_toolbar.LoadToolBar(IDR_TOOLBAR))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
m_toolbar.EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_toolbar);
如果要将其放置在其他地方(例如在对话框中),则必须采用另一种方式.要做更多的工作,但易于管理.您可能想看看此 [文档 [位于其他位置中间的工具栏 [
If you want it placed somewhere else, like in a dialog, you have to do it another way. A bit more work but manageable. You might wanna have a look at this[^].
Also check the documentation[^]
The excellent article A Toolbar in the middle of elsewhere[^] describes very well how to add a toolbar to a dialog.
这篇关于如何使用MFC创建工具栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文