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

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

logging fix for CreateWindowExW + fix for dialog template parsing

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