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

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

Changed SetFocus fix; only disallow focus change for minimized and disabled windows.

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