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

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

focus/activation fixes

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