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 |
|
|
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) (); |
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 |
254 |
WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmdline, int cmdshow) |
WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmdline, int cmdshow) |
255 |
{ |
{ |
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 |
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); |
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); |
358 |
} |
} |
359 |
} |
} |
360 |
|
|
361 |
|
WTSUnRegisterSessionNotification(g_hwnd); |
362 |
|
|
363 |
remove_hooks_fn(); |
remove_hooks_fn(); |
364 |
|
|
365 |
FreeLibrary(hookdll); |
FreeLibrary(hookdll); |