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

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

customization updates

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