Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC VC++
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?
Posted 24-Feb-13 6:33am
Edited 24-Feb-13 6:34am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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);
}
- Call it from your dialog class's InitDialog()
  Permalink  
v6
Comments
H.Brydon at 24-Feb-13 21:25pm
   
Great answer. +5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,078
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 24 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100