/[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 1163 by ossman_, Mon Mar 20 10:31:58 2006 UTC revision 1177 by ossman_, Tue Mar 21 14:42:25 2006 UTC
# Line 46  int g_instance_count SHARED = 0; Line 46  int g_instance_count SHARED = 0;
46    
47  // blocks for locally generated events  // blocks for locally generated events
48  HWND g_block_move_hwnd SHARED = NULL;  HWND g_block_move_hwnd SHARED = NULL;
49    unsigned int g_block_move_serial SHARED = 0;
50  RECT g_block_move SHARED = { 0, 0, 0, 0 };  RECT g_block_move SHARED = { 0, 0, 0, 0 };
51    
52    unsigned int g_blocked_zchange_serial SHARED = 0;
53  HWND g_blocked_zchange[2] SHARED = { NULL, NULL };  HWND g_blocked_zchange[2] SHARED = { NULL, NULL };
54    
55    unsigned int g_blocked_focus_serial SHARED = 0;
56  HWND g_blocked_focus SHARED = NULL;  HWND g_blocked_focus SHARED = NULL;
57    
58    unsigned int g_blocked_state_serial SHARED = 0;
59  HWND g_blocked_state_hwnd SHARED = NULL;  HWND g_blocked_state_hwnd SHARED = NULL;
60  int g_blocked_state SHARED = -1;  int g_blocked_state SHARED = -1;
61    
# Line 72  update_position(HWND hwnd) Line 79  update_position(HWND hwnd)
79  {  {
80          RECT rect, blocked;          RECT rect, blocked;
81          HWND blocked_hwnd;          HWND blocked_hwnd;
82            unsigned int serial;
83    
84            WaitForSingleObject(g_mutex, INFINITE);
85            blocked_hwnd = g_block_move_hwnd;
86            serial = g_block_move_serial;
87            memcpy(&blocked, &g_block_move, sizeof(RECT));
88            ReleaseMutex(g_mutex);
89    
90            vchannel_block();
91    
92          if (!GetWindowRect(hwnd, &rect))          if (!GetWindowRect(hwnd, &rect))
93          {          {
94                  debug("GetWindowRect failed!\n");                  debug("GetWindowRect failed!\n");
95                  return;                  goto end;
96          }          }
97    
         WaitForSingleObject(g_mutex, INFINITE);  
         blocked_hwnd = hwnd;  
         memcpy(&blocked, &g_block_move, sizeof(RECT));  
         ReleaseMutex(g_mutex);  
   
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                  return;                  goto end;
101    
102          vchannel_write("POSITION", "0x%p,%d,%d,%d,%d,0x%x",          vchannel_write("POSITION", "0x%p,%d,%d,%d,%d,0x%x",
103                         hwnd,                         hwnd,
104                         rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 0);                         rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 0);
105    
106          end:
107            vchannel_unblock();
108  }  }
109    
110  static void  static void
# Line 98  update_zorder(HWND hwnd) Line 112  update_zorder(HWND hwnd)
112  {  {
113          HWND behind;          HWND behind;
114          HWND block_hwnd, block_behind;          HWND block_hwnd, block_behind;
115            unsigned int serial;
116    
117          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
118            serial = g_blocked_zchange_serial;
119          block_hwnd = g_blocked_zchange[0];          block_hwnd = g_blocked_zchange[0];
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 118  update_zorder(HWND hwnd) Line 136  update_zorder(HWND hwnd)
136          }          }
137    
138          if ((hwnd == block_hwnd) && (behind == block_behind))          if ((hwnd == block_hwnd) && (behind == block_behind))
139                  return;                  vchannel_write("ACK", "%u", serial);
140            else
141                    vchannel_write("ZCHANGE", "0x%p,0x%p,0x%x", hwnd, behind, 0);
142    
143          vchannel_write("ZCHANGE", "0x%p,0x%p,0x%x", hwnd, behind, 0);          vchannel_unblock();
144  }  }
145    
146  static LRESULT CALLBACK  static LRESULT CALLBACK
# Line 167  wndproc_hook_proc(int code, WPARAM cur_t Line 187  wndproc_hook_proc(int code, WPARAM cur_t
187                                  {                                  {
188                                          unsigned short title[150];                                          unsigned short title[150];
189                                          int state;                                          int state;
190                                            DWORD pid;
191                                            int flags;
192    
193                                          vchannel_write("CREATE", "0x%p,0x%p,0x%x", hwnd, parent, 0);                                          GetWindowThreadProcessId(hwnd, &pid);
194    
195                                            flags = 0;
196                                            if (style & DS_MODALFRAME)
197                                                    flags |= SEAMLESS_CREATE_MODAL;
198    
199                                            vchannel_write("CREATE", "0x%08lx,0x%08lx,0x%08lx,0x%08x",
200                                                           (long) hwnd, (long) pid, (long) parent,
201                                                           flags);
202    
203                                          GetWindowTextW(hwnd, title, sizeof(title) / sizeof(*title));                                          GetWindowTextW(hwnd, title, sizeof(title) / sizeof(*title));
204    
# Line 298  wndprocret_hook_proc(int code, WPARAM cu Line 328  wndprocret_hook_proc(int code, WPARAM cu
328                     way to solve this. */                     way to solve this. */
329                  if ((GetActiveWindow() != hwnd) && !parent)                  if ((GetActiveWindow() != hwnd) && !parent)
330                          SetActiveWindow(hwnd);                          SetActiveWindow(hwnd);
331    
332                    vchannel_write("ACK", "%u", g_blocked_focus_serial);
333          }          }
334    
335        end:        end:
# Line 316  cbt_hook_proc(int code, WPARAM wparam, L Line 348  cbt_hook_proc(int code, WPARAM wparam, L
348                          {                          {
349                                  int show, state, blocked;                                  int show, state, blocked;
350                                  HWND blocked_hwnd;                                  HWND blocked_hwnd;
351                                    unsigned int serial;
352    
353                                  WaitForSingleObject(g_mutex, INFINITE);                                  WaitForSingleObject(g_mutex, INFINITE);
354                                  blocked_hwnd = g_blocked_state_hwnd;                                  blocked_hwnd = g_blocked_state_hwnd;
355                                    serial = g_blocked_state_serial;
356                                  blocked = g_blocked_state;                                  blocked = g_blocked_state;
357                                  ReleaseMutex(g_mutex);                                  ReleaseMutex(g_mutex);
358    
# Line 337  cbt_hook_proc(int code, WPARAM wparam, L Line 371  cbt_hook_proc(int code, WPARAM wparam, L
371                                          break;                                          break;
372                                  }                                  }
373    
374                                  if ((blocked_hwnd != (HWND) wparam) || (blocked != state))                                  if ((blocked_hwnd == (HWND) wparam) && (blocked == state))
375                                            vchannel_write("ACK", "%u", serial);
376                                    else
377                                          vchannel_write("STATE", "0x%p,0x%x,0x%x", (HWND) wparam,                                          vchannel_write("STATE", "0x%p,0x%x,0x%x", (HWND) wparam,
378                                                         state, 0);                                                         state, 0);
379    
# Line 380  RemoveHooks(void) Line 416  RemoveHooks(void)
416  }  }
417    
418  DLL_EXPORT void  DLL_EXPORT void
419  SafeMoveWindow(HWND hwnd, int x, int y, int width, int height)  SafeMoveWindow(unsigned int serial, HWND hwnd, int x, int y, int width, int height)
420  {  {
421            RECT rect;
422    
423          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
424          g_block_move_hwnd = hwnd;          g_block_move_hwnd = hwnd;
425            g_block_move_serial = serial;
426          g_block_move.left = x;          g_block_move.left = x;
427          g_block_move.top = y;          g_block_move.top = y;
428          g_block_move.right = x + width;          g_block_move.right = x + width;
# Line 392  SafeMoveWindow(HWND hwnd, int x, int y, Line 431  SafeMoveWindow(HWND hwnd, int x, int y,
431    
432          SetWindowPos(hwnd, NULL, x, y, width, height, SWP_NOACTIVATE | SWP_NOZORDER);          SetWindowPos(hwnd, NULL, x, y, width, height, SWP_NOACTIVATE | SWP_NOZORDER);
433    
434            vchannel_write("ACK", "%u", serial);
435    
436            if (!GetWindowRect(hwnd, &rect))
437                    debug("GetWindowRect failed!\n");
438            else if ((rect.left != x) || (rect.top != y) || (rect.right != x + width)
439                     || (rect.bottom != y + height))
440                    update_position(hwnd);
441    
442          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
443          g_block_move_hwnd = NULL;          g_block_move_hwnd = NULL;
444          memset(&g_block_move, 0, sizeof(RECT));          memset(&g_block_move, 0, sizeof(RECT));
# Line 399  SafeMoveWindow(HWND hwnd, int x, int y, Line 446  SafeMoveWindow(HWND hwnd, int x, int y,
446  }  }
447    
448  DLL_EXPORT void  DLL_EXPORT void
449  SafeZChange(HWND hwnd, HWND behind)  SafeZChange(unsigned int serial, HWND hwnd, HWND behind)
450  {  {
451          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
452            g_blocked_zchange_serial = serial;
453          g_blocked_zchange[0] = hwnd;          g_blocked_zchange[0] = hwnd;
454          g_blocked_zchange[1] = behind;          g_blocked_zchange[1] = behind;
455          ReleaseMutex(g_mutex);          ReleaseMutex(g_mutex);
# Line 418  SafeZChange(HWND hwnd, HWND behind) Line 466  SafeZChange(HWND hwnd, HWND behind)
466  }  }
467    
468  DLL_EXPORT void  DLL_EXPORT void
469  SafeFocus(HWND hwnd)  SafeFocus(unsigned int serial, HWND hwnd)
470  {  {
471          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
472            g_blocked_focus_serial = serial;
473          g_blocked_focus = hwnd;          g_blocked_focus = hwnd;
474          ReleaseMutex(g_mutex);          ReleaseMutex(g_mutex);
475    
# Line 432  SafeFocus(HWND hwnd) Line 481  SafeFocus(HWND hwnd)
481  }  }
482    
483  DLL_EXPORT void  DLL_EXPORT void
484  SafeSetState(HWND hwnd, int state)  SafeSetState(unsigned int serial, HWND hwnd, int state)
485  {  {
486            LONG style;
487            int curstate;
488    
489            vchannel_block();
490    
491            style = GetWindowLong(hwnd, GWL_STYLE);
492    
493            if (style & WS_MAXIMIZE)
494                    curstate = 2;
495            else if (style & WS_MINIMIZE)
496                    curstate = 1;
497            else
498                    curstate = 0;
499    
500            if (state == curstate)
501            {
502                    vchannel_write("ACK", "%u", serial);
503                    vchannel_unblock();
504                    return;
505            }
506    
507          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
508          g_blocked_state_hwnd = hwnd;          g_blocked_state_hwnd = hwnd;
509            g_blocked_state_serial = serial;
510          g_blocked_state = state;          g_blocked_state = state;
511          ReleaseMutex(g_mutex);          ReleaseMutex(g_mutex);
512    
513            vchannel_unblock();
514    
515          if (state == 0)          if (state == 0)
516                  ShowWindow(hwnd, SW_RESTORE);                  ShowWindow(hwnd, SW_RESTORE);
517          else if (state == 1)          else if (state == 1)

Legend:
Removed from v.1163  
changed lines
  Added in v.1177

  ViewVC Help
Powered by ViewVC 1.1.26