/[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 1165 by ossman_, Mon Mar 20 12:28:03 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          if (!GetWindowRect(hwnd, &rect))          if (!GetWindowRect(hwnd, &rect))
85          {          {
# Line 80  update_position(HWND hwnd) Line 88  update_position(HWND hwnd)
88          }          }
89    
90          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
91          blocked_hwnd = hwnd;          blocked_hwnd = g_block_move_hwnd;
92            serial = g_block_move_serial;
93          memcpy(&blocked, &g_block_move, sizeof(RECT));          memcpy(&blocked, &g_block_move, sizeof(RECT));
94          ReleaseMutex(g_mutex);          ReleaseMutex(g_mutex);
95    
96          if ((hwnd == blocked_hwnd) && (rect.left == blocked.left) && (rect.top == blocked.top)          if ((hwnd == blocked_hwnd) && (rect.left == blocked.left) && (rect.top == blocked.top)
97              && (rect.right == blocked.right) && (rect.bottom == blocked.bottom))              && (rect.right == blocked.right) && (rect.bottom == blocked.bottom))
98                  return;                  vchannel_write("ACK", "%u", serial);
99            else
100          vchannel_write("POSITION", "0x%p,%d,%d,%d,%d,0x%x",                  vchannel_write("POSITION", "0x%p,%d,%d,%d,%d,0x%x",
101                         hwnd,                                 hwnd,
102                         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,
103                                   0);
104  }  }
105    
106  static void  static void
# Line 98  update_zorder(HWND hwnd) Line 108  update_zorder(HWND hwnd)
108  {  {
109          HWND behind;          HWND behind;
110          HWND block_hwnd, block_behind;          HWND block_hwnd, block_behind;
111            unsigned int serial;
112    
113          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
114            serial = g_blocked_zchange_serial;
115          block_hwnd = g_blocked_zchange[0];          block_hwnd = g_blocked_zchange[0];
116          block_behind = g_blocked_zchange[1];          block_behind = g_blocked_zchange[1];
117          ReleaseMutex(g_mutex);          ReleaseMutex(g_mutex);
# Line 118  update_zorder(HWND hwnd) Line 130  update_zorder(HWND hwnd)
130          }          }
131    
132          if ((hwnd == block_hwnd) && (behind == block_behind))          if ((hwnd == block_hwnd) && (behind == block_behind))
133                  return;                  vchannel_write("ACK", "%u", serial);
134            else
135          vchannel_write("ZCHANGE", "0x%p,0x%p,0x%x", hwnd, behind, 0);                  vchannel_write("ZCHANGE", "0x%p,0x%p,0x%x", hwnd, behind, 0);
136  }  }
137    
138  static LRESULT CALLBACK  static LRESULT CALLBACK
# Line 298  wndprocret_hook_proc(int code, WPARAM cu Line 310  wndprocret_hook_proc(int code, WPARAM cu
310                     way to solve this. */                     way to solve this. */
311                  if ((GetActiveWindow() != hwnd) && !parent)                  if ((GetActiveWindow() != hwnd) && !parent)
312                          SetActiveWindow(hwnd);                          SetActiveWindow(hwnd);
313    
314                    vchannel_write("ACK", "%u", g_blocked_focus_serial);
315          }          }
316    
317        end:        end:
# Line 316  cbt_hook_proc(int code, WPARAM wparam, L Line 330  cbt_hook_proc(int code, WPARAM wparam, L
330                          {                          {
331                                  int show, state, blocked;                                  int show, state, blocked;
332                                  HWND blocked_hwnd;                                  HWND blocked_hwnd;
333                                    unsigned int serial;
334    
335                                  WaitForSingleObject(g_mutex, INFINITE);                                  WaitForSingleObject(g_mutex, INFINITE);
336                                  blocked_hwnd = g_blocked_state_hwnd;                                  blocked_hwnd = g_blocked_state_hwnd;
337                                    serial = g_blocked_state_serial;
338                                  blocked = g_blocked_state;                                  blocked = g_blocked_state;
339                                  ReleaseMutex(g_mutex);                                  ReleaseMutex(g_mutex);
340    
# Line 337  cbt_hook_proc(int code, WPARAM wparam, L Line 353  cbt_hook_proc(int code, WPARAM wparam, L
353                                          break;                                          break;
354                                  }                                  }
355    
356                                  if ((blocked_hwnd != (HWND) wparam) || (blocked != state))                                  if ((blocked_hwnd == (HWND) wparam) && (blocked == state))
357                                            vchannel_write("ACK", "%u", serial);
358                                    else
359                                          vchannel_write("STATE", "0x%p,0x%x,0x%x", (HWND) wparam,                                          vchannel_write("STATE", "0x%p,0x%x,0x%x", (HWND) wparam,
360                                                         state, 0);                                                         state, 0);
361    
# Line 380  RemoveHooks(void) Line 398  RemoveHooks(void)
398  }  }
399    
400  DLL_EXPORT void  DLL_EXPORT void
401  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)
402  {  {
403            RECT rect;
404    
405            vchannel_block();
406    
407            if (!GetWindowRect(hwnd, &rect))
408            {
409                    vchannel_unblock();
410                    debug("GetWindowRect failed!\n");
411                    return;
412            }
413    
414            if ((rect.left == x) && (rect.top == y) && (rect.right == x + width)
415                && (rect.bottom == y + height))
416            {
417                    vchannel_write("ACK", "%u", serial);
418                    vchannel_unblock();
419            }
420    
421          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
422          g_block_move_hwnd = hwnd;          g_block_move_hwnd = hwnd;
423            g_block_move_serial = serial;
424          g_block_move.left = x;          g_block_move.left = x;
425          g_block_move.top = y;          g_block_move.top = y;
426          g_block_move.right = x + width;          g_block_move.right = x + width;
427          g_block_move.bottom = y + height;          g_block_move.bottom = y + height;
428          ReleaseMutex(g_mutex);          ReleaseMutex(g_mutex);
429    
430            vchannel_unblock();
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          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
# Line 399  SafeMoveWindow(HWND hwnd, int x, int y, Line 438  SafeMoveWindow(HWND hwnd, int x, int y,
438  }  }
439    
440  DLL_EXPORT void  DLL_EXPORT void
441  SafeZChange(HWND hwnd, HWND behind)  SafeZChange(unsigned int serial, HWND hwnd, HWND behind)
442  {  {
443          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
444            g_blocked_zchange_serial = serial;
445          g_blocked_zchange[0] = hwnd;          g_blocked_zchange[0] = hwnd;
446          g_blocked_zchange[1] = behind;          g_blocked_zchange[1] = behind;
447          ReleaseMutex(g_mutex);          ReleaseMutex(g_mutex);
# Line 418  SafeZChange(HWND hwnd, HWND behind) Line 458  SafeZChange(HWND hwnd, HWND behind)
458  }  }
459    
460  DLL_EXPORT void  DLL_EXPORT void
461  SafeFocus(HWND hwnd)  SafeFocus(unsigned int serial, HWND hwnd)
462  {  {
463          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
464            g_blocked_focus_serial = serial;
465          g_blocked_focus = hwnd;          g_blocked_focus = hwnd;
466          ReleaseMutex(g_mutex);          ReleaseMutex(g_mutex);
467    
# Line 432  SafeFocus(HWND hwnd) Line 473  SafeFocus(HWND hwnd)
473  }  }
474    
475  DLL_EXPORT void  DLL_EXPORT void
476  SafeSetState(HWND hwnd, int state)  SafeSetState(unsigned int serial, HWND hwnd, int state)
477  {  {
478            LONG style;
479            int curstate;
480    
481            vchannel_block();
482    
483            style = GetWindowLong(hwnd, GWL_STYLE);
484    
485            if (style & WS_MAXIMIZE)
486                    curstate = 2;
487            else if (style & WS_MINIMIZE)
488                    curstate = 1;
489            else
490                    curstate = 0;
491    
492            if (state == curstate)
493            {
494                    vchannel_write("ACK", "%u", serial);
495                    vchannel_unblock();
496            }
497    
498          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
499          g_blocked_state_hwnd = hwnd;          g_blocked_state_hwnd = hwnd;
500            g_blocked_state_serial = serial;
501          g_blocked_state = state;          g_blocked_state = state;
502          ReleaseMutex(g_mutex);          ReleaseMutex(g_mutex);
503    
504            vchannel_unblock();
505    
506          if (state == 0)          if (state == 0)
507                  ShowWindow(hwnd, SW_RESTORE);                  ShowWindow(hwnd, SW_RESTORE);
508          else if (state == 1)          else if (state == 1)

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

  ViewVC Help
Powered by ViewVC 1.1.26