我用MFC创建了一个单文档、根据需要要更改工具栏按钮图标、
我想导入自己现有的图标、这个怎么实现???
不管用什么方法、在原工具栏的基础上也行、另创建一个工具栏也行!
只要能解决这个问题、最好回答详细点、刚学MFC不久、。。多谢了!
回答的好有加分!!!!!!!多谢各位!!!
MFC单文档如何更改工具栏图标???急!!!!
答案:4 悬赏:0
解决时间 2021-03-14 21:52
- 提问者网友:霸道ぁ小哥
- 2021-03-14 09:04
最佳答案
- 二级知识专家网友:温柔刺客
- 2021-03-14 10:36
Visual C++ provides you with two methods to create a toolbar. To create a toolbar resource using the Resource Editor, follow these steps: //在资源编辑器中创建一个toolbar资源
Create a toolbar resource.//常见一个toolbar资源
Construct the CToolBar object.//构造一个toolbar对象
Call the Create (or CreateEx) function to create the Windows toolbar and attach it to the CToolBar object.//调用creat或者createx函数创建窗口toolbar并且将其与toolbar对象关联
Call LoadToolBar to load the toolbar resource.//调用 LoadToolBar载入toolbar资源
Otherwise, follow these steps:
Construct the CToolBar object.//构造CToolBar对象
Call the Create (or CreateEx) function to create the Windows toolbar and attach it to the CToolBar object.//调用Create (or CreateEx)函数创建窗口toolbar并关联到CToolBar 对象
Call LoadBitmap to load the bitmap that contains the toolbar button images.//调用LoadBitmap 载入包含了toolbar按钮图片的bitmap*****************载入图标操作,图标可以通过资源管理器导入。
Call SetButtons to set the button style and associate each button with an image in the bitmap.//调用SetButtons 设置按钮类型并且将每一个按钮和图片关联
All the button images in the toolbar are taken from one bitmap, which must contain one image for each button. All images must be the same size; the default is 16 pixels wide and 15 pixels high. Images must be side by side in the bitmap.//所有的工具栏按钮图片都来自于一个位图,且每一个按钮必须包含一个位图。所有的图片必须有相同的大小,默认时16像素宽,15像素高。图片必须边挨边在为图中。
上面是MSDN中的说明,很清楚的说明了如何向工具栏中添加图标。
1、在资源管理器中添加一个工具栏资源
2、定义一个工具栏对象并且和工具栏资源关联
3、用loadbitmap函数将图标载入到工具栏,LoadBitmap 函数的使用可以查阅MSDN
4、用SetButtons 将按钮和图片关联起来就行了
Create a toolbar resource.//常见一个toolbar资源
Construct the CToolBar object.//构造一个toolbar对象
Call the Create (or CreateEx) function to create the Windows toolbar and attach it to the CToolBar object.//调用creat或者createx函数创建窗口toolbar并且将其与toolbar对象关联
Call LoadToolBar to load the toolbar resource.//调用 LoadToolBar载入toolbar资源
Otherwise, follow these steps:
Construct the CToolBar object.//构造CToolBar对象
Call the Create (or CreateEx) function to create the Windows toolbar and attach it to the CToolBar object.//调用Create (or CreateEx)函数创建窗口toolbar并关联到CToolBar 对象
Call LoadBitmap to load the bitmap that contains the toolbar button images.//调用LoadBitmap 载入包含了toolbar按钮图片的bitmap*****************载入图标操作,图标可以通过资源管理器导入。
Call SetButtons to set the button style and associate each button with an image in the bitmap.//调用SetButtons 设置按钮类型并且将每一个按钮和图片关联
All the button images in the toolbar are taken from one bitmap, which must contain one image for each button. All images must be the same size; the default is 16 pixels wide and 15 pixels high. Images must be side by side in the bitmap.//所有的工具栏按钮图片都来自于一个位图,且每一个按钮必须包含一个位图。所有的图片必须有相同的大小,默认时16像素宽,15像素高。图片必须边挨边在为图中。
上面是MSDN中的说明,很清楚的说明了如何向工具栏中添加图标。
1、在资源管理器中添加一个工具栏资源
2、定义一个工具栏对象并且和工具栏资源关联
3、用loadbitmap函数将图标载入到工具栏,LoadBitmap 函数的使用可以查阅MSDN
4、用SetButtons 将按钮和图片关联起来就行了
全部回答
- 1楼网友:浪者不回头
- 2021-03-14 14:40
mfc单文档程序,在资源编辑器中只有一个已有的toolbar资源,你只需要在资源编辑器里面,通过“空位”建立一个按钮图标(通过绘制或者复制)并加工好,然后选中这个工具条按钮,右键属性,给予它一个id就可以使用了。
id最好是先建立菜单项的方式给予,这样方便建立提示说明等文字。
工具条按钮,不需要setbutton方法,这个是对话框按钮控件的方式,而不是工具条按钮。
- 2楼网友:最后战士
- 2021-03-14 13:01
需要自己绘制同样规格的bmp工具条,然后导入该工具条,修改ID即可
- 3楼网友:不服输就别哭
- 2021-03-14 11:44
在原工具栏的基础上:
工具栏的对象(CToolBar m_wndToolBar)在frame里面。
首先获取
CToolBarCtrl tc= m_wndToolBar.GetToolBarCtrl( )
再
tc.AddBitmap(...)
再
tc.AddButtons(...)
具体看msdn
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |