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

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

CreateFakeWindowEx changes + added DestroyFakeWindow

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