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

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

adding documentation

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