📄 main.cpp
字号:
#include <windows.h>
#include <stdio.h>
#include "accelerator.h"
#include "initialize.h"
#include "readrawdata.h"
#include "analyzedata.h"
#include "simulateaction.h"
#pragma data_seg ("Shared")
volatile HWND hwnd = NULL;
#pragma data_seg()
#pragma comment(linker, "/Section:Shared,RWS")
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
static TCHAR szAppName[] = TEXT ("Accelerator") ;
MSG msg ;
WNDCLASS wndclass ;
if (EndProgram())
{
PostMessage(hwnd, WM_DESTROY, NULL, NULL);
exit (0);
}
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground= (HBRUSH) GetStockObject (HOLLOW_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName= szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow(szAppName,
NULL,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL) ;
UpdateWindow (hwnd) ;
while ( GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return (int)msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//用于读写串口
static HANDLE hAccelerator = NULL;
static OVERLAPPED OverlappedRead, OverlappedWrite;
static HANDLE hReadThread;
//判断加速器是否在工作
static bool bWorking = false;
//存储原始数据的缓存,所有的动作判断都是基于对这个缓存里的数据进行分析
static RAWDATA rdBuffer[BUFFER_SIZE];
static int iBufPos = 0;
//用于测试
static FILE *fout = NULL;
static int xPos, yPos;
switch (message)
{
case WM_CREATE:
//初始化加速器
hAccelerator = Initialize(hAccelerator, &OverlappedRead, &OverlappedWrite);
if (!hAccelerator)
{
DisplayCOMError();
//SendMessage(hwnd, WM_DESTROY, NULL, NULL);
}
SetRegedit();
if (hAccelerator)
{
hReadThread = StartReadThread(hwnd, hAccelerator, &OverlappedRead, &OverlappedWrite);
bWorking = true;
}
//设置定时器监视加速器是否在工作
SetTimer(hwnd, TIMER_SCANNER,20, NULL);
//将数据写入文件, 用于测试
//fout = fopen( FILENAME, "w" );
return 0 ;
case WM_TIMER:
switch(wParam)
{
case TIMER_SCANNER:
if (bWorking != true)
{
hAccelerator = Initialize(hAccelerator, &OverlappedRead, &OverlappedWrite);
if (!hAccelerator && com_error == CANNOT_SETUP_ACCELERATOR)
{
MessageBox(NULL,"请重启加速器!","警告!",MB_OK);
}
else if (!hAccelerator && com_error == CANNOT_OPEN_COM)
{
}
else if (hAccelerator != NULL)
{
hReadThread = StartReadThread(hwnd, hAccelerator, &OverlappedRead, &OverlappedWrite);
bWorking = true;
}
}
break;
}
return 0;
case AM_CLOSEACCELERATION:
bWorking = false;
CloseHandle(hAccelerator);
CloseHandle(hReadThread);
CloseHandle(OverlappedRead.hEvent);
CloseHandle(OverlappedWrite.hEvent);
return 0;
case AM_ANALYZEDATA:
AnalyzeData(hwnd, (char *)lParam, (int)wParam, rdBuffer, &iBufPos, fout);
return 0;
case AM_MOUSEMOVE:
xPos = (int)(short)LOWORD(lParam);
yPos = (int)(short)HIWORD(lParam);
SetCursorPos(xPos, yPos);
return 0;
case AM_RBUTTONCLICK:
xPos = (int)(short)LOWORD(lParam);
yPos = (int)(short)HIWORD(lParam);
Beep(3000,10);
SimulateRightSingleClick(xPos, yPos);
return 0;
case AM_LBUTTONCLICK:
xPos = (int)(short)LOWORD(lParam);
yPos = (int)(short)HIWORD(lParam);
Beep(4000,10);
SimulateLeftSingleClick(xPos, yPos);
return 0;
case AM_LBUTTONDCLICK:
xPos = (int)(short)LOWORD(lParam);
yPos = (int)(short)HIWORD(lParam);
Beep(2000,10);
SimulateLeftDoubleClick(xPos, yPos);
return 0;
case WM_DESTROY:
KillTimer(hwnd, TIMER_SCANNER);
//fclose(fout);
DeleteReg();
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -