1 /*----------------------------------------------------------------------------
3 ** Utilty to pick clicks posted to Wine Windows
6 **---------------------------------------------------------------------------
7 ** Copyright 2004 Jozef Stefanka for CodeWeavers, Inc.
8 ** Copyright 2005 Francois Gouget for CodeWeavers, Inc.
9 ** Copyright 2005 Dmitry Timoshkov for CodeWeavers, Inc.
11 ** This program is free software; you can redistribute it and/or modify
12 ** it under the terms of the GNU General Public License as published by
13 ** the Free Software Foundation; either version 2 of the License, or
14 ** (at your option) any later version.
16 ** This program is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ** GNU General Public License for more details.
21 ** You should have received a copy of the GNU General Public License
22 ** along with this program; if not, write to the Free Software
23 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 **--------------------------------------------------------------------------*/
34 #define APP_NAME "wpickclick.exe"
37 static BOOL (WINAPI
*pInstallHooks
)(HMODULE hdll
);
38 static void (WINAPI
*pRemoveHooks
)();
39 static action_t
* (WINAPI
*pGetAction
)();
40 static void (WINAPI
*pFreeAction
)(action_t
* action
);
44 * Provide some basic debugging support.
47 #define __PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
49 #define __PRINTF_ATTR(fmt,args)
51 static int debug_on
=0;
52 static int init_debug()
54 char* str
=getenv("CXTEST_DEBUG");
55 if (str
&& strstr(str
, "+hook"))
60 static void cxlog(const char* format
, ...) __PRINTF_ATTR(1,2);
61 static void cxlog(const char* format
, ...)
67 va_start(valist
, format
);
68 vfprintf(stderr
, format
, valist
);
73 static HINSTANCE
load_hook_dll()
76 char dllpath
[MAX_PATH
];
79 hinstDll
=LoadLibrary("hook.dll");
83 if (!GetModuleFileName(NULL
,dllpath
,sizeof(dllpath
)))
86 p
=strrchr(dllpath
,'\\');
90 p
=strrchr(dllpath
,'\\');
94 strcat(dllpath
,"\\hookdll\\hook.dll");
95 hinstDll
=LoadLibrary(dllpath
);
99 char* cleanup(char* str
)
103 while (*str
==' ' || *str
=='\t' || *str
=='\r' || *str
=='\n')
108 while (s
>str
&& (*s
==' ' || *s
=='\t' || *s
=='\r' || *s
=='\n'))
114 int WINAPI
WinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
115 LPSTR lpCmdLine
, int nCmdShow
)
122 /* Our scripts expect Unix-style line ends */
123 _setmode(1,_O_BINARY
);
124 _setmode(2,_O_BINARY
);
126 if (strstr(lpCmdLine
,"--help"))
128 fprintf(stderr
,"%s - Utility to print coordinates, component, window title, component class and window class name of a click\n", APP_NAME
);
129 fprintf(stderr
,"----------------------------------------------\n");
130 fprintf(stderr
,"Usage: %s\n",APP_NAME
);
131 fprintf(stderr
,"The options are as follows:\n");
132 fprintf(stderr
,"After starting you can\n");
133 fprintf(stderr
,"select where to click. If we properly track the click, it will be reported\n");
134 fprintf(stderr
,"in the following format:\n");
135 fprintf(stderr
," button-name x y component_name window_name component_class_name window_class_name\n");
136 fprintf(stderr
,"Note that x and y can be negative; this typically happens if you click within the\n");
137 fprintf(stderr
,"window manager decorations of a given window.\n");
138 fprintf(stderr
,"On success, %s returns 0, non zero on some failure\n",APP_NAME
);
142 /* Load the hook library */
143 hDll
= load_hook_dll();
146 fprintf(stderr
, "Error: Unable to load 'hook.dll'\n");
151 pInstallHooks
=(void*)GetProcAddress(hDll
, "InstallHooks");
152 pRemoveHooks
=(void*)GetProcAddress(hDll
, "RemoveHooks");
153 pGetAction
=(void*)GetProcAddress(hDll
, "GetAction");
154 pFreeAction
=(void*)GetProcAddress(hDll
, "FreeAction");
155 if (!pInstallHooks
|| !pRemoveHooks
|| !pGetAction
)
157 fprintf(stderr
, "Error: Unable to get the hook.dll functions (%ld)\n",
163 if (!pInstallHooks(hDll
))
165 fprintf(stderr
, "Error: Unable to install the hooks (%ld)\n",
171 fprintf(stderr
, "Ready for capture...\n");
175 fprintf(stderr
, "Error: GetAction() failed\n");
180 switch (action
->action
)
194 printf("button%d %ld %ld\n", action
->action
-ACTION_BUTTON1
+1,
195 action
->x
, action
->y
);
198 fprintf(stderr
, "Error: Unknown action %d\n",action
->action
);
199 printf("%d\n", action
->action
);
202 printf("%s\n", action
->window_class
);
203 printf("%s\n", action
->window_title
);
204 printf("%ld\n", action
->control_id
);
205 printf("%s\n", action
->control_class
);
206 printf("%s\n", cleanup(action
->control_caption
));
208 cxlog("\n%s: action=%d x=%ld y=%ld\n", __FILE__
, action
->action
,
209 action
->x
, action
->y
);
210 cxlog("window_class='%s'\n", action
->window_class
);
211 cxlog("window_title='%s'\n", action
->window_title
);
212 cxlog("control_id=%ld\n", action
->control_id
);
213 cxlog("control_class='%s'\n", action
->control_class
);
214 cxlog("control_caption='%s'\n", action
->control_caption
);