/[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 1135 by ossman_, Wed Mar 15 13:45:42 2006 UTC revision 1156 by ossman_, Fri Mar 17 10:48:55 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    #define FOCUS_MSG_NAME "WM_SEAMLESS_FOCUS"
37    static UINT g_wm_seamless_focus;
38    
39    #ifndef WM_WTSSESSION_CHANGE
40    #define WM_WTSSESSION_CHANGE 0x02B1
41    #endif
42    #ifndef WTS_REMOTE_CONNECT
43    #define WTS_REMOTE_CONNECT 0x3
44    #endif
45    
46  /* Global data */  /* Global data */
47  static HINSTANCE g_instance;  static HINSTANCE g_instance;
48    static HWND g_hwnd;
49    
50  typedef void (*set_hooks_proc_t) ();  typedef void (*set_hooks_proc_t) ();
51  typedef void (*remove_hooks_proc_t) ();  typedef void (*remove_hooks_proc_t) ();
52  typedef int (*get_instance_count_proc_t) ();  typedef int (*get_instance_count_proc_t) ();
53    
54    typedef void (*move_window_proc_t) (HWND hwnd, int x, int y, int width, int height);
55    
56    static move_window_proc_t g_move_window_fn = NULL;
57    
58  static void  static void
59  message(const char *text)  message(const char *text)
60  {  {
# Line 144  do_state(HWND hwnd, int state) Line 161  do_state(HWND hwnd, int state)
161  static void  static void
162  do_position(HWND hwnd, int x, int y, int width, int height)  do_position(HWND hwnd, int x, int y, int width, int height)
163  {  {
164          SetWindowPos(hwnd, NULL, x, y, width, height, SWP_NOACTIVATE | SWP_NOZORDER);          g_move_window_fn(hwnd, x, y, width, height);
165  }  }
166    
167  static void  static void
# Line 156  do_zchange(HWND hwnd, HWND behind) Line 173  do_zchange(HWND hwnd, HWND behind)
173  }  }
174    
175  static void  static void
176    do_focus(HWND hwnd)
177    {
178            SendMessage(hwnd, g_wm_seamless_focus, 0, 0);
179    }
180    
181    static void
182  process_cmds(void)  process_cmds(void)
183  {  {
184          char line[VCHANNEL_MAX_LINE];          char line[VCHANNEL_MAX_LINE];
# Line 165  process_cmds(void) Line 188  process_cmds(void)
188    
189          while ((size = vchannel_read(line, sizeof(line))) >= 0)          while ((size = vchannel_read(line, sizeof(line))) >= 0)
190          {          {
                 debug("Got: %s", line);  
   
191                  p = line;                  p = line;
192    
193                  tok1 = get_token(&p);                  tok1 = get_token(&p);
# Line 188  process_cmds(void) Line 209  process_cmds(void)
209                                                                                           0));                                                                                           0));
210                  else if (strcmp(tok1, "ZCHANGE") == 0)                  else if (strcmp(tok1, "ZCHANGE") == 0)
211                          do_zchange((HWND) strtoul(tok2, NULL, 0), (HWND) strtoul(tok3, NULL, 0));                          do_zchange((HWND) strtoul(tok2, NULL, 0), (HWND) strtoul(tok3, NULL, 0));
212                    else if (strcmp(tok1, "FOCUS") == 0)
213                            do_focus((HWND) strtoul(tok2, NULL, 0));
214            }
215    }
216    
217    static LRESULT CALLBACK
218    wndproc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
219    {
220            if (message == WM_WTSSESSION_CHANGE)
221            {
222                    if (wparam == WTS_REMOTE_CONNECT)
223                    {
224                            /* These get reset on each reconnect */
225                            SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, TRUE, NULL, 0);
226                            SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, NULL, 0);
227                            vchannel_write("HELLO,0x%08x", 1);
228                    }
229          }          }
230    
231            return DefWindowProc(hwnd, message, wparam, lparam);
232    }
233    
234    static BOOL
235    register_class(void)
236    {
237            WNDCLASSEX wcx;
238    
239            memset(&wcx, 0, sizeof(wcx));
240    
241            wcx.cbSize = sizeof(wcx);
242            wcx.lpfnWndProc = wndproc;
243            wcx.hInstance = g_instance;
244            wcx.lpszClassName = "SeamlessClass";
245    
246            return RegisterClassEx(&wcx);
247    }
248    
249    static BOOL
250    create_wnd(void)
251    {
252            if (!register_class())
253                    return FALSE;
254    
255            g_hwnd = CreateWindow("SeamlessClass",
256                                  "Seamless Window",
257                                  WS_OVERLAPPEDWINDOW,
258                                  CW_USEDEFAULT,
259                                  CW_USEDEFAULT,
260                                  CW_USEDEFAULT,
261                                  CW_USEDEFAULT, (HWND) NULL, (HMENU) NULL, g_instance, (LPVOID) NULL);
262    
263            if (!g_hwnd)
264                    return FALSE;
265    
266            return TRUE;
267  }  }
268    
269  int WINAPI  int WINAPI
# Line 212  WinMain(HINSTANCE instance, HINSTANCE pr Line 287  WinMain(HINSTANCE instance, HINSTANCE pr
287          set_hooks_fn = (set_hooks_proc_t) GetProcAddress(hookdll, "SetHooks");          set_hooks_fn = (set_hooks_proc_t) GetProcAddress(hookdll, "SetHooks");
288          remove_hooks_fn = (remove_hooks_proc_t) GetProcAddress(hookdll, "RemoveHooks");          remove_hooks_fn = (remove_hooks_proc_t) GetProcAddress(hookdll, "RemoveHooks");
289          instance_count_fn = (get_instance_count_proc_t) GetProcAddress(hookdll, "GetInstanceCount");          instance_count_fn = (get_instance_count_proc_t) GetProcAddress(hookdll, "GetInstanceCount");
290            g_move_window_fn = (move_window_proc_t) GetProcAddress(hookdll, "SafeMoveWindow");
291    
292          if (!set_hooks_fn || !remove_hooks_fn || !instance_count_fn)          if (!set_hooks_fn || !remove_hooks_fn || !instance_count_fn || !g_move_window_fn)
293          {          {
294                  FreeLibrary(hookdll);                  FreeLibrary(hookdll);
295                  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 228  WinMain(HINSTANCE instance, HINSTANCE pr Line 304  WinMain(HINSTANCE instance, HINSTANCE pr
304                  return -1;                  return -1;
305          }          }
306    
307            if (!create_wnd())
308            {
309                    FreeLibrary(hookdll);
310                    message("Couldn't create a window to catch events.");
311                    return -1;
312            }
313    
314            g_wm_seamless_focus = RegisterWindowMessage(FOCUS_MSG_NAME);
315    
316            WTSRegisterSessionNotification(g_hwnd, NOTIFY_FOR_THIS_SESSION);
317    
318          vchannel_open();          vchannel_open();
319    
320            vchannel_write("HELLO,0x%08x", 0);
321    
322          set_hooks_fn();          set_hooks_fn();
323    
324          /* 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 250  WinMain(HINSTANCE instance, HINSTANCE pr Line 339  WinMain(HINSTANCE instance, HINSTANCE pr
339                  DWORD exitcode;                  DWORD exitcode;
340                  PROCESS_INFORMATION proc_info;                  PROCESS_INFORMATION proc_info;
341                  STARTUPINFO startup_info;                  STARTUPINFO startup_info;
342                    MSG msg;
343    
344                  memset(&startup_info, 0, sizeof(STARTUPINFO));                  memset(&startup_info, 0, sizeof(STARTUPINFO));
345                  startup_info.cb = sizeof(STARTUPINFO);                  startup_info.cb = sizeof(STARTUPINFO);
# Line 261  WinMain(HINSTANCE instance, HINSTANCE pr Line 351  WinMain(HINSTANCE instance, HINSTANCE pr
351                  {                  {
352                          do                          do
353                          {                          {
354                                    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
355                                    {
356                                            TranslateMessage(&msg);
357                                            DispatchMessage(&msg);
358                                    }
359                                  process_cmds();                                  process_cmds();
360                                  Sleep(100);                                  Sleep(100);
361                                  GetExitCodeProcess(proc_info.hProcess, &exitcode);                                  GetExitCodeProcess(proc_info.hProcess, &exitcode);
# Line 281  WinMain(HINSTANCE instance, HINSTANCE pr Line 376  WinMain(HINSTANCE instance, HINSTANCE pr
376                  }                  }
377          }          }
378    
379            WTSUnRegisterSessionNotification(g_hwnd);
380    
381          remove_hooks_fn();          remove_hooks_fn();
382    
383          FreeLibrary(hookdll);          FreeLibrary(hookdll);

Legend:
Removed from v.1135  
changed lines
  Added in v.1156

  ViewVC Help
Powered by ViewVC 1.1.26