?? uartmousedlg.cpp
字號:
// UartMouseDlg.cpp : implementation file
//
#include "stdafx.h"
#include "UartMouse.h"
#include "UartMouseDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
DWORD WINAPI DriverThreadProc(LPVOID lpParameter);
INPUT input;
BYTE COM_Read_Data[8];
bool StartDriver;
HANDLE g_hCom1 ; // Comm Port Handle
HWND Register_hwnd;
// CUartMouseDlg dialog
CUartMouseDlg::CUartMouseDlg(CWnd* pParent /*=NULL*/)
: CDialog(CUartMouseDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CUartMouseDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CUartMouseDlg, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
ON_WM_SIZE()
#endif
//}}AFX_MSG_MAP
ON_WM_PAINT()
END_MESSAGE_MAP()
// CUartMouseDlg message handlers
BOOL CUartMouseDlg::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
// TODO: Add extra initialization here
MoveWindow(-100,-100,2,2,TRUE);
if(Initial_COMPort()==FALSE)
{
exit(0);
}
Register_hwnd=NULL;
return TRUE; // return TRUE unless you set the focus to a control
}
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CUartMouseDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
if (AfxIsDRAEnabled())
{
DRA::RelayoutDialog(
AfxGetResourceHandle(),
this->m_hWnd,
DRA::GetDisplayMode() != DRA::Portrait ?
MAKEINTRESOURCE(IDD_UARTMOUSE_DIALOG_WIDE) :
MAKEINTRESOURCE(IDD_UARTMOUSE_DIALOG));
}
}
#endif
BOOL CUartMouseDlg::Initial_COMPort()
{
COMMTIMEOUTS commTimeout;
// TODO: Add your control notification handler code here
g_hCom1 = CreateFile( TEXT("COM3:"), GENERIC_READ | GENERIC_WRITE,0, NULL, OPEN_EXISTING,0, NULL);
if( g_hCom1 == INVALID_HANDLE_VALUE ) //
{
//MessageBox( L"Tablet CreateFile Failed", NULL, MB_OK );
}
// g_hCom1=g_hCom;
// Configure port.
dcbComm.DCBlength = sizeof (DCB);
if( GetCommState (g_hCom1, &dcbComm)==0)
{
MessageBox( L"Mouse GetCommState Failed", NULL, MB_OK );
return FALSE;
}
dcbComm.BaudRate =9600;//19200;
dcbComm.fParity=TRUE;
dcbComm.StopBits = ONESTOPBIT;
dcbComm.Parity = EVENPARITY;
dcbComm.ByteSize = 8;
if(SetCommState (g_hCom1, &dcbComm)==0)
{
MessageBox( L"Mouse SetCommState Failed", NULL, MB_OK );
return FALSE;
}
if( GetCommTimeouts( g_hCom1, &commTimeout )==0 )
{
MessageBox( L"Mouse GetCommTimeouts Failed", NULL, MB_OK );
CloseHandle( g_hCom1 );
return FALSE;
}
commTimeout.ReadIntervalTimeout = 0;
commTimeout.ReadTotalTimeoutMultiplier = 0;
commTimeout.ReadTotalTimeoutConstant = 0;
if( SetCommTimeouts( g_hCom1, &commTimeout )==0 )
{
MessageBox( L"Mouse SetCommTimeouts Failed", NULL, MB_OK );
CloseHandle( g_hCom1 );
return FALSE;
}
// InitializeCriticalSection(&g_sCritSection);
if (g_hCom1 != INVALID_HANDLE_VALUE)
{
}
//g_hTreadStopedEvent = CreateEvent (0, FALSE, FALSE, 0);
g_hDriverThread = CreateThread( NULL, 0, DriverThreadProc, NULL, 0, NULL );
if( !g_hDriverThread )
{
MessageBox( L"Mouse CreateThread Failed", NULL, MB_OK );
CloseHandle( g_hCom1 );
return FALSE;
}
StartDriver=TRUE;
//ShowWindow(SW_HIDE);
return TRUE;
}
DWORD WINAPI DriverThreadProc(LPVOID lpParameter)
{
DWORD cBytes;
BYTE InputD[1];
int temp;
int x,y;
BYTE Buf_Count=0;
BYTE Button_Status=0;
BYTE Pre_Button_Status=0;
// SetCommMask( g_hCom1, EV_RXCHAR );
// Write to the serial port
while(StartDriver)
{
//ReadFile (g_hCom1, COM_Read_Data+i, 1, &cBytes, 0);
ReadFile (g_hCom1, InputD, 1, &cBytes, 0);
switch(Buf_Count)
{
case 0:
if(InputD[0]==0xA5)
Buf_Count++;
else
Buf_Count=0;
break;
case 1:
COM_Read_Data[Buf_Count-1]=0;
COM_Read_Data[Buf_Count-1]=InputD[0];
Buf_Count++;
break;
case 2:
COM_Read_Data[Buf_Count-1]=0;
temp=InputD[0];
if(temp<=127)
COM_Read_Data[Buf_Count-1]=temp;
else if(temp>127 && temp<256)
COM_Read_Data[Buf_Count-1]=(temp-256);
Buf_Count++;
break;
case 3:
COM_Read_Data[Buf_Count-1]=0;
temp=InputD[0];
if(temp<=127)
COM_Read_Data[Buf_Count-1]=temp;
else if(temp>127 && temp<256)
COM_Read_Data[Buf_Count-1]=(temp-256);
x= COM_Read_Data[1];
y= COM_Read_Data[2];
/* input.mi.dx = ((COM_Read_Data[1]<<8)+COM_Read_Data[0])*10;
input.mi.dy = ((COM_Read_Data[3]<<8)+COM_Read_Data[2])*13;
input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
SendInput(1, &input,sizeof(input));
*/ ;;;;
mouse_event( MOUSEEVENTF_MOVE,(COM_Read_Data[1]),(COM_Read_Data[2]),NULL,NULL);
x=0; y=0;
Buf_Count=0;
break;
}//end of switch- */
}
return 0;
}
void CUartMouseDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
ShowWindow(SW_HIDE);
}
LRESULT CUartMouseDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
switch(message)
{
case WM_USER+98:
{
Register_hwnd = NULL;
}
break;
/////////
case WM_USER+99:
{
Register_hwnd = (HWND)wParam;
}
break;
/////////
}//end of switch(message)
return CDialog::WindowProc(message, wParam, lParam);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -