CodeGuru
Earthweb Search
Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

Become a Marketplace Partner

jobs.internet.com

internet.commerce
Partners & Affiliates
















RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

Home >> Visual C++ / C++ >> Controls >> Status Bar


Extended statusbar with bitmap, progress bar and mouse action
Rating: none

Joachim Raidl (view profile)
August 6, 1998


(continued)



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

Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed







RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

(You must be signed in to rank an article. Not a member? Click here to register)

Latest Comments:
How can i add Text and Bitmap both on one pane? - ziashahid (03/06/2008)
How do i add a colour to the status bar - Legacy CodeGuru (07/11/2003)
How to run it in a separate thread?? - Legacy CodeGuru (04/20/2003)
Redraw ProgressBar - Legacy CodeGuru (07/21/2002)
Status Bar with Progress bar and bitmap - Legacy CodeGuru (09/26/2001)

View All Comments
Add a Comment:
Title:
Comment:
Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



(You must be signed in to comment on an article. Not a member? Click here to register)


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Tripwire Whitepaper: Seven Practical Steps to Mitigate Virtualization Security Risks
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES