// TimeOutDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Timer.h"
#include "TimeOutDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTimeOutDlg dialog


CTimeOutDlg::CTimeOutDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTimeOutDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTimeOutDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CTimeOutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTimeOutDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTimeOutDlg, CDialog)
	//{{AFX_MSG_MAP(CTimeOutDlg)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTimeOutDlg message handlers

BOOL CTimeOutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	m_SecondsLeft = 5;
	SetTimer( 1, 1000, 0 );
	ShowSeconds();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CTimeOutDlg::OnTimer(UINT nIDEvent) 
{
	// Decrement seconds left and update the display
	--m_SecondsLeft;
	ShowSeconds();

	// If no more seconds left, then close the dialog
	if( !m_SecondsLeft )
		EndDialog( IDOK );

	// Comment out the following line:
//	CDialog::OnTimer(nIDEvent);
}

void CTimeOutDlg::ShowSeconds()
{
	// Display the remaining seconds in the IDC_REMAINING static control:
	CString Tmp;
	Tmp.Format( "Seconds remaining: %d", m_SecondsLeft );
	SetDlgItemText( IDC_REMAINING, Tmp );
}
