Click here to Skip to main content
13,298,965 members (40,053 online)
Click here to Skip to main content
Add your own
alternative version


26 bookmarked
Posted 16 Jul 2003

CStatic derived control which is a replacement for standard toolbar

, 16 Jul 2003
Rate this:
Please Sign up or sign in to vote.
ToolBar control with cool look and easy implementation.

Sample Image - toolbarexctrl.jpg


This is a replacement for a standard ToolBar. This control is derived from CStatic to allow you an easy drop in, also the usage is very simple. It also features tooltips for every button and any size icons for buttons.



In your dialog template, place a CStatic control and make sure to check the Notify check box. Add a member to you dialog for this CStatic and specify CtoolBarEx as it's type.

Adding buttons

In your dialog InitDialog function, add buttons to the toolbar like this:

m_toolBar.AddButton((HICON)LoadImage(AfxGetInstanceHandle( ),
  MAKEINTRESOURCE(IDI_ICON2),IMAGE_ICON,16,16,0),300,"Test Button 1");
 m_toolBar.AddButton((HICON)LoadImage(AfxGetInstanceHandle( ),
  MAKEINTRESOURCE(IDI_ICON3),IMAGE_ICON,16,16,0),301,"Test Button 2");
 m_toolBar.AddButton((HICON)LoadImage(AfxGetInstanceHandle( ),
  MAKEINTRESOURCE(IDI_ICON2),IMAGE_ICON,16,16,0),302,"Test Button 3");
 m_toolBar.AddButton((HICON)LoadImage(AfxGetInstanceHandle( ),
  MAKEINTRESOURCE(IDI_ICON5),IMAGE_ICON,16,16,0),303,"Test Button 4");
 m_toolBar.AddButton((HICON)LoadImage(AfxGetInstanceHandle( ),
  MAKEINTRESOURCE(IDI_ICON2),IMAGE_ICON,16,16,0),304,"Test Button 5");

The AddButton function receives these parameters:

HICON hIcon ,  // The Icon for this button 
int commandId, // The command id of this button
               // (will be used in message handler) 
LPCTSTR buttonText  // The text of the tooltip
                    // that will be displayed for this button 

Optionally you can:

Set the button size:
CToolBarEx::SetButtonSize(CSize size);
Set button spacing:
CToolBarExCtrl::SetButtonSpacing(CSize spacing);
Add a separator:
Remove buttons:
CToolBarExCtrl::RemoveButton(int nIndex, int commandId);

Use either the button index or commandId, set the one that is not in use to -1.

Set the background color:
CToolBarExCtrl::SetBackGroundColor(COLORREF color);
Enable or disable buttons:
CToolBarExCtrl::EnableButton(int nButtonId, bool bEnable);

TRUE to enable, FALSE to disable.

Reacting to button clicks

In your dialog add a handler to WM_COMMAND message. The button commandId is passed in wParam. Example:

BOOL CCToolBarExDlg::OnCommand(WPARAM wParam, LPARAM lParam)
 // TODO: Add your specialized code here and/or call the base class
 case 300:
 case 301:
 case 302:
 case 303:
 case 304:
 case 305:
 return CDialog::OnCommand(wParam, lParam);


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Alex Hazanov
Software Developer (Senior) RDV Systems
Israel Israel
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralNice idea, tooltip does not show Pin
s196675m15-Oct-07 8:15
members196675m15-Oct-07 8:15 
Generalmemory leak fixed Pin
shreejan19-Jan-06 21:00
membershreejan19-Jan-06 21:00 
Questionhow to use in sdi or mdi Pin
liuliu17-Oct-05 18:21
memberliuliu17-Oct-05 18:21 
AnswerRe: how to use in sdi or mdi Pin
Alex Hazanov18-Oct-05 2:48
memberAlex Hazanov18-Oct-05 2:48 
Generalproblem in property list ocx Pin
moshtagh18-Mar-06 4:02
membermoshtagh18-Mar-06 4:02 
GeneralRe: problem in property list ocx Pin
Alex Hazanov20-Mar-06 11:49
memberAlex Hazanov20-Mar-06 11:49 
GeneralMemory leak. Pin
sayherman19-Feb-05 4:28
membersayherman19-Feb-05 4:28 
GeneralNo any target of applicability Pin
vgrigor23-Jul-03 0:22
membervgrigor23-Jul-03 0:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 17 Jul 2003
Article Copyright 2003 by Alex Hazanov
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid