Release 950109
[wine.git] / misc / spy.c
blobf121b1846f7ae8b7571969b84c97752a30b7020f
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 "WM_INITMENU", /* 0x0116 */
157 "WM_INITMENUPOPUP", /* 0x0117 */
158 "WM_SYSTIMER", /* 0x0118 */
159 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
161 /* 0x0120 */
162 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
163 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
165 /* 0x0130 */
166 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
167 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
169 /* 0x0140 */
170 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
171 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
173 /* 0x0150 */
174 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
175 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
177 /* 0x0160 */
178 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
179 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
181 /* 0x0170 */
182 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
183 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
185 /* 0x0180 */
186 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
187 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
189 /* 0x0190 */
190 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
191 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
193 /* 0x01A0 */
194 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
195 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
197 /* 0x01B0 */
198 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
199 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
201 /* 0x01C0 */
202 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
203 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
205 /* 0x01D0 */
206 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
207 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
209 /* 0x01E0 */
210 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
211 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
213 /* 0x01F0 */
214 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
215 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
217 "WM_MOUSEMOVE", /* 0x0200 */
218 "WM_LBUTTONDOWN", /* 0x0201 */
219 "WM_LBUTTONUP", /* 0x0202 */
220 "WM_LBUTTONDBLCLK", /* 0x0203 */
221 "WM_RBUTTONDOWN", /* 0x0204 */
222 "WM_RBUTTONUP", /* 0x0205 */
223 "WM_RBUTTONDBLCLK", /* 0x0206 */
224 "WM_MBUTTONDOWN", /* 0x0207 */
225 "WM_MBUTTONUP", /* 0x0208 */
226 "WM_MBUTTONDBLCLK", /* 0x0209 */
227 NULL, NULL, NULL, NULL, NULL, NULL,
229 "WM_PARENTNOTIFY", /* 0x0210 */
231 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
232 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
234 /* 0x0220 */
235 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
236 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
239 NULL, /* 0x0230 */
240 "WM_ENTERSIZEMOVE", /* 0x0231 */
241 "WM_EXITSIZEMOVE" /* 0x0232 */
244 char SpyFilters[256+1];
245 char SpyIncludes[256+1];
247 #endif /* NOSPY */
249 /**********************************************************************
250 * SpyMessage
252 void SpyMessage(HWND hwnd, WORD msg, WORD wParam, LONG lParam)
254 #ifndef NOSPY
255 char msg_name[80];
257 if (SpyFp == NULL)
258 return;
260 if (msg > SPY_MAX_MSGNUM || MessageTypeNames[msg] == NULL)
261 sprintf(msg_name, "%04x", msg);
262 else
263 strcpy(msg_name, MessageTypeNames[msg]);
265 strcat(msg_name, ";");
267 if ((strlen(SpyIncludes) == 0 || strstr(SpyIncludes, msg_name) != NULL) &&
268 strstr(SpyFilters, msg_name) == NULL)
270 msg_name[strlen(msg_name) - 1] = '\0';
271 fprintf(SpyFp, "%04x %20.20s %04x %04x %08lx\n",
272 hwnd, msg_name, msg, wParam, lParam);
274 #endif
277 /**********************************************************************
278 * SpyInit
280 void SpyInit(void)
282 char filename[100];
284 if (SpyFp != NULL)
285 return;
287 if (Options.spyFilename == NULL)
289 GetPrivateProfileString("spy", "file", "", filename, sizeof(filename),
290 WINE_INI);
292 else
293 strncpy(filename, Options.spyFilename, 100);
295 if (strcasecmp(filename, "CON") == 0)
296 SpyFp = stdout;
297 else if (strlen(filename))
298 SpyFp = fopen(filename, "a");
299 else
301 SpyFp = NULL;
302 return;
305 GetPrivateProfileString("spy", "exclude", "", SpyFilters,
306 sizeof(SpyFilters)-1, WINE_INI);
307 GetPrivateProfileString("spy", "include", "", SpyIncludes,
308 sizeof(SpyIncludes)-1, WINE_INI);
310 if (*SpyIncludes != 0) {
311 strcat(SpyIncludes, ";");
313 if (*SpyFilters != 0) {
314 strcat(SpyFilters, ";");