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

Last change on this file since 8848 was 8848, checked in by sandervl, 23 years ago

Added GetAncestor; SetFocus fix

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