Click here to Skip to main content
Licence CPOL
First Posted 3 Nov 2008
Views 30,051
Bookmarked 80 times

XProgressWnd - A Popup Progress Window with optional AVI and time

By | 3 Nov 2008 | Article
XProgressWnd is a popup progress window that display a progress control and optional AVI animation and estimated time left, without requiring a dialog resource.

Introduction

I have been using Chris Maunder's excellent Popup Progress Window for some time now, and wanted to add an AVI animation and "time left" display similar to what you see in IE:

screenshot

XProgressWnd Window

Here is what XProgressWnd looks like:

screenshot

and when you select all options:

screenshot

Changes in Version 2.0

Here are the changes I made to Chris's control:
screenshot Added optional AVI animation.
screenshot Added optional estimated time left, with ability to customize labels.
screenshot Added [X] (Close) button to progress window.
screenshot Used memory DC to eliminate flickering of message text. Text can now be changed dynamically during progress display, with no flickering.
screenshot Fixed problem with NONCLIENTMETRICS and VS2008, plus several other issues reported in forum.

Demo App

The demo app allows you to select an AVI, the progress range, and other options:

screenshot

How To Use

To integrate CXProgressWnd into your app, you first need to add following files to your project:

  • XProgressWnd.cpp
  • XProgressWnd.h

Next, include header file XProgressWnd.h in appropriate project files. Now you are ready to start using CXProgressWnd.

Example 1 - Using XProgressWnd within a single function

The file XProgressWndTestDlg.cpp gives an example:
    CXProgressWnd wndProgress(this, 
        _T("Progress"), (LPCTSTR)nAvi[m_nAvi], nAviHeight[m_nAvi]);
    
    if (m_bModal)
        wndProgress.GoModal(this);

    wndProgress.SetRange(0, nRange[m_nRange])
               .EnableTimeLeft(m_bTimeLeft)
               .SetText(_T("This is a progress window...\n\n")
                        _T("Try dragging it around, hitting Cancel or pressing ESC."));
    
    for (int i = 0; i < nRange[m_nRange]; i++) 
    {
        if (i > (4000*(m_nRange+1)))
        {
            // no flickering!
            wndProgress.SetText(_T("\nThis is step #%d"), i);
        }
        wndProgress.StepIt();
        wndProgress.PeekAndPump();
        
        if (wndProgress.Cancelled()) 
        {
            AfxMessageBox(_T("Operation Canceled."));
            break;
        }
    }

Example 2 - Creating XProgressWnd in one function, and using it in another

You can create the XProgressWnd in one part of your program, and use it in another, by declaring a class member variable:
    CXProgressWnd *m_pwndProgress;
To create the XProgressWnd:
    m_pwndProgress = new CXProgressWnd(this, _T("Progress"), 
        (LPCTSTR)nAvi[m_nAvi], nAviHeight[m_nAvi]);
    
    if (m_bModal)
        m_pwndProgress->GoModal(this);

    m_pwndProgress->SetRange(0, nRange[m_nRange]);
    m_pwndProgress->EnableTimeLeft(m_bTimeLeft);
    m_pwndProgress->SetText(_T("This is a progress window...\n\n")
                            _T("Try dragging it around, hitting Cancel or pressing ESC."));
and then you can use it in another function like this:
    for (int i = 0; i < nRange[m_nRange]; i++) 
    {
        if (i > (4000*(m_nRange+1)))
        {
            // no flickering!
            m_pwndProgress->SetText(_T("\nThis is step #%d"), i);
        }
        m_pwndProgress->StepIt();
        m_pwndProgress->PeekAndPump();
        
        if (m_pwndProgress->Cancelled()) 
        {
            AfxMessageBox(_T("Operation Canceled."));
            break;
        }
    }
When you finish with it, don't forget to delete it:
    delete m_pwndProgress;

Revision History

Version 2.0 - 2008 November 3

  • Initial public release.

Usage

This software is released into the public domain. You are free to use it in any way you like, except that you may not sell this source code. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.

License

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

About the Author

Hans Dietrich

Software Developer (Senior)
Hans Dietrich Software
United States United States

Member

I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.
 
Recently, I have moved to Los Angeles where I am doing consulting and development work.
 
For consulting and custom software development, please see www.hdsoft.org.







Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 PinmemberJoerg Hoffmann0:13 2 Aug '10  
QuestionProblem with small range PinmemberJoerg Hoffmann4:53 28 Jul '10  
AnswerRe: Problem with small range PinmentorHans Dietrich5:51 28 Jul '10  
GeneralRe: Problem with small range PinmemberJoerg Hoffmann11:24 28 Jul '10  
GeneralRe: Problem with small range PinmentorHans Dietrich2:41 29 Jul '10  
GeneralRe: Problem with small range PinmemberJoerg Hoffmann21:30 1 Aug '10  
GeneralGreat Job! Pinmembergegegegeda1:57 15 Jun '10  
GeneralStack around the variable 'ncm' was corrupted PinmemberSonar10:42 17 Sep '09  
GeneralRe: Stack around the variable 'ncm' was corrupted PinmvpHans Dietrich16:18 17 Sep '09  
GeneralSuper but... PinmemberKeith Dennis3:37 9 Jan '09  
GeneralPerfect PinmemberAbhijit Jana3:19 12 Dec '08  
GeneralWow! PinmemberPaul Conrad18:34 10 Nov '08  
QuestionWho gave it a one? Pinmember.dan.g.11:42 6 Nov '08  
AnswerRe: Who gave it a one? PinmvpHans Dietrich12:21 6 Nov '08  
GeneralRe: Who gave it a one? PinmemberHamed Mosavi4:39 9 Dec '08  
JokeRe: Who gave it a one? Pinmembersk8er_boy2874:20 12 Dec '08  
AnswerRe: Who gave it a one? PinmemberPaul Conrad18:35 10 Nov '08  
AnswerRe: Who gave it a one? PinmemberStefano Bettega1:35 11 Nov '08  
GeneralRe: Who gave it a one? PinmemberSabuncu4:12 7 Feb '09  
GeneralLengthly operations PinmemberDavide Zaccanti3:22 4 Nov '08  
GeneralRe: Lengthly operations PinmvpHans Dietrich5:39 4 Nov '08  
GeneralRe: Lengthly operations PinmemberDavide Zaccanti6:01 4 Nov '08  
GeneralRe: Lengthly operations PinmemberNGS 5496725:42 4 Nov '08  
GeneralRe: Lengthly operations PinmemberDavide Zaccanti6:07 4 Nov '08  
GeneralRe: Lengthly operations PinmemberJoseph Mccornell5:16 11 Nov '08  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 3 Nov 2008
Article Copyright 2008 by Hans Dietrich
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid