/[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 1111 by ossman_, Fri Mar 10 15:25:17 2006 UTC revision 1147 by ossman_, Thu Mar 16 14:54:02 2006 UTC
# Line 24  Line 24 
24    
25  #include <windows.h>  #include <windows.h>
26  #include <stdio.h>  #include <stdio.h>
27    #include <wtsapi32.h>
28    #include <cchannel.h>
29    
30  #include "vchannel.h"  #include "vchannel.h"
31    
# Line 31  Line 33 
33    
34  #define APP_NAME "SeamlessRDP Shell"  #define APP_NAME "SeamlessRDP Shell"
35    
36    #ifndef WM_WTSSESSION_CHANGE
37    #define WM_WTSSESSION_CHANGE 0x02B1
38    #endif
39    #ifndef WTS_REMOTE_CONNECT
40    #define WTS_REMOTE_CONNECT 0x3
41    #endif
42    
43  /* Global data */  /* Global data */
44  static HINSTANCE g_instance;  static HINSTANCE g_instance;
45    static HWND g_hwnd;
46    
47  typedef void (*set_hooks_proc_t) ();  typedef void (*set_hooks_proc_t) ();
48  typedef void (*remove_hooks_proc_t) ();  typedef void (*remove_hooks_proc_t) ();
49  typedef int (*get_instance_count_proc_t) ();  typedef int (*get_instance_count_proc_t) ();
50    
51    typedef void (*move_window_proc_t) (HWND hwnd, int x, int y, int width, int height);
52    
53    static move_window_proc_t g_move_window_fn = NULL;
54    
55  static void  static void
56  message(const char *text)  message(const char *text)
57  {  {
# Line 71  static BOOL CALLBACK Line 85  static BOOL CALLBACK
85  enum_cb(HWND hwnd, LPARAM lparam)  enum_cb(HWND hwnd, LPARAM lparam)
86  {  {
87          RECT rect;          RECT rect;
88          char title[150];          unsigned short title[150];
89          LONG styles;          LONG styles;
90          int state;          int state;
91          HWND parent;          HWND parent;
# Line 98  enum_cb(HWND hwnd, LPARAM lparam) Line 112  enum_cb(HWND hwnd, LPARAM lparam)
112                         hwnd,                         hwnd,
113                         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);
114    
115          GetWindowText(hwnd, title, sizeof(title));          GetWindowTextW(hwnd, title, sizeof(title) / sizeof(*title));
116    
117          /* FIXME: Strip title of dangerous characters */          vchannel_write("TITLE,0x%x,%s,0x%x", hwnd, vchannel_strfilter_unicode(title), 0);
   
         vchannel_write("TITLE,0x%x,%s,0x%x", hwnd, title, 0);  
118    
119          if (styles & WS_MAXIMIZE)          if (styles & WS_MAXIMIZE)
120                  state = 2;                  state = 2;
# Line 144  do_state(HWND hwnd, int state) Line 156  do_state(HWND hwnd, int state)
156  }  }
157    
158  static void  static void
159    do_position(HWND hwnd, int x, int y, int width, int height)
160    {
161            g_move_window_fn(hwnd, x, y, width, height);
162    }
163    
164    static void
165    do_zchange(HWND hwnd, HWND behind)
166    {
167            if (behind == NULL)
168                    behind = HWND_TOP;
169            SetWindowPos(hwnd, behind, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
170    }
171    
172    static void
173  process_cmds(void)  process_cmds(void)
174  {  {
175          char line[VCHANNEL_MAX_LINE];          char line[VCHANNEL_MAX_LINE];
# Line 153  process_cmds(void) Line 179  process_cmds(void)
179    
180          while ((size = vchannel_read(line, sizeof(line))) >= 0)          while ((size = vchannel_read(line, sizeof(line))) >= 0)
181          {          {
                 debug("Got: %s", line);  
   
182                  p = line;                  p = line;
183    
184                  tok1 = get_token(&p);                  tok1 = get_token(&p);
# Line 169  process_cmds(void) Line 193  process_cmds(void)
193                  if (strcmp(tok1, "SYNC") == 0)                  if (strcmp(tok1, "SYNC") == 0)
194                          do_sync();                          do_sync();
195                  else if (strcmp(tok1, "STATE") == 0)                  else if (strcmp(tok1, "STATE") == 0)
196                          do_state((HWND) strtol(tok2, NULL, 0), strtol(tok3, NULL, 0));                          do_state((HWND) strtoul(tok2, NULL, 0), strtol(tok3, NULL, 0));
197                    else if (strcmp(tok1, "POSITION") == 0)
198                            do_position((HWND) strtoul(tok2, NULL, 0), strtol(tok3, NULL, 0),
199                                        strtol(tok4, NULL, 0), strtol(tok5, NULL, 0), strtol(tok6, NULL,
200                                                                                             0));
201                    else if (strcmp(tok1, "ZCHANGE") == 0)
202                            do_zchange((HWND) strtoul(tok2, NULL, 0), (HWND) strtoul(tok3, NULL, 0));
203            }
204    }
205    
206    static LRESULT CALLBACK
207    wndproc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
208    {
209            if (message == WM_WTSSESSION_CHANGE)
210            {
211                    if (wparam == WTS_REMOTE_CONNECT)
212                            vchannel_write("HELLO,0x%08x", 1);
213          }          }
214    
215            return DefWindowProc(hwnd, message, wparam, lparam);
216    }
217    
218    static BOOL
219    register_class(void)
220    {
221            WNDCLASSEX wcx;
222    
223            memset(&wcx, 0, sizeof(wcx));
224    
225            wcx.cbSize = sizeof(wcx);
226            wcx.lpfnWndProc = wndproc;
227            wcx.hInstance = g_instance;
228            wcx.lpszClassName = "SeamlessClass";
229    
230            return RegisterClassEx(&wcx);
231    }
232    
233    static BOOL
234    create_wnd(void)
235    {
236            if (!register_class())
237                    return FALSE;
238    
239            g_hwnd = CreateWindow("SeamlessClass",
240                                  "Seamless Window",
241                                  WS_OVERLAPPEDWINDOW,
242                                  CW_USEDEFAULT,
243                                  CW_USEDEFAULT,
244                                  CW_USEDEFAULT,
245                                  CW_USEDEFAULT, (HWND) NULL, (HMENU) NULL, g_instance, (LPVOID) NULL);
246    
247            if (!g_hwnd)
248                    return FALSE;
249    
250            return TRUE;
251  }  }
252    
253  int WINAPI  int WINAPI
# Line 194  WinMain(HINSTANCE instance, HINSTANCE pr Line 271  WinMain(HINSTANCE instance, HINSTANCE pr
271          set_hooks_fn = (set_hooks_proc_t) GetProcAddress(hookdll, "SetHooks");          set_hooks_fn = (set_hooks_proc_t) GetProcAddress(hookdll, "SetHooks");
272          remove_hooks_fn = (remove_hooks_proc_t) GetProcAddress(hookdll, "RemoveHooks");          remove_hooks_fn = (remove_hooks_proc_t) GetProcAddress(hookdll, "RemoveHooks");
273          instance_count_fn = (get_instance_count_proc_t) GetProcAddress(hookdll, "GetInstanceCount");          instance_count_fn = (get_instance_count_proc_t) GetProcAddress(hookdll, "GetInstanceCount");
274            g_move_window_fn = (move_window_proc_t) GetProcAddress(hookdll, "SafeMoveWindow");
275    
276          if (!set_hooks_fn || !remove_hooks_fn || !instance_count_fn)          if (!set_hooks_fn || !remove_hooks_fn || !instance_count_fn || !g_move_window_fn)
277          {          {
278                  FreeLibrary(hookdll);                  FreeLibrary(hookdll);
279                  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 210  WinMain(HINSTANCE instance, HINSTANCE pr Line 288  WinMain(HINSTANCE instance, HINSTANCE pr
288                  return -1;                  return -1;
289          }          }
290    
291            if (!create_wnd())
292            {
293                    FreeLibrary(hookdll);
294                    message("Couldn't create a window to catch events.");
295                    return -1;
296            }
297    
298            WTSRegisterSessionNotification(g_hwnd, NOTIFY_FOR_THIS_SESSION);
299    
300          vchannel_open();          vchannel_open();
301    
302            vchannel_write("HELLO,0x%08x", 0);
303    
304          set_hooks_fn();          set_hooks_fn();
305    
306          /* Since we don't see the entire desktop we must resize windows          /* Since we don't see the entire desktop we must resize windows
# Line 232  WinMain(HINSTANCE instance, HINSTANCE pr Line 321  WinMain(HINSTANCE instance, HINSTANCE pr
321                  DWORD exitcode;                  DWORD exitcode;
322                  PROCESS_INFORMATION proc_info;                  PROCESS_INFORMATION proc_info;
323                  STARTUPINFO startup_info;                  STARTUPINFO startup_info;
324                    MSG msg;
325    
326                  memset(&startup_info, 0, sizeof(STARTUPINFO));                  memset(&startup_info, 0, sizeof(STARTUPINFO));
327                  startup_info.cb = sizeof(STARTUPINFO);                  startup_info.cb = sizeof(STARTUPINFO);
# Line 243  WinMain(HINSTANCE instance, HINSTANCE pr Line 333  WinMain(HINSTANCE instance, HINSTANCE pr
333                  {                  {
334                          do                          do
335                          {                          {
336                                    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
337                                    {
338                                            TranslateMessage(&msg);
339                                            DispatchMessage(&msg);
340                                    }
341                                  process_cmds();                                  process_cmds();
342                                  Sleep(100);                                  Sleep(100);
343                                  GetExitCodeProcess(proc_info.hProcess, &exitcode);                                  GetExitCodeProcess(proc_info.hProcess, &exitcode);
# Line 263  WinMain(HINSTANCE instance, HINSTANCE pr Line 358  WinMain(HINSTANCE instance, HINSTANCE pr
358                  }                  }
359          }          }
360    
361            WTSUnRegisterSessionNotification(g_hwnd);
362    
363          remove_hooks_fn();          remove_hooks_fn();
364    
365          FreeLibrary(hookdll);          FreeLibrary(hookdll);

Legend:
Removed from v.1111  
changed lines
  Added in v.1147

  ViewVC Help
Powered by ViewVC 1.1.26