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

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

SetFocus fix

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