1
2
3
4 package org.sirius.server.win32.classes;
5
6 import javax.jws.WebService;
7
8 import org.sirius.server.win32.constants.IMKConsts;
9 import org.sirius.server.win32.constants.IWMConsts;
10 import org.sirius.server.win32.core.types.WinDefExt.WINDOWPLACEMENT;
11
12 import com.sun.jna.Pointer;
13
14
15
16
17
18 @WebService
19 public class Window extends Common implements IWMConsts, IMKConsts {
20
21
22
23
24 public Window() {
25
26 }
27
28
29
30
31
32 public final void activate(final long hwnd) {
33 HWND handle = longToHwnd(hwnd);
34 getUser32().SetForegroundWindow(handle);
35 }
36
37
38
39
40
41
42
43
44
45
46
47 public final void click(final long hwnd, final int button, final int x,
48 final int y, final boolean isControl, final boolean isAlt,
49 final boolean isShift) {
50 mouseDown(hwnd, button, x, y, isControl, isAlt, isShift);
51 mouseUp(hwnd, button, x, y, isControl, isAlt, isShift);
52 }
53
54
55
56
57
58 public final void close(final long hwnd) {
59 HWND handle = longToHwnd(hwnd);
60 WPARAM wParam = new WPARAM();
61 LPARAM lParam = new LPARAM();
62
63 wParam.setValue(0);
64 lParam.setValue(0);
65 getUser32().PostMessage(handle, WM_CLOSE, wParam, lParam);
66 }
67
68
69
70
71
72
73
74
75
76
77
78 public final void doubleClick(
79 final long hwnd,
80 final int button,
81 final int x,
82 final int y,
83 final boolean isControl,
84 final boolean isAlt,
85 final boolean isShift) {
86 int message = 0;
87 int flags = 0;
88 switch (button) {
89 case 0:
90 message = WM_LBUTTONDBLCLK;
91 break;
92 case 1:
93 message = WM_RBUTTONDBLCLK;
94 break;
95 case 2:
96 message = WM_MBUTTONDBLCLK;
97 break;
98 default:
99 message = WM_LBUTTONDBLCLK;
100 break;
101 }
102
103 if (isControl) {
104 flags |= MK_CONTROL;
105 }
106 if (isShift) {
107 flags |= MK_SHIFT;
108 }
109 sendMessage(hwnd, message, flags, makeLParam(x, y).intValue());
110 }
111
112
113
114
115
116
117 public final RECT getClientRect(final long hwnd) {
118 RECT result = new RECT();
119 HWND handle = longToHwnd(hwnd);
120 getUser32().GetClientRect(handle, result);
121 return result;
122 }
123
124 public final long getDesktopWindow(){
125 return 0;
126 }
127
128
129
130
131
132
133 public final long getMenu(final long hwnd) {
134 HWND handle = longToHwnd(hwnd);
135 HMENU hmenu = getUser32().GetMenu(handle);
136 return Pointer.nativeValue(hmenu.getPointer());
137 }
138
139
140
141
142
143
144 public final RECT getRect(final long hwnd) {
145 RECT result = new RECT();
146 HWND handle = longToHwnd(hwnd);
147 getUser32().GetWindowRect(handle, result);
148 return result;
149 }
150
151
152
153
154
155
156
157 public final long getSystemMenu(final long hwnd, final boolean revert) {
158 HWND handle = longToHwnd(hwnd);
159 HMENU hmenu = getUser32().GetSystemMenu(handle, revert);
160 return Pointer.nativeValue(hmenu.getPointer());
161 }
162
163
164
165
166
167
168 public final String getText(final long hwnd) {
169 HWND handle = longToHwnd(hwnd);
170 int length = getUser32().GetWindowTextLength(handle) + 1;
171 char[] buf = new char[length];
172
173 getUser32().GetWindowText(handle, buf, length);
174 String text = String.valueOf(buf).trim();
175 return text;
176 }
177
178
179
180
181
182
183
184 public final boolean getWindowPlacement(final long hwnd,
185 final WINDOWPLACEMENT placement) {
186 HWND handle = longToHwnd(hwnd);
187 return getUser32().GetWindowPlacement(handle, placement);
188 }
189
190
191
192
193
194
195 public final boolean isEnabled(final long hwnd) {
196 HWND handle = longToHwnd(hwnd);
197 return getUser32().IsWindowEnabled(handle);
198 }
199
200
201
202
203
204
205 public final boolean isMaximized(final long hwnd) {
206 HWND handle = longToHwnd(hwnd);
207 WINDOWPLACEMENT placement = new WINDOWPLACEMENT();
208 getUser32().GetWindowPlacement(handle, placement);
209 return placement.showCmd == SW_MAXIMIZE;
210 }
211
212
213
214
215
216
217 public final boolean isMinimized(final long hwnd) {
218 HWND handle = longToHwnd(hwnd);
219 WINDOWPLACEMENT placement = new WINDOWPLACEMENT();
220 getUser32().GetWindowPlacement(handle, placement);
221 return placement.showCmd == SW_SHOWMINIMIZED;
222 }
223
224
225
226
227
228
229 public final boolean isNormal(final long hwnd) {
230 HWND handle = longToHwnd(hwnd);
231 WINDOWPLACEMENT placement = new WINDOWPLACEMENT();
232 getUser32().GetWindowPlacement(handle, placement);
233 return placement.showCmd == SW_NORMAL;
234 }
235
236
237
238
239
240
241 public final boolean isUnicode(final long hwnd) {
242 HWND handle = longToHwnd(hwnd);
243 return getUser32().IsWindowUnicode(handle);
244 }
245
246
247
248
249
250
251 public final boolean isVisible(final long hwnd) {
252 HWND handle = longToHwnd(hwnd);
253 return getUser32().IsWindowVisible(handle);
254 }
255
256
257
258
259
260
261 public final boolean isWindow(final long hwnd) {
262 HWND handle = longToHwnd(hwnd);
263 return getUser32().IsWindow(handle);
264 }
265
266
267
268
269
270
271 public final void keyDown(final long hwnd, final int key) {
272 sendMessage(hwnd, WM_KEYDOWN, key, 0);
273 }
274
275
276
277
278
279
280 public final void keyPress(final long hwnd, final int key) {
281 sendMessage(hwnd, WM_CHAR, key, 0);
282 }
283
284
285
286
287
288
289 public final void keyUp(final long hwnd, final int key) {
290 sendMessage(hwnd, WM_KEYUP, key, 0);
291 }
292
293
294
295
296
297 public final void maximize(final long hwnd) {
298 HWND handle = longToHwnd(hwnd);
299 getUser32().ShowWindow(handle, SW_MAXIMIZE);
300 }
301
302
303
304
305
306 public final void minimize(final long hwnd) {
307 HWND handle = longToHwnd(hwnd);
308 getUser32().ShowWindow(handle, SW_MINIMIZE);
309 }
310
311
312
313
314
315
316
317
318
319
320
321 public final void mouseDown(final long hwnd, final int button, final int x,
322 final int y, final boolean isControl, final boolean isAlt,
323 final boolean isShift) {
324 int message = 0;
325 int flags = 0;
326 switch (button) {
327 case 0:
328 message = WM_LBUTTONDOWN;
329 break;
330 case 1:
331 message = WM_RBUTTONDOWN;
332 break;
333 case 2:
334 message = WM_MBUTTONDOWN;
335 break;
336 default:
337 message = WM_LBUTTONDOWN;
338 break;
339 }
340
341 if (isControl) {
342 flags |= MK_CONTROL;
343 }
344 if (isShift) {
345 flags |= MK_SHIFT;
346 }
347 sendMessage(hwnd, message, flags, makeLParam(x, y).intValue());
348 }
349
350
351
352
353
354
355
356
357
358
359
360 public final void mouseUp(final long hwnd, final int button, final int x,
361 final int y, final boolean isControl, final boolean isAlt,
362 final boolean isShift) {
363 int message = 0;
364 int flags = 0;
365 switch (button) {
366 case 0:
367 message = WM_LBUTTONUP;
368 break;
369 case 1:
370 message = WM_RBUTTONUP;
371 break;
372 case 2:
373 message = WM_MBUTTONUP;
374 break;
375 default:
376 message = WM_LBUTTONUP;
377 break;
378 }
379
380 if (isControl) {
381 flags |= MK_CONTROL;
382 }
383 if (isShift) {
384 flags |= MK_SHIFT;
385 }
386 sendMessage(hwnd, message, flags, makeLParam(x, y).intValue());
387 }
388
389
390
391
392
393
394
395
396
397 public final void move(final long hwnd, final int x, final int y,
398 final int width, final int height) {
399 moveTo(hwnd, x, y);
400 sizeTo(hwnd, width, height);
401 }
402
403
404
405
406
407
408
409 public final void moveTo(final long hwnd, final int x, final int y) {
410 HWND handle = longToHwnd(hwnd);
411 RECT rc = getRect(hwnd);
412 getUser32().MoveWindow(
413 handle,
414 x,
415 y,
416 rc.right - rc.left,
417 rc.bottom - rc.top,
418 true);
419 }
420
421
422
423
424
425 public final void restore(final long hwnd) {
426 HWND handle = longToHwnd(hwnd);
427 getUser32().ShowWindow(handle, SW_SHOWNORMAL);
428 }
429
430
431
432
433
434
435
436 public final void sizeTo(
437 final long hwnd,
438 final int width,
439 final int height) {
440 HWND handle = longToHwnd(hwnd);
441 RECT rc = getRect(hwnd);
442 getUser32().MoveWindow(handle, rc.left, rc.top, width, height, true);
443 }
444
445
446
447
448
449
450
451
452 public final void start(
453 final long hwnd,
454 final String command,
455 final String params,
456 final String workingDir) {
457 HWND handle = longToHwnd(hwnd);
458 getShell32().ShellExecute(
459 handle,
460 null,
461 command,
462 params,
463 workingDir,
464 SW_SHOW);
465 }
466 }