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

Last change on this file since 8941 was 8941, checked in by achimha, 23 years ago

adding documentation

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