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

Last change on this file since 6972 was 6972, checked in by phaller, 24 years ago

enabled low-level keyboard hook

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