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 enum_cb(HWND hwnd, LPARAM lparam) |
71 |
|
{ |
72 |
|
RECT rect; |
73 |
|
char title[150]; |
74 |
|
LONG styles; |
75 |
|
int state; |
76 |
|
|
77 |
|
styles = GetWindowLong(hwnd, GWL_STYLE); |
78 |
|
|
79 |
|
if (!(styles & WS_VISIBLE)) |
80 |
|
return TRUE; |
81 |
|
|
82 |
|
vchannel_write("CREATE1,0x%p,0x%x", hwnd, 0); |
83 |
|
|
84 |
|
if (!GetWindowRect(hwnd, &rect)) { |
85 |
|
debug("GetWindowRect failed!"); |
86 |
|
return TRUE; |
87 |
|
} |
88 |
|
|
89 |
|
vchannel_write("POSITION1,0x%p,%d,%d,%d,%d,0x%x", |
90 |
|
hwnd, |
91 |
|
rect.left, rect.top, |
92 |
|
rect.right - rect.left, |
93 |
|
rect.bottom - rect.top, |
94 |
|
0); |
95 |
|
|
96 |
|
GetWindowText(hwnd, title, sizeof(title)); |
97 |
|
|
98 |
|
/* FIXME: Strip title of dangerous characters */ |
99 |
|
|
100 |
|
if (styles & WS_MAXIMIZE) |
101 |
|
state = 2; |
102 |
|
else if (styles & WS_MINIMIZE) |
103 |
|
state = 1; |
104 |
|
else |
105 |
|
state = 0; |
106 |
|
|
107 |
|
vchannel_write("SETSTATE1,0x%p,%s,0x%x,0x%x", |
108 |
|
hwnd, title, state, 0); |
109 |
|
|
110 |
|
return TRUE; |
111 |
|
} |
112 |
|
|
113 |
|
static void |
114 |
|
do_sync(void) |
115 |
|
{ |
116 |
|
vchannel_block(); |
117 |
|
|
118 |
|
vchannel_write("SYNCBEGIN,0x0"); |
119 |
|
|
120 |
|
EnumWindows(enum_cb, 0); |
121 |
|
|
122 |
|
vchannel_write("SYNCEND,0x0"); |
123 |
|
|
124 |
|
vchannel_unblock(); |
125 |
|
} |
126 |
|
|
127 |
|
static void |
128 |
|
process_cmds(void) |
129 |
|
{ |
130 |
|
char line[VCHANNEL_MAX_LINE]; |
131 |
|
int size; |
132 |
|
|
133 |
|
char *p, *tok1, *tok2, *tok3, *tok4, *tok5, *tok6, *tok7, *tok8; |
134 |
|
|
135 |
|
while ((size = vchannel_read(line, sizeof(line))) >= 0) { |
136 |
|
debug("Got: %s", line); |
137 |
|
|
138 |
|
p = line; |
139 |
|
|
140 |
|
tok1 = get_token(&p); |
141 |
|
tok2 = get_token(&p); |
142 |
|
tok3 = get_token(&p); |
143 |
|
tok4 = get_token(&p); |
144 |
|
tok5 = get_token(&p); |
145 |
|
tok6 = get_token(&p); |
146 |
|
tok7 = get_token(&p); |
147 |
|
tok8 = get_token(&p); |
148 |
|
|
149 |
|
if (strcmp(tok1, "SYNC") == 0) |
150 |
|
do_sync(); |
151 |
|
} |
152 |
|
} |
153 |
|
|
154 |
int WINAPI |
int WINAPI |
155 |
WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmdline, int cmdshow) |
WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmdline, int cmdshow) |
156 |
{ |
{ |
188 |
return -1; |
return -1; |
189 |
} |
} |
190 |
|
|
191 |
|
vchannel_open(); |
192 |
|
|
193 |
set_hooks_fn(); |
set_hooks_fn(); |
194 |
|
|
195 |
|
/* Since we don't see the entire desktop we must resize windows |
196 |
|
immediatly. */ |
197 |
|
SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, TRUE, NULL, 0); |
198 |
|
|
199 |
if (strlen(cmdline) == 0) |
if (strlen(cmdline) == 0) |
200 |
{ |
{ |
201 |
message("No command line specified."); |
message("No command line specified."); |
218 |
{ |
{ |
219 |
do |
do |
220 |
{ |
{ |
221 |
Sleep(1000); |
process_cmds(); |
222 |
|
Sleep(100); |
223 |
GetExitCodeProcess(proc_info.hProcess, &exitcode); |
GetExitCodeProcess(proc_info.hProcess, &exitcode); |
224 |
} |
} |
225 |
while (exitcode == STILL_ACTIVE); |
while (exitcode == STILL_ACTIVE); |
242 |
|
|
243 |
FreeLibrary(hookdll); |
FreeLibrary(hookdll); |
244 |
|
|
245 |
|
vchannel_close(); |
246 |
|
|
247 |
return 1; |
return 1; |
248 |
} |
} |