//////////////////////////////////////////////////////////////////////
//
// SHProgressWnd.cpp: implementation of the CSHProgressWnd class.
//
//////////////////////////////////////////////////////////////////////
//
// This is a basic wrapper class for the IE 5 built-in progress dialog.
// Written by Michael Dunn, mdunn at inreach dot com.
// You can use it to your heart's content, just give me credit where
// credit is due. I'd also appreciate an email telling me if you use
// this code in a publicly-released program, just to satisfy my own
// curiosity about whether folks are really using the code.
//
// Notes:
// 1. You need to call AfxOleInit() before using this class, preferably
// in your app's InitInstance() function.
//
/////////////////////////////////////////////////////////////////////////////
//
// Release history:
// Jan 31, 2000: v1.0 - First release!
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "IProgDlg.h"
#include "SHProgressWnd.h"
#include <atlconv.h>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
// Uncomment these lines if you get unresolved external errors on these
// two GUIDs.
//extern "C" const GUID CLSID_ProgressDialog = {0xf8383852, 0xfcd3, 0x11d1, 0xa6, 0xb9, 0x0, 0x60, 0x97, 0xdf, 0x5b, 0xd4};
//extern "C" const GUID IID_IProgressDialog = {0xebbc7c04, 0x315e, 0x11d2, 0xb6, 0x2f, 0x0, 0x60, 0x97, 0xdf, 0x5b, 0xd4};
//////////////////////////////////////////////////////////////////////
// CSHProgressWnd Construction/Destruction
CSHProgressWnd::CSHProgressWnd() :
m_bValid ( false ), m_bDlgVisible ( false ),
m_dwDlgFlags ( PROGDLG_NORMAL ), m_dwLastMaxProgress (0),
m_u64LastMaxProgress (0), m_pIDlg ( NULL )
{
HRESULT hr;
hr = CoCreateInstance ( CLSID_ProgressDialog, NULL, CLSCTX_INPROC_SERVER,
IID_IProgressDialog, (void**) &m_pIDlg );
if ( SUCCEEDED(hr) )
m_bValid = true;
}
CSHProgressWnd::~CSHProgressWnd()
{
if ( m_bValid )
{
if ( m_bDlgVisible )
m_pIDlg->StopProgressDialog();
m_pIDlg->Release();
}
}
//////////////////////////////////////////////////////////////////////
// CSHProgressWnd dialog setup functions
// SetTitle: Sets the text that appears in the dialog caption bar.
void CSHProgressWnd::SetTitle ( LPCTSTR szTitle )
{
USES_CONVERSION;
ASSERT ( AfxIsValidString ( szTitle ));
ASSERT ( m_bValid );
m_pIDlg->SetTitle ( T2COLE(szTitle) );
}
// SetAnimation: Specifies the module that contains an AVI resource,
// and the resource ID.
void CSHProgressWnd::SetAnimation ( HINSTANCE hinst, UINT uRsrcID )
{
ASSERT ( m_bValid );
m_pIDlg->SetAnimation ( hinst, uRsrcID );
}
// SetAnimation: Specifies the resource ID of an AVI resource. The
// module handle is the value returned by AfxGetResourceHandle().
void CSHProgressWnd::SetAnimation ( UINT uRsrcID )
{
ASSERT ( m_bValid );
m_pIDlg->SetAnimation ( AfxGetResourceHandle(), uRsrcID );
}
// SetCancelMessage: Specifies text that the dialog will display on
// line 3 if the user clicks the Cancel button.
void CSHProgressWnd::SetCancelMessage ( LPCTSTR szMessage )
{
USES_CONVERSION;
ASSERT ( m_bValid );
ASSERT ( AfxIsValidString ( szMessage ));
m_pIDlg->SetCancelMsg ( T2COLE(szMessage), NULL );
}
// SetCalculateTime: Sets whether the dialog will estimate the time remaining
// before the maximum progress value is reached. Passing true makes line
// 3 unavailable to SetLineText().
void CSHProgressWnd::SetCalculateTime ( bool bCalculate /*=true*/ )
{
m_dwDlgFlags &= ~(PROGDLG_NOTIME | PROGDLG_AUTOTIME);
if ( bCalculate )
m_dwDlgFlags |= PROGDLG_AUTOTIME;
else
m_dwDlgFlags |= PROGDLG_NOTIME;
}
// SetAllowMinimize: Sets whether the dialog will have a minimize button.
// **NOTE** This is currently broken (in the COM object itself), and the
// dialog will always have a minimize button.
void CSHProgressWnd::SetAllowMinimize ( bool bAllow /*=true*/ )
{
if ( bAllow )
m_dwDlgFlags &= ~PROGDLG_NOMINIMIZE;
else
m_dwDlgFlags |= PROGDLG_NOMINIMIZE;
}
// SetShowProgressBar: Sets whether the dialog will have a progress bar.
void CSHProgressWnd::SetShowProgressBar ( bool bShow /*=true*/ )
{
if ( bShow )
m_dwDlgFlags &= ~PROGDLG_NOPROGRESSBAR;
else
m_dwDlgFlags |= PROGDLG_NOPROGRESSBAR;
}
//////////////////////////////////////////////////////////////////////
// CSHProgressWnd - showing the dialog
// ShowModal: Shows the dialog as a modal window. pwndParent is a pointer
// to the parent window. Returns an HRESULT - test with the SUCCEEDED()
// macro to determine if the dialog was created successfully. If the
// return value is a failure HRESULT, it indicates the error return from
// IProgressDialog::StartProgressDialog()
HRESULT CSHProgressWnd::ShowModal ( CWnd* pwndParent )
{
HRESULT hr;
ASSERT ( m_bValid );
ASSERT_VALID ( pwndParent );
hr = m_pIDlg->StartProgressDialog ( pwndParent->GetSafeHwnd(),
NULL,
m_dwDlgFlags | PROGDLG_MODAL,
NULL );
if ( SUCCEEDED(hr) )
{
m_bDlgVisible = true;
}
return hr;
}
// ShowModeless: Shows the dialog as a modeless window. pwndParent is a pointer
// to the parent window. Returns an HRESULT - test with the SUCCEEDED()
// macro to determine if the dialog was created successfully. If the
// return value is a failure HRESULT, it indicates the error return from
// IProgressDialog::StartProgressDialog()
HRESULT CSHProgressWnd::ShowModeless ( CWnd* pwndParent )
{
HRESULT hr;
ASSERT ( m_bValid );
ASSERT_VALID ( pwndParent );
hr = m_pIDlg->StartProgressDialog ( pwndParent->GetSafeHwnd(),
NULL, m_dwDlgFlags, NULL );
if ( SUCCEEDED(hr) )
{
m_bDlgVisible = true;
}
return hr;
}
//////////////////////////////////////////////////////////////////////
// CSHProgressWnd - updating the progress
// SetLineText: Sets one of the three lines of text in the dialog.
// Parameters:
// dwLine: Must be 1, 2, or 3. The first two lines are above the progress
// bar, and the third line is below the progress bar. Line 3 is
// unavailable if the dialog is showing the estimated time remaining.
// szText: Text to display.
// bCompactPath: Pass true if szText is a file name or path. The dialog
// will shorten the path if necessary to make it fit in the
// dialog.
void CSHProgressWnd::SetLineText ( DWORD dwLine,
LPCTSTR szText,
bool bCompactPath /*=false*/ )
{
USES_CONVERSION;
ASSERT ( AfxIsValidString ( szText ));
ASSERT ( dwLine >= 1 && dwLine <= 3 );
ASSERT ( m_bValid );
m_pIDlg->SetLine ( dwLine, T2COLE(szText), bCompactPath, NULL );
}
// UpdateProgress: Sets the dialog's progress bar. The current and max progress
// values are limited to DWORDs.
// Parameters:
// dwProgress: The current progress value.
// dwMax: The maximum progress value (representing completion)
// Note:
// You only have to call this once to set the max value. Afterwards, you
// can call UpdateProgress(DWORD dwProgress) as long as the max value
// doesn't change.
void CSHProgressWnd::UpdateProgress ( DWORD dwProgress, DWORD dwMax )
{
ASSERT ( m_bValid );
ASSERT ( 0 != dwMax );
m_dwLastMaxProgress = dwMax;
m_u64LastMaxProgress = 0;
m_pIDlg->SetProgr
- 1
- 2
- 3
前往页