如何在工具栏上设置图标 [英] How to set an icon on a tool bar

查看:83
本文介绍了如何在工具栏上设置图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我对如何在工具栏中放置的按钮中设置图标感到困惑。我的意思是,假设我有名称为IDR_TOOLBAR1的工具栏。我有保存图标。我想将此保存图标设置为此工具栏。怎么可能?

Hi,
Iam confused about how to set an icon in a button placed in a tool bar. What i meant was, suppose i have tool bar with name of IDR_TOOLBAR1. i have "save" icon. i want set this save icon to this tool bar. how it is possible?

推荐答案

你可以使用WHOLE工具栏的位图,这是可能的

(如果你想改变它您需要更改整个位图的单个按钮的位图):

- 制作一个256色的位图,其中所有图标都排成一行(触摸)连续

使用你最喜欢的油漆程序。我建议调用文件TOOLBAR.BMP。

- 将位图导入为资源。称之为IDB_TOOLBAR。

- 将其添加到对话框类的标题中:

You can use the bitmap for the WHOLE Toolbar, that is possible
(if you want to change the bitmap of one single button you need to change the whole bitmap as well):
- Make a 256 color bitmap that has all your icons lined (touching) up in a row
using your favourite paint program. I suggest calling the file TOOLBAR.BMP.
- Import the bitmap as a resource. Call it IDB_TOOLBAR.
- Add this to your dialog class''s header:
CBitmap     m_bitmapToolbar;
CToolBar    m_Toolbar;
void CreateToolbar();



- 在对话框类中添加以下函数:


- Add a the following function to your dialog class:

static int iToolbarIconWidth = 32;
static int iToolbarIconHeight = 32;

void CMyDialog::CreateToolbar()
{
	const UINT ids[] = { IDC_YOUR_ACTION1, IDC_YOUR_ACTION2, IDC_YOUR_ACTION3 };

	m_Toolbar.CreateEx(this, TBSTYLE_FLAT | TBSTYLE_TOOLTIPS);
	m_bitmapToolbar.LoadBitmap(IDB_TOOLBAR);
	m_Toolbar.SetBitmap((HBITMAP)m_bitmapToolbar);
	m_Toolbar.SetButtons((const UINT *)&ids, sizeof(ids) / sizeof(ids[0]));
	m_Toolbar.ShowWindow(SW_SHOW);
	RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
	m_Toolbar.SetSizes(CSize(iToolbarIconWidth+7, iToolbarIconHeight+6),  CSize(iToolbarIconWidth, iToolbarIconHeight));
	m_Toolbar.SetHeight(0);
}



- 从对话框类的'InitDialog()


- Call it from your dialog class''s InitDialog()

这篇关于如何在工具栏上设置图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆