Showing progress bar in a status bar pane (2)

and updated by Michael Martin.

Download source files or demo project

Adding a CProgressCtrl to the status bar has already been addressed by Brad Mann. His method involved modifying the status bar and messing around with the resource editor. I developed a separate CProgressBar class in order to allow the programmer to just drop in a progress bar whereever they wanted using a single "CProgressBar Bar(...)" declaration, which would initialise and display itself and clean up after itself after it was done. The progress bar can also be created once (say as a member variable) and reused multiple times. This new version of the progress bar also resizes itself if the status bar size changes.

The progress bar lets you specify a message (displayed to the left of the bar) and a Progress Control bar in the any pane of your applications status bar (if it has one - thanks to Patty You for a bug fix on that one). The message for the progress bar can be changed at any time, as can the size and range of the bar.

Construction

	CProgressBar(); 
	CProgressBar(LPCTSTR strMessage, int nSize=100, int MaxValue=100, BOOL bSmooth=FALSE, int nPane=0);
	BOOL Create(LPCTSTR strMessage, int nSize=100, int MaxValue=100, BOOL bSmooth=FALSE, int nPane=0);

Construction is either via the constructor or a two-step process using the constructor and the "Create" function. "strMessage" is the message to be displayed, "nSize" is the percentage width of the status bar that will be occupied by the bar (including the text), and "MaxValue" is the maximum range of the bar.

"bSmooth" will only be effective if you have the header files and commctrl32.dll from IE 3.0 or above (no problems for MS VC 5.0). It specifies whether the progress bar will be smooth or chunky.

New additions to version 1.1

The progress bar now makes use of the PBM_SETRANGE32 message to allow the range to be set from -0x7FFFFFFF to 0x7FFFFFFF. This will only be used if the the PBM_SETRANGE32 macro is defined.

Two new functions SetBarColour and SetBkColour have been added, but are only effective if the new macros PBM_SETBARCOLOR and PBM_SETBKCOLOR are defined.

New additions to version 1.2

The progress bar can now be placed in any pane of the status bar. (Thanks to Michael Martin). I also did a bit of a code cleanup.

Operations

	BOOL Success()                      // Construction successful?

	COLORREF SetBarColour(COLORREF clrBar);  // Set Bar colour, returns previous
	COLORREF SetBkColour(COLORREF clrBar);   // Set background colour, returns previous

	int  SetPos(int nPos);              // Same as CProgressCtrl
	int  OffsetPos(int nPos);           // Same as CProgressCtrl
	int  SetStep(int nStep);            // Same as CProgressCtrl
	int  StepIt();                      // Same as CProgressCtrl
	void Clear();                       // Clear the status bar
	void SetRange(int nLower, int nUpper, int nStep = 1);
	                                    // Set min, max and step size
	void SetText(LPCTSTR strMessage);   // Set the message
	void SetSize(int nSize);            // Set the bar size

To use the bar, just do something like:

	CProgressBar Bar("Testing", 40, 1000);
	
	for (int i = 0; i < 1000; i++) {
	    // perform operation
	    Bar.StepIt();
	}
or it can be done two stage as:
	CProgressBar bar;
	
	bar.Create("Processing", 40, 1000);
	for (int i = 0; i < 1000; i++) {
	    // perform operation
	    bar.StepIt();
	}

	bar.SetText("Writing");
	for (int i = 0; i < 1000; i++) {
	    // perform operation
	    bar.StepIt();
	    PeekAndPump();	// Message pump
	}
	bar.Clear();

In the above case, PeekAndPump() is a function which simply peeks and pumps messages, allowing user interaction with the window during a lengthy process. If the window size changes during the processing, the progress bar size will alsow change.

Last update: August 25, 1998



Comments

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

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • 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 …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds