source: trunk/src/user32/window.cpp@ 2881

Last change on this file since 2881 was 2881, checked in by sandervl, 26 years ago

WS_MAXIMIZE & WS_MINIMIZE flags updated when necessary & RedrawWindow changes

File size: 52.7 KB
Line 
1/* $Id: window.cpp,v 1.57 2000-02-24 19:19:10 sandervl Exp $ */
2/*
3 * Win32 window apis for OS/2
4 *
5 * Copyright 1999 Sander van Leeuwen
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 * Copyright 2000 Christoph Bratschi (cbratschi@datacomm.ch)
8 *
9 * Parts based on Wine Windows code (windows\win.c)
10 *
11 * Copyright 1993, 1994 Alexandre Julliard
12 *
13 * Project Odin Software License can be found in LICENSE.TXT
14 *
15 *
16 * TODO: Decide what to do about commands for OS/2 windows (non-Win32 apps)
17 *
18 */
19
20#include <os2win.h>
21#include <misc.h>
22#include <string.h>
23#include <stdio.h>
24#include <win32wbase.h>
25#include <win32wmdiclient.h>
26#include <win32wdesktop.h>
27#include "win32dlg.h"
28#include <oslibwin.h>
29#include <oslibgdi.h>
30#include "user32.h"
31#include "winicon.h"
32#include <win\winpos.h>
33
34#define DBG_LOCALLOG DBG_window
35#include "dbglocal.h"
36
37//******************************************************************************
38//******************************************************************************
39HWND WIN32API CreateWindowExA(DWORD exStyle, LPCSTR className,
40 LPCSTR windowName, DWORD style, INT x,
41 INT y, INT width, INT height,
42 HWND parent, HMENU menu,
43 HINSTANCE instance, LPVOID data )
44{
45 Win32BaseWindow *window;
46 ATOM classAtom;
47 CREATESTRUCTA cs;
48 char tmpClass[20];
49
50 if(exStyle & WS_EX_MDICHILD)
51 return CreateMDIWindowA(className, windowName, style, x, y, width, height, parent, instance, (LPARAM)data);
52
53#if 1
54 /* Find the class atom */
55 if (!(classAtom = GlobalFindAtomA(className)))
56 {
57 if (!HIWORD(className))
58 dprintf(("CreateWindowEx32A: bad class name %04x\n",LOWORD(className)));
59 else
60 dprintf(("CreateWindowEx32A: bad class name '%s'\n", className));
61
62 SetLastError(ERROR_INVALID_PARAMETER);
63 return 0;
64 }
65
66 if (!HIWORD(className))
67 {
68 sprintf(tmpClass,"#%d", (int) className);
69 className = tmpClass;
70 }
71#else
72 /* Find the class atom */
73 if (!HIWORD(className) || !(classAtom = GlobalFindAtomA(className)))
74 {
75 if (!HIWORD(className))
76 {
77 sprintf(tmpClass,"#%d", (int) className);
78 classAtom = GlobalFindAtomA(tmpClass);
79 className = tmpClass;
80 }
81 if (!classAtom)
82 {
83 if (!HIWORD(className)) {
84 dprintf(("CreateWindowEx32A: bad class name %04x\n", LOWORD(className)));
85 }
86 else dprintf(("CreateWindowEx32A: bad class name '%s'\n", className ));
87
88 SetLastError(ERROR_INVALID_PARAMETER);
89 return 0;
90 }
91 }
92#endif
93
94 /* Create the window */
95 cs.lpCreateParams = data;
96 cs.hInstance = instance;
97 cs.hMenu = menu;
98 cs.hwndParent = parent;
99 cs.x = x;
100 cs.y = y;
101 cs.cx = width;
102 cs.cy = height;
103 cs.style = style;
104 cs.lpszName = windowName;
105 cs.lpszClass = className;
106 cs.dwExStyle = exStyle;
107 if(HIWORD(className)) {
108 dprintf(("CreateWindowExA: class %s parent %x (%d,%d) (%d,%d), %x %x", className, parent, x, y, width, height, style, exStyle));
109 }
110 else dprintf(("CreateWindowExA: class %d parent %x (%d,%d) (%d,%d), %x %x", className, parent, x, y, width, height, style, exStyle));
111
112 if(!strcmpi(className, MDICLIENTCLASSNAMEA)) {
113 window = (Win32BaseWindow *) new Win32MDIClientWindow(&cs, classAtom, FALSE);
114 }
115 else
116 if(!strcmpi((char *) className, DIALOG_CLASS_NAMEA))
117 {
118 DLG_TEMPLATE dlgTemplate = {0};
119 dlgTemplate.style = cs.style;
120 dlgTemplate.exStyle = cs.dwExStyle;
121 dlgTemplate.x = cs.x;
122 dlgTemplate.y = cs.y;
123 dlgTemplate.cx = cs.cx;
124 dlgTemplate.cy = cs.cy;
125 dlgTemplate.className = cs.lpszClass;
126 dlgTemplate.caption = cs.lpszName;
127 window = (Win32BaseWindow *) new Win32Dialog(cs.hInstance,
128 (LPCSTR) &dlgTemplate,
129 cs.hwndParent,
130 NULL,
131 (LPARAM) data,
132 FALSE);
133 }
134 else {
135 window = new Win32BaseWindow( &cs, classAtom, FALSE );
136 }
137 if(window == NULL)
138 {
139 dprintf(("Win32BaseWindow creation failed!!"));
140 return 0;
141 }
142 if(GetLastError() != 0)
143 {
144 dprintf(("Win32BaseWindow error found!!"));
145 delete window;
146 return 0;
147 }
148 return window->getWindowHandle();
149}
150//******************************************************************************
151//******************************************************************************
152HWND WIN32API CreateWindowExW(DWORD exStyle, LPCWSTR className,
153 LPCWSTR windowName, DWORD style, INT x,
154 INT y, INT width, INT height,
155 HWND parent, HMENU menu,
156 HINSTANCE instance, LPVOID data )
157{
158 Win32BaseWindow *window;
159 ATOM classAtom;
160 CREATESTRUCTA cs;
161 char tmpClassA[20];
162 WCHAR tmpClassW[20];
163
164 if(exStyle & WS_EX_MDICHILD)
165 return CreateMDIWindowW(className, windowName, style, x, y, width, height, parent, instance, (LPARAM)data);
166
167 /* Find the class atom */
168 if (!HIWORD(className) || !(classAtom = GlobalFindAtomW(className)))
169 {
170 if (!HIWORD(className))
171 {
172 sprintf(tmpClassA,"#%d", (int) className);
173 AsciiToUnicode(tmpClassA, tmpClassW);
174 classAtom = GlobalFindAtomW(tmpClassW);
175 className = (LPCWSTR)tmpClassW;
176 }
177 if (!classAtom)
178 {
179 if (!HIWORD(className)) {
180 dprintf(("CreateWindowEx32W: bad class name %04x\n", LOWORD(className)));
181 }
182 else dprintf(("CreateWindowEx32W: bad class name "));
183
184 SetLastError(ERROR_INVALID_PARAMETER);
185 return 0;
186 }
187 }
188 if(HIWORD(className)) {
189 dprintf(("CreateWindowExW: class %s parent %x (%d,%d) (%d,%d), %x %x", className, parent, x, y, width, height, style, exStyle));
190 }
191 else dprintf(("CreateWindowExW: class %d parent %x (%d,%d) (%d,%d), %x %x", className, parent, x, y, width, height, style, exStyle));
192
193 /* Create the window */
194 cs.lpCreateParams = data;
195 cs.hInstance = instance;
196 cs.hMenu = menu;
197 cs.hwndParent = parent;
198 cs.x = x;
199 cs.y = y;
200 cs.cx = width;
201 cs.cy = height;
202 cs.style = style;
203 cs.lpszName = (LPSTR)windowName;
204 cs.lpszClass = (LPSTR)className;
205 cs.dwExStyle = exStyle;
206
207 if(!lstrcmpiW(className, (LPWSTR)MDICLIENTCLASSNAMEW)) {
208 window = (Win32BaseWindow *) new Win32MDIClientWindow(&cs, classAtom, TRUE);
209 }
210 else
211 if(!lstrcmpiW(className, (LPWSTR)DIALOG_CLASS_NAMEW))
212 {
213 DLG_TEMPLATE dlgTemplate = {0};
214 dlgTemplate.style = cs.style;
215 dlgTemplate.exStyle = cs.dwExStyle;
216 dlgTemplate.x = cs.x;
217 dlgTemplate.y = cs.y;
218 dlgTemplate.cx = cs.cx;
219 dlgTemplate.cy = cs.cy;
220 dlgTemplate.className = cs.lpszClass;
221 dlgTemplate.caption = cs.lpszName;
222 window = (Win32BaseWindow *) new Win32Dialog(cs.hInstance,
223 (LPCSTR) &dlgTemplate,
224 cs.hwndParent,
225 NULL,
226 (LPARAM) data,
227 TRUE);
228 }
229 else {
230 window = new Win32BaseWindow( &cs, classAtom, TRUE );
231 }
232 if(window == NULL)
233 {
234 dprintf(("Win32BaseWindow creation failed!!"));
235 return 0;
236 }
237 if(GetLastError() != 0)
238 {
239 dprintf(("Win32BaseWindow error found!!"));
240 delete window;
241 return 0;
242 }
243 return window->getWindowHandle();
244}
245//******************************************************************************
246//******************************************************************************
247HWND WIN32API CreateMDIWindowA(LPCSTR lpszClassName, LPCSTR lpszWindowName,
248 DWORD dwStyle, int x, int y, int nWidth,
249 int nHeight, HWND hwndParent,
250 HINSTANCE hInstance, LPARAM lParam )
251{
252 HWND hwnd;
253 MDICREATESTRUCTA cs;
254 Win32BaseWindow *window;
255
256 window = Win32BaseWindow::GetWindowFromHandle(hwndParent);
257 if(!window) {
258 dprintf(("CreateMDIWindowA, window %x not found", hwndParent));
259 return 0;
260 }
261
262 dprintf(("USER32: CreateMDIWindowA\n"));
263 cs.szClass = lpszClassName;
264 cs.szTitle = lpszWindowName;
265 cs.hOwner = hInstance;
266 cs.x = x;
267 cs.y = y;
268 cs.cx = nHeight;
269 cs.cy = nWidth;
270 cs.style = dwStyle;
271 cs.lParam = lParam;
272
273 return window->SendMessageA(WM_MDICREATE, 0, (LPARAM)&cs);
274}
275//******************************************************************************
276//******************************************************************************
277HWND WIN32API CreateMDIWindowW(LPCWSTR lpszClassName, LPCWSTR lpszWindowName,
278 DWORD dwStyle, int x, int y, int nWidth,
279 int nHeight, HWND hwndParent,
280 HINSTANCE hInstance, LPARAM lParam )
281{
282 HWND hwnd;
283 MDICREATESTRUCTW cs;
284 Win32BaseWindow *window;
285
286 window = Win32BaseWindow::GetWindowFromHandle(hwndParent);
287 if(!window) {
288 dprintf(("CreateMDIWindowW, window %x not found", hwndParent));
289 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
290 return 0;
291 }
292
293 dprintf(("USER32: CreateMDIWindowW\n"));
294 cs.szClass = lpszClassName;
295 cs.szTitle = lpszWindowName;
296 cs.hOwner = hInstance;
297 cs.x = x;
298 cs.y = y;
299 cs.cx = nHeight;
300 cs.cy = nWidth;
301 cs.style = dwStyle;
302 cs.lParam = lParam;
303
304 return window->SendMessageW(WM_MDICREATE, 0, (LPARAM)&cs);
305}
306//******************************************************************************
307//******************************************************************************
308BOOL WIN32API DestroyWindow(HWND hwnd)
309{
310 Win32BaseWindow *window;
311
312 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
313 if(!window) {
314 dprintf(("DestroyWindow, window %x not found", hwnd));
315 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
316 return 0;
317 }
318 dprintf(("DestroyWindow %x", hwnd));
319 return window->DestroyWindow();
320}
321//******************************************************************************
322//******************************************************************************
323HWND WIN32API SetActiveWindow( HWND hwnd)
324{
325 Win32BaseWindow *window;
326
327 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
328 if(!window) {
329 dprintf(("SetActiveWindow, window %x not found", hwnd));
330 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
331 return 0;
332 }
333 return window->SetActiveWindow();
334}
335//******************************************************************************
336//******************************************************************************
337HWND WIN32API GetParent( HWND hwnd)
338{
339 Win32BaseWindow *window;
340
341 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
342 if(!window) {
343 dprintf(("GetParent, window %x not found", hwnd));
344 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
345 return 0;
346 }
347// dprintf(("GetParent %x", hwnd));
348 return window->GetParent();
349}
350//******************************************************************************
351//******************************************************************************
352HWND WIN32API SetParent( HWND hwndChild, HWND hwndNewParent)
353{
354 Win32BaseWindow *window;
355
356 window = Win32BaseWindow::GetWindowFromHandle(hwndChild);
357 if(!window) {
358 dprintf(("SetParent, window %x not found", hwndChild));
359 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
360 return 0;
361 }
362 dprintf(("SetParent %x %x", hwndChild, hwndNewParent));
363 return window->SetParent(hwndNewParent);
364}
365//******************************************************************************
366//******************************************************************************
367BOOL WIN32API IsChild( HWND hwndParent, HWND hwnd)
368{
369 Win32BaseWindow *window;
370
371 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
372 if(!window) {
373 dprintf(("IsChild, window %x not found", hwnd));
374 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
375 return 0;
376 }
377 dprintf(("IsChild %x %x", hwndParent, hwnd));
378 return window->IsChild(hwndParent);
379}
380//******************************************************************************
381//******************************************************************************
382HWND WIN32API GetTopWindow( HWND hwnd)
383{
384 Win32BaseWindow *window;
385
386 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
387 if(!window) {
388 dprintf(("GetTopWindow, window %x not found", hwnd));
389 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
390 return 0;
391 }
392 return window->GetTopWindow();
393}
394//******************************************************************************
395//******************************************************************************
396BOOL WIN32API IsIconic( HWND hwnd)
397{
398 Win32BaseWindow *window;
399 BOOL rc;
400
401 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
402 if(!window) {
403 dprintf(("IsIconic, window %x not found", hwnd));
404 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
405 return FALSE;
406 }
407 rc = window->IsWindowIconic();
408 dprintf(("IsIconic %x returned %d", hwnd, rc));
409 return rc;
410}
411//******************************************************************************
412//******************************************************************************
413HWND WIN32API GetWindow(HWND hwnd, UINT uCmd)
414{
415 Win32BaseWindow *window;
416 HWND rc;
417
418 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
419 if(!window) {
420 dprintf(("GetWindow, window %x not found", hwnd));
421 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
422 return 0;
423 }
424 rc = window->GetWindow(uCmd);
425 return rc;
426}
427//******************************************************************************
428//******************************************************************************
429BOOL WIN32API EnableWindow( HWND hwnd, BOOL fEnable)
430{
431 Win32BaseWindow *window;
432
433 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
434 if(!window) {
435 dprintf(("EnableWindow, window %x not found", hwnd));
436 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
437 return 0;
438 }
439 dprintf(("EnableWindow %x %d", hwnd, fEnable));
440 return window->EnableWindow(fEnable);
441}
442//******************************************************************************
443//******************************************************************************
444BOOL WIN32API BringWindowToTop(HWND hwnd)
445{
446 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
447}
448//******************************************************************************
449//******************************************************************************
450HWND WIN32API GetActiveWindow()
451{
452 return Win32BaseWindow::GetActiveWindow();
453}
454//******************************************************************************
455//******************************************************************************
456BOOL WIN32API ShowWindow(HWND hwnd, int nCmdShow)
457{
458 Win32BaseWindow *window;
459
460 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
461 if(!window) {
462 dprintf(("ShowWindow, window %x not found", hwnd));
463 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
464 return 0;
465 }
466 dprintf(("ShowWindow %x", hwnd));
467 return window->ShowWindow(nCmdShow);
468}
469/*****************************************************************************
470 * Name : BOOL WIN32API ShowWindowAsync
471 * Purpose : The ShowWindowAsync function sets the show state of a window
472 * created by a different thread.
473 * Parameters: HWND hwnd handle of window
474 * int nCmdShow show state of window
475 * Variables :
476 * Result : If the window was previously visible, the return value is TRUE.
477 * If the window was previously hidden, the return value is FALSE.
478 * Remark :
479 * Status : UNTESTED STUB
480 *
481 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
482 *****************************************************************************/
483BOOL WIN32API ShowWindowAsync (HWND hwnd,
484 int nCmdShow)
485{
486 dprintf(("USER32:ShowWindowAsync (%08xh,%08x) not correctly implemented.\n",
487 hwnd,
488 nCmdShow));
489
490 return ShowWindow(hwnd, nCmdShow);
491}
492//******************************************************************************
493//******************************************************************************
494BOOL WIN32API SetWindowPos(HWND hwnd, HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
495{
496 Win32BaseWindow *window;
497
498 if (!hwnd)
499 {
500 dprintf(("SetWindowPos: Can't move desktop!"));
501 return TRUE;
502 }
503 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
504 if(!window) {
505 dprintf(("SetWindowPos, window %x not found", hwnd));
506 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
507 return FALSE;
508 }
509 dprintf(("SetWindowPos %x %x x=%d y=%d cx=%d cy=%d %x", hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
510 return window->SetWindowPos(hwndInsertAfter, x, y, cx, cy, fuFlags);
511}
512//******************************************************************************
513//******************************************************************************
514BOOL WIN32API SetWindowPlacement(HWND hwnd, const WINDOWPLACEMENT *winpos)
515{
516 Win32BaseWindow *window;
517
518 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
519 if(!window) {
520 dprintf(("SetWindowPlacement, window %x not found", hwnd));
521 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
522 return 0;
523 }
524 return window->SetWindowPlacement((WINDOWPLACEMENT *)winpos);
525}
526//******************************************************************************
527//******************************************************************************
528BOOL WIN32API GetWindowPlacement(HWND hwnd, LPWINDOWPLACEMENT arg2)
529{
530 dprintf(("USER32: GetWindowPlacement\n"));
531 return O32_GetWindowPlacement(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd), arg2);
532}
533//******************************************************************************
534//******************************************************************************
535BOOL WIN32API IsWindow( HWND hwnd)
536{
537 Win32BaseWindow *window;
538
539 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
540 if(!window) {
541 dprintf(("IsWindow, window %x not found", hwnd));
542 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
543 return FALSE;
544 }
545 dprintf(("IsWindow %x", hwnd));
546 return window->IsWindow();
547}
548//******************************************************************************
549//******************************************************************************
550BOOL WIN32API IsWindowEnabled( HWND hwnd)
551{
552 Win32BaseWindow *window;
553
554 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
555 if(!window) {
556 dprintf(("IsWindowEnabled, window %x not found", hwnd));
557 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
558 return 0;
559 }
560 dprintf(("IsWindowEnabled %x", hwnd));
561 return window->IsWindowEnabled();
562}
563//******************************************************************************
564//******************************************************************************
565BOOL WIN32API IsWindowVisible( HWND hwnd)
566{
567 Win32BaseWindow *window;
568 BOOL rc;
569
570 if (hwnd)
571 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
572 else
573 window = windowDesktop;
574 if(!window) {
575 dprintf(("IsWindowVisible, window %x not found", hwnd));
576 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
577 return 0;
578 }
579 rc = window->IsWindowVisible();
580 dprintf(("IsWindowVisible %x returned %d", hwnd, rc));
581 return rc;
582}
583//******************************************************************************
584//******************************************************************************
585HWND WIN32API SetFocus (HWND hwnd)
586{
587 HWND lastFocus, lastFocus_W, hwnd_O;
588 BOOL activate;
589
590 hwnd_O = Win32BaseWindow::Win32ToOS2Handle (hwnd);
591 lastFocus = OSLibWinQueryFocus (OSLIB_HWND_DESKTOP);
592 activate = ((hwnd_O == lastFocus) || OSLibWinIsChild (lastFocus, hwnd_O));
593 lastFocus_W = Win32BaseWindow::OS2ToWin32Handle (lastFocus);
594
595 dprintf(("SetFocus %x (%x) -> %x (%x)\n", lastFocus_W, lastFocus, hwnd, hwnd_O));
596
597 return (OSLibWinSetFocus (OSLIB_HWND_DESKTOP, hwnd_O, activate)) ? lastFocus_W : 0;
598}
599//******************************************************************************
600//******************************************************************************
601HWND WIN32API GetFocus(void)
602{
603 HWND hwnd;
604
605 hwnd = OSLibWinQueryFocus(OSLIB_HWND_DESKTOP);
606 dprintf(("USER32: GetFocus %x\n", hwnd));
607 hwnd = Win32BaseWindow::OS2ToWin32Handle(hwnd);
608 return hwnd;
609}
610//******************************************************************************
611//******************************************************************************
612/***********************************************************************
613 * GetInternalWindowPos (USER32.245)
614 */
615UINT WIN32API GetInternalWindowPos(HWND hwnd,
616 LPRECT rectWnd,
617 LPPOINT ptIcon )
618{
619 WINDOWPLACEMENT wndpl;
620
621 dprintf(("USER32: GetInternalWindowPos(%08xh,%08xh,%08xh)\n",
622 hwnd,
623 rectWnd,
624 ptIcon));
625
626 if (GetWindowPlacement( hwnd, &wndpl ))
627 {
628 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
629 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
630 return wndpl.showCmd;
631 }
632 return 0;
633}
634//******************************************************************************
635//******************************************************************************
636BOOL WIN32API IsZoomed(HWND hwnd)
637{
638 dprintf(("USER32: IsZoomed\n"));
639 return O32_IsZoomed(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd));
640}
641//******************************************************************************
642//******************************************************************************
643BOOL WIN32API LockWindowUpdate(HWND hwnd)
644{
645 dprintf(("USER32: LockWindowUpdate\n"));
646 return O32_LockWindowUpdate(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd));
647}
648//******************************************************************************
649//******************************************************************************
650BOOL WIN32API GetWindowRect( HWND hwnd, PRECT pRect)
651{
652 Win32BaseWindow *window;
653
654 if (hwnd)
655 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
656 else
657 window = windowDesktop;
658
659
660 if(!window) {
661 dprintf(("GetWindowRect, window %x not found", hwnd));
662 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
663 return FALSE;
664 }
665 if(pRect == NULL) {
666 SetLastError(ERROR_INVALID_PARAMETER);
667 return FALSE;
668 }
669 *pRect = *window->getWindowRect(); //always in screen coordinates
670
671 if(hwnd == 0x68000034) {
672 window = 0;
673 }
674 dprintf(("GetWindowRect %x (%d,%d) (%d,%d)", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom));
675 return TRUE;
676}
677//******************************************************************************
678//******************************************************************************
679int WIN32API GetWindowTextLengthA( HWND hwnd)
680{
681 Win32BaseWindow *window;
682
683 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
684 if(!window) {
685 dprintf(("GetWindowTextLength, window %x not found", hwnd));
686 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
687 return 0;
688 }
689 dprintf(("GetWindowTextLength %x", hwnd));
690 return window->GetWindowTextLength();
691}
692//******************************************************************************
693//******************************************************************************
694int WIN32API GetWindowTextA( HWND hwnd, LPSTR lpsz, int cch)
695{
696 Win32BaseWindow *window;
697 int rc;
698
699 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
700 if(!window) {
701 dprintf(("GetWindowTextA, window %x not found", hwnd));
702 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
703 return 0;
704 }
705 rc = window->GetWindowTextA(lpsz, cch);
706 dprintf(("GetWindowTextA %x %s", hwnd, lpsz));
707 return rc;
708}
709//******************************************************************************
710//******************************************************************************
711int WIN32API GetWindowTextLengthW( HWND hwnd)
712{
713 dprintf(("USER32: GetWindowTextLengthW\n"));
714 return GetWindowTextLengthA(hwnd);
715}
716//******************************************************************************
717//******************************************************************************
718int WIN32API GetWindowTextW(HWND hwnd, LPWSTR lpsz, int cch)
719{
720 Win32BaseWindow *window;
721
722 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
723 if(!window) {
724 dprintf(("GetWindowTextW, window %x not found", hwnd));
725 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
726 return 0;
727 }
728 dprintf(("GetWindowTextW %x", hwnd));
729 return window->GetWindowTextW(lpsz, cch);
730}
731//******************************************************************************
732//******************************************************************************
733BOOL WIN32API SetWindowTextA(HWND hwnd, LPCSTR lpsz)
734{
735 Win32BaseWindow *window;
736
737 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
738 if(!window) {
739 dprintf(("SetWindowTextA, window %x not found", hwnd));
740 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
741 return 0;
742 }
743 dprintf(("SetWindowTextA %x %s", hwnd, lpsz));
744 return window->SetWindowTextA((LPSTR)lpsz);
745}
746//******************************************************************************
747//******************************************************************************
748BOOL WIN32API SetWindowTextW( HWND hwnd, LPCWSTR lpsz)
749{
750 Win32BaseWindow *window;
751
752 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
753 if(!window) {
754 dprintf(("SetWindowTextA, window %x not found", hwnd));
755 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
756 return 0;
757 }
758 dprintf(("SetWindowTextW %x", hwnd));
759 return window->SetWindowTextW((LPWSTR)lpsz);
760}
761/*******************************************************************
762 * InternalGetWindowText (USER32.326)
763 */
764int WIN32API InternalGetWindowText(HWND hwnd,
765 LPWSTR lpString,
766 INT nMaxCount )
767{
768 dprintf(("USER32: InternalGetWindowText(%08xh,%08xh,%08xh) not properly implemented.\n",
769 hwnd,
770 lpString,
771 nMaxCount));
772
773 return GetWindowTextW(hwnd,lpString,nMaxCount);
774}
775//******************************************************************************
776//TODO: Correct?
777//******************************************************************************
778BOOL WIN32API SetForegroundWindow(HWND hwnd)
779{
780 dprintf((" SetForegroundWindow %x", hwnd));
781
782 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER );
783}
784//******************************************************************************
785//******************************************************************************
786BOOL WIN32API GetClientRect( HWND hwnd, PRECT pRect)
787{
788 HWND hwndWin32 = hwnd;
789 Win32BaseWindow *window;
790
791 if (!pRect)
792 {
793 SetLastError(ERROR_INVALID_PARAMETER);
794 return FALSE;
795 }
796 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
797 if(!window) {
798 dprintf(("GetClientRect, window %x not found", hwnd));
799 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
800 return FALSE;
801 }
802 window->getClientRect(pRect);
803 dprintf(("GetClientRect of %X returned (%d,%d) (%d,%d)\n", hwndWin32, pRect->left, pRect->top, pRect->right, pRect->bottom));
804 return TRUE;
805}
806//******************************************************************************
807//******************************************************************************
808BOOL WIN32API AdjustWindowRect(PRECT rect, DWORD style, BOOL menu)
809{
810 return AdjustWindowRectEx(rect, style, menu, 0);
811}
812//******************************************************************************
813//******************************************************************************
814BOOL WIN32API AdjustWindowRectEx( PRECT rect, DWORD style, BOOL menu, DWORD exStyle)
815{
816 dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d)\n", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
817
818 /* Correct the window style */
819 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
820 style |= WS_CAPTION;
821
822 style &= (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME | WS_CHILD | WS_VSCROLL | WS_HSCROLL);
823 exStyle &= (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE |
824 WS_EX_STATICEDGE | WS_EX_TOOLWINDOW);
825 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
826
827 //Adjust rect outer (Win32BaseWindow::AdjustRectOuter)
828 if (HAS_THICKFRAME(style,exStyle))
829 InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
830 else
831 if (HAS_DLGFRAME(style,exStyle))
832 InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
833 else
834 if (HAS_THINFRAME(style))
835 InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
836
837 if ((style & WS_CAPTION) == WS_CAPTION)
838 {
839 if (exStyle & WS_EX_TOOLWINDOW)
840 rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
841 else
842 rect->top -= GetSystemMetrics(SM_CYCAPTION);
843 }
844
845 if (menu)
846 rect->top -= GetSystemMetrics(SM_CYMENU);
847
848 //Adjust rect inner (Win32BaseWindow::AdjustRectInner)
849 if (exStyle & WS_EX_CLIENTEDGE)
850 InflateRect (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
851
852 if (exStyle & WS_EX_STATICEDGE)
853 InflateRect (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
854
855 if (style & WS_VSCROLL) rect->right += GetSystemMetrics(SM_CXVSCROLL);
856 if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
857
858 dprintf(("AdjustWindowRectEx returned (%d,%d)(%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom));
859
860 return TRUE;
861}
862//******************************************************************************
863/* Coordinate Space and Transformation Functions */
864//******************************************************************************
865int WIN32API MapWindowPoints(HWND hwndFrom, HWND hwndTo, LPPOINT lpPoints,
866 UINT cPoints)
867{
868 Win32BaseWindow *wndfrom, *wndto;
869 int retval = 0;
870 OSLIBPOINT point;
871
872 if(lpPoints == NULL || cPoints == 0) {
873 SetLastError(ERROR_INVALID_PARAMETER);
874 return 0;
875 }
876 if(hwndFrom)
877 {
878 wndfrom = Win32BaseWindow::GetWindowFromHandle(hwndFrom);
879 if(!wndfrom) {
880 dprintf(("MapWindowPoints, window %x not found", hwndFrom));
881 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
882 return 0;
883 }
884 }
885 else wndfrom = windowDesktop;
886
887 if(hwndTo)
888 {
889 wndto = Win32BaseWindow::GetWindowFromHandle(hwndTo);
890 if(!wndto) {
891 dprintf(("MapWindowPoints, window %x not found", hwndTo));
892 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
893 return 0;
894 }
895 }
896 else wndto = windowDesktop;
897
898 if(wndto == wndfrom)
899 return 0; //nothing to do
900
901 dprintf(("USER32: MapWindowPoints %x to %x (%d,%d) (%d)", hwndFrom, hwndTo, lpPoints->x, lpPoints->y, cPoints));
902 point.x = lpPoints->x;
903 point.y = lpPoints->y;
904 if (!mapWin32Point(wndfrom,wndto,&point))
905 {
906 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
907 return 0;
908 }
909
910 short int xinc = point.x - lpPoints->x;
911 short int yinc = point.y - lpPoints->y;
912
913 for(int i=0;i<cPoints;i++)
914 {
915 lpPoints[i].x += xinc;
916 lpPoints[i].y += yinc;
917 }
918 retval = ((LONG)yinc << 16) | xinc;
919 return retval;
920}
921//******************************************************************************
922//******************************************************************************
923BOOL WIN32API ScreenToClient (HWND hwnd, LPPOINT pt)
924{
925 Win32BaseWindow *wnd;
926 PRECT rcl;
927 BOOL rc;
928
929 if (!hwnd) return (TRUE);
930 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
931 if (!wnd) {
932 dprintf(("warning: ScreenToClient: window %x not found!", hwnd));
933 return (TRUE);
934 }
935#ifdef DEBUG
936 POINT tmp = *pt;
937#endif
938 rc = mapWin32Point(OSLIB_HWND_DESKTOP, wnd->getOS2WindowHandle(), (OSLIBPOINT*)pt);
939 dprintf(("ScreenToClient %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
940 return rc;
941}
942//******************************************************************************
943//******************************************************************************
944HWND WIN32API GetDesktopWindow(void)
945{
946 HWND DesktopWindow = windowDesktop->getWindowHandle();
947 dprintf2(("USER32: GetDesktopWindow, returned %d\n", DesktopWindow));
948 return DesktopWindow;
949}
950//******************************************************************************
951//******************************************************************************
952HWND WIN32API FindWindowA(LPCSTR lpszClass, LPCSTR lpszWindow)
953{
954 if(!lpszClass) {
955 SetLastError(ERROR_INVALID_PARAMETER);
956 return 0;
957 }
958 if(HIWORD(lpszClass)) {
959 dprintf(("USER32: FindWindow %s %s\n", lpszClass, lpszWindow));
960 }
961 else dprintf(("USER32: FindWindow %x %s\n", lpszClass, lpszWindow));
962
963 return Win32BaseWindow::FindWindowEx(OSLIB_HWND_DESKTOP, 0, (LPSTR)lpszClass, (LPSTR)lpszWindow);
964}
965//******************************************************************************
966//******************************************************************************
967HWND WIN32API FindWindowW( LPCWSTR lpClassName, LPCWSTR lpWindowName)
968{
969 char *astring1 = UnicodeToAsciiString((LPWSTR)lpClassName);
970 char *astring2 = UnicodeToAsciiString((LPWSTR)lpWindowName);
971 HWND rc;
972
973 rc = FindWindowA(astring1, astring2);
974 FreeAsciiString(astring1);
975 FreeAsciiString(astring2);
976 return rc;
977}
978//******************************************************************************
979//******************************************************************************
980HWND WIN32API FindWindowExA(HWND hwndParent, HWND hwndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow)
981{
982 if(!lpszClass) {
983 SetLastError(ERROR_INVALID_PARAMETER);
984 return 0;
985 }
986 if(HIWORD(lpszClass)) {
987 dprintf(("USER32: FindWindowExA (%x,%x) %s %s\n", hwndParent, hwndChildAfter, lpszClass, lpszWindow));
988 }
989 else dprintf(("USER32: FindWindowExA (%x,%x)%x %s\n", hwndParent, hwndChildAfter, lpszClass, lpszWindow));
990
991 return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, (LPSTR)lpszClass, (LPSTR)lpszWindow);
992}
993/*****************************************************************************
994 * Name : HWND WIN32API FindWindowExW
995 * Purpose : The FindWindowEx function retrieves the handle of a window whose
996 * class name and window name match the specified strings. The
997 * function searches child windows, beginning with the one following
998 * the given child window.
999 * Parameters: HWND hwndParent handle of parent window
1000 * HWND hwndChildAfter handle of a child window
1001 * LPCTSTR lpszClass address of class name
1002 * LPCTSTR lpszWindow address of window name
1003 * Variables :
1004 * Result : If the function succeeds, the return value is the handle of the
1005 * window that has the specified class and window names.
1006 * If the function fails, the return value is NULL. To get extended
1007 * error information, call GetLastError.
1008 * Remark :
1009 * Status : UNTESTED STUB
1010 *
1011 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1012 *****************************************************************************/
1013
1014HWND WIN32API FindWindowExW(HWND hwndParent,
1015 HWND hwndChildAfter,
1016 LPCWSTR lpszClass,
1017 LPCWSTR lpszWindow)
1018{
1019 if(!lpszClass) {
1020 SetLastError(ERROR_INVALID_PARAMETER);
1021 return 0;
1022 }
1023 dprintf(("USER32: FindWindowExW (%x,%x) %x %s\n", hwndParent, hwndChildAfter, lpszClass, lpszWindow));
1024
1025 return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, (LPSTR)lpszClass, (LPSTR)lpszWindow);
1026}
1027//******************************************************************************
1028//******************************************************************************
1029BOOL WIN32API FlashWindow(HWND hwnd, BOOL fFlash)
1030{
1031 dprintf(("FlashWindow %x %d\n", hwnd, fFlash));
1032 return OSLibWinFlashWindow(Win32BaseWindow::Win32ToOS2Handle(hwnd), fFlash);
1033}
1034//******************************************************************************
1035//******************************************************************************
1036BOOL WIN32API MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
1037 BOOL repaint )
1038{
1039 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
1040
1041 if (!repaint) flags |= SWP_NOREDRAW;
1042 dprintf(("MoveWindow: %x %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint ));
1043
1044 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
1045}
1046//******************************************************************************
1047//******************************************************************************
1048BOOL WIN32API ClientToScreen (HWND hwnd, PPOINT pt)
1049{
1050 Win32BaseWindow *wnd;
1051 PRECT rcl;
1052 BOOL rc;
1053
1054 if (!hwnd) {
1055 SetLastError(ERROR_INVALID_PARAMETER);
1056 return (FALSE);
1057 }
1058 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1059 if (!wnd) {
1060 dprintf(("warning: ClientToScreen window %x not found!", hwnd));
1061 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1062 return (FALSE);
1063 }
1064#ifdef DEBUG
1065 POINT tmp = *pt;
1066#endif
1067 rc = mapWin32Point(wnd->getOS2WindowHandle(),OSLIB_HWND_DESKTOP,(OSLIBPOINT*)pt);
1068 dprintf(("ClientToScreen %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
1069
1070 return rc;
1071}
1072//******************************************************************************
1073//******************************************************************************
1074HDWP WIN32API BeginDeferWindowPos(int count)
1075{
1076 HDWP handle;
1077 DWP *pDWP;
1078
1079 if (count <= 0)
1080 {
1081 dprintf(("USER32: BeginDeferWindowPos invalid param %d", count));
1082 SetLastError(ERROR_INVALID_PARAMETER);
1083 return 0;
1084 }
1085 dprintf(("USER32: BeginDeferWindowPos %d", count));
1086 handle = (HDWP)HeapAlloc(GetProcessHeap(), 0, sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
1087 if (!handle)
1088 return 0;
1089
1090 pDWP = (DWP *) handle;
1091 pDWP->actualCount = 0;
1092 pDWP->suggestedCount = count;
1093 pDWP->valid = TRUE;
1094 pDWP->wMagic = DWP_MAGIC;
1095 pDWP->hwndParent = 0;
1096 return handle;
1097}
1098/***********************************************************************
1099 * DeferWindowPos (USER32.128)
1100 */
1101HDWP WIN32API DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1102 INT x, INT y, INT cx, INT cy,
1103 UINT flags )
1104{
1105 DWP *pDWP;
1106 int i;
1107 HDWP newhdwp = hdwp,retvalue;
1108 Win32BaseWindow *window;
1109
1110 pDWP = (DWP *)hdwp;
1111 if (!pDWP) {
1112 SetLastError(ERROR_INVALID_PARAMETER);
1113 return 0;
1114 }
1115
1116 if (hwnd == GetDesktopWindow())
1117 return 0;
1118
1119 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1120 if(!window) {
1121 dprintf(("DeferWindowPos, window %x not found", hwnd));
1122 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1123 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1124 return 0;
1125 }
1126
1127 dprintf(("USER32: DeferWindowPos hdwp %x hwnd %x hwndAfter %x (%d,%d)(%d,%d) %x", hdwp, hwnd, hwndAfter,
1128 x, y, cx, cy, flags));
1129
1130/* Numega Bounds Checker Demo dislikes the following code.
1131 In fact, I've not been able to find any "same parent" requirement in any docu
1132 [AM 980509]
1133 */
1134#if 0
1135 /* All the windows of a DeferWindowPos() must have the same parent */
1136 parent = pWnd->parent->hwndSelf;
1137 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
1138 else if (parent != pDWP->hwndParent)
1139 {
1140 USER_HEAP_FREE( hdwp );
1141 retvalue = 0;
1142 goto END;
1143 }
1144#endif
1145
1146 for (i = 0; i < pDWP->actualCount; i++)
1147 {
1148 if (pDWP->winPos[i].hwnd == hwnd)
1149 {
1150 /* Merge with the other changes */
1151 if (!(flags & SWP_NOZORDER))
1152 {
1153 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1154 }
1155 if (!(flags & SWP_NOMOVE))
1156 {
1157 pDWP->winPos[i].x = x;
1158 pDWP->winPos[i].y = y;
1159 }
1160 if (!(flags & SWP_NOSIZE))
1161 {
1162 pDWP->winPos[i].cx = cx;
1163 pDWP->winPos[i].cy = cy;
1164 }
1165 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1166 SWP_NOZORDER | SWP_NOREDRAW |
1167 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1168 SWP_NOOWNERZORDER);
1169 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1170 SWP_FRAMECHANGED);
1171 retvalue = hdwp;
1172 goto END;
1173 }
1174 }
1175 if (pDWP->actualCount >= pDWP->suggestedCount)
1176 {
1177 newhdwp = (HDWP)HeapReAlloc(GetProcessHeap(), 0, (LPVOID)hdwp,
1178 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS));
1179 if (!newhdwp)
1180 {
1181 retvalue = 0;
1182 goto END;
1183 }
1184 pDWP = (DWP *) newhdwp;
1185 pDWP->suggestedCount++;
1186 }
1187 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1188 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1189 pDWP->winPos[pDWP->actualCount].x = x;
1190 pDWP->winPos[pDWP->actualCount].y = y;
1191 pDWP->winPos[pDWP->actualCount].cx = cx;
1192 pDWP->winPos[pDWP->actualCount].cy = cy;
1193 pDWP->winPos[pDWP->actualCount].flags = flags;
1194 pDWP->actualCount++;
1195 retvalue = newhdwp;
1196END:
1197 return retvalue;
1198}
1199//******************************************************************************
1200//******************************************************************************
1201BOOL WIN32API EndDeferWindowPos( HDWP hdwp)
1202{
1203 DWP *pDWP;
1204 WINDOWPOS *winpos;
1205 BOOL res = TRUE;
1206 int i;
1207
1208 pDWP = (DWP *) hdwp;
1209 if (!pDWP) {
1210 dprintf(("**EndDeferWindowPos invalid parameter\n"));
1211 SetLastError(ERROR_INVALID_PARAMETER);
1212 return FALSE;
1213 }
1214 dprintf(("**EndDeferWindowPos for %d windows", pDWP->actualCount));
1215 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1216 {
1217 dprintf(("**EndDeferWindowPos %x (%d,%d) (%d,%d) %x", winpos->hwnd, winpos->x, winpos->y, winpos->x, winpos->cy, winpos->flags));
1218 if (!(res = SetWindowPos(winpos->hwnd, winpos->hwndInsertAfter,
1219 winpos->x, winpos->y, winpos->cx,
1220 winpos->cy, winpos->flags )))
1221 break;
1222 }
1223 dprintf(("**EndDeferWindowPos DONE"));
1224 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1225 return res;
1226}
1227//******************************************************************************
1228//******************************************************************************
1229HWND WIN32API ChildWindowFromPoint( HWND hwnd, POINT pt)
1230{
1231 dprintf(("USER32: ChildWindowFromPoint\n"));
1232 return ChildWindowFromPointEx(hwnd, pt, 0);
1233}
1234/*****************************************************************************
1235 * Name : HWND WIN32API ChildWindowFromPointEx
1236 * Purpose : pt: client coordinates
1237 * Parameters:
1238 * Variables :
1239 * Result : If the function succeeds, the return value is the window handle.
1240 * If the function fails, the return value is zero
1241 * Remark :
1242 * Status : FULLY IMPLEMENTED AND TESTED
1243 *
1244 * Author : Rene Pronk [Sun, 1999/08/08 23:30]
1245 *****************************************************************************/
1246HWND WIN32API ChildWindowFromPointEx (HWND hwndParent, POINT pt, UINT uFlags)
1247{
1248 RECT rect;
1249 HWND hWnd;
1250
1251 dprintf(("ChildWindowFromPointEx(%08xh,%08xh,%08xh).\n",
1252 hwndParent, pt, uFlags));
1253
1254 if (GetWindowRect (hwndParent, &rect) == 0) {
1255 // oops, invalid handle
1256 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1257 return NULL;
1258 }
1259
1260 ClientToScreen(hwndParent, &pt);
1261 if (PtInRect (&rect, pt) == 0) {
1262 // point is outside window
1263 return NULL;
1264 }
1265
1266
1267 // get first child
1268 hWnd = GetWindow (hwndParent, GW_CHILD);
1269
1270 while (hWnd != NULL) {
1271
1272 // do I need to skip this window?
1273 if (((uFlags & CWP_SKIPINVISIBLE) &&
1274 (IsWindowVisible (hWnd) == FALSE)) ||
1275 ((uFlags & CWP_SKIPDISABLED) &&
1276 (IsWindowEnabled (hWnd) == FALSE)) ||
1277 ((uFlags & CWP_SKIPTRANSPARENT) &&
1278 (GetWindowLongA (hWnd, GWL_EXSTYLE) & WS_EX_TRANSPARENT)))
1279
1280 {
1281 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1282 continue;
1283 }
1284
1285 // is the point in this window's rect?
1286 GetWindowRect (hWnd, &rect);
1287 if (PtInRect (&rect,pt) == FALSE) {
1288 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1289 continue;
1290 }
1291
1292 dprintf(("ChildWindowFromPointEx returned %x", hWnd));
1293 // found it!
1294 return hWnd;
1295 }
1296
1297 // the point is in the parentwindow but the parentwindow has no child
1298 // at this coordinate
1299 dprintf(("ChildWindowFromPointEx returned parent %x", hwndParent));
1300 return hwndParent;
1301}
1302//******************************************************************************
1303//******************************************************************************
1304BOOL WIN32API CloseWindow(HWND hwnd)
1305{
1306 Win32BaseWindow *window;
1307
1308 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1309 if(!window) {
1310 dprintf(("CloseWindow, window %x not found", hwnd));
1311 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1312 return 0;
1313 }
1314 dprintf(("CloseWindow %x\n", hwnd));
1315 return window->CloseWindow();
1316}
1317//******************************************************************************
1318//TODO: Does this return handles of hidden or disabled windows?
1319//******************************************************************************
1320HWND WIN32API WindowFromPoint( POINT point)
1321{
1322 HWND hwndOS2, hwnd;
1323 POINT wPoint;
1324
1325 wPoint.x = point.x;
1326 wPoint.y = mapScreenY(point.y);
1327
1328 hwndOS2 = OSLibWinWindowFromPoint(OSLIB_HWND_DESKTOP, (PVOID)&wPoint);
1329 if(hwndOS2)
1330 {
1331 hwnd = Win32BaseWindow::OS2ToWin32Handle(hwndOS2);
1332 if(hwnd) {
1333 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwnd));
1334 return hwnd;
1335 }
1336 }
1337 dprintf(("WindowFromPoint (%d,%d) %x->1\n", point.x, point.y, hwndOS2));
1338 return windowDesktop->getWindowHandle();
1339}
1340//******************************************************************************
1341//******************************************************************************
1342BOOL WIN32API IsWindowUnicode(HWND hwnd)
1343{
1344 Win32BaseWindow *window;
1345
1346 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1347 if(!window) {
1348 dprintf(("IsWindowUnicode, window %x not found", hwnd));
1349 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1350 return 0;
1351 }
1352 return window->IsWindowUnicode();
1353}
1354/***********************************************************************
1355 * SwitchToThisWindow (USER32.539)
1356 */
1357DWORD WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
1358{
1359 return ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
1360}
1361//******************************************************************************
1362//******************************************************************************
1363BOOL WIN32API EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
1364{
1365 return windowDesktop->EnumThreadWindows(dwThreadId, lpfn, lParam);
1366}
1367//******************************************************************************
1368//******************************************************************************
1369BOOL WIN32API EnumChildWindows(HWND hwnd, WNDENUMPROC lpfn, LPARAM lParam)
1370{
1371 Win32BaseWindow *window;
1372 BOOL rc = TRUE;
1373 ULONG henum;
1374 HWND hwndNext;
1375
1376 if(lpfn == NULL) {
1377 dprintf(("EnumChildWindows invalid parameter %x %x\n", hwnd, lParam));
1378 SetLastError(ERROR_INVALID_PARAMETER);
1379 return FALSE;
1380 }
1381 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1382 if(!window) {
1383 dprintf(("EnumChildWindows, window %x not found", hwnd));
1384 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1385 return FALSE;
1386 }
1387 return window->EnumChildWindows(lpfn, lParam);
1388}
1389//******************************************************************************
1390//******************************************************************************
1391BOOL WIN32API EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
1392{
1393 return windowDesktop->EnumWindows(lpfn, lParam);
1394}
1395//******************************************************************************
1396//******************************************************************************
1397UINT WIN32API ArrangeIconicWindows( HWND hwnd)
1398{
1399 dprintf(("USER32: ArrangeIconicWindows %x", hwnd));
1400 return O32_ArrangeIconicWindows(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd));
1401}
1402//******************************************************************************
1403//restores iconized window to previous size/position
1404//******************************************************************************
1405BOOL WIN32API OpenIcon(HWND hwnd)
1406{
1407 dprintf(("USER32: OpenIcon"));
1408
1409 if(!IsIconic(hwnd))
1410 return FALSE;
1411 ShowWindow(hwnd, SW_SHOWNORMAL);
1412 return TRUE;
1413}
1414//******************************************************************************
1415//******************************************************************************
1416BOOL WIN32API ShowOwnedPopups( HWND hwnd, BOOL arg2)
1417{
1418 dprintf(("USER32: ShowOwnedPopups %x", hwnd));
1419 return O32_ShowOwnedPopups(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd), arg2);
1420}
1421//******************************************************************************
1422//******************************************************************************
1423HWND WIN32API GetForegroundWindow(void)
1424{
1425 dprintf(("USER32: GetForegroundWindow"));
1426 return Win32BaseWindow::OS2ToWin32Handle(O32_GetForegroundWindow());
1427}
1428//******************************************************************************
1429//******************************************************************************
1430HWND WIN32API GetLastActivePopup( HWND hWnd)
1431{
1432 HWND hwnd;
1433
1434 hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd);
1435
1436 hwnd = Win32BaseWindow::OS2ToWin32Handle(O32_GetLastActivePopup(hWnd));
1437
1438 dprintf(("GetLastActivePopup %x returned %x", hWnd, hwnd));
1439 return hwnd;
1440}
1441//******************************************************************************
1442//******************************************************************************
1443DWORD WIN32API GetWindowThreadProcessId(HWND hWnd, PDWORD lpdwProcessId)
1444{
1445 dprintf2(("USER32: GetWindowThreadProcessId"));
1446 hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd);
1447
1448 return O32_GetWindowThreadProcessId(hWnd,lpdwProcessId);
1449}
1450//******************************************************************************
1451//******************************************************************************
1452DWORD WIN32API GetWindowContextHelpId(HWND hwnd)
1453{
1454 Win32BaseWindow *window;
1455
1456 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1457 if(!window) {
1458 dprintf(("GetWindowContextHelpId, window %x not found", hwnd));
1459 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1460 return 0;
1461 }
1462 dprintf(("GetWindowContextHelpId %x", hwnd));
1463 return window->getWindowContextHelpId();
1464}
1465//******************************************************************************
1466//******************************************************************************
1467BOOL WIN32API SetWindowContextHelpId(HWND hwnd, DWORD dwContextHelpId)
1468{
1469 Win32BaseWindow *window;
1470
1471 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1472 if(!window) {
1473 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
1474 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1475 return 0;
1476 }
1477 dprintf(("SetWindowContextHelpId %x %d", hwnd, dwContextHelpId));
1478 window->setWindowContextHelpId(dwContextHelpId);
1479 return(TRUE);
1480}
1481//******************************************************************************
1482//******************************************************************************
Note: See TracBrowser for help on using the repository browser.