📄 teststringdriverdlg.cpp
字号:
// TestStringDriverDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TestStringDriver.h"
#include "TestStringDriverDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestStringDriverDlg dialog
CTestStringDriverDlg::CTestStringDriverDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestStringDriverDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestStringDriverDlg)
// 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 CTestStringDriverDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestStringDriverDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestStringDriverDlg, CDialog)
//{{AFX_MSG_MAP(CTestStringDriverDlg)
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_BN_CLICKED(IDC_IOCONTROL, OnIocontrol)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestStringDriverDlg message handlers
BOOL CTestStringDriverDlg::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
hStr=INVALID_HANDLE_VALUE;
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestStringDriverDlg::OnOpen()
{
//打开String驱动
hStr=CreateFile(TEXT("STR1:"),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,0);
if(hStr==INVALID_HANDLE_VALUE)
{
::MessageBox(NULL,_T("无法打开STR1:"),_T("String驱动测试程序"),MB_OK);
}
else
{
::MessageBox(NULL,_T("打开STR1:成功"),_T("String驱动测试程序"),MB_OK);
}
}
void CTestStringDriverDlg::OnClose()
{
if(hStr!=INVALID_HANDLE_VALUE)
{
CloseHandle(hStr);
AfxMessageBox(L"关闭STR1成功!");
hStr=INVALID_HANDLE_VALUE;
}
else
{
AfxMessageBox(L"未打开!");
}
}
void CTestStringDriverDlg::OnRead()
{
char b[100];
memset(b,0,100*sizeof(char));
if(hStr==INVALID_HANDLE_VALUE)
{
AfxMessageBox(L"未打开!");
return;
}
DWORD dwBytesread;
ReadFile(hStr,b,100,&dwBytesread,NULL);
if(dwBytesread>0)
{
AfxMessageBox(CString(b));
}
}
void CTestStringDriverDlg::OnWrite()
{
char a[100]="This is a test string!";
if(hStr==INVALID_HANDLE_VALUE)
{
AfxMessageBox(L"未打开!");
return;
}
DWORD dwByteswritten;
WriteFile(hStr,a,22,&dwByteswritten,NULL);
if(dwByteswritten>0)
{
CString inf;
inf.Format(L"写入%d字节.",dwByteswritten);
AfxMessageBox(inf);
}
}
void CTestStringDriverDlg::OnIocontrol()
{
DeviceIoControl(hStr,0,NULL,NULL,NULL,NULL,NULL,NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -