49 |
|
|
50 |
static HANDLE g_mutex = NULL; |
static HANDLE g_mutex = NULL; |
51 |
|
|
52 |
|
static void |
53 |
|
update_position(HWND hwnd) |
54 |
|
{ |
55 |
|
RECT rect; |
56 |
|
|
57 |
|
if (!GetWindowRect(hwnd, &rect)) |
58 |
|
{ |
59 |
|
debug("GetWindowRect failed!\n"); |
60 |
|
return; |
61 |
|
} |
62 |
|
|
63 |
|
vchannel_write("POSITION,0x%p,%d,%d,%d,%d,0x%x", |
64 |
|
hwnd, |
65 |
|
rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 0); |
66 |
|
} |
67 |
|
|
68 |
static LRESULT CALLBACK |
static LRESULT CALLBACK |
69 |
wndproc_hook_proc(int code, WPARAM cur_thread, LPARAM details) |
wndproc_hook_proc(int code, WPARAM cur_thread, LPARAM details) |
70 |
{ |
{ |
71 |
HWND hwnd; |
HWND hwnd, parent; |
72 |
UINT msg; |
UINT msg; |
73 |
WPARAM wparam; |
WPARAM wparam; |
74 |
LPARAM lparam; |
LPARAM lparam; |
85 |
|
|
86 |
style = GetWindowLong(hwnd, GWL_STYLE); |
style = GetWindowLong(hwnd, GWL_STYLE); |
87 |
|
|
88 |
if (style & WS_CHILD) |
/* Docs say that WS_CHILD and WS_POPUP is an illegal combination, |
89 |
|
but they exist nonetheless. */ |
90 |
|
if ((style & WS_CHILD) && !(style & WS_POPUP)) |
91 |
goto end; |
goto end; |
92 |
|
|
93 |
|
if (style & WS_POPUP) |
94 |
|
parent = (HWND) GetWindowLong(hwnd, GWL_HWNDPARENT); |
95 |
|
else |
96 |
|
parent = NULL; |
97 |
|
|
98 |
switch (msg) |
switch (msg) |
99 |
{ |
{ |
100 |
|
|
101 |
case WM_WINDOWPOSCHANGED: |
case WM_WINDOWPOSCHANGED: |
102 |
{ |
{ |
|
RECT rect; |
|
103 |
WINDOWPOS *wp = (WINDOWPOS *) lparam; |
WINDOWPOS *wp = (WINDOWPOS *) lparam; |
104 |
|
|
105 |
if (wp->flags & SWP_SHOWWINDOW) |
if (wp->flags & SWP_SHOWWINDOW) |
106 |
{ |
{ |
107 |
// FIXME: Now, just like create! |
char title[150]; |
108 |
debug("SWP_SHOWWINDOW for %p!", hwnd); |
int state; |
109 |
vchannel_write("CREATE1,0x%p,0x%x", hwnd, 0); |
|
110 |
|
vchannel_write("CREATE,0x%p,0x%p,0x%x", hwnd, parent, 0); |
111 |
// FIXME: SETSTATE |
|
112 |
|
GetWindowText(hwnd, title, sizeof(title)); |
113 |
if (!GetWindowRect(hwnd, &rect)) |
|
114 |
{ |
/* FIXME: Strip title of dangerous characters */ |
115 |
debug("GetWindowRect failed!\n"); |
|
116 |
break; |
vchannel_write("TITLE,0x%x,%s,0x%x", hwnd, title, 0); |
117 |
} |
|
118 |
vchannel_write("POSITION1,0x%p,%d,%d,%d,%d,0x%x", |
if (style & WS_MAXIMIZE) |
119 |
hwnd, |
state = 2; |
120 |
rect.left, rect.top, |
else if (style & WS_MINIMIZE) |
121 |
rect.right - rect.left, |
state = 1; |
122 |
rect.bottom - rect.top, 0); |
else |
123 |
|
state = 0; |
124 |
|
|
125 |
|
vchannel_write("STATE,0x%p,0x%x,0x%x", hwnd, state, 0); |
126 |
|
|
127 |
|
update_position(hwnd); |
128 |
|
|
129 |
|
/* FIXME: Figure out z order */ |
130 |
} |
} |
131 |
|
|
132 |
if (wp->flags & SWP_HIDEWINDOW) |
if (wp->flags & SWP_HIDEWINDOW) |
133 |
vchannel_write("DESTROY1,0x%p,0x%x", hwnd, 0); |
vchannel_write("DESTROY,0x%p,0x%x", hwnd, 0); |
134 |
|
|
135 |
if (!(style & WS_VISIBLE)) |
if (!(style & WS_VISIBLE)) |
136 |
break; |
break; |
137 |
|
|
138 |
if (!(wp->flags & SWP_NOMOVE && wp->flags & SWP_NOSIZE)) |
if (!(wp->flags & SWP_NOMOVE && wp->flags & SWP_NOSIZE)) |
139 |
{ |
update_position(hwnd); |
|
if (!GetWindowRect(hwnd, &rect)) |
|
|
{ |
|
|
debug("GetWindowRect failed!\n"); |
|
|
break; |
|
|
} |
|
|
|
|
|
vchannel_write("POSITION1,0x%p,%d,%d,%d,%d,0x%x", |
|
|
hwnd, |
|
|
rect.left, rect.top, |
|
|
rect.right - rect.left, |
|
|
rect.bottom - rect.top, 0); |
|
|
} |
|
140 |
|
|
141 |
if (!(wp->flags & SWP_NOZORDER)) |
if (!(wp->flags & SWP_NOZORDER)) |
142 |
{ |
{ |
143 |
vchannel_write("ZCHANGE1,0x%p,0x%p,0x%x", |
vchannel_write("ZCHANGE,0x%p,0x%p,0x%x", |
144 |
hwnd, |
hwnd, |
145 |
wp->flags & SWP_NOACTIVATE ? wp-> |
wp->flags & SWP_NOACTIVATE ? wp-> |
146 |
hwndInsertAfter : 0, 0); |
hwndInsertAfter : 0, 0); |
149 |
break; |
break; |
150 |
} |
} |
151 |
|
|
152 |
|
case WM_SIZE: |
153 |
|
if (!(style & WS_VISIBLE)) |
154 |
|
break; |
155 |
|
update_position(hwnd); |
156 |
|
break; |
157 |
|
|
158 |
|
case WM_MOVE: |
159 |
|
if (!(style & WS_VISIBLE)) |
160 |
|
break; |
161 |
|
update_position(hwnd); |
162 |
|
break; |
163 |
|
|
164 |
case WM_DESTROY: |
case WM_DESTROY: |
165 |
vchannel_write("DESTROY1,0x%p,0x%x", hwnd, 0); |
if (!(style & WS_VISIBLE)) |
166 |
|
break; |
167 |
|
vchannel_write("DESTROY,0x%p,0x%x", hwnd, 0); |
168 |
break; |
break; |
169 |
|
|
170 |
default: |
default: |
178 |
static LRESULT CALLBACK |
static LRESULT CALLBACK |
179 |
cbt_hook_proc(int code, WPARAM wparam, LPARAM lparam) |
cbt_hook_proc(int code, WPARAM wparam, LPARAM lparam) |
180 |
{ |
{ |
|
char title[150]; |
|
|
|
|
181 |
if (code < 0) |
if (code < 0) |
182 |
goto end; |
goto end; |
183 |
|
|
189 |
|
|
190 |
show = LOWORD(lparam); |
show = LOWORD(lparam); |
191 |
|
|
|
if ((show == SW_SHOWMINIMIZED) || (show == SW_MINIMIZE)) |
|
|
{ |
|
|
MessageBox(0, |
|
|
"Minimizing windows is not allowed in this version. Sorry!", |
|
|
"SeamlessRDP", MB_OK); |
|
|
return 1; |
|
|
} |
|
|
|
|
|
GetWindowText((HWND) wparam, title, sizeof(title)); |
|
|
|
|
|
/* FIXME: Strip title of dangerous characters */ |
|
|
|
|
192 |
if (show == SW_SHOWNORMAL) |
if (show == SW_SHOWNORMAL) |
193 |
state = 0; |
state = 0; |
194 |
else if (show == SW_SHOWMINIMIZED) |
else if (show == SW_SHOWMINIMIZED) |
195 |
state = 1; |
state = 1; |
196 |
else if (show == SW_SHOWMAXIMIZED) |
else if (show == SW_SHOWMAXIMIZED) |
197 |
state = 2; |
state = 2; |
198 |
vchannel_write("SETSTATE1,0x%p,%s,0x%x,0x%x", |
vchannel_write("STATE,0x%p,0x%x,0x%x", (HWND) wparam, state, 0); |
|
(HWND) wparam, title, state, 0); |
|
199 |
break; |
break; |
200 |
} |
} |
201 |
|
|