// ProgTimeDlg.cpp : implementation file
//

#include "stdafx.h"
#include "mw4gameed2.h"
#include "ProgTimeDlg.h"


/////////////////////////////////////////////////////////////////////////////
// CProgTimeDlg dialog


CProgTimeDlg::CProgTimeDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CProgTimeDlg::IDD, pParent)
{

	//{{AFX_DATA_INIT(CProgTimeDlg)
	m_ETime = _T("");
	m_ProgPer = _T("");
	//}}AFX_DATA_INIT
	TimeElapsed=0;

}

void CProgTimeDlg::InitWin(UINT title,CWnd* pParent)
{
	Create(CProgTimeDlg::IDD ,pParent);
	CString strtitle;
	strtitle.LoadString(title);
	SetWindowText(strtitle);
	ShowWindow(SW_SHOW);
	SetPos(0);
	UpdateWindow();
}

void CProgTimeDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CProgTimeDlg)
	DDX_Control(pDX, IDC_PROGRESSBAR, m_ProgBar);
	DDX_Text(pDX, IDC_ETIME, m_ETime);
	DDX_Text(pDX, IDC_PROGRESS, m_ProgPer);
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// CProgTimeDlg message handlers

void CProgTimeDlg::SetPos(int per)
{
UpdateData(TRUE);

	m_ProgPer.Format("%i%%",per);
	m_ProgBar.SetPos(per);

UpdateData(FALSE);
	UpdateWindow();
}

BOOL CProgTimeDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_ETime="00:00:00";
	m_ProgPer="0%";
	m_ProgBar.SetRange(0,100);
	m_ProgBar.SetPos(0);
	SetTimer(NULL,1000,NULL);
	UpdateData(FALSE);
	UpdateWindow();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CProgTimeDlg::OnTimer(UINT nIDEvent) 
{

UpdateData(TRUE);

TimeElapsed++;
int sc=TimeElapsed;
int hour,min,sec;
sec=sc%60;
sc-=sec;
min=(sc/60)%60;
sc-=min*60;
hour=sc/(60*60);

m_ETime.Format("%02i:%02i:%02i",hour,min,sec);

UpdateData(FALSE);
SetTimer(NULL,1000,NULL);
	CDialog::OnTimer(nIDEvent);
}
