Extended statusbar with bitmap, progress bar and mouse action

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 progressbar indicates how long it takes. The class also provides actions when you click in any pane (also in dialogbased 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_TEST Display text in this pane
XSB_NUMBER Display a number in this pane
XSB_BITMAP Display a bitmap in this pane
XSB_PROGRESS Display a progressbar in this pane
XSB_HSCROLL Scroll the text, number or bitmap in this pane horizontal
XSB_VSCROLL Scroll the text, number or bitmap in this pane vertical
XSB_DSCROLL Scroll horizontal and vertical
XSB_REPEAT Draw the text, number or bitmap multiple times to fill the pane
XSB_STRETCH Grow or shrink the bitmap, so that the entire pane was filled
XSB_SMOOTH Progressbar was drawn smooth
   
XSB_TOP Align top (like DT_TOP)
XSB_LEFT Align left (like DT_LEFT)
XSB_CENTER Align center (like DT_CENTER)
XSB_RIGHT Align right (like DT_RIGHT)
XSB_VCENTER Align vertical center (like DT_VCENTER)
XSB_BOTTOM Align 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:

Method Description Default
SetFgColor Set the pane's textcolor (Mode XSB_TEXT or XSB_NUMBER) * enabled: standard textcolor (e.g. black) disabled: greyed text (e.g. grey)
SetBkColor Set the pane's backgroundcolor (Mode XSB_TEXT or XSB_NUMBER) * std-backgroundcolor (e.g. light grey)
SetBitmap Set the pane's bitmap (Mode XSB_BITMAP)* The bitmaps are defined as stringresources. If you use int-resource use MAKEINTRESOURCE(..) -
SetText Set the pane's text (Mode XSB_TEXT or XSB_NUMBER) * Indicatortext (e.g. CAPS, NUM, ...)
SetNumber Set the pane's number (Mode XSB_TEXT or XSB_NUMBER) * -
SetFont Set the pane's font (LOGFONT or CFont, Mode XSB_TEXT or XSB_NUMBER) standard textfont (e.g. MS Sans Serif 10pt)
SetFontSize Set the pane's fontsize (Mode XSB_TEXT or XSB_NUMBER) standard textfontsize (e.g. 10pt)
SetFontName Set the pane's fontname (Mode XSB_TEXT or XSB_NUMBER) standard textfontname (e.g. MS Sans Serif)
SetRange Set the pane's progressbarrange (see CProgressBar, Mode XSB_PROGRESS) 0 .. 100
SetPos Set the pane's progressbarposition (see CProgressBar, Mode XSB_PROGRESS) 0
SetOffset Set the pane's progressbaroffset (see CProgressBar, Mode XSB_PROGRESS) 1
SetStep Set the pane's progressbarstep (see CProgressBar, Mode XSB_PROGRESS) 1
     
Increment Incremet the pane's numbervalue (Mode XSB_NUMBER) -
Decrement Decremet the pane's numbervalue (Mode XSB_NUMBER) -
     
* Remeber: 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



Comments

  • How can i add Text and Bitmap both on one pane?

    Posted by ziashahid on 03/06/2008 05:29am

    Hi! I wanna add Text and Bitmap both on one pane, how cud i achieve this?

    Reply
  • How do i add a colour to the status bar

    Posted by Legacy on 07/11/2003 12:00am

    Originally posted by: kishore

    Hello, i want to know how we add colour to the status bar.. I used OnCtlColor earlier and i wanna suggestion on how to do it. If there are any other ways, kindly do suggest me. Thanks a lot
    Amie

    Reply
  • How to run it in a separate thread??

    Posted by Legacy on 04/20/2003 12:00am

    Originally posted by: Mustafa

    Hi

    Thank you for this great work....but when I have horizontal scrolling text running in Win98 the scroll-speed is very slow but if you continously move the mouse, the scroll speed is faster and smoother...so I thought what if I place the whole XStatusBar in it's own thread...but don't know how..have been trying some approaches but failed...could you help me there??

    Regards

    Mustafa

    Reply
  • Redraw ProgressBar

    Posted by Legacy on 07/21/2002 12:00am

    Originally posted by: Christophe Jacquelin

    Hello,

    After fixing SetPos on a ProgressBar, its work better whith the use of the redraw fonction on the status bar :

    m_wndStatusBar.RedrawWindow(NULL,NULL,RDW_INVALIDATE | RDW_UPDATENOW);

    Sincerely,
    Christophe,

    • mouse

      Posted by chrif on 03/16/2005 08:18am

      I would like to do a graph who follow the mouvment of the mouse . I program with C# on PDA

      Reply
    Reply
  • Status Bar with Progress bar and bitmap

    Posted by Legacy on 09/26/2001 12:00am

    Originally posted by: Jessica

    May i know how to do it in WIN32 API?
    Please E-mail me as soon as possible

    Reply
  • Adding the title tip

    Posted by Legacy on 09/18/2001 12:00am

    Originally posted by: Prakash

    How can i add the title tip to the panes in this statusbar control ???

    Reply
  • A Question??? Resizing a pane of the Status Bar

    Posted by Legacy on 07/23/2001 12:00am

    Originally posted by: BizQt

    How can I Resize a width of pane. I have declared as in example the second pane to XSB_PROGRESS. But it's too short! How can I correct this???

    Reply
  • Gripper property removed but....

    Posted by Legacy on 06/05/2001 12:00am

    Originally posted by: Prasad

    In PreCreateWindow, I disable the gripper property, it work in functionality but the gripper Icon is displayed over the first pane from right.

    PreCreateWindow(CREATESTRUCT& cs)
    {
    BOOL bRet = CStatusBar::PreCreateWindow(cs);
    //Removed gripper property
    cs.style &= ~SBARS_SIZEGRIP;
    return bRet;
    }

    I know that there is something in OnPaint Handler, which does this.

    If someone could point me in the direction of what is happening, I would really appreciate it.

    Prasad

    Reply
  • That's what I have looked for long time!

    Posted by Legacy on 05/27/2001 12:00am

    Originally posted by: vector zhu

    Thank you very much!

    Reply
  • Thanks for posting this.

    Posted by Legacy on 05/14/2001 12:00am

    Originally posted by: Rudy Schalk

    Just what I needed for a real time updating status bar. I used ability to change the background colors to alert the user to changes of state in my system. Again, thanks for taking the time to post this code.

    --Rudy

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • QA teams don't have time to test everything yet they can't afford to ship buggy code. Learn how Coverity can help organizations shrink their testing cycles and reduce regression risk by focusing their manual and automated testing based on the impact of change.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds