1、注意大小可以由自己定
2、绘制好图后,在画图板中拷贝就可以
3、还有更高明的一招,vs2017中,
注意:选择打开外部编辑器,就会在画图中操作,先怎么操作都行!!!!
4、在头文件中加入
//.h
CToolBar m_wndToolBar;
5、在oninitdlg的最后加入,等其他都初始化完成后
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
if(!m_wndToolBar.CreateEx(this))
{
ASSERT(FALSE);
}
m_wndToolBar.LoadToolBar(IDR_TOOLBAR1);
/*
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
*/
CRect rcClientStart;
CRect rcClientNow;
GetClientRect(rcClientStart);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,
AFX_IDW_CONTROLBAR_LAST,
0, reposQuery, rcClientNow);
CPoint ptOffset(rcClientNow.left - rcClientStart.left,
rcClientNow.top - rcClientStart.top);
CRect rcChild;
CWnd* pwndChild = GetWindow(GW_CHILD);
while (pwndChild)
{
pwndChild->GetWindowRect(rcChild);
ScreenToClient(rcChild);
rcChild.OffsetRect(ptOffset);
pwndChild->MoveWindow(rcChild, FALSE);
pwndChild = pwndChild->GetNextWindow();
}
CRect rcWindow;
GetWindowRect(rcWindow);
rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
MoveWindow(rcWindow, FALSE);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,
AFX_IDW_CONTROLBAR_LAST, 0, reposExtra);
return TRUE; // return TRUE unless you set the focus to a control
}
6、处理函数添加的最简单方法,修改个规范的名字
7、MFC向导中添加下处理函数
8、随便测试下
参考了
https://blog.youkuaiyun.com/zgl7903/article/details/7357655
转载于
https://blog.youkuaiyun.com/qq_38149046/article/details/80986917
1、新建MFC工程,找到“资源视图”界面,找不到资源视图的,或者不小心关闭了,可以通过快捷键(cotrl+shift+e),或者在视图->其他窗口中找到资源视图界面。
2、右键添加资源,可以找到以下类型,其中就有Toolbar,点击新建即可。
3、添加的工具条可以修改属性,主要是工具条的ID,方便后面调用。
4、逐个添加工具条里面的各个工具,可以在网上下载、截图。然后在此界面右键粘贴即可。
5、导入图标后,可以通过打开外部编辑器在画图工具下编辑图标。导入的每个图标记得要修改ID属性。
6、经过上面的步骤,图标的导入已经完成了。可以创建工具条
-
if (!m_wndToolBarEdit.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, CRect(1, 1, 1, 1), IDR_TOOLBAR_EDITOR ) ||
-
!m_wndToolBarEdit.LoadToolBar(theApp.m_bHiColorIcons ? IDR_TOOLBAR_EDITOR : IDR_TOOLBAR_EDITOR))
-
{
-
TRACE0("未能创建工具栏\n");
-
return FALSE; // 未能创建
-
}
-
CString strToolBarEditName = _T("编辑工具栏");
-
ASSERT(bNameValid);
-
m_wndToolBarEdit.SetWindowText(strToolBarEditName);
7、最后在需要使用改图表功能的界面添加响应函数就OK了。
8、如果需要在工具栏实现消息提示,则需要在各个工具的propmt属性添加想显示的内容。
注:具体格式如下(xx\nyy),其中yy为提示的内容,如果格式不正确,就不能显示内容。具体实现及效果如下。