Extended statusbar with bitmap, progress bar and mouse action

Published on: November 21, 2000
Last Updated: November 21, 2000

Extended statusbar with bitmap, progress bar and mouse action

Published on: November 21, 2000
Last Updated: November 21, 2000

With the XStatusBar-class it is very easy to display text, numbers, bitmaps or progressbars in a statusbar.

It also provides temporary display of text in any pane with automatic restore of the normal appearance. For example, it is possible to display a scrolling bitmap in a pane but during a long operation, a progress bar indicates how long it takes.

The class also provides actions when you click in any pane (also in dialog based applications).

In this example, the first pane temporarily changes to a progressbar. When the long operation ends, it automaticly changes back to a normal textpane.

What Have You To Do, To Use This Class?

The use the XStatusBar-class is quite simple. First you have change the existing CStatusBar-member m_wndStatusBar to XStatusBar in your mainframe-headerfile.

XStatusBar m_wndStatusBar;

Second, replace the creation-functions in the OnCreate()-method of CMainFrame by:

if(!m_wndStatusBar.CreateStatusBar(this, indicators, sizeof(indicators)/sizeof(UINT)))
{
TRACE0(“Failed to create status bar\n”);
return -1;
}

Third, define the appearance of the panes. For example

m_wndStatusBar.SetMode(1, XSB_TEXT | DT_CENTER | DT_VCENTER);
m_wndStatusBar.SetMode(2, XSB_NUMBER | DT_CENTER);
m_wndStatusBar.SetMode(3, XSB_BITMAP| XSB_REPEAT);

For each pane, you can combine the following modes:

XSB_TESTDisplay text in this pane
XSB_NUMBERDisplay a number in this pane
XSB_BITMAPDisplay a bitmap in this pane
XSB_PROGRESSDisplay a progressbar in this pane
XSB_HSCROLLScroll the text, number or bitmap in this pane horizontal
XSB_VSCROLLScroll the text, number or bitmap in this pane vertical
XSB_DSCROLLScroll horizontal and vertical
XSB_REPEATDraw the text, number or bitmap multiple times to fill the pane
XSB_STRETCHGrow or shrink the bitmap, so that the entire pane was filled
XSB_SMOOTHProgressbar was drawn smooth
XSB_TOPAlign top (like DT_TOP)
XSB_LEFTAlign left (like DT_LEFT)
XSB_CENTERAlign center (like DT_CENTER)
XSB_RIGHTAlign right (like DT_RIGHT)
XSB_VCENTERAlign vertical center (like DT_VCENTER)
XSB_BOTTOMAlign bottom (like DT_BOTTOM)

You can change the mode for every Pane whenever you want.

Fourth, after the mode-definition, you have to tell the panes about further information:

m_wndStatusBar.SetFgColor(1, RGB( 0, 0, 0), RGB(255, 255, 255));
m_wndStatusBar.SetBkColor(1, RGB( 0, 255, 255), RGB(128, 0, 0));
m_wndStatusBar.SetNumber(2, 0, 0);
m_wndStatusBar.SetBitmap(3, "BM1", "BM2");

There are a couple of functions to change the appearance of the panes:

MethodDescriptionDefault
SetFgColorSet the pane’s textcolor (Mode XSB_TEXT or XSB_NUMBER) *enabled: standard textcolor (e.g. black) disabled: greyed text (e.g. grey)
SetBkColorSet the pane’s backgroundcolor (Mode XSB_TEXT or XSB_NUMBER) *std-backgroundcolor (e.g. light grey)
SetBitmapSet the pane’s bitmap (Mode XSB_BITMAP)* The bitmaps are defined as stringresources. If you use int-resource use MAKEINTRESOURCE(..)
SetTextSet the pane’s text (Mode XSB_TEXT or XSB_NUMBER) *Indicatortext (e.g. CAPS, NUM, …)
SetNumberSet the pane’s number (Mode XSB_TEXT or XSB_NUMBER) *
SetFontSet the pane’s font (LOGFONT or CFont, Mode XSB_TEXT or XSB_NUMBER)standard textfont (e.g. MS Sans Serif 10pt)
SetFontSizeSet the pane’s fontsize (Mode XSB_TEXT or XSB_NUMBER)standard textfontsize (e.g. 10pt)
SetFontNameSet the pane’s fontname (Mode XSB_TEXT or XSB_NUMBER)standard textfontname (e.g. MS Sans Serif)
SetRangeSet the pane’s progressbarrange (see CProgressBar, Mode XSB_PROGRESS)0 .. 100
SetPosSet the pane’s progressbarposition (see CProgressBar, Mode XSB_PROGRESS)0
SetOffsetSet the pane’s progressbaroffset (see CProgressBar, Mode XSB_PROGRESS)1
SetStepSet the pane’s progressbarstep (see CProgressBar, Mode XSB_PROGRESS)1
   
IncrementIncremet the pane’s numbervalue (Mode XSB_NUMBER)
DecrementDecremet the pane’s numbervalue (Mode XSB_NUMBER)
   
* Remember: You can set two values, one for the enabled pane and one for the disabled pane

If you only need textpanes, like the standard-statusbar you don’t need to do step 3 and 4. Now you are ready to use the class.

What Have You To Do, To Temporarily Display A Progress Bar?

First you have to save the pane’s appearance with SavePane(ix). Then you can change the mode of the pane to XSB_PROGRESS and set the progress bars parameters (e.g. SetRange(ix, 0, 100), SetStep(ix, 2), …).

Now it’s time to do your long operation and step your progressbar (StepIt(ix)). At last, restore the pane’s appearance (RestorePane(ix)).

m_wndStatusBar.SavePane(0);
m_wndStatusBar.SetMode(0, XSB_PROGRESS);
m_wndStatusBar.SetRange(0, 0, 100);
...
(long operation)
...
m_wndStatusBar.RestorePane(0);

What Have You To Do, To Temporarily Display A Text?

There is another class called XPaneText, to simplify this action. When you want to show temporar text in a pane (no matter if the pane is enabled or disabled) just create a XPaneText-object with the specified text.

When you destroy the object, the original appearance of the pane was restored.

For example, the following code displays the text “Display this text” in the first pane until you end the dialog. There’s no matter if the pane was in bitmap-mode or if it was disabled.

{
XPaneText(“Display this text”);
CTestDialog dlg;
dlg.DoModal();
} // Destroy the XPaneText-object ==> Restore pane

How Does The Application Know, Which Pane Was Clicked?

First you have to add a normal handler for the mouse-event (for example ON_WM_LBUTTONDBLCLK()).

In the eventhandler, use the function GetPaneAtPosition(point) to determine, wich pane belongs to the mouse-position. This function also works fine in dialogs, because in this case, the point was translatet into client-corrdinates.

void CMainFrame::OnLButtonDblClk(UINT nFlags, CPoint point)
{
if (m_wndStatusBar.GetPaneAtPosition(point) == 3)
AfxMessageBox(“Pane 3 doubleclicked”);
else

}
Download demo project – 11KB
Download source – 43KB
Date Posted: 20 May 1998
Comments:
StatusBar – Kevin Cao (1999/06/14)
CPU time! – Prasad (1999/03/29)
Hi – Bryan Dunbar (1999/03/16)

Stay on top of the latest technology trends — delivered directly to your inbox, free!

Subscription Form Posts

Don't worry, we don't spam

Written by Bobby

Bobby Lawson is a seasoned technology writer with over a decade of experience in the industry. He has written extensively on topics such as cybersecurity, cloud computing, and data analytics. His articles have been featured in several prominent publications, and he is known for his ability to distill complex technical concepts into easily digestible content.