Click here to Skip to main content
13,449,063 members (54,289 online)
Click here to Skip to main content
Add your own
alternative version


49 bookmarked
Posted 2 Aug 2002

Toolbar & StatusBar on Dialog

, 7 Aug 2002
Rate this:
Please Sign up or sign in to vote.
Toolbar / Statusbar on Dialog Window

Sample Image - DlgToolStatusBar.gif

What's New

Carried out some changes as suggested by Russ Freeman. The Changes are as follows

  • Moved all string in code to String Table
  • Delete unwanted sub-class files CStatusBar
  • Added menu to generate 3 types of ToolBars
  • Retained Old Toolbar as is
  • New Toolbars use Arrays
  • Added Date & Time on the Statusbar
  • Added message Maps for new Toolbars


This Article demonstrates the technique of creating Toolbar and StatusBar on a Dialog Window.

To acheive the goal you create a Dialog-based project from the New Project Wizard, a blank form with Ok and Cancel buttons is created by default.

Delete the buttons since you will most probably be making the project menu-driven.

//  First we create the ImageList for use with the ToolBar
//  in following manner
CWinApp* pApp = AfxGetApp();
mImageList->Create(24, 24, ILC_COLOR8 | ILC_MASK,  9, 9);
// next we create the Toolbar


    CRect(0,0,0,0), this, 0);

   // Set ImageList for this Toolbar created 
   // in the previous section
tb.iBitmap = 0;
tb.iString = NULL;
tb.fsStyle = TBSTYLE_BUTTON;
tb.idCommand = ID_HELP_ABOUT;

m_ToolBar.AddButtons(1, &tb);
tb.iBitmap = 1;
tb.idCommand = ID_BOLD;
m_ToolBar.AddButtons(1, &tb);
tb.iBitmap = 2;
tb.idCommand = ID_DRAWING;
m_ToolBar.AddButtons(1, &tb);

tb1.fsStyle = TBSTYLE_SEP;
m_ToolBar.AddButtons(1, &tb1);

tb.iBitmap = 3;
tb.idCommand = ID_STRIKEOUT;
tb.iString = NULL;
m_ToolBar.AddButtons(1, &tb);

// We now Create the Statusbar as show below

    CRect(0,0,0,0), this, 0);

// You can set the no. of parts of the StatusBar (4 in this case) 
// and the width of each part not -1 means remaining width

int strPartDim[4]= {180, 260, 340, -1};
m_StatusBar.SetParts(4, strPartDim);

m_StatusBar.SetText(_T("Dialog / StatusBar / Toolbar"),0,0);
m_StatusBar.SetText(_T("Example"), 1, 0);
CString string;
m_StatusBar.SetText(string, 3 ,SBT_NOBORDERS   );
m_StatusBar.SetIcon(3,     SetIcon(AfxGetApp()->LoadIcon(IDI_COMP), FALSE));


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

Barretto VN
India India
Nothing to boast about

You may also be interested in...

Comments and Discussions

GeneralVery helpful - but image list wrong size Pin
rneville7-Apr-04 2:09
memberrneville7-Apr-04 2:09 
GeneralRe: Very helpful - but image list wrong size Pin
Barretto VN8-Apr-04 23:49
memberBarretto VN8-Apr-04 23:49 
GeneralBug OnTimer Pin
TomBest12-Dec-03 0:03
memberTomBest12-Dec-03 0:03 

I found a bug in void CDlgToolStatusBarDlg::OnTimer(UINT nIDEvent).
Actual the sDate variable is declared as char sDate[11].
But this is not enough to hold the date/time string.

I modify this using CString:

<code>void CDlgToolStatusBarDlg::OnTimer(UINT nIDEvent) 
    time_t t;
    struct tm *ptm;
    ptm = localtime(&t);
    CString strDate;
    strDate.Format( "%.19s", asctime(ptm) );
    m_StatusBar.SetText(strDate, 1, 0);


GeneralRe: Bug OnTimer Pin
Barretto VN10-Mar-05 2:29
memberBarretto VN10-Mar-05 2:29 
GeneralThe Menue Pin
joerghamster14-Mar-03 1:30
memberjoerghamster14-Mar-03 1:30 
AnswerRe: The Menue Pin
Amar Sutar6-Apr-06 3:23
memberAmar Sutar6-Apr-06 3:23 
GeneralRe: Some bad habits and other code comments. Pin
George8-Aug-02 16:17
memberGeorge8-Aug-02 16:17 

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
Web04 | 2.8.180318.3 | Last Updated 8 Aug 2002
Article Copyright 2002 by Barretto VN
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid