回复 8楼 caicaicai0
SendInput()的示例:
#include<windows.h>
#include<stdio.h>
void MouseClick(HWND hWnd, int xPos, int yPos)
{
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0,(SWP_NOMOVE|SWP_NOSIZE));
RECT rect;
GetWindowRect(hWnd, &rect);
INPUT input;
input.type = INPUT_MOUSE;
input.mi.dx = 0xFFFF/(GetSystemMetrics(SM_CXSCREEN)-1) * (rect.left+xPos);
input.mi.dy = 0xFFFF/(GetSystemMetrics(SM_CYSCREEN)-1) * (rect.top+yPos);
// 先看看确定鼠标移动位置
//input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP;
SendInput(1, &input, sizeof(INPUT));
SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,(SWP_NOMOVE|SWP_NOSIZE));
}
int main(int argc, char* argv[])
{
HWND hWnd = FindWindow(NULL, "计算器");
if (hWnd == NULL)
return 0;
int X = 220; // 相对窗口区域
int Y = 380;
MouseClick(hWnd, X, Y);
return 0;
}