9 |
#include "wtsapi32.h" |
#include "wtsapi32.h" |
10 |
#include "Cchannel.h" |
#include "Cchannel.h" |
11 |
|
|
12 |
#define DLL_EXPORT extern "C" __declspec(dllexport) |
#define DLL_EXPORT extern "C" __declspec(dllexport) |
13 |
|
|
14 |
// Shared DATA |
// Shared DATA |
15 |
#pragma data_seg ( "SHAREDDATA" ) |
#pragma data_seg ( "SHAREDDATA" ) |
25 |
bool bHooked = false; |
bool bHooked = false; |
26 |
bool bHooked2 = false; |
bool bHooked2 = false; |
27 |
bool bHooked3 = false; |
bool bHooked3 = false; |
28 |
HHOOK hhook = 0; //cbt |
HHOOK hhook = 0; //cbt |
29 |
HHOOK hhook2 = 0; //shell |
HHOOK hhook2 = 0; //shell |
30 |
HHOOK hhook3 = 0; //wnd proc |
HHOOK hhook3 = 0; //wnd proc |
31 |
HINSTANCE hInst = 0; |
HINSTANCE hInst = 0; |
32 |
HANDLE m_vcHandle = 0; |
HANDLE m_vcHandle = 0; |
33 |
|
|
34 |
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD ul_reason_for_call, |
BOOL APIENTRY DllMain( HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID lpReserved ) |
|
LPVOID lpReserved) |
|
35 |
{ |
{ |
36 |
switch (ul_reason_for_call) { |
switch ( ul_reason_for_call ) { |
37 |
case DLL_PROCESS_ATTACH: { |
case DLL_PROCESS_ATTACH: { |
38 |
// remember our instance handle |
// remember our instance handle |
39 |
hInst = hinstDLL; |
hInst = hinstDLL; |
40 |
++iInstanceCount; |
++iInstanceCount; |
41 |
OpenVirtualChannel(); |
OpenVirtualChannel(); |
42 |
break; |
break; |
43 |
} |
} |
44 |
|
|
45 |
case DLL_THREAD_ATTACH: |
case DLL_THREAD_ATTACH: |
46 |
break; |
break; |
47 |
case DLL_THREAD_DETACH: |
case DLL_THREAD_DETACH: |
48 |
break; |
break; |
49 |
case DLL_PROCESS_DETACH: { |
case DLL_PROCESS_DETACH: { |
50 |
--iInstanceCount; |
--iInstanceCount; |
51 |
CloseVirtualChannel(); |
CloseVirtualChannel(); |
52 |
} |
} |
53 |
break; |
break; |
54 |
} |
} |
55 |
|
|
56 |
return TRUE; |
return TRUE; |
57 |
} |
} |
58 |
|
|
59 |
LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam) |
LRESULT CALLBACK CallWndProc( int nCode, WPARAM wParam, LPARAM lParam ) |
60 |
{ |
{ |
61 |
if (nCode < 0) { |
if ( nCode < 0 ) { |
62 |
return CallNextHookEx(hhook3, nCode, wParam, lParam); |
return CallNextHookEx( hhook3, nCode, wParam, lParam ); |
63 |
} |
} |
64 |
|
|
65 |
PCHAR buffer = NULL; |
PCHAR buffer = NULL; |
66 |
char windowTitle[150] = { "" }; |
char windowTitle[ 150 ] = { "" |
67 |
|
}; |
68 |
HWND windowHandle = NULL; |
HWND windowHandle = NULL; |
69 |
char result[255] = { "" }; |
HWND windowHandle2 = NULL; |
70 |
char strWindowId[25]; |
char result[ 255 ] = { "" |
71 |
char type[25]; |
}; |
72 |
|
char strWindowId[ 25 ]; |
73 |
|
char type[ 25 ]; |
74 |
|
|
75 |
LONG b, t, l, r; |
LONG b, t, l, r; |
76 |
char strB[5]; |
char strX[ 5 ]; |
77 |
char strT[5]; |
char strY[ 5 ]; |
78 |
char strL[5]; |
char strW[ 5 ]; |
79 |
char strR[5]; |
char strH[ 5 ]; |
80 |
RECT rect; |
RECT rect; |
81 |
|
|
82 |
CWPSTRUCT *details = (CWPSTRUCT *) lParam; |
CWPSTRUCT *details = ( CWPSTRUCT * ) lParam; |
83 |
|
|
84 |
switch (details->message) { |
switch ( details->message ) { |
85 |
case WM_SIZING: |
case WM_SIZING: |
|
case WM_MOVING: |
|
|
|
|
86 |
windowHandle = details->hwnd; |
windowHandle = details->hwnd; |
87 |
//get win name |
//get win name |
88 |
GetWindowText(windowHandle, windowTitle, 150); |
GetWindowText( windowHandle, windowTitle, 150 ); |
89 |
|
|
90 |
//get an id for it |
//get an id for it |
91 |
itoa((int) windowHandle, strWindowId, 10); |
itoa( ( int ) windowHandle, strWindowId, 10 ); |
92 |
|
|
93 |
//get coords |
//get coords |
94 |
GetWindowRect(windowHandle, &rect); |
GetWindowRect( windowHandle, &rect ); |
95 |
b = rect.bottom; |
b = rect.bottom; |
96 |
t = rect.top; |
t = rect.top; |
97 |
l = rect.left; |
l = rect.left; |
98 |
r = rect.right; |
r = rect.right; |
99 |
ltoa(b, strB, 10); |
ltoa( b - t, strH, 10 ); |
100 |
ltoa(t, strT, 10); |
ltoa( t, strY, 10 ); |
101 |
ltoa(r, strR, 10); |
ltoa( r - l, strW, 10 ); |
102 |
ltoa(l, strL, 10); |
ltoa( l, strX, 10 ); |
103 |
|
|
104 |
////setup return string |
////setup return string |
105 |
strcat(result, "MSG=CALLWNDPROC_WM_MOVING;"); |
strcat( result, "MSG=CALLWNDPROC_WM_SIZING;OP=6;" ); |
106 |
strcat(result, "ID="); |
strcat( result, "ID=" ); |
107 |
strcat(result, strWindowId); |
strcat( result, strWindowId ); |
108 |
strcat(result, ";"); |
strcat( result, ";" ); |
109 |
strcat(result, "TITLE="); |
strcat( result, "TITLE=" ); |
110 |
strcat(result, windowTitle); |
strcat( result, windowTitle ); |
111 |
strcat(result, ";"); |
strcat( result, ";" ); |
112 |
strcat(result, "POS="); |
strcat( result, "X=" ); |
113 |
strcat(result, strL); |
strcat( result, strX ); |
114 |
strcat(result, "~"); |
strcat( result, ";" ); |
115 |
strcat(result, strT); |
strcat( result, "Y=" ); |
116 |
strcat(result, "~"); |
strcat( result, strY ); |
117 |
strcat(result, strR); |
strcat( result, ";" ); |
118 |
strcat(result, "~"); |
strcat( result, "H=" ); |
119 |
strcat(result, strB); |
strcat( result, strH ); |
120 |
strcat(result, ";"); |
strcat( result, ";" ); |
121 |
|
strcat( result, "W=" ); |
122 |
|
strcat( result, strW ); |
123 |
|
strcat( result, "." ); |
124 |
|
|
125 |
buffer = result; |
buffer = result; |
126 |
|
|
127 |
break; |
break; |
128 |
|
case WM_MOVING: |
129 |
default: |
|
130 |
|
windowHandle = details->hwnd; |
131 |
|
//get win name |
132 |
|
GetWindowText( windowHandle, windowTitle, 150 ); |
133 |
|
|
134 |
|
//get an id for it |
135 |
|
itoa( ( int ) windowHandle, strWindowId, 10 ); |
136 |
|
|
137 |
|
//get coords |
138 |
|
GetWindowRect( windowHandle, &rect ); |
139 |
|
b = rect.bottom; |
140 |
|
t = rect.top; |
141 |
|
l = rect.left; |
142 |
|
r = rect.right; |
143 |
|
ltoa( b - t, strH, 10 ); |
144 |
|
ltoa( t, strY, 10 ); |
145 |
|
ltoa( r - l, strW, 10 ); |
146 |
|
ltoa( l, strX, 10 ); |
147 |
|
|
148 |
|
////setup return string |
149 |
|
strcat( result, "MSG=CALLWNDPROC_WM_MOVING;OP=2;" ); |
150 |
|
strcat( result, "ID=" ); |
151 |
|
strcat( result, strWindowId ); |
152 |
|
strcat( result, ";" ); |
153 |
|
strcat( result, "TITLE=" ); |
154 |
|
strcat( result, windowTitle ); |
155 |
|
strcat( result, ";" ); |
156 |
|
strcat( result, "X=" ); |
157 |
|
strcat( result, strX ); |
158 |
|
strcat( result, ";" ); |
159 |
|
strcat( result, "Y=" ); |
160 |
|
strcat( result, strY ); |
161 |
|
strcat( result, ";" ); |
162 |
|
strcat( result, "H=" ); |
163 |
|
strcat( result, strH ); |
164 |
|
strcat( result, ";" ); |
165 |
|
strcat( result, "W=" ); |
166 |
|
strcat( result, strW ); |
167 |
|
strcat( result, "." ); |
168 |
|
|
169 |
|
buffer = result; |
170 |
|
|
171 |
|
break; |
172 |
|
|
173 |
|
|
174 |
|
case WM_WINDOWPOSCHANGING: |
175 |
|
|
176 |
|
windowHandle = details->hwnd; |
177 |
|
//windowHandle2 = details->hwndInsertAfter; |
178 |
|
//get win name |
179 |
|
GetWindowText( windowHandle, windowTitle, 150 ); |
180 |
|
|
181 |
|
//get an id for it |
182 |
|
itoa( ( int ) windowHandle, strWindowId, 10 ); |
183 |
|
|
184 |
|
//get coords |
185 |
|
GetWindowRect( windowHandle, &rect ); |
186 |
|
b = rect.bottom; |
187 |
|
t = rect.top; |
188 |
|
l = rect.left; |
189 |
|
r = rect.right; |
190 |
|
ltoa( b - t, strH, 10 ); |
191 |
|
ltoa( t, strY, 10 ); |
192 |
|
ltoa( r - l, strW, 10 ); |
193 |
|
ltoa( l, strX, 10 ); |
194 |
|
|
195 |
|
////setup return string |
196 |
|
strcat( result, "MSG=CALLWNDPROC_WM_WINDOWPOSCHANGING;OP=7;" ); |
197 |
|
strcat( result, "ID=" ); |
198 |
|
strcat( result, strWindowId ); |
199 |
|
strcat( result, ";" ); |
200 |
|
strcat( result, "TITLE=" ); |
201 |
|
strcat( result, windowTitle ); |
202 |
|
strcat( result, ";" ); |
203 |
|
strcat( result, "X=" ); |
204 |
|
strcat( result, strX ); |
205 |
|
strcat( result, ";" ); |
206 |
|
strcat( result, "Y=" ); |
207 |
|
strcat( result, strY ); |
208 |
|
strcat( result, ";" ); |
209 |
|
strcat( result, "H=" ); |
210 |
|
strcat( result, strH ); |
211 |
|
strcat( result, ";" ); |
212 |
|
strcat( result, "W=" ); |
213 |
|
strcat( result, strW ); |
214 |
|
strcat( result, "." ); |
215 |
|
|
216 |
|
buffer = result; |
217 |
|
|
218 |
|
break; |
219 |
|
case WM_WINDOWPOSCHANGED: |
220 |
|
|
221 |
|
windowHandle = details->hwnd; |
222 |
|
//windowHandle2 = details->hwndInsertAfter; |
223 |
|
//get win name |
224 |
|
GetWindowText( windowHandle, windowTitle, 150 ); |
225 |
|
|
226 |
|
//get an id for it |
227 |
|
itoa( ( int ) windowHandle, strWindowId, 10 ); |
228 |
|
|
229 |
|
//get coords |
230 |
|
GetWindowRect( windowHandle, &rect ); |
231 |
|
b = rect.bottom; |
232 |
|
t = rect.top; |
233 |
|
l = rect.left; |
234 |
|
r = rect.right; |
235 |
|
ltoa( b - t, strH, 10 ); |
236 |
|
ltoa( t, strY, 10 ); |
237 |
|
ltoa( r - l, strW, 10 ); |
238 |
|
ltoa( l, strX, 10 ); |
239 |
|
|
240 |
|
////setup return string |
241 |
|
strcat( result, "MSG=CALLWNDPROC_WM_WINDOWPOSCHANGED;OP=8;" ); |
242 |
|
strcat( result, "ID=" ); |
243 |
|
strcat( result, strWindowId ); |
244 |
|
strcat( result, ";" ); |
245 |
|
strcat( result, "TITLE=" ); |
246 |
|
strcat( result, windowTitle ); |
247 |
|
strcat( result, ";" ); |
248 |
|
strcat( result, "X=" ); |
249 |
|
strcat( result, strX ); |
250 |
|
strcat( result, ";" ); |
251 |
|
strcat( result, "Y=" ); |
252 |
|
strcat( result, strY ); |
253 |
|
strcat( result, ";" ); |
254 |
|
strcat( result, "H=" ); |
255 |
|
strcat( result, strH ); |
256 |
|
strcat( result, ";" ); |
257 |
|
strcat( result, "W=" ); |
258 |
|
strcat( result, strW ); |
259 |
|
strcat( result, "." ); |
260 |
|
|
261 |
|
buffer = result; |
262 |
|
|
263 |
|
break; |
264 |
|
|
265 |
|
default: |
266 |
break; |
break; |
267 |
} |
} |
268 |
|
|
269 |
if (ChannelIsOpen()) { |
if ( ChannelIsOpen() ) { |
270 |
if (buffer != NULL) { |
if ( buffer != NULL ) { |
271 |
WriteToChannel(buffer); |
WriteToChannel( buffer ); |
272 |
} |
} |
273 |
} |
} |
274 |
|
|
275 |
return CallNextHookEx(hhook3, nCode, wParam, lParam); |
return CallNextHookEx( hhook3, nCode, wParam, lParam ); |
276 |
} |
} |
277 |
|
|
278 |
LRESULT CALLBACK CbtProc(int nCode, WPARAM wParam, LPARAM lParam) |
LRESULT CALLBACK CbtProc( int nCode, WPARAM wParam, LPARAM lParam ) |
279 |
{ |
{ |
280 |
if (nCode < 0) { |
if ( nCode < 0 ) { |
281 |
return CallNextHookEx(hhook, nCode, wParam, lParam); |
return CallNextHookEx( hhook, nCode, wParam, lParam ); |
282 |
} |
} |
283 |
|
|
284 |
|
|
285 |
PCHAR buffer = NULL; |
PCHAR buffer = NULL; |
286 |
|
|
287 |
|
|
288 |
char windowTitle[150] = { "" }; |
char windowTitle[ 150 ] = { "" |
289 |
|
}; |
290 |
HWND windowHandle = NULL; |
HWND windowHandle = NULL; |
291 |
char result[255] = { "" }; |
char result[ 255 ] = { "" |
292 |
char strWindowId[25]; |
}; |
293 |
char type[25]; |
char strWindowId[ 25 ]; |
294 |
|
char type[ 25 ]; |
295 |
|
|
296 |
|
|
297 |
LONG b, t, l, r; |
LONG b, t, l, r; |
298 |
char strB[5]; |
char strW[ 5 ]; |
299 |
char strT[5]; |
char strY[ 5 ]; |
300 |
char strL[5]; |
char strX[ 5 ]; |
301 |
char strR[5]; |
char strH[ 5 ]; |
302 |
RECT rect; |
RECT rect; |
303 |
|
|
304 |
int i = 0; //tmp |
int i = 0; //tmp |
305 |
|
|
306 |
switch (nCode) { |
switch ( nCode ) { |
307 |
case HCBT_MINMAX: |
case HCBT_MINMAX: |
308 |
|
|
309 |
windowHandle = (HWND) wParam; |
windowHandle = ( HWND ) wParam; |
310 |
//get win name |
//get win name |
311 |
GetWindowText(windowHandle, windowTitle, 150); |
GetWindowText( windowHandle, windowTitle, 150 ); |
312 |
|
|
313 |
//get an id for it |
//get an id for it |
314 |
itoa((int) windowHandle, strWindowId, 10); |
itoa( ( int ) windowHandle, strWindowId, 10 ); |
315 |
|
|
316 |
//get operation type(min,max). if max, do not clip at all,if min use window's previous coords |
//get operation type(min,max). if max, do not clip at all,if min use window's previous coords |
317 |
//codes are: |
//codes are: |
318 |
|
|
319 |
// SW_HIDE= 0 SW_SHOWNORMAL=1 SW_NORMAL=1 SW_SHOWMINIMIZED=2 SW_SHOWMAXIMIZED=3 SW_MAXIMIZE=3 |
// SW_HIDE= 0 SW_SHOWNORMAL=1 SW_NORMAL=1 SW_SHOWMINIMIZED=2 SW_SHOWMAXIMIZED=3 SW_MAXIMIZE=3 |
320 |
// SW_SHOWNOACTIVATE=4 SW_SHOW=5 SW_MINIMIZE=6 SW_SHOWMINNOACTIVE=7 SW_SHOWNA=8 SW_RESTORE=9 |
// SW_SHOWNOACTIVATE=4 SW_SHOW=5 SW_MINIMIZE=6 SW_SHOWMINNOACTIVE=7 SW_SHOWNA=8 SW_RESTORE=9 |
321 |
// SW_SHOWDEFAULT=10 SW_FORCEMINIMIZE=11 SW_MAX=11 |
// SW_SHOWDEFAULT=10 SW_FORCEMINIMIZE=11 SW_MAX=11 |
322 |
|
|
323 |
itoa((int) lParam, type, 10); |
itoa( ( int ) lParam, type, 10 ); |
324 |
|
|
325 |
//get coords |
//get coords |
326 |
GetWindowRect(windowHandle, &rect); |
GetWindowRect( windowHandle, &rect ); |
327 |
b = rect.bottom; |
b = rect.bottom; |
328 |
t = rect.top; |
t = rect.top; |
329 |
l = rect.left; |
l = rect.left; |
330 |
r = rect.right; |
r = rect.right; |
331 |
ltoa(b, strB, 10); |
ltoa( b - t, strW, 10 ); |
332 |
ltoa(t, strT, 10); |
ltoa( t, strY, 10 ); |
333 |
ltoa(r, strR, 10); |
ltoa( r - l, strH, 10 ); |
334 |
ltoa(l, strL, 10); |
ltoa( l, strX, 10 ); |
335 |
|
|
336 |
//get name |
//get name |
337 |
GetWindowText(windowHandle, windowTitle, 150); |
GetWindowText( windowHandle, windowTitle, 150 ); |
338 |
|
|
339 |
////setup return string |
////setup return string |
340 |
strcat(result, "MSG=HCBT_MINMAX;"); |
strcat( result, "MSG=HCBT_MINMAX;OP=4;" ); |
341 |
strcat(result, "ID="); |
|
342 |
strcat(result, strWindowId); |
// SW_SHOWNOACTIVATE=4 SW_SHOW=5 SW_MINIMIZE=6 SW_SHOWMINNOACTIVE=7 SW_SHOWNA=8 SW_RESTORE=9 |
343 |
strcat(result, ";"); |
// SW_SHOWDEFAULT=10 SW_FORCEMINIMIZE=11 SW_MAX=11 |
344 |
strcat(result, "TITLE="); |
strcat( result, "ID=" ); |
345 |
strcat(result, windowTitle); |
strcat( result, strWindowId ); |
346 |
strcat(result, ";"); |
strcat( result, ";" ); |
347 |
strcat(result, "POS="); |
strcat( result, "TITLE=" ); |
348 |
strcat(result, strL); |
strcat( result, windowTitle ); |
349 |
strcat(result, "~"); |
strcat( result, ";" ); |
350 |
strcat(result, strT); |
strcat( result, "X=" ); |
351 |
strcat(result, "~"); |
strcat( result, strX ); |
352 |
strcat(result, strR); |
strcat( result, ";" ); |
353 |
strcat(result, "~"); |
strcat( result, "Y=" ); |
354 |
strcat(result, strB); |
strcat( result, strY ); |
355 |
strcat(result, ";"); |
strcat( result, ";" ); |
356 |
strcat(result, "TYPE="); |
strcat( result, "H=" ); |
357 |
strcat(result, type); |
strcat( result, strH ); |
358 |
strcat(result, ";"); |
strcat( result, ";" ); |
359 |
|
strcat( result, "W=" ); |
360 |
|
strcat( result, strW ); |
361 |
|
strcat( result, ";" ); |
362 |
|
strcat( result, "TYPE=" ); |
363 |
|
strcat( result, type ); |
364 |
|
strcat( result, "." ); |
365 |
|
|
366 |
//------------------------------------------------------------------------------------------------- |
//------------------------------------------------------------------------------------------------- |
367 |
// code to prevent minimising windows (can be removed once minimise has been implemented) |
// code to prevent minimising windows (can be removed once minimise has been implemented) |
368 |
i = (int) lParam; |
//i = (int)lParam; |
369 |
//if (i==0 || i==2 || i==6 || i==7 || i==8 || i==11) |
//if (i==0 || i==2 || i==6 || i==7 || i==8 || i==11) |
370 |
if (i == 2 || i == 6) { |
//if ( i==2 || i==6 ) |
371 |
MessageBox(0, |
//{ |
372 |
"Minimising windows is not allowed in this version. Sorry!", |
// MessageBox(0,"Minimising windows is not allowed in this version. Sorry!","TS Window Clipper", MB_OK); |
373 |
"TS Window Clipper", MB_OK); |
// return 1; |
374 |
return 1; |
//} |
|
} |
|
375 |
//----------------------------------------------------------------------------------------- |
//----------------------------------------------------------------------------------------- |
376 |
|
|
377 |
//------------------------------------------------------------------------------------------------- |
//------------------------------------------------------------------------------------------------- |
378 |
// code to prevent maximising windows (can be removed once maximise has been implemented) |
// code to prevent maximising windows (can be removed once maximise has been implemented) |
379 |
i = (int) lParam; |
//i = (int)lParam; |
380 |
//if (i==3 || i==9 || i==11) |
//if (i==3 || i==9 || i==11) |
381 |
if (i == 3 || i == 11) { |
//if (i==3 || i==11) |
382 |
MessageBox(0, |
//{ |
383 |
"Maximising windows is not allowed in this version. Sorry!", |
// MessageBox(0,"Maximising windows is not allowed in this version. Sorry!","TS Window Clipper", MB_OK); |
384 |
"TS Window Clipper", MB_OK); |
// return 1; |
385 |
return 1; |
//} |
|
} |
|
386 |
//----------------------------------------------------------------------------------------- |
//----------------------------------------------------------------------------------------- |
387 |
|
|
388 |
buffer = result; |
buffer = result; |
389 |
|
|
390 |
break; |
break; |
391 |
|
|
392 |
case HCBT_MOVESIZE: |
case HCBT_MOVESIZE: |
393 |
|
|
394 |
windowHandle = (HWND) wParam; |
windowHandle = ( HWND ) wParam; |
395 |
//get win name |
//get win name |
396 |
GetWindowText(windowHandle, windowTitle, 150); |
GetWindowText( windowHandle, windowTitle, 150 ); |
397 |
|
|
398 |
//get an id for it |
//get an id for it |
399 |
itoa((int) windowHandle, strWindowId, 10); |
itoa( ( int ) windowHandle, strWindowId, 10 ); |
400 |
|
|
401 |
//get coords |
//get coords |
402 |
GetWindowRect(windowHandle, &rect); |
GetWindowRect( windowHandle, &rect ); |
403 |
b = rect.bottom; |
b = rect.bottom; |
404 |
t = rect.top; |
t = rect.top; |
405 |
l = rect.left; |
l = rect.left; |
406 |
r = rect.right; |
r = rect.right; |
407 |
ltoa(b, strB, 10); |
ltoa( b - t, strH, 10 ); |
408 |
ltoa(t, strT, 10); |
ltoa( t, strY, 10 ); |
409 |
ltoa(r, strR, 10); |
ltoa( r - l, strW, 10 ); |
410 |
ltoa(l, strL, 10); |
ltoa( l, strX, 10 ); |
411 |
|
|
412 |
//get name |
//get name |
413 |
GetWindowText(windowHandle, windowTitle, 150); |
GetWindowText( windowHandle, windowTitle, 150 ); |
414 |
|
|
415 |
////setup return string |
////setup return string |
416 |
strcat(result, "MSG=HCBT_MOVESIZE;"); |
strcat( result, "MSG=HCBT_MOVESIZE;OP=5;" ); |
417 |
strcat(result, "ID="); |
strcat( result, "ID=" ); |
418 |
strcat(result, strWindowId); |
strcat( result, strWindowId ); |
419 |
strcat(result, ";"); |
strcat( result, ";" ); |
420 |
strcat(result, "TITLE="); |
strcat( result, "TITLE=" ); |
421 |
strcat(result, windowTitle); |
strcat( result, windowTitle ); |
422 |
strcat(result, ";"); |
strcat( result, ";" ); |
423 |
strcat(result, "POS="); |
strcat( result, "X=" ); |
424 |
strcat(result, strL); |
strcat( result, strX ); |
425 |
strcat(result, "~"); |
strcat( result, ";" ); |
426 |
strcat(result, strT); |
strcat( result, "Y=" ); |
427 |
strcat(result, "~"); |
strcat( result, strY ); |
428 |
strcat(result, strR); |
strcat( result, ";" ); |
429 |
strcat(result, "~"); |
strcat( result, "H=" ); |
430 |
strcat(result, strB); |
strcat( result, strH ); |
431 |
strcat(result, ";"); |
strcat( result, ";" ); |
432 |
|
strcat( result, "W=" ); |
433 |
|
strcat( result, strW ); |
434 |
|
strcat( result, "." ); |
435 |
|
|
436 |
buffer = result; |
buffer = result; |
437 |
|
|
438 |
break; |
break; |
439 |
case HCBT_SETFOCUS: |
case HCBT_SETFOCUS: |
440 |
//buffer = "HCBT_SETFOCUS"; |
//buffer = "HCBT_SETFOCUS"; |
441 |
//not needed yet |
//not needed yet |
442 |
break; |
break; |
443 |
default: |
default: |
444 |
break; |
break; |
445 |
} |
} |
446 |
|
|
447 |
if (ChannelIsOpen()) { |
if ( ChannelIsOpen() ) { |
448 |
if (buffer != NULL) { |
if ( buffer != NULL ) { |
449 |
WriteToChannel(buffer); |
WriteToChannel( buffer ); |
450 |
} |
} |
451 |
} |
} |
452 |
|
|
453 |
return CallNextHookEx(hhook, nCode, wParam, lParam); |
return CallNextHookEx( hhook, nCode, wParam, lParam ); |
454 |
} |
} |
455 |
|
|
456 |
|
|
457 |
LRESULT CALLBACK ShellProc(int nCode, WPARAM wParam, LPARAM lParam) |
LRESULT CALLBACK ShellProc( int nCode, WPARAM wParam, LPARAM lParam ) |
458 |
{ |
{ |
459 |
if (nCode < 0) { |
if ( nCode < 0 ) { |
460 |
return CallNextHookEx(hhook, nCode, wParam, lParam); |
return CallNextHookEx( hhook, nCode, wParam, lParam ); |
461 |
} |
} |
462 |
|
|
463 |
if (ChannelIsOpen()) { |
if ( ChannelIsOpen() ) { |
464 |
PCHAR buffer = NULL; |
PCHAR buffer = NULL; |
465 |
|
|
466 |
char windowTitle[150] = { "" }; |
char windowTitle[ 150 ] = { "" |
467 |
|
}; |
468 |
HWND windowHandle = NULL; |
HWND windowHandle = NULL; |
469 |
char result[255] = { "" }; |
char result[ 255 ] = { "" |
470 |
char strWindowId[25]; |
}; |
471 |
|
char strWindowId[ 25 ]; |
472 |
LONG b, t, l, r; |
LONG b, t, l, r; |
473 |
char strB[5]; |
char strW[ 5 ]; |
474 |
char strT[5]; |
char strY[ 5 ]; |
475 |
char strL[5]; |
char strX[ 5 ]; |
476 |
char strR[5]; |
char strH[ 5 ]; |
477 |
RECT rect; |
RECT rect; |
478 |
|
|
479 |
switch (nCode) { |
switch ( nCode ) { |
480 |
case HSHELL_WINDOWCREATED: |
case HSHELL_WINDOWCREATED: |
481 |
|
|
482 |
//get window id |
//get window id |
483 |
windowHandle = (HWND) wParam; |
windowHandle = ( HWND ) wParam; |
484 |
itoa((int) windowHandle, strWindowId, 10); |
itoa( ( int ) windowHandle, strWindowId, 10 ); |
485 |
|
|
486 |
//get coords |
//get coords |
487 |
GetWindowRect(windowHandle, &rect); |
GetWindowRect( windowHandle, &rect ); |
488 |
b = rect.bottom; |
b = rect.bottom; |
489 |
t = rect.top; |
t = rect.top; |
490 |
l = rect.left; |
l = rect.left; |
491 |
r = rect.right; |
r = rect.right; |
492 |
ltoa(b, strB, 10); |
ltoa( b - t, strH, 10 ); |
493 |
ltoa(t, strT, 10); |
ltoa( t, strY, 10 ); |
494 |
ltoa(r, strR, 10); |
ltoa( r - l, strW, 10 ); |
495 |
ltoa(l, strL, 10); |
ltoa( l, strX, 10 ); |
496 |
|
|
497 |
//get name |
//get name |
498 |
GetWindowText(windowHandle, windowTitle, 150); |
GetWindowText( windowHandle, windowTitle, 150 ); |
499 |
|
|
500 |
////setup return string |
////setup return string |
501 |
strcat(result, "MSG=HSHELL_WINDOWCREATED;"); |
strcat( result, "MSG=HSHELL_WINDOWCREATED;OP=0;" ); |
502 |
strcat(result, "ID="); |
strcat( result, "ID=" ); |
503 |
strcat(result, strWindowId); |
strcat( result, strWindowId ); |
504 |
strcat(result, ";"); |
strcat( result, ";" ); |
505 |
strcat(result, "TITLE="); |
strcat( result, "TITLE=" ); |
506 |
strcat(result, windowTitle); |
strcat( result, windowTitle ); |
507 |
strcat(result, ";"); |
strcat( result, ";" ); |
508 |
strcat(result, "POS="); |
strcat( result, "X=" ); |
509 |
strcat(result, strL); |
strcat( result, strX ); |
510 |
strcat(result, "~"); |
strcat( result, ";" ); |
511 |
strcat(result, strT); |
strcat( result, "Y=" ); |
512 |
strcat(result, "~"); |
strcat( result, strY ); |
513 |
strcat(result, strR); |
strcat( result, ";" ); |
514 |
strcat(result, "~"); |
strcat( result, "H=" ); |
515 |
strcat(result, strB); |
strcat( result, strH ); |
516 |
strcat(result, ";"); |
strcat( result, ";" ); |
517 |
|
strcat( result, "W=" ); |
518 |
|
strcat( result, strW ); |
519 |
|
strcat( result, "." ); |
520 |
|
|
521 |
buffer = result; |
buffer = result; |
522 |
|
|
523 |
break; |
break; |
524 |
|
|
525 |
case HSHELL_WINDOWDESTROYED: |
case HSHELL_WINDOWDESTROYED: |
526 |
|
|
527 |
//get window id |
//get window id |
528 |
windowHandle = (HWND) wParam; |
windowHandle = ( HWND ) wParam; |
529 |
itoa((int) windowHandle, strWindowId, 10); |
itoa( ( int ) windowHandle, strWindowId, 10 ); |
530 |
|
|
531 |
|
//get coords |
532 |
|
GetWindowRect( windowHandle, &rect ); |
533 |
|
b = rect.bottom; |
534 |
|
t = rect.top; |
535 |
|
l = rect.left; |
536 |
|
r = rect.right; |
537 |
|
ltoa( b - t, strH, 10 ); |
538 |
|
ltoa( t, strY, 10 ); |
539 |
|
ltoa( r - l, strW, 10 ); |
540 |
|
ltoa( l, strX, 10 ); |
541 |
|
|
542 |
//get name |
//get name |
543 |
GetWindowText(windowHandle, windowTitle, 150); |
GetWindowText( windowHandle, windowTitle, 150 ); |
544 |
|
|
545 |
////setup return string |
////setup return string |
546 |
strcat(result, "MSG=HSHELL_WINDOWDESTROYED;"); |
strcat( result, "MSG=HSHELL_WINDOWDESTROYED;OP=1;" ); |
547 |
strcat(result, "ID="); |
strcat( result, "ID=" ); |
548 |
strcat(result, strWindowId); |
strcat( result, strWindowId ); |
549 |
strcat(result, ";"); |
strcat( result, ";" ); |
550 |
strcat(result, "TITLE="); |
strcat( result, "TITLE=" ); |
551 |
strcat(result, windowTitle); |
strcat( result, windowTitle ); |
552 |
strcat(result, ";"); |
strcat( result, ";" ); |
553 |
|
strcat( result, "X=" ); |
554 |
|
strcat( result, strX ); |
555 |
|
strcat( result, ";" ); |
556 |
|
strcat( result, "Y=" ); |
557 |
|
strcat( result, strY ); |
558 |
|
strcat( result, ";" ); |
559 |
|
strcat( result, "H=" ); |
560 |
|
strcat( result, strH ); |
561 |
|
strcat( result, ";" ); |
562 |
|
strcat( result, "W=" ); |
563 |
|
strcat( result, strW ); |
564 |
|
strcat( result, "." ); |
565 |
|
|
566 |
buffer = result; |
buffer = result; |
567 |
|
|
568 |
break; |
break; |
569 |
default: |
default: |
570 |
break; |
break; |
571 |
} |
} |
572 |
|
|
573 |
if (buffer != NULL) { |
if ( buffer != NULL ) { |
574 |
WriteToChannel(buffer); |
WriteToChannel( buffer ); |
575 |
} |
} |
576 |
} |
} |
577 |
|
|
578 |
return CallNextHookEx(hhook, nCode, wParam, lParam); |
return CallNextHookEx( hhook, nCode, wParam, lParam ); |
579 |
} |
} |
580 |
|
|
581 |
DLL_EXPORT void SetCbtHook(void) |
DLL_EXPORT void SetCbtHook( void ) |
582 |
{ |
{ |
583 |
if (!bHooked) { |
if ( !bHooked ) { |
584 |
hhook = |
hhook = SetWindowsHookEx( WH_CBT, ( HOOKPROC ) CbtProc, hInst, ( DWORD ) NULL ); |
|
SetWindowsHookEx(WH_CBT, (HOOKPROC) CbtProc, hInst, (DWORD) NULL); |
|
585 |
bHooked = true; |
bHooked = true; |
586 |
} |
} |
587 |
|
|
588 |
if (!bHooked2) { |
if ( !bHooked2 ) { |
589 |
hhook2 = |
hhook2 = SetWindowsHookEx( WH_SHELL, ( HOOKPROC ) ShellProc, hInst, ( DWORD ) NULL ); |
|
SetWindowsHookEx(WH_SHELL, (HOOKPROC) ShellProc, hInst, |
|
|
(DWORD) NULL); |
|
590 |
bHooked2 = true; |
bHooked2 = true; |
591 |
} |
} |
592 |
|
|
593 |
if (!bHooked3) { |
if ( !bHooked3 ) { |
594 |
hhook3 = |
hhook3 = SetWindowsHookEx( WH_CALLWNDPROC, ( HOOKPROC ) CallWndProc, hInst, ( DWORD ) NULL ); |
|
SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC) CallWndProc, hInst, |
|
|
(DWORD) NULL); |
|
595 |
bHooked3 = true; |
bHooked3 = true; |
596 |
} |
} |
597 |
} |
} |
598 |
|
|
599 |
DLL_EXPORT void RemoveCbtHook(void) |
DLL_EXPORT void RemoveCbtHook( void ) |
600 |
{ |
{ |
601 |
if (bHooked) { |
if ( bHooked ) { |
602 |
UnhookWindowsHookEx(hhook); |
UnhookWindowsHookEx( hhook ); |
603 |
bHooked = false; |
bHooked = false; |
604 |
} |
} |
605 |
|
|
606 |
if (bHooked2) { |
if ( bHooked2 ) { |
607 |
UnhookWindowsHookEx(hhook2); |
UnhookWindowsHookEx( hhook2 ); |
608 |
bHooked2 = false; |
bHooked2 = false; |
609 |
} |
} |
610 |
|
|
611 |
if (bHooked3) { |
if ( bHooked3 ) { |
612 |
UnhookWindowsHookEx(hhook3); |
UnhookWindowsHookEx( hhook3 ); |
613 |
bHooked3 = false; |
bHooked3 = false; |
614 |
} |
} |
615 |
} |
} |
621 |
|
|
622 |
int OpenVirtualChannel() |
int OpenVirtualChannel() |
623 |
{ |
{ |
624 |
m_vcHandle = |
m_vcHandle = WTSVirtualChannelOpen( WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, CHANNELNAME ); |
625 |
WTSVirtualChannelOpen(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, |
|
626 |
CHANNELNAME); |
if ( m_vcHandle == NULL ) { |
|
|
|
|
if (m_vcHandle == NULL) { |
|
627 |
return 0; |
return 0; |
628 |
} else { |
} else { |
629 |
return 1; |
return 1; |
632 |
|
|
633 |
int CloseVirtualChannel() |
int CloseVirtualChannel() |
634 |
{ |
{ |
635 |
BOOL result = WTSVirtualChannelClose(m_vcHandle); |
BOOL result = WTSVirtualChannelClose( m_vcHandle ); |
636 |
|
|
637 |
m_vcHandle = NULL; |
m_vcHandle = NULL; |
638 |
|
|
639 |
if (result) { |
if ( result ) { |
640 |
return 1; |
return 1; |
641 |
} else { |
} else { |
642 |
return 0; |
return 0; |
645 |
|
|
646 |
int ChannelIsOpen() |
int ChannelIsOpen() |
647 |
{ |
{ |
648 |
if (m_vcHandle == NULL) { |
if ( m_vcHandle == NULL ) { |
649 |
return 0; |
return 0; |
650 |
} else { |
} else { |
651 |
return 1; |
return 1; |
652 |
} |
} |
653 |
} |
} |
654 |
|
|
655 |
int WriteToChannel(PCHAR buffer) |
int WriteToChannel( PCHAR buffer ) |
656 |
{ |
{ |
657 |
PULONG bytesRead = 0; |
PULONG bytesRead = 0; |
658 |
PULONG pBytesWritten = 0; |
PULONG pBytesWritten = 0; |
659 |
|
|
660 |
BOOL result = |
BOOL result = WTSVirtualChannelWrite( m_vcHandle, buffer, ( ULONG ) strlen( buffer ), pBytesWritten ); |
661 |
WTSVirtualChannelWrite(m_vcHandle, buffer, (ULONG) strlen(buffer), |
|
662 |
pBytesWritten); |
if ( result ) { |
|
|
|
|
if (result) { |
|
663 |
return 1; |
return 1; |
664 |
} else { |
} else { |
665 |
return 0; |
return 0; |