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

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

logging updates

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