Click here to Skip to main content
11,496,146 members (816 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
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

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 Dnyaneshwar@Pune 692
1 RyanDev 230
2 CHill60 163
3 Sascha Lefèvre 145
4 Sergey Alexandrovich Kryukov 124
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 24 Feb 2013
Copyright © CodeProject, 1999-2015
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