Showing progress bar in a status bar pane


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

This code creates a progress bar anywhere in the status window and the control is created only once.

1. From the View menu, choose Resource Symbols. Press the New button and assign the symbol a name. (In this example well be using ID_INDICATOR_PROGRESS_PANE) Its probably best if you let the computer assign a value for it.

2. In MainFrm.cpp, find the indicators array (located under the message map section) and type the ID of the resource (ID_INDICATOR_PROGRESS_PANE) in the section. Put it under all the rest of the IDs, unless you dont want the bar in the far right corner. (placing the ID at the beginning of the array puts the pane in the far left where the program messages usually go)

3. Open the string table in the resource editor, and from the Insert menu, choose New String.

4. Double click the string and select the ID. For the message, just type a bunch of spaces. (the more spaces the larger the progress bar)

Now that weve created the pane, its time to put a progress bar in it.

1. Declare a public variable in MainFrm.h of type CProgressCtrl. (In this example well call it m_Progress)

2. Declare a protected variable in MainFrm.h of type BOOL. (In this example well call it m_bCreated)

3. In the OnCreate() function in MainFrm.cpp, initialize m_bCreated to FALSE:

	m_bCreated = FALSE;

4. Now, when we need to use the progress bar, we check to see if its created, and if it isnt, we make a new one:

	RECT MyRect;
	// substitute 4 with the zero-based index of your status bar pane. 
	// For example, if you put your pane first in the indicators array, 
	// youd put 0, second youd put 1, etc.
	m_wndStatusBar.GetItemRect(4, &MyRect);  

	if (m_bCreated == FALSE)
		//Create the progress control
		m_Progress.Create(WS_VISIBLE|WS_CHILD, MyRect, &wndStatusBar, 1); 

		m_Progress.SetRange(0,100); //Set the range to between 0 and 100
		m_Progress.SetStep(1); // Set the step amount
		m_bCreated = TRUE;

	// Now well simulate a long process:
	for (int I = 0; I < 100; I++)

If the window is resized while the progress bar is created, the progress control doesnt reposition correctly, so we have to override the WM_SIZE event of class CMainFrame:

void CMainFrame::OnSize(UINT nType, int cx, int cy) 
	CMDIFrameWnd::OnSize(nType, cx, cy);
	RECT rc;
	m_wndStatusBar.GetItemRect(4, &rc);

	// Reposition the progress control correctly!
	m_Progress.SetWindowPos(&wndTop, rc.left, rc.top, rc.right - rc.left,
		rc.bottom - rc.top, 0); 

Thats the way to implement a progress control into a status bar pane! Although the process is long, it is relatively simple.


  • How do I get the code listing.

    Posted by Legacy on 11/26/2003 08:00am

    Originally posted by: ppt

    Where is teh code. Can you list it please.

  • woooooooooooooooooo!!!

    Posted by Legacy on 10/09/2003 07:00am

    Originally posted by: ben

    i have no clue what i am doing on this webpage, so i decided to leave a comment complaing about that. you guys need to be more obvious on what its talking about. you talk all this "computer lingo" and i dont understand it. i have to admit, i am a little slow in the head, but thats not my fault. i was born with that mind thing that makes me dumb in the head. what was i talking about again. i forgot so im gonna stop typing now

  • Elegante!

    Posted by Legacy on 09/18/2003 07:00am

    Originally posted by: truthADjuster

    this is simply, Elegant! No overhead, no third party classes. Just pure MFC. The "better OnSize" response by a previous coder is very helpful. Thanks.

  • good

    Posted by Legacy on 08/17/2003 07:00am

    Originally posted by: hata

    very good

  • Debug assertion ..problem

    Posted by Legacy on 08/15/2003 07:00am

    Originally posted by: shanti

    I am a begginer in VC++.
    I did the program(SDI application) as Brad Mann specified.Then i got "Debug assertion problem".So i changed the code as David Menifield specified ,then i am not getting the previous problem but a new problem came "failed to create empty document".
    Pls help me out as i need it urgently.

  • Progress bar creation

    Posted by Legacy on 07/03/2003 07:00am

    Originally posted by: mary lowe

    I want ot implement a Progress bar on my dialog box. and I want hte progress status to be implemented till i complete a function.

    for example say i want to add numbers...

    I want the progress bar to continue form the time I inout the numbers, add them and print the result...

    Any help will be deeply appreciated.


  • Error??????????????

    Posted by Legacy on 04/17/2003 07:00am

    Originally posted by: Ravinder Reddy

    I am Ravinder reddy your Example is very good but when i a implemented your code the progress bar i mean the thread loop that is slee() function is not working progress bar is not process is not displaying in the status bar,so please help me how to solve this Error.

    I will be Great Thankfull to your's Suggesstions.

    Thank you

  • Three Corrections to Brad Mann's progress bar

    Posted by Legacy on 03/12/2003 08:00am

    Originally posted by: Paul Ganney

    At least one of these has been posted before, but I thought I'd bring all the corrections together (to make them easier to find!)

    All apply to the second set of points (where 1. starts "Declare..")

    3. m_bCreated=FALSE; needs to be the first line of OnCreate()

    4. //Create the progress control
    m_progress.Create(WS_VISIBLE|WS_CHILD, MyRect, &m_wndStatusBar, 1);

    (the "m_" was missing)

    in OnSize():
    RECT rc;
    // ...

    I hope that all makes sense. It certainly makes one of the best implementations I've found even better.


  • Good.. It's cool!!!!

    Posted by Legacy on 11/06/2002 08:00am

    Originally posted by: changjin

    return.. -_-;;

  • How do we show a double number in a status bar

    Posted by Legacy on 10/23/2002 07:00am

    Originally posted by: Mehrdad Bahar

    I want to show a measurement, which is a double number ,in a status bar

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

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

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date