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

Last change on this file since 6392 was 6392, checked in by sandervl, 24 years ago

IsWindowVisible bugfix

File size: 71.0 KB
Line 
1/* $Id: window.cpp,v 1.101 2001-07-23 19:16:41 sandervl Exp $ */
2/*
3 * Win32 window apis for OS/2
4 *
5 * Copyright 1999-2001 Sander van Leeuwen (sandervl@xs4all.nl)
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, windows\property.c, windows\winpos.c)
10 *
11 * Copyright 1993, 1994, 1995 Alexandre Julliard
12 * 1995, 1996, 1999 Alex Korobka
13 *
14 * Project Odin Software License can be found in LICENSE.TXT
15 *
16 *
17 * TODO: Decide what to do about commands for OS/2 windows (non-Win32 apps)
18 * TODO: ShowOwnedPopups needs to be tested
19 * GetLastActivePopup needs to be rewritten
20 * ArrangeIconicWindows probably too
21 *
22 */
23
24#include <os2win.h>
25#include <misc.h>
26#include <string.h>
27#include <stdio.h>
28#include <win32wbase.h>
29#include <win32wmdiclient.h>
30#include <win32wdesktop.h>
31#include "win32dlg.h"
32#include <oslibwin.h>
33#include <oslibgdi.h>
34#include "user32.h"
35#include "winicon.h"
36#include "oslibmsg.h"
37#include <win\winpos.h>
38#include <win\win.h>
39#include <heapstring.h>
40#include <winuser32.h>
41#include "hook.h"
42
43#define DBG_LOCALLOG DBG_window
44#include "dbglocal.h"
45
46//******************************************************************************
47//******************************************************************************
48HWND WIN32API CreateWindowExA(DWORD exStyle, LPCSTR className,
49 LPCSTR windowName, DWORD style, INT x,
50 INT y, INT width, INT height,
51 HWND parent, HMENU menu,
52 HINSTANCE instance, LPVOID data )
53{
54 Win32BaseWindow *window;
55 ATOM classAtom;
56 CREATESTRUCTA cs;
57 char tmpClass[20];
58
59 if(exStyle & WS_EX_MDICHILD)
60 return CreateMDIWindowA(className, windowName, style, x, y, width, height, parent, instance, (LPARAM)data);
61
62 /* Find the class atom */
63 if (!(classAtom = GlobalFindAtomA(className)))
64 {
65 if (!HIWORD(className))
66 dprintf(("CreateWindowEx32A: bad class name %04x\n",LOWORD(className)));
67 else
68 dprintf(("CreateWindowEx32A: bad class name '%s'\n", className));
69
70 SetLastError(ERROR_INVALID_PARAMETER);
71 return 0;
72 }
73
74 if (!HIWORD(className))
75 {
76 sprintf(tmpClass,"#%d", (int) className);
77 className = tmpClass;
78 }
79
80 /* Create the window */
81 cs.lpCreateParams = data;
82 cs.hInstance = instance;
83 cs.hMenu = menu;
84 cs.hwndParent = parent;
85 cs.x = x;
86 cs.y = y;
87 cs.cx = width;
88 cs.cy = height;
89 cs.style = style;
90 cs.lpszName = windowName;
91 cs.lpszClass = className;
92 cs.dwExStyle = exStyle;
93 if(HIWORD(className)) {
94 dprintf(("CreateWindowExA: class %s parent %x (%d,%d) (%d,%d), %x %x menu=%x", className, parent, x, y, width, height, style, exStyle, menu));
95 }
96 else dprintf(("CreateWindowExA: class %d parent %x (%d,%d) (%d,%d), %x %x menu=%x", className, parent, x, y, width, height, style, exStyle, menu));
97
98 if(!strcmpi(className, MDICLIENTCLASSNAMEA)) {
99 window = (Win32BaseWindow *) new Win32MDIClientWindow(&cs, classAtom, FALSE);
100 }
101 else
102 if(!strcmpi((char *) className, DIALOG_CLASS_NAMEA))
103 {
104 DLG_TEMPLATE dlgTemplate = {0};
105 dlgTemplate.style = cs.style;
106 dlgTemplate.exStyle = cs.dwExStyle;
107 dlgTemplate.x = cs.x;
108 dlgTemplate.y = cs.y;
109 dlgTemplate.cx = cs.cx;
110 dlgTemplate.cy = cs.cy;
111 dlgTemplate.className = cs.lpszClass;
112 dlgTemplate.caption = cs.lpszName;
113 window = (Win32BaseWindow *) new Win32Dialog(cs.hInstance,
114 (LPCSTR) &dlgTemplate,
115 cs.hwndParent,
116 NULL,
117 (LPARAM) data,
118 FALSE);
119 }
120 else {
121 window = new Win32BaseWindow( &cs, classAtom, FALSE );
122 }
123 if(window == NULL)
124 {
125 dprintf(("Win32BaseWindow creation failed!!"));
126 return 0;
127 }
128 if(GetLastError() != 0)
129 {
130 dprintf(("Win32BaseWindow error found!!"));
131 RELEASE_WNDOBJ(window);
132 delete window;
133 return 0;
134 }
135 HWND hwnd = window->getWindowHandle();
136 RELEASE_WNDOBJ(window);
137 return hwnd;
138}
139//******************************************************************************
140//******************************************************************************
141HWND WIN32API CreateWindowExW(DWORD exStyle, LPCWSTR className,
142 LPCWSTR windowName, DWORD style, INT x,
143 INT y, INT width, INT height,
144 HWND parent, HMENU menu,
145 HINSTANCE instance, LPVOID data )
146{
147 Win32BaseWindow *window;
148 ATOM classAtom;
149 CREATESTRUCTA cs;
150 WCHAR tmpClassW[20];
151
152 if(exStyle & WS_EX_MDICHILD)
153 return CreateMDIWindowW(className, windowName, style, x, y, width, height, parent, instance, (LPARAM)data);
154
155 /* Find the class atom */
156 if (!(classAtom = GlobalFindAtomW(className)))
157 {
158 if (!HIWORD(className))
159 dprintf(("CreateWindowEx32W: bad class name %04x",LOWORD(className)));
160 else
161 dprintf(("CreateWindowEx32W: bad class name '%ls'", className));
162
163 SetLastError(ERROR_INVALID_PARAMETER);
164 return 0;
165 }
166#ifdef DEBUG
167 if(HIWORD(className)) {
168 dprintf(("CreateWindowExW: class %ls name %ls parent %x (%d,%d) (%d,%d), %x %x", className, HIWORD(windowName) ? windowName : NULL, parent, x, y, width, height, style, exStyle));
169 }
170 else dprintf(("CreateWindowExW: class %d name %ls parent %x (%d,%d) (%d,%d), %x %x", className, HIWORD(windowName) ? windowName : NULL, parent, x, y, width, height, style, exStyle));
171#endif
172 if (!HIWORD(className))
173 {
174 wsprintfW(tmpClassW, (LPCWSTR)L"#%d", (int) className);
175 className = tmpClassW;
176 }
177
178 /* Create the window */
179 cs.lpCreateParams = data;
180 cs.hInstance = instance;
181 cs.hMenu = menu;
182 cs.hwndParent = parent;
183 cs.x = x;
184 cs.y = y;
185 cs.cx = width;
186 cs.cy = height;
187 cs.style = style;
188 cs.lpszName = (LPSTR)windowName;
189 cs.lpszClass = (LPSTR)className;
190 cs.dwExStyle = exStyle;
191
192 if(!lstrcmpiW(className, (LPWSTR)MDICLIENTCLASSNAMEW)) {
193 window = (Win32BaseWindow *) new Win32MDIClientWindow(&cs, classAtom, TRUE);
194 }
195 else
196 if(!lstrcmpiW(className, (LPWSTR)DIALOG_CLASS_NAMEW))
197 {
198 DLG_TEMPLATE dlgTemplate = {0};
199 dlgTemplate.style = cs.style;
200 dlgTemplate.exStyle = cs.dwExStyle;
201 dlgTemplate.x = cs.x;
202 dlgTemplate.y = cs.y;
203 dlgTemplate.cx = cs.cx;
204 dlgTemplate.cy = cs.cy;
205 dlgTemplate.className = cs.lpszClass;
206 dlgTemplate.caption = cs.lpszName;
207 window = (Win32BaseWindow *) new Win32Dialog(cs.hInstance,
208 (LPCSTR) &dlgTemplate,
209 cs.hwndParent,
210 NULL,
211 (LPARAM) data,
212 TRUE);
213 }
214 else {
215 window = new Win32BaseWindow( &cs, classAtom, TRUE );
216 }
217 if(window == NULL)
218 {
219 dprintf(("Win32BaseWindow creation failed!!"));
220 return 0;
221 }
222 if(GetLastError() != 0)
223 {
224 dprintf(("Win32BaseWindow error found!!"));
225 RELEASE_WNDOBJ(window);
226 delete window;
227 return 0;
228 }
229 HWND hwnd = window->getWindowHandle();
230 RELEASE_WNDOBJ(window);
231 return hwnd;
232}
233//******************************************************************************
234//******************************************************************************
235HWND WIN32API CreateFakeWindowEx(HWND hwndOS2)
236{
237 Win32BaseWindow *window;
238
239 window = new Win32BaseWindow(hwndOS2, 0);
240 if(window == NULL)
241 {
242 dprintf(("Win32BaseWindow creation failed!!"));
243 return 0;
244 }
245 HWND hwnd = window->getWindowHandle();
246 RELEASE_WNDOBJ(window);
247 return hwnd;
248}
249//******************************************************************************
250//******************************************************************************
251HWND WIN32API CreateMDIWindowA(LPCSTR lpszClassName, LPCSTR lpszWindowName,
252 DWORD dwStyle, int x, int y, int nWidth,
253 int nHeight, HWND hwndParent,
254 HINSTANCE hInstance, LPARAM lParam )
255{
256 HWND hwnd;
257 MDICREATESTRUCTA cs;
258 Win32BaseWindow *window;
259
260 window = Win32BaseWindow::GetWindowFromHandle(hwndParent);
261 if(!window) {
262 dprintf(("CreateMDIWindowA, window %x not found", hwndParent));
263 return 0;
264 }
265
266 cs.szClass = lpszClassName;
267 cs.szTitle = lpszWindowName;
268 cs.hOwner = hInstance;
269 cs.x = x;
270 cs.y = y;
271 cs.cx = nHeight;
272 cs.cy = nWidth;
273 cs.style = dwStyle;
274 cs.lParam = lParam;
275
276 if(HIWORD(lpszClassName)) {
277 dprintf(("CreateMDIWindowA: class %s parent %x (%d,%d) (%d,%d), %x %x lParam=%x", lpszClassName, hwndParent, x, y, nWidth, nHeight, dwStyle, lParam));
278 }
279 else dprintf(("CreateMDIWindowA: class %d parent %x (%d,%d) (%d,%d), %x %x lParam=%x", lpszClassName, hwndParent, x, y, nWidth, nHeight, dwStyle, lParam));
280
281 hwnd = window->SendMessageA(WM_MDICREATE, 0, (LPARAM)&cs);
282 RELEASE_WNDOBJ(window);
283 return hwnd;
284}
285//******************************************************************************
286//******************************************************************************
287HWND WIN32API CreateMDIWindowW(LPCWSTR lpszClassName, LPCWSTR lpszWindowName,
288 DWORD dwStyle, int x, int y, int nWidth,
289 int nHeight, HWND hwndParent,
290 HINSTANCE hInstance, LPARAM lParam )
291{
292 HWND hwnd;
293 MDICREATESTRUCTW cs;
294 Win32BaseWindow *window;
295
296 window = Win32BaseWindow::GetWindowFromHandle(hwndParent);
297 if(!window) {
298 dprintf(("CreateMDIWindowW, window %x not found", hwndParent));
299 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
300 return 0;
301 }
302
303 cs.szClass = lpszClassName;
304 cs.szTitle = lpszWindowName;
305 cs.hOwner = hInstance;
306 cs.x = x;
307 cs.y = y;
308 cs.cx = nHeight;
309 cs.cy = nWidth;
310 cs.style = dwStyle;
311 cs.lParam = lParam;
312
313 if(HIWORD(lpszClassName)) {
314 dprintf(("CreateMDIWindowW: class %ls parent %x (%d,%d) (%d,%d), %x %x lParam=%x", lpszClassName, hwndParent, x, y, nWidth, nHeight, dwStyle, lParam));
315 }
316 else dprintf(("CreateMDIWindowW: class %d parent %x (%d,%d) (%d,%d), %x %x lParam=%x", lpszClassName, hwndParent, x, y, nWidth, nHeight, dwStyle, lParam));
317
318 hwnd = window->SendMessageW(WM_MDICREATE, 0, (LPARAM)&cs);
319 RELEASE_WNDOBJ(window);
320 return hwnd;
321}
322//******************************************************************************
323//******************************************************************************
324BOOL WIN32API DestroyWindow(HWND hwnd)
325{
326 Win32BaseWindow *window;
327 BOOL ret;
328
329 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
330 if(!window) {
331 dprintf(("DestroyWindow, window %x not found", hwnd));
332 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
333 return 0;
334 }
335 ret = window->DestroyWindow();
336 RELEASE_WNDOBJ(window);
337 return ret;
338}
339//******************************************************************************
340//******************************************************************************
341HWND WIN32API SetActiveWindow( HWND hwnd)
342{
343 Win32BaseWindow *window;
344 HWND hwndActive;
345
346 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
347 if(!window) {
348 dprintf(("SetActiveWindow, window %x not found", hwnd));
349 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
350 return 0;
351 }
352 hwndActive = window->SetActiveWindow();
353 RELEASE_WNDOBJ(window);
354 return hwndActive;
355}
356//******************************************************************************
357//Note: does not set last error if no parent (verified in NT4, SP6)
358//******************************************************************************
359HWND WIN32API GetParent( HWND hwnd)
360{
361 Win32BaseWindow *window;
362 HWND hwndParent;
363
364 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
365 if(!window) {
366 dprintf(("GetParent, window %x not found", hwnd));
367 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
368 return 0;
369 }
370 dprintf2(("GetParent %x", hwnd));
371 hwndParent = window->GetParent();
372 RELEASE_WNDOBJ(window);
373 return hwndParent;
374}
375//******************************************************************************
376//******************************************************************************
377HWND WIN32API SetParent( HWND hwndChild, HWND hwndNewParent)
378{
379 Win32BaseWindow *window;
380 HWND hwndOldParent;
381
382 window = Win32BaseWindow::GetWindowFromHandle(hwndChild);
383 if(!window) {
384 dprintf(("SetParent, window %x not found", hwndChild));
385 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
386 return 0;
387 }
388 if(hwndNewParent == HWND_DESKTOP) {
389 hwndNewParent = GetDesktopWindow();
390 }
391 else {
392 if(!IsWindow(hwndNewParent)) {
393 RELEASE_WNDOBJ(window);
394 dprintf(("SetParent, parent %x not found", hwndNewParent));
395 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
396 return 0;
397 }
398 }
399 dprintf(("SetParent %x %x", hwndChild, hwndNewParent));
400 hwndOldParent = window->SetParent(hwndNewParent);
401 RELEASE_WNDOBJ(window);
402 return hwndOldParent;
403}
404//******************************************************************************
405//******************************************************************************
406BOOL WIN32API IsChild( HWND hwndParent, HWND hwnd)
407{
408 Win32BaseWindow *window;
409 BOOL fIsChild;
410
411 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
412 if(!window) {
413 dprintf(("IsChild %x, window %x not found", hwndParent, hwnd));
414 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
415 return 0;
416 }
417 dprintf(("IsChild %x %x", hwndParent, hwnd));
418 fIsChild = window->IsChild(hwndParent);
419 RELEASE_WNDOBJ(window);
420 return fIsChild;
421}
422//******************************************************************************
423//******************************************************************************
424HWND WIN32API GetTopWindow( HWND hwnd)
425{
426 Win32BaseWindow *window;
427 HWND hwndTop;
428
429 if(hwnd == HWND_DESKTOP) {
430 windowDesktop->addRef();
431 window = windowDesktop;
432 }
433 else {
434 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
435 if(!window) {
436 dprintf(("GetTopWindow, window %x not found", hwnd));
437 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
438 return 0;
439 }
440 }
441 hwndTop = window->GetTopWindow();
442 dprintf2(("GetTopWindow %x returned %x", hwnd, hwndTop));
443 RELEASE_WNDOBJ(window);
444 return hwndTop;
445}
446//******************************************************************************
447//******************************************************************************
448BOOL WIN32API IsIconic( HWND hwnd)
449{
450 Win32BaseWindow *window;
451 BOOL fIsIconic;
452
453 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
454 if(!window) {
455 dprintf(("IsIconic, window %x not found", hwnd));
456 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
457 return FALSE;
458 }
459 fIsIconic = window->IsWindowIconic();
460 dprintf(("IsIconic %x returned %d", hwnd, fIsIconic));
461 RELEASE_WNDOBJ(window);
462 return fIsIconic;
463}
464//******************************************************************************
465//******************************************************************************
466HWND WIN32API GetWindow(HWND hwnd, UINT uCmd)
467{
468 Win32BaseWindow *window;
469 HWND hwndRelated;
470
471 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
472 if(!window) {
473 dprintf(("GetWindow, window %x not found", hwnd));
474 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
475 return 0;
476 }
477 hwndRelated = window->GetWindow(uCmd);
478 RELEASE_WNDOBJ(window);
479 return hwndRelated;
480}
481//******************************************************************************
482//******************************************************************************
483BOOL WIN32API EnableWindow( HWND hwnd, BOOL fEnable)
484{
485 Win32BaseWindow *window;
486 BOOL fEnabled;
487
488 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
489 if(!window) {
490 dprintf(("EnableWindow, window %x not found", hwnd));
491 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
492 return 0;
493 }
494 dprintf(("EnableWindow %x %d", hwnd, fEnable));
495 fEnabled = window->EnableWindow(fEnable);
496 RELEASE_WNDOBJ(window);
497 return fEnabled;
498}
499//******************************************************************************
500//******************************************************************************
501BOOL WIN32API BringWindowToTop(HWND hwnd)
502{
503 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
504}
505/***********************************************************************
506 * SetInternalWindowPos (USER32.483)
507 */
508void WIN32API SetInternalWindowPos(HWND hwnd,
509 UINT showCmd,
510 LPRECT lpRect,
511 LPPOINT lpPoint )
512{
513 dprintf(("USER32: SetInternalWindowPos(%08xh,%08xh,%08xh,%08xh)",
514 hwnd, showCmd, lpRect, lpPoint));
515
516 if( IsWindow(hwnd) )
517 {
518 WINDOWPLACEMENT wndpl;
519 UINT flags;
520
521 GetWindowPlacement(hwnd, &wndpl);
522 wndpl.length = sizeof(wndpl);
523 wndpl.showCmd = showCmd;
524 wndpl.flags = 0;
525
526 if(lpPoint)
527 {
528 wndpl.flags |= WPF_SETMINPOSITION;
529 wndpl.ptMinPosition = *lpPoint;
530 }
531 if(lpRect)
532 {
533 wndpl.rcNormalPosition = *lpRect;
534 }
535 SetWindowPlacement( hwnd, &wndpl);
536 }
537
538}
539/***********************************************************************
540 * GetInternalWindowPos (USER32.245)
541 */
542UINT WIN32API GetInternalWindowPos(HWND hwnd,
543 LPRECT rectWnd,
544 LPPOINT ptIcon )
545{
546 WINDOWPLACEMENT wndpl;
547
548 dprintf(("USER32: GetInternalWindowPos(%08xh,%08xh,%08xh)\n",
549 hwnd,
550 rectWnd,
551 ptIcon));
552
553 if(GetWindowPlacement( hwnd, &wndpl ))
554 {
555 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
556 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
557 return wndpl.showCmd;
558 }
559 return 0;
560}
561//******************************************************************************
562//******************************************************************************
563HWND WIN32API GetActiveWindow()
564{
565 return Win32BaseWindow::GetActiveWindow();
566}
567//******************************************************************************
568//******************************************************************************
569BOOL WIN32API ShowWindow(HWND hwnd, int nCmdShow)
570{
571 Win32BaseWindow *window;
572 BOOL ret;
573
574 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
575 if(!window) {
576 dprintf(("ShowWindow, window %x not found", hwnd));
577 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
578 return 0;
579 }
580 ret = window->ShowWindow(nCmdShow);
581 RELEASE_WNDOBJ(window);
582 return ret;
583}
584/*****************************************************************************
585 * Name : BOOL WIN32API ShowWindowAsync
586 * Purpose : The ShowWindowAsync function sets the show state of a window
587 * created by a different thread.
588 * Parameters: HWND hwnd handle of window
589 * int nCmdShow show state of window
590 * Variables :
591 * Result : If the window was previously visible, the return value is TRUE.
592 * If the window was previously hidden, the return value is FALSE.
593 * Remark :
594 * Status : UNTESTED STUB
595 *
596 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
597 *****************************************************************************/
598BOOL WIN32API ShowWindowAsync (HWND hwnd,
599 int nCmdShow)
600{
601 dprintf(("USER32:ShowWindowAsync (%08xh,%08x) not correctly implemented.\n",
602 hwnd,
603 nCmdShow));
604
605 return ShowWindow(hwnd, nCmdShow);
606}
607//******************************************************************************
608//******************************************************************************
609BOOL WIN32API SetWindowPos(HWND hwnd, HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
610{
611 Win32BaseWindow *window;
612
613 if (!hwnd)
614 {
615 dprintf(("SetWindowPos: Can't move desktop!"));
616 return TRUE;
617 }
618 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
619 if(!window) {
620 dprintf(("SetWindowPos, window %x not found", hwnd));
621 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
622 return FALSE;
623 }
624 dprintf(("SetWindowPos %x %x x=%d y=%d cx=%d cy=%d %x", hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
625 BOOL ret = window->SetWindowPos(hwndInsertAfter, x, y, cx, cy, fuFlags);
626 RELEASE_WNDOBJ(window);
627 return ret;
628}
629//******************************************************************************
630//NOTE: length must equal structure size or else api fails (verified in NT4, SP6)
631//******************************************************************************
632BOOL WIN32API SetWindowPlacement(HWND hwnd, const WINDOWPLACEMENT *winpos)
633{
634 Win32BaseWindow *window;
635
636 if(!winpos || winpos->length != sizeof(WINDOWPLACEMENT)) {
637 dprintf(("SetWindowPlacement %x invalid parameter", hwnd));
638 SetLastError(ERROR_INVALID_PARAMETER);
639 return FALSE;
640 }
641 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
642 if(!window) {
643 dprintf(("SetWindowPlacement, window %x not found", hwnd));
644 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
645 return FALSE;
646 }
647 dprintf(("USER32: SetWindowPlacement %x %x", hwnd, winpos));
648 BOOL ret = window->SetWindowPlacement((WINDOWPLACEMENT *)winpos);
649 RELEASE_WNDOBJ(window);
650 return ret;
651}
652//******************************************************************************
653//NOTE: Length does not need to be correct (even though the SDK docs claim otherwise)
654// (Verified in NT4, SP6)
655//******************************************************************************
656BOOL WIN32API GetWindowPlacement(HWND hwnd, LPWINDOWPLACEMENT winpos)
657{
658 Win32BaseWindow *window;
659
660 if(!winpos) {
661 dprintf(("GetWindowPlacement %x invalid parameter", hwnd));
662 SetLastError(ERROR_INVALID_PARAMETER);
663 return FALSE;
664 }
665 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
666 if(!window) {
667 dprintf(("GetWindowPlacement, window %x not found", hwnd));
668 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
669 return FALSE;
670 }
671 dprintf(("USER32: GetWindowPlacement %x %x", hwnd, winpos));
672 BOOL ret = window->GetWindowPlacement(winpos);
673 RELEASE_WNDOBJ(window);
674 return ret;
675}
676//******************************************************************************
677//******************************************************************************
678BOOL WIN32API IsWindow( HWND hwnd)
679{
680 Win32BaseWindow *window;
681
682 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
683 if(!window) {
684 dprintf(("IsWindow, window %x not found", hwnd));
685 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
686 return FALSE;
687 }
688 dprintf2(("IsWindow %x", hwnd));
689 BOOL fIsWindow = window->IsWindow();
690 RELEASE_WNDOBJ(window);
691 return fIsWindow;
692}
693//******************************************************************************
694//******************************************************************************
695BOOL WIN32API IsWindowEnabled( HWND hwnd)
696{
697 DWORD dwStyle;
698
699 if(!IsWindow(hwnd)) {
700 dprintf(("IsWindowEnabled, window %x not found", hwnd));
701 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
702 return 0;
703 }
704 dprintf(("IsWindowEnabled %x", hwnd));
705 dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
706 if(dwStyle & WS_DISABLED) {
707 return FALSE;
708 }
709 return TRUE;
710}
711//******************************************************************************
712//******************************************************************************
713BOOL WIN32API IsWindowVisible(HWND hwnd)
714{
715 BOOL ret;
716 HWND hwndParent;
717 DWORD dwStyle;
718
719 if(hwnd == HWND_DESKTOP) {//TODO: verify in NT!
720 dprintf(("IsWindowVisible DESKTOP returned TRUE"));
721 return TRUE; //desktop is always visible
722 }
723 if(!IsWindow(hwnd)) {
724 dprintf(("IsWindowVisible, window %x not found", hwnd));
725 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
726 return 0;
727 }
728 //check visibility of this window
729 dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
730 if(!(dwStyle & WS_VISIBLE)) {
731 ret = FALSE;
732 goto end;
733 }
734 ret = TRUE;
735
736 //check visibility of parents
737 hwndParent = GetParent(hwnd);
738 while(hwndParent) {
739 dwStyle = GetWindowLongA(hwndParent, GWL_STYLE);
740 if(!(dwStyle & WS_VISIBLE)) {
741 dprintf(("IsWindowVisible %x returned FALSE (parent %x invisible)", hwnd, hwndParent));
742 return FALSE;
743 }
744 if(!(dwStyle & WS_CHILD)) {
745 break; //GetParent can also return the owner
746 }
747 hwndParent = GetParent(hwndParent);
748 }
749
750end:
751 dprintf(("IsWindowVisible %x returned %d", hwnd, ret));
752 return ret;
753}
754//******************************************************************************
755//******************************************************************************
756HWND WIN32API SetFocus(HWND hwnd)
757{
758 Win32BaseWindow *window;
759 Win32BaseWindow *oldfocuswnd;
760 HWND lastFocus, lastFocus_W, hwnd_O, hwndTopParent;
761 BOOL activate;
762 TEB *teb;
763
764 teb = GetThreadTEB();
765 if(teb == NULL) {
766 DebugInt3();
767 return 0;
768 }
769
770 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
771 if(!window) {
772 dprintf(("SetFocus, window %x not found", hwnd));
773 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
774 return 0;
775 }
776
777 hwnd_O = window->getOS2WindowHandle();
778 if(teb->o.odin.hwndFocus) {
779 lastFocus = teb->o.odin.hwndFocus;
780 }
781 else lastFocus = OSLibWinQueryFocus (OSLIB_HWND_DESKTOP);
782
783 hwndTopParent = window->GetTopParent();
784 activate = FALSE;
785 lastFocus_W = OS2ToWin32Handle(lastFocus);
786 if(lastFocus_W) {
787 oldfocuswnd = Win32BaseWindow::GetWindowFromHandle(lastFocus_W);
788 if(lastFocus_W != hwnd && hwndTopParent != oldfocuswnd->GetTopParent()) {
789 activate = TRUE;
790 }
791 RELEASE_WNDOBJ(oldfocuswnd);
792 }
793 else activate = TRUE;
794
795 dprintf(("SetFocus %x (%x) -> %x (%x) act %d", lastFocus_W, lastFocus, hwnd, hwnd_O, activate));
796
797 if(HOOK_CallHooksA(WH_CBT, HCBT_SETFOCUS, hwnd, (LPARAM)lastFocus_W)) {
798 dprintf(("hook cancelled SetFocus call!"));
799 return 0;
800 }
801
802 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
803 //must delay this function call
804 if(teb->o.odin.fWM_SETFOCUS) {
805 dprintf(("USER32: Delay SetFocus call!"));
806 teb->o.odin.hwndFocus = hwnd;
807 //mp1 = win32 window handle
808 //mp2 = top parent if activation required
809 OSLibPostMessageDirect(hwnd_O, WIN32APP_SETFOCUSMSG, hwnd, (activate) ? hwndTopParent : 0);
810 return lastFocus_W;
811 }
812 teb->o.odin.hwndFocus = 0;
813 if(activate) {
814 SetActiveWindow(hwndTopParent);
815 }
816 if(!IsWindow(hwnd)) return FALSE; //abort if window destroyed
817
818 return (OSLibWinSetFocus(OSLIB_HWND_DESKTOP, hwnd_O, 0)) ? lastFocus_W : 0;
819}
820//******************************************************************************
821//******************************************************************************
822HWND WIN32API GetFocus(void)
823{
824 TEB *teb;
825 HWND hwnd;
826
827 teb = GetThreadTEB();
828 if(teb == NULL) {
829 DebugInt3();
830 return 0;
831 }
832 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
833 //If focus was changed during WM_SETFOCUS, the focus window handle is
834 //stored in teb->o.odin.hwndFocus (set back to 0 when delayed SetFocus
835 //is activated)
836 if(teb->o.odin.hwndFocus) {
837 dprintf(("USER32: GetFocus %x (DURING WM_SETFOCUS PROCESSING)", teb->o.odin.hwndFocus));
838 return teb->o.odin.hwndFocus;
839 }
840
841 hwnd = OSLibWinQueryFocus(OSLIB_HWND_DESKTOP);
842 hwnd = OS2ToWin32Handle(hwnd);
843 dprintf(("USER32: GetFocus %x\n", hwnd));
844 return hwnd;
845}
846//******************************************************************************
847//******************************************************************************
848BOOL WIN32API IsZoomed(HWND hwnd)
849{
850 DWORD style;
851
852 style = GetWindowLongA(hwnd, GWL_STYLE);
853 dprintf(("USER32: IsZoomed %x returned %d", hwnd, ((style & WS_MAXIMIZE) != 0)));
854
855 return (style & WS_MAXIMIZE) != 0;
856}
857//******************************************************************************
858//******************************************************************************
859BOOL WIN32API LockWindowUpdate(HWND hwnd)
860{
861 dprintf(("USER32: LockWindowUpdate %x", hwnd));
862 return OSLibWinLockWindowUpdate(Win32ToOS2Handle(hwnd));
863}
864//******************************************************************************
865//******************************************************************************
866BOOL WIN32API GetWindowRect( HWND hwnd, PRECT pRect)
867{
868 Win32BaseWindow *window;
869
870 if(pRect == NULL) {
871 dprintf(("GetWindowRect %x invalid parameter!", hwnd));
872 SetLastError(ERROR_INVALID_PARAMETER);
873 return FALSE;
874 }
875
876 if(hwnd == HWND_DESKTOP) {
877 windowDesktop->addRef();
878 window = windowDesktop;
879 }
880 else window = Win32BaseWindow::GetWindowFromHandle(hwnd);
881
882 if(!window) {
883 dprintf(("GetWindowRect, window %x not found", hwnd));
884 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
885 return FALSE;
886 }
887 *pRect = *window->getWindowRect();
888
889 //convert from parent coordinates to screen (if necessary)
890 if(window->getParent()) {
891 MapWindowPoints(window->getParent()->getWindowHandle(), 0, (PPOINT)pRect, 2);
892 }
893 RELEASE_WNDOBJ(window);
894 dprintf(("GetWindowRect %x (%d,%d) (%d,%d)", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom));
895 return TRUE;
896}
897//******************************************************************************
898//******************************************************************************
899int WIN32API GetWindowTextLengthA( HWND hwnd)
900{
901 Win32BaseWindow *window;
902
903 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
904 if(!window) {
905 dprintf(("GetWindowTextLengthA, window %x not found", hwnd));
906 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
907 return 0;
908 }
909 dprintf(("GetWindowTextLengthA %x", hwnd));
910 int ret = window->GetWindowTextLengthA();
911 RELEASE_WNDOBJ(window);
912 return ret;
913}
914//******************************************************************************
915//******************************************************************************
916int WIN32API GetWindowTextA( HWND hwnd, LPSTR lpsz, int cch)
917{
918 Win32BaseWindow *window;
919 int rc;
920
921 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
922 if(!window) {
923 dprintf(("GetWindowTextA, window %x not found", hwnd));
924 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
925 return 0;
926 }
927 rc = window->GetWindowTextA(lpsz, cch);
928 dprintf(("GetWindowTextA %x %s", hwnd, lpsz));
929 RELEASE_WNDOBJ(window);
930 return rc;
931}
932//******************************************************************************
933//******************************************************************************
934int WIN32API GetWindowTextLengthW( HWND hwnd)
935{
936 Win32BaseWindow *window;
937
938 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
939 if(!window) {
940 dprintf(("GetWindowTextLengthW, window %x not found", hwnd));
941 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
942 return 0;
943 }
944 dprintf(("GetWindowTextLengthW %x", hwnd));
945 int ret = window->GetWindowTextLengthW();
946 RELEASE_WNDOBJ(window);
947 return ret;
948}
949//******************************************************************************
950//******************************************************************************
951int WIN32API GetWindowTextW(HWND hwnd, LPWSTR lpsz, int cch)
952{
953 Win32BaseWindow *window;
954
955 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
956 if(!window) {
957 dprintf(("GetWindowTextW, window %x not found", hwnd));
958 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
959 return 0;
960 }
961 int rc = window->GetWindowTextW(lpsz, cch);
962 RELEASE_WNDOBJ(window);
963 dprintf(("GetWindowTextW %x %ls", hwnd, lpsz));
964 return rc;
965}
966//******************************************************************************
967//******************************************************************************
968BOOL WIN32API SetWindowTextA(HWND hwnd, LPCSTR lpsz)
969{
970 Win32BaseWindow *window;
971
972 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
973 if(!window) {
974 dprintf(("SetWindowTextA, window %x not found", hwnd));
975 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
976 return 0;
977 }
978 dprintf(("SetWindowTextA %x %s", hwnd, lpsz));
979 BOOL ret = window->SetWindowTextA((LPSTR)lpsz);
980 RELEASE_WNDOBJ(window);
981 return ret;
982}
983//******************************************************************************
984//******************************************************************************
985BOOL WIN32API SetWindowTextW( HWND hwnd, LPCWSTR lpsz)
986{
987 Win32BaseWindow *window;
988
989 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
990 if(!window) {
991 dprintf(("SetWindowTextA, window %x not found", hwnd));
992 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
993 return 0;
994 }
995 dprintf(("SetWindowTextW %x %ls", hwnd, lpsz));
996 BOOL ret = window->SetWindowTextW((LPWSTR)lpsz);
997 RELEASE_WNDOBJ(window);
998 return ret;
999}
1000/*******************************************************************
1001 * InternalGetWindowText (USER32.326)
1002 */
1003int WIN32API InternalGetWindowText(HWND hwnd,
1004 LPWSTR lpString,
1005 INT nMaxCount )
1006{
1007 dprintf(("USER32: InternalGetWindowText(%08xh,%08xh,%08xh) not properly implemented.\n",
1008 hwnd,
1009 lpString,
1010 nMaxCount));
1011
1012 return GetWindowTextW(hwnd,lpString,nMaxCount);
1013}
1014//******************************************************************************
1015//TODO: Correct?
1016//******************************************************************************
1017BOOL WIN32API SetForegroundWindow(HWND hwnd)
1018{
1019 dprintf((" SetForegroundWindow %x", hwnd));
1020
1021 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
1022}
1023//******************************************************************************
1024//******************************************************************************
1025BOOL WIN32API GetClientRect( HWND hwnd, PRECT pRect)
1026{
1027 HWND hwndWin32 = hwnd;
1028 Win32BaseWindow *window;
1029
1030 if (!pRect)
1031 {
1032 SetLastError(ERROR_INVALID_PARAMETER);
1033 return FALSE;
1034 }
1035 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1036 if(!window) {
1037 dprintf(("GetClientRect, window %x not found", hwnd));
1038 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1039 return FALSE;
1040 }
1041 window->getClientRect(pRect);
1042 dprintf(("GetClientRect of %X returned (%d,%d) (%d,%d)\n", hwndWin32, pRect->left, pRect->top, pRect->right, pRect->bottom));
1043 RELEASE_WNDOBJ(window);
1044 return TRUE;
1045}
1046//******************************************************************************
1047//******************************************************************************
1048BOOL WIN32API AdjustWindowRect(PRECT rect, DWORD style, BOOL menu)
1049{
1050 return AdjustWindowRectEx(rect, style, menu, 0);
1051}
1052//******************************************************************************
1053//Calculate window rectangle based on given client rectangle, style, menu and extended style
1054//******************************************************************************
1055BOOL WIN32API AdjustWindowRectEx( PRECT rect, DWORD style, BOOL menu, DWORD exStyle)
1056{
1057 if(style == 0 && menu == FALSE && exStyle == 0) {
1058 dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d) -> no change required", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
1059 return TRUE; //nothing needs to be changed (VERIFIED in NT 4)
1060 }
1061 dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d)\n", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
1062 /* Correct the window style */
1063 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
1064 style |= WS_CAPTION;
1065
1066 //SvL: Include WS_POPUP -> otherwise HAS_THINFRAME is true for popup windows
1067 // Also include WS_CHILD -> otherwise HAS_THICKFRAME doesn't work correctly
1068 style &= (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_POPUP);
1069 exStyle &= (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EX_TOOLWINDOW);
1070 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
1071
1072 //Adjust rect outer (Win32BaseWindow::AdjustRectOuter)
1073 if (HAS_THICKFRAME(style,exStyle))
1074 InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
1075 else
1076 if (HAS_DLGFRAME(style,exStyle))
1077 InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
1078 else
1079 if (HAS_THINFRAME(style))
1080 InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
1081
1082 if ((style & WS_CAPTION) == WS_CAPTION)
1083 {
1084 if (exStyle & WS_EX_TOOLWINDOW)
1085 rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
1086 else
1087 rect->top -= GetSystemMetrics(SM_CYCAPTION);
1088 }
1089
1090 if (menu)
1091 rect->top -= GetSystemMetrics(SM_CYMENU);
1092
1093 //Adjust rect inner (Win32BaseWindow::AdjustRectInner)
1094 if(!(style & WS_ICONIC)) {
1095 if (exStyle & WS_EX_CLIENTEDGE)
1096 InflateRect (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
1097
1098 if (exStyle & WS_EX_STATICEDGE)
1099 InflateRect (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
1100
1101 //SvL: scrollbars aren't checked *UNLESS* the style includes a border (any border)
1102 // --> VERIFIED IN NT4, SP6 (fixes MFC apps with scrollbars + bar controls)
1103 if(style & (WS_THICKFRAME|WS_BORDER|WS_DLGFRAME)) {
1104 if (style & WS_VSCROLL) rect->right += GetSystemMetrics(SM_CXVSCROLL);
1105 if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
1106 }
1107 }
1108
1109 dprintf(("AdjustWindowRectEx returned (%d,%d)(%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom));
1110
1111 return TRUE;
1112}
1113//******************************************************************************
1114/* Coordinate Space and Transformation Functions */
1115//******************************************************************************
1116/*******************************************************************
1117 * WINPOS_GetWinOffset
1118 *
1119 * Calculate the offset between the origin of the two windows. Used
1120 * to implement MapWindowPoints.
1121 */
1122static void WINPOS_GetWinOffset( Win32BaseWindow *wndFrom, Win32BaseWindow *wndTo,
1123 POINT *offset )
1124{
1125 Win32BaseWindow *window;
1126
1127 offset->x = offset->y = 0;
1128
1129 /* Translate source window origin to screen coords */
1130 if(wndFrom != windowDesktop)
1131 {
1132 window = wndFrom;
1133 while(window)
1134 {
1135 offset->x += window->getClientRectPtr()->left + window->getWindowRect()->left;
1136 offset->y += window->getClientRectPtr()->top + window->getWindowRect()->top;
1137 window = window->getParent();
1138 }
1139 }
1140
1141 /* Translate origin to destination window coords */
1142 if(wndTo != windowDesktop)
1143 {
1144 window = wndTo;
1145 while(window)
1146 {
1147 offset->x -= window->getClientRectPtr()->left + window->getWindowRect()->left;
1148 offset->y -= window->getClientRectPtr()->top + window->getWindowRect()->top;
1149 window = window->getParent();
1150 }
1151 }
1152}
1153//******************************************************************************
1154//******************************************************************************
1155int WIN32API MapWindowPoints(HWND hwndFrom, HWND hwndTo, LPPOINT lpPoints,
1156 UINT cPoints)
1157{
1158 Win32BaseWindow *wndfrom, *wndto;
1159 int retval = 0;
1160 POINT offset;
1161
1162 SetLastError(0);
1163 if(lpPoints == NULL || cPoints == 0) {
1164 SetLastError(ERROR_INVALID_PARAMETER);
1165 return 0;
1166 }
1167 if(hwndTo == hwndFrom)
1168 return 0; //nothing to do
1169
1170 if(hwndFrom == HWND_DESKTOP)
1171 {
1172 windowDesktop->addRef();
1173 wndfrom = windowDesktop;
1174 }
1175 else {
1176 wndfrom = Win32BaseWindow::GetWindowFromHandle(hwndFrom);
1177 if(!wndfrom) {
1178 dprintf(("MapWindowPoints, window %x not found", hwndFrom));
1179 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1180 return 0;
1181 }
1182 }
1183
1184 if(hwndTo == HWND_DESKTOP)
1185 {
1186 windowDesktop->addRef();
1187 wndto = windowDesktop;
1188 }
1189 else {
1190 wndto = Win32BaseWindow::GetWindowFromHandle(hwndTo);
1191 if(!wndto) {
1192 dprintf(("MapWindowPoints, window %x not found", hwndTo));
1193 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1194 return 0;
1195 }
1196 }
1197
1198 dprintf2(("USER32: MapWindowPoints %x to %x (%d,%d) (%d)", hwndFrom, hwndTo, lpPoints->x, lpPoints->y, cPoints));
1199 WINPOS_GetWinOffset(wndfrom, wndto, &offset);
1200
1201 RELEASE_WNDOBJ(wndto);
1202 RELEASE_WNDOBJ(wndfrom);
1203 for(int i=0;i<cPoints;i++)
1204 {
1205 lpPoints[i].x += offset.x;
1206 lpPoints[i].y += offset.y;
1207 }
1208 retval = ((LONG)offset.y << 16) | offset.x;
1209 return retval;
1210}
1211//******************************************************************************
1212//******************************************************************************
1213BOOL WIN32API ScreenToClient(HWND hwnd, LPPOINT pt)
1214{
1215 PRECT rcl;
1216 BOOL rc;
1217
1218 if(hwnd == HWND_DESKTOP) {
1219 return (TRUE); //nothing to do
1220 }
1221 if (!IsWindow(hwnd)) {
1222 dprintf(("warning: ScreenToClient: window %x not found!", hwnd));
1223 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1224 return FALSE;
1225 }
1226 SetLastError(0);
1227#ifdef DEBUG
1228 POINT tmp = *pt;
1229#endif
1230 MapWindowPoints(0, hwnd, pt, 1);
1231 dprintf2(("ScreenToClient %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
1232 return TRUE;
1233}
1234//******************************************************************************
1235//******************************************************************************
1236HWND WIN32API GetDesktopWindow(void)
1237{
1238 HWND DesktopWindow = windowDesktop->getWindowHandle();
1239 dprintf2(("USER32: GetDesktopWindow, returned %x\n", DesktopWindow));
1240 return DesktopWindow;
1241}
1242//******************************************************************************
1243//******************************************************************************
1244HWND WIN32API FindWindowA(LPCSTR lpszClass, LPCSTR lpszWindow)
1245{
1246 return FindWindowExA( NULL, NULL, lpszClass, lpszWindow );
1247}
1248//******************************************************************************
1249//******************************************************************************
1250HWND WIN32API FindWindowW( LPCWSTR lpClassName, LPCWSTR lpWindowName)
1251{
1252 return FindWindowExW( NULL, NULL, lpClassName, lpWindowName );
1253}
1254//******************************************************************************
1255//******************************************************************************
1256HWND WIN32API FindWindowExA(HWND hwndParent, HWND hwndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow)
1257{
1258 ATOM atom = 0;
1259
1260 if (lpszClass)
1261 {
1262 /* If the atom doesn't exist, then no class */
1263 /* with this name exists either. */
1264 if (!(atom = GlobalFindAtomA( lpszClass )))
1265 {
1266 SetLastError(ERROR_CANNOT_FIND_WND_CLASS);
1267 return 0;
1268 }
1269 }
1270 return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, atom, (LPSTR)lpszWindow);
1271}
1272/*****************************************************************************
1273 * Name : HWND WIN32API FindWindowExW
1274 * Purpose : The FindWindowEx function retrieves the handle of a window whose
1275 * class name and window name match the specified strings. The
1276 * function searches child windows, beginning with the one following
1277 * the given child window.
1278 * Parameters: HWND hwndParent handle of parent window
1279 * HWND hwndChildAfter handle of a child window
1280 * LPCTSTR lpszClass address of class name
1281 * LPCTSTR lpszWindow address of window name
1282 * Variables :
1283 * Result : If the function succeeds, the return value is the handle of the
1284 * window that has the specified class and window names.
1285 * If the function fails, the return value is NULL. To get extended
1286 * error information, call GetLastError.
1287 * Remark :
1288 *
1289 *****************************************************************************/
1290
1291HWND WIN32API FindWindowExW(HWND hwndParent,
1292 HWND hwndChildAfter,
1293 LPCWSTR lpszClass,
1294 LPCWSTR lpszWindow)
1295{
1296 ATOM atom = 0;
1297 char *buffer;
1298 HWND hwnd;
1299
1300 if (lpszClass)
1301 {
1302 /* If the atom doesn't exist, then no class */
1303 /* with this name exists either. */
1304 if (!(atom = GlobalFindAtomW( lpszClass )))
1305 {
1306 SetLastError(ERROR_CANNOT_FIND_WND_CLASS);
1307 return 0;
1308 }
1309 }
1310 buffer = HEAP_strdupWtoA( GetProcessHeap(), 0, lpszWindow );
1311 hwnd = Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, atom, buffer);
1312 HeapFree( GetProcessHeap(), 0, buffer );
1313 return hwnd;
1314}
1315//******************************************************************************
1316//******************************************************************************
1317BOOL WIN32API FlashWindow(HWND hwnd, BOOL fFlash)
1318{
1319 dprintf(("FlashWindow %x %d\n", hwnd, fFlash));
1320// return OSLibWinFlashWindow(Win32ToOS2Handle(hwnd), fFlash);
1321 return 1;
1322}
1323//******************************************************************************
1324//******************************************************************************
1325BOOL WIN32API MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
1326 BOOL repaint )
1327{
1328 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
1329
1330 if (!repaint) flags |= SWP_NOREDRAW;
1331 dprintf(("MoveWindow: %x %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint ));
1332
1333 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
1334}
1335//******************************************************************************
1336//******************************************************************************
1337BOOL WIN32API ClientToScreen (HWND hwnd, PPOINT pt)
1338{
1339 PRECT rcl;
1340
1341 if(hwnd == HWND_DESKTOP) {
1342 return(TRUE); //nothing to do
1343 }
1344 if(!IsWindow(hwnd)) {
1345 dprintf(("warning: ClientToScreen window %x not found!", hwnd));
1346 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1347 return (FALSE);
1348 }
1349#ifdef DEBUG
1350 POINT tmp = *pt;
1351#endif
1352 MapWindowPoints(hwnd, 0, pt, 1);
1353 dprintf2(("ClientToScreen %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
1354
1355 return TRUE;
1356}
1357//******************************************************************************
1358//Note: count 0 is a legal parameter (verified in NT4)
1359//******************************************************************************
1360HDWP WIN32API BeginDeferWindowPos(int count)
1361{
1362 HDWP handle;
1363 DWP *pDWP;
1364
1365 if (count < 0)
1366 {
1367 dprintf(("USER32: BeginDeferWindowPos invalid param %d", count));
1368 SetLastError(ERROR_INVALID_PARAMETER);
1369 return 0;
1370 }
1371 dprintf(("USER32: BeginDeferWindowPos %d", count));
1372 if(count == 0)
1373 count = 8; // change to any non-zero value
1374
1375 handle = (HDWP)HeapAlloc(GetProcessHeap(), 0, sizeof(DWP) + (count-1)*sizeof(WINDOWPOS));
1376 if (!handle)
1377 return 0;
1378
1379 pDWP = (DWP *) handle;
1380 pDWP->actualCount = 0;
1381 pDWP->suggestedCount = count;
1382 pDWP->valid = TRUE;
1383 pDWP->wMagic = DWP_MAGIC;
1384 pDWP->hwndParent = 0;
1385 return handle;
1386}
1387/***********************************************************************
1388 * DeferWindowPos (USER32.128)
1389 *
1390 * TODO: SvL: Does this need to be thread safe?
1391 *
1392 */
1393HDWP WIN32API DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1394 INT x, INT y, INT cx, INT cy,
1395 UINT flags )
1396{
1397 DWP *pDWP;
1398 int i;
1399 HDWP newhdwp = hdwp,retvalue;
1400
1401 pDWP = (DWP *)hdwp;
1402 if (!pDWP) {
1403 SetLastError(ERROR_INVALID_PARAMETER);
1404 return 0;
1405 }
1406
1407 if (hwnd == GetDesktopWindow())
1408 return 0;
1409
1410 if(!IsWindow(hwnd)) {
1411 dprintf(("DeferWindowPos, window %x not found", hwnd));
1412 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1413 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1414 return 0;
1415 }
1416
1417 dprintf(("USER32: DeferWindowPos hdwp %x hwnd %x hwndAfter %x (%d,%d)(%d,%d) %x", hdwp, hwnd, hwndAfter,
1418 x, y, cx, cy, flags));
1419
1420/* Numega Bounds Checker Demo dislikes the following code.
1421 In fact, I've not been able to find any "same parent" requirement in any docu
1422 [AM 980509]
1423 */
1424#if 0
1425 /* All the windows of a DeferWindowPos() must have the same parent */
1426 parent = pWnd->parent->hwndSelf;
1427 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
1428 else if (parent != pDWP->hwndParent)
1429 {
1430 USER_HEAP_FREE( hdwp );
1431 retvalue = 0;
1432 goto END;
1433 }
1434#endif
1435
1436 for (i = 0; i < pDWP->actualCount; i++)
1437 {
1438 if (pDWP->winPos[i].hwnd == hwnd)
1439 {
1440 /* Merge with the other changes */
1441 if (!(flags & SWP_NOZORDER))
1442 {
1443 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1444 }
1445 if (!(flags & SWP_NOMOVE))
1446 {
1447 pDWP->winPos[i].x = x;
1448 pDWP->winPos[i].y = y;
1449 }
1450 if (!(flags & SWP_NOSIZE))
1451 {
1452 pDWP->winPos[i].cx = cx;
1453 pDWP->winPos[i].cy = cy;
1454 }
1455 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1456 SWP_NOZORDER | SWP_NOREDRAW |
1457 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1458 SWP_NOOWNERZORDER);
1459 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1460 SWP_FRAMECHANGED);
1461 retvalue = hdwp;
1462 goto END;
1463 }
1464 }
1465 if (pDWP->actualCount >= pDWP->suggestedCount)
1466 {
1467 //DWP structure already contains WINDOWPOS, allocated with (count-1)
1468 //in BeginDeferWindowPos; pDWP->suggestedCount alloc increases it by one
1469 newhdwp = (HDWP)HeapReAlloc(GetProcessHeap(), 0, (LPVOID)hdwp,
1470 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS));
1471 if (!newhdwp)
1472 {
1473 retvalue = 0;
1474 goto END;
1475 }
1476 pDWP = (DWP *) newhdwp;
1477 pDWP->suggestedCount++;
1478 }
1479 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1480 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1481 pDWP->winPos[pDWP->actualCount].x = x;
1482 pDWP->winPos[pDWP->actualCount].y = y;
1483 pDWP->winPos[pDWP->actualCount].cx = cx;
1484 pDWP->winPos[pDWP->actualCount].cy = cy;
1485 pDWP->winPos[pDWP->actualCount].flags = flags;
1486 pDWP->actualCount++;
1487 retvalue = newhdwp;
1488END:
1489 return retvalue;
1490}
1491//******************************************************************************
1492//******************************************************************************
1493BOOL WIN32API EndDeferWindowPos( HDWP hdwp)
1494{
1495 DWP *pDWP;
1496 WINDOWPOS *winpos;
1497 BOOL res = TRUE;
1498 int i;
1499
1500 pDWP = (DWP *) hdwp;
1501 if (!pDWP) {
1502 dprintf(("**EndDeferWindowPos invalid parameter\n"));
1503 SetLastError(ERROR_INVALID_PARAMETER);
1504 return FALSE;
1505 }
1506 dprintf(("**EndDeferWindowPos for %d windows", pDWP->actualCount));
1507 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1508 {
1509 dprintf(("**EndDeferWindowPos %x (%d,%d) (%d,%d) %x", winpos->hwnd, winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags));
1510 if (!(res = SetWindowPos(winpos->hwnd, winpos->hwndInsertAfter,
1511 winpos->x, winpos->y, winpos->cx,
1512 winpos->cy, winpos->flags )))
1513 break;
1514 }
1515 dprintf(("**EndDeferWindowPos DONE"));
1516 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1517 return res;
1518}
1519//******************************************************************************
1520//******************************************************************************
1521HWND WIN32API ChildWindowFromPoint( HWND hwnd, POINT pt)
1522{
1523 dprintf(("USER32: ChildWindowFromPoint\n"));
1524 return ChildWindowFromPointEx(hwnd, pt, 0);
1525}
1526/*****************************************************************************
1527 * Name : HWND WIN32API ChildWindowFromPointEx
1528 * Purpose : pt: client coordinates
1529 * Parameters:
1530 * Variables :
1531 * Result : If the function succeeds, the return value is the window handle.
1532 * If the function fails, the return value is zero
1533 * Remark :
1534 * Status : COMPLETELY IMPLEMENTED AND TESTED
1535 *
1536 * Author : Rene Pronk [Sun, 1999/08/08 23:30]
1537 *****************************************************************************/
1538HWND WIN32API ChildWindowFromPointEx (HWND hwndParent, POINT pt, UINT uFlags)
1539{
1540 RECT rect;
1541 HWND hWnd;
1542
1543 dprintf(("ChildWindowFromPointEx(%08xh,%08xh,%08xh).\n",
1544 hwndParent, pt, uFlags));
1545
1546 if (GetWindowRect (hwndParent, &rect) == 0) {
1547 // oops, invalid handle
1548 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1549 return NULL;
1550 }
1551
1552 ClientToScreen(hwndParent, &pt);
1553 if (PtInRect (&rect, pt) == 0) {
1554 // point is outside window
1555 return NULL;
1556 }
1557
1558 // get first child
1559 hWnd = GetWindow (hwndParent, GW_CHILD);
1560
1561 while (hWnd != NULL)
1562 {
1563 // do I need to skip this window?
1564 if (((uFlags & CWP_SKIPINVISIBLE) &&
1565 (IsWindowVisible (hWnd) == FALSE)) ||
1566 ((uFlags & CWP_SKIPDISABLED) &&
1567 (IsWindowEnabled (hWnd) == FALSE)) ||
1568 ((uFlags & CWP_SKIPTRANSPARENT) &&
1569 (GetWindowLongA (hWnd, GWL_EXSTYLE) & WS_EX_TRANSPARENT)))
1570 {
1571 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1572 continue;
1573 }
1574
1575 // is the point in this window's rect?
1576 GetWindowRect (hWnd, &rect);
1577 if (PtInRect (&rect,pt) == FALSE) {
1578 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1579 continue;
1580 }
1581
1582 dprintf(("ChildWindowFromPointEx returned %x", hWnd));
1583 // found it!
1584 return hWnd;
1585 }
1586 // the point is in the parentwindow but the parentwindow has no child
1587 // at this coordinate
1588 dprintf(("ChildWindowFromPointEx returned parent %x", hwndParent));
1589 return hwndParent;
1590}
1591//******************************************************************************
1592//******************************************************************************
1593BOOL WIN32API CloseWindow(HWND hwnd)
1594{
1595 Win32BaseWindow *window;
1596
1597 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1598 if(!window) {
1599 dprintf(("CloseWindow, window %x not found", hwnd));
1600 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1601 return 0;
1602 }
1603 dprintf(("CloseWindow %x\n", hwnd));
1604 BOOL ret = window->CloseWindow();
1605 RELEASE_WNDOBJ(window);
1606 return ret;
1607}
1608//******************************************************************************
1609//******************************************************************************
1610static BOOL IsPointInWindow(HWND hwnd, POINT point)
1611{
1612 RECT rectWindow;
1613 DWORD hittest, dwStyle, dwExStyle;
1614
1615 dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1616 dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1617
1618 GetWindowRect(hwnd, &rectWindow);
1619
1620 /* If point is in window, and window is visible, and it */
1621 /* is enabled (or it's a top-level window), then explore */
1622 /* its children. Otherwise, go to the next window. */
1623
1624 if( (dwStyle & WS_VISIBLE) &&
1625 ((dwExStyle & (WS_EX_LAYERED | WS_EX_TRANSPARENT)) != (WS_EX_LAYERED | WS_EX_TRANSPARENT)) &&
1626 (!(dwStyle & WS_DISABLED) || ((dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)) &&
1627 ((point.x >= rectWindow.left) && (point.x < rectWindow.right) &&
1628 (point.y >= rectWindow.top) && (point.y < rectWindow.bottom))
1629#if 1
1630 )
1631#else
1632 &&
1633 (wndPtr->hrgnWnd ? PtInRegion(wndPtr->hrgnWnd, 1))
1634#endif
1635 {
1636 hittest = SendMessageA(hwnd, WM_NCHITTEST, 0, MAKELONG(point.x, point.y));
1637 if(hittest != HTTRANSPARENT) {
1638 return TRUE;
1639 }
1640 }
1641 return FALSE;
1642}
1643//******************************************************************************
1644//TODO: Does this return handles of hidden or disabled windows?
1645//******************************************************************************
1646HWND WIN32API WindowFromPoint( POINT point)
1647{
1648 HWND hwndOS2, hwnd;
1649 POINT wPoint;
1650
1651 wPoint.x = point.x;
1652 wPoint.y = mapScreenY(point.y);
1653
1654 hwndOS2 = OSLibWinWindowFromPoint(OSLIB_HWND_DESKTOP, (PVOID)&wPoint);
1655 if(hwndOS2)
1656 {
1657 hwnd = OS2ToWin32Handle(hwndOS2);
1658 while(hwnd)
1659 {
1660 if(IsPointInWindow(hwnd, point)) {
1661 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwnd));
1662 return hwnd;
1663 }
1664 //try siblings
1665 HWND hwndSibling;
1666 HWND hwndParent = GetParent(hwnd);
1667
1668 if(hwndParent) {
1669 hwndSibling = GetWindow(hwndParent, GW_CHILD);
1670 while(hwndSibling) {
1671 if(hwndSibling != hwnd) {
1672 if(IsPointInWindow(hwndSibling, point)) {
1673 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwndSibling));
1674 return hwndSibling;
1675 }
1676 }
1677 hwndSibling = GetWindow(hwndSibling, GW_HWNDNEXT);
1678 }
1679 }
1680 hwnd = hwndParent;
1681 }
1682 }
1683 dprintf(("WindowFromPoint (%d,%d) %x->1\n", point.x, point.y, hwndOS2));
1684 return windowDesktop->getWindowHandle();
1685}
1686//******************************************************************************
1687//******************************************************************************
1688BOOL WIN32API IsWindowUnicode(HWND hwnd)
1689{
1690 Win32BaseWindow *window;
1691
1692 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1693 if(!window) {
1694 dprintf(("IsWindowUnicode, window %x not found", hwnd));
1695 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1696 return 0;
1697 }
1698 BOOL ret = window->IsWindowUnicode();
1699 RELEASE_WNDOBJ(window);
1700 return ret;
1701}
1702/***********************************************************************
1703 * SwitchToThisWindow (USER32.539)
1704 */
1705DWORD WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
1706{
1707 return ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
1708}
1709//******************************************************************************
1710//******************************************************************************
1711BOOL WIN32API EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
1712{
1713 return windowDesktop->EnumThreadWindows(dwThreadId, lpfn, lParam);
1714}
1715//******************************************************************************
1716//******************************************************************************
1717BOOL WIN32API EnumChildWindows(HWND hwnd, WNDENUMPROC lpfn, LPARAM lParam)
1718{
1719 Win32BaseWindow *window;
1720 BOOL ret = TRUE;
1721 ULONG henum;
1722 HWND hwndNext;
1723
1724 if(lpfn == NULL) {
1725 dprintf(("EnumChildWindows invalid parameter %x %x\n", hwnd, lParam));
1726 SetLastError(ERROR_INVALID_PARAMETER);
1727 return FALSE;
1728 }
1729 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1730 if(!window) {
1731 dprintf(("EnumChildWindows, window %x not found", hwnd));
1732 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1733 return FALSE;
1734 }
1735 ret = window->EnumChildWindows(lpfn, lParam);
1736 RELEASE_WNDOBJ(window);
1737 return ret;
1738}
1739//******************************************************************************
1740//******************************************************************************
1741BOOL WIN32API EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
1742{
1743 return windowDesktop->EnumWindows(lpfn, lParam);
1744}
1745//******************************************************************************
1746//******************************************************************************
1747UINT WIN32API ArrangeIconicWindows( HWND hwnd)
1748{
1749 dprintf(("USER32: ArrangeIconicWindows %x", hwnd));
1750 return O32_ArrangeIconicWindows(Win32ToOS2Handle(hwnd));
1751}
1752//******************************************************************************
1753//restores iconized window to previous size/position
1754//******************************************************************************
1755BOOL WIN32API OpenIcon(HWND hwnd)
1756{
1757 dprintf(("USER32: OpenIcon %x", hwnd));
1758
1759 if(!IsIconic(hwnd))
1760 return FALSE;
1761 ShowWindow(hwnd, SW_SHOWNORMAL);
1762 return TRUE;
1763}
1764//******************************************************************************
1765//SDK: Windows can only be shown with ShowOwnedPopups if they were previously
1766// hidden with the same api
1767//TODO: -> needs testing
1768//******************************************************************************
1769BOOL WIN32API ShowOwnedPopups(HWND hwndOwner, BOOL fShow)
1770{
1771 Win32BaseWindow *window, *owner;
1772 HWND hwnd;
1773
1774 owner = Win32BaseWindow::GetWindowFromHandle(hwndOwner);
1775 if(!owner) {
1776 dprintf(("ShowOwnedPopups, window %x not found", hwndOwner));
1777 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1778 return FALSE;
1779 }
1780 dprintf(("USER32: ShowOwnedPopups %x %d", hwndOwner, fShow));
1781
1782 hwnd = GetWindow(GetDesktopWindow(), GW_CHILD);
1783 while(hwnd) {
1784 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1785 if(window) {
1786 if(window == owner && (window->getStyle() & WS_POPUP))
1787 {
1788 if(fShow) {
1789 if(window->getFlags() & WIN_NEEDS_SHOW_OWNEDPOPUP)
1790 {
1791 /*
1792 * In Windows, ShowOwnedPopups(TRUE) generates WM_SHOWWINDOW messages with SW_PARENTOPENING,
1793 * regardless of the state of the owner
1794 */
1795 SendMessageA(hwnd, WM_SHOWWINDOW, SW_SHOW, SW_PARENTOPENING);
1796 window->setFlags(window->getFlags() & ~WIN_NEEDS_SHOW_OWNEDPOPUP);
1797 }
1798 }
1799 else
1800 {
1801 if(IsWindowVisible(hwnd))
1802 {
1803 /*
1804 * In Windows, ShowOwnedPopups(FALSE) generates WM_SHOWWINDOW messages with SW_PARENTCLOSING,
1805 * regardless of the state of the owner
1806 */
1807 SendMessageA(hwnd, WM_SHOWWINDOW, SW_HIDE, SW_PARENTCLOSING);
1808 window->setFlags(window->getFlags() | WIN_NEEDS_SHOW_OWNEDPOPUP);
1809 }
1810 }
1811 }
1812 RELEASE_WNDOBJ(window);
1813 }
1814 else dprintf(("WARNING: window %x is not valid", hwnd));
1815
1816 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1817 }
1818 RELEASE_WNDOBJ(owner);
1819 return TRUE;
1820}
1821//******************************************************************************
1822//******************************************************************************
1823HWND WIN32API GetForegroundWindow(void)
1824{
1825 HWND hwnd;
1826
1827 hwnd = OS2ToWin32Handle(OSLibWinQueryActiveWindow());
1828 dprintf(("USER32: GetForegroundWindow returned %x", hwnd));
1829 return hwnd;
1830}
1831//******************************************************************************
1832//******************************************************************************
1833HWND WIN32API GetLastActivePopup( HWND hWnd)
1834{
1835 HWND hwnd;
1836
1837 hwnd = Win32ToOS2Handle(hWnd);
1838 hwnd = OS2ToWin32Handle(O32_GetLastActivePopup(hwnd));
1839
1840 dprintf(("GetLastActivePopup %x returned %x NOT CORRECTLY IMPLEMENTED", hWnd, hwnd));
1841 return hwnd;
1842}
1843//******************************************************************************
1844//******************************************************************************
1845DWORD WIN32API GetWindowThreadProcessId(HWND hWnd, PDWORD lpdwProcessId)
1846{
1847 dprintf2(("USER32: GetWindowThreadProcessId"));
1848 hWnd = Win32ToOS2Handle(hWnd);
1849
1850 return O32_GetWindowThreadProcessId(hWnd,lpdwProcessId);
1851}
1852//******************************************************************************
1853//******************************************************************************
1854DWORD WIN32API GetWindowContextHelpId(HWND hwnd)
1855{
1856 Win32BaseWindow *window;
1857
1858 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1859 if(!window) {
1860 dprintf(("GetWindowContextHelpId, window %x not found", hwnd));
1861 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1862 return 0;
1863 }
1864 dprintf(("GetWindowContextHelpId %x", hwnd));
1865 DWORD ret = window->getWindowContextHelpId();
1866 RELEASE_WNDOBJ(window);
1867 return ret;
1868}
1869//******************************************************************************
1870//******************************************************************************
1871BOOL WIN32API SetWindowContextHelpId(HWND hwnd, DWORD dwContextHelpId)
1872{
1873 Win32BaseWindow *window;
1874
1875 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1876 if(!window) {
1877 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
1878 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1879 return 0;
1880 }
1881 dprintf(("SetWindowContextHelpId %x %d", hwnd, dwContextHelpId));
1882 window->setWindowContextHelpId(dwContextHelpId);
1883 RELEASE_WNDOBJ(window);
1884 return(TRUE);
1885}
1886//******************************************************************************
1887//******************************************************************************
1888HANDLE WINAPI GetPropA( HWND hwnd, LPCSTR str )
1889{
1890 Win32BaseWindow *window;
1891
1892 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1893 if(!window) {
1894 dprintf(("GetPropA, window %x not found", hwnd));
1895 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1896 return 0;
1897 }
1898 HANDLE ret = window->getProp(str);
1899 RELEASE_WNDOBJ(window);
1900 return ret;
1901}
1902//******************************************************************************
1903//******************************************************************************
1904HANDLE WINAPI GetPropW( HWND hwnd, LPCWSTR str )
1905{
1906 LPSTR strA;
1907 HANDLE ret;
1908
1909 if (!HIWORD(str)) return GetPropA( hwnd, (LPCSTR)(UINT)LOWORD(str) );
1910 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
1911 ret = GetPropA( hwnd, strA );
1912 HeapFree( GetProcessHeap(), 0, strA );
1913 return ret;
1914}
1915//******************************************************************************
1916//******************************************************************************
1917BOOL WINAPI SetPropA( HWND hwnd, LPCSTR str, HANDLE handle )
1918{
1919 Win32BaseWindow *window;
1920
1921 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1922 if(!window) {
1923 dprintf(("SetPropA, window %x not found", hwnd));
1924 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1925 return FALSE;
1926 }
1927 BOOL ret = window->setProp(str, handle);
1928 RELEASE_WNDOBJ(window);
1929 return ret;
1930}
1931//******************************************************************************
1932//******************************************************************************
1933BOOL WINAPI SetPropW( HWND hwnd, LPCWSTR str, HANDLE handle )
1934{
1935 BOOL ret;
1936 LPSTR strA;
1937
1938 if (!HIWORD(str))
1939 return SetPropA( hwnd, (LPCSTR)(UINT)LOWORD(str), handle );
1940 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
1941 ret = SetPropA( hwnd, strA, handle );
1942 HeapFree( GetProcessHeap(), 0, strA );
1943 return ret;
1944}
1945//******************************************************************************
1946//******************************************************************************
1947HANDLE WINAPI RemovePropA( HWND hwnd, LPCSTR str )
1948{
1949 Win32BaseWindow *window;
1950
1951 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1952 if(!window) {
1953 dprintf(("RemovePropA, window %x not found", hwnd));
1954 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1955 return 0;
1956 }
1957 HANDLE ret = window->removeProp(str);
1958 RELEASE_WNDOBJ(window);
1959 return ret;
1960}
1961//******************************************************************************
1962//******************************************************************************
1963HANDLE WINAPI RemovePropW( HWND hwnd, LPCWSTR str )
1964{
1965 LPSTR strA;
1966 HANDLE ret;
1967
1968 if (!HIWORD(str))
1969 return RemovePropA( hwnd, (LPCSTR)(UINT)LOWORD(str) );
1970 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
1971 ret = RemovePropA( hwnd, strA );
1972 HeapFree( GetProcessHeap(), 0, strA );
1973 return ret;
1974}
1975//******************************************************************************
1976//******************************************************************************
1977INT WINAPI EnumPropsA( HWND hwnd, PROPENUMPROCA func )
1978{
1979 return EnumPropsExA( hwnd, (PROPENUMPROCEXA)func, 0 );
1980}
1981//******************************************************************************
1982//******************************************************************************
1983INT WINAPI EnumPropsW( HWND hwnd, PROPENUMPROCW func )
1984{
1985 return EnumPropsExW( hwnd, (PROPENUMPROCEXW)func, 0 );
1986}
1987//******************************************************************************
1988//******************************************************************************
1989INT WINAPI EnumPropsExA(HWND hwnd, PROPENUMPROCEXA func, LPARAM lParam)
1990{
1991 Win32BaseWindow *window;
1992
1993 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1994 if(!window) {
1995 dprintf(("EnumPropsExA, window %x not found", hwnd));
1996 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1997 return -1;
1998 }
1999 INT ret = window->enumPropsExA(func, lParam);
2000 RELEASE_WNDOBJ(window);
2001 return ret;
2002}
2003//******************************************************************************
2004//******************************************************************************
2005INT WINAPI EnumPropsExW(HWND hwnd, PROPENUMPROCEXW func, LPARAM lParam)
2006{
2007 Win32BaseWindow *window;
2008
2009 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2010 if(!window) {
2011 dprintf(("EnumPropsExA, window %x not found", hwnd));
2012 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2013 return -1;
2014 }
2015 INT ret = window->enumPropsExW(func, lParam);
2016 RELEASE_WNDOBJ(window);
2017 return ret;
2018}
2019//******************************************************************************
2020//******************************************************************************
Note: See TracBrowser for help on using the repository browser.