// HotKeyDialog.cpp : implementation file
//

#include "stdafx.h"
#include "EPro.h"
#include "HotKeyDialog.h"

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

/////////////////////////////////////////////////////////////////////////////
// CHotKeyDialog dialog


CHotKeyDialog::CHotKeyDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CHotKeyDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CHotKeyDialog)
	m_bAlt = FALSE;
	m_bCtrl = FALSE;
	m_bShift = FALSE;
	m_strKey = _T("");
	//}}AFX_DATA_INIT
}


void CHotKeyDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CHotKeyDialog)
	DDX_Control(pDX, IDOK, m_btOk);
	DDX_Control(pDX, IDCANCEL, m_btCancel);
	DDX_Check(pDX, IDC_CHECK_ALT, m_bAlt);
	DDX_Check(pDX, IDC_CHECK_CTRL, m_bCtrl);
	DDX_Check(pDX, IDC_CHECK_SHIFT, m_bShift);
	DDX_Text(pDX, IDC_EDIT_KEY, m_strKey);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CHotKeyDialog, CDialog)
	//{{AFX_MSG_MAP(CHotKeyDialog)
	ON_WM_KEYDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHotKeyDialog message handlers

void CHotKeyDialog::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	
	TRACE("nChar:%d nRepCnt:%d nFlags:%d\n",nChar,nRepCnt,nFlags);
	
	CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CHotKeyDialog::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData(TRUE);
	if(m_strKey.GetLength()!=1)
	{
		AfxMessageBox("ÇëÊäÈë¼üÖµ!");
		return;
	}
	m_byteMask=0;
	if(m_bShift)
		m_byteMask|=1;
	if(m_bCtrl)
		m_byteMask|=4;
	if(m_bAlt)
		m_byteMask|=2;
	m_strKey.MakeUpper();
	m_byteKey=m_strKey.GetBuffer(1)[0];
	TRACE("m_byteMask:%0x,m_byteKey:%0x\n",m_byteMask,m_byteKey);
	CDialog::OnOK();
}

BOOL CHotKeyDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	m_btOk.InitButton(this);
	m_btCancel.InitButton(this);
	
	m_bShift=(BOOL)m_byteMask & 1;
	m_bAlt=(BOOL)m_byteMask & 2;
	m_bCtrl=m_byteMask & 4!=0;
	m_strKey=m_byteKey;
	CEdit* pEdit=(CEdit*)GetDlgItem(IDC_EDIT_KEY);
	pEdit->SetLimitText(1);
	UpdateData(FALSE);
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
