// UserErrorDlg.cpp : implementation file
//

#include "stdafx.h"
#include "LocalErrors.h"
#include "UserErrorDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CUserErrorDlg dialog

CUserErrorDlg::CUserErrorDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CUserErrorDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CUserErrorDlg)
	m_csCorrectiveAction = _T("");
	m_csWhatHappened = _T("");
	//}}AFX_DATA_INIT
	m_csCaption = _T("");
	m_nTimeout = 0;
	m_bTimer = FALSE;
}

void CUserErrorDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUserErrorDlg)
	DDX_Control(pDX, IDD_WHAT_HAPPENED, m_btnCaption_WhatHappened);
	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_WHAT_HAPPENED, m_csWhatHappened);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CUserErrorDlg, CDialog)
	//{{AFX_MSG_MAP(CUserErrorDlg)
	ON_NOTIFY(NM_CLICK, IDC_TIMEOUT_PROGRESS, OnClickTimeoutProgress)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUserErrorDlg message handlers

BOOL CUserErrorDlg::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 );
	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 CUserErrorDlg::OnClickTimeoutProgress(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	if( m_bTimer )	KillTimer( 1 );
	else				SetTimer( 1, 1000, NULL );
	*pResult = 0;
}

void CUserErrorDlg::OnTimer(UINT nIDEvent) 
{
	m_ProgressCtrl.StepIt();
	if( ! m_nTimeout )
	{
		KillTimer(1);
		PostMessage( WM_COMMAND, IDOK, 0L );
		m_bTimer = FALSE;
	}
	m_nTimeout--;
	CDialog::OnTimer(nIDEvent);
}

