📄 test6dlg.cpp
字号:
// test6Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "test6.h"
#include "test6Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//volatile IOPreg *v_pIOPRegs;
HANDLE hKey;
/////////////////////////////////////////////////////////////////////////////
// CTest6Dlg dialog
CTest6Dlg::CTest6Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CTest6Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTest6Dlg)
m_KeyVal = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTest6Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTest6Dlg)
DDX_Text(pDX, IDC_EDIT1, m_KeyVal);
DDV_MinMaxInt(pDX, m_KeyVal, 0, 255);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTest6Dlg, CDialog)
//{{AFX_MSG_MAP(CTest6Dlg)
ON_WM_HELPINFO()
ON_BN_CLICKED(IDC_OPEN, OnOpen)
ON_BN_CLICKED(IDC_CLOSE, OnClose)
ON_BN_CLICKED(IDC_READ, OnRead)
ON_BN_CLICKED(IDC_WRITE, OnWrite)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_BN_CLICKED(IDC_EXIT, OnExit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTest6Dlg message handlers
BOOL CTest6Dlg::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
((CButton *)GetDlgItem(IDC_DATREG))->SetCheck(1);
GetDlgItem(IDC_READ)->EnableWindow(FALSE);
GetDlgItem(IDC_WRITE)->EnableWindow(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CTest6Dlg::OnHelpInfo()
{
// TODO: implement help here
MessageBox(_T("Help"));
}
void CTest6Dlg::OnOpen()
{
// TODO: Add your control notification handler code here
hKey = CreateFile(L"EXT0:",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
if(hKey == INVALID_HANDLE_VALUE)
{
MessageBox(_T("扩展并口打开失败"));
return;
}
GetDlgItem(IDC_READ)->EnableWindow(TRUE);
GetDlgItem(IDC_WRITE)->EnableWindow(TRUE);
}
void CTest6Dlg::OnClose()
{
// TODO: Add your control notification handler code here
CloseHandle(hKey);
GetDlgItem(IDC_READ)->EnableWindow(FALSE);
GetDlgItem(IDC_WRITE)->EnableWindow(FALSE);
}
void CTest6Dlg::OnRead()
{
// TODO: Add your control notification handler code here
// DWORD KeyValue;
DWORD RecvBuf;
BOOL iRet;
DWORD iLen = 1;
int id=0;
id = GetCheckedRadioButton(IDC_DATREG,IDC_CONTROLREG);
if (id == IDC_DATREG)
iLen = 1;
else
if (id == IDC_CONTROLREG)
iLen = 3;
else
iLen = 2;
RecvBuf = 0;
iRet = ReadFile(hKey,&RecvBuf,iLen,&iLen,NULL);
if (iRet )
{
m_KeyVal = RecvBuf;
UpdateData(FALSE);
}
else
MessageBox(_T("读并口数据失败"));
}
void CTest6Dlg::OnWrite()
{
// TODO: Add your control notification handler code here
unsigned char RecvBuf[2];
BOOL iRet;
DWORD iLen = 1;
int id=0;
id = GetCheckedRadioButton(IDC_DATREG,IDC_CONTROLREG);
if (id == IDC_DATREG)
iLen = 1;
else
if (id == IDC_CONTROLREG)
iLen = 3;
else
{ MessageBox(_T("状态寄存器不能写"));
return;
}
RecvBuf[0] = (unsigned char)m_KeyVal;
iRet = WriteFile(hKey,&RecvBuf,iLen,&iLen,NULL);
if (!iRet )
MessageBox(_T("写并口数据失败"));
}
void CTest6Dlg::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
}
void CTest6Dlg::OnExit()
{
// TODO: Add your control notification handler code here
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -