/[rdesktop]/sourceforge.net/trunk/seamlessrdp/ServerExe/main.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/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1093 by ossman_, Fri Mar 10 09:47:10 2006 UTC revision 1145 by ossman_, Thu Mar 16 13:24:18 2006 UTC
# Line 38  typedef void (*set_hooks_proc_t) (); Line 38  typedef void (*set_hooks_proc_t) ();
38  typedef void (*remove_hooks_proc_t) ();  typedef void (*remove_hooks_proc_t) ();
39  typedef int (*get_instance_count_proc_t) ();  typedef int (*get_instance_count_proc_t) ();
40    
41    typedef void (*move_window_proc_t) (HWND hwnd, int x, int y, int width, int height);
42    
43    static move_window_proc_t g_move_window_fn = NULL;
44    
45  static void  static void
46  message(const char *text)  message(const char *text)
47  {  {
# Line 71  static BOOL CALLBACK Line 75  static BOOL CALLBACK
75  enum_cb(HWND hwnd, LPARAM lparam)  enum_cb(HWND hwnd, LPARAM lparam)
76  {  {
77          RECT rect;          RECT rect;
78          char title[150];          unsigned short title[150];
79          LONG styles;          LONG styles;
80          int state;          int state;
81            HWND parent;
82    
83          styles = GetWindowLong(hwnd, GWL_STYLE);          styles = GetWindowLong(hwnd, GWL_STYLE);
84    
85          if (!(styles & WS_VISIBLE))          if (!(styles & WS_VISIBLE))
86                  return TRUE;                  return TRUE;
87    
88          vchannel_write("CREATE,0x%p,0x%x", hwnd, 0);          if (styles & WS_POPUP)
89                    parent = (HWND) GetWindowLong(hwnd, GWL_HWNDPARENT);
90            else
91                    parent = NULL;
92    
93            vchannel_write("CREATE,0x%p,0x%p,0x%x", hwnd, parent, 0);
94    
95          if (!GetWindowRect(hwnd, &rect))          if (!GetWindowRect(hwnd, &rect))
96          {          {
# Line 92  enum_cb(HWND hwnd, LPARAM lparam) Line 102  enum_cb(HWND hwnd, LPARAM lparam)
102                         hwnd,                         hwnd,
103                         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);
104    
105          GetWindowText(hwnd, title, sizeof(title));          GetWindowTextW(hwnd, title, sizeof(title) / sizeof(*title));
106    
107          /* FIXME: Strip title of dangerous characters */          vchannel_write("TITLE,0x%x,%s,0x%x", hwnd, vchannel_strfilter_unicode(title), 0);
108    
109          if (styles & WS_MAXIMIZE)          if (styles & WS_MAXIMIZE)
110                  state = 2;                  state = 2;
# Line 103  enum_cb(HWND hwnd, LPARAM lparam) Line 113  enum_cb(HWND hwnd, LPARAM lparam)
113          else          else
114                  state = 0;                  state = 0;
115    
116          vchannel_write("SETSTATE,0x%p,%s,0x%x,0x%x", hwnd, title, state, 0);          vchannel_write("STATE,0x%p,0x%x,0x%x", hwnd, state, 0);
117    
118          return TRUE;          return TRUE;
119  }  }
# Line 123  do_sync(void) Line 133  do_sync(void)
133  }  }
134    
135  static void  static void
136    do_state(HWND hwnd, int state)
137    {
138            if (state == 0)
139                    ShowWindow(hwnd, SW_RESTORE);
140            else if (state == 1)
141                    ShowWindow(hwnd, SW_MINIMIZE);
142            else if (state == 2)
143                    ShowWindow(hwnd, SW_MAXIMIZE);
144            else
145                    debug("Invalid state %d sent.", state);
146    }
147    
148    static void
149    do_position(HWND hwnd, int x, int y, int width, int height)
150    {
151            g_move_window_fn(hwnd, x, y, width, height);
152    }
153    
154    static void
155    do_zchange(HWND hwnd, HWND behind)
156    {
157            if (behind == NULL)
158                    behind = HWND_TOP;
159            SetWindowPos(hwnd, behind, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
160    }
161    
162    static void
163  process_cmds(void)  process_cmds(void)
164  {  {
165          char line[VCHANNEL_MAX_LINE];          char line[VCHANNEL_MAX_LINE];
# Line 132  process_cmds(void) Line 169  process_cmds(void)
169    
170          while ((size = vchannel_read(line, sizeof(line))) >= 0)          while ((size = vchannel_read(line, sizeof(line))) >= 0)
171          {          {
                 debug("Got: %s", line);  
   
172                  p = line;                  p = line;
173    
174                  tok1 = get_token(&p);                  tok1 = get_token(&p);
# Line 147  process_cmds(void) Line 182  process_cmds(void)
182    
183                  if (strcmp(tok1, "SYNC") == 0)                  if (strcmp(tok1, "SYNC") == 0)
184                          do_sync();                          do_sync();
185                    else if (strcmp(tok1, "STATE") == 0)
186                            do_state((HWND) strtoul(tok2, NULL, 0), strtol(tok3, NULL, 0));
187                    else if (strcmp(tok1, "POSITION") == 0)
188                            do_position((HWND) strtoul(tok2, NULL, 0), strtol(tok3, NULL, 0),
189                                        strtol(tok4, NULL, 0), strtol(tok5, NULL, 0), strtol(tok6, NULL,
190                                                                                             0));
191                    else if (strcmp(tok1, "ZCHANGE") == 0)
192                            do_zchange((HWND) strtoul(tok2, NULL, 0), (HWND) strtoul(tok3, NULL, 0));
193          }          }
194  }  }
195    
# Line 171  WinMain(HINSTANCE instance, HINSTANCE pr Line 214  WinMain(HINSTANCE instance, HINSTANCE pr
214          set_hooks_fn = (set_hooks_proc_t) GetProcAddress(hookdll, "SetHooks");          set_hooks_fn = (set_hooks_proc_t) GetProcAddress(hookdll, "SetHooks");
215          remove_hooks_fn = (remove_hooks_proc_t) GetProcAddress(hookdll, "RemoveHooks");          remove_hooks_fn = (remove_hooks_proc_t) GetProcAddress(hookdll, "RemoveHooks");
216          instance_count_fn = (get_instance_count_proc_t) GetProcAddress(hookdll, "GetInstanceCount");          instance_count_fn = (get_instance_count_proc_t) GetProcAddress(hookdll, "GetInstanceCount");
217            g_move_window_fn = (move_window_proc_t) GetProcAddress(hookdll, "SafeMoveWindow");
218    
219          if (!set_hooks_fn || !remove_hooks_fn || !instance_count_fn)          if (!set_hooks_fn || !remove_hooks_fn || !instance_count_fn || !g_move_window_fn)
220          {          {
221                  FreeLibrary(hookdll);                  FreeLibrary(hookdll);
222                  message("Hook DLL doesn't contain the correct functions. Unable to continue.");                  message("Hook DLL doesn't contain the correct functions. Unable to continue.");

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

  ViewVC Help
Powered by ViewVC 1.1.26