/[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 1145 by ossman_, Thu Mar 16 13:24:18 2006 UTC revision 1162 by ossman_, Mon Mar 20 09:36:23 2006 UTC
# Line 45  Line 45 
45  int g_instance_count SHARED = 0;  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;
49  RECT g_block_move SHARED = { 0, 0, 0, 0 };  RECT g_block_move SHARED = { 0, 0, 0, 0 };
50    HWND g_blocked_zchange[2] SHARED = { NULL, NULL };
51    HWND g_blocked_focus SHARED = NULL;
52    HWND g_blocked_state_hwnd SHARED = NULL;
53    int g_blocked_state SHARED = -1;
54    
55  #pragma data_seg ()  #pragma data_seg ()
56    
57  #pragma comment(linker, "/section:SHAREDDATA,rws")  #pragma comment(linker, "/section:SHAREDDATA,rws")
58    
59    #define FOCUS_MSG_NAME "WM_SEAMLESS_FOCUS"
60    static UINT g_wm_seamless_focus;
61    
62  static HHOOK g_cbt_hook = NULL;  static HHOOK g_cbt_hook = NULL;
63  static HHOOK g_wndproc_hook = NULL;  static HHOOK g_wndproc_hook = NULL;
64  static HHOOK g_wndprocret_hook = NULL;  static HHOOK g_wndprocret_hook = NULL;
# Line 63  static void Line 71  static void
71  update_position(HWND hwnd)  update_position(HWND hwnd)
72  {  {
73          RECT rect, blocked;          RECT rect, blocked;
74            HWND blocked_hwnd;
75    
76          if (!GetWindowRect(hwnd, &rect))          if (!GetWindowRect(hwnd, &rect))
77          {          {
# Line 71  update_position(HWND hwnd) Line 80  update_position(HWND hwnd)
80          }          }
81    
82          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
83            blocked_hwnd = hwnd;
84          memcpy(&blocked, &g_block_move, sizeof(RECT));          memcpy(&blocked, &g_block_move, sizeof(RECT));
85          ReleaseMutex(g_mutex);          ReleaseMutex(g_mutex);
86    
87          if ((rect.left == blocked.left) && (rect.top == blocked.top)          if ((hwnd == blocked_hwnd) && (rect.left == blocked.left) && (rect.top == blocked.top)
88              && (rect.right == blocked.right) && (rect.bottom == blocked.bottom))              && (rect.right == blocked.right) && (rect.bottom == blocked.bottom))
89                  return;                  return;
90    
# Line 83  update_position(HWND hwnd) Line 93  update_position(HWND hwnd)
93                         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);
94  }  }
95    
96    static void
97    update_zorder(HWND hwnd)
98    {
99            HWND behind;
100            HWND block_hwnd, block_behind;
101    
102            WaitForSingleObject(g_mutex, INFINITE);
103            block_hwnd = g_blocked_zchange[0];
104            block_behind = g_blocked_zchange[1];
105            ReleaseMutex(g_mutex);
106    
107            behind = GetNextWindow(hwnd, GW_HWNDPREV);
108            while (behind)
109            {
110                    LONG style;
111    
112                    style = GetWindowLong(behind, GWL_STYLE);
113    
114                    if ((!(style & WS_CHILD) || (style & WS_POPUP)) && (style & WS_VISIBLE))
115                            break;
116    
117                    behind = GetNextWindow(behind, GW_HWNDPREV);
118            }
119    
120            if ((hwnd == block_hwnd) && (behind == block_behind))
121                    return;
122    
123            vchannel_write("ZCHANGE,0x%p,0x%p,0x%x", hwnd, behind, 0);
124    }
125    
126  static LRESULT CALLBACK  static LRESULT CALLBACK
127  wndproc_hook_proc(int code, WPARAM cur_thread, LPARAM details)  wndproc_hook_proc(int code, WPARAM cur_thread, LPARAM details)
128  {  {
# Line 119  wndproc_hook_proc(int code, WPARAM cur_t Line 159  wndproc_hook_proc(int code, WPARAM cur_t
159    
160          switch (msg)          switch (msg)
161          {          {
   
162                  case WM_WINDOWPOSCHANGED:                  case WM_WINDOWPOSCHANGED:
163                          {                          {
164                                  WINDOWPOS *wp = (WINDOWPOS *) lparam;                                  WINDOWPOS *wp = (WINDOWPOS *) lparam;
# Line 157  wndproc_hook_proc(int code, WPARAM cur_t Line 196  wndproc_hook_proc(int code, WPARAM cur_t
196                                  if (!(wp->flags & SWP_NOMOVE && wp->flags & SWP_NOSIZE))                                  if (!(wp->flags & SWP_NOMOVE && wp->flags & SWP_NOSIZE))
197                                          update_position(hwnd);                                          update_position(hwnd);
198    
                                 if (!(wp->flags & SWP_NOZORDER))  
                                 {  
                                         vchannel_write("ZCHANGE,0x%p,0x%p,0x%x",  
                                                        hwnd,  
                                                        wp->flags & SWP_NOACTIVATE ? wp->  
                                                        hwndInsertAfter : 0, 0);  
                                 }  
   
199                                  break;                                  break;
200                          }                          }
201    
# Line 219  wndprocret_hook_proc(int code, WPARAM cu Line 250  wndprocret_hook_proc(int code, WPARAM cu
250          if ((style & WS_CHILD) && !(style & WS_POPUP))          if ((style & WS_CHILD) && !(style & WS_POPUP))
251                  goto end;                  goto end;
252    
253            if (style & WS_POPUP)
254            {
255                    parent = (HWND) GetWindowLong(hwnd, GWL_HWNDPARENT);
256                    if (!parent)
257                            parent = (HWND) - 1;
258            }
259            else
260                    parent = NULL;
261    
262          switch (msg)          switch (msg)
263          {          {
264                    case WM_WINDOWPOSCHANGED:
265                            {
266                                    WINDOWPOS *wp = (WINDOWPOS *) lparam;
267    
268                                    if (!(style & WS_VISIBLE) || (style & WS_MINIMIZE))
269                                            break;
270    
271                                    if (!(wp->flags & SWP_NOZORDER))
272                                            update_zorder(hwnd);
273    
274                                    break;
275                            }
276    
277    
278                  case WM_SETTEXT:                  case WM_SETTEXT:
279                          {                          {
280                                  unsigned short title[150];                                  unsigned short title[150];
# Line 238  wndprocret_hook_proc(int code, WPARAM cu Line 292  wndprocret_hook_proc(int code, WPARAM cu
292                          break;                          break;
293          }          }
294    
295            if (msg == g_wm_seamless_focus)
296            {
297                    /* FIXME: SetActiveWindow() kills menus. Need to find a clean
298                       way to solve this. */
299                    if ((GetActiveWindow() != hwnd) && !parent)
300                            SetActiveWindow(hwnd);
301            }
302    
303        end:        end:
304          return CallNextHookEx(g_wndprocret_hook, code, cur_thread, details);          return CallNextHookEx(g_wndprocret_hook, code, cur_thread, details);
305  }  }
# Line 252  cbt_hook_proc(int code, WPARAM wparam, L Line 314  cbt_hook_proc(int code, WPARAM wparam, L
314          {          {
315                  case HCBT_MINMAX:                  case HCBT_MINMAX:
316                          {                          {
317                                  int show, state;                                  int show, state, blocked;
318                                    HWND blocked_hwnd;
319    
320                                    WaitForSingleObject(g_mutex, INFINITE);
321                                    blocked_hwnd = g_blocked_state_hwnd;
322                                    blocked = g_blocked_state;
323                                    ReleaseMutex(g_mutex);
324    
325                                  show = LOWORD(lparam);                                  show = LOWORD(lparam);
326    
# Line 268  cbt_hook_proc(int code, WPARAM wparam, L Line 336  cbt_hook_proc(int code, WPARAM wparam, L
336                                          debug("Unexpected show: %d", show);                                          debug("Unexpected show: %d", show);
337                                          break;                                          break;
338                                  }                                  }
339                                  vchannel_write("STATE,0x%p,0x%x,0x%x", (HWND) wparam, state, 0);  
340                                    if ((blocked_hwnd != (HWND) wparam) || (blocked != state))
341                                            vchannel_write("STATE,0x%p,0x%x,0x%x", (HWND) wparam, state,
342                                                           0);
343    
344                                  break;                                  break;
345                          }                          }
346    
# Line 311  DLL_EXPORT void Line 383  DLL_EXPORT void
383  SafeMoveWindow(HWND hwnd, int x, int y, int width, int height)  SafeMoveWindow(HWND hwnd, int x, int y, int width, int height)
384  {  {
385          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
386            g_block_move_hwnd = hwnd;
387          g_block_move.left = x;          g_block_move.left = x;
388          g_block_move.top = y;          g_block_move.top = y;
389          g_block_move.right = x + width;          g_block_move.right = x + width;
# Line 320  SafeMoveWindow(HWND hwnd, int x, int y, Line 393  SafeMoveWindow(HWND hwnd, int x, int y,
393          SetWindowPos(hwnd, NULL, x, y, width, height, SWP_NOACTIVATE | SWP_NOZORDER);          SetWindowPos(hwnd, NULL, x, y, width, height, SWP_NOACTIVATE | SWP_NOZORDER);
394    
395          WaitForSingleObject(g_mutex, INFINITE);          WaitForSingleObject(g_mutex, INFINITE);
396            g_block_move_hwnd = NULL;
397          memset(&g_block_move, 0, sizeof(RECT));          memset(&g_block_move, 0, sizeof(RECT));
398          ReleaseMutex(g_mutex);          ReleaseMutex(g_mutex);
399  }  }
400    
401    DLL_EXPORT void
402    SafeZChange(HWND hwnd, HWND behind)
403    {
404            WaitForSingleObject(g_mutex, INFINITE);
405            g_blocked_zchange[0] = hwnd;
406            g_blocked_zchange[1] = behind;
407            ReleaseMutex(g_mutex);
408    
409            if (behind == NULL)
410                    behind = HWND_TOP;
411    
412            SetWindowPos(hwnd, behind, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
413    
414            WaitForSingleObject(g_mutex, INFINITE);
415            g_blocked_zchange[0] = NULL;
416            g_blocked_zchange[1] = NULL;
417            ReleaseMutex(g_mutex);
418    }
419    
420    DLL_EXPORT void
421    SafeFocus(HWND hwnd)
422    {
423            WaitForSingleObject(g_mutex, INFINITE);
424            g_blocked_focus = hwnd;
425            ReleaseMutex(g_mutex);
426    
427            SendMessage(hwnd, g_wm_seamless_focus, 0, 0);
428    
429            WaitForSingleObject(g_mutex, INFINITE);
430            g_blocked_focus = NULL;
431            ReleaseMutex(g_mutex);
432    }
433    
434    DLL_EXPORT void
435    SafeSetState(HWND hwnd, int state)
436    {
437            WaitForSingleObject(g_mutex, INFINITE);
438            g_blocked_state_hwnd = hwnd;
439            g_blocked_state = state;
440            ReleaseMutex(g_mutex);
441    
442            if (state == 0)
443                    ShowWindow(hwnd, SW_RESTORE);
444            else if (state == 1)
445                    ShowWindow(hwnd, SW_MINIMIZE);
446            else if (state == 2)
447                    ShowWindow(hwnd, SW_MAXIMIZE);
448            else
449                    debug("Invalid state %d sent.", state);
450    
451            WaitForSingleObject(g_mutex, INFINITE);
452            g_blocked_state_hwnd = NULL;
453            g_blocked_state = -1;
454            ReleaseMutex(g_mutex);
455    }
456    
457  DLL_EXPORT int  DLL_EXPORT int
458  GetInstanceCount()  GetInstanceCount()
459  {  {
# Line 347  DllMain(HINSTANCE hinstDLL, DWORD ul_rea Line 477  DllMain(HINSTANCE hinstDLL, DWORD ul_rea
477                          ++g_instance_count;                          ++g_instance_count;
478                          ReleaseMutex(g_mutex);                          ReleaseMutex(g_mutex);
479    
480                            g_wm_seamless_focus = RegisterWindowMessage(FOCUS_MSG_NAME);
481    
482                          vchannel_open();                          vchannel_open();
483    
484                          break;                          break;

Legend:
Removed from v.1145  
changed lines
  Added in v.1162

  ViewVC Help
Powered by ViewVC 1.1.26