/[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 1079 by ossman_, Thu Mar 9 15:48:55 2006 UTC revision 1134 by ossman_, Wed Mar 15 13:19:54 2006 UTC
# Line 44  int g_instance_count = 0; Line 44  int g_instance_count = 0;
44    
45  static HHOOK g_cbt_hook = NULL;  static HHOOK g_cbt_hook = NULL;
46  static HHOOK g_wndproc_hook = NULL;  static HHOOK g_wndproc_hook = NULL;
47    static HHOOK g_wndprocret_hook = NULL;
48    
49  static HINSTANCE g_instance = NULL;  static HINSTANCE g_instance = NULL;
50    
51  static HANDLE g_mutex = NULL;  static HANDLE g_mutex = NULL;
52    
53    static void
54    update_position(HWND hwnd)
55    {
56            RECT rect;
57    
58            if (!GetWindowRect(hwnd, &rect))
59            {
60                    debug("GetWindowRect failed!\n");
61                    return;
62            }
63    
64            vchannel_write("POSITION,0x%p,%d,%d,%d,%d,0x%x",
65                           hwnd,
66                           rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 0);
67    }
68    
69  static LRESULT CALLBACK  static LRESULT CALLBACK
70  wndproc_hook_proc(int code, WPARAM cur_thread, LPARAM details)  wndproc_hook_proc(int code, WPARAM cur_thread, LPARAM details)
71  {  {
72          HWND hwnd;          HWND hwnd, parent;
73          UINT msg;          UINT msg;
74          WPARAM wparam;          WPARAM wparam;
75          LPARAM lparam;          LPARAM lparam;
# Line 69  wndproc_hook_proc(int code, WPARAM cur_t Line 86  wndproc_hook_proc(int code, WPARAM cur_t
86    
87          style = GetWindowLong(hwnd, GWL_STYLE);          style = GetWindowLong(hwnd, GWL_STYLE);
88    
89          if (style & WS_CHILD)          /* Docs say that WS_CHILD and WS_POPUP is an illegal combination,
90               but they exist nonetheless. */
91            if ((style & WS_CHILD) && !(style & WS_POPUP))
92                  goto end;                  goto end;
93    
94            if (style & WS_POPUP)
95            {
96                    parent = (HWND) GetWindowLong(hwnd, GWL_HWNDPARENT);
97                    if (!parent)
98                            parent = (HWND) - 1;
99            }
100            else
101                    parent = NULL;
102    
103          switch (msg)          switch (msg)
104          {          {
105    
106                  case WM_WINDOWPOSCHANGED:                  case WM_WINDOWPOSCHANGED:
107                          {                          {
                                 RECT rect;  
108                                  WINDOWPOS *wp = (WINDOWPOS *) lparam;                                  WINDOWPOS *wp = (WINDOWPOS *) lparam;
109    
110                                  if (wp->flags & SWP_SHOWWINDOW)                                  if (wp->flags & SWP_SHOWWINDOW)
111                                  {                                  {
112                                          // FIXME: Now, just like create!                                          unsigned short title[150];
113                                          debug("SWP_SHOWWINDOW for %p!", hwnd);                                          int state;
                                         vchannel_write("CREATE1,0x%p,0x%x", hwnd, 0);  
   
                                         // FIXME: SETSTATE  
   
                                         if (!GetWindowRect(hwnd, &rect))  
                                         {  
                                                 debug("GetWindowRect failed!\n");  
                                                 break;  
                                         }  
                                         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);  
                                 }  
114    
115                                  if (wp->flags & SWP_HIDEWINDOW)                                          vchannel_write("CREATE,0x%p,0x%p,0x%x", hwnd, parent, 0);
                                         vchannel_write("DESTROY1,0x%p,0x%x", hwnd, 0);  
116    
117                                  if (!(style & WS_VISIBLE))                                          GetWindowTextW(hwnd, title, sizeof(title) / sizeof(*title));
                                         break;  
118    
119                                  if (wp->flags & SWP_NOMOVE && wp->flags & SWP_NOSIZE)                                          vchannel_write("TITLE,0x%x,%s,0x%x", hwnd,
120                                          break;                                                         vchannel_strfilter_unicode(title), 0);
121    
122                                  if (!GetWindowRect(hwnd, &rect))                                          if (style & WS_MAXIMIZE)
123                                  {                                                  state = 2;
124                                          debug("GetWindowRect failed!\n");                                          else if (style & WS_MINIMIZE)
125                                          break;                                                  state = 1;
126                                  }                                          else
127                                                    state = 0;
128    
129                                  vchannel_write("POSITION1,0x%p,%d,%d,%d,%d,0x%x",                                          update_position(hwnd);
                                                hwnd,  
                                                rect.left, rect.top,  
                                                rect.right - rect.left, rect.bottom - rect.top, 0);  
130    
131                                  break;                                          vchannel_write("STATE,0x%p,0x%x,0x%x", hwnd, state, 0);
132                          }                                  }
133    
134                  case WM_WINDOWPOSCHANGING:                                  if (wp->flags & SWP_HIDEWINDOW)
135                          {                                          vchannel_write("DESTROY,0x%p,0x%x", hwnd, 0);
                                 WINDOWPOS *wp = (WINDOWPOS *) lparam;  
136    
137                                  if (!(style & WS_VISIBLE))                                  if (!(style & WS_VISIBLE) || (style & WS_MINIMIZE))
138                                          break;                                          break;
139    
140                                    if (!(wp->flags & SWP_NOMOVE && wp->flags & SWP_NOSIZE))
141                                            update_position(hwnd);
142    
143                                  if (!(wp->flags & SWP_NOZORDER))                                  if (!(wp->flags & SWP_NOZORDER))
144                                          vchannel_write("ZCHANGE1,0x%p,0x%p,0x%x",                                  {
145                                            vchannel_write("ZCHANGE,0x%p,0x%p,0x%x",
146                                                         hwnd,                                                         hwnd,
147                                                         wp->flags & SWP_NOACTIVATE ? wp->                                                         wp->flags & SWP_NOACTIVATE ? wp->
148                                                         hwndInsertAfter : 0, 0);                                                         hwndInsertAfter : 0, 0);
149                                    }
150    
151                                  break;                                  break;
152                          }                          }
153    
154                    case WM_SIZE:
155                            if (!(style & WS_VISIBLE) || (style & WS_MINIMIZE))
156                                    break;
157                            update_position(hwnd);
158                            break;
159    
160                    case WM_MOVE:
161                            if (!(style & WS_VISIBLE) || (style & WS_MINIMIZE))
162                                    break;
163                            update_position(hwnd);
164                            break;
165    
166                  case WM_DESTROY:                  case WM_DESTROY:
167                          vchannel_write("DESTROY1,0x%p,0x%x", hwnd, 0);                          if (!(style & WS_VISIBLE))
168                                    break;
169                            vchannel_write("DESTROY,0x%p,0x%x", hwnd, 0);
170                          break;                          break;
171    
172                  default:                  default:
# Line 152  wndproc_hook_proc(int code, WPARAM cur_t Line 178  wndproc_hook_proc(int code, WPARAM cur_t
178  }  }
179    
180  static LRESULT CALLBACK  static LRESULT CALLBACK
181  cbt_hook_proc(int code, WPARAM wparam, LPARAM lparam)  wndprocret_hook_proc(int code, WPARAM cur_thread, LPARAM details)
182  {  {
183          char title[150];          HWND hwnd, parent;
184            UINT msg;
185            WPARAM wparam;
186            LPARAM lparam;
187    
188            LONG style;
189    
190          if (code < 0)          if (code < 0)
191                  goto end;                  goto end;
192    
193            hwnd = ((CWPRETSTRUCT *) details)->hwnd;
194            msg = ((CWPRETSTRUCT *) details)->message;
195            wparam = ((CWPRETSTRUCT *) details)->wParam;
196            lparam = ((CWPRETSTRUCT *) details)->lParam;
197    
198            style = GetWindowLong(hwnd, GWL_STYLE);
199    
200            /* Docs say that WS_CHILD and WS_POPUP is an illegal combination,
201               but they exist nonetheless. */
202            if ((style & WS_CHILD) && !(style & WS_POPUP))
203                    goto end;
204    
205            switch (msg)
206            {
207                    case WM_SETTEXT:
208                            {
209                                    unsigned short title[150];
210                                    if (!(style & WS_VISIBLE))
211                                            break;
212                                    /* We cannot use the string in lparam because
213                                       we need unicode. */
214                                    GetWindowTextW(hwnd, title, sizeof(title) / sizeof(*title));
215                                    vchannel_write("TITLE,0x%p,%s,0x%x", hwnd,
216                                                   vchannel_strfilter_unicode(title), 0);
217                                    break;
218                            }
219    
220                    default:
221                            break;
222            }
223    
224          end:
225            return CallNextHookEx(g_wndprocret_hook, code, cur_thread, details);
226    }
227    
228    static LRESULT CALLBACK
229    cbt_hook_proc(int code, WPARAM wparam, LPARAM lparam)
230    {
231            if (code < 0)
232                    goto end;
233    
234          switch (code)          switch (code)
235          {          {
236                  case HCBT_MINMAX:                  case HCBT_MINMAX:
# Line 167  cbt_hook_proc(int code, WPARAM wparam, L Line 239  cbt_hook_proc(int code, WPARAM wparam, L
239    
240                                  show = LOWORD(lparam);                                  show = LOWORD(lparam);
241    
242                                  if ((show == SW_SHOWMINIMIZED) || (show == SW_MINIMIZE))                                  if ((show == SW_NORMAL) || (show == SW_SHOWNORMAL)
243                                  {                                      || (show == SW_RESTORE))
                                         MessageBox(0,  
                                                    "Minimizing windows is not allowed in this version. Sorry!",  
                                                    "SeamlessRDP", MB_OK);  
                                         return 1;  
                                 }  
   
                                 GetWindowText((HWND) wparam, title, sizeof(title));  
   
                                 /* FIXME: Strip title of dangerous characters */  
   
                                 if (show == SW_SHOWNORMAL)  
244                                          state = 0;                                          state = 0;
245                                  else if (show == SW_SHOWMINIMIZED)                                  else if ((show == SW_MINIMIZE) || (show == SW_SHOWMINIMIZED))
246                                          state = 1;                                          state = 1;
247                                  else if (show == SW_SHOWMAXIMIZED)                                  else if ((show == SW_MAXIMIZE) || (show == SW_SHOWMAXIMIZED))
248                                          state = 2;                                          state = 2;
249                                  vchannel_write("SETSTATE1,0x%p,%s,0x%x,0x%x",                                  else
250                                                 (HWND) wparam, title, state, 0);                                  {
251                                            debug("Unexpected show: %d", show);
252                                            break;
253                                    }
254                                    vchannel_write("STATE,0x%p,0x%x,0x%x", (HWND) wparam, state, 0);
255                                  break;                                  break;
256                          }                          }
257    
# Line 206  SetHooks(void) Line 271  SetHooks(void)
271    
272          if (!g_wndproc_hook)          if (!g_wndproc_hook)
273                  g_wndproc_hook = SetWindowsHookEx(WH_CALLWNDPROC, wndproc_hook_proc, g_instance, 0);                  g_wndproc_hook = SetWindowsHookEx(WH_CALLWNDPROC, wndproc_hook_proc, g_instance, 0);
274    
275            if (!g_wndprocret_hook)
276                    g_wndprocret_hook =
277                            SetWindowsHookEx(WH_CALLWNDPROCRET, wndprocret_hook_proc, g_instance, 0);
278  }  }
279    
280  DLL_EXPORT void  DLL_EXPORT void
# Line 216  RemoveHooks(void) Line 285  RemoveHooks(void)
285    
286          if (g_wndproc_hook)          if (g_wndproc_hook)
287                  UnhookWindowsHookEx(g_wndproc_hook);                  UnhookWindowsHookEx(g_wndproc_hook);
288    
289            if (g_wndprocret_hook)
290                    UnhookWindowsHookEx(g_wndprocret_hook);
291  }  }
292    
293  DLL_EXPORT int  DLL_EXPORT int

Legend:
Removed from v.1079  
changed lines
  Added in v.1134

  ViewVC Help
Powered by ViewVC 1.1.26