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

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

logging changes, window title fix (codepage), keyboard fixes

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