/[rdesktop]/sourceforge.net/trunk/seamlessrdp/ServerExe/HookDll/hookdll.cpp
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/seamlessrdp/ServerExe/HookDll/hookdll.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.938  
changed lines
  Added in v.995

  ViewVC Help
Powered by ViewVC 1.1.26