/[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 996 by astrand, Mon Aug 29 09:11:50 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            case WM_WINDOWPOSCHANGED:
177            
178            windowHandle = details->hwnd;
179            //windowHandle2 = details->hwndInsertAfter;
180            //get win name
181            GetWindowText( windowHandle, windowTitle, 150 );
182            
183            //get an id for it
184            itoa( ( int ) windowHandle, strWindowId, 10 );
185            
186            //get coords
187            GetWindowRect( windowHandle, &rect );
188            b = rect.bottom;
189            t = rect.top;
190            l = rect.left;
191            r = rect.right;
192            ltoa( b - t, strH, 10 );
193            ltoa( t, strY, 10 );
194            ltoa( r - l, strW, 10 );
195            ltoa( l, strX, 10 );
196            
197            ////setup return string
198            strcat( result, "MSG=CALLWNDPROC_WM_WINDOWPOSCHANGED;OP=8;" );
199            strcat( result, "ID=" );
200            strcat( result, strWindowId );
201            strcat( result, ";" );
202            strcat( result, "TITLE=" );
203            strcat( result, windowTitle );
204            strcat( result, ";" );
205            strcat( result, "X=" );
206            strcat( result, strX );
207            strcat( result, ";" );
208            strcat( result, "Y=" );
209            strcat( result, strY );
210            strcat( result, ";" );
211            strcat( result, "H=" );
212            strcat( result, strH );
213            strcat( result, ";" );
214            strcat( result, "W=" );
215            strcat( result, strW );
216            strcat( result, "." );
217            
218            buffer = result;
219            
220            break;
221            
222            
223            case WM_CREATE:
224            if ( cs->style & WS_DLGFRAME ) {
225                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",
226                         cs->cx, cs->cy, cs->x, cs->y, cs->lpszName, cs->hMenu, details->hwnd,
227                         cs->style & WS_BORDER, cs->style & WS_DLGFRAME,
228                         cs->style & WS_POPUP );
229                buffer = result;
230            }
231            
232            break;
233            
234            
235            case WM_DESTROY:
236            if ( dwStyle & WS_DLGFRAME ) {
237                sprintf( result, "WM_DESTROY:%p", details->hwnd );
238                buffer = result;
239            }
240            
241            break;
242            
243            default:
244          break;          break;
245      }      }
246        
247      if (ChannelIsOpen()) {      if ( ChannelIsOpen() ) {
248          if (buffer != NULL) {          if ( buffer != NULL ) {
249              WriteToChannel(buffer);              WriteToChannel( buffer );
250          }          }
251      }      }
252        
253      return CallNextHookEx(hhook3, nCode, wParam, lParam);      return CallNextHookEx( hhook3, nCode, wParam, lParam );
254  }  }
255    
256  LRESULT CALLBACK CbtProc(int nCode, WPARAM wParam, LPARAM lParam)  LRESULT CALLBACK CbtProc( int nCode, WPARAM wParam, LPARAM lParam )
257  {  {
258      if (nCode < 0) {      if ( nCode < 0 ) {
259          return CallNextHookEx(hhook, nCode, wParam, lParam);          return CallNextHookEx( hhook, nCode, wParam, lParam );
260      }      }
261        
262        
263      PCHAR buffer = NULL;      PCHAR buffer = NULL;
264        
265        
266      char windowTitle[150] = { "" };      char windowTitle[ 150 ] = { ""
267                                  };
268      HWND windowHandle = NULL;      HWND windowHandle = NULL;
269      char result[255] = { "" };      char result[ 255 ] = { ""
270      char strWindowId[25];                           };
271      char type[25];      char strWindowId[ 25 ];
272        char type[ 25 ];
273        
274        
275      LONG b, t, l, r;      LONG b, t, l, r;
276      char strB[5];      char strW[ 5 ];
277      char strT[5];      char strY[ 5 ];
278      char strL[5];      char strX[ 5 ];
279      char strR[5];      char strH[ 5 ];
280      RECT rect;      RECT rect;
281        
282      int i = 0;                  //tmp      int i = 0; //tmp
283        
284      switch (nCode) {      switch ( nCode ) {
285      case HCBT_MINMAX:          case HCBT_MINMAX:
286            
287          windowHandle = (HWND) wParam;          windowHandle = ( HWND ) wParam;
288          //get win name          //get win name
289          GetWindowText(windowHandle, windowTitle, 150);          GetWindowText( windowHandle, windowTitle, 150 );
290            
291          //get an id for it          //get an id for it
292          itoa((int) windowHandle, strWindowId, 10);          itoa( ( int ) windowHandle, strWindowId, 10 );
293            
294          //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
295          //codes are:          //codes are:
296            
297          // 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
298          // 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
299          // SW_SHOWDEFAULT=10  SW_FORCEMINIMIZE=11  SW_MAX=11          // SW_SHOWDEFAULT=10  SW_FORCEMINIMIZE=11  SW_MAX=11
300            
301          itoa((int) lParam, type, 10);          itoa( ( int ) lParam, type, 10 );
302            
303          //get coords          //get coords
304          GetWindowRect(windowHandle, &rect);          GetWindowRect( windowHandle, &rect );
305          b = rect.bottom;          b = rect.bottom;
306          t = rect.top;          t = rect.top;
307          l = rect.left;          l = rect.left;
308          r = rect.right;          r = rect.right;
309          ltoa(b, strB, 10);          ltoa( b - t, strW, 10 );
310          ltoa(t, strT, 10);          ltoa( t, strY, 10 );
311          ltoa(r, strR, 10);          ltoa( r - l, strH, 10 );
312          ltoa(l, strL, 10);          ltoa( l, strX, 10 );
313            
314          //get name          //get name
315          GetWindowText(windowHandle, windowTitle, 150);          GetWindowText( windowHandle, windowTitle, 150 );
316            
317          ////setup return string          ////setup return string
318          strcat(result, "MSG=HCBT_MINMAX;");          strcat( result, "MSG=HCBT_MINMAX;OP=4;" );
319          strcat(result, "ID=");          
320          strcat(result, strWindowId);          // SW_SHOWNOACTIVATE=4  SW_SHOW=5  SW_MINIMIZE=6  SW_SHOWMINNOACTIVE=7  SW_SHOWNA=8  SW_RESTORE=9
321          strcat(result, ";");          // SW_SHOWDEFAULT=10  SW_FORCEMINIMIZE=11  SW_MAX=11
322          strcat(result, "TITLE=");          strcat( result, "ID=" );
323          strcat(result, windowTitle);          strcat( result, strWindowId );
324          strcat(result, ";");          strcat( result, ";" );
325          strcat(result, "POS=");          strcat( result, "TITLE=" );
326          strcat(result, strL);          strcat( result, windowTitle );
327          strcat(result, "~");          strcat( result, ";" );
328          strcat(result, strT);          strcat( result, "X=" );
329          strcat(result, "~");          strcat( result, strX );
330          strcat(result, strR);          strcat( result, ";" );
331          strcat(result, "~");          strcat( result, "Y=" );
332          strcat(result, strB);          strcat( result, strY );
333          strcat(result, ";");          strcat( result, ";" );
334          strcat(result, "TYPE=");          strcat( result, "H=" );
335          strcat(result, type);          strcat( result, strH );
336          strcat(result, ";");          strcat( result, ";" );
337            strcat( result, "W=" );
338            strcat( result, strW );
339            strcat( result, ";" );
340            strcat( result, "TYPE=" );
341            strcat( result, type );
342            strcat( result, "." );
343            
344          //-------------------------------------------------------------------------------------------------          //-------------------------------------------------------------------------------------------------
345          // 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)
346          i = (int) lParam;          //i = (int)lParam;
347          //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)
348          if (i == 2 || i == 6) {          //if ( i==2 || i==6 )
349              MessageBox(0,          //{
350                         "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);
351                         "TS Window Clipper", MB_OK);          // return 1;
352              return 1;          //}
         }  
353          //-----------------------------------------------------------------------------------------          //-----------------------------------------------------------------------------------------
354            
355          //-------------------------------------------------------------------------------------------------          //-------------------------------------------------------------------------------------------------
356          // 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)
357          i = (int) lParam;          //i = (int)lParam;
358          //if (i==3 || i==9 || i==11)          //if (i==3 || i==9 || i==11)
359          if (i == 3 || i == 11) {          //if (i==3 || i==11)
360              MessageBox(0,          //{
361                         "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);
362                         "TS Window Clipper", MB_OK);          // return 1;
363              return 1;          //}
         }  
364          //-----------------------------------------------------------------------------------------          //-----------------------------------------------------------------------------------------
365            
366          buffer = result;          buffer = result;
367            
368          break;          break;
369            
370      case HCBT_MOVESIZE:          case HCBT_MOVESIZE:
371            
372          windowHandle = (HWND) wParam;          windowHandle = ( HWND ) wParam;
373          //get win name          //get win name
374          GetWindowText(windowHandle, windowTitle, 150);          GetWindowText( windowHandle, windowTitle, 150 );
375            
376          //get an id for it          //get an id for it
377          itoa((int) windowHandle, strWindowId, 10);          itoa( ( int ) windowHandle, strWindowId, 10 );
378            
379          //get coords          //get coords
380          GetWindowRect(windowHandle, &rect);          GetWindowRect( windowHandle, &rect );
381          b = rect.bottom;          b = rect.bottom;
382          t = rect.top;          t = rect.top;
383          l = rect.left;          l = rect.left;
384          r = rect.right;          r = rect.right;
385          ltoa(b, strB, 10);          ltoa( b - t, strH, 10 );
386          ltoa(t, strT, 10);          ltoa( t, strY, 10 );
387          ltoa(r, strR, 10);          ltoa( r - l, strW, 10 );
388          ltoa(l, strL, 10);          ltoa( l, strX, 10 );
389            
390          //get name          //get name
391          GetWindowText(windowHandle, windowTitle, 150);          GetWindowText( windowHandle, windowTitle, 150 );
392            
393          ////setup return string          ////setup return string
394          strcat(result, "MSG=HCBT_MOVESIZE;");          strcat( result, "MSG=HCBT_MOVESIZE;OP=5;" );
395          strcat(result, "ID=");          strcat( result, "ID=" );
396          strcat(result, strWindowId);          strcat( result, strWindowId );
397          strcat(result, ";");          strcat( result, ";" );
398          strcat(result, "TITLE=");          strcat( result, "TITLE=" );
399          strcat(result, windowTitle);          strcat( result, windowTitle );
400          strcat(result, ";");          strcat( result, ";" );
401          strcat(result, "POS=");          strcat( result, "X=" );
402          strcat(result, strL);          strcat( result, strX );
403          strcat(result, "~");          strcat( result, ";" );
404          strcat(result, strT);          strcat( result, "Y=" );
405          strcat(result, "~");          strcat( result, strY );
406          strcat(result, strR);          strcat( result, ";" );
407          strcat(result, "~");          strcat( result, "H=" );
408          strcat(result, strB);          strcat( result, strH );
409          strcat(result, ";");          strcat( result, ";" );
410            strcat( result, "W=" );
411            strcat( result, strW );
412            strcat( result, "." );
413            
414          buffer = result;          buffer = result;
415            
416          break;          break;
417      case HCBT_SETFOCUS:          case HCBT_SETFOCUS:
418          //buffer = "HCBT_SETFOCUS";          //buffer = "HCBT_SETFOCUS";
419          //not needed yet          //not needed yet
420          break;          break;
421      default:          default:
422          break;          break;
423      }      }
424        
425      if (ChannelIsOpen()) {      if ( ChannelIsOpen() ) {
426          if (buffer != NULL) {          if ( buffer != NULL ) {
427              WriteToChannel(buffer);              WriteToChannel( buffer );
428          }          }
429      }      }
430        
431      return CallNextHookEx(hhook, nCode, wParam, lParam);      return CallNextHookEx( hhook, nCode, wParam, lParam );
432  }  }
433    
434    
435  LRESULT CALLBACK ShellProc(int nCode, WPARAM wParam, LPARAM lParam)  LRESULT CALLBACK ShellProc( int nCode, WPARAM wParam, LPARAM lParam )
436  {  {
437      if (nCode < 0) {      if ( nCode < 0 ) {
438          return CallNextHookEx(hhook, nCode, wParam, lParam);          return CallNextHookEx( hhook, nCode, wParam, lParam );
439      }      }
440        
441      if (ChannelIsOpen()) {      if ( ChannelIsOpen() ) {
442          PCHAR buffer = NULL;          PCHAR buffer = NULL;
443            
444          char windowTitle[150] = { "" };          char windowTitle[ 150 ] = { ""
445                                      };
446          HWND windowHandle = NULL;          HWND windowHandle = NULL;
447          char result[255] = { "" };          char result[ 255 ] = { ""
448          char strWindowId[25];                               };
449            char strWindowId[ 25 ];
450          LONG b, t, l, r;          LONG b, t, l, r;
451          char strB[5];          char strW[ 5 ];
452          char strT[5];          char strY[ 5 ];
453          char strL[5];          char strX[ 5 ];
454          char strR[5];          char strH[ 5 ];
455          RECT rect;          RECT rect;
456            
457          switch (nCode) {          switch ( nCode ) {
458          case HSHELL_WINDOWCREATED:              case HSHELL_WINDOWCREATED:
459                
460              //get window id              //get window id
461              windowHandle = (HWND) wParam;              windowHandle = ( HWND ) wParam;
462              itoa((int) windowHandle, strWindowId, 10);              itoa( ( int ) windowHandle, strWindowId, 10 );
463                
464              //get coords              //get coords
465              GetWindowRect(windowHandle, &rect);              GetWindowRect( windowHandle, &rect );
466              b = rect.bottom;              b = rect.bottom;
467              t = rect.top;              t = rect.top;
468              l = rect.left;              l = rect.left;
469              r = rect.right;              r = rect.right;
470              ltoa(b, strB, 10);              ltoa( b - t, strH, 10 );
471              ltoa(t, strT, 10);              ltoa( t, strY, 10 );
472              ltoa(r, strR, 10);              ltoa( r - l, strW, 10 );
473              ltoa(l, strL, 10);              ltoa( l, strX, 10 );
474                
475              //get name              //get name
476              GetWindowText(windowHandle, windowTitle, 150);              GetWindowText( windowHandle, windowTitle, 150 );
477                
478              ////setup return string              ////setup return string
479              strcat(result, "MSG=HSHELL_WINDOWCREATED;");              strcat( result, "MSG=HSHELL_WINDOWCREATED;OP=0;" );
480              strcat(result, "ID=");              strcat( result, "ID=" );
481              strcat(result, strWindowId);              strcat( result, strWindowId );
482              strcat(result, ";");              strcat( result, ";" );
483              strcat(result, "TITLE=");              strcat( result, "TITLE=" );
484              strcat(result, windowTitle);              strcat( result, windowTitle );
485              strcat(result, ";");              strcat( result, ";" );
486              strcat(result, "POS=");              strcat( result, "X=" );
487              strcat(result, strL);              strcat( result, strX );
488              strcat(result, "~");              strcat( result, ";" );
489              strcat(result, strT);              strcat( result, "Y=" );
490              strcat(result, "~");              strcat( result, strY );
491              strcat(result, strR);              strcat( result, ";" );
492              strcat(result, "~");              strcat( result, "H=" );
493              strcat(result, strB);              strcat( result, strH );
494              strcat(result, ";");              strcat( result, ";" );
495                strcat( result, "W=" );
496                strcat( result, strW );
497                strcat( result, "." );
498                
499              buffer = result;              buffer = result;
500                
501              break;              break;
502                
503          case HSHELL_WINDOWDESTROYED:              case HSHELL_WINDOWDESTROYED:
504                
505              //get window id              //get window id
506              windowHandle = (HWND) wParam;              windowHandle = ( HWND ) wParam;
507              itoa((int) windowHandle, strWindowId, 10);              itoa( ( int ) windowHandle, strWindowId, 10 );
508                
509                //get coords
510                GetWindowRect( windowHandle, &rect );
511                b = rect.bottom;
512                t = rect.top;
513                l = rect.left;
514                r = rect.right;
515                ltoa( b - t, strH, 10 );
516                ltoa( t, strY, 10 );
517                ltoa( r - l, strW, 10 );
518                ltoa( l, strX, 10 );
519                
520              //get name              //get name
521              GetWindowText(windowHandle, windowTitle, 150);              GetWindowText( windowHandle, windowTitle, 150 );
522                
523              ////setup return string              ////setup return string
524              strcat(result, "MSG=HSHELL_WINDOWDESTROYED;");              strcat( result, "MSG=HSHELL_WINDOWDESTROYED;OP=1;" );
525              strcat(result, "ID=");              strcat( result, "ID=" );
526              strcat(result, strWindowId);              strcat( result, strWindowId );
527              strcat(result, ";");              strcat( result, ";" );
528              strcat(result, "TITLE=");              strcat( result, "TITLE=" );
529              strcat(result, windowTitle);              strcat( result, windowTitle );
530              strcat(result, ";");              strcat( result, ";" );
531                strcat( result, "X=" );
532                strcat( result, strX );
533                strcat( result, ";" );
534                strcat( result, "Y=" );
535                strcat( result, strY );
536                strcat( result, ";" );
537                strcat( result, "H=" );
538                strcat( result, strH );
539                strcat( result, ";" );
540                strcat( result, "W=" );
541                strcat( result, strW );
542                strcat( result, "." );
543                
544              buffer = result;              buffer = result;
545                
546              break;              break;
547          default:              default:
548              break;              break;
549          }          }
550            
551          if (buffer != NULL) {          if ( buffer != NULL ) {
552              WriteToChannel(buffer);              WriteToChannel( buffer );
553          }          }
554      }      }
555        
556      return CallNextHookEx(hhook, nCode, wParam, lParam);      return CallNextHookEx( hhook, nCode, wParam, lParam );
557  }  }
558    
559  DLL_EXPORT void SetCbtHook(void)  DLL_EXPORT void SetCbtHook( void )
560  {  {
561      if (!bHooked) {      if ( !bHooked ) {
562          hhook =          hhook = SetWindowsHookEx( WH_CBT, ( HOOKPROC ) CbtProc, hInst, ( DWORD ) NULL );
             SetWindowsHookEx(WH_CBT, (HOOKPROC) CbtProc, hInst, (DWORD) NULL);  
563          bHooked = true;          bHooked = true;
564      }      }
565        
566      if (!bHooked2) {      if ( !bHooked2 ) {
567          hhook2 =          hhook2 = SetWindowsHookEx( WH_SHELL, ( HOOKPROC ) ShellProc, hInst, ( DWORD ) NULL );
             SetWindowsHookEx(WH_SHELL, (HOOKPROC) ShellProc, hInst,  
                              (DWORD) NULL);  
568          bHooked2 = true;          bHooked2 = true;
569      }      }
570        
571      if (!bHooked3) {      if ( !bHooked3 ) {
572          hhook3 =          hhook3 = SetWindowsHookEx( WH_CALLWNDPROC, ( HOOKPROC ) CallWndProc, hInst, ( DWORD ) NULL );
             SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC) CallWndProc, hInst,  
                              (DWORD) NULL);  
573          bHooked3 = true;          bHooked3 = true;
574      }      }
575  }  }
576    
577  DLL_EXPORT void RemoveCbtHook(void)  DLL_EXPORT void RemoveCbtHook( void )
578  {  {
579      if (bHooked) {      if ( bHooked ) {
580          UnhookWindowsHookEx(hhook);          UnhookWindowsHookEx( hhook );
581          bHooked = false;          bHooked = false;
582      }      }
583        
584      if (bHooked2) {      if ( bHooked2 ) {
585          UnhookWindowsHookEx(hhook2);          UnhookWindowsHookEx( hhook2 );
586          bHooked2 = false;          bHooked2 = false;
587      }      }
588        
589      if (bHooked3) {      if ( bHooked3 ) {
590          UnhookWindowsHookEx(hhook3);          UnhookWindowsHookEx( hhook3 );
591          bHooked3 = false;          bHooked3 = false;
592      }      }
593  }  }
# Line 450  DLL_EXPORT int GetInstanceCount() Line 599  DLL_EXPORT int GetInstanceCount()
599    
600  int OpenVirtualChannel()  int OpenVirtualChannel()
601  {  {
602      m_vcHandle =      m_vcHandle = WTSVirtualChannelOpen( WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, CHANNELNAME );
603          WTSVirtualChannelOpen(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION,      
604                                CHANNELNAME);      if ( m_vcHandle == NULL ) {
   
     if (m_vcHandle == NULL) {  
605          return 0;          return 0;
606      } else {      } else {
607          return 1;          return 1;
# Line 463  int OpenVirtualChannel() Line 610  int OpenVirtualChannel()
610    
611  int CloseVirtualChannel()  int CloseVirtualChannel()
612  {  {
613      BOOL result = WTSVirtualChannelClose(m_vcHandle);      BOOL result = WTSVirtualChannelClose( m_vcHandle );
614        
615      m_vcHandle = NULL;      m_vcHandle = NULL;
616        
617      if (result) {      if ( result ) {
618          return 1;          return 1;
619      } else {      } else {
620          return 0;          return 0;
# Line 476  int CloseVirtualChannel() Line 623  int CloseVirtualChannel()
623    
624  int ChannelIsOpen()  int ChannelIsOpen()
625  {  {
626      if (m_vcHandle == NULL) {      if ( m_vcHandle == NULL ) {
627          return 0;          return 0;
628      } else {      } else {
629          return 1;          return 1;
630      }      }
631  }  }
632    
633  int WriteToChannel(PCHAR buffer)  int WriteToChannel( PCHAR buffer )
634  {  {
635      PULONG bytesRead = 0;      PULONG bytesRead = 0;
636      PULONG pBytesWritten = 0;      PULONG pBytesWritten = 0;
637        
638      BOOL result =      BOOL result = WTSVirtualChannelWrite( m_vcHandle, buffer, ( ULONG ) strlen( buffer ), pBytesWritten );
639          WTSVirtualChannelWrite(m_vcHandle, buffer, (ULONG) strlen(buffer),      
640                                 pBytesWritten);      if ( result ) {
   
     if (result) {  
641          return 1;          return 1;
642      } else {      } else {
643          return 0;          return 0;

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

  ViewVC Help
Powered by ViewVC 1.1.26