/[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 997 by astrand, Mon Aug 29 09:31:51 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:      WINDOWPOS *wp = (WINDOWPOS *) details->lParam;
87      case WM_MOVING:      
88        switch ( details->message ) {
89            case WM_SIZING:
90          windowHandle = details->hwnd;          windowHandle = details->hwnd;
91          //get win name          //get win name
92          GetWindowText(windowHandle, windowTitle, 150);          GetWindowText( windowHandle, windowTitle, 150 );
93            
94          //get an id for it          //get an id for it
95          itoa((int) windowHandle, strWindowId, 10);          itoa( ( int ) windowHandle, strWindowId, 10 );
96            
97          //get coords          //get coords
98          GetWindowRect(windowHandle, &rect);          GetWindowRect( windowHandle, &rect );
99          b = rect.bottom;          b = rect.bottom;
100          t = rect.top;          t = rect.top;
101          l = rect.left;          l = rect.left;
102          r = rect.right;          r = rect.right;
103          ltoa(b, strB, 10);          ltoa( b - t, strH, 10 );
104          ltoa(t, strT, 10);          ltoa( t, strY, 10 );
105          ltoa(r, strR, 10);          ltoa( r - l, strW, 10 );
106          ltoa(l, strL, 10);          ltoa( l, strX, 10 );
107            
108          ////setup return string          ////setup return string
109          strcat(result, "MSG=CALLWNDPROC_WM_MOVING;");          strcat( result, "MSG=CALLWNDPROC_WM_SIZING;OP=6;" );
110          strcat(result, "ID=");          strcat( result, "ID=" );
111          strcat(result, strWindowId);          strcat( result, strWindowId );
112          strcat(result, ";");          strcat( result, ";" );
113          strcat(result, "TITLE=");          strcat( result, "TITLE=" );
114          strcat(result, windowTitle);          strcat( result, windowTitle );
115          strcat(result, ";");          strcat( result, ";" );
116          strcat(result, "POS=");          strcat( result, "X=" );
117          strcat(result, strL);          strcat( result, strX );
118          strcat(result, "~");          strcat( result, ";" );
119          strcat(result, strT);          strcat( result, "Y=" );
120          strcat(result, "~");          strcat( result, strY );
121          strcat(result, strR);          strcat( result, ";" );
122          strcat(result, "~");          strcat( result, "H=" );
123          strcat(result, strB);          strcat( result, strH );
124          strcat(result, ";");          strcat( result, ";" );
125            strcat( result, "W=" );
126            strcat( result, strW );
127            strcat( result, "." );
128            
129          buffer = result;          buffer = result;
130            
131          break;          break;
132            case WM_MOVING:
133      default:          
134            windowHandle = details->hwnd;
135            //get win name
136            GetWindowText( windowHandle, windowTitle, 150 );
137            
138            //get an id for it
139            itoa( ( int ) windowHandle, strWindowId, 10 );
140            
141            //get coords
142            GetWindowRect( windowHandle, &rect );
143            b = rect.bottom;
144            t = rect.top;
145            l = rect.left;
146            r = rect.right;
147            ltoa( b - t, strH, 10 );
148            ltoa( t, strY, 10 );
149            ltoa( r - l, strW, 10 );
150            ltoa( l, strX, 10 );
151            
152            ////setup return string
153            strcat( result, "MSG=CALLWNDPROC_WM_MOVING;OP=2;" );
154            strcat( result, "ID=" );
155            strcat( result, strWindowId );
156            strcat( result, ";" );
157            strcat( result, "TITLE=" );
158            strcat( result, windowTitle );
159            strcat( result, ";" );
160            strcat( result, "X=" );
161            strcat( result, strX );
162            strcat( result, ";" );
163            strcat( result, "Y=" );
164            strcat( result, strY );
165            strcat( result, ";" );
166            strcat( result, "H=" );
167            strcat( result, strH );
168            strcat( result, ";" );
169            strcat( result, "W=" );
170            strcat( result, strW );
171            strcat( result, "." );
172            
173            buffer = result;
174            
175            break;
176            
177            case WM_WINDOWPOSCHANGED:
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            // FIXME: This is a crude hack to shut up the language bar and
199            // the Office XP speech/handwriting recognition.
200            if (!strcmp(windowTitle, "TF_FloatingLangBar_WndTitle") ||
201                !strcmp(windowTitle, "CiceroUIWndFrame")) {
202                break;
203            }
204            
205            ////setup return string
206            //sprintf( result, "WM_WINDOWPOSCHANGED: title=%s, flags=0x%lx", windowTitle,  wp->flags);
207            strcat( result, "MSG=CALLWNDPROC_WM_WINDOWPOSCHANGED;OP=8;" );
208            strcat( result, "ID=" );
209            strcat( result, strWindowId );
210            strcat( result, ";" );
211            strcat( result, "TITLE=" );
212            strcat( result, windowTitle );
213            strcat( result, ";" );
214            strcat( result, "X=" );
215            strcat( result, strX );
216            strcat( result, ";" );
217            strcat( result, "Y=" );
218            strcat( result, strY );
219            strcat( result, ";" );
220            strcat( result, "H=" );
221            strcat( result, strH );
222            strcat( result, ";" );
223            strcat( result, "W=" );
224            strcat( result, strW );
225            strcat( result, "." );
226            
227            buffer = result;
228            
229            break;
230            
231            
232            case WM_CREATE:
233            if ( cs->style & WS_DLGFRAME ) {
234                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",
235                         cs->cx, cs->cy, cs->x, cs->y, cs->lpszName, cs->hMenu, details->hwnd,
236                         cs->style & WS_BORDER, cs->style & WS_DLGFRAME,
237                         cs->style & WS_POPUP );
238                buffer = result;
239            }
240            
241            break;
242            
243            
244            case WM_DESTROY:
245            if ( dwStyle & WS_DLGFRAME ) {
246                sprintf( result, "WM_DESTROY:%p", details->hwnd );
247                buffer = result;
248            }
249            
250            break;
251            
252            default:
253          break;          break;
254      }      }
255        
256      if (ChannelIsOpen()) {      if ( ChannelIsOpen() ) {
257          if (buffer != NULL) {          if ( buffer != NULL ) {
258              WriteToChannel(buffer);              WriteToChannel( buffer );
259          }          }
260      }      }
261        
262      return CallNextHookEx(hhook3, nCode, wParam, lParam);      return CallNextHookEx( hhook3, nCode, wParam, lParam );
263  }  }
264    
265  LRESULT CALLBACK CbtProc(int nCode, WPARAM wParam, LPARAM lParam)  LRESULT CALLBACK CbtProc( int nCode, WPARAM wParam, LPARAM lParam )
266  {  {
267      if (nCode < 0) {      if ( nCode < 0 ) {
268          return CallNextHookEx(hhook, nCode, wParam, lParam);          return CallNextHookEx( hhook, nCode, wParam, lParam );
269      }      }
270        
271        
272      PCHAR buffer = NULL;      PCHAR buffer = NULL;
273        
274        
275      char windowTitle[150] = { "" };      char windowTitle[ 150 ] = { ""
276                                  };
277      HWND windowHandle = NULL;      HWND windowHandle = NULL;
278      char result[255] = { "" };      char result[ 255 ] = { ""
279      char strWindowId[25];                           };
280      char type[25];      char strWindowId[ 25 ];
281        char type[ 25 ];
282        
283        
284      LONG b, t, l, r;      LONG b, t, l, r;
285      char strB[5];      char strW[ 5 ];
286      char strT[5];      char strY[ 5 ];
287      char strL[5];      char strX[ 5 ];
288      char strR[5];      char strH[ 5 ];
289      RECT rect;      RECT rect;
290        
291      int i = 0;                  //tmp      int i = 0; //tmp
292        
293      switch (nCode) {      switch ( nCode ) {
294      case HCBT_MINMAX:          case HCBT_MINMAX:
295            
296          windowHandle = (HWND) wParam;          windowHandle = ( HWND ) wParam;
297          //get win name          //get win name
298          GetWindowText(windowHandle, windowTitle, 150);          GetWindowText( windowHandle, windowTitle, 150 );
299            
300          //get an id for it          //get an id for it
301          itoa((int) windowHandle, strWindowId, 10);          itoa( ( int ) windowHandle, strWindowId, 10 );
302            
303          //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
304          //codes are:          //codes are:
305            
306          // 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
307          // 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
308          // SW_SHOWDEFAULT=10  SW_FORCEMINIMIZE=11  SW_MAX=11          // SW_SHOWDEFAULT=10  SW_FORCEMINIMIZE=11  SW_MAX=11
309            
310          itoa((int) lParam, type, 10);          itoa( ( int ) lParam, type, 10 );
311            
312          //get coords          //get coords
313          GetWindowRect(windowHandle, &rect);          GetWindowRect( windowHandle, &rect );
314          b = rect.bottom;          b = rect.bottom;
315          t = rect.top;          t = rect.top;
316          l = rect.left;          l = rect.left;
317          r = rect.right;          r = rect.right;
318          ltoa(b, strB, 10);          ltoa( b - t, strW, 10 );
319          ltoa(t, strT, 10);          ltoa( t, strY, 10 );
320          ltoa(r, strR, 10);          ltoa( r - l, strH, 10 );
321          ltoa(l, strL, 10);          ltoa( l, strX, 10 );
322            
323          //get name          //get name
324          GetWindowText(windowHandle, windowTitle, 150);          GetWindowText( windowHandle, windowTitle, 150 );
325            
326          ////setup return string          ////setup return string
327          strcat(result, "MSG=HCBT_MINMAX;");          strcat( result, "MSG=HCBT_MINMAX;OP=4;" );
328          strcat(result, "ID=");          
329          strcat(result, strWindowId);          // SW_SHOWNOACTIVATE=4  SW_SHOW=5  SW_MINIMIZE=6  SW_SHOWMINNOACTIVE=7  SW_SHOWNA=8  SW_RESTORE=9
330          strcat(result, ";");          // SW_SHOWDEFAULT=10  SW_FORCEMINIMIZE=11  SW_MAX=11
331          strcat(result, "TITLE=");          strcat( result, "ID=" );
332          strcat(result, windowTitle);          strcat( result, strWindowId );
333          strcat(result, ";");          strcat( result, ";" );
334          strcat(result, "POS=");          strcat( result, "TITLE=" );
335          strcat(result, strL);          strcat( result, windowTitle );
336          strcat(result, "~");          strcat( result, ";" );
337          strcat(result, strT);          strcat( result, "X=" );
338          strcat(result, "~");          strcat( result, strX );
339          strcat(result, strR);          strcat( result, ";" );
340          strcat(result, "~");          strcat( result, "Y=" );
341          strcat(result, strB);          strcat( result, strY );
342          strcat(result, ";");          strcat( result, ";" );
343          strcat(result, "TYPE=");          strcat( result, "H=" );
344          strcat(result, type);          strcat( result, strH );
345          strcat(result, ";");          strcat( result, ";" );
346            strcat( result, "W=" );
347            strcat( result, strW );
348            strcat( result, ";" );
349            strcat( result, "TYPE=" );
350            strcat( result, type );
351            strcat( result, "." );
352            
353          //-------------------------------------------------------------------------------------------------          //-------------------------------------------------------------------------------------------------
354          // 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)
355          i = (int) lParam;          //i = (int)lParam;
356          //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)
357          if (i == 2 || i == 6) {          //if ( i==2 || i==6 )
358              MessageBox(0,          //{
359                         "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);
360                         "TS Window Clipper", MB_OK);          // return 1;
361              return 1;          //}
         }  
362          //-----------------------------------------------------------------------------------------          //-----------------------------------------------------------------------------------------
363            
364          //-------------------------------------------------------------------------------------------------          //-------------------------------------------------------------------------------------------------
365          // 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)
366          i = (int) lParam;          //i = (int)lParam;
367          //if (i==3 || i==9 || i==11)          //if (i==3 || i==9 || i==11)
368          if (i == 3 || i == 11) {          //if (i==3 || i==11)
369              MessageBox(0,          //{
370                         "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);
371                         "TS Window Clipper", MB_OK);          // return 1;
372              return 1;          //}
         }  
373          //-----------------------------------------------------------------------------------------          //-----------------------------------------------------------------------------------------
374            
375          buffer = result;          buffer = result;
376            
377          break;          break;
378            
379      case HCBT_MOVESIZE:          case HCBT_MOVESIZE:
380            
381          windowHandle = (HWND) wParam;          windowHandle = ( HWND ) wParam;
382          //get win name          //get win name
383          GetWindowText(windowHandle, windowTitle, 150);          GetWindowText( windowHandle, windowTitle, 150 );
384            
385          //get an id for it          //get an id for it
386          itoa((int) windowHandle, strWindowId, 10);          itoa( ( int ) windowHandle, strWindowId, 10 );
387            
388          //get coords          //get coords
389          GetWindowRect(windowHandle, &rect);          GetWindowRect( windowHandle, &rect );
390          b = rect.bottom;          b = rect.bottom;
391          t = rect.top;          t = rect.top;
392          l = rect.left;          l = rect.left;
393          r = rect.right;          r = rect.right;
394          ltoa(b, strB, 10);          ltoa( b - t, strH, 10 );
395          ltoa(t, strT, 10);          ltoa( t, strY, 10 );
396          ltoa(r, strR, 10);          ltoa( r - l, strW, 10 );
397          ltoa(l, strL, 10);          ltoa( l, strX, 10 );
398            
399          //get name          //get name
400          GetWindowText(windowHandle, windowTitle, 150);          GetWindowText( windowHandle, windowTitle, 150 );
401            
402          ////setup return string          ////setup return string
403          strcat(result, "MSG=HCBT_MOVESIZE;");          strcat( result, "MSG=HCBT_MOVESIZE;OP=5;" );
404          strcat(result, "ID=");          strcat( result, "ID=" );
405          strcat(result, strWindowId);          strcat( result, strWindowId );
406          strcat(result, ";");          strcat( result, ";" );
407          strcat(result, "TITLE=");          strcat( result, "TITLE=" );
408          strcat(result, windowTitle);          strcat( result, windowTitle );
409          strcat(result, ";");          strcat( result, ";" );
410          strcat(result, "POS=");          strcat( result, "X=" );
411          strcat(result, strL);          strcat( result, strX );
412          strcat(result, "~");          strcat( result, ";" );
413          strcat(result, strT);          strcat( result, "Y=" );
414          strcat(result, "~");          strcat( result, strY );
415          strcat(result, strR);          strcat( result, ";" );
416          strcat(result, "~");          strcat( result, "H=" );
417          strcat(result, strB);          strcat( result, strH );
418          strcat(result, ";");          strcat( result, ";" );
419            strcat( result, "W=" );
420            strcat( result, strW );
421            strcat( result, "." );
422            
423          buffer = result;          buffer = result;
424            
425          break;          break;
426      case HCBT_SETFOCUS:          case HCBT_SETFOCUS:
427          //buffer = "HCBT_SETFOCUS";          //buffer = "HCBT_SETFOCUS";
428          //not needed yet          //not needed yet
429          break;          break;
430      default:          default:
431          break;          break;
432      }      }
433        
434      if (ChannelIsOpen()) {      if ( ChannelIsOpen() ) {
435          if (buffer != NULL) {          if ( buffer != NULL ) {
436              WriteToChannel(buffer);              WriteToChannel( buffer );
437          }          }
438      }      }
439        
440      return CallNextHookEx(hhook, nCode, wParam, lParam);      return CallNextHookEx( hhook, nCode, wParam, lParam );
441  }  }
442    
443    
444  LRESULT CALLBACK ShellProc(int nCode, WPARAM wParam, LPARAM lParam)  LRESULT CALLBACK ShellProc( int nCode, WPARAM wParam, LPARAM lParam )
445  {  {
446      if (nCode < 0) {      if ( nCode < 0 ) {
447          return CallNextHookEx(hhook, nCode, wParam, lParam);          return CallNextHookEx( hhook, nCode, wParam, lParam );
448      }      }
449        
450      if (ChannelIsOpen()) {      if ( ChannelIsOpen() ) {
451          PCHAR buffer = NULL;          PCHAR buffer = NULL;
452            
453          char windowTitle[150] = { "" };          char windowTitle[ 150 ] = { ""
454                                      };
455          HWND windowHandle = NULL;          HWND windowHandle = NULL;
456          char result[255] = { "" };          char result[ 255 ] = { ""
457          char strWindowId[25];                               };
458            char strWindowId[ 25 ];
459          LONG b, t, l, r;          LONG b, t, l, r;
460          char strB[5];          char strW[ 5 ];
461          char strT[5];          char strY[ 5 ];
462          char strL[5];          char strX[ 5 ];
463          char strR[5];          char strH[ 5 ];
464          RECT rect;          RECT rect;
465            
466          switch (nCode) {          switch ( nCode ) {
467          case HSHELL_WINDOWCREATED:              case HSHELL_WINDOWCREATED:
468                
469              //get window id              //get window id
470              windowHandle = (HWND) wParam;              windowHandle = ( HWND ) wParam;
471              itoa((int) windowHandle, strWindowId, 10);              itoa( ( int ) windowHandle, strWindowId, 10 );
472                
473              //get coords              //get coords
474              GetWindowRect(windowHandle, &rect);              GetWindowRect( windowHandle, &rect );
475              b = rect.bottom;              b = rect.bottom;
476              t = rect.top;              t = rect.top;
477              l = rect.left;              l = rect.left;
478              r = rect.right;              r = rect.right;
479              ltoa(b, strB, 10);              ltoa( b - t, strH, 10 );
480              ltoa(t, strT, 10);              ltoa( t, strY, 10 );
481              ltoa(r, strR, 10);              ltoa( r - l, strW, 10 );
482              ltoa(l, strL, 10);              ltoa( l, strX, 10 );
483                
484              //get name              //get name
485              GetWindowText(windowHandle, windowTitle, 150);              GetWindowText( windowHandle, windowTitle, 150 );
486                
487              ////setup return string              ////setup return string
488              strcat(result, "MSG=HSHELL_WINDOWCREATED;");              strcat( result, "MSG=HSHELL_WINDOWCREATED;OP=0;" );
489              strcat(result, "ID=");              strcat( result, "ID=" );
490              strcat(result, strWindowId);              strcat( result, strWindowId );
491              strcat(result, ";");              strcat( result, ";" );
492              strcat(result, "TITLE=");              strcat( result, "TITLE=" );
493              strcat(result, windowTitle);              strcat( result, windowTitle );
494              strcat(result, ";");              strcat( result, ";" );
495              strcat(result, "POS=");              strcat( result, "X=" );
496              strcat(result, strL);              strcat( result, strX );
497              strcat(result, "~");              strcat( result, ";" );
498              strcat(result, strT);              strcat( result, "Y=" );
499              strcat(result, "~");              strcat( result, strY );
500              strcat(result, strR);              strcat( result, ";" );
501              strcat(result, "~");              strcat( result, "H=" );
502              strcat(result, strB);              strcat( result, strH );
503              strcat(result, ";");              strcat( result, ";" );
504                strcat( result, "W=" );
505                strcat( result, strW );
506                strcat( result, "." );
507                
508              buffer = result;              buffer = result;
509                
510              break;              break;
511                
512          case HSHELL_WINDOWDESTROYED:              case HSHELL_WINDOWDESTROYED:
513                
514              //get window id              //get window id
515              windowHandle = (HWND) wParam;              windowHandle = ( HWND ) wParam;
516              itoa((int) windowHandle, strWindowId, 10);              itoa( ( int ) windowHandle, strWindowId, 10 );
517                
518                //get coords
519                GetWindowRect( windowHandle, &rect );
520                b = rect.bottom;
521                t = rect.top;
522                l = rect.left;
523                r = rect.right;
524                ltoa( b - t, strH, 10 );
525                ltoa( t, strY, 10 );
526                ltoa( r - l, strW, 10 );
527                ltoa( l, strX, 10 );
528                
529              //get name              //get name
530              GetWindowText(windowHandle, windowTitle, 150);              GetWindowText( windowHandle, windowTitle, 150 );
531                
532              ////setup return string              ////setup return string
533              strcat(result, "MSG=HSHELL_WINDOWDESTROYED;");              strcat( result, "MSG=HSHELL_WINDOWDESTROYED;OP=1;" );
534              strcat(result, "ID=");              strcat( result, "ID=" );
535              strcat(result, strWindowId);              strcat( result, strWindowId );
536              strcat(result, ";");              strcat( result, ";" );
537              strcat(result, "TITLE=");              strcat( result, "TITLE=" );
538              strcat(result, windowTitle);              strcat( result, windowTitle );
539              strcat(result, ";");              strcat( result, ";" );
540                strcat( result, "X=" );
541                strcat( result, strX );
542                strcat( result, ";" );
543                strcat( result, "Y=" );
544                strcat( result, strY );
545                strcat( result, ";" );
546                strcat( result, "H=" );
547                strcat( result, strH );
548                strcat( result, ";" );
549                strcat( result, "W=" );
550                strcat( result, strW );
551                strcat( result, "." );
552                
553              buffer = result;              buffer = result;
554                
555              break;              break;
556          default:              default:
557              break;              break;
558          }          }
559            
560          if (buffer != NULL) {          if ( buffer != NULL ) {
561              WriteToChannel(buffer);              WriteToChannel( buffer );
562          }          }
563      }      }
564        
565      return CallNextHookEx(hhook, nCode, wParam, lParam);      return CallNextHookEx( hhook, nCode, wParam, lParam );
566  }  }
567    
568  DLL_EXPORT void SetCbtHook(void)  DLL_EXPORT void SetCbtHook( void )
569  {  {
570      if (!bHooked) {      if ( !bHooked ) {
571          hhook =          hhook = SetWindowsHookEx( WH_CBT, ( HOOKPROC ) CbtProc, hInst, ( DWORD ) NULL );
             SetWindowsHookEx(WH_CBT, (HOOKPROC) CbtProc, hInst, (DWORD) NULL);  
572          bHooked = true;          bHooked = true;
573      }      }
574        
575      if (!bHooked2) {      if ( !bHooked2 ) {
576          hhook2 =          hhook2 = SetWindowsHookEx( WH_SHELL, ( HOOKPROC ) ShellProc, hInst, ( DWORD ) NULL );
             SetWindowsHookEx(WH_SHELL, (HOOKPROC) ShellProc, hInst,  
                              (DWORD) NULL);  
577          bHooked2 = true;          bHooked2 = true;
578      }      }
579        
580      if (!bHooked3) {      if ( !bHooked3 ) {
581          hhook3 =          hhook3 = SetWindowsHookEx( WH_CALLWNDPROC, ( HOOKPROC ) CallWndProc, hInst, ( DWORD ) NULL );
             SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC) CallWndProc, hInst,  
                              (DWORD) NULL);  
582          bHooked3 = true;          bHooked3 = true;
583      }      }
584  }  }
585    
586  DLL_EXPORT void RemoveCbtHook(void)  DLL_EXPORT void RemoveCbtHook( void )
587  {  {
588      if (bHooked) {      if ( bHooked ) {
589          UnhookWindowsHookEx(hhook);          UnhookWindowsHookEx( hhook );
590          bHooked = false;          bHooked = false;
591      }      }
592        
593      if (bHooked2) {      if ( bHooked2 ) {
594          UnhookWindowsHookEx(hhook2);          UnhookWindowsHookEx( hhook2 );
595          bHooked2 = false;          bHooked2 = false;
596      }      }
597        
598      if (bHooked3) {      if ( bHooked3 ) {
599          UnhookWindowsHookEx(hhook3);          UnhookWindowsHookEx( hhook3 );
600          bHooked3 = false;          bHooked3 = false;
601      }      }
602  }  }
# Line 450  DLL_EXPORT int GetInstanceCount() Line 608  DLL_EXPORT int GetInstanceCount()
608    
609  int OpenVirtualChannel()  int OpenVirtualChannel()
610  {  {
611      m_vcHandle =      m_vcHandle = WTSVirtualChannelOpen( WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, CHANNELNAME );
612          WTSVirtualChannelOpen(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION,      
613                                CHANNELNAME);      if ( m_vcHandle == NULL ) {
   
     if (m_vcHandle == NULL) {  
614          return 0;          return 0;
615      } else {      } else {
616          return 1;          return 1;
# Line 463  int OpenVirtualChannel() Line 619  int OpenVirtualChannel()
619    
620  int CloseVirtualChannel()  int CloseVirtualChannel()
621  {  {
622      BOOL result = WTSVirtualChannelClose(m_vcHandle);      BOOL result = WTSVirtualChannelClose( m_vcHandle );
623        
624      m_vcHandle = NULL;      m_vcHandle = NULL;
625        
626      if (result) {      if ( result ) {
627          return 1;          return 1;
628      } else {      } else {
629          return 0;          return 0;
# Line 476  int CloseVirtualChannel() Line 632  int CloseVirtualChannel()
632    
633  int ChannelIsOpen()  int ChannelIsOpen()
634  {  {
635      if (m_vcHandle == NULL) {      if ( m_vcHandle == NULL ) {
636          return 0;          return 0;
637      } else {      } else {
638          return 1;          return 1;
639      }      }
640  }  }
641    
642  int WriteToChannel(PCHAR buffer)  int WriteToChannel( PCHAR buffer )
643  {  {
644      PULONG bytesRead = 0;      PULONG bytesRead = 0;
645      PULONG pBytesWritten = 0;      PULONG pBytesWritten = 0;
646        
647      BOOL result =      BOOL result = WTSVirtualChannelWrite( m_vcHandle, buffer, ( ULONG ) strlen( buffer ), pBytesWritten );
648          WTSVirtualChannelWrite(m_vcHandle, buffer, (ULONG) strlen(buffer),      
649                                 pBytesWritten);      if ( result ) {
   
     if (result) {  
650          return 1;          return 1;
651      } else {      } else {
652          return 0;          return 0;

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

  ViewVC Help
Powered by ViewVC 1.1.26