/[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 1102 by ossman_, Fri Mar 10 13:25:25 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    
# Line 91  wndproc_hook_proc(int code, WPARAM cur_t Line 92  wndproc_hook_proc(int code, WPARAM cur_t
92                  goto end;                  goto end;
93    
94          if (style & WS_POPUP)          if (style & WS_POPUP)
95            {
96                  parent = (HWND) GetWindowLong(hwnd, GWL_HWNDPARENT);                  parent = (HWND) GetWindowLong(hwnd, GWL_HWNDPARENT);
97                    if (!parent)
98                            parent = (HWND) - 1;
99            }
100          else          else
101                  parent = NULL;                  parent = NULL;
102    
# Line 104  wndproc_hook_proc(int code, WPARAM cur_t Line 109  wndproc_hook_proc(int code, WPARAM cur_t
109    
110                                  if (wp->flags & SWP_SHOWWINDOW)                                  if (wp->flags & SWP_SHOWWINDOW)
111                                  {                                  {
112                                          char title[150];                                          unsigned short title[150];
113                                          int state;                                          int state;
114    
115                                          vchannel_write("CREATE,0x%p,0x%p,0x%x", hwnd, parent, 0);                                          vchannel_write("CREATE,0x%p,0x%p,0x%x", hwnd, parent, 0);
116    
117                                          GetWindowText(hwnd, title, sizeof(title));                                          GetWindowTextW(hwnd, title, sizeof(title) / sizeof(*title));
118    
119                                          /* FIXME: Strip title of dangerous characters */                                          vchannel_write("TITLE,0x%x,%s,0x%x", hwnd,
120                                                           vchannel_strfilter_unicode(title), 0);
                                         vchannel_write("TITLE,0x%x,%s,0x%x", hwnd, title, 0);  
121    
122                                          if (style & WS_MAXIMIZE)                                          if (style & WS_MAXIMIZE)
123                                                  state = 2;                                                  state = 2;
# Line 122  wndproc_hook_proc(int code, WPARAM cur_t Line 126  wndproc_hook_proc(int code, WPARAM cur_t
126                                          else                                          else
127                                                  state = 0;                                                  state = 0;
128    
                                         vchannel_write("STATE,0x%p,0x%x,0x%x", hwnd, state, 0);  
   
129                                          update_position(hwnd);                                          update_position(hwnd);
130    
131                                          /* FIXME: Figure out z order */                                          vchannel_write("STATE,0x%p,0x%x,0x%x", hwnd, state, 0);
132                                  }                                  }
133    
134                                  if (wp->flags & SWP_HIDEWINDOW)                                  if (wp->flags & SWP_HIDEWINDOW)
135                                          vchannel_write("DESTROY,0x%p,0x%x", hwnd, 0);                                          vchannel_write("DESTROY,0x%p,0x%x", hwnd, 0);
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))                                  if (!(wp->flags & SWP_NOMOVE && wp->flags & SWP_NOSIZE))
# Line 150  wndproc_hook_proc(int code, WPARAM cur_t Line 152  wndproc_hook_proc(int code, WPARAM cur_t
152                          }                          }
153    
154                  case WM_SIZE:                  case WM_SIZE:
155                          if (!(style & WS_VISIBLE))                          if (!(style & WS_VISIBLE) || (style & WS_MINIMIZE))
156                                  break;                                  break;
157                          update_position(hwnd);                          update_position(hwnd);
158                          break;                          break;
159    
160                  case WM_MOVE:                  case WM_MOVE:
161                          if (!(style & WS_VISIBLE))                          if (!(style & WS_VISIBLE) || (style & WS_MINIMIZE))
162                                  break;                                  break;
163                          update_position(hwnd);                          update_position(hwnd);
164                          break;                          break;
165    
                 case WM_SETTEXT:  
                         if (!(style & WS_VISIBLE))  
                                 break;  
                         /* FIXME: Strip title of dangerous characters */  
                         vchannel_write("TITLE,0x%p,%s,0x%x", hwnd, (char *) lparam, 0);  
                         break;  
   
166                  case WM_DESTROY:                  case WM_DESTROY:
167                          if (!(style & WS_VISIBLE))                          if (!(style & WS_VISIBLE))
168                                  break;                                  break;
# Line 183  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    wndprocret_hook_proc(int code, WPARAM cur_thread, LPARAM details)
182    {
183            HWND hwnd, parent;
184            UINT msg;
185            WPARAM wparam;
186            LPARAM lparam;
187    
188            LONG style;
189    
190            if (code < 0)
191                    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)  cbt_hook_proc(int code, WPARAM wparam, LPARAM lparam)
230  {  {
231          if (code < 0)          if (code < 0)
# Line 196  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_SHOWNORMAL)                                  if ((show == SW_NORMAL) || (show == SW_SHOWNORMAL)
243                                        || (show == SW_RESTORE))
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                                  else                                  else
250                                    {
251                                            debug("Unexpected show: %d", show);
252                                          break;                                          break;
253                                    }
254                                  vchannel_write("STATE,0x%p,0x%x,0x%x", (HWND) wparam, state, 0);                                  vchannel_write("STATE,0x%p,0x%x,0x%x", (HWND) wparam, state, 0);
255                                  break;                                  break;
256                          }                          }
# Line 224  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 234  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.1102  
changed lines
  Added in v.1134

  ViewVC Help
Powered by ViewVC 1.1.26