/[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 993 by astrand, Sun Aug 28 12:58:39 2005 UTC revision 994 by astrand, Sun Aug 28 13:06:05 2005 UTC
# Line 25  HWND hWnd = 0; Line 25  HWND hWnd = 0;
25  bool bHooked = false;  bool bHooked = false;
26  bool bHooked2 = false;  bool bHooked2 = false;
27  bool bHooked3 = false;  bool bHooked3 = false;
28  HHOOK hhook = 0;                //cbt  HHOOK hhook = 0; //cbt
29  HHOOK hhook2 = 0;               //shell  HHOOK hhook2 = 0; //shell
30  HHOOK hhook3 = 0;               //wnd proc  HHOOK hhook3 = 0; //wnd proc
31  HINSTANCE hInst = 0;  HINSTANCE hInst = 0;
32  HANDLE m_vcHandle = 0;  HANDLE m_vcHandle = 0;
33    
34  BOOL APIENTRY DllMain( HINSTANCE hinstDLL, DWORD ul_reason_for_call,  BOOL APIENTRY DllMain( HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID lpReserved )
                        LPVOID lpReserved )  
35  {  {
36      switch ( ul_reason_for_call ) {      switch ( ul_reason_for_call ) {
37          case DLL_PROCESS_ATTACH: {          case DLL_PROCESS_ATTACH: {
# Line 67  LRESULT CALLBACK CallWndProc( int nCode, Line 66  LRESULT CALLBACK CallWndProc( int nCode,
66      char windowTitle[ 150 ] = { ""      char windowTitle[ 150 ] = { ""
67                                };                                };
68      HWND windowHandle = NULL;      HWND windowHandle = NULL;
69        HWND windowHandle2 = NULL;
70      char result[ 255 ] = { ""      char result[ 255 ] = { ""
71                           };                           };
72      char strWindowId[ 25 ];      char strWindowId[ 25 ];
73      char type[ 25 ];      char type[ 25 ];
74            
75      LONG b, t, l, r;      LONG b, t, l, r;
76      char strB[ 5 ];      char strX[ 5 ];
77      char strT[ 5 ];      char strY[ 5 ];
78      char strL[ 5 ];      char strW[ 5 ];
79      char strR[ 5 ];      char strH[ 5 ];
80      RECT rect;      RECT rect;
81            
82      CWPSTRUCT *details = ( CWPSTRUCT * ) lParam;      CWPSTRUCT *details = ( CWPSTRUCT * ) lParam;
83            
84      switch ( details->message ) {      switch ( details->message ) {
85          case WM_SIZING:          case WM_SIZING:
86            windowHandle = details->hwnd;
87            //get win name
88            GetWindowText( windowHandle, windowTitle, 150 );
89            
90            //get an id for it
91            itoa( ( int ) windowHandle, strWindowId, 10 );
92            
93            //get coords
94            GetWindowRect( windowHandle, &rect );
95            b = rect.bottom;
96            t = rect.top;
97            l = rect.left;
98            r = rect.right;
99            ltoa( b - t, strH, 10 );
100            ltoa( t, strY, 10 );
101            ltoa( r - l, strW, 10 );
102            ltoa( l, strX, 10 );
103            
104            ////setup return string
105            strcat( result, "MSG=CALLWNDPROC_WM_SIZING;OP=6;" );
106            strcat( result, "ID=" );
107            strcat( result, strWindowId );
108            strcat( result, ";" );
109            strcat( result, "TITLE=" );
110            strcat( result, windowTitle );
111            strcat( result, ";" );
112            strcat( result, "X=" );
113            strcat( result, strX );
114            strcat( result, ";" );
115            strcat( result, "Y=" );
116            strcat( result, strY );
117            strcat( result, ";" );
118            strcat( result, "H=" );
119            strcat( result, strH );
120            strcat( result, ";" );
121            strcat( result, "W=" );
122            strcat( result, strW );
123            strcat( result, "." );
124            
125            buffer = result;
126            
127            break;
128          case WM_MOVING:          case WM_MOVING:
129                    
130          windowHandle = details->hwnd;          windowHandle = details->hwnd;
# Line 98  LRESULT CALLBACK CallWndProc( int nCode, Line 140  LRESULT CALLBACK CallWndProc( int nCode,
140          t = rect.top;          t = rect.top;
141          l = rect.left;          l = rect.left;
142          r = rect.right;          r = rect.right;
143          ltoa( b, strB, 10 );          ltoa( b - t, strH, 10 );
144          ltoa( t, strT, 10 );          ltoa( t, strY, 10 );
145          ltoa( r, strR, 10 );          ltoa( r - l, strW, 10 );
146          ltoa( l, strL, 10 );          ltoa( l, strX, 10 );
147                    
148          ////setup return string          ////setup return string
149          strcat( result, "MSG=CALLWNDPROC_WM_MOVING;" );          strcat( result, "MSG=CALLWNDPROC_WM_MOVING;OP=2;" );
150          strcat( result, "ID=" );          strcat( result, "ID=" );
151          strcat( result, strWindowId );          strcat( result, strWindowId );
152          strcat( result, ";" );          strcat( result, ";" );
153          strcat( result, "TITLE=" );          strcat( result, "TITLE=" );
154          strcat( result, windowTitle );          strcat( result, windowTitle );
155          strcat( result, ";" );          strcat( result, ";" );
156          strcat( result, "POS=" );          strcat( result, "X=" );
157          strcat( result, strL );          strcat( result, strX );
158          strcat( result, "~" );          strcat( result, ";" );
159          strcat( result, strT );          strcat( result, "Y=" );
160          strcat( result, "~" );          strcat( result, strY );
         strcat( result, strR );  
         strcat( result, "~" );  
         strcat( result, strB );  
161          strcat( result, ";" );          strcat( result, ";" );
162            strcat( result, "H=" );
163            strcat( result, strH );
164            strcat( result, ";" );
165            strcat( result, "W=" );
166            strcat( result, strW );
167            strcat( result, "." );
168            
169            buffer = result;
170            
171            break;
172            
173            
174            case WM_WINDOWPOSCHANGING:
175            
176            windowHandle = details->hwnd;
177            //windowHandle2 = details->hwndInsertAfter;
178            //get win name
179            GetWindowText( windowHandle, windowTitle, 150 );
180            
181            //get an id for it
182            itoa( ( int ) windowHandle, strWindowId, 10 );
183            
184            //get coords
185            GetWindowRect( windowHandle, &rect );
186            b = rect.bottom;
187            t = rect.top;
188            l = rect.left;
189            r = rect.right;
190            ltoa( b - t, strH, 10 );
191            ltoa( t, strY, 10 );
192            ltoa( r - l, strW, 10 );
193            ltoa( l, strX, 10 );
194            
195            ////setup return string
196            strcat( result, "MSG=CALLWNDPROC_WM_WINDOWPOSCHANGING;OP=7;" );
197            strcat( result, "ID=" );
198            strcat( result, strWindowId );
199            strcat( result, ";" );
200            strcat( result, "TITLE=" );
201            strcat( result, windowTitle );
202            strcat( result, ";" );
203            strcat( result, "X=" );
204            strcat( result, strX );
205            strcat( result, ";" );
206            strcat( result, "Y=" );
207            strcat( result, strY );
208            strcat( result, ";" );
209            strcat( result, "H=" );
210            strcat( result, strH );
211            strcat( result, ";" );
212            strcat( result, "W=" );
213            strcat( result, strW );
214            strcat( result, "." );
215            
216            buffer = result;
217            
218            break;
219            case WM_WINDOWPOSCHANGED:
220            
221            windowHandle = details->hwnd;
222            //windowHandle2 = details->hwndInsertAfter;
223            //get win name
224            GetWindowText( windowHandle, windowTitle, 150 );
225            
226            //get an id for it
227            itoa( ( int ) windowHandle, strWindowId, 10 );
228            
229            //get coords
230            GetWindowRect( windowHandle, &rect );
231            b = rect.bottom;
232            t = rect.top;
233            l = rect.left;
234            r = rect.right;
235            ltoa( b - t, strH, 10 );
236            ltoa( t, strY, 10 );
237            ltoa( r - l, strW, 10 );
238            ltoa( l, strX, 10 );
239            
240            ////setup return string
241            strcat( result, "MSG=CALLWNDPROC_WM_WINDOWPOSCHANGED;OP=8;" );
242            strcat( result, "ID=" );
243            strcat( result, strWindowId );
244            strcat( result, ";" );
245            strcat( result, "TITLE=" );
246            strcat( result, windowTitle );
247            strcat( result, ";" );
248            strcat( result, "X=" );
249            strcat( result, strX );
250            strcat( result, ";" );
251            strcat( result, "Y=" );
252            strcat( result, strY );
253            strcat( result, ";" );
254            strcat( result, "H=" );
255            strcat( result, strH );
256            strcat( result, ";" );
257            strcat( result, "W=" );
258            strcat( result, strW );
259            strcat( result, "." );
260                    
261          buffer = result;          buffer = result;
262                    
# Line 158  LRESULT CALLBACK CbtProc( int nCode, WPA Line 295  LRESULT CALLBACK CbtProc( int nCode, WPA
295            
296            
297      LONG b, t, l, r;      LONG b, t, l, r;
298      char strB[ 5 ];      char strW[ 5 ];
299      char strT[ 5 ];      char strY[ 5 ];
300      char strL[ 5 ];      char strX[ 5 ];
301      char strR[ 5 ];      char strH[ 5 ];
302      RECT rect;      RECT rect;
303            
304      int i = 0;                  //tmp      int i = 0; //tmp
305            
306      switch ( nCode ) {      switch ( nCode ) {
307          case HCBT_MINMAX:          case HCBT_MINMAX:
# Line 191  LRESULT CALLBACK CbtProc( int nCode, WPA Line 328  LRESULT CALLBACK CbtProc( int nCode, WPA
328          t = rect.top;          t = rect.top;
329          l = rect.left;          l = rect.left;
330          r = rect.right;          r = rect.right;
331          ltoa( b, strB, 10 );          ltoa( b - t, strW, 10 );
332          ltoa( t, strT, 10 );          ltoa( t, strY, 10 );
333          ltoa( r, strR, 10 );          ltoa( r - l, strH, 10 );
334          ltoa( l, strL, 10 );          ltoa( l, strX, 10 );
335                    
336          //get name          //get name
337          GetWindowText( windowHandle, windowTitle, 150 );          GetWindowText( windowHandle, windowTitle, 150 );
338                    
339          ////setup return string          ////setup return string
340          strcat( result, "MSG=HCBT_MINMAX;" );          strcat( result, "MSG=HCBT_MINMAX;OP=4;" );
341            
342            // SW_SHOWNOACTIVATE=4  SW_SHOW=5  SW_MINIMIZE=6  SW_SHOWMINNOACTIVE=7  SW_SHOWNA=8  SW_RESTORE=9
343            // SW_SHOWDEFAULT=10  SW_FORCEMINIMIZE=11  SW_MAX=11
344          strcat( result, "ID=" );          strcat( result, "ID=" );
345          strcat( result, strWindowId );          strcat( result, strWindowId );
346          strcat( result, ";" );          strcat( result, ";" );
347          strcat( result, "TITLE=" );          strcat( result, "TITLE=" );
348          strcat( result, windowTitle );          strcat( result, windowTitle );
349          strcat( result, ";" );          strcat( result, ";" );
350          strcat( result, "POS=" );          strcat( result, "X=" );
351          strcat( result, strL );          strcat( result, strX );
352          strcat( result, "~" );          strcat( result, ";" );
353          strcat( result, strT );          strcat( result, "Y=" );
354          strcat( result, "~" );          strcat( result, strY );
355          strcat( result, strR );          strcat( result, ";" );
356          strcat( result, "~" );          strcat( result, "H=" );
357          strcat( result, strB );          strcat( result, strH );
358            strcat( result, ";" );
359            strcat( result, "W=" );
360            strcat( result, strW );
361          strcat( result, ";" );          strcat( result, ";" );
362          strcat( result, "TYPE=" );          strcat( result, "TYPE=" );
363          strcat( result, type );          strcat( result, type );
364          strcat( result, ";" );          strcat( result, "." );
365                    
366          //-------------------------------------------------------------------------------------------------          //-------------------------------------------------------------------------------------------------
367          // code to prevent minimising windows (can be removed once minimise has been implemented)          // code to prevent minimising windows (can be removed once minimise has been implemented)
368          i = ( int ) lParam;          //i = (int)lParam;
369          //if (i==0 || i==2 || i==6 || i==7 || i==8 || i==11)          //if (i==0 || i==2 || i==6 || i==7 || i==8 || i==11)
370          if ( i == 2 || i == 6 ) {          //if ( i==2 || i==6 )
371              MessageBox( 0,          //{
372                          "Minimising windows is not allowed in this version. Sorry!",          // MessageBox(0,"Minimising windows is not allowed in this version. Sorry!","TS Window Clipper", MB_OK);
373                          "TS Window Clipper", MB_OK );          // return 1;
374              return 1;          //}
         }  
375          //-----------------------------------------------------------------------------------------          //-----------------------------------------------------------------------------------------
376                    
377          //-------------------------------------------------------------------------------------------------          //-------------------------------------------------------------------------------------------------
378          // code to prevent maximising windows (can be removed once maximise has been implemented)          // code to prevent maximising windows (can be removed once maximise has been implemented)
379          i = ( int ) lParam;          //i = (int)lParam;
380          //if (i==3 || i==9 || i==11)          //if (i==3 || i==9 || i==11)
381          if ( i == 3 || i == 11 ) {          //if (i==3 || i==11)
382              MessageBox( 0,          //{
383                          "Maximising windows is not allowed in this version. Sorry!",          // MessageBox(0,"Maximising windows is not allowed in this version. Sorry!","TS Window Clipper", MB_OK);
384                          "TS Window Clipper", MB_OK );          // return 1;
385              return 1;          //}
         }  
386          //-----------------------------------------------------------------------------------------          //-----------------------------------------------------------------------------------------
387                    
388          buffer = result;          buffer = result;
# Line 263  LRESULT CALLBACK CbtProc( int nCode, WPA Line 404  LRESULT CALLBACK CbtProc( int nCode, WPA
404          t = rect.top;          t = rect.top;
405          l = rect.left;          l = rect.left;
406          r = rect.right;          r = rect.right;
407          ltoa( b, strB, 10 );          ltoa( b - t, strH, 10 );
408          ltoa( t, strT, 10 );          ltoa( t, strY, 10 );
409          ltoa( r, strR, 10 );          ltoa( r - l, strW, 10 );
410          ltoa( l, strL, 10 );          ltoa( l, strX, 10 );
411                    
412          //get name          //get name
413          GetWindowText( windowHandle, windowTitle, 150 );          GetWindowText( windowHandle, windowTitle, 150 );
414                    
415          ////setup return string          ////setup return string
416          strcat( result, "MSG=HCBT_MOVESIZE;" );          strcat( result, "MSG=HCBT_MOVESIZE;OP=5;" );
417          strcat( result, "ID=" );          strcat( result, "ID=" );
418          strcat( result, strWindowId );          strcat( result, strWindowId );
419          strcat( result, ";" );          strcat( result, ";" );
420          strcat( result, "TITLE=" );          strcat( result, "TITLE=" );
421          strcat( result, windowTitle );          strcat( result, windowTitle );
422          strcat( result, ";" );          strcat( result, ";" );
423          strcat( result, "POS=" );          strcat( result, "X=" );
424          strcat( result, strL );          strcat( result, strX );
425          strcat( result, "~" );          strcat( result, ";" );
426          strcat( result, strT );          strcat( result, "Y=" );
427          strcat( result, "~" );          strcat( result, strY );
428          strcat( result, strR );          strcat( result, ";" );
429          strcat( result, "~" );          strcat( result, "H=" );
430          strcat( result, strB );          strcat( result, strH );
431          strcat( result, ";" );          strcat( result, ";" );
432            strcat( result, "W=" );
433            strcat( result, strW );
434            strcat( result, "." );
435                    
436          buffer = result;          buffer = result;
437                    
# Line 326  LRESULT CALLBACK ShellProc( int nCode, W Line 470  LRESULT CALLBACK ShellProc( int nCode, W
470                               };                               };
471          char strWindowId[ 25 ];          char strWindowId[ 25 ];
472          LONG b, t, l, r;          LONG b, t, l, r;
473          char strB[ 5 ];          char strW[ 5 ];
474          char strT[ 5 ];          char strY[ 5 ];
475          char strL[ 5 ];          char strX[ 5 ];
476          char strR[ 5 ];          char strH[ 5 ];
477          RECT rect;          RECT rect;
478                    
479          switch ( nCode ) {          switch ( nCode ) {
# Line 345  LRESULT CALLBACK ShellProc( int nCode, W Line 489  LRESULT CALLBACK ShellProc( int nCode, W
489              t = rect.top;              t = rect.top;
490              l = rect.left;              l = rect.left;
491              r = rect.right;              r = rect.right;
492              ltoa( b, strB, 10 );              ltoa( b - t, strH, 10 );
493              ltoa( t, strT, 10 );              ltoa( t, strY, 10 );
494              ltoa( r, strR, 10 );              ltoa( r - l, strW, 10 );
495              ltoa( l, strL, 10 );              ltoa( l, strX, 10 );
496                            
497              //get name              //get name
498              GetWindowText( windowHandle, windowTitle, 150 );              GetWindowText( windowHandle, windowTitle, 150 );
499                            
500              ////setup return string              ////setup return string
501              strcat( result, "MSG=HSHELL_WINDOWCREATED;" );              strcat( result, "MSG=HSHELL_WINDOWCREATED;OP=0;" );
502              strcat( result, "ID=" );              strcat( result, "ID=" );
503              strcat( result, strWindowId );              strcat( result, strWindowId );
504              strcat( result, ";" );              strcat( result, ";" );
505              strcat( result, "TITLE=" );              strcat( result, "TITLE=" );
506              strcat( result, windowTitle );              strcat( result, windowTitle );
507              strcat( result, ";" );              strcat( result, ";" );
508              strcat( result, "POS=" );              strcat( result, "X=" );
509              strcat( result, strL );              strcat( result, strX );
             strcat( result, "~" );  
             strcat( result, strT );  
             strcat( result, "~" );  
             strcat( result, strR );  
             strcat( result, "~" );  
             strcat( result, strB );  
510              strcat( result, ";" );              strcat( result, ";" );
511                strcat( result, "Y=" );
512                strcat( result, strY );
513                strcat( result, ";" );
514                strcat( result, "H=" );
515                strcat( result, strH );
516                strcat( result, ";" );
517                strcat( result, "W=" );
518                strcat( result, strW );
519                strcat( result, "." );
520                            
521              buffer = result;              buffer = result;
522                            
# Line 381  LRESULT CALLBACK ShellProc( int nCode, W Line 528  LRESULT CALLBACK ShellProc( int nCode, W
528              windowHandle = ( HWND ) wParam;              windowHandle = ( HWND ) wParam;
529              itoa( ( int ) windowHandle, strWindowId, 10 );              itoa( ( int ) windowHandle, strWindowId, 10 );
530                            
531                //get coords
532                GetWindowRect( windowHandle, &rect );
533                b = rect.bottom;
534                t = rect.top;
535                l = rect.left;
536                r = rect.right;
537                ltoa( b - t, strH, 10 );
538                ltoa( t, strY, 10 );
539                ltoa( r - l, strW, 10 );
540                ltoa( l, strX, 10 );
541                
542              //get name              //get name
543              GetWindowText( windowHandle, windowTitle, 150 );              GetWindowText( windowHandle, windowTitle, 150 );
544                            
545              ////setup return string              ////setup return string
546              strcat( result, "MSG=HSHELL_WINDOWDESTROYED;" );              strcat( result, "MSG=HSHELL_WINDOWDESTROYED;OP=1;" );
547              strcat( result, "ID=" );              strcat( result, "ID=" );
548              strcat( result, strWindowId );              strcat( result, strWindowId );
549              strcat( result, ";" );              strcat( result, ";" );
550              strcat( result, "TITLE=" );              strcat( result, "TITLE=" );
551              strcat( result, windowTitle );              strcat( result, windowTitle );
552              strcat( result, ";" );              strcat( result, ";" );
553                strcat( result, "X=" );
554                strcat( result, strX );
555                strcat( result, ";" );
556                strcat( result, "Y=" );
557                strcat( result, strY );
558                strcat( result, ";" );
559                strcat( result, "H=" );
560                strcat( result, strH );
561                strcat( result, ";" );
562                strcat( result, "W=" );
563                strcat( result, strW );
564                strcat( result, "." );
565                            
566              buffer = result;              buffer = result;
567                            
# Line 411  LRESULT CALLBACK ShellProc( int nCode, W Line 581  LRESULT CALLBACK ShellProc( int nCode, W
581  DLL_EXPORT void SetCbtHook( void )  DLL_EXPORT void SetCbtHook( void )
582  {  {
583      if ( !bHooked ) {      if ( !bHooked ) {
584          hhook =          hhook = SetWindowsHookEx( WH_CBT, ( HOOKPROC ) CbtProc, hInst, ( DWORD ) NULL );
             SetWindowsHookEx( WH_CBT, ( HOOKPROC ) CbtProc, hInst, ( DWORD ) NULL );  
585          bHooked = true;          bHooked = true;
586      }      }
587            
588      if ( !bHooked2 ) {      if ( !bHooked2 ) {
589          hhook2 =          hhook2 = SetWindowsHookEx( WH_SHELL, ( HOOKPROC ) ShellProc, hInst, ( DWORD ) NULL );
             SetWindowsHookEx( WH_SHELL, ( HOOKPROC ) ShellProc, hInst,  
                               ( DWORD ) NULL );  
590          bHooked2 = true;          bHooked2 = true;
591      }      }
592            
593      if ( !bHooked3 ) {      if ( !bHooked3 ) {
594          hhook3 =          hhook3 = SetWindowsHookEx( WH_CALLWNDPROC, ( HOOKPROC ) CallWndProc, hInst, ( DWORD ) NULL );
             SetWindowsHookEx( WH_CALLWNDPROC, ( HOOKPROC ) CallWndProc, hInst,  
                               ( DWORD ) NULL );  
595          bHooked3 = true;          bHooked3 = true;
596      }      }
597  }  }
# Line 456  DLL_EXPORT int GetInstanceCount() Line 621  DLL_EXPORT int GetInstanceCount()
621    
622  int OpenVirtualChannel()  int OpenVirtualChannel()
623  {  {
624      m_vcHandle =      m_vcHandle = WTSVirtualChannelOpen( WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, CHANNELNAME );
625          WTSVirtualChannelOpen( WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION,      
                                CHANNELNAME );  
                                 
626      if ( m_vcHandle == NULL ) {      if ( m_vcHandle == NULL ) {
627          return 0;          return 0;
628      } else {      } else {
# Line 494  int WriteToChannel( PCHAR buffer ) Line 657  int WriteToChannel( PCHAR buffer )
657      PULONG bytesRead = 0;      PULONG bytesRead = 0;
658      PULONG pBytesWritten = 0;      PULONG pBytesWritten = 0;
659            
660      BOOL result =      BOOL result = WTSVirtualChannelWrite( m_vcHandle, buffer, ( ULONG ) strlen( buffer ), pBytesWritten );
661          WTSVirtualChannelWrite( m_vcHandle, buffer, ( ULONG ) strlen( buffer ),      
                                 pBytesWritten );  
                                   
662      if ( result ) {      if ( result ) {
663          return 1;          return 1;
664      } else {      } else {

Legend:
Removed from v.993  
changed lines
  Added in v.994

  ViewVC Help
Powered by ViewVC 1.1.26