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 = ((CWPSTRUCT *) details)->hwnd; |
HWND hwnd, parent; |
72 |
UINT msg = ((CWPSTRUCT *) details)->message; |
UINT msg; |
73 |
WPARAM wparam = ((CWPSTRUCT *) details)->wParam; |
WPARAM wparam; |
74 |
LPARAM lparam = ((CWPSTRUCT *) details)->lParam; |
LPARAM lparam; |
75 |
|
|
76 |
LONG style = GetWindowLong(hwnd, GWL_STYLE); |
LONG style; |
|
WINDOWPOS *wp = (WINDOWPOS *) lparam; |
|
|
RECT rect; |
|
77 |
|
|
78 |
if (code < 0) |
if (code < 0) |
79 |
goto end; |
goto end; |
80 |
|
|
81 |
|
hwnd = ((CWPSTRUCT *) details)->hwnd; |
82 |
|
msg = ((CWPSTRUCT *) details)->message; |
83 |
|
wparam = ((CWPSTRUCT *) details)->wParam; |
84 |
|
lparam = ((CWPSTRUCT *) details)->lParam; |
85 |
|
|
86 |
|
style = GetWindowLong(hwnd, GWL_STYLE); |
87 |
|
|
88 |
|
/* 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; |
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 |
if (style & WS_CHILD) |
{ |
103 |
break; |
WINDOWPOS *wp = (WINDOWPOS *) lparam; |
104 |
|
|
105 |
|
if (wp->flags & SWP_SHOWWINDOW) |
106 |
|
{ |
107 |
|
char title[150]; |
108 |
|
int state; |
109 |
|
|
110 |
if (wp->flags & SWP_SHOWWINDOW) |
vchannel_write("CREATE,0x%p,0x%p,0x%x", hwnd, parent, 0); |
|
{ |
|
|
// FIXME: Now, just like create! |
|
|
debug("SWP_SHOWWINDOW for %p!", hwnd); |
|
|
vchannel_write("CREATE1,0x%p,0x%x", hwnd, 0); |
|
111 |
|
|
112 |
// FIXME: SETSTATE |
GetWindowText(hwnd, title, sizeof(title)); |
113 |
|
|
114 |
if (!GetWindowRect(hwnd, &rect)) |
/* FIXME: Strip title of dangerous characters */ |
|
{ |
|
|
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); |
|
|
} |
|
115 |
|
|
116 |
|
vchannel_write("TITLE,0x%x,%s,0x%x", hwnd, title, 0); |
117 |
|
|
118 |
if (wp->flags & SWP_HIDEWINDOW) |
if (style & WS_MAXIMIZE) |
119 |
vchannel_write("DESTROY1,0x%p,0x%x", hwnd, 0); |
state = 2; |
120 |
|
else if (style & WS_MINIMIZE) |
121 |
|
state = 1; |
122 |
|
else |
123 |
|
state = 0; |
124 |
|
|
125 |
|
vchannel_write("STATE,0x%p,0x%x,0x%x", hwnd, state, 0); |
126 |
|
|
127 |
if (!(style & WS_VISIBLE)) |
update_position(hwnd); |
|
break; |
|
128 |
|
|
129 |
if (wp->flags & SWP_NOMOVE && wp->flags & SWP_NOSIZE) |
/* FIXME: Figure out z order */ |
130 |
break; |
} |
131 |
|
|
132 |
if (!GetWindowRect(hwnd, &rect)) |
if (wp->flags & SWP_HIDEWINDOW) |
133 |
{ |
vchannel_write("DESTROY,0x%p,0x%x", hwnd, 0); |
|
debug("GetWindowRect failed!\n"); |
|
|
break; |
|
|
} |
|
134 |
|
|
135 |
vchannel_write("POSITION1,0x%p,%d,%d,%d,%d,0x%x", |
if (!(style & WS_VISIBLE)) |
136 |
hwnd, |
break; |
|
rect.left, rect.top, |
|
|
rect.right - rect.left, rect.bottom - rect.top, 0); |
|
137 |
|
|
138 |
break; |
if (!(wp->flags & SWP_NOMOVE && wp->flags & SWP_NOSIZE)) |
139 |
|
update_position(hwnd); |
140 |
|
|
141 |
|
if (!(wp->flags & SWP_NOZORDER)) |
142 |
|
{ |
143 |
|
vchannel_write("ZCHANGE,0x%p,0x%p,0x%x", |
144 |
|
hwnd, |
145 |
|
wp->flags & SWP_NOACTIVATE ? wp-> |
146 |
|
hwndInsertAfter : 0, 0); |
147 |
|
} |
148 |
|
|
|
/* Note: WM_WINDOWPOSCHANGING/WM_WINDOWPOSCHANGED are |
|
|
strange. Sometimes, for example when bringing up the |
|
|
Notepad About dialog, only an WM_WINDOWPOSCHANGING is |
|
|
sent. In some other cases, for exmaple when opening |
|
|
Format->Text in Notepad, both events are sent. Also, for |
|
|
some reason, when closing the Notepad About dialog, an |
|
|
WM_WINDOWPOSCHANGING event is sent which looks just like |
|
|
the event that was sent when the About dialog was opened... */ |
|
|
case WM_WINDOWPOSCHANGING: |
|
|
if (style & WS_CHILD) |
|
149 |
break; |
break; |
150 |
|
} |
151 |
|
|
152 |
|
case WM_SIZE: |
153 |
if (!(style & WS_VISIBLE)) |
if (!(style & WS_VISIBLE)) |
154 |
break; |
break; |
155 |
|
update_position(hwnd); |
|
if (!(wp->flags & SWP_NOZORDER)) |
|
|
vchannel_write("ZCHANGE1,0x%p,0x%p,0x%x", |
|
|
hwnd, |
|
|
wp->flags & SWP_NOACTIVATE ? wp->hwndInsertAfter : 0, |
|
|
0); |
|
|
|
|
156 |
break; |
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 |
if (style & WS_CHILD) |
if (!(style & WS_VISIBLE)) |
166 |
break; |
break; |
167 |
|
vchannel_write("DESTROY,0x%p,0x%x", hwnd, 0); |
|
vchannel_write("DESTROY1,0x%p,0x%x", hwnd, 0); |
|
|
|
|
168 |
break; |
break; |
169 |
|
|
|
|
|
170 |
default: |
default: |
171 |
break; |
break; |
172 |
} |
} |
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 |
|
|
185 |
{ |
{ |
186 |
case HCBT_MINMAX: |
case HCBT_MINMAX: |
187 |
{ |
{ |
188 |
int show; |
int show, state; |
189 |
|
|
190 |
show = LOWORD(lparam); |
show = LOWORD(lparam); |
191 |
|
|
192 |
if ((show == SW_SHOWMINIMIZED) || (show == SW_MINIMIZE)) |
if (show == SW_SHOWNORMAL) |
193 |
{ |
state = 0; |
194 |
MessageBox(0, |
else if (show == SW_SHOWMINIMIZED) |
195 |
"Minimizing windows is not allowed in this version. Sorry!", |
state = 1; |
196 |
"SeamlessRDP", MB_OK); |
else if (show == SW_SHOWMAXIMIZED) |
197 |
return 1; |
state = 2; |
198 |
} |
else |
199 |
|
break; |
200 |
GetWindowText((HWND) wparam, title, sizeof(title)); |
vchannel_write("STATE,0x%p,0x%x,0x%x", (HWND) wparam, state, 0); |
|
|
|
|
/* FIXME: Strip title of dangerous characters */ |
|
|
|
|
|
vchannel_write("SETSTATE1,0x%p,%s,0x%x,0x%x", |
|
|
(HWND) wparam, title, show, 0); |
|
201 |
break; |
break; |
202 |
} |
} |
203 |
|
|