// KEYTESTDlg.cpp : implementation file
//

#include "stdafx.h"
#include "KEYTEST.h"
#include "KEYTESTDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define IO_CTL_LED_1_ON 0x01
#define IO_CTL_LED_2_ON 0x02
#define IO_CTL_LED_3_ON 0x03
#define IO_CTL_LED_4_ON 0x04
#define IO_CTL_LED_ALL_ON 0x05
#define IO_CTL_LED_1_OFF 0x06
#define IO_CTL_LED_2_OFF 0x07
#define IO_CTL_LED_3_OFF 0x08
#define IO_CTL_LED_4_OFF 0x09
#define IO_CTL_LED_ALL_OFF 0x0a

/////////////////////////////////////////////////////////////////////////////
// CKEYTESTDlg dialog

CKEYTESTDlg::CKEYTESTDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CKEYTESTDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CKEYTESTDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

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

BEGIN_MESSAGE_MAP(CKEYTESTDlg, CDialog)
	//{{AFX_MSG_MAP(CKEYTESTDlg)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
	ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
	ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
	ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
	ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CKEYTESTDlg message handlers

BOOL CKEYTESTDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here
	exec=new SHELLEXECUTEINFO;
	exec->cbSize=sizeof(SHELLEXECUTEINFO);
	exec->dwHotKey=0;
	exec->fMask=SEE_MASK_NOCLOSEPROCESS;
	exec->hIcon=NULL;
	exec->hInstApp=NULL;
	exec->hkeyClass=NULL;
	//exec->hMonitorhMonitor=NULL;
	exec->hwnd=NULL;
	exec->lpClass=NULL;
	exec->lpDirectory=NULL;
	exec->lpFile=L"windows\\ceplayer.exe";
	exec->lpIDList=NULL;
	exec->lpParameters=NULL;
	exec->lpVerb=NULL;
	exec->nShow=SW_SHOW;

	leddriver=CreateFile(L"LED1:",GENERIC_READ | GENERIC_WRITE, 0,NULL,OPEN_EXISTING,0,NULL );
	
	if(!leddriver)
		MessageBox(L"ERROR OPENING LED!");

	return TRUE;  // return TRUE  unless you set the focus to a control
}



BOOL CKEYTESTDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->message==WM_KEYDOWN)   
	{   
		if(pMsg->wParam==VK_F3)   
		{   
			MessageBox(L"Botton k2 has been pushed!");
			exec->lpFile=L"windows\\ceplayer.exe";
			ShellExecuteEx(exec);
			return   TRUE;   
		}  
		if(pMsg->wParam==VK_F2)   
		{   
			MessageBox(L"Botton k1 has been pushed!");
			exec->lpFile=L"windows\\comtest.exe";
			ShellExecuteEx(exec);
			return   TRUE;   
		}   
	}   	
	return CDialog::PreTranslateMessage(pMsg);
}

void CKEYTESTDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	DeviceIoControl(leddriver,IO_CTL_LED_1_ON, NULL,0,NULL,0,NULL,NULL);
	
}

void CKEYTESTDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	DeviceIoControl(leddriver,IO_CTL_LED_2_ON,NULL,0,NULL,0,NULL,NULL);
}

void CKEYTESTDlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
	DeviceIoControl(leddriver,IO_CTL_LED_3_ON,NULL,0,NULL,0,NULL,NULL);
}

void CKEYTESTDlg::OnButton4() 
{
	// TODO: Add your control notification handler code here
	DeviceIoControl(leddriver,IO_CTL_LED_4_ON,NULL,0,NULL,0,NULL,NULL);
}

BOOL CKEYTESTDlg::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	DeviceIoControl(leddriver,IO_CTL_LED_ALL_OFF,NULL,0,NULL,0,NULL,NULL);
	return CDialog::DestroyWindow();
}

void CKEYTESTDlg::OnButton5() 
{
	// TODO: Add your control notification handler code here
	DeviceIoControl(leddriver,IO_CTL_LED_ALL_ON,NULL,0,NULL,0,NULL,NULL);
}

void CKEYTESTDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	DeviceIoControl(leddriver,IO_CTL_LED_ALL_OFF,NULL,0,NULL,0,NULL,NULL);
	CDialog::OnClose();
}

void CKEYTESTDlg::OnButton6() 
{
	// TODO: Add your control notification handler code here
	DeviceIoControl(leddriver,IO_CTL_LED_1_OFF,NULL,0,NULL,0,NULL,NULL);
}

//DEL void CKEYTESTDlg::OnDoubleclickedButton6() 
//DEL {
//DEL 	// TODO: Add your control notification handler code here
//DEL 	
//DEL }

void CKEYTESTDlg::OnButton7() 
{
	// TODO: Add your control notification handler code here
	DeviceIoControl(leddriver,IO_CTL_LED_2_OFF,NULL,0,NULL,0,NULL,NULL);
}

void CKEYTESTDlg::OnButton8() 
{
	// TODO: Add your control notification handler code here
	DeviceIoControl(leddriver,IO_CTL_LED_3_OFF,NULL,0,NULL,0,NULL,NULL);
}

void CKEYTESTDlg::OnButton9() 
{
	// TODO: Add your control notification handler code here
	DeviceIoControl(leddriver,IO_CTL_LED_4_OFF,NULL,0,NULL,0,NULL,NULL);
}

void CKEYTESTDlg::OnButton10() 
{
	// TODO: Add your control notification handler code here
	DeviceIoControl(leddriver,IO_CTL_LED_ALL_OFF,NULL,0,NULL,0,NULL,NULL);
}
