/[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 997 by astrand, Mon Aug 29 09:31:51 2005 UTC revision 998 by astrand, Tue Aug 30 09:15:44 2005 UTC
# Line 6  Line 6 
6  #include <windows.h>  #include <windows.h>
7  #include <winuser.h>  #include <winuser.h>
8  #include <stdio.h>  #include <stdio.h>
9    #include <stdarg.h>
10    
11  #include "wtsapi32.h"  #include "wtsapi32.h"
12  #include "Cchannel.h"  #include "Cchannel.h"
# Line 23  HWND hWnd = 0; Line 24  HWND hWnd = 0;
24    
25  #pragma comment(linker, "/section:SHAREDDATA,rws")  #pragma comment(linker, "/section:SHAREDDATA,rws")
26    
27    #define snprintf _snprintf
28    
29  bool bHooked = false;  bool bHooked = false;
30  bool bHooked2 = false;  bool bHooked2 = false;
31  bool bHooked3 = false;  bool bHooked3 = false;
# Line 32  HHOOK hhook3 = 0; //wnd proc Line 35  HHOOK hhook3 = 0; //wnd proc
35  HINSTANCE hInst = 0;  HINSTANCE hInst = 0;
36  HANDLE m_vcHandle = 0;  HANDLE m_vcHandle = 0;
37    
38    
39    void SendDebug( char *format, ... )
40    {
41        va_list argp;
42        char buf [ 256 ];
43        
44        va_start( argp, format );
45        vsprintf( buf, format, argp );
46        va_end( argp );
47        
48        if ( ChannelIsOpen() ) {
49            WriteToChannel( "DEBUG1," );
50            WriteToChannel( buf );
51            WriteToChannel( "\n" );
52        }
53    }
54    
55    
56    
57  BOOL APIENTRY DllMain( HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID lpReserved )  BOOL APIENTRY DllMain( HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID lpReserved )
58  {  {
59      switch ( ul_reason_for_call ) {      switch ( ul_reason_for_call ) {
# Line 78  LRESULT CALLBACK CallWndProc( int nCode, Line 100  LRESULT CALLBACK CallWndProc( int nCode,
100      char strY[ 5 ];      char strY[ 5 ];
101      char strW[ 5 ];      char strW[ 5 ];
102      char strH[ 5 ];      char strH[ 5 ];
     RECT rect;  
103            
104      CWPSTRUCT *details = ( CWPSTRUCT * ) lParam;      CWPSTRUCT *details = ( CWPSTRUCT * ) lParam;
105      CREATESTRUCT *cs = ( CREATESTRUCT * ) details->lParam;      CREATESTRUCT *cs = ( CREATESTRUCT * ) details->lParam;
106      LONG dwStyle = GetWindowLong( details->hwnd, GWL_STYLE );      LONG dwStyle = GetWindowLong( details->hwnd, GWL_STYLE );
107      WINDOWPOS *wp = (WINDOWPOS *) details->lParam;      WINDOWPOS *wp = ( WINDOWPOS * ) details->lParam;
108        RECT *rect = ( RECT * ) details->lParam;
109            
110      switch ( details->message ) {      switch ( details->message ) {
111        
112          case WM_SIZING:          case WM_SIZING:
         windowHandle = details->hwnd;  
         //get win name  
         GetWindowText( windowHandle, windowTitle, 150 );  
           
         //get an id for it  
         itoa( ( int ) windowHandle, strWindowId, 10 );  
           
         //get coords  
         GetWindowRect( windowHandle, &rect );  
         b = rect.bottom;  
         t = rect.top;  
         l = rect.left;  
         r = rect.right;  
         ltoa( b - t, strH, 10 );  
         ltoa( t, strY, 10 );  
         ltoa( r - l, strW, 10 );  
         ltoa( l, strX, 10 );  
           
         ////setup return string  
         strcat( result, "MSG=CALLWNDPROC_WM_SIZING;OP=6;" );  
         strcat( result, "ID=" );  
         strcat( result, strWindowId );  
         strcat( result, ";" );  
         strcat( result, "TITLE=" );  
         strcat( result, windowTitle );  
         strcat( result, ";" );  
         strcat( result, "X=" );  
         strcat( result, strX );  
         strcat( result, ";" );  
         strcat( result, "Y=" );  
         strcat( result, strY );  
         strcat( result, ";" );  
         strcat( result, "H=" );  
         strcat( result, strH );  
         strcat( result, ";" );  
         strcat( result, "W=" );  
         strcat( result, strW );  
         strcat( result, "." );  
           
         buffer = result;  
           
         break;  
113          case WM_MOVING:          case WM_MOVING:
114                    snprintf( result, sizeof( result ),
115          windowHandle = details->hwnd;                    "POSITION1,0x%x,%d,%d,%d,%d,0x%x",
116          //get win name                    ( int ) details->hwnd,
117          GetWindowText( windowHandle, windowTitle, 150 );                    rect->left, rect->top,
118                              rect->right - rect->left,
119          //get an id for it                    rect->bottom - rect->top,
120          itoa( ( int ) windowHandle, strWindowId, 10 );                    0 );
121                    result[ sizeof( result ) - 1 ] = '\0';
         //get coords  
         GetWindowRect( windowHandle, &rect );  
         b = rect.bottom;  
         t = rect.top;  
         l = rect.left;  
         r = rect.right;  
         ltoa( b - t, strH, 10 );  
         ltoa( t, strY, 10 );  
         ltoa( r - l, strW, 10 );  
         ltoa( l, strX, 10 );  
           
         ////setup return string  
         strcat( result, "MSG=CALLWNDPROC_WM_MOVING;OP=2;" );  
         strcat( result, "ID=" );  
         strcat( result, strWindowId );  
         strcat( result, ";" );  
         strcat( result, "TITLE=" );  
         strcat( result, windowTitle );  
         strcat( result, ";" );  
         strcat( result, "X=" );  
         strcat( result, strX );  
         strcat( result, ";" );  
         strcat( result, "Y=" );  
         strcat( result, strY );  
         strcat( result, ";" );  
         strcat( result, "H=" );  
         strcat( result, strH );  
         strcat( result, ";" );  
         strcat( result, "W=" );  
         strcat( result, strW );  
         strcat( result, "." );  
           
122          buffer = result;          buffer = result;
123                    
124          break;          break;
125                    
126          case WM_WINDOWPOSCHANGED:          /* Note: WM_WINDOWPOSCHANGING/WM_WINDOWPOSCHANGED are
127                    strange. Sometimes, for example when bringing up the
128          windowHandle = details->hwnd;          Notepad About dialog, only an WM_WINDOWPOSCHANGING is
129          //windowHandle2 = details->hwndInsertAfter;          sent. In some other cases, for exmaple when opening
130          //get win name          Format->Text in Notepad, both events are sent. Also, for
131          GetWindowText( windowHandle, windowTitle, 150 );          some reason, when closing the Notepad About dialog, an
132                    WM_WINDOWPOSCHANGING event is sent which looks just like
133          //get an id for it          the event that was sent when the About dialog was opened...  */
134          itoa( ( int ) windowHandle, strWindowId, 10 );          case WM_WINDOWPOSCHANGING:
           
         //get coords  
         GetWindowRect( windowHandle, &rect );  
         b = rect.bottom;  
         t = rect.top;  
         l = rect.left;  
         r = rect.right;  
         ltoa( b - t, strH, 10 );  
         ltoa( t, strY, 10 );  
         ltoa( r - l, strW, 10 );  
         ltoa( l, strX, 10 );  
   
         // FIXME: This is a crude hack to shut up the language bar and  
         // the Office XP speech/handwriting recognition.  
         if (!strcmp(windowTitle, "TF_FloatingLangBar_WndTitle") ||  
             !strcmp(windowTitle, "CiceroUIWndFrame")) {  
             break;  
         }  
           
         ////setup return string  
         //sprintf( result, "WM_WINDOWPOSCHANGED: title=%s, flags=0x%lx", windowTitle,  wp->flags);  
         strcat( result, "MSG=CALLWNDPROC_WM_WINDOWPOSCHANGED;OP=8;" );  
         strcat( result, "ID=" );  
         strcat( result, strWindowId );  
         strcat( result, ";" );  
         strcat( result, "TITLE=" );  
         strcat( result, windowTitle );  
         strcat( result, ";" );  
         strcat( result, "X=" );  
         strcat( result, strX );  
         strcat( result, ";" );  
         strcat( result, "Y=" );  
         strcat( result, strY );  
         strcat( result, ";" );  
         strcat( result, "H=" );  
         strcat( result, strH );  
         strcat( result, ";" );  
         strcat( result, "W=" );  
         strcat( result, strW );  
         strcat( result, "." );  
135                    
136            if ( !( dwStyle & WS_VISIBLE ) )
137                break;
138                
139            if ( !( dwStyle & WS_DLGFRAME ) )
140                break;
141                
142            if ( !( wp->flags & SWP_NOZORDER ) ) {
143                snprintf( result, sizeof( result ),
144                          "ZCHANGE1,0x%x,0x%x,0x%x\n",
145                          details->hwnd,
146                          wp->flags & SWP_NOACTIVATE ? wp->hwndInsertAfter : 0,
147                          0 );
148                result[ sizeof( result ) - 1 ] = '\0';
149            }
150          buffer = result;          buffer = result;
151                    
152          break;          break;

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

  ViewVC Help
Powered by ViewVC 1.1.26