32 |
|
|
33 |
#define DLL_EXPORT __declspec(dllexport) |
#define DLL_EXPORT __declspec(dllexport) |
34 |
|
|
35 |
|
#ifdef __GNUC__ |
36 |
|
#define SHARED __attribute__((section ("SHAREDDATA"), shared)) |
37 |
|
#else |
38 |
|
#define SHARED |
39 |
|
#endif |
40 |
|
|
41 |
// Shared DATA |
// Shared DATA |
42 |
#pragma data_seg ( "SHAREDDATA" ) |
#pragma data_seg ( "SHAREDDATA" ) |
43 |
|
|
44 |
// this is the total number of processes this dll is currently attached to |
// this is the total number of processes this dll is currently attached to |
45 |
int g_instance_count = 0; |
int g_instance_count SHARED = 0; |
46 |
|
|
47 |
|
// blocks for locally generated events |
48 |
|
RECT g_block_move SHARED = { 0, 0, 0, 0 }; |
49 |
|
|
50 |
#pragma data_seg () |
#pragma data_seg () |
51 |
|
|
53 |
|
|
54 |
static HHOOK g_cbt_hook = NULL; |
static HHOOK g_cbt_hook = NULL; |
55 |
static HHOOK g_wndproc_hook = NULL; |
static HHOOK g_wndproc_hook = NULL; |
56 |
|
static HHOOK g_wndprocret_hook = NULL; |
57 |
|
|
58 |
static HINSTANCE g_instance = NULL; |
static HINSTANCE g_instance = NULL; |
59 |
|
|
62 |
static void |
static void |
63 |
update_position(HWND hwnd) |
update_position(HWND hwnd) |
64 |
{ |
{ |
65 |
RECT rect; |
RECT rect, blocked; |
66 |
|
|
67 |
if (!GetWindowRect(hwnd, &rect)) |
if (!GetWindowRect(hwnd, &rect)) |
68 |
{ |
{ |
70 |
return; |
return; |
71 |
} |
} |
72 |
|
|
73 |
|
WaitForSingleObject(g_mutex, INFINITE); |
74 |
|
memcpy(&blocked, &g_block_move, sizeof(RECT)); |
75 |
|
ReleaseMutex(g_mutex); |
76 |
|
|
77 |
|
if ((rect.left == blocked.left) && (rect.top == blocked.top) |
78 |
|
&& (rect.right == blocked.right) && (rect.bottom == blocked.bottom)) |
79 |
|
return; |
80 |
|
|
81 |
vchannel_write("POSITION,0x%p,%d,%d,%d,%d,0x%x", |
vchannel_write("POSITION,0x%p,%d,%d,%d,%d,0x%x", |
82 |
hwnd, |
hwnd, |
83 |
rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 0); |
rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 0); |
126 |
|
|
127 |
if (wp->flags & SWP_SHOWWINDOW) |
if (wp->flags & SWP_SHOWWINDOW) |
128 |
{ |
{ |
129 |
char title[150]; |
unsigned short title[150]; |
130 |
int state; |
int state; |
131 |
|
|
132 |
vchannel_write("CREATE,0x%p,0x%p,0x%x", hwnd, parent, 0); |
vchannel_write("CREATE,0x%p,0x%p,0x%x", hwnd, parent, 0); |
133 |
|
|
134 |
GetWindowText(hwnd, title, sizeof(title)); |
GetWindowTextW(hwnd, title, sizeof(title) / sizeof(*title)); |
135 |
|
|
136 |
vchannel_write("TITLE,0x%x,%s,0x%x", hwnd, |
vchannel_write("TITLE,0x%x,%s,0x%x", hwnd, |
137 |
vchannel_strfilter(title), 0); |
vchannel_strfilter_unicode(title), 0); |
138 |
|
|
139 |
if (style & WS_MAXIMIZE) |
if (style & WS_MAXIMIZE) |
140 |
state = 2; |
state = 2; |
143 |
else |
else |
144 |
state = 0; |
state = 0; |
145 |
|
|
|
vchannel_write("STATE,0x%p,0x%x,0x%x", hwnd, state, 0); |
|
|
|
|
146 |
update_position(hwnd); |
update_position(hwnd); |
147 |
|
|
148 |
/* FIXME: Figure out z order */ |
vchannel_write("STATE,0x%p,0x%x,0x%x", hwnd, state, 0); |
149 |
} |
} |
150 |
|
|
151 |
if (wp->flags & SWP_HIDEWINDOW) |
if (wp->flags & SWP_HIDEWINDOW) |
180 |
update_position(hwnd); |
update_position(hwnd); |
181 |
break; |
break; |
182 |
|
|
183 |
|
case WM_DESTROY: |
184 |
|
if (!(style & WS_VISIBLE)) |
185 |
|
break; |
186 |
|
vchannel_write("DESTROY,0x%p,0x%x", hwnd, 0); |
187 |
|
break; |
188 |
|
|
189 |
|
default: |
190 |
|
break; |
191 |
|
} |
192 |
|
|
193 |
|
end: |
194 |
|
return CallNextHookEx(g_wndproc_hook, code, cur_thread, details); |
195 |
|
} |
196 |
|
|
197 |
|
static LRESULT CALLBACK |
198 |
|
wndprocret_hook_proc(int code, WPARAM cur_thread, LPARAM details) |
199 |
|
{ |
200 |
|
HWND hwnd, parent; |
201 |
|
UINT msg; |
202 |
|
WPARAM wparam; |
203 |
|
LPARAM lparam; |
204 |
|
|
205 |
|
LONG style; |
206 |
|
|
207 |
|
if (code < 0) |
208 |
|
goto end; |
209 |
|
|
210 |
|
hwnd = ((CWPRETSTRUCT *) details)->hwnd; |
211 |
|
msg = ((CWPRETSTRUCT *) details)->message; |
212 |
|
wparam = ((CWPRETSTRUCT *) details)->wParam; |
213 |
|
lparam = ((CWPRETSTRUCT *) details)->lParam; |
214 |
|
|
215 |
|
style = GetWindowLong(hwnd, GWL_STYLE); |
216 |
|
|
217 |
|
/* Docs say that WS_CHILD and WS_POPUP is an illegal combination, |
218 |
|
but they exist nonetheless. */ |
219 |
|
if ((style & WS_CHILD) && !(style & WS_POPUP)) |
220 |
|
goto end; |
221 |
|
|
222 |
|
switch (msg) |
223 |
|
{ |
224 |
case WM_SETTEXT: |
case WM_SETTEXT: |
225 |
{ |
{ |
226 |
char *title; |
unsigned short title[150]; |
227 |
if (!(style & WS_VISIBLE)) |
if (!(style & WS_VISIBLE)) |
228 |
break; |
break; |
229 |
title = _strdup((char *) lparam); |
/* We cannot use the string in lparam because |
230 |
|
we need unicode. */ |
231 |
|
GetWindowTextW(hwnd, title, sizeof(title) / sizeof(*title)); |
232 |
vchannel_write("TITLE,0x%p,%s,0x%x", hwnd, |
vchannel_write("TITLE,0x%p,%s,0x%x", hwnd, |
233 |
vchannel_strfilter(title), 0); |
vchannel_strfilter_unicode(title), 0); |
|
free(title); |
|
234 |
break; |
break; |
235 |
} |
} |
236 |
|
|
|
case WM_DESTROY: |
|
|
if (!(style & WS_VISIBLE)) |
|
|
break; |
|
|
vchannel_write("DESTROY,0x%p,0x%x", hwnd, 0); |
|
|
break; |
|
|
|
|
237 |
default: |
default: |
238 |
break; |
break; |
239 |
} |
} |
240 |
|
|
241 |
end: |
end: |
242 |
return CallNextHookEx(g_wndproc_hook, code, cur_thread, details); |
return CallNextHookEx(g_wndprocret_hook, code, cur_thread, details); |
243 |
} |
} |
244 |
|
|
245 |
static LRESULT CALLBACK |
static LRESULT CALLBACK |
288 |
|
|
289 |
if (!g_wndproc_hook) |
if (!g_wndproc_hook) |
290 |
g_wndproc_hook = SetWindowsHookEx(WH_CALLWNDPROC, wndproc_hook_proc, g_instance, 0); |
g_wndproc_hook = SetWindowsHookEx(WH_CALLWNDPROC, wndproc_hook_proc, g_instance, 0); |
291 |
|
|
292 |
|
if (!g_wndprocret_hook) |
293 |
|
g_wndprocret_hook = |
294 |
|
SetWindowsHookEx(WH_CALLWNDPROCRET, wndprocret_hook_proc, g_instance, 0); |
295 |
} |
} |
296 |
|
|
297 |
DLL_EXPORT void |
DLL_EXPORT void |
302 |
|
|
303 |
if (g_wndproc_hook) |
if (g_wndproc_hook) |
304 |
UnhookWindowsHookEx(g_wndproc_hook); |
UnhookWindowsHookEx(g_wndproc_hook); |
305 |
|
|
306 |
|
if (g_wndprocret_hook) |
307 |
|
UnhookWindowsHookEx(g_wndprocret_hook); |
308 |
|
} |
309 |
|
|
310 |
|
DLL_EXPORT void |
311 |
|
SafeMoveWindow(HWND hwnd, int x, int y, int width, int height) |
312 |
|
{ |
313 |
|
WaitForSingleObject(g_mutex, INFINITE); |
314 |
|
g_block_move.left = x; |
315 |
|
g_block_move.top = y; |
316 |
|
g_block_move.right = x + width; |
317 |
|
g_block_move.bottom = y + height; |
318 |
|
ReleaseMutex(g_mutex); |
319 |
|
|
320 |
|
SetWindowPos(hwnd, NULL, x, y, width, height, SWP_NOACTIVATE | SWP_NOZORDER); |
321 |
|
|
322 |
|
WaitForSingleObject(g_mutex, INFINITE); |
323 |
|
memset(&g_block_move, 0, sizeof(RECT)); |
324 |
|
ReleaseMutex(g_mutex); |
325 |
} |
} |
326 |
|
|
327 |
DLL_EXPORT int |
DLL_EXPORT int |