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:
XProgressWnd Window
Here is what
XProgressWnd looks like:
and when you select all options:
Changes in Version 2.0
Here are the changes I made to Chris's control:
|
Added optional AVI animation.
|
|
Added optional estimated time left, with ability to customize labels.
|
|
Added [X] (Close) button to progress window.
|
|
Used memory DC to eliminate flickering of message text. Text can
now be changed dynamically during progress display, with no flickering.
|
|
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:
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)))
{
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)))
{
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
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.