25 |
#include <windows.h> |
#include <windows.h> |
26 |
#include <stdio.h> |
#include <stdio.h> |
27 |
|
|
28 |
|
#include "vchannel.h" |
29 |
|
|
30 |
#include "resource.h" |
#include "resource.h" |
31 |
|
|
32 |
#define APP_NAME "SeamlessRDP Shell" |
#define APP_NAME "SeamlessRDP Shell" |
44 |
MessageBox(GetDesktopWindow(), text, "SeamlessRDP Shell", MB_OK); |
MessageBox(GetDesktopWindow(), text, "SeamlessRDP Shell", MB_OK); |
45 |
} |
} |
46 |
|
|
47 |
|
static char * |
48 |
|
get_token(char **s) |
49 |
|
{ |
50 |
|
char *comma, *head; |
51 |
|
head = *s; |
52 |
|
|
53 |
|
if (!head) |
54 |
|
return NULL; |
55 |
|
|
56 |
|
comma = strchr(head, ','); |
57 |
|
if (comma) |
58 |
|
{ |
59 |
|
*comma = '\0'; |
60 |
|
*s = comma + 1; |
61 |
|
} |
62 |
|
else |
63 |
|
{ |
64 |
|
*s = NULL; |
65 |
|
} |
66 |
|
|
67 |
|
return head; |
68 |
|
} |
69 |
|
|
70 |
|
static BOOL CALLBACK |
71 |
|
enum_cb(HWND hwnd, LPARAM lparam) |
72 |
|
{ |
73 |
|
RECT rect; |
74 |
|
char title[150]; |
75 |
|
LONG styles; |
76 |
|
int state; |
77 |
|
|
78 |
|
styles = GetWindowLong(hwnd, GWL_STYLE); |
79 |
|
|
80 |
|
if (!(styles & WS_VISIBLE)) |
81 |
|
return TRUE; |
82 |
|
|
83 |
|
vchannel_write("CREATE,0x%p,0x%x", hwnd, 0); |
84 |
|
|
85 |
|
if (!GetWindowRect(hwnd, &rect)) |
86 |
|
{ |
87 |
|
debug("GetWindowRect failed!"); |
88 |
|
return TRUE; |
89 |
|
} |
90 |
|
|
91 |
|
vchannel_write("POSITION,0x%p,%d,%d,%d,%d,0x%x", |
92 |
|
hwnd, |
93 |
|
rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 0); |
94 |
|
|
95 |
|
GetWindowText(hwnd, title, sizeof(title)); |
96 |
|
|
97 |
|
/* FIXME: Strip title of dangerous characters */ |
98 |
|
|
99 |
|
if (styles & WS_MAXIMIZE) |
100 |
|
state = 2; |
101 |
|
else if (styles & WS_MINIMIZE) |
102 |
|
state = 1; |
103 |
|
else |
104 |
|
state = 0; |
105 |
|
|
106 |
|
vchannel_write("SETSTATE,0x%p,%s,0x%x,0x%x", hwnd, title, state, 0); |
107 |
|
|
108 |
|
return TRUE; |
109 |
|
} |
110 |
|
|
111 |
|
static void |
112 |
|
do_sync(void) |
113 |
|
{ |
114 |
|
vchannel_block(); |
115 |
|
|
116 |
|
vchannel_write("SYNCBEGIN,0x0"); |
117 |
|
|
118 |
|
EnumWindows(enum_cb, 0); |
119 |
|
|
120 |
|
vchannel_write("SYNCEND,0x0"); |
121 |
|
|
122 |
|
vchannel_unblock(); |
123 |
|
} |
124 |
|
|
125 |
|
static void |
126 |
|
process_cmds(void) |
127 |
|
{ |
128 |
|
char line[VCHANNEL_MAX_LINE]; |
129 |
|
int size; |
130 |
|
|
131 |
|
char *p, *tok1, *tok2, *tok3, *tok4, *tok5, *tok6, *tok7, *tok8; |
132 |
|
|
133 |
|
while ((size = vchannel_read(line, sizeof(line))) >= 0) |
134 |
|
{ |
135 |
|
debug("Got: %s", line); |
136 |
|
|
137 |
|
p = line; |
138 |
|
|
139 |
|
tok1 = get_token(&p); |
140 |
|
tok2 = get_token(&p); |
141 |
|
tok3 = get_token(&p); |
142 |
|
tok4 = get_token(&p); |
143 |
|
tok5 = get_token(&p); |
144 |
|
tok6 = get_token(&p); |
145 |
|
tok7 = get_token(&p); |
146 |
|
tok8 = get_token(&p); |
147 |
|
|
148 |
|
if (strcmp(tok1, "SYNC") == 0) |
149 |
|
do_sync(); |
150 |
|
} |
151 |
|
} |
152 |
|
|
153 |
int WINAPI |
int WINAPI |
154 |
WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmdline, int cmdshow) |
WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmdline, int cmdshow) |
155 |
{ |
{ |
161 |
|
|
162 |
g_instance = instance; |
g_instance = instance; |
163 |
|
|
164 |
hookdll = LoadLibrary("hookdll.dll"); |
hookdll = LoadLibrary("seamlessrdp.dll"); |
165 |
if (!hookdll) |
if (!hookdll) |
166 |
{ |
{ |
167 |
message("Could not load hook DLL. Unable to continue."); |
message("Could not load hook DLL. Unable to continue."); |
187 |
return -1; |
return -1; |
188 |
} |
} |
189 |
|
|
190 |
|
vchannel_open(); |
191 |
|
|
192 |
set_hooks_fn(); |
set_hooks_fn(); |
193 |
|
|
194 |
|
/* Since we don't see the entire desktop we must resize windows |
195 |
|
immediatly. */ |
196 |
|
SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, TRUE, NULL, 0); |
197 |
|
|
198 |
|
/* Disable screen saver since we cannot catch its windows. */ |
199 |
|
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, NULL, 0); |
200 |
|
|
201 |
if (strlen(cmdline) == 0) |
if (strlen(cmdline) == 0) |
202 |
{ |
{ |
203 |
message("No command line specified."); |
message("No command line specified."); |
220 |
{ |
{ |
221 |
do |
do |
222 |
{ |
{ |
223 |
Sleep(1000); |
process_cmds(); |
224 |
|
Sleep(100); |
225 |
GetExitCodeProcess(proc_info.hProcess, &exitcode); |
GetExitCodeProcess(proc_info.hProcess, &exitcode); |
226 |
} |
} |
227 |
while (exitcode == STILL_ACTIVE); |
while (exitcode == STILL_ACTIVE); |
244 |
|
|
245 |
FreeLibrary(hookdll); |
FreeLibrary(hookdll); |
246 |
|
|
247 |
|
vchannel_close(); |
248 |
|
|
249 |
return 1; |
return 1; |
250 |
} |
} |