OSDN Git Service

v0.0.1 release
[winautomata/winautomata.git] / cursor_pos.c
1 #include <windows.h>
2 #include <stdio.h>
3
4 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
5             PSTR lpCmdLine, int nCmdShow)
6 {
7     char* p = lpCmdLine;
8
9     if(*p) {
10         int x = -1;
11         int y = -1;
12
13         int arg_num = 0;
14
15         char buf[256];
16         char* p2 = buf;
17
18         if(*p == ' ') p++;
19
20         while(1) {
21             if(*p == ' ' || *p == 0) {
22                 *p2 = 0;
23                 arg_num++;
24                 
25                 if(arg_num == 1) 
26                     x = atoi(buf);
27                 else if(arg_num == 2)
28                     y = atoi(buf);
29
30                 if(*p == 0) break;
31
32                 p++;
33                 p2 = buf;
34             }
35             else {
36                 if(p2 - buf < 255) {
37                     *p2++ = *p++;
38                 }
39                 else {
40                     p++;
41                 }
42             }
43         }
44
45         printf("x %d y %d\n", x, y);
46
47         POINT point;
48         GetCursorPos(&point);
49
50         if(x < 0) 
51             x = point.x;
52         else if(y < 0)
53             y = point.y;
54
55         SetCursorPos(x, y);
56     }
57     else {
58         POINT point;
59         GetCursorPos(&point);
60
61         printf("x %d y %d\n", point.x, point.y);
62     }
63
64     return 0;
65 }
66