Address: http://blog.csdn.net/ariesjzj/article/details/8526103
You can use the following methods to simulate mouse input with a program:
1. sendmessage and postmessage, by sending a mouse message and simulating a mouse event, the advantage is that the window is still valid after being minimized.
2. mouse_event: Simulate the mouse operation. The window must be in front.
3. sendinput, which can be used as a simulated mouse or keyboard.
Here we use the first method to achieve click and drag-and-drop
Click:
void click_point(unsigned long x, unsigned long y){SendMessage(hwnd, WM_LBUTTONDOWN, NULL, MAKELPARAM(x, y));SendMessage(hwnd, WM_LBUTTONUP, NULL, MAKELPARAM(x, y));}
Drag and Drop:
void drag_drop(unsigned long x1, unsigned long y1, unsigned long x2, unsigned long y2){#define MOVE_STEP50assert(hwnd);POINT point1, point2;point1.x = x1; point1.y = y1;point2.x = x2; point2.y = y2;SendMessage(hwnd, WM_LBUTTONDOWN, NULL, MAKELPARAM(point1.x, point1.y));if (x2 >= x1) {for (unsigned long i = x1; i < x2; i += MOVE_STEP) {Sleep(10);SendMessage(hwnd, WM_MOUSEMOVE, NULL, MAKELPARAM(i, point1.y));}} else {for (unsigned long i = x1; i > x2; i -= MOVE_STEP) {Sleep(10);SendMessage(hwnd, WM_MOUSEMOVE, NULL, MAKELPARAM(i, point1.y));}}SendMessage(hwnd, WM_LBUTTONUP, NULL, MAKELPARAM(point2.x, point2.y));}