/[rdesktop]/sourceforge.net/trunk/seamlessrdp/ServerExe/HookDll/hookdll.c
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.c

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

revision 1073 by ossman_, Thu Mar 9 12:26:31 2006 UTC revision 1131 by ossman_, Wed Mar 15 12:15:23 2006 UTC
# Line 49  static HINSTANCE g_instance = NULL; Line 49  static HINSTANCE g_instance = NULL;
49    
50  static HANDLE g_mutex = NULL;  static HANDLE g_mutex = NULL;
51    
52    static void
53    update_position(HWND hwnd)
54    {
55            RECT rect;
56    
57            if (!GetWindowRect(hwnd, &rect))
58            {
59                    debug("GetWindowRect failed!\n");
60                    return;
61            }
62    
63            vchannel_write("POSITION,0x%p,%d,%d,%d,%d,0x%x",
64                           hwnd,
65                           rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 0);
66    }
67    
68  static LRESULT CALLBACK  static LRESULT CALLBACK
69  wndproc_hook_proc(int code, WPARAM cur_thread, LPARAM details)  wndproc_hook_proc(int code, WPARAM cur_thread, LPARAM details)
70  {  {
71          HWND hwnd = ((CWPSTRUCT *) details)->hwnd;          HWND hwnd, parent;
72          UINT msg = ((CWPSTRUCT *) details)->message;          UINT msg;
73          WPARAM wparam = ((CWPSTRUCT *) details)->wParam;          WPARAM wparam;
74          LPARAM lparam = ((CWPSTRUCT *) details)->lParam;          LPARAM lparam;
75    
76          LONG style = GetWindowLong(hwnd, GWL_STYLE);          LONG style;
         WINDOWPOS *wp = (WINDOWPOS *) lparam;  
         RECT rect;  
77    
78          if (code < 0)          if (code < 0)
79                  goto end;                  goto end;
80    
81            hwnd = ((CWPSTRUCT *) details)->hwnd;
82            msg = ((CWPSTRUCT *) details)->message;
83            wparam = ((CWPSTRUCT *) details)->wParam;
84            lparam = ((CWPSTRUCT *) details)->lParam;
85    
86            style = GetWindowLong(hwnd, GWL_STYLE);
87    
88            /* Docs say that WS_CHILD and WS_POPUP is an illegal combination,
89               but they exist nonetheless. */
90            if ((style & WS_CHILD) && !(style & WS_POPUP))
91                    goto end;
92    
93            if (style & WS_POPUP)
94            {
95                    parent = (HWND) GetWindowLong(hwnd, GWL_HWNDPARENT);
96                    if (!parent)
97                            parent = (HWND) - 1;
98            }
99            else
100                    parent = NULL;
101    
102          switch (msg)          switch (msg)
103          {          {
104    
105                  case WM_WINDOWPOSCHANGED:                  case WM_WINDOWPOSCHANGED:
                         if (style & WS_CHILD)  
                                 break;  
   
   
                         if (wp->flags & SWP_SHOWWINDOW)  
106                          {                          {
107                                  // FIXME: Now, just like create!                                  WINDOWPOS *wp = (WINDOWPOS *) lparam;
                                 debug("SWP_SHOWWINDOW for %p!", hwnd);  
                                 vchannel_write("CREATE1,0x%p,0x%x", hwnd, 0);  
   
                                 // FIXME: SETSTATE  
108    
109                                  if (!GetWindowRect(hwnd, &rect))                                  if (wp->flags & SWP_SHOWWINDOW)
110                                  {                                  {
111                                          debug("GetWindowRect failed!\n");                                          char title[150];
112                                          break;                                          int state;
                                 }  
                                 vchannel_write("POSITION1,0x%p,%d,%d,%d,%d,0x%x",  
                                                hwnd,  
                                                rect.left, rect.top,  
                                                rect.right - rect.left, rect.bottom - rect.top, 0);  
                         }  
113    
114                                            vchannel_write("CREATE,0x%p,0x%p,0x%x", hwnd, parent, 0);
115    
116                          if (wp->flags & SWP_HIDEWINDOW)                                          GetWindowText(hwnd, title, sizeof(title));
                                 vchannel_write("DESTROY1,0x%p,0x%x", hwnd, 0);  
117    
118                                            vchannel_write("TITLE,0x%x,%s,0x%x", hwnd,
119                                                           vchannel_strfilter(title), 0);
120    
121                          if (!(style & WS_VISIBLE))                                          if (style & WS_MAXIMIZE)
122                                  break;                                                  state = 2;
123                                            else if (style & WS_MINIMIZE)
124                                                    state = 1;
125                                            else
126                                                    state = 0;
127    
128                          if (wp->flags & SWP_NOMOVE && wp->flags & SWP_NOSIZE)                                          update_position(hwnd);
                                 break;  
129    
130                          if (!GetWindowRect(hwnd, &rect))                                          vchannel_write("STATE,0x%p,0x%x,0x%x", hwnd, state, 0);
131                          {                                  }
                                 debug("GetWindowRect failed!\n");  
                                 break;  
                         }  
132    
133                          vchannel_write("POSITION1,0x%p,%d,%d,%d,%d,0x%x",                                  if (wp->flags & SWP_HIDEWINDOW)
134                                         hwnd,                                          vchannel_write("DESTROY,0x%p,0x%x", hwnd, 0);
                                        rect.left, rect.top,  
                                        rect.right - rect.left, rect.bottom - rect.top, 0);  
135    
136                          break;                                  if (!(style & WS_VISIBLE) || (style & WS_MINIMIZE))
137                                            break;
138    
139                                    if (!(wp->flags & SWP_NOMOVE && wp->flags & SWP_NOSIZE))
140                                            update_position(hwnd);
141    
142                          /* Note: WM_WINDOWPOSCHANGING/WM_WINDOWPOSCHANGED are                                  if (!(wp->flags & SWP_NOZORDER))
143                             strange. Sometimes, for example when bringing up the                                  {
144                             Notepad About dialog, only an WM_WINDOWPOSCHANGING is                                          vchannel_write("ZCHANGE,0x%p,0x%p,0x%x",
145                             sent. In some other cases, for exmaple when opening                                                         hwnd,
146                             Format->Text in Notepad, both events are sent. Also, for                                                         wp->flags & SWP_NOACTIVATE ? wp->
147                             some reason, when closing the Notepad About dialog, an                                                         hwndInsertAfter : 0, 0);
148                             WM_WINDOWPOSCHANGING event is sent which looks just like                                  }
                            the event that was sent when the About dialog was opened...  */  
                 case WM_WINDOWPOSCHANGING:  
                         if (style & WS_CHILD)  
                                 break;  
149    
                         if (!(style & WS_VISIBLE))  
150                                  break;                                  break;
151                            }
152    
153                          if (!(wp->flags & SWP_NOZORDER))                  case WM_SIZE:
154                                  vchannel_write("ZCHANGE1,0x%p,0x%p,0x%x",                          if (!(style & WS_VISIBLE) || (style & WS_MINIMIZE))
155                                                 hwnd,                                  break;
156                                                 wp->flags & SWP_NOACTIVATE ? wp->hwndInsertAfter : 0,                          update_position(hwnd);
                                                0);  
   
157                          break;                          break;
158    
159                    case WM_MOVE:
160                            if (!(style & WS_VISIBLE) || (style & WS_MINIMIZE))
161                                    break;
162                            update_position(hwnd);
163                            break;
164    
165                    case WM_SETTEXT:
166                            {
167                                    char *title;
168                                    if (!(style & WS_VISIBLE))
169                                            break;
170                                    title = _strdup((char *) lparam);
171                                    vchannel_write("TITLE,0x%p,%s,0x%x", hwnd,
172                                                   vchannel_strfilter(title), 0);
173                                    free(title);
174                                    break;
175                            }
176    
177                  case WM_DESTROY:                  case WM_DESTROY:
178                          if (style & WS_CHILD)                          if (!(style & WS_VISIBLE))
179                                  break;                                  break;
180                            vchannel_write("DESTROY,0x%p,0x%x", hwnd, 0);
                         vchannel_write("DESTROY1,0x%p,0x%x", hwnd, 0);  
   
181                          break;                          break;
182    
   
183                  default:                  default:
184                          break;                          break;
185          }          }
# Line 162  wndproc_hook_proc(int code, WPARAM cur_t Line 191  wndproc_hook_proc(int code, WPARAM cur_t
191  static LRESULT CALLBACK  static LRESULT CALLBACK
192  cbt_hook_proc(int code, WPARAM wparam, LPARAM lparam)  cbt_hook_proc(int code, WPARAM wparam, LPARAM lparam)
193  {  {
         char title[150];  
   
194          if (code < 0)          if (code < 0)
195                  goto end;                  goto end;
196    
# Line 171  cbt_hook_proc(int code, WPARAM wparam, L Line 198  cbt_hook_proc(int code, WPARAM wparam, L
198          {          {
199                  case HCBT_MINMAX:                  case HCBT_MINMAX:
200                          {                          {
201                                  int show;                                  int show, state;
202    
203                                  show = LOWORD(lparam);                                  show = LOWORD(lparam);
204    
205                                  if ((show == SW_SHOWMINIMIZED) || (show == SW_MINIMIZE))                                  if ((show == SW_NORMAL) || (show == SW_SHOWNORMAL)
206                                        || (show == SW_RESTORE))
207                                            state = 0;
208                                    else if ((show == SW_MINIMIZE) || (show == SW_SHOWMINIMIZED))
209                                            state = 1;
210                                    else if ((show == SW_MAXIMIZE) || (show == SW_SHOWMAXIMIZED))
211                                            state = 2;
212                                    else
213                                  {                                  {
214                                          MessageBox(0,                                          debug("Unexpected show: %d", show);
215                                                     "Minimizing windows is not allowed in this version. Sorry!",                                          break;
                                                    "SeamlessRDP", MB_OK);  
                                         return 1;  
216                                  }                                  }
217                                    vchannel_write("STATE,0x%p,0x%x,0x%x", (HWND) wparam, state, 0);
                                 GetWindowText((HWND) wparam, title, sizeof(title));  
   
                                 /* FIXME: Strip title of dangerous characters */  
   
                                 vchannel_write("SETSTATE1,0x%p,%s,0x%x,0x%x",  
                                                (HWND) wparam, title, show, 0);  
218                                  break;                                  break;
219                          }                          }
220    

Legend:
Removed from v.1073  
changed lines
  Added in v.1131

  ViewVC Help
Powered by ViewVC 1.1.26