ReactOS 0.4.15-dev-7788-g1ad9096
wpickclick.c File Reference
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <windows.h>
#include "hook.h"
Include dependency graph for wpickclick.c:

Go to the source code of this file.

Macros

#define APP_NAME   "wpickclick.exe"
 
#define __PRINTF_ATTR(fmt, args)
 

Functions

static BOOL (WINAPI *pInstallHooks)(HMODULE hdll)
 
static void (WINAPI *pRemoveHooks)()
 
static action_t *WINAPIpGetAction ()
 
static int init_debug ()
 
static void cxlog (const char *format,...) __PRINTF_ATTR(1
 
static HINSTANCE load_hook_dll ()
 
charcleanup (char *str)
 
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
 

Variables

static int debug_on =0
 

Macro Definition Documentation

◆ __PRINTF_ATTR

#define __PRINTF_ATTR (   fmt,
  args 
)

Definition at line 49 of file wpickclick.c.

◆ APP_NAME

#define APP_NAME   "wpickclick.exe"

Definition at line 34 of file wpickclick.c.

Function Documentation

◆ BOOL()

static BOOL ( WINAPI pInstallHooks)
static

◆ cleanup()

char * cleanup ( char str)

Definition at line 99 of file wpickclick.c.

100{
101 char* s;
102
103 while (*str==' ' || *str=='\t' || *str=='\r' || *str=='\n')
104 str++;
105 s=strchr(str,'\n');
106 if (!s)
107 s=str+strlen(str)-1;
108 while (s>str && (*s==' ' || *s=='\t' || *s=='\r' || *s=='\n'))
109 s--;
110 *(s+1)='\0';
111 return str;
112}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strchr(const char *String, int ch)
Definition: utclib.c:501
GLdouble s
Definition: gl.h:2039
const WCHAR * str

◆ cxlog()

static void static void cxlog ( const char format,
  ... 
)
static

Definition at line 61 of file wpickclick.c.

62{
64
65 if (debug_on)
66 {
70 }
71}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl vfprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
static __ms_va_list valist
Definition: printf.c:66
static int debug_on
Definition: wpickclick.c:51

Referenced by WinMain().

◆ init_debug()

static int init_debug ( )
static

Definition at line 52 of file wpickclick.c.

53{
54 char* str=getenv("CXTEST_DEBUG");
55 if (str && strstr(str, "+hook"))
56 debug_on=1;
57 return debug_on;
58}
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)

Referenced by WinMain().

◆ load_hook_dll()

static HINSTANCE load_hook_dll ( )
static

Definition at line 73 of file wpickclick.c.

74{
75 HINSTANCE hinstDll;
76 char dllpath[MAX_PATH];
77 char* p;
78
79 hinstDll=LoadLibrary("hook.dll");
80 if (hinstDll != NULL)
81 return hinstDll;
82
84 return NULL;
85
86 p=strrchr(dllpath,'\\');
87 if (!p)
88 return NULL;
89 *p='\0';
90 p=strrchr(dllpath,'\\');
91 if (!p)
92 return NULL;
93 *p='\0';
94 strcat(dllpath,"\\hookdll\\hook.dll");
95 hinstDll=LoadLibrary(dllpath);
96 return hinstDll;
97}
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
#define NULL
Definition: types.h:112
#define MAX_PATH
Definition: compat.h:34
GLfloat GLfloat p
Definition: glext.h:8902
WCHAR dllpath[MAX_PATH]
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
#define LoadLibrary
Definition: winbase.h:3797
#define GetModuleFileName
Definition: winbase.h:3766

Referenced by WinMain().

◆ pGetAction()

static action_t *WINAPI * pGetAction ( )
static

Referenced by WinMain().

◆ void()

static void ( WINAPI pRemoveHooks)
static

◆ WinMain()

int WINAPI WinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPSTR  lpCmdLine,
int  nCmdShow 
)

Definition at line 114 of file wpickclick.c.

116{
117 HINSTANCE hDll;
118 action_t* action;
119
120 init_debug();
121
122 /* Our scripts expect Unix-style line ends */
125
126 if (strstr(lpCmdLine,"--help"))
127 {
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);
139 exit(0);
140 };
141
142 /* Load the hook library */
143 hDll = load_hook_dll();
144 if (!hDll)
145 {
146 fprintf(stderr, "Error: Unable to load 'hook.dll'\n");
147 printf("failed\n");
148 return 1;
149 }
150
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)
156 {
157 fprintf(stderr, "Error: Unable to get the hook.dll functions (%ld)\n",
158 GetLastError());
159 printf("failed\n");
160 return 1;
161 }
162
163 if (!pInstallHooks(hDll))
164 {
165 fprintf(stderr, "Error: Unable to install the hooks (%ld)\n",
166 GetLastError());
167 printf("failed\n");
168 return 1;
169 }
170
171 fprintf(stderr, "Ready for capture...\n");
173 if (!action)
174 {
175 fprintf(stderr, "Error: GetAction() failed\n");
176 printf("failed\n");
177 return 1;
178 }
179
180 switch (action->action)
181 {
182 case ACTION_FAILED:
183 printf("failed\n");
184 break;
185 case ACTION_NONE:
186 printf("none\n");
187 break;
188 case ACTION_FIND:
189 printf("find\n");
190 break;
191 case ACTION_BUTTON1:
192 case ACTION_BUTTON2:
193 case ACTION_BUTTON3:
194 printf("button%d %ld %ld\n", action->action-ACTION_BUTTON1+1,
195 action->x, action->y);
196 break;
197 default:
198 fprintf(stderr, "Error: Unknown action %d\n",action->action);
199 printf("%d\n", action->action);
200 break;
201 }
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));
207
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);
215
216 pFreeAction(action);
217 pRemoveHooks();
218 return 0;
219}
#define _setmode(fd, mode)
Definition: cat.c:21
#define _O_BINARY
Definition: cabinet.h:51
#define GetProcAddress(x, y)
Definition: compat.h:753
static void cleanup(void)
Definition: main.c:1335
const WCHAR * action
Definition: action.c:7479
#define printf
Definition: freeldr.h:93
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define exit(n)
Definition: config.h:202
@ ACTION_FIND
Definition: wclickat.c:57
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
static action_t *WINAPI * pGetAction()
static int init_debug()
Definition: wpickclick.c:52
static void cxlog(const char *format,...) __PRINTF_ATTR(1
Definition: wpickclick.c:61
static HINSTANCE load_hook_dll()
Definition: wpickclick.c:73
#define APP_NAME
Definition: wpickclick.c:34

Variable Documentation

◆ debug_on

int debug_on =0
static

Definition at line 51 of file wpickclick.c.

Referenced by cxlog(), and init_debug().