// Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved // ProgDlg.cpp : implementation file // CG: This file was added by the Progress Dialog component #include "precomp.h" #include "resource.h" #include "wbemidl.h" #include "olemsclient.h" #include "ProgDlg.h" #ifdef _DEBUG #undef THIS_FILE static char BASED_CODE THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CProgressDlg dialog CProgressDlg::CProgressDlg(UINT nCaptionID) { m_bCancel=FALSE; //{{AFX_DATA_INIT(CProgressDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_bParentDisabled = FALSE; } CProgressDlg::~CProgressDlg() { if(m_hWnd!=NULL) DestroyWindow(); m_bCancel=FALSE; } BOOL CProgressDlg::DestroyWindow() { m_bCancel=FALSE; ReEnableParent(); return CDialog::DestroyWindow(); } void CProgressDlg::ReEnableParent() { CWnd *pParentOwner = CWnd::GetSafeOwner(m_pParentWnd); if(m_bParentDisabled && (pParentOwner!=NULL)) pParentOwner->EnableWindow(TRUE); m_bParentDisabled=FALSE; } BOOL CProgressDlg::Create(CWnd *pParent) { m_pParentWnd = pParent; m_bCancel=FALSE; // m_bParentDisabled is used to re-enable the parent window // when the dialog is destroyed. So we don't want to set // it to TRUE unless the parent was already enabled. // Get the true parent of the dialog CWnd *pParentOwner = CWnd::GetSafeOwner(m_pParentWnd); if((pParentOwner!=NULL) && pParentOwner->IsWindowEnabled()) { pParentOwner->EnableWindow(FALSE); m_bParentDisabled = TRUE; } if(!CDialog::Create(CProgressDlg::IDD,pParentOwner)) { ReEnableParent(); return FALSE; } return TRUE; } void CProgressDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CProgressDlg) DDX_Control(pDX, CG_IDC_PROGDLG_STATUS, m_cstaticMessage); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CProgressDlg, CDialog) //{{AFX_MSG_MAP(CProgressDlg) ON_WM_CREATE() //}}AFX_MSG_MAP END_MESSAGE_MAP() void CProgressDlg::SetStatus(LPCTSTR lpszMessage) { ASSERT(m_hWnd); // Don't call this _before_ the dialog has // been created. Can be called from OnInitDialog CWnd *pWndStatus = GetDlgItem(CG_IDC_PROGDLG_STATUS); // Verify that the static text control exists ASSERT(pWndStatus!=NULL); pWndStatus->SetWindowText(lpszMessage); } void CProgressDlg::OnCancel() { m_bCancel=TRUE; } void CProgressDlg::PumpMessages() { // Must call Create() before using the dialog ASSERT(m_hWnd!=NULL); MSG msg; // Handle dialog messages while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if(!IsDialogMessage(&msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } } BOOL CProgressDlg::CheckCancelButton() { // Process all pending messages PumpMessages(); // Reset m_bCancel to FALSE so that // CheckCancelButton returns FALSE until the user // clicks Cancel again. This will allow you to call // CheckCancelButton and still continue the operation. // If m_bCancel stayed TRUE, then the next call to // CheckCancelButton would always return TRUE BOOL bResult = m_bCancel; //m_bCancel = FALSE; return bResult; } ///////////////////////////////////////////////////////////////////////////// // CProgressDlg message handlers BOOL CProgressDlg::OnInitDialog() { CDialog::OnInitDialog(); m_bCancel=FALSE; m_cstaticMessage.SetWindowText(m_csMessage); SetWindowText(m_csLabel); MoveWindowToLowerLeftOfOwner(this); return TRUE; } int CProgressDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) { lpCreateStruct->style |= WS_EX_TOPMOST; if (CDialog::OnCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specialized creation code here return 0; }