📄 myappview.cpp
字号:
// MyAppView.cpp : implementation of the CMyAppView class
//
#include "stdafx.h"
#include "MyApp.h"
#include "MyAppDoc.h"
#include "MyAppView.h"
#include "ezusbsys.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BOOLEAN
bOpenDriver (HANDLE * phDeviceHandle, PCHAR devname);
int LEDWrite(int index,int digit);
int GetKey(char *Key);
/////////////////////////////////////////////////////////////////////////////
// CMyAppView
IMPLEMENT_DYNCREATE(CMyAppView, CView)
BEGIN_MESSAGE_MAP(CMyAppView, CView)
//{{AFX_MSG_MAP(CMyAppView)
ON_WM_KEYUP()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyAppView construction/destruction
CMyAppView::CMyAppView()
{
// TODO: add construction code here
}
CMyAppView::~CMyAppView()
{
}
BOOL CMyAppView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMyAppView drawing
void CMyAppView::OnDraw(CDC* pDC)
{
CMyAppDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMyAppView printing
BOOL CMyAppView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMyAppView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMyAppView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMyAppView diagnostics
#ifdef _DEBUG
void CMyAppView::AssertValid() const
{
CView::AssertValid();
}
void CMyAppView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMyAppDoc* CMyAppView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyAppDoc)));
return (CMyAppDoc*)m_pDocument;
}
#endif //_DEBUG
int i = 0;
/////////////////////////////////////////////////////////////////////////////
// CMyAppView message handlers
HANDLE hDevice = NULL;
void CMyAppView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
char pcDriverName[16] = "";
char Key;
BOOLEAN bResult = FALSE;
{
sprintf(pcDriverName, "Ezusb-%d", 0);
if (bOpenDriver (&hDevice, pcDriverName) == TRUE)
{
// TRACE("TPM:CEzMrApp::OnFileUpdateAllDevs(): %s available\n", pcDriverName);
// CloseHandle (hDevice);
}
LEDWrite(0,i%16);
LEDWrite(1,(i+1)%16);
LEDWrite(2,(i+2)%16);
LEDWrite(3,(i+3)%16);
GetKey(&Key);
i++;
}
// MessageBox("Hello","ABC",MB_OK);
CView::OnKeyUp(nChar, nRepCnt, nFlags);
}
int LEDWrite(int index,int digit) //写LED
{
unsigned long wcnt;
BOOLEAN bResult = FALSE;
VENDOR_OR_CLASS_REQUEST_CONTROL myrequest;
myrequest.direction=0;
myrequest.requestType=2;
myrequest.recepient=0;
myrequest.request=0xB0;
myrequest.value=(index&0xff)*256+digit;
// if (hDevice != NULL)
{// Perform the Get-Descriptor IOCTL
bResult = DeviceIoControl(hDevice,
IOCTL_EZUSB_VENDOR_OR_CLASS_REQUEST,
&myrequest,
sizeof(VENDOR_OR_CLASS_REQUEST_CONTROL),
NULL,
0,
&wcnt,
NULL);
if (bResult==TRUE)
{
// do nothin
}
else
{
}
}
return wcnt;
}
int GetKey(char *Key)
{ //获取键盘字符
unsigned long rcnt;
VENDOR_OR_CLASS_REQUEST_CONTROL myrequest;
myrequest.direction=1;
myrequest.requestType=2;
myrequest.recepient=0;
myrequest.request=0xB1;
if (!DeviceIoControl(hDevice,IOCTL_EZUSB_VENDOR_OR_CLASS_REQUEST,&myrequest,
sizeof(VENDOR_OR_CLASS_REQUEST_CONTROL),Key,1,&rcnt,NULL))
{
;
}
return rcnt;
}
/**************************************************
* bOpenDriver proc *
* *
* Purpose: *
* Opens the device driver using symbolic *
* name provided *
* *
* Input: *
* phDeviceHandle: *
* Pointer to Device Driver handle where *
* the file handle is placed. *
* devname: *
* Null terminated string containing the *
* device name *
* *
* Return Value: *
* Boolean that indicates if the driver was *
* successfully opened or not. *
* *
**************************************************/
BOOLEAN
bOpenDriver (HANDLE * phDeviceHandle, PCHAR devname)
{
char completeDeviceName[64] = "";
char pcMsg[64] = "";
strcat (completeDeviceName,
"\\\\.\\"
);
strcat (completeDeviceName,
devname
);
*phDeviceHandle = CreateFile( completeDeviceName,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
if (*phDeviceHandle == INVALID_HANDLE_VALUE) {
return (FALSE);
} else {
return (TRUE);
} /*else*/
}//OpenDevice
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -