Progress Sphere | CodeGuru

Progress Sphere

This class displays a translucent, shadowed modal progress dialog. The process whose progress is to be monitored is started as a new thread, allowing the progress sphere to update smoothly. If enabled, the user is given the ability to terminate the process with the ESC key. The code runs on Windows 2000 and later. 1. […]

Written By
CodeGuru Staff
CodeGuru Staff
Jun 23, 2006
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

This class displays a translucent, shadowed modal progress dialog. The process whose progress is to be monitored is started as a new thread, allowing the progress sphere to update smoothly. If enabled, the user is given the ability to terminate the process with the ESC key. The code runs on Windows 2000 and later.

1. Structure

All initialisation is performed in the constructor:

CDlgProgress(HWND hParentWnd, PROGRESSFUNC hThreadProc,
             const wchar_t* strTitle, bool bAllowCancel = false);

The parameters in detail:

  • hParentWnd takes a handle to the calling window
  • PROGRESSFUNC supplies the name of the user function that contains the code whose progress is to be monitored
  • strTitle is the text that will display at the top of the window, during the entire execution
  • bAllowCancel tells the class whether to allow premature termination by the user

This method checks whether the progress funtion should continue executing:

bool Continue();

The following function sets the status message of the progress dialog:

void SetProgress(CString strText, double dPos);
  • strText is the status message
  • dPos is the percent completed

This one returns the handle of the dialog:

HWND GetWindowHandle();

The progress function needs to have the following form:

bool ProgressFunction(CDlgProgress* pDlgProgress);

2. Usage

  1. Do the inclusion:
    #include "CDlgProgress.h"
  2. Construct the CDlgProgress object; for example:
    CDlgProgress dlg(m_hWnd, ProgressFunction,
                     L"Lengthy operation being performed...",
                     true);
    
  3. Write a progress function:
    bool ProgressFunction(CDlgProgress* pDlgProgress)
    {
       for(int i = 0; i < 5000; i++)
       {
          if(!pDlgProgress->Continue())
             return 1;
    
          CString strMessage;
          strMessage.Format(L"Current number is %i", i);
          pDlgProgress->SetProgress(strMessage, (double)i/50.0f);
       }
    
       return 0;
    }
    
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.