⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xaviplay.cpp

📁 这是一本学习 window编程的很好的参考教材
💻 CPP
字号:
#include "stdafx.h"

#include "XAviPlay.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;

  
    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 )
{
    

    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 )
{
   

    m_pIDlg->SetAnimation ( _Module.GetResourceInstance(), 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;



    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 ( HWND hWndParent )
{
HRESULT hr;

    

    hr = m_pIDlg->StartProgressDialog ( hWndParent,
                                        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 ( HWND hWndParent)
{
HRESULT hr;

  

    hr = m_pIDlg->StartProgressDialog ( hWndParent,
                                        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;

   

    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 )
{
   

    m_dwLastMaxProgress = dwMax;
    m_u64LastMaxProgress = 0;

    m_pIDlg->SetProgress ( dwProgress, dwMax );
}

// UpdateProgress: Sets the dialog's progress bar.  The current progress value
// is limited to a DWORD.
// Parameters:
//   dwProgress: The current progress value.
// Note:
//   You must call UpdateProgress(DWORD dwProgress, DWORD dwMax) at least 
//   once to set the max value.
void CSHProgressWnd::UpdateProgress ( DWORD dwProgress )
{
   ;

    m_pIDlg->SetProgress ( dwProgress, m_dwLastMaxProgress );
}

// UpdateProgress: Sets the dialog's progress bar.  The current and max progress
// values can be 64 bits.
// Parameters:
//   u64Progress: The current progress value.
//   u64Max: 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 ( ULONGLONG u64Progress,
                                      ULONGLONG u64ProgressMax )
{

    m_dwLastMaxProgress = 0;
    m_u64LastMaxProgress = u64ProgressMax;

    m_pIDlg->SetProgress64 ( u64Progress, u64ProgressMax );
}

// UpdateProgress: Sets the dialog's progress bar.  The current progress value
// can be 64 bits.
// Parameters:
//   u64Progress: The current progress value.
// Note:
//   You must call UpdateProgress(DWORD dwProgress, DWORD dwMax) at least 
//   once to set the max value.
void CSHProgressWnd::UpdateProgress ( ULONGLONG u64Progress )
{
   
   
    m_pIDlg->SetProgress64 ( u64Progress, m_u64LastMaxProgress );
}


//////////////////////////////////////////////////////////////////////
// CSHProgressWnd - updating the progress

// HasUserCanceled: Returns true if the user has clicked the Cancel 
// button.  You should call this periodically during your processing.
bool CSHProgressWnd::HasUserCanceled()
{
   
    return 0 != m_pIDlg->HasUserCancelled();
}

// EndDialog: Closes the progress dialog.
void CSHProgressWnd::EndDialog()
{
    

    if ( m_bDlgVisible )
        {
        m_pIDlg->StopProgressDialog();
        m_bDlgVisible = false;
        }
}

// ResetTimer: Restarts the dialog's timer that is used to estimate the time
// remaining.  You normally don't have to call this function, since the dialog
// will gague the time by the time between calls to 
// IProgressDialog::StartProgressDialog() and IProgressDialog::SetProgress().
// If you have a long period of inactivity between DoModal/DoModeless and
// your first UpdateProgress(), then call this function right before the first
// call to UpdateProgress().
void CSHProgressWnd::ResetTimer()
{
    

    m_pIDlg->Timer ( PDTIMER_RESET, NULL );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -