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

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

rewrote some functions

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