diff options
author | Stef Walter <stef@thewalter.net> | 2003-09-17 19:07:23 +0000 |
---|---|---|
committer | Stef Walter <stef@thewalter.net> | 2003-09-17 19:07:23 +0000 |
commit | 3f95d417d9e623ac0c74df8ef11d7a01846392dd (patch) | |
tree | 45ec73f2dc07eafd7f41a6f62a8cdfbaa279469f /NSCmpts/ProgressDlg.cpp |
Diffstat (limited to 'NSCmpts/ProgressDlg.cpp')
-rw-r--r-- | NSCmpts/ProgressDlg.cpp | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/NSCmpts/ProgressDlg.cpp b/NSCmpts/ProgressDlg.cpp new file mode 100644 index 0000000..9f1ae5c --- /dev/null +++ b/NSCmpts/ProgressDlg.cpp @@ -0,0 +1,151 @@ +// ProgressDlg.cpp : Implementation of CProgressDlg +#include "stdafx.h" +#include "ProgressDlg.h" + +///////////////////////////////////////////////////////////////////////////// +// CProgressDlg + +CActionProgressDlg::CActionProgressDlg(IUnknown* pSite, UINT nIDD) + : CDialogImplEx(nIDD) +{ + m_pUnk = pSite; + m_bCancel = false; +} + +CActionProgressDlg::~CActionProgressDlg() +{ + if(IsWindow()) + DestroyWindow(); + + // Release any pointers we're holding on to + if(m_pUnk) + m_pUnk->Release(); + if(m_pErrorLog) + m_pErrorLog->Release(); +} + +LRESULT CActionProgressDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + // Used later + m_ctlProgress = GetDlgItem(IDC_PROGRESS); + + CenterWindow(GetDesktopWindow()); + + // This sets up the Event Mechanism + if(m_pUnk != NULL) + DispEventAdvise(m_pUnk); // Pointer from IObjectWithSite + + return 1; // Let the system set the focus +} + +LRESULT CActionProgressDlg::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + + // Release any pointers we're holding on to + if(m_pUnk) + { + // Drop the Event Stuff + DispEventUnadvise(m_pUnk); // Pointer from IObjectWithSite + + m_pUnk->Release(); + } + if(m_pErrorLog) + m_pErrorLog->Release(); + + return 0; +} + +// Update Message from Action Engine +LRESULT CActionProgressDlg::OnUpdateFile(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + NS_UPDATE_DATA* pData = (NS_UPDATE_DATA*)lParam; + + // If there 0 in the total then clear + if(pData->lTot == 0) + { + m_ctlProgress.SetRange(0, 1); + m_ctlProgress.SetPos(0); + } + else + { + // If total != -1 then change range + if(pData->lTot > 0) + m_ctlProgress.SetRange(0, pData->lTot); + + // If Current changed (!= -1) then set state + if(pData->lCur >= 0) + m_ctlProgress.SetPos(pData->lCur); + } + + // If there's a message display it + if(pData->szMessage1) + ::SetWindowText(GetDlgItem(IDC_MESSAGE1), pData->szMessage1); + if(pData->szMessage2) + ::SetWindowText(GetDlgItem(IDC_MESSAGE2), pData->szMessage2); + + // If m_bCancel is set then this cancels the CActionEngine + return m_bCancel ? 0 : 1; +} + +// Called in response to the button being pressed, window being closed, or +// event being fired +LRESULT CActionProgressDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) +{ + // This gets checked when the Engine sends and Update (OnUpdateFile) + m_bCancel = true; + + // We're working on cancelling so reflect that in UI + ::SetWindowText(GetDlgItem(IDCANCEL), _T("Cancelling...")); + ::EnableWindow(GetDlgItem(IDCANCEL), FALSE); + return 0; +} + +// Called when event Fired +STDMETHODIMP CActionProgressDlg::OnCancelEv() +{ + // Just call normal cancel event + BOOL bHandled = TRUE; + OnCancel(0, 0, NULL, bHandled); + + return S_OK; +}; + +// Error Message from CActionEngine +LRESULT CActionProgressDlg::OnError(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + // See if we can get an INightSecErrorLog pointer that IObjectWithSite + // gave us + if(m_pErrorLog == NULL) + m_pErrorLog = m_pUnk; + + if(m_pErrorLog == NULL) + return 0; + + // Create a new NightSecError object + CComObject<CActionErrorImpl>* pError = NULL; + HRESULT hr = CComObject<CActionErrorImpl>::CreateInstance(&pError); + + if(FAILED(hr)) + return 0; + + // Set info on the Error Object + NS_ERROR_DATA* pData = (NS_ERROR_DATA*)lParam; + pError->SetError(pData->szDesc, pData->hRes); + pError->Attach((CAction*)pData->lParam); + + // Send it to the INightSecErrorLog + m_pErrorLog->AddError(pError->GetUnknown()); + + return 0; +} + +// Starts the AVI file playing from resources +bool CActionProgressDlg::PlayAmination(UINT nID) +{ + ASSERT(IsWindow()); + ASSERT(GetDlgItem(IDC_ANIMATION)); + + // Dialog box should have AutoPlay enabled + return ((BOOL)::SendMessage(GetDlgItem(IDC_ANIMATION), ACM_OPEN, 0, (LPARAM)MAKEINTRESOURCE(nID))) ? true : false; +} + |