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

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

Fixed reference count leaks

File size: 72.5 KB
Line 
1/* $Id: window.cpp,v 1.120 2002-02-12 18:07:21 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 WIN32API SetFocus(HWND hwnd)
730{
731 Win32BaseWindow *window;
732 Win32BaseWindow *oldfocuswnd;
733 HWND lastFocus, lastFocus_W, hwnd_O, hwndTopParent;
734 BOOL activate, ret;
735 TEB *teb;
736
737 teb = GetThreadTEB();
738 if(teb == NULL) {
739 DebugInt3();
740 return 0;
741 }
742
743 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
744 if(!window) {
745 dprintf(("SetFocus, window %x not found", hwnd));
746 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
747 return 0;
748 }
749
750 hwnd_O = window->getOS2WindowHandle();
751 if(teb->o.odin.hwndFocus) {
752 lastFocus = teb->o.odin.hwndFocus;
753 }
754 else lastFocus = OSLibWinQueryFocus (OSLIB_HWND_DESKTOP);
755
756 hwndTopParent = window->GetTopParent();
757 activate = FALSE;
758 lastFocus_W = OS2ToWin32Handle(lastFocus);
759 if(lastFocus_W) {
760 oldfocuswnd = Win32BaseWindow::GetWindowFromHandle(lastFocus_W);
761 if(lastFocus_W != hwnd && hwndTopParent != oldfocuswnd->GetTopParent()) {
762 activate = TRUE;
763 }
764 RELEASE_WNDOBJ(oldfocuswnd);
765 }
766 else activate = TRUE;
767
768 dprintf(("SetFocus %x (%x) -> %x (%x) act %d", lastFocus_W, lastFocus, hwnd, hwnd_O, activate));
769
770 if(HOOK_CallHooksA(WH_CBT, HCBT_SETFOCUS, hwnd, (LPARAM)lastFocus_W)) {
771 dprintf(("hook cancelled SetFocus call!"));
772 RELEASE_WNDOBJ(window);
773 return 0;
774 }
775
776 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
777 //must delay this function call
778 if(teb->o.odin.fWM_SETFOCUS) {
779 dprintf(("USER32: Delay SetFocus call!"));
780 teb->o.odin.hwndFocus = hwnd;
781 //mp1 = win32 window handle
782 //mp2 = top parent if activation required
783 OSLibPostMessageDirect(hwnd_O, WIN32APP_SETFOCUSMSG, hwnd, (activate) ? hwndTopParent : 0);
784 RELEASE_WNDOBJ(window);
785 return lastFocus_W;
786 }
787 teb->o.odin.hwndFocus = 0;
788 if(!IsWindow(hwnd)) return FALSE; //abort if window destroyed
789
790 //NOTE: Don't always activate the window or else the z-order will be changed!!
791 ret = (OSLibWinSetFocus(OSLIB_HWND_DESKTOP, hwnd_O, activate)) ? lastFocus_W : 0;
792 RELEASE_WNDOBJ(window);
793 return ret;
794}
795//******************************************************************************
796//******************************************************************************
797HWND WIN32API GetFocus()
798{
799 TEB *teb;
800 HWND hwnd;
801
802 teb = GetThreadTEB();
803 if(teb == NULL) {
804 DebugInt3();
805 return 0;
806 }
807 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
808 //If focus was changed during WM_SETFOCUS, the focus window handle is
809 //stored in teb->o.odin.hwndFocus (set back to 0 when delayed SetFocus
810 //is activated)
811 if(teb->o.odin.hwndFocus) {
812 dprintf(("USER32: GetFocus %x (DURING WM_SETFOCUS PROCESSING)", teb->o.odin.hwndFocus));
813 return teb->o.odin.hwndFocus;
814 }
815
816 hwnd = OSLibWinQueryFocus(OSLIB_HWND_DESKTOP);
817 hwnd = OS2ToWin32Handle(hwnd);
818 dprintf(("USER32: GetFocus %x\n", hwnd));
819 return hwnd;
820}
821//******************************************************************************
822//******************************************************************************
823BOOL WIN32API IsZoomed(HWND hwnd)
824{
825 DWORD style;
826
827 style = GetWindowLongA(hwnd, GWL_STYLE);
828 dprintf(("USER32: IsZoomed %x returned %d", hwnd, ((style & WS_MAXIMIZE) != 0)));
829
830 return (style & WS_MAXIMIZE) != 0;
831}
832//******************************************************************************
833//******************************************************************************
834BOOL WIN32API LockWindowUpdate(HWND hwnd)
835{
836 return OSLibWinLockWindowUpdate(Win32ToOS2Handle(hwnd));
837}
838//******************************************************************************
839//******************************************************************************
840BOOL WIN32API GetWindowRect(HWND hwnd, PRECT pRect)
841{
842 Win32BaseWindow *window;
843
844 if(pRect == NULL) {
845 dprintf(("GetWindowRect %x invalid parameter!", hwnd));
846 SetLastError(ERROR_INVALID_PARAMETER);
847 return FALSE;
848 }
849
850 if(hwnd == HWND_DESKTOP) {
851 windowDesktop->addRef();
852 window = windowDesktop;
853 }
854 else window = Win32BaseWindow::GetWindowFromHandle(hwnd);
855
856 if(!window) {
857 dprintf(("GetWindowRect, window %x not found", hwnd));
858 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
859 return FALSE;
860 }
861 *pRect = *window->getWindowRect();
862
863 //convert from parent coordinates to screen (if necessary)
864 if(window->getParent()) {
865 MapWindowPoints(window->getParent()->getWindowHandle(), 0, (PPOINT)pRect, 2);
866 }
867 RELEASE_WNDOBJ(window);
868 dprintf(("GetWindowRect %x (%d,%d) (%d,%d)", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom));
869 return TRUE;
870}
871//******************************************************************************
872//******************************************************************************
873INT WIN32API GetWindowTextLengthA(HWND hwnd)
874{
875 Win32BaseWindow *window;
876
877 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
878 if(!window) {
879 dprintf(("GetWindowTextLengthA, window %x not found", hwnd));
880 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
881 return 0;
882 }
883 dprintf(("GetWindowTextLengthA %x", hwnd));
884 int ret = window->GetWindowTextLengthA();
885 RELEASE_WNDOBJ(window);
886 return ret;
887}
888//******************************************************************************
889//******************************************************************************
890int WIN32API GetWindowTextA( HWND hwnd, LPSTR lpsz, int cch)
891{
892 Win32BaseWindow *window;
893 int rc;
894
895 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
896 if(!window) {
897 dprintf(("GetWindowTextA, window %x not found", hwnd));
898 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
899 return 0;
900 }
901 rc = window->GetWindowTextA(lpsz, cch);
902 dprintf(("GetWindowTextA %x %s", hwnd, lpsz));
903 RELEASE_WNDOBJ(window);
904 return rc;
905}
906//******************************************************************************
907//******************************************************************************
908int WIN32API GetWindowTextLengthW( HWND hwnd)
909{
910 Win32BaseWindow *window;
911
912 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
913 if(!window) {
914 dprintf(("GetWindowTextLengthW, window %x not found", hwnd));
915 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
916 return 0;
917 }
918 dprintf(("GetWindowTextLengthW %x", hwnd));
919 int ret = window->GetWindowTextLengthW();
920 RELEASE_WNDOBJ(window);
921 return ret;
922}
923//******************************************************************************
924//******************************************************************************
925int WIN32API GetWindowTextW(HWND hwnd, LPWSTR lpsz, int cch)
926{
927 Win32BaseWindow *window;
928
929 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
930 if(!window) {
931 dprintf(("GetWindowTextW, window %x not found", hwnd));
932 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
933 return 0;
934 }
935 int rc = window->GetWindowTextW(lpsz, cch);
936 RELEASE_WNDOBJ(window);
937 dprintf(("GetWindowTextW %x %ls", hwnd, lpsz));
938 return rc;
939}
940//******************************************************************************
941//******************************************************************************
942BOOL WIN32API SetWindowTextA(HWND hwnd, LPCSTR lpsz)
943{
944 Win32BaseWindow *window;
945
946 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
947 if(!window) {
948 dprintf(("SetWindowTextA, window %x not found", hwnd));
949 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
950 return 0;
951 }
952 dprintf(("SetWindowTextA %x %s", hwnd, lpsz));
953 BOOL ret = window->SetWindowTextA((LPSTR)lpsz);
954 RELEASE_WNDOBJ(window);
955 return ret;
956}
957//******************************************************************************
958//******************************************************************************
959BOOL WIN32API SetWindowTextW( HWND hwnd, LPCWSTR lpsz)
960{
961 Win32BaseWindow *window;
962
963 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
964 if(!window) {
965 dprintf(("SetWindowTextA, window %x not found", hwnd));
966 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
967 return 0;
968 }
969 dprintf(("SetWindowTextW %x %ls", hwnd, lpsz));
970 BOOL ret = window->SetWindowTextW((LPWSTR)lpsz);
971 RELEASE_WNDOBJ(window);
972 return ret;
973}
974/*******************************************************************
975 * InternalGetWindowText (USER32.326)
976 */
977int WIN32API InternalGetWindowText(HWND hwnd,
978 LPWSTR lpString,
979 INT nMaxCount )
980{
981 dprintf(("USER32: InternalGetWindowText(%08xh,%08xh,%08xh) not properly implemented.\n",
982 hwnd, lpString, nMaxCount));
983
984 return GetWindowTextW(hwnd, lpString,nMaxCount);
985}
986//******************************************************************************
987//TODO: Correct?
988//******************************************************************************
989BOOL WIN32API SetForegroundWindow(HWND hwnd)
990{
991 dprintf((" SetForegroundWindow %x", hwnd));
992
993 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
994}
995//******************************************************************************
996//******************************************************************************
997BOOL WIN32API GetClientRect( HWND hwnd, PRECT pRect)
998{
999 HWND hwndWin32 = hwnd;
1000 Win32BaseWindow *window;
1001
1002 if (!pRect)
1003 {
1004 SetLastError(ERROR_INVALID_PARAMETER);
1005 return FALSE;
1006 }
1007 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1008 if(!window) {
1009 dprintf(("GetClientRect, window %x not found", hwnd));
1010 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1011 return FALSE;
1012 }
1013 window->getClientRect(pRect);
1014 dprintf(("GetClientRect of %X returned (%d,%d) (%d,%d)\n", hwndWin32, pRect->left, pRect->top, pRect->right, pRect->bottom));
1015 RELEASE_WNDOBJ(window);
1016 return TRUE;
1017}
1018//******************************************************************************
1019//******************************************************************************
1020BOOL WIN32API AdjustWindowRect(PRECT rect, DWORD style, BOOL menu)
1021{
1022 return AdjustWindowRectEx(rect, style, menu, 0);
1023}
1024//******************************************************************************
1025//Calculate window rectangle based on given client rectangle, style, menu and extended style
1026//******************************************************************************
1027BOOL WIN32API AdjustWindowRectEx( PRECT rect, DWORD style, BOOL menu, DWORD exStyle)
1028{
1029 if(style == 0 && menu == FALSE && exStyle == 0) {
1030 dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d) -> no change required", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
1031 return TRUE; //nothing needs to be changed (VERIFIED in NT 4)
1032 }
1033 dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d)\n", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
1034 /* Correct the window style */
1035 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
1036 style |= WS_CAPTION;
1037
1038 //SvL: Include WS_POPUP -> otherwise HAS_THINFRAME is true for popup windows
1039 // Also include WS_CHILD -> otherwise HAS_THICKFRAME doesn't work correctly
1040 style &= (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_POPUP);
1041 exStyle &= (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EX_TOOLWINDOW);
1042 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
1043
1044 //Adjust rect outer (Win32BaseWindow::AdjustRectOuter)
1045 if (HAS_THICKFRAME(style,exStyle))
1046 InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
1047 else
1048 if (HAS_DLGFRAME(style,exStyle))
1049 InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
1050 else
1051 if (HAS_THINFRAME(style))
1052 InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
1053
1054 if ((style & WS_CAPTION) == WS_CAPTION)
1055 {
1056 if (exStyle & WS_EX_TOOLWINDOW)
1057 rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
1058 else
1059 rect->top -= GetSystemMetrics(SM_CYCAPTION);
1060 }
1061
1062 if (menu)
1063 rect->top -= GetSystemMetrics(SM_CYMENU);
1064
1065 //Adjust rect inner (Win32BaseWindow::AdjustRectInner)
1066 if(!(style & WS_ICONIC)) {
1067 if (exStyle & WS_EX_CLIENTEDGE)
1068 InflateRect (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
1069
1070 if (exStyle & WS_EX_STATICEDGE)
1071 InflateRect (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
1072
1073 //SvL: scrollbars aren't checked *UNLESS* the style includes a border (any border)
1074 // --> VERIFIED IN NT4, SP6 (fixes MFC apps with scrollbars + bar controls)
1075 if(style & (WS_THICKFRAME|WS_BORDER|WS_DLGFRAME)) {
1076 if (style & WS_VSCROLL) rect->right += GetSystemMetrics(SM_CXVSCROLL);
1077 if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
1078 }
1079 }
1080
1081 dprintf(("AdjustWindowRectEx returned (%d,%d)(%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom));
1082
1083 return TRUE;
1084}
1085//******************************************************************************
1086/* Coordinate Space and Transformation Functions */
1087//******************************************************************************
1088/*******************************************************************
1089 * WINPOS_GetWinOffset
1090 *
1091 * Calculate the offset between the origin of the two windows. Used
1092 * to implement MapWindowPoints.
1093 */
1094static void WINPOS_GetWinOffset( Win32BaseWindow *wndFrom, Win32BaseWindow *wndTo,
1095 POINT *offset )
1096{
1097 Win32BaseWindow *window;
1098
1099 offset->x = offset->y = 0;
1100
1101 /* Translate source window origin to screen coords */
1102 if(wndFrom != windowDesktop)
1103 {
1104 window = wndFrom;
1105 while(window)
1106 {
1107 offset->x += window->getClientRectPtr()->left + window->getWindowRect()->left;
1108 offset->y += window->getClientRectPtr()->top + window->getWindowRect()->top;
1109 window = window->getParent();
1110 }
1111 }
1112
1113 /* Translate origin to destination window coords */
1114 if(wndTo != windowDesktop)
1115 {
1116 window = wndTo;
1117 while(window)
1118 {
1119 offset->x -= window->getClientRectPtr()->left + window->getWindowRect()->left;
1120 offset->y -= window->getClientRectPtr()->top + window->getWindowRect()->top;
1121 window = window->getParent();
1122 }
1123 }
1124}
1125//******************************************************************************
1126//******************************************************************************
1127int WIN32API MapWindowPoints(HWND hwndFrom, HWND hwndTo, LPPOINT lpPoints,
1128 UINT cPoints)
1129{
1130 Win32BaseWindow *wndfrom, *wndto;
1131 int retval = 0;
1132 POINT offset;
1133
1134 SetLastError(0);
1135 if(lpPoints == NULL || cPoints == 0) {
1136 SetLastError(ERROR_INVALID_PARAMETER);
1137 return 0;
1138 }
1139 if(hwndTo == hwndFrom)
1140 return 0; //nothing to do
1141
1142 if(hwndFrom == HWND_DESKTOP)
1143 {
1144 windowDesktop->addRef();
1145 wndfrom = windowDesktop;
1146 }
1147 else {
1148 wndfrom = Win32BaseWindow::GetWindowFromHandle(hwndFrom);
1149 if(!wndfrom) {
1150 dprintf(("MapWindowPoints, window %x not found", hwndFrom));
1151 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1152 return 0;
1153 }
1154 }
1155
1156 if(hwndTo == HWND_DESKTOP)
1157 {
1158 windowDesktop->addRef();
1159 wndto = windowDesktop;
1160 }
1161 else {
1162 wndto = Win32BaseWindow::GetWindowFromHandle(hwndTo);
1163 if(!wndto) {
1164 dprintf(("MapWindowPoints, window %x not found", hwndTo));
1165 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1166 return 0;
1167 }
1168 }
1169
1170 dprintf2(("USER32: MapWindowPoints %x to %x (%d,%d) (%d)", hwndFrom, hwndTo, lpPoints->x, lpPoints->y, cPoints));
1171 WINPOS_GetWinOffset(wndfrom, wndto, &offset);
1172
1173 RELEASE_WNDOBJ(wndto);
1174 RELEASE_WNDOBJ(wndfrom);
1175 for(int i=0;i<cPoints;i++)
1176 {
1177 lpPoints[i].x += offset.x;
1178 lpPoints[i].y += offset.y;
1179 }
1180 retval = ((LONG)offset.y << 16) | offset.x;
1181 return retval;
1182}
1183//******************************************************************************
1184//******************************************************************************
1185BOOL WIN32API ScreenToClient(HWND hwnd, LPPOINT pt)
1186{
1187 PRECT rcl;
1188 BOOL rc;
1189
1190 if(hwnd == HWND_DESKTOP) {
1191 return (TRUE); //nothing to do
1192 }
1193 if (!IsWindow(hwnd)) {
1194 dprintf(("warning: ScreenToClient: window %x not found!", hwnd));
1195 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1196 return FALSE;
1197 }
1198 SetLastError(0);
1199#ifdef DEBUG
1200 POINT tmp = *pt;
1201#endif
1202 MapWindowPoints(0, hwnd, pt, 1);
1203 dprintf2(("ScreenToClient %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
1204 return TRUE;
1205}
1206//******************************************************************************
1207//******************************************************************************
1208HWND WIN32API GetDesktopWindow(void)
1209{
1210 HWND hDesktopWindow = windowDesktop->getWindowHandle();
1211 dprintf2(("USER32: GetDesktopWindow, returned %x\n", hDesktopWindow));
1212 return hDesktopWindow;
1213}
1214//******************************************************************************
1215//******************************************************************************
1216HWND WIN32API FindWindowA(LPCSTR lpszClass, LPCSTR lpszWindow)
1217{
1218 return FindWindowExA( NULL, NULL, lpszClass, lpszWindow );
1219}
1220//******************************************************************************
1221//******************************************************************************
1222HWND WIN32API FindWindowW( LPCWSTR lpClassName, LPCWSTR lpWindowName)
1223{
1224 return FindWindowExW( NULL, NULL, lpClassName, lpWindowName );
1225}
1226//******************************************************************************
1227//******************************************************************************
1228HWND WIN32API FindWindowExA(HWND hwndParent, HWND hwndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow)
1229{
1230 ATOM atom = 0;
1231
1232 if (lpszClass)
1233 {
1234 /* If the atom doesn't exist, then no class */
1235 /* with this name exists either. */
1236 if (!(atom = GlobalFindAtomA( lpszClass )))
1237 {
1238 SetLastError(ERROR_CANNOT_FIND_WND_CLASS);
1239 return 0;
1240 }
1241 }
1242 return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, atom, (LPSTR)lpszWindow);
1243}
1244/*****************************************************************************
1245 * Name : HWND WIN32API FindWindowExW
1246 * Purpose : The FindWindowEx function retrieves the handle of a window whose
1247 * class name and window name match the specified strings. The
1248 * function searches child windows, beginning with the one following
1249 * the given child window.
1250 * Parameters: HWND hwndParent handle of parent window
1251 * HWND hwndChildAfter handle of a child window
1252 * LPCTSTR lpszClass address of class name
1253 * LPCTSTR lpszWindow address of window name
1254 * Variables :
1255 * Result : If the function succeeds, the return value is the handle of the
1256 * window that has the specified class and window names.
1257 * If the function fails, the return value is NULL. To get extended
1258 * error information, call GetLastError.
1259 * Remark :
1260 *
1261 *****************************************************************************/
1262
1263HWND WIN32API FindWindowExW(HWND hwndParent,
1264 HWND hwndChildAfter,
1265 LPCWSTR lpszClass,
1266 LPCWSTR lpszWindow)
1267{
1268 ATOM atom = 0;
1269 char *buffer;
1270 HWND hwnd;
1271
1272 if (lpszClass)
1273 {
1274 /* If the atom doesn't exist, then no class */
1275 /* with this name exists either. */
1276 if (!(atom = GlobalFindAtomW( lpszClass )))
1277 {
1278 SetLastError(ERROR_CANNOT_FIND_WND_CLASS);
1279 return 0;
1280 }
1281 }
1282 buffer = HEAP_strdupWtoA( GetProcessHeap(), 0, lpszWindow );
1283 hwnd = Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, atom, buffer);
1284 HeapFree( GetProcessHeap(), 0, buffer );
1285 return hwnd;
1286}
1287//******************************************************************************
1288//******************************************************************************
1289BOOL WIN32API FlashWindow(HWND hwnd, BOOL fFlash)
1290{
1291 dprintf(("FlashWindow %x %d\n", hwnd, fFlash));
1292// return OSLibWinFlashWindow(Win32ToOS2Handle(hwnd), fFlash);
1293 return 1;
1294}
1295//******************************************************************************
1296//******************************************************************************
1297BOOL WIN32API MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
1298 BOOL repaint )
1299{
1300 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
1301
1302 if (!repaint) flags |= SWP_NOREDRAW;
1303 dprintf(("MoveWindow: %x %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint ));
1304
1305 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
1306}
1307//******************************************************************************
1308//******************************************************************************
1309BOOL WIN32API ClientToScreen (HWND hwnd, PPOINT pt)
1310{
1311 PRECT rcl;
1312
1313 if(hwnd == HWND_DESKTOP) {
1314 return(TRUE); //nothing to do
1315 }
1316 if(!IsWindow(hwnd)) {
1317 dprintf(("warning: ClientToScreen window %x not found!", hwnd));
1318 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1319 return (FALSE);
1320 }
1321#ifdef DEBUG
1322 POINT tmp = *pt;
1323#endif
1324 MapWindowPoints(hwnd, 0, pt, 1);
1325 dprintf2(("ClientToScreen %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
1326
1327 return TRUE;
1328}
1329//******************************************************************************
1330//Note: count 0 is a legal parameter (verified in NT4)
1331//******************************************************************************
1332HDWP WIN32API BeginDeferWindowPos(int count)
1333{
1334 HDWP handle;
1335 DWP *pDWP;
1336
1337 if (count < 0)
1338 {
1339 dprintf(("USER32: BeginDeferWindowPos invalid param %d", count));
1340 SetLastError(ERROR_INVALID_PARAMETER);
1341 return 0;
1342 }
1343 dprintf(("USER32: BeginDeferWindowPos %d", count));
1344 if(count == 0)
1345 count = 8; // change to any non-zero value
1346
1347 handle = (HDWP)HeapAlloc(GetProcessHeap(), 0, sizeof(DWP) + (count-1)*sizeof(WINDOWPOS));
1348 if (!handle)
1349 return 0;
1350
1351 pDWP = (DWP *) handle;
1352 pDWP->actualCount = 0;
1353 pDWP->suggestedCount = count;
1354 pDWP->valid = TRUE;
1355 pDWP->wMagic = DWP_MAGIC;
1356 pDWP->hwndParent = 0;
1357 return handle;
1358}
1359/***********************************************************************
1360 * DeferWindowPos (USER32.128)
1361 *
1362 * TODO: SvL: Does this need to be thread safe?
1363 *
1364 */
1365HDWP WIN32API DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1366 INT x, INT y, INT cx, INT cy,
1367 UINT flags )
1368{
1369 DWP *pDWP;
1370 int i;
1371 HDWP newhdwp = hdwp,retvalue;
1372
1373 pDWP = (DWP *)hdwp;
1374 if (!pDWP) {
1375 SetLastError(ERROR_INVALID_PARAMETER);
1376 return 0;
1377 }
1378
1379 if (hwnd == GetDesktopWindow())
1380 return 0;
1381
1382 if(!IsWindow(hwnd)) {
1383 dprintf(("DeferWindowPos, window %x not found", hwnd));
1384 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1385 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1386 return 0;
1387 }
1388
1389 dprintf(("USER32: DeferWindowPos hdwp %x hwnd %x hwndAfter %x (%d,%d)(%d,%d) %x", hdwp, hwnd, hwndAfter,
1390 x, y, cx, cy, flags));
1391
1392/* Numega Bounds Checker Demo dislikes the following code.
1393 In fact, I've not been able to find any "same parent" requirement in any docu
1394 [AM 980509]
1395 */
1396#if 0
1397 /* All the windows of a DeferWindowPos() must have the same parent */
1398 parent = pWnd->parent->hwndSelf;
1399 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
1400 else if (parent != pDWP->hwndParent)
1401 {
1402 USER_HEAP_FREE( hdwp );
1403 retvalue = 0;
1404 goto END;
1405 }
1406#endif
1407
1408 for (i = 0; i < pDWP->actualCount; i++)
1409 {
1410 if (pDWP->winPos[i].hwnd == hwnd)
1411 {
1412 /* Merge with the other changes */
1413 if (!(flags & SWP_NOZORDER))
1414 {
1415 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1416 }
1417 if (!(flags & SWP_NOMOVE))
1418 {
1419 pDWP->winPos[i].x = x;
1420 pDWP->winPos[i].y = y;
1421 }
1422 if (!(flags & SWP_NOSIZE))
1423 {
1424 pDWP->winPos[i].cx = cx;
1425 pDWP->winPos[i].cy = cy;
1426 }
1427 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1428 SWP_NOZORDER | SWP_NOREDRAW |
1429 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1430 SWP_NOOWNERZORDER);
1431 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1432 SWP_FRAMECHANGED);
1433 retvalue = hdwp;
1434 goto END;
1435 }
1436 }
1437 if (pDWP->actualCount >= pDWP->suggestedCount)
1438 {
1439 //DWP structure already contains WINDOWPOS, allocated with (count-1)
1440 //in BeginDeferWindowPos; pDWP->suggestedCount alloc increases it by one
1441 newhdwp = (HDWP)HeapReAlloc(GetProcessHeap(), 0, (LPVOID)hdwp,
1442 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS));
1443 if (!newhdwp)
1444 {
1445 retvalue = 0;
1446 goto END;
1447 }
1448 pDWP = (DWP *) newhdwp;
1449 pDWP->suggestedCount++;
1450 }
1451 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1452 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1453 pDWP->winPos[pDWP->actualCount].x = x;
1454 pDWP->winPos[pDWP->actualCount].y = y;
1455 pDWP->winPos[pDWP->actualCount].cx = cx;
1456 pDWP->winPos[pDWP->actualCount].cy = cy;
1457 pDWP->winPos[pDWP->actualCount].flags = flags;
1458 pDWP->actualCount++;
1459 retvalue = newhdwp;
1460END:
1461 return retvalue;
1462}
1463//******************************************************************************
1464//******************************************************************************
1465BOOL WIN32API EndDeferWindowPos( HDWP hdwp)
1466{
1467 DWP *pDWP;
1468 WINDOWPOS *winpos;
1469 BOOL res = TRUE;
1470 int i;
1471
1472 pDWP = (DWP *) hdwp;
1473 if (!pDWP) {
1474 dprintf(("**EndDeferWindowPos invalid parameter\n"));
1475 SetLastError(ERROR_INVALID_PARAMETER);
1476 return FALSE;
1477 }
1478 dprintf(("**EndDeferWindowPos for %d windows", pDWP->actualCount));
1479 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1480 {
1481 dprintf(("**EndDeferWindowPos %x (%d,%d) (%d,%d) %x", winpos->hwnd, winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags));
1482 if (!(res = SetWindowPos(winpos->hwnd, winpos->hwndInsertAfter,
1483 winpos->x, winpos->y, winpos->cx,
1484 winpos->cy, winpos->flags )))
1485 break;
1486 }
1487 dprintf(("**EndDeferWindowPos DONE"));
1488 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1489 return res;
1490}
1491//******************************************************************************
1492//******************************************************************************
1493HWND WIN32API ChildWindowFromPoint( HWND hwnd, POINT pt)
1494{
1495 dprintf(("USER32: ChildWindowFromPoint\n"));
1496 return ChildWindowFromPointEx(hwnd, pt, 0);
1497}
1498/*****************************************************************************
1499 * Name : HWND WIN32API ChildWindowFromPointEx
1500 * Purpose : pt: client coordinates
1501 * Parameters:
1502 * Variables :
1503 * Result : If the function succeeds, the return value is the window handle.
1504 * If the function fails, the return value is zero
1505 * Remark :
1506 * Status : COMPLETELY IMPLEMENTED AND TESTED
1507 *
1508 * Author : Rene Pronk [Sun, 1999/08/08 23:30]
1509 *****************************************************************************/
1510HWND WIN32API ChildWindowFromPointEx (HWND hwndParent, POINT pt, UINT uFlags)
1511{
1512 RECT rect;
1513 HWND hWnd;
1514
1515 dprintf(("ChildWindowFromPointEx(%08xh,%08xh,%08xh).\n",
1516 hwndParent, pt, uFlags));
1517
1518 if (GetWindowRect (hwndParent, &rect) == 0) {
1519 // oops, invalid handle
1520 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1521 return NULL;
1522 }
1523
1524 ClientToScreen(hwndParent, &pt);
1525 if (PtInRect (&rect, pt) == 0) {
1526 // point is outside window
1527 return NULL;
1528 }
1529
1530 // get first child
1531 hWnd = GetWindow (hwndParent, GW_CHILD);
1532
1533 while (hWnd != NULL)
1534 {
1535 // do I need to skip this window?
1536 if (((uFlags & CWP_SKIPINVISIBLE) &&
1537 (IsWindowVisible (hWnd) == FALSE)) ||
1538 ((uFlags & CWP_SKIPDISABLED) &&
1539 (IsWindowEnabled (hWnd) == FALSE)) ||
1540 ((uFlags & CWP_SKIPTRANSPARENT) &&
1541 (GetWindowLongA (hWnd, GWL_EXSTYLE) & WS_EX_TRANSPARENT)))
1542 {
1543 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1544 continue;
1545 }
1546
1547 // is the point in this window's rect?
1548 GetWindowRect (hWnd, &rect);
1549 if (PtInRect (&rect,pt) == FALSE) {
1550 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1551 continue;
1552 }
1553
1554 dprintf(("ChildWindowFromPointEx returned %x", hWnd));
1555 // found it!
1556 return hWnd;
1557 }
1558 // the point is in the parentwindow but the parentwindow has no child
1559 // at this coordinate
1560 dprintf(("ChildWindowFromPointEx returned parent %x", hwndParent));
1561 return hwndParent;
1562}
1563//******************************************************************************
1564//******************************************************************************
1565BOOL WIN32API CloseWindow(HWND hwnd)
1566{
1567 Win32BaseWindow *window;
1568
1569 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1570 if(!window) {
1571 dprintf(("CloseWindow, window %x not found", hwnd));
1572 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1573 return 0;
1574 }
1575 dprintf(("CloseWindow %x\n", hwnd));
1576 BOOL ret = window->CloseWindow();
1577 RELEASE_WNDOBJ(window);
1578 return ret;
1579}
1580//******************************************************************************
1581//******************************************************************************
1582static BOOL IsPointInWindow(HWND hwnd, POINT point)
1583{
1584 RECT rectWindow;
1585 DWORD hittest, dwStyle, dwExStyle;
1586
1587 dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1588 dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1589
1590 GetWindowRect(hwnd, &rectWindow);
1591
1592 /* If point is in window, and window is visible, and it */
1593 /* is enabled (or it's a top-level window), then explore */
1594 /* its children. Otherwise, go to the next window. */
1595
1596 if( (dwStyle & WS_VISIBLE) &&
1597 ((dwExStyle & (WS_EX_LAYERED | WS_EX_TRANSPARENT)) != (WS_EX_LAYERED | WS_EX_TRANSPARENT)) &&
1598 (!(dwStyle & WS_DISABLED) || ((dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)) &&
1599 ((point.x >= rectWindow.left) && (point.x < rectWindow.right) &&
1600 (point.y >= rectWindow.top) && (point.y < rectWindow.bottom))
1601#if 1
1602 )
1603#else
1604 &&
1605 (wndPtr->hrgnWnd ? PtInRegion(wndPtr->hrgnWnd, 1))
1606#endif
1607 {
1608 hittest = SendMessageA(hwnd, WM_NCHITTEST, 0, MAKELONG(point.x, point.y));
1609 if(hittest != HTTRANSPARENT) {
1610 return TRUE;
1611 }
1612 }
1613 return FALSE;
1614}
1615//******************************************************************************
1616//TODO: Does this return handles of hidden or disabled windows?
1617//******************************************************************************
1618HWND WIN32API WindowFromPoint( POINT point)
1619{
1620 HWND hwndOS2, hwnd;
1621 POINT wPoint;
1622
1623 wPoint.x = point.x;
1624 wPoint.y = mapScreenY(point.y);
1625
1626 hwndOS2 = OSLibWinWindowFromPoint(OSLIB_HWND_DESKTOP, (PVOID)&wPoint);
1627 if(hwndOS2)
1628 {
1629 hwnd = OS2ToWin32Handle(hwndOS2);
1630 while(hwnd)
1631 {
1632 if(IsPointInWindow(hwnd, point)) {
1633 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwnd));
1634 return hwnd;
1635 }
1636 //try siblings
1637 HWND hwndSibling;
1638 HWND hwndParent = GetParent(hwnd);
1639
1640 if(hwndParent) {
1641 hwndSibling = GetWindow(hwndParent, GW_CHILD);
1642 while(hwndSibling) {
1643 if(hwndSibling != hwnd) {
1644 if(IsPointInWindow(hwndSibling, point)) {
1645 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwndSibling));
1646 return hwndSibling;
1647 }
1648 }
1649 hwndSibling = GetWindow(hwndSibling, GW_HWNDNEXT);
1650 }
1651 }
1652 hwnd = hwndParent;
1653 }
1654 }
1655 dprintf(("WindowFromPoint (%d,%d) %x->1\n", point.x, point.y, hwndOS2));
1656 return windowDesktop->getWindowHandle();
1657}
1658//******************************************************************************
1659//******************************************************************************
1660BOOL WIN32API IsWindowUnicode(HWND hwnd)
1661{
1662 Win32BaseWindow *window;
1663
1664 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1665 if(!window) {
1666 dprintf(("IsWindowUnicode, window %x not found", hwnd));
1667 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1668 return 0;
1669 }
1670 BOOL ret = window->IsWindowUnicode();
1671 RELEASE_WNDOBJ(window);
1672 return ret;
1673}
1674/***********************************************************************
1675 * SwitchToThisWindow (USER32.539)
1676 */
1677DWORD WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
1678{
1679 return ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
1680}
1681//******************************************************************************
1682//******************************************************************************
1683BOOL WIN32API EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
1684{
1685 return windowDesktop->EnumThreadWindows(dwThreadId, lpfn, lParam);
1686}
1687//******************************************************************************
1688//******************************************************************************
1689BOOL WIN32API EnumChildWindows(HWND hwnd, WNDENUMPROC lpfn, LPARAM lParam)
1690{
1691 Win32BaseWindow *window;
1692 BOOL ret = TRUE;
1693 ULONG henum;
1694 HWND hwndNext;
1695
1696 if(lpfn == NULL) {
1697 dprintf(("EnumChildWindows invalid parameter %x %x\n", hwnd, lParam));
1698 SetLastError(ERROR_INVALID_PARAMETER);
1699 return FALSE;
1700 }
1701 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1702 if(!window) {
1703 dprintf(("EnumChildWindows, window %x not found", hwnd));
1704 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1705 return FALSE;
1706 }
1707 ret = window->EnumChildWindows(lpfn, lParam);
1708 RELEASE_WNDOBJ(window);
1709 return ret;
1710}
1711//******************************************************************************
1712//******************************************************************************
1713BOOL WIN32API EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
1714{
1715 return windowDesktop->EnumWindows(lpfn, lParam);
1716}
1717//******************************************************************************
1718//******************************************************************************
1719UINT WIN32API ArrangeIconicWindows( HWND parent)
1720{
1721 RECT rectParent;
1722 HWND hwndChild;
1723 INT x, y, xspacing, yspacing;
1724
1725 dprintf(("USER32: ArrangeIconicWindows %x", parent));
1726 dprintf(("USER32: TODO: icon title!!"));
1727
1728 GetClientRect(parent, &rectParent);
1729 x = rectParent.left;
1730 y = rectParent.bottom;
1731 xspacing = GetSystemMetrics(SM_CXICONSPACING);
1732 yspacing = GetSystemMetrics(SM_CYICONSPACING);
1733
1734 hwndChild = GetWindow( parent, GW_CHILD );
1735 while (hwndChild)
1736 {
1737 if( IsIconic( hwndChild ) )
1738 {
1739// WND *wndPtr = WIN_FindWndPtr(hwndChild);
1740
1741// WINPOS_ShowIconTitle( wndPtr, FALSE );
1742
1743 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
1744 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
1745 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1746// if( IsWindow(hwndChild) )
1747// WINPOS_ShowIconTitle(wndPtr , TRUE );
1748// WIN_ReleaseWndPtr(wndPtr);
1749
1750 if (x <= rectParent.right - xspacing) x += xspacing;
1751 else
1752 {
1753 x = rectParent.left;
1754 y -= yspacing;
1755 }
1756 }
1757 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
1758 }
1759 return yspacing;
1760}
1761//******************************************************************************
1762//restores iconized window to previous size/position
1763//******************************************************************************
1764BOOL WIN32API OpenIcon(HWND hwnd)
1765{
1766 dprintf(("USER32: OpenIcon %x", hwnd));
1767
1768 if(!IsIconic(hwnd))
1769 return FALSE;
1770 ShowWindow(hwnd, SW_SHOWNORMAL);
1771 return TRUE;
1772}
1773//******************************************************************************
1774//SDK: Windows can only be shown with ShowOwnedPopups if they were previously
1775// hidden with the same api
1776//TODO: -> needs testing
1777//******************************************************************************
1778BOOL WIN32API ShowOwnedPopups(HWND hwndOwner, BOOL fShow)
1779{
1780 Win32BaseWindow *window, *owner;
1781 HWND hwnd;
1782
1783 owner = Win32BaseWindow::GetWindowFromHandle(hwndOwner);
1784 if(!owner) {
1785 dprintf(("ShowOwnedPopups, window %x not found", hwndOwner));
1786 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1787 return FALSE;
1788 }
1789 dprintf(("USER32: ShowOwnedPopups %x %d", hwndOwner, fShow));
1790
1791 hwnd = GetWindow(GetDesktopWindow(), GW_CHILD);
1792 while(hwnd) {
1793 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1794 if(window) {
1795 if(window == owner && (window->getStyle() & WS_POPUP))
1796 {
1797 if(fShow) {
1798 if(window->getFlags() & WIN_NEEDS_SHOW_OWNEDPOPUP)
1799 {
1800 /*
1801 * In Windows, ShowOwnedPopups(TRUE) generates WM_SHOWWINDOW messages with SW_PARENTOPENING,
1802 * regardless of the state of the owner
1803 */
1804 SendMessageA(hwnd, WM_SHOWWINDOW, SW_SHOW, SW_PARENTOPENING);
1805 window->setFlags(window->getFlags() & ~WIN_NEEDS_SHOW_OWNEDPOPUP);
1806 }
1807 }
1808 else
1809 {
1810 if(IsWindowVisible(hwnd))
1811 {
1812 /*
1813 * In Windows, ShowOwnedPopups(FALSE) generates WM_SHOWWINDOW messages with SW_PARENTCLOSING,
1814 * regardless of the state of the owner
1815 */
1816 SendMessageA(hwnd, WM_SHOWWINDOW, SW_HIDE, SW_PARENTCLOSING);
1817 window->setFlags(window->getFlags() | WIN_NEEDS_SHOW_OWNEDPOPUP);
1818 }
1819 }
1820 }
1821 RELEASE_WNDOBJ(window);
1822 }
1823 else dprintf(("WARNING: window %x is not valid", hwnd));
1824
1825 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1826 }
1827 RELEASE_WNDOBJ(owner);
1828 return TRUE;
1829}
1830//******************************************************************************
1831//******************************************************************************
1832HWND WIN32API GetForegroundWindow()
1833{
1834 HWND hwnd;
1835
1836 hwnd = OS2ToWin32Handle(OSLibWinQueryActiveWindow());
1837 return hwnd;
1838}
1839//******************************************************************************
1840
1841/******************************************************************************
1842 * The return value identifies the most recently active pop-up window.
1843 * The return value is the same as the hWnd parameter, if any of the
1844 * following conditions are met:
1845 *
1846 * - The window identified by hWnd was most recently active.
1847 * - The window identified by hWnd does not own any pop-up windows.
1848 * - The window identified by hWnd is not a top-level window or it is
1849 * owned by another window.
1850 */
1851HWND WIN32API GetLastActivePopup(HWND hWnd)
1852{
1853 Win32BaseWindow *owner;
1854
1855 owner = Win32BaseWindow::GetWindowFromHandle(hWnd);
1856 if(!owner)
1857 {
1858 dprintf(("GetLastActivePopup, window %x not found", hWnd));
1859 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1860 return hWnd;
1861 }
1862
1863 HWND hwndRetVal = owner->getLastActive();
1864 if (!IsWindow( hwndRetVal ))
1865 hwndRetVal = owner->getWindowHandle();
1866
1867 RELEASE_WNDOBJ(owner);
1868
1869 return hwndRetVal;
1870}
1871//******************************************************************************
1872//******************************************************************************
1873DWORD WIN32API GetWindowThreadProcessId(HWND hwnd, PDWORD lpdwProcessId)
1874{
1875 DWORD dwThreadId;
1876
1877 dwThreadId = O32_GetWindowThreadProcessId(Win32ToOS2Handle(hwnd), lpdwProcessId);
1878 if(dwThreadId == 0) {
1879 dprintf(("!WARNING! GetWindowThreadProcessId %x failed!!", hwnd));
1880 }
1881 return dwThreadId;
1882}
1883//******************************************************************************
1884//******************************************************************************
1885DWORD WIN32API GetWindowContextHelpId(HWND hwnd)
1886{
1887 Win32BaseWindow *window;
1888
1889 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1890 if(!window) {
1891 dprintf(("GetWindowContextHelpId, window %x not found", hwnd));
1892 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1893 return 0;
1894 }
1895 dprintf(("GetWindowContextHelpId %x", hwnd));
1896 DWORD ret = window->getWindowContextHelpId();
1897 RELEASE_WNDOBJ(window);
1898 return ret;
1899}
1900//******************************************************************************
1901//******************************************************************************
1902BOOL WIN32API SetWindowContextHelpId(HWND hwnd, DWORD dwContextHelpId)
1903{
1904 Win32BaseWindow *window;
1905
1906 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1907 if(!window) {
1908 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
1909 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1910 return 0;
1911 }
1912 dprintf(("SetWindowContextHelpId %x %d", hwnd, dwContextHelpId));
1913 window->setWindowContextHelpId(dwContextHelpId);
1914 RELEASE_WNDOBJ(window);
1915 return(TRUE);
1916}
1917//******************************************************************************
1918//******************************************************************************
1919HANDLE WIN32API GetPropA(HWND hwnd, LPCSTR str )
1920{
1921 Win32BaseWindow *window;
1922
1923 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1924 if(!window) {
1925 dprintf(("GetPropA, window %x not found", hwnd));
1926 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1927 return 0;
1928 }
1929 HANDLE ret = window->getProp(str);
1930 RELEASE_WNDOBJ(window);
1931 return ret;
1932}
1933//******************************************************************************
1934//******************************************************************************
1935HANDLE WIN32API GetPropW(HWND hwnd, LPCWSTR str)
1936{
1937 Win32BaseWindow *window;
1938 LPSTR strA;
1939 HANDLE ret;
1940
1941 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1942 if(!window) {
1943 dprintf(("GetPropW, window %x not found", hwnd));
1944 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1945 return 0;
1946 }
1947
1948 if(HIWORD(str)) {
1949 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
1950 }
1951 else strA = (LPSTR)str;
1952
1953 ret = window->getProp(strA);
1954
1955 RELEASE_WNDOBJ(window);
1956 if(HIWORD(str)) HeapFree( GetProcessHeap(), 0, strA );
1957 return ret;
1958}
1959//******************************************************************************
1960//******************************************************************************
1961BOOL WIN32API SetPropA(HWND hwnd, LPCSTR str, HANDLE handle )
1962{
1963 Win32BaseWindow *window;
1964
1965 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1966 if(!window) {
1967 dprintf(("SetPropA, window %x not found", hwnd));
1968 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1969 return FALSE;
1970 }
1971 BOOL ret = window->setProp(str, handle);
1972 RELEASE_WNDOBJ(window);
1973 return ret;
1974}
1975//******************************************************************************
1976//******************************************************************************
1977BOOL SetPropW(HWND hwnd, LPCWSTR str, HANDLE handle )
1978{
1979 BOOL ret;
1980 LPSTR strA;
1981
1982 if (!HIWORD(str))
1983 return SetPropA( hwnd, (LPCSTR)(UINT)LOWORD(str), handle );
1984 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
1985 ret = SetPropA( hwnd, strA, handle );
1986 HeapFree( GetProcessHeap(), 0, strA );
1987 return ret;
1988}
1989//******************************************************************************
1990//******************************************************************************
1991HANDLE WIN32API RemovePropA(HWND hwnd, LPCSTR str)
1992{
1993 Win32BaseWindow *window;
1994
1995 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1996 if(!window) {
1997 dprintf(("RemovePropA, window %x not found", hwnd));
1998 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1999 return 0;
2000 }
2001 HANDLE ret = window->removeProp(str);
2002 RELEASE_WNDOBJ(window);
2003 return ret;
2004}
2005//******************************************************************************
2006//******************************************************************************
2007HANDLE WIN32API RemovePropW(HWND hwnd, LPCWSTR str)
2008{
2009 LPSTR strA;
2010 HANDLE ret;
2011
2012 if (!HIWORD(str))
2013 return RemovePropA( hwnd, (LPCSTR)(UINT)LOWORD(str) );
2014 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
2015 ret = RemovePropA( hwnd, strA );
2016 HeapFree( GetProcessHeap(), 0, strA );
2017 return ret;
2018}
2019//******************************************************************************
2020//******************************************************************************
2021INT WIN32API EnumPropsA(HWND hwnd, PROPENUMPROCA func )
2022{
2023 return EnumPropsExA( hwnd, (PROPENUMPROCEXA)func, 0 );
2024}
2025//******************************************************************************
2026//******************************************************************************
2027INT WIN32API EnumPropsW(HWND hwnd, PROPENUMPROCW func )
2028{
2029 return EnumPropsExW( hwnd, (PROPENUMPROCEXW)func, 0 );
2030}
2031//******************************************************************************
2032//******************************************************************************
2033INT WIN32API EnumPropsExA(HWND hwnd, PROPENUMPROCEXA func, LPARAM lParam)
2034{
2035 Win32BaseWindow *window;
2036
2037 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2038 if(!window) {
2039 dprintf(("EnumPropsExA, window %x not found", hwnd));
2040 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2041 return -1;
2042 }
2043 INT ret = window->enumPropsExA(func, lParam);
2044 RELEASE_WNDOBJ(window);
2045 return ret;
2046}
2047//******************************************************************************
2048//******************************************************************************
2049INT WIN32API EnumPropsExW(HWND hwnd, PROPENUMPROCEXW func, LPARAM lParam)
2050{
2051 Win32BaseWindow *window;
2052
2053 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2054 if(!window) {
2055 dprintf(("EnumPropsExA, window %x not found", hwnd));
2056 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2057 return -1;
2058 }
2059 INT ret = window->enumPropsExW(func, lParam);
2060 RELEASE_WNDOBJ(window);
2061 return ret;
2062}
2063//******************************************************************************
2064//******************************************************************************
2065
2066
2067/*****************************************************************************
2068 * Name : BOOL WIN32API AnyPopup
2069 * Purpose : The AnyPopup function indicates whether an owned, visible,
2070 * top-level pop-up, or overlapped window exists on the screen. The
2071 * function searches the entire Windows screen, not just the calling
2072 * application's client area.
2073 * Parameters: VOID
2074 * Variables :
2075 * Result : If a pop-up window exists, the return value is TRUE even if the
2076 * pop-up window is completely covered by other windows. Otherwise,
2077 * it is FALSE.
2078 * Remark : AnyPopup is a Windows version 1.x function and is retained for
2079 * compatibility purposes. It is generally not useful.
2080 * Status : UNTESTED STUB
2081 *
2082 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
2083 *****************************************************************************/
2084BOOL WIN32API AnyPopup()
2085{
2086 dprintf(("USER32:AnyPopup() not implemented.\n"));
2087
2088 return (FALSE);
2089}
Note: See TracBrowser for help on using the repository browser.