Click here to Skip to main content
12,299,231 members (61,277 online)
Click here to Skip to main content
Add your own
alternative version


147 bookmarked

A Popup Progress Window

, 21 Apr 2002 CPOL
Rate this:
Please Sign up or sign in to vote.
A popup window containing a progress control and cancel button - no resource file needed

Sample Image


There are many occasions where it's nice to have a popup window that shows the progress of a lengthy operation. Incorporating a dialog resource with a progress control and cancel button, then linking up the control messages for every project you wish to have the progress window can get monotonous and messy.

The class CProgressWnd is a simple drop in window that contains a progress control, a cancel button and a text area for messages. The text area can display 4 lines of text as default, although this can be changed using CProgressWnd::SetWindowSize() (below)


CProgressWnd(CWnd* pParent, LPCTSTR strTitle, BOOL bSmooth=FALSE);
BOOL Create(CWnd* pParent, LPCTSTR strTitle, BOOL bSmooth=FALSE);

Construction is either via the constructor or a two-step process using the constructor and the Create function. pParent is the parent of the progress window,strTitle is the window caption title. 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.


BOOL GoModal(LPCTSTR strTitle = _T("Progress"), BOOL bSmooth=FALSE);
                                    // Make window modal

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 SetRange(int nLower, int nUpper, int nStep = 1);
                                    // Set min, max and step size

void Hide();                        // Hide the window
void Show();                        // Show the window
void Clear();                       // Clear the text and reset the 
                                    // progress bar
void SetText(LPCTSTR fmt, ...);     // Set the text in the text area

BOOL Cancelled()                    // Has the cancel button been pressed?

void SetWindowSize(int nNumTextLines, int nWindowWidth = 390);
                                    // Sets the size of the window 
                                    // according to the number of text 
                                    // lines specifed and the
                                    // desired window size in pixels.

void PeekAndPump(BOOL bCancelOnESCkey = TRUE);
                                    // Message pumping, with options of
                                    // allowing Cancel on ESC key.  

The PeekAndPump function allows messages to be pumped during long operations. The first parameter allows the window to be cancelled by pressing the ESC key.

You can also make the window modal by creating the window and calling GoModal(). This will disable the main window, and re-enable the main window when this window is destroyed. See the demo app for example code.

The window will also store and restore its position to and from the registry between incantations.

To use the window, just do something like:

CProgressWnd wndProgress(this, "Progress");

// wndProgress.GoModal(); // Call this if you want a modal window

for (int i = 0; i < 5000; i++) {

    if (wndProgress.Cancelled()) {
        MessageBox("Progress Cancelled");

or it can be done two stage as:

CProgressWnd wndProgress;

if (!wndProgress.Create(this, "Progress"))



  • 13 Apr 2002 - added SaveSettings call to OnCancel. Updated project for VC.NET.
  • 22 Apr 2002 - minor mods by Luke Gabello


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Chris Maunder
Founder CodeProject
Canada Canada
Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs The Code Project. He's been programming since 1988 while pretending to be, in various guises, an astrophysicist, mathematician, physicist, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer. He is a Microsoft Visual C++ MVP both globally and for Canada locally.

His programming experience includes C/C++, C#, SQL, MFC, ASP, ASP.NET, and far, far too much FORTRAN. He has worked on PocketPCs, AIX mainframes, Sun workstations, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.

He dodges, he weaves, and he never gets enough sleep. He is kind to small animals.

Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is into road cycling, snowboarding, rock climbing, and storm chasing.

You may also be interested in...

Comments and Discussions

QuestionHow Do I close the ProgressWindow ? Pin
sunil_rbc13-Oct-15 2:07
professionalsunil_rbc13-Oct-15 2:07 
Questionquestion Pin
kcpnevergiveup15-Apr-13 16:21
memberkcpnevergiveup15-Apr-13 16:21 
AnswerRe: question Pin
kcpnevergiveup15-Apr-13 17:01
memberkcpnevergiveup15-Apr-13 17:01 
GeneralThis is really cool.... Pin
Rangarajan Varadan8-Apr-09 6:52
memberRangarajan Varadan8-Apr-09 6:52 
Generalthanks Pin
Dirk Higbee2-Sep-08 3:17
memberDirk Higbee2-Sep-08 3:17 
QuestionProgress bar frozen Pin
Solange200831-Aug-08 12:05
memberSolange200831-Aug-08 12:05 
QuestionCrash in CProgressWnd::Create() in VS2008 Pin
oldNic15-Aug-08 7:28
memberoldNic15-Aug-08 7:28 
AnswerRe: Crash in CProgressWnd::Create() in VS2008 Pin
oldNic18-Aug-08 10:41
memberoldNic18-Aug-08 10:41 
GeneralRe: Crash in CProgressWnd::Create() in VS2008 Pin
arokicki5-Mar-09 7:57
memberarokicki5-Mar-09 7:57 
AnswerRe: Crash in CProgressWnd::Create() in VS2008 Pin
Ards6-Jun-11 18:02
memberArds6-Jun-11 18:02 
Generalerror C2504: 'CWnd' : base class undefined Pin
Luke DeStevens9-Oct-07 10:29
memberLuke DeStevens9-Oct-07 10:29 
GeneralRe: error C2504: 'CWnd' : base class undefined Pin
jaymz12-May-08 1:43
memberjaymz12-May-08 1:43 
QuestionHow get rid of flickering? Pin
Walxer28-Aug-07 13:04
memberWalxer28-Aug-07 13:04 
GeneralThank you Chris : I no more need two threads Pin
charfeddine_ahmed24-Aug-07 1:28
membercharfeddine_ahmed24-Aug-07 1:28 
QuestionAccessing Progress Window? Pin
WVP10-Aug-07 5:48
memberWVP10-Aug-07 5:48 
AnswerRe: Accessing Progress Window? Pin
charfeddine_ahmed24-Aug-07 2:21
membercharfeddine_ahmed24-Aug-07 2:21 
GeneralGood! Pin
napo@burgasnet.com26-Jun-07 3:28
membernapo@burgasnet.com26-Jun-07 3:28 
GeneralThe same for .NET Pin
_slav_4-Feb-07 3:04
member_slav_4-Feb-07 3:04 
GeneralCool ! Pin
eigen30-Sep-06 18:03
membereigen30-Sep-06 18:03 
Generalproblem used in worker thread Pin
how jack24-Feb-06 9:48
memberhow jack24-Feb-06 9:48 
GeneralRe: problem used in worker thread Pin
Kevin Done9-Nov-11 21:21
memberKevin Done9-Nov-11 21:21 
GeneralCrash on MouseOver Pin
Staati25-Jan-06 4:48
memberStaati25-Jan-06 4:48 
GeneralRe: Crash on MouseOver Pin
Staati26-Jan-06 5:37
memberStaati26-Jan-06 5:37 
GeneralAlways crashes for me :-( Pin
EthannCastell4-Oct-05 0:49
memberEthannCastell4-Oct-05 0:49 
I downloaded the sample and it looks cool.

But whenever my code tries to initialize an object of class CProgressWnd, I get an Assert from winocc.cpp on line 279. I am trying to display the progress dialog from another modal dialog. I don't think this should be a problem though, should it ?

Perhaps I'm not passing the correct *Cwnd as the first parameter. I've tried "this" and "NULL" but neither seem to work. I'm using VC++ 6.0 with service pack 6. I would really appreciate any ideas that may help.

Generalgreat timesaver Pin
jefflewis26-Aug-05 22:38
memberjefflewis26-Aug-05 22:38 
Generalget information popup Pin
Tailana1-Jun-05 22:33
memberTailana1-Jun-05 22:33 
GeneralConsole Pin
bachi13-Feb-05 21:12
memberbachi13-Feb-05 21:12 
GeneralWorkaround to bitmap buttons showing through Pin
Tom Archer9-Jan-05 8:09
memberTom Archer9-Jan-05 8:09 
GeneralRe: Workaround to bitmap buttons showing through Pin
kido972-Nov-09 22:43
memberkido972-Nov-09 22:43 
GeneralVC++ 7.0 Problem Pin
Anonymous22-Oct-04 1:36
sussAnonymous22-Oct-04 1:36 
GeneralRe: VC++ 7.0 Problem Pin
Solion22-Oct-04 1:41
memberSolion22-Oct-04 1:41 
GeneralRe: VC++ 7.0 Problem Pin
seafishkakakaka28-Apr-08 12:08
memberseafishkakakaka28-Apr-08 12:08 
GeneralGoModal() always on top Pin
LizardKingSchwing5-Apr-04 23:33
memberLizardKingSchwing5-Apr-04 23:33 
GeneralRe: GoModal() always on top Pin
mcvf26-May-04 7:10
membermcvf26-May-04 7:10 
GeneralSmall cosmetic fix Pin
phykell24-Sep-03 2:40
memberphykell24-Sep-03 2:40 
QuestionHow to call up the progressbar Pin
Pelge28-Apr-03 9:08
memberPelge28-Apr-03 9:08 
QuestionCrash? Pin
Anonymous2-Oct-02 16:37
sussAnonymous2-Oct-02 16:37 
QuestionPoopup...? Pin
Hockey25-Aug-02 16:39
memberHockey25-Aug-02 16:39 
AnswerRe: Poopup...? Pin
Chris Maunder11-Dec-02 10:52
adminChris Maunder11-Dec-02 10:52 
QuestionSmall bug with title ? Pin
Jonathan de Halleux29-Apr-02 0:01
memberJonathan de Halleux29-Apr-02 0:01 
GeneralThanks for the minor mods Pin
Geert Delmeiren22-Apr-02 22:41
memberGeert Delmeiren22-Apr-02 22:41 
GeneralRe: Thanks for the minor mods Pin
Luke Gabello16-May-02 1:51
memberLuke Gabello16-May-02 1:51 
GeneralJust a spelling error Pin
Brit22-Apr-02 11:30
memberBrit22-Apr-02 11:30 
GeneralRe: Just a spelling error Pin
Ravi Bhavnani22-Apr-02 11:51
memberRavi Bhavnani22-Apr-02 11:51 
GeneralRe: Just a spelling error Pin
Chris Maunder22-Apr-02 13:49
adminChris Maunder22-Apr-02 13:49 
GeneralSmall improvement Pin
Geert Delmeiren12-Apr-02 1:44
memberGeert Delmeiren12-Apr-02 1:44 
GeneralShort cut keys Pin
Geert Delmeiren11-Apr-02 5:25
memberGeert Delmeiren11-Apr-02 5:25 
GeneralExiting Pin
Hal Baird3-Apr-02 0:56
memberHal Baird3-Apr-02 0:56 
GeneralWher to call the function Pin
housefreak14-Mar-02 13:03
memberhousefreak14-Mar-02 13:03 
GeneralRe: Wher to call the function Pin
AJ Wilkinson10-Dec-02 13:12
memberAJ Wilkinson10-Dec-02 13:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160525.2 | Last Updated 22 Apr 2002
Article Copyright 1999 by Chris Maunder
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid