Microsoft KB Archive/142202

= How to create a process bar on the status bar in Visual C++ =

Article ID: 142202

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 4.0 Standard Edition

 Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 5.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2002 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2003 Standard Edition</li></ul>

 Microsoft Visual Studio .NET 2003 Enterprise Developer</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q142202

<div class="notice_section">

Note Microsoft Visual C++ .NET 2002 and Microsoft Visual C++ .NET 2003 support both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code.

<div class="summary_section">

SUMMARY
There are times when you may want to show the progress of a process on the status bar. Developer Studio does this when loading a project. You can implement this by using CStatusBar and CProgressCtrl.

<div class="moreinformation_section">

MORE INFORMATION
A default AppWizard-generated MFC application has a class (CMainFrame) that contains a member variable m_wndStatusBar of type CStatusBar. The following sample code uses this member variable as the parent of a CProgressCtrl, which will be positioned over the first pane of m_wndStatusBar. First, the CProgressCtrl is created. Then, the sample code simulates a lengthy process using the Sleep function in a for loop.

Sample code
/* Compile options needed: default */

// This is a menu option handler that takes a long period of time void CMainFrame::OnLengthyProcess {      // Create the CProgressCtrl as a child of the status bar positioned // over the first pane.

RECT rc; m_wndStatusBar.GetItemRect (0, &rc); CProgressCtrl wndProgress; VERIFY (wndProgress.Create(WS_CHILD | WS_VISIBLE, rc, &m_wndStatusBar, 1)); wndProgress.SetRange(0, 50); wndProgress.SetStep(1);

// Perform some lengthy process, simulated here with a for loop // and the Sleep function.

for(int i=0;i<50;i++) {         Sleep(50); wndProgress.StepIt; }  }

Keywords: kbinfo kbhowto kbmfcctrlbar kbstatbar kbuidesign KB142202

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.