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

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

PF: SetFocus not allowed on invisible windows

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