创建 DLL 步骤 和 SRC
LIBRARY SimulationTouchDll EXPORTS MouseControl GetPosition
//MouseControlInterface.def 文件
#pragma once #define RET_SUCCESS 0 #define RET_ERROR 1 enum MOUSE_STATUS { MOUSE_MOVE, MOUSE_LCLICK, MOUSE_RCLICK, MOUSE_DCLICK, }; extern "C" _declspec(dllexport)int __stdcall MouseControl(MOUSE_STATUS eMouseStatus, double dX, double dY); extern "C" _declspec(dllexport)int __stdcall GetPosition(long *pX, long *pY);
//MouseControlInterface.h 头文件
#include "MouseControlInterface.h" #include "Sensor.h" #include <Windows.h> int __stdcall MouseControl(MOUSE_STATUS eMouseStatus, double dX, double dY) { POINT p; p.x = dX; p.y = dY; HWND hd = ::WindowFromPoint(p); HWND hdp = ::GetParent(hd); LPARAM lParam = MAKELPARAM(p.x,p.y); switch(eMouseStatus) { case MOUSE_MOVE: break; case MOUSE_LCLICK: ::PostMessage(hd, WM_LBUTTONDOWN, MK_LBUTTON, lParam); ::PostMessage(hd, WM_LBUTTONUP, MK_LBUTTON, lParam); break; case MOUSE_RCLICK: ::PostMessage(hd, WM_RBUTTONDOWN, MK_RBUTTON, lParam); ::PostMessage(hd, WM_RBUTTONUP, MK_RBUTTON, lParam); break; case MOUSE_DCLICK: ::PostMessage(hd, WM_LBUTTONDOWN, MK_LBUTTON, lParam); ::PostMessage(hd, WM_LBUTTONUP, MK_LBUTTON, lParam); ::PostMessage(hd, WM_LBUTTONDBLCLK, MK_LBUTTON, lParam); break; default: break; } return RET_SUCCESS; } int __stdcall GetPosition(long *pX, long *pY) { POINT p; GetCursorPos(&p); *pX = p.x; *pY = p.y; Sensor sensor; sensor.SetInterval(5); return RET_SUCCESS; }
//MouseControlInterface.cpp 源文件
#pragma once class Sensor { private: static int interval; public: void SetInterval(int inter); };
//Sensor.h头文件
#include "Sensor.h" #include <Windows.h> void Sensor::SetInterval(int inter) { inter++; };
//Sensor.cpp源文件
posted on 2013-12-09 15:44 JackSlaterYu 阅读(231) 评论(0) 编辑 收藏 举报