/[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 1165 by ossman_, Mon Mar 20 12:28:03 2006 UTC revision 1230 by ossman_, Thu Apr 20 12:56:18 2006 UTC
# Line 81  update_position(HWND hwnd) Line 81  update_position(HWND hwnd)
81          HWND blocked_hwnd;          HWND blocked_hwnd;
82          unsigned int serial;          unsigned int serial;
83    
         if (!GetWindowRect(hwnd, &rect))  
         {  
                 debug("GetWindowRect failed!\n");  
                 return;  
         }  
   
84          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
85          blocked_hwnd = g_block_move_hwnd;          blocked_hwnd = g_block_move_hwnd;
86          serial = g_block_move_serial;          serial = g_block_move_serial;
87          memcpy(&blocked, &g_block_move, sizeof(RECT));          memcpy(&blocked, &g_block_move, sizeof(RECT));
88          ReleaseMutex(g_mutex);          ReleaseMutex(g_mutex);
89    
90            vchannel_block();
91    
92            if (!GetWindowRect(hwnd, &rect))
93            {
94                    debug("GetWindowRect failed!\n");
95                    goto end;
96            }
97    
98          if ((hwnd == blocked_hwnd) && (rect.left == blocked.left) && (rect.top == blocked.top)          if ((hwnd == blocked_hwnd) && (rect.left == blocked.left) && (rect.top == blocked.top)
99              && (rect.right == blocked.right) && (rect.bottom == blocked.bottom))              && (rect.right == blocked.right) && (rect.bottom == blocked.bottom))
100                  vchannel_write("ACK", "%u", serial);                  goto end;
101          else  
102                  vchannel_write("POSITION", "0x%p,%d,%d,%d,%d,0x%x",          vchannel_write("POSITION", "0x%08lx,%d,%d,%d,%d,0x%08x",
103                                 hwnd,                         hwnd,
104                                 rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,                         rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 0);
105                                 0);  
106          end:
107            vchannel_unblock();
108  }  }
109    
110  static void  static void
# Line 116  update_zorder(HWND hwnd) Line 120  update_zorder(HWND hwnd)
120          block_behind = g_blocked_zchange[1];          block_behind = g_blocked_zchange[1];
121          ReleaseMutex(g_mutex);          ReleaseMutex(g_mutex);
122    
123            vchannel_block();
124    
125          behind = GetNextWindow(hwnd, GW_HWNDPREV);          behind = GetNextWindow(hwnd, GW_HWNDPREV);
126          while (behind)          while (behind)
127          {          {
# Line 132  update_zorder(HWND hwnd) Line 138  update_zorder(HWND hwnd)
138          if ((hwnd == block_hwnd) && (behind == block_behind))          if ((hwnd == block_hwnd) && (behind == block_behind))
139                  vchannel_write("ACK", "%u", serial);                  vchannel_write("ACK", "%u", serial);
140          else          else
141                  vchannel_write("ZCHANGE", "0x%p,0x%p,0x%x", hwnd, behind, 0);                  vchannel_write("ZCHANGE", "0x%08lx,0x%08lx,0x%08x", hwnd, behind, 0);
142    
143            vchannel_unblock();
144    }
145    
146    static HWND
147    get_parent(HWND hwnd)
148    {
149            LONG style;
150            HWND parent;
151    
152            style = GetWindowLong(hwnd, GWL_STYLE);
153    
154            if (style & (WS_POPUP | DS_MODALFRAME))
155            {
156                    parent = (HWND) GetWindowLong(hwnd, GWL_HWNDPARENT);
157    
158                    if (parent)
159                    {
160                            style = GetWindowLong(parent, GWL_STYLE);
161                            if (((style & WS_CHILD) && !(style & WS_POPUP)) || !(style & WS_VISIBLE))
162                                    parent = NULL;
163                    }
164    
165                    if (!parent)
166                            parent = GetWindow(hwnd, GW_OWNER);
167    
168                    if (parent)
169                    {
170                            style = GetWindowLong(parent, GWL_STYLE);
171                            if (((style & WS_CHILD) && !(style & WS_POPUP)) || !(style & WS_VISIBLE))
172                                    parent = NULL;
173                    }
174    
175                    if (!parent)
176                            parent = (HWND) - 1;
177            }
178            else
179                    parent = NULL;
180    
181            return parent;
182  }  }
183    
184  static LRESULT CALLBACK  static LRESULT CALLBACK
# Line 160  wndproc_hook_proc(int code, WPARAM cur_t Line 206  wndproc_hook_proc(int code, WPARAM cur_t
206          if ((style & WS_CHILD) && !(style & WS_POPUP))          if ((style & WS_CHILD) && !(style & WS_POPUP))
207                  goto end;                  goto end;
208    
209          if (style & WS_POPUP)          parent = get_parent(hwnd);
         {  
                 parent = (HWND) GetWindowLong(hwnd, GWL_HWNDPARENT);  
                 if (!parent)  
                         parent = (HWND) - 1;  
         }  
         else  
                 parent = NULL;  
210    
211          switch (msg)          switch (msg)
212          {          {
# Line 179  wndproc_hook_proc(int code, WPARAM cur_t Line 218  wndproc_hook_proc(int code, WPARAM cur_t
218                                  {                                  {
219                                          unsigned short title[150];                                          unsigned short title[150];
220                                          int state;                                          int state;
221                                            DWORD pid;
222                                            int flags;
223    
224                                            GetWindowThreadProcessId(hwnd, &pid);
225    
226                                          vchannel_write("CREATE", "0x%p,0x%p,0x%x", hwnd, parent, 0);                                          flags = 0;
227                                            if (style & DS_MODALFRAME)
228                                                    flags |= SEAMLESS_CREATE_MODAL;
229    
230                                            vchannel_write("CREATE", "0x%08lx,0x%08lx,0x%08lx,0x%08x",
231                                                           (long) hwnd, (long) pid, (long) parent,
232                                                           flags);
233    
234                                          GetWindowTextW(hwnd, title, sizeof(title) / sizeof(*title));                                          GetWindowTextW(hwnd, title, sizeof(title) / sizeof(*title));
235    
236                                          vchannel_write("TITLE", "0x%x,%s,0x%x", hwnd,                                          vchannel_write("TITLE", "0x%08lx,%s,0x%08x", hwnd,
237                                                         vchannel_strfilter_unicode(title), 0);                                                         vchannel_strfilter_unicode(title), 0);
238    
239                                          if (style & WS_MAXIMIZE)                                          if (style & WS_MAXIMIZE)
# Line 196  wndproc_hook_proc(int code, WPARAM cur_t Line 245  wndproc_hook_proc(int code, WPARAM cur_t
245    
246                                          update_position(hwnd);                                          update_position(hwnd);
247    
248                                          vchannel_write("STATE", "0x%p,0x%x,0x%x", hwnd, state, 0);                                          vchannel_write("STATE", "0x%08lx,0x%08x,0x%08x", hwnd,
249                                                           state, 0);
250                                  }                                  }
251    
252                                  if (wp->flags & SWP_HIDEWINDOW)                                  if (wp->flags & SWP_HIDEWINDOW)
253                                          vchannel_write("DESTROY", "0x%p,0x%x", hwnd, 0);                                          vchannel_write("DESTROY", "0x%08lx,0x%08x", hwnd, 0);
254    
255                                  if (!(style & WS_VISIBLE) || (style & WS_MINIMIZE))                                  if (!(style & WS_VISIBLE) || (style & WS_MINIMIZE))
256                                          break;                                          break;
# Line 226  wndproc_hook_proc(int code, WPARAM cur_t Line 276  wndproc_hook_proc(int code, WPARAM cur_t
276                  case WM_DESTROY:                  case WM_DESTROY:
277                          if (!(style & WS_VISIBLE))                          if (!(style & WS_VISIBLE))
278                                  break;                                  break;
279                          vchannel_write("DESTROY", "0x%p,0x%x", hwnd, 0);                          vchannel_write("DESTROY", "0x%08lx,0x%08x", hwnd, 0);
280                          break;                          break;
281    
282                  default:                  default:
# Line 262  wndprocret_hook_proc(int code, WPARAM cu Line 312  wndprocret_hook_proc(int code, WPARAM cu
312          if ((style & WS_CHILD) && !(style & WS_POPUP))          if ((style & WS_CHILD) && !(style & WS_POPUP))
313                  goto end;                  goto end;
314    
315          if (style & WS_POPUP)          parent = get_parent(hwnd);
         {  
                 parent = (HWND) GetWindowLong(hwnd, GWL_HWNDPARENT);  
                 if (!parent)  
                         parent = (HWND) - 1;  
         }  
         else  
                 parent = NULL;  
316    
317          switch (msg)          switch (msg)
318          {          {
# Line 295  wndprocret_hook_proc(int code, WPARAM cu Line 338  wndprocret_hook_proc(int code, WPARAM cu
338                                  /* We cannot use the string in lparam because                                  /* We cannot use the string in lparam because
339                                     we need unicode. */                                     we need unicode. */
340                                  GetWindowTextW(hwnd, title, sizeof(title) / sizeof(*title));                                  GetWindowTextW(hwnd, title, sizeof(title) / sizeof(*title));
341                                  vchannel_write("TITLE", "0x%p,%s,0x%x", hwnd,                                  vchannel_write("TITLE", "0x%08lx,%s,0x%08x", hwnd,
342                                                 vchannel_strfilter_unicode(title), 0);                                                 vchannel_strfilter_unicode(title), 0);
343                                  break;                                  break;
344                          }                          }
# Line 306  wndprocret_hook_proc(int code, WPARAM cu Line 349  wndprocret_hook_proc(int code, WPARAM cu
349    
350          if (msg == g_wm_seamless_focus)          if (msg == g_wm_seamless_focus)
351          {          {
352                  /* FIXME: SetActiveWindow() kills menus. Need to find a clean                  /* FIXME: SetForegroundWindow() kills menus. Need to find a
353                     way to solve this. */                     clean way to solve this. */
354                  if ((GetActiveWindow() != hwnd) && !parent)                  if ((GetForegroundWindow() != hwnd) && !parent)
355                          SetActiveWindow(hwnd);                          SetForegroundWindow(hwnd);
356    
357                  vchannel_write("ACK", "%u", g_blocked_focus_serial);                  vchannel_write("ACK", "%u", g_blocked_focus_serial);
358          }          }
# Line 329  cbt_hook_proc(int code, WPARAM wparam, L Line 372  cbt_hook_proc(int code, WPARAM wparam, L
372                  case HCBT_MINMAX:                  case HCBT_MINMAX:
373                          {                          {
374                                  int show, state, blocked;                                  int show, state, blocked;
375                                  HWND blocked_hwnd;                                  HWND hwnd, blocked_hwnd;
376                                  unsigned int serial;                                  unsigned int serial;
377                                    LONG style;
378    
379                                  WaitForSingleObject(g_mutex, INFINITE);                                  WaitForSingleObject(g_mutex, INFINITE);
380                                  blocked_hwnd = g_blocked_state_hwnd;                                  blocked_hwnd = g_blocked_state_hwnd;
# Line 338  cbt_hook_proc(int code, WPARAM wparam, L Line 382  cbt_hook_proc(int code, WPARAM wparam, L
382                                  blocked = g_blocked_state;                                  blocked = g_blocked_state;
383                                  ReleaseMutex(g_mutex);                                  ReleaseMutex(g_mutex);
384    
385                                    hwnd = (HWND) wparam;
386    
387                                    style = GetWindowLong(hwnd, GWL_STYLE);
388    
389                                    if (!(style & WS_VISIBLE))
390                                            break;
391    
392                                  show = LOWORD(lparam);                                  show = LOWORD(lparam);
393    
394                                  if ((show == SW_NORMAL) || (show == SW_SHOWNORMAL)                                  if ((show == SW_NORMAL) || (show == SW_SHOWNORMAL)
# Line 353  cbt_hook_proc(int code, WPARAM wparam, L Line 404  cbt_hook_proc(int code, WPARAM wparam, L
404                                          break;                                          break;
405                                  }                                  }
406    
407                                  if ((blocked_hwnd == (HWND) wparam) && (blocked == state))                                  if ((blocked_hwnd == hwnd) && (blocked == state))
408                                          vchannel_write("ACK", "%u", serial);                                          vchannel_write("ACK", "%u", serial);
409                                  else                                  else
410                                          vchannel_write("STATE", "0x%p,0x%x,0x%x", (HWND) wparam,                                          vchannel_write("STATE", "0x%08lx,0x%08x,0x%08x",
411                                                         state, 0);                                                         hwnd, state, 0);
412    
413                                  break;                                  break;
414                          }                          }
# Line 402  SafeMoveWindow(unsigned int serial, HWND Line 453  SafeMoveWindow(unsigned int serial, HWND
453  {  {
454          RECT rect;          RECT rect;
455    
         vchannel_block();  
   
         if (!GetWindowRect(hwnd, &rect))  
         {  
                 vchannel_unblock();  
                 debug("GetWindowRect failed!\n");  
                 return;  
         }  
   
         if ((rect.left == x) && (rect.top == y) && (rect.right == x + width)  
             && (rect.bottom == y + height))  
         {  
                 vchannel_write("ACK", "%u", serial);  
                 vchannel_unblock();  
         }  
   
456          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
457          g_block_move_hwnd = hwnd;          g_block_move_hwnd = hwnd;
458          g_block_move_serial = serial;          g_block_move_serial = serial;
# Line 427  SafeMoveWindow(unsigned int serial, HWND Line 462  SafeMoveWindow(unsigned int serial, HWND
462          g_block_move.bottom = y + height;          g_block_move.bottom = y + height;
463          ReleaseMutex(g_mutex);          ReleaseMutex(g_mutex);
464    
         vchannel_unblock();  
   
465          SetWindowPos(hwnd, NULL, x, y, width, height, SWP_NOACTIVATE | SWP_NOZORDER);          SetWindowPos(hwnd, NULL, x, y, width, height, SWP_NOACTIVATE | SWP_NOZORDER);
466    
467            vchannel_write("ACK", "%u", serial);
468    
469            if (!GetWindowRect(hwnd, &rect))
470                    debug("GetWindowRect failed!\n");
471            else if ((rect.left != x) || (rect.top != y) || (rect.right != x + width)
472                     || (rect.bottom != y + height))
473                    update_position(hwnd);
474    
475          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
476          g_block_move_hwnd = NULL;          g_block_move_hwnd = NULL;
477          memset(&g_block_move, 0, sizeof(RECT));          memset(&g_block_move, 0, sizeof(RECT));
# Line 493  SafeSetState(unsigned int serial, HWND h Line 534  SafeSetState(unsigned int serial, HWND h
534          {          {
535                  vchannel_write("ACK", "%u", serial);                  vchannel_write("ACK", "%u", serial);
536                  vchannel_unblock();                  vchannel_unblock();
537                    return;
538          }          }
539    
540          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);

Legend:
Removed from v.1165  
changed lines
  Added in v.1230

  ViewVC Help
Powered by ViewVC 1.1.26