/[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 1077 by ossman_, Thu Mar 9 15:26:35 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 67  get_token(char **s) Line 71  get_token(char **s)
71          return head;          return head;
72  }  }
73    
74  static BOOL CALLBACK enum_cb(HWND hwnd, LPARAM lparam)  static BOOL CALLBACK
75    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("CREATE1,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            {
97                  debug("GetWindowRect failed!");                  debug("GetWindowRect failed!");
98                  return TRUE;                  return TRUE;
99          }          }
100    
101          vchannel_write("POSITION1,0x%p,%d,%d,%d,%d,0x%x",          vchannel_write("POSITION,0x%p,%d,%d,%d,%d,0x%x",
102                         hwnd,                         hwnd,
103                         rect.left, rect.top,                         rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 0);
                        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 104  static BOOL CALLBACK enum_cb(HWND hwnd, Line 113  static BOOL CALLBACK enum_cb(HWND hwnd,
113          else          else
114                  state = 0;                  state = 0;
115    
116          vchannel_write("SETSTATE1,0x%p,%s,0x%x,0x%x",          vchannel_write("STATE,0x%p,0x%x,0x%x", hwnd, state, 0);
                        hwnd, title, state, 0);  
117    
118          return TRUE;          return TRUE;
119  }  }
# Line 125  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 167  process_cmds(void)
167    
168          char *p, *tok1, *tok2, *tok3, *tok4, *tok5, *tok6, *tok7, *tok8;          char *p, *tok1, *tok2, *tok3, *tok4, *tok5, *tok6, *tok7, *tok8;
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 148  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 162  WinMain(HINSTANCE instance, HINSTANCE pr Line 204  WinMain(HINSTANCE instance, HINSTANCE pr
204    
205          g_instance = instance;          g_instance = instance;
206    
207          hookdll = LoadLibrary("hookdll.dll");          hookdll = LoadLibrary("seamlessrdp.dll");
208          if (!hookdll)          if (!hookdll)
209          {          {
210                  message("Could not load hook DLL. Unable to continue.");                  message("Could not load hook DLL. Unable to continue.");
# Line 172  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.");
# Line 196  WinMain(HINSTANCE instance, HINSTANCE pr Line 239  WinMain(HINSTANCE instance, HINSTANCE pr
239             immediatly. */             immediatly. */
240          SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, TRUE, NULL, 0);          SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, TRUE, NULL, 0);
241    
242            /* Disable screen saver since we cannot catch its windows. */
243            SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, NULL, 0);
244    
245          if (strlen(cmdline) == 0)          if (strlen(cmdline) == 0)
246          {          {
247                  message("No command line specified.");                  message("No command line specified.");

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

  ViewVC Help
Powered by ViewVC 1.1.26