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

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

ported the Wine MDI control + some menu fixes

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