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

Last change on this file since 5060 was 5060, checked in by sandervl, 25 years ago

Get/SetWindowLongA fixes (last error) + focus hack for realplayer 8

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