Release 940804
[wine/gsoc-2012-control.git] / misc / spy.c
blobc52db357809237c4559e3827f4232a3511bde306
1 /* SPY.C
3 * Copyright 1994, Bob Amstadt
4 */
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <X11/Xlib.h>
9 #include <X11/Xresource.h>
10 #include <string.h>
11 #include "wineopts.h"
12 #include "windows.h"
13 #include "wine.h"
14 #include "options.h"
16 #ifndef NOSPY
18 #define SPY_MAX_MSGNUM 0x0232
20 const char *MessageTypeNames[SPY_MAX_MSGNUM + 1] =
22 "WM_NULL", /* 0x00 */
23 "WM_CREATE",
24 "WM_DESTROY",
25 "WM_MOVE",
26 "WM_UNUSED0",
27 "WM_SIZE",
28 "WM_ACTIVATE",
29 "WM_SETFOCUS",
30 "WM_KILLFOCUS",
31 "WM_UNUSED1",
32 "WM_ENABLE",
33 "WM_SETREDRAW",
34 "WM_SETTEXT",
35 "WM_GETTEXT",
36 "WM_GETTEXTLENGTH",
37 "WM_PAINT",
38 "WM_CLOSE", /* 0x10 */
39 "WM_QUERYENDSESSION",
40 "WM_QUIT",
41 "WM_QUERYOPEN",
42 "WM_ERASEBKGND",
43 "WM_SYSCOLORCHANGE",
44 "WM_ENDSESSION",
45 "WM_UNUSED2",
46 "WM_SHOWWINDOW",
47 "WM_CTLCOLOR",
48 "WM_WININICHANGE",
49 "WM_DEVMODECHANGE",
50 "WM_ACTIVATEAPP",
51 "WM_FONTCHANGE",
52 "WM_TIMECHANGE",
53 "WM_CANCELMODE",
54 "WM_SETCURSOR", /* 0x20 */
55 "WM_MOUSEACTIVATE",
56 "WM_CHILDACTIVATE",
57 "WM_QUEUESYNC",
58 "WM_GETMINMAXINFO",
59 "WM_UNUSED3",
60 "WM_PAINTICON",
61 "WM_ICONERASEBKGND",
62 "WM_NEXTDLGCTL",
63 "WM_UNUSED4",
64 "WM_SPOOLERSTATUS",
65 "WM_DRAWITEM",
66 "WM_MEASUREITEM",
67 "WM_DELETEITEM",
68 "WM_VKEYTOITEM",
69 "WM_CHARTOITEM",
70 "WM_SETFONT", /* 0x30 */
71 "WM_GETFONT", NULL, NULL, NULL, NULL, NULL, NULL,
72 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
74 /* 0x40 */
75 NULL, NULL, NULL, NULL, NULL, NULL,
76 "WM_WINDOWPOSCHANGING", /* 0x0046 */
77 "WM_WINDOWPOSCHANGED", /* 0x0047 */
78 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
80 /* 0x0050 */
81 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
82 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
84 /* 0x0060 */
85 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
86 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
88 /* 0x0070 */
89 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
90 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
92 NULL, /* 0x0080 */
93 "WM_NCCREATE", /* 0x0081 */
94 "WM_NCDESTROY", /* 0x0082 */
95 "WM_NCCALCSIZE", /* 0x0083 */
96 "WM_NCHITTEST", /* 0x0084 */
97 "WM_NCPAINT", /* 0x0085 */
98 "WM_NCACTIVATE", /* 0x0086 */
99 "WM_GETDLGCODE", /* 0x0087 */
100 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
102 /* 0x0090 */
103 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
104 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
106 /* 0x00A0 */
107 "WM_NCMOUSEMOVE", /* 0x00A0 */
108 "WM_NCLBUTTONDOWN", /* 0x00A1 */
109 "WM_NCLBUTTONUP", /* 0x00A2 */
110 "WM_NCLBUTTONDBLCLK", /* 0x00A3 */
111 "WM_NCRBUTTONDOWN", /* 0x00A4 */
112 "WM_NCRBUTTONUP", /* 0x00A5 */
113 "WM_NCRBUTTONDBLCLK", /* 0x00A6 */
114 "WM_NCMBUTTONDOWN", /* 0x00A7 */
115 "WM_NCMBUTTONUP", /* 0x00A8 */
116 "WM_NCMBUTTONDBLCLK", /* 0x00A9 */
117 NULL, NULL, NULL, NULL, NULL, NULL,
119 /* 0x00B0 */
120 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
121 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
123 /* 0x00C0 */
124 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
125 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
127 /* 0x00D0 */
128 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
129 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
131 /* 0x00E0 */
132 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
133 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
135 /* 0x00F0 */
136 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
137 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
139 "WM_KEYDOWN", /* 0x0100 */
140 "WM_KEYUP", /* 0x0101 */
141 "WM_CHAR", /* 0x0102 */
142 "WM_DEADCHAR", /* 0x0103 */
143 "WM_SYSKEYDOWN", /* 0x0104 */
144 "WM_SYSKEYUP", /* 0x0105 */
145 "WM_SYSCHAR", /* 0x0106 */
146 "WM_SYSDEADCHAR", /* 0x0107 */
147 "WM_KEYLAST", /* 0x0108 */
148 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
150 "WM_INITDIALOG", /* 0x0110 */
151 "WM_COMMAND", /* 0x0111 */
152 "WM_SYSCOMMAND", /* 0x0112 */
153 "WM_TIMER", /* 0x0113 */
154 "WM_HSCROLL", /* 0x0114 */
155 "WM_VSCROLL", /* 0x0115 */
156 NULL, NULL,
157 "WM_SYSTIMER", /* 0x0118 */
158 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
160 /* 0x0120 */
161 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
162 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
164 /* 0x0130 */
165 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
166 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
168 /* 0x0140 */
169 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
170 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
172 /* 0x0150 */
173 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
174 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
176 /* 0x0160 */
177 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
178 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
180 /* 0x0170 */
181 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
182 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
184 /* 0x0180 */
185 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
186 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
188 /* 0x0190 */
189 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
190 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
192 /* 0x01A0 */
193 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
194 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
196 /* 0x01B0 */
197 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
198 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
200 /* 0x01C0 */
201 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
202 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
204 /* 0x01D0 */
205 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
206 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
208 /* 0x01E0 */
209 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
210 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
212 /* 0x01F0 */
213 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
214 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
216 "WM_MOUSEMOVE", /* 0x0200 */
217 "WM_LBUTTONDOWN", /* 0x0201 */
218 "WM_LBUTTONUP", /* 0x0202 */
219 "WM_LBUTTONDBLCLK", /* 0x0203 */
220 "WM_RBUTTONDOWN", /* 0x0204 */
221 "WM_RBUTTONUP", /* 0x0205 */
222 "WM_RBUTTONDBLCLK", /* 0x0206 */
223 "WM_MBUTTONDOWN", /* 0x0207 */
224 "WM_MBUTTONUP", /* 0x0208 */
225 "WM_MBUTTONDBLCLK", /* 0x0209 */
226 NULL, NULL, NULL, NULL, NULL, NULL,
228 "WM_PARENTNOTIFY", /* 0x0210 */
230 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
231 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
233 /* 0x0220 */
234 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
235 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
238 NULL, /* 0x0230 */
239 "WM_ENTERSIZEMOVE", /* 0x0231 */
240 "WM_EXITSIZEMOVE" /* 0x0232 */
243 char SpyFilters[256];
244 char SpyIncludes[256];
246 #endif /* NOSPY */
248 /**********************************************************************
249 * SpyMessage
251 void SpyMessage(HWND hwnd, WORD msg, WORD wParam, LONG lParam)
253 #ifndef NOSPY
254 char msg_name[80];
256 if (SpyFp == NULL)
257 return;
259 if (msg > SPY_MAX_MSGNUM || MessageTypeNames[msg] == NULL)
260 sprintf(msg_name, "%04x", msg);
261 else
262 strcpy(msg_name, MessageTypeNames[msg]);
264 strcat(msg_name, ";");
266 if ((strlen(SpyIncludes) == 0 || strstr(SpyIncludes, msg_name) != NULL) &&
267 strstr(SpyFilters, msg_name) == NULL)
269 msg_name[strlen(msg_name) - 1] = '\0';
270 fprintf(SpyFp, "%04.4x %20.20s %04.4x %04.4x %08.8x\n",
271 hwnd, msg_name, msg, wParam, lParam);
273 #endif
276 /**********************************************************************
277 * SpyInit
279 void SpyInit(void)
281 char filename[100];
283 if (SpyFp != NULL)
284 return;
286 if (Options.spyFilename == NULL)
288 GetPrivateProfileString("spy", "file", "", filename, sizeof(filename),
289 WINE_INI);
291 else
292 strncpy(filename, Options.spyFilename, 100);
294 if (strcasecmp(filename, "CON") == 0)
295 SpyFp = stdout;
296 else if (strlen(filename))
297 SpyFp = fopen(filename, "a");
298 else
300 SpyFp = NULL;
301 return;
304 GetPrivateProfileString("spy", "exclude", "", SpyFilters,
305 sizeof(SpyFilters), WINE_INI);
306 GetPrivateProfileString("spy", "include", "", SpyIncludes,
307 sizeof(SpyIncludes), WINE_INI);