home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Windows Gam…ming Gurus (2nd Edition)
/
Disc2.iso
/
common
/
msdev98
/
bin
/
ide
/
progdlg.dll
/
TEMPLATE
/
149
< prev
Wrap
Text File
|
1998-06-18
|
6KB
|
246 lines
// $$VAL:CppFile$$ : implementation file
// CG: This file was added by the Progress Dialog component
#include "stdafx.h"
#include "$$VAL:ResourceInclude$$"
#include "$$VAL:HeaderFile$$"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// $$VAL:ClassName$$ dialog
$$VAL:ClassName$$::$$VAL:ClassName$$(UINT nCaptionID)
{
m_nCaptionID = $$VAL:StringID$$;
if (nCaptionID != 0)
m_nCaptionID = nCaptionID;
$$IF:CancelButton$$
m_bCancel=FALSE;
$$ENDIF$$
m_nLower=$$VAL:Lower$$;
m_nUpper=$$VAL:Upper$$;
m_nStep=$$VAL:Step$$;
//{{AFX_DATA_INIT($$VAL:ClassName$$)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_bParentDisabled = FALSE;
}
$$VAL:ClassName$$::~$$VAL:ClassName$$()
{
if(m_hWnd!=NULL)
DestroyWindow();
}
BOOL $$VAL:ClassName$$::DestroyWindow()
{
ReEnableParent();
return CDialog::DestroyWindow();
}
void $$VAL:ClassName$$::ReEnableParent()
{
if(m_bParentDisabled && (m_pParentWnd!=NULL))
m_pParentWnd->EnableWindow(TRUE);
m_bParentDisabled=FALSE;
}
BOOL $$VAL:ClassName$$::Create(CWnd *pParent)
{
// Get the true parent of the dialog
m_pParentWnd = CWnd::GetSafeOwner(pParent);
// 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.
if((m_pParentWnd!=NULL) && m_pParentWnd->IsWindowEnabled())
{
m_pParentWnd->EnableWindow(FALSE);
m_bParentDisabled = TRUE;
}
if(!CDialog::Create($$VAL:ClassName$$::IDD,pParent))
{
ReEnableParent();
return FALSE;
}
return TRUE;
}
void $$VAL:ClassName$$::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP($$VAL:ClassName$$)
DDX_Control(pDX, CG_IDC_PROGDLG_PROGRESS, m_Progress);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP($$VAL:ClassName$$, CDialog)
//{{AFX_MSG_MAP($$VAL:ClassName$$)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
$$IF:ShowStatus$$
void $$VAL:ClassName$$::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);
}
$$ENDIF$$
void $$VAL:ClassName$$::OnCancel()
{
$$IF:CancelButton$$
m_bCancel=TRUE;
$$ENDIF$$
}
void $$VAL:ClassName$$::SetRange(int nLower,int nUpper)
{
m_nLower = nLower;
m_nUpper = nUpper;
m_Progress.SetRange(nLower,nUpper);
}
int $$VAL:ClassName$$::SetPos(int nPos)
{
PumpMessages();
$$IF:ShowPercent$$
int iResult = m_Progress.SetPos(nPos);
UpdatePercent(nPos);
return iResult;
$$ENDIF$$
$$IF:!ShowPercent$$
return m_Progress.SetPos(nPos);
$$ENDIF$$
}
int $$VAL:ClassName$$::SetStep(int nStep)
{
m_nStep = nStep; // Store for later use in calculating percentage
return m_Progress.SetStep(nStep);
}
int $$VAL:ClassName$$::OffsetPos(int nPos)
{
PumpMessages();
$$IF:ShowPercent$$
int iResult = m_Progress.OffsetPos(nPos);
UpdatePercent(iResult+nPos);
return iResult;
$$ENDIF$$
$$IF:!ShowPercent$$
return m_Progress.OffsetPos(nPos);
$$ENDIF$$
}
int $$VAL:ClassName$$::StepIt()
{
PumpMessages();
$$IF:ShowPercent$$
int iResult = m_Progress.StepIt();
UpdatePercent(iResult+m_nStep);
return iResult;
$$ENDIF$$
$$IF:!ShowPercent$$
return m_Progress.StepIt();
$$ENDIF$$
}
void $$VAL:ClassName$$::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);
}
}
}
$$IF:CancelButton$$
BOOL $$VAL:ClassName$$::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;
}
$$ENDIF$$
$$IF:ShowPercent$$
void $$VAL:ClassName$$::UpdatePercent(int nNewPos)
{
CWnd *pWndPercent = GetDlgItem(CG_IDC_PROGDLG_PERCENT);
int nPercent;
int nDivisor = m_nUpper - m_nLower;
ASSERT(nDivisor>0); // m_nLower should be smaller than m_nUpper
int nDividend = (nNewPos - m_nLower);
ASSERT(nDividend>=0); // Current position should be greater than m_nLower
nPercent = nDividend * 100 / nDivisor;
// Since the Progress Control wraps, we will wrap the percentage
// along with it. However, don't reset 100% back to 0%
if(nPercent!=100)
nPercent %= 100;
// Display the percentage
CString strBuf;
strBuf.Format(_T("%d%c"),nPercent,_T('%'));
CString strCur; // get current percentage
pWndPercent->GetWindowText(strCur);
if (strCur != strBuf)
pWndPercent->SetWindowText(strBuf);
}
$$ENDIF$$
/////////////////////////////////////////////////////////////////////////////
// $$VAL:ClassName$$ message handlers
BOOL $$VAL:ClassName$$::OnInitDialog()
{
CDialog::OnInitDialog();
m_Progress.SetRange(m_nLower,m_nUpper);
m_Progress.SetStep(m_nStep);
m_Progress.SetPos(m_nLower);
CString strCaption;
VERIFY(strCaption.LoadString(m_nCaptionID));
SetWindowText(strCaption);
return TRUE;
}