// InfoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "LocalErrors.h"
#include "InfoDlg.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CInfoDlg dialog


CInfoDlg::CInfoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CInfoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CInfoDlg)
	m_csCorrectiveAction = _T("");
	m_csResults = _T("");
	m_csWhatHappened = _T("");
	//}}AFX_DATA_INIT
	m_csCaption = _T("");
	m_bTimer = FALSE;
	m_nTimeout = 0;
}


void CInfoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CInfoDlg)
	DDX_Control(pDX, IDD_WHAT_HAPPENED, m_btnCaption_WhatHappened);
	DDX_Control(pDX, IDD_RESULTS, m_btnCaption_Results);
	DDX_Control(pDX, IDD_CORRECTIVE_ACTION, m_btnCaption_CorrectiveAction);
	DDX_Control(pDX, IDC_TIMEOUT_PROGRESS, m_ProgressCtrl);
	DDX_Text(pDX, IDC_CORRECTIVE_ACTION, m_csCorrectiveAction);
	DDX_Text(pDX, IDC_RESULTS, m_csResults);
	DDX_Text(pDX, IDC_WHAT_HAPPENED, m_csWhatHappened);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CInfoDlg, CDialog)
	//{{AFX_MSG_MAP(CInfoDlg)
	ON_NOTIFY(NM_CLICK, IDC_TIMEOUT_PROGRESS, OnClickTimeoutProgress)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInfoDlg message handlers

BOOL CInfoDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	if( ! m_csCaption_WhatHappened.IsEmpty() )
		m_btnCaption_WhatHappened.SetWindowText( m_csCaption_WhatHappened );
	if( ! m_csCaption_CorrectiveAction.IsEmpty() )
		m_btnCaption_CorrectiveAction.SetWindowText( m_csCaption_CorrectiveAction );
	if( ! m_csCaption_Results.IsEmpty() )
		m_btnCaption_Results.SetWindowText( m_csCaption_Results );
	SetWindowText( m_csCaption );
	if( m_nTimeout )
	{
		m_ProgressCtrl.SetRange( 0, m_nTimeout );
		m_ProgressCtrl.SetStep( 1 );
		SetTimer( 1, 1000, NULL );
		m_bTimer = TRUE;
	}
	else
		m_ProgressCtrl.ShowWindow( SW_HIDE );	// if no delay is specified,
															// the progress bar control is hidden
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CInfoDlg::OnClickTimeoutProgress(NMHDR* pNMHDR, LRESULT* pResult) 
{
	if( m_bTimer )	KillTimer( 1 );
	else				SetTimer( 1, 1000, NULL );
	*pResult = 0;
}

void CInfoDlg::OnTimer(UINT nIDEvent) 
{
	m_ProgressCtrl.StepIt();
	if( ! m_nTimeout )
	{
		KillTimer(1);
		PostMessage( WM_COMMAND, IDOK, 0L );
		m_bTimer = FALSE;
	}
	m_nTimeout--;
	CDialog::OnTimer(nIDEvent);
}

