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

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

scrollbar fix; don't set focus unless it has the WS_TABSTOP style

File size: 72.8 KB
Line 
1/* $Id: window.cpp,v 1.111 2001-10-24 09:53:14 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", className, HIWORD(windowName) ? windowName : NULL, parent, x, y, width, height, style, exStyle));
195 }
196 else dprintf(("CreateWindowExW: class %d name %ls parent %x (%d,%d) (%d,%d), %x %x", className, HIWORD(windowName) ? windowName : NULL, parent, x, y, width, height, style, exStyle));
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 //check visibility of parents
731 hwndParent = GetParent(hwnd);
732 while(hwndParent) {
733 dwStyle = GetWindowLongA(hwndParent, GWL_STYLE);
734 if(!(dwStyle & WS_VISIBLE)) {
735 dprintf(("IsWindowVisible %x returned FALSE (parent %x invisible)", hwnd, hwndParent));
736 return FALSE;
737 }
738 if(!(dwStyle & WS_CHILD)) {
739 break; //GetParent can also return the owner
740 }
741 hwndParent = GetParent(hwndParent);
742 }
743
744end:
745 dprintf(("IsWindowVisible %x returned %d", hwnd, ret));
746 return ret;
747}
748//******************************************************************************
749//******************************************************************************
750ODINFUNCTION1(HWND, SetFocus,
751 HWND, hwnd)
752{
753 Win32BaseWindow *window;
754 Win32BaseWindow *oldfocuswnd;
755 HWND lastFocus, lastFocus_W, hwnd_O, hwndTopParent;
756 BOOL activate;
757 TEB *teb;
758
759 teb = GetThreadTEB();
760 if(teb == NULL) {
761 DebugInt3();
762 return 0;
763 }
764
765 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
766 if(!window) {
767 dprintf(("SetFocus, window %x not found", hwnd));
768 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
769 return 0;
770 }
771
772 hwnd_O = window->getOS2WindowHandle();
773 if(teb->o.odin.hwndFocus) {
774 lastFocus = teb->o.odin.hwndFocus;
775 }
776 else lastFocus = OSLibWinQueryFocus (OSLIB_HWND_DESKTOP);
777
778 hwndTopParent = window->GetTopParent();
779 activate = FALSE;
780 lastFocus_W = OS2ToWin32Handle(lastFocus);
781 if(lastFocus_W) {
782 oldfocuswnd = Win32BaseWindow::GetWindowFromHandle(lastFocus_W);
783 if(lastFocus_W != hwnd && hwndTopParent != oldfocuswnd->GetTopParent()) {
784 activate = TRUE;
785 }
786 RELEASE_WNDOBJ(oldfocuswnd);
787 }
788 else activate = TRUE;
789
790 dprintf(("SetFocus %x (%x) -> %x (%x) act %d", lastFocus_W, lastFocus, hwnd, hwnd_O, activate));
791
792 if(HOOK_CallHooksA(WH_CBT, HCBT_SETFOCUS, hwnd, (LPARAM)lastFocus_W)) {
793 dprintf(("hook cancelled SetFocus call!"));
794 return 0;
795 }
796
797 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
798 //must delay this function call
799 if(teb->o.odin.fWM_SETFOCUS) {
800 dprintf(("USER32: Delay SetFocus call!"));
801 teb->o.odin.hwndFocus = hwnd;
802 //mp1 = win32 window handle
803 //mp2 = top parent if activation required
804 OSLibPostMessageDirect(hwnd_O, WIN32APP_SETFOCUSMSG, hwnd, (activate) ? hwndTopParent : 0);
805 return lastFocus_W;
806 }
807 teb->o.odin.hwndFocus = 0;
808 if(!IsWindow(hwnd)) return FALSE; //abort if window destroyed
809
810 //NOTE: Don't always activate the window or else the z-order will be changed!!
811 return (OSLibWinSetFocus(OSLIB_HWND_DESKTOP, hwnd_O, activate)) ? lastFocus_W : 0;
812}
813//******************************************************************************
814//******************************************************************************
815ODINFUNCTION0(HWND, GetFocus)
816{
817 TEB *teb;
818 HWND hwnd;
819
820 teb = GetThreadTEB();
821 if(teb == NULL) {
822 DebugInt3();
823 return 0;
824 }
825 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
826 //If focus was changed during WM_SETFOCUS, the focus window handle is
827 //stored in teb->o.odin.hwndFocus (set back to 0 when delayed SetFocus
828 //is activated)
829 if(teb->o.odin.hwndFocus) {
830 dprintf(("USER32: GetFocus %x (DURING WM_SETFOCUS PROCESSING)", teb->o.odin.hwndFocus));
831 return teb->o.odin.hwndFocus;
832 }
833
834 hwnd = OSLibWinQueryFocus(OSLIB_HWND_DESKTOP);
835 hwnd = OS2ToWin32Handle(hwnd);
836 dprintf(("USER32: GetFocus %x\n", hwnd));
837 return hwnd;
838}
839//******************************************************************************
840//******************************************************************************
841ODINFUNCTION1(BOOL, IsZoomed,
842 HWND, hwnd)
843{
844 DWORD style;
845
846 style = GetWindowLongA(hwnd, GWL_STYLE);
847 dprintf(("USER32: IsZoomed %x returned %d", hwnd, ((style & WS_MAXIMIZE) != 0)));
848
849 return (style & WS_MAXIMIZE) != 0;
850}
851//******************************************************************************
852//******************************************************************************
853ODINFUNCTION1(BOOL, LockWindowUpdate,
854 HWND, hwnd)
855{
856 return OSLibWinLockWindowUpdate(Win32ToOS2Handle(hwnd));
857}
858//******************************************************************************
859//******************************************************************************
860ODINFUNCTION2(BOOL, GetWindowRect,
861 HWND, hwnd,
862 PRECT, pRect)
863{
864 Win32BaseWindow *window;
865
866 if(pRect == NULL) {
867 dprintf(("GetWindowRect %x invalid parameter!", hwnd));
868 SetLastError(ERROR_INVALID_PARAMETER);
869 return FALSE;
870 }
871
872 if(hwnd == HWND_DESKTOP) {
873 windowDesktop->addRef();
874 window = windowDesktop;
875 }
876 else window = Win32BaseWindow::GetWindowFromHandle(hwnd);
877
878 if(!window) {
879 dprintf(("GetWindowRect, window %x not found", hwnd));
880 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
881 return FALSE;
882 }
883 *pRect = *window->getWindowRect();
884
885 //convert from parent coordinates to screen (if necessary)
886 if(window->getParent()) {
887 MapWindowPoints(window->getParent()->getWindowHandle(), 0, (PPOINT)pRect, 2);
888 }
889 RELEASE_WNDOBJ(window);
890 dprintf(("GetWindowRect %x (%d,%d) (%d,%d)", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom));
891 return TRUE;
892}
893//******************************************************************************
894//******************************************************************************
895ODINFUNCTION1(int, GetWindowTextLengthA,
896 HWND, hwnd)
897{
898 Win32BaseWindow *window;
899
900 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
901 if(!window) {
902 dprintf(("GetWindowTextLengthA, window %x not found", hwnd));
903 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
904 return 0;
905 }
906 dprintf(("GetWindowTextLengthA %x", hwnd));
907 int ret = window->GetWindowTextLengthA();
908 RELEASE_WNDOBJ(window);
909 return ret;
910}
911//******************************************************************************
912//******************************************************************************
913int WIN32API GetWindowTextA( HWND hwnd, LPSTR lpsz, int cch)
914{
915 Win32BaseWindow *window;
916 int rc;
917
918 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
919 if(!window) {
920 dprintf(("GetWindowTextA, window %x not found", hwnd));
921 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
922 return 0;
923 }
924 rc = window->GetWindowTextA(lpsz, cch);
925 dprintf(("GetWindowTextA %x %s", hwnd, lpsz));
926 RELEASE_WNDOBJ(window);
927 return rc;
928}
929//******************************************************************************
930//******************************************************************************
931int WIN32API GetWindowTextLengthW( HWND hwnd)
932{
933 Win32BaseWindow *window;
934
935 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
936 if(!window) {
937 dprintf(("GetWindowTextLengthW, window %x not found", hwnd));
938 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
939 return 0;
940 }
941 dprintf(("GetWindowTextLengthW %x", hwnd));
942 int ret = window->GetWindowTextLengthW();
943 RELEASE_WNDOBJ(window);
944 return ret;
945}
946//******************************************************************************
947//******************************************************************************
948int WIN32API GetWindowTextW(HWND hwnd, LPWSTR lpsz, int cch)
949{
950 Win32BaseWindow *window;
951
952 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
953 if(!window) {
954 dprintf(("GetWindowTextW, window %x not found", hwnd));
955 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
956 return 0;
957 }
958 int rc = window->GetWindowTextW(lpsz, cch);
959 RELEASE_WNDOBJ(window);
960 dprintf(("GetWindowTextW %x %ls", hwnd, lpsz));
961 return rc;
962}
963//******************************************************************************
964//******************************************************************************
965BOOL WIN32API SetWindowTextA(HWND hwnd, LPCSTR lpsz)
966{
967 Win32BaseWindow *window;
968
969 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
970 if(!window) {
971 dprintf(("SetWindowTextA, window %x not found", hwnd));
972 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
973 return 0;
974 }
975 dprintf(("SetWindowTextA %x %s", hwnd, lpsz));
976 BOOL ret = window->SetWindowTextA((LPSTR)lpsz);
977 RELEASE_WNDOBJ(window);
978 return ret;
979}
980//******************************************************************************
981//******************************************************************************
982BOOL WIN32API SetWindowTextW( HWND hwnd, LPCWSTR lpsz)
983{
984 Win32BaseWindow *window;
985
986 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
987 if(!window) {
988 dprintf(("SetWindowTextA, window %x not found", hwnd));
989 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
990 return 0;
991 }
992 dprintf(("SetWindowTextW %x %ls", hwnd, lpsz));
993 BOOL ret = window->SetWindowTextW((LPWSTR)lpsz);
994 RELEASE_WNDOBJ(window);
995 return ret;
996}
997/*******************************************************************
998 * InternalGetWindowText (USER32.326)
999 */
1000int WIN32API InternalGetWindowText(HWND hwnd,
1001 LPWSTR lpString,
1002 INT nMaxCount )
1003{
1004 dprintf(("USER32: InternalGetWindowText(%08xh,%08xh,%08xh) not properly implemented.\n",
1005 hwnd,
1006 lpString,
1007 nMaxCount));
1008
1009 return GetWindowTextW(hwnd,lpString,nMaxCount);
1010}
1011//******************************************************************************
1012//TODO: Correct?
1013//******************************************************************************
1014BOOL WIN32API SetForegroundWindow(HWND hwnd)
1015{
1016 dprintf((" SetForegroundWindow %x", hwnd));
1017
1018 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
1019}
1020//******************************************************************************
1021//******************************************************************************
1022BOOL WIN32API GetClientRect( HWND hwnd, PRECT pRect)
1023{
1024 HWND hwndWin32 = hwnd;
1025 Win32BaseWindow *window;
1026
1027 if (!pRect)
1028 {
1029 SetLastError(ERROR_INVALID_PARAMETER);
1030 return FALSE;
1031 }
1032 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1033 if(!window) {
1034 dprintf(("GetClientRect, window %x not found", hwnd));
1035 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1036 return FALSE;
1037 }
1038 window->getClientRect(pRect);
1039 dprintf(("GetClientRect of %X returned (%d,%d) (%d,%d)\n", hwndWin32, pRect->left, pRect->top, pRect->right, pRect->bottom));
1040 RELEASE_WNDOBJ(window);
1041 return TRUE;
1042}
1043//******************************************************************************
1044//******************************************************************************
1045BOOL WIN32API AdjustWindowRect(PRECT rect, DWORD style, BOOL menu)
1046{
1047 return AdjustWindowRectEx(rect, style, menu, 0);
1048}
1049//******************************************************************************
1050//Calculate window rectangle based on given client rectangle, style, menu and extended style
1051//******************************************************************************
1052BOOL WIN32API AdjustWindowRectEx( PRECT rect, DWORD style, BOOL menu, DWORD exStyle)
1053{
1054 if(style == 0 && menu == FALSE && exStyle == 0) {
1055 dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d) -> no change required", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
1056 return TRUE; //nothing needs to be changed (VERIFIED in NT 4)
1057 }
1058 dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d)\n", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
1059 /* Correct the window style */
1060 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
1061 style |= WS_CAPTION;
1062
1063 //SvL: Include WS_POPUP -> otherwise HAS_THINFRAME is true for popup windows
1064 // Also include WS_CHILD -> otherwise HAS_THICKFRAME doesn't work correctly
1065 style &= (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_POPUP);
1066 exStyle &= (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EX_TOOLWINDOW);
1067 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
1068
1069 //Adjust rect outer (Win32BaseWindow::AdjustRectOuter)
1070 if (HAS_THICKFRAME(style,exStyle))
1071 InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
1072 else
1073 if (HAS_DLGFRAME(style,exStyle))
1074 InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
1075 else
1076 if (HAS_THINFRAME(style))
1077 InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
1078
1079 if ((style & WS_CAPTION) == WS_CAPTION)
1080 {
1081 if (exStyle & WS_EX_TOOLWINDOW)
1082 rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
1083 else
1084 rect->top -= GetSystemMetrics(SM_CYCAPTION);
1085 }
1086
1087 if (menu)
1088 rect->top -= GetSystemMetrics(SM_CYMENU);
1089
1090 //Adjust rect inner (Win32BaseWindow::AdjustRectInner)
1091 if(!(style & WS_ICONIC)) {
1092 if (exStyle & WS_EX_CLIENTEDGE)
1093 InflateRect (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
1094
1095 if (exStyle & WS_EX_STATICEDGE)
1096 InflateRect (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
1097
1098 //SvL: scrollbars aren't checked *UNLESS* the style includes a border (any border)
1099 // --> VERIFIED IN NT4, SP6 (fixes MFC apps with scrollbars + bar controls)
1100 if(style & (WS_THICKFRAME|WS_BORDER|WS_DLGFRAME)) {
1101 if (style & WS_VSCROLL) rect->right += GetSystemMetrics(SM_CXVSCROLL);
1102 if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
1103 }
1104 }
1105
1106 dprintf(("AdjustWindowRectEx returned (%d,%d)(%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom));
1107
1108 return TRUE;
1109}
1110//******************************************************************************
1111/* Coordinate Space and Transformation Functions */
1112//******************************************************************************
1113/*******************************************************************
1114 * WINPOS_GetWinOffset
1115 *
1116 * Calculate the offset between the origin of the two windows. Used
1117 * to implement MapWindowPoints.
1118 */
1119static void WINPOS_GetWinOffset( Win32BaseWindow *wndFrom, Win32BaseWindow *wndTo,
1120 POINT *offset )
1121{
1122 Win32BaseWindow *window;
1123
1124 offset->x = offset->y = 0;
1125
1126 /* Translate source window origin to screen coords */
1127 if(wndFrom != windowDesktop)
1128 {
1129 window = wndFrom;
1130 while(window)
1131 {
1132 offset->x += window->getClientRectPtr()->left + window->getWindowRect()->left;
1133 offset->y += window->getClientRectPtr()->top + window->getWindowRect()->top;
1134 window = window->getParent();
1135 }
1136 }
1137
1138 /* Translate origin to destination window coords */
1139 if(wndTo != windowDesktop)
1140 {
1141 window = wndTo;
1142 while(window)
1143 {
1144 offset->x -= window->getClientRectPtr()->left + window->getWindowRect()->left;
1145 offset->y -= window->getClientRectPtr()->top + window->getWindowRect()->top;
1146 window = window->getParent();
1147 }
1148 }
1149}
1150//******************************************************************************
1151//******************************************************************************
1152int WIN32API MapWindowPoints(HWND hwndFrom, HWND hwndTo, LPPOINT lpPoints,
1153 UINT cPoints)
1154{
1155 Win32BaseWindow *wndfrom, *wndto;
1156 int retval = 0;
1157 POINT offset;
1158
1159 SetLastError(0);
1160 if(lpPoints == NULL || cPoints == 0) {
1161 SetLastError(ERROR_INVALID_PARAMETER);
1162 return 0;
1163 }
1164 if(hwndTo == hwndFrom)
1165 return 0; //nothing to do
1166
1167 if(hwndFrom == HWND_DESKTOP)
1168 {
1169 windowDesktop->addRef();
1170 wndfrom = windowDesktop;
1171 }
1172 else {
1173 wndfrom = Win32BaseWindow::GetWindowFromHandle(hwndFrom);
1174 if(!wndfrom) {
1175 dprintf(("MapWindowPoints, window %x not found", hwndFrom));
1176 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1177 return 0;
1178 }
1179 }
1180
1181 if(hwndTo == HWND_DESKTOP)
1182 {
1183 windowDesktop->addRef();
1184 wndto = windowDesktop;
1185 }
1186 else {
1187 wndto = Win32BaseWindow::GetWindowFromHandle(hwndTo);
1188 if(!wndto) {
1189 dprintf(("MapWindowPoints, window %x not found", hwndTo));
1190 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1191 return 0;
1192 }
1193 }
1194
1195 dprintf2(("USER32: MapWindowPoints %x to %x (%d,%d) (%d)", hwndFrom, hwndTo, lpPoints->x, lpPoints->y, cPoints));
1196 WINPOS_GetWinOffset(wndfrom, wndto, &offset);
1197
1198 RELEASE_WNDOBJ(wndto);
1199 RELEASE_WNDOBJ(wndfrom);
1200 for(int i=0;i<cPoints;i++)
1201 {
1202 lpPoints[i].x += offset.x;
1203 lpPoints[i].y += offset.y;
1204 }
1205 retval = ((LONG)offset.y << 16) | offset.x;
1206 return retval;
1207}
1208//******************************************************************************
1209//******************************************************************************
1210BOOL WIN32API ScreenToClient(HWND hwnd, LPPOINT pt)
1211{
1212 PRECT rcl;
1213 BOOL rc;
1214
1215 if(hwnd == HWND_DESKTOP) {
1216 return (TRUE); //nothing to do
1217 }
1218 if (!IsWindow(hwnd)) {
1219 dprintf(("warning: ScreenToClient: window %x not found!", hwnd));
1220 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1221 return FALSE;
1222 }
1223 SetLastError(0);
1224#ifdef DEBUG
1225 POINT tmp = *pt;
1226#endif
1227 MapWindowPoints(0, hwnd, pt, 1);
1228 dprintf2(("ScreenToClient %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
1229 return TRUE;
1230}
1231//******************************************************************************
1232//******************************************************************************
1233HWND WIN32API GetDesktopWindow(void)
1234{
1235 HWND DesktopWindow = windowDesktop->getWindowHandle();
1236 dprintf2(("USER32: GetDesktopWindow, returned %x\n", DesktopWindow));
1237 return DesktopWindow;
1238}
1239//******************************************************************************
1240//******************************************************************************
1241HWND WIN32API FindWindowA(LPCSTR lpszClass, LPCSTR lpszWindow)
1242{
1243 return FindWindowExA( NULL, NULL, lpszClass, lpszWindow );
1244}
1245//******************************************************************************
1246//******************************************************************************
1247HWND WIN32API FindWindowW( LPCWSTR lpClassName, LPCWSTR lpWindowName)
1248{
1249 return FindWindowExW( NULL, NULL, lpClassName, lpWindowName );
1250}
1251//******************************************************************************
1252//******************************************************************************
1253HWND WIN32API FindWindowExA(HWND hwndParent, HWND hwndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow)
1254{
1255 ATOM atom = 0;
1256
1257 if (lpszClass)
1258 {
1259 /* If the atom doesn't exist, then no class */
1260 /* with this name exists either. */
1261 if (!(atom = GlobalFindAtomA( lpszClass )))
1262 {
1263 SetLastError(ERROR_CANNOT_FIND_WND_CLASS);
1264 return 0;
1265 }
1266 }
1267 return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, atom, (LPSTR)lpszWindow);
1268}
1269/*****************************************************************************
1270 * Name : HWND WIN32API FindWindowExW
1271 * Purpose : The FindWindowEx function retrieves the handle of a window whose
1272 * class name and window name match the specified strings. The
1273 * function searches child windows, beginning with the one following
1274 * the given child window.
1275 * Parameters: HWND hwndParent handle of parent window
1276 * HWND hwndChildAfter handle of a child window
1277 * LPCTSTR lpszClass address of class name
1278 * LPCTSTR lpszWindow address of window name
1279 * Variables :
1280 * Result : If the function succeeds, the return value is the handle of the
1281 * window that has the specified class and window names.
1282 * If the function fails, the return value is NULL. To get extended
1283 * error information, call GetLastError.
1284 * Remark :
1285 *
1286 *****************************************************************************/
1287
1288HWND WIN32API FindWindowExW(HWND hwndParent,
1289 HWND hwndChildAfter,
1290 LPCWSTR lpszClass,
1291 LPCWSTR lpszWindow)
1292{
1293 ATOM atom = 0;
1294 char *buffer;
1295 HWND hwnd;
1296
1297 if (lpszClass)
1298 {
1299 /* If the atom doesn't exist, then no class */
1300 /* with this name exists either. */
1301 if (!(atom = GlobalFindAtomW( lpszClass )))
1302 {
1303 SetLastError(ERROR_CANNOT_FIND_WND_CLASS);
1304 return 0;
1305 }
1306 }
1307 buffer = HEAP_strdupWtoA( GetProcessHeap(), 0, lpszWindow );
1308 hwnd = Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, atom, buffer);
1309 HeapFree( GetProcessHeap(), 0, buffer );
1310 return hwnd;
1311}
1312//******************************************************************************
1313//******************************************************************************
1314BOOL WIN32API FlashWindow(HWND hwnd, BOOL fFlash)
1315{
1316 dprintf(("FlashWindow %x %d\n", hwnd, fFlash));
1317// return OSLibWinFlashWindow(Win32ToOS2Handle(hwnd), fFlash);
1318 return 1;
1319}
1320//******************************************************************************
1321//******************************************************************************
1322BOOL WIN32API MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
1323 BOOL repaint )
1324{
1325 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
1326
1327 if (!repaint) flags |= SWP_NOREDRAW;
1328 dprintf(("MoveWindow: %x %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint ));
1329
1330 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
1331}
1332//******************************************************************************
1333//******************************************************************************
1334BOOL WIN32API ClientToScreen (HWND hwnd, PPOINT pt)
1335{
1336 PRECT rcl;
1337
1338 if(hwnd == HWND_DESKTOP) {
1339 return(TRUE); //nothing to do
1340 }
1341 if(!IsWindow(hwnd)) {
1342 dprintf(("warning: ClientToScreen window %x not found!", hwnd));
1343 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1344 return (FALSE);
1345 }
1346#ifdef DEBUG
1347 POINT tmp = *pt;
1348#endif
1349 MapWindowPoints(hwnd, 0, pt, 1);
1350 dprintf2(("ClientToScreen %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
1351
1352 return TRUE;
1353}
1354//******************************************************************************
1355//Note: count 0 is a legal parameter (verified in NT4)
1356//******************************************************************************
1357HDWP WIN32API BeginDeferWindowPos(int count)
1358{
1359 HDWP handle;
1360 DWP *pDWP;
1361
1362 if (count < 0)
1363 {
1364 dprintf(("USER32: BeginDeferWindowPos invalid param %d", count));
1365 SetLastError(ERROR_INVALID_PARAMETER);
1366 return 0;
1367 }
1368 dprintf(("USER32: BeginDeferWindowPos %d", count));
1369 if(count == 0)
1370 count = 8; // change to any non-zero value
1371
1372 handle = (HDWP)HeapAlloc(GetProcessHeap(), 0, sizeof(DWP) + (count-1)*sizeof(WINDOWPOS));
1373 if (!handle)
1374 return 0;
1375
1376 pDWP = (DWP *) handle;
1377 pDWP->actualCount = 0;
1378 pDWP->suggestedCount = count;
1379 pDWP->valid = TRUE;
1380 pDWP->wMagic = DWP_MAGIC;
1381 pDWP->hwndParent = 0;
1382 return handle;
1383}
1384/***********************************************************************
1385 * DeferWindowPos (USER32.128)
1386 *
1387 * TODO: SvL: Does this need to be thread safe?
1388 *
1389 */
1390HDWP WIN32API DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1391 INT x, INT y, INT cx, INT cy,
1392 UINT flags )
1393{
1394 DWP *pDWP;
1395 int i;
1396 HDWP newhdwp = hdwp,retvalue;
1397
1398 pDWP = (DWP *)hdwp;
1399 if (!pDWP) {
1400 SetLastError(ERROR_INVALID_PARAMETER);
1401 return 0;
1402 }
1403
1404 if (hwnd == GetDesktopWindow())
1405 return 0;
1406
1407 if(!IsWindow(hwnd)) {
1408 dprintf(("DeferWindowPos, window %x not found", hwnd));
1409 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1410 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1411 return 0;
1412 }
1413
1414 dprintf(("USER32: DeferWindowPos hdwp %x hwnd %x hwndAfter %x (%d,%d)(%d,%d) %x", hdwp, hwnd, hwndAfter,
1415 x, y, cx, cy, flags));
1416
1417/* Numega Bounds Checker Demo dislikes the following code.
1418 In fact, I've not been able to find any "same parent" requirement in any docu
1419 [AM 980509]
1420 */
1421#if 0
1422 /* All the windows of a DeferWindowPos() must have the same parent */
1423 parent = pWnd->parent->hwndSelf;
1424 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
1425 else if (parent != pDWP->hwndParent)
1426 {
1427 USER_HEAP_FREE( hdwp );
1428 retvalue = 0;
1429 goto END;
1430 }
1431#endif
1432
1433 for (i = 0; i < pDWP->actualCount; i++)
1434 {
1435 if (pDWP->winPos[i].hwnd == hwnd)
1436 {
1437 /* Merge with the other changes */
1438 if (!(flags & SWP_NOZORDER))
1439 {
1440 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1441 }
1442 if (!(flags & SWP_NOMOVE))
1443 {
1444 pDWP->winPos[i].x = x;
1445 pDWP->winPos[i].y = y;
1446 }
1447 if (!(flags & SWP_NOSIZE))
1448 {
1449 pDWP->winPos[i].cx = cx;
1450 pDWP->winPos[i].cy = cy;
1451 }
1452 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1453 SWP_NOZORDER | SWP_NOREDRAW |
1454 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1455 SWP_NOOWNERZORDER);
1456 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1457 SWP_FRAMECHANGED);
1458 retvalue = hdwp;
1459 goto END;
1460 }
1461 }
1462 if (pDWP->actualCount >= pDWP->suggestedCount)
1463 {
1464 //DWP structure already contains WINDOWPOS, allocated with (count-1)
1465 //in BeginDeferWindowPos; pDWP->suggestedCount alloc increases it by one
1466 newhdwp = (HDWP)HeapReAlloc(GetProcessHeap(), 0, (LPVOID)hdwp,
1467 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS));
1468 if (!newhdwp)
1469 {
1470 retvalue = 0;
1471 goto END;
1472 }
1473 pDWP = (DWP *) newhdwp;
1474 pDWP->suggestedCount++;
1475 }
1476 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1477 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1478 pDWP->winPos[pDWP->actualCount].x = x;
1479 pDWP->winPos[pDWP->actualCount].y = y;
1480 pDWP->winPos[pDWP->actualCount].cx = cx;
1481 pDWP->winPos[pDWP->actualCount].cy = cy;
1482 pDWP->winPos[pDWP->actualCount].flags = flags;
1483 pDWP->actualCount++;
1484 retvalue = newhdwp;
1485END:
1486 return retvalue;
1487}
1488//******************************************************************************
1489//******************************************************************************
1490BOOL WIN32API EndDeferWindowPos( HDWP hdwp)
1491{
1492 DWP *pDWP;
1493 WINDOWPOS *winpos;
1494 BOOL res = TRUE;
1495 int i;
1496
1497 pDWP = (DWP *) hdwp;
1498 if (!pDWP) {
1499 dprintf(("**EndDeferWindowPos invalid parameter\n"));
1500 SetLastError(ERROR_INVALID_PARAMETER);
1501 return FALSE;
1502 }
1503 dprintf(("**EndDeferWindowPos for %d windows", pDWP->actualCount));
1504 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1505 {
1506 dprintf(("**EndDeferWindowPos %x (%d,%d) (%d,%d) %x", winpos->hwnd, winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags));
1507 if (!(res = SetWindowPos(winpos->hwnd, winpos->hwndInsertAfter,
1508 winpos->x, winpos->y, winpos->cx,
1509 winpos->cy, winpos->flags )))
1510 break;
1511 }
1512 dprintf(("**EndDeferWindowPos DONE"));
1513 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1514 return res;
1515}
1516//******************************************************************************
1517//******************************************************************************
1518HWND WIN32API ChildWindowFromPoint( HWND hwnd, POINT pt)
1519{
1520 dprintf(("USER32: ChildWindowFromPoint\n"));
1521 return ChildWindowFromPointEx(hwnd, pt, 0);
1522}
1523/*****************************************************************************
1524 * Name : HWND WIN32API ChildWindowFromPointEx
1525 * Purpose : pt: client coordinates
1526 * Parameters:
1527 * Variables :
1528 * Result : If the function succeeds, the return value is the window handle.
1529 * If the function fails, the return value is zero
1530 * Remark :
1531 * Status : COMPLETELY IMPLEMENTED AND TESTED
1532 *
1533 * Author : Rene Pronk [Sun, 1999/08/08 23:30]
1534 *****************************************************************************/
1535HWND WIN32API ChildWindowFromPointEx (HWND hwndParent, POINT pt, UINT uFlags)
1536{
1537 RECT rect;
1538 HWND hWnd;
1539
1540 dprintf(("ChildWindowFromPointEx(%08xh,%08xh,%08xh).\n",
1541 hwndParent, pt, uFlags));
1542
1543 if (GetWindowRect (hwndParent, &rect) == 0) {
1544 // oops, invalid handle
1545 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1546 return NULL;
1547 }
1548
1549 ClientToScreen(hwndParent, &pt);
1550 if (PtInRect (&rect, pt) == 0) {
1551 // point is outside window
1552 return NULL;
1553 }
1554
1555 // get first child
1556 hWnd = GetWindow (hwndParent, GW_CHILD);
1557
1558 while (hWnd != NULL)
1559 {
1560 // do I need to skip this window?
1561 if (((uFlags & CWP_SKIPINVISIBLE) &&
1562 (IsWindowVisible (hWnd) == FALSE)) ||
1563 ((uFlags & CWP_SKIPDISABLED) &&
1564 (IsWindowEnabled (hWnd) == FALSE)) ||
1565 ((uFlags & CWP_SKIPTRANSPARENT) &&
1566 (GetWindowLongA (hWnd, GWL_EXSTYLE) & WS_EX_TRANSPARENT)))
1567 {
1568 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1569 continue;
1570 }
1571
1572 // is the point in this window's rect?
1573 GetWindowRect (hWnd, &rect);
1574 if (PtInRect (&rect,pt) == FALSE) {
1575 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1576 continue;
1577 }
1578
1579 dprintf(("ChildWindowFromPointEx returned %x", hWnd));
1580 // found it!
1581 return hWnd;
1582 }
1583 // the point is in the parentwindow but the parentwindow has no child
1584 // at this coordinate
1585 dprintf(("ChildWindowFromPointEx returned parent %x", hwndParent));
1586 return hwndParent;
1587}
1588//******************************************************************************
1589//******************************************************************************
1590BOOL WIN32API CloseWindow(HWND hwnd)
1591{
1592 Win32BaseWindow *window;
1593
1594 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1595 if(!window) {
1596 dprintf(("CloseWindow, window %x not found", hwnd));
1597 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1598 return 0;
1599 }
1600 dprintf(("CloseWindow %x\n", hwnd));
1601 BOOL ret = window->CloseWindow();
1602 RELEASE_WNDOBJ(window);
1603 return ret;
1604}
1605//******************************************************************************
1606//******************************************************************************
1607static BOOL IsPointInWindow(HWND hwnd, POINT point)
1608{
1609 RECT rectWindow;
1610 DWORD hittest, dwStyle, dwExStyle;
1611
1612 dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1613 dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1614
1615 GetWindowRect(hwnd, &rectWindow);
1616
1617 /* If point is in window, and window is visible, and it */
1618 /* is enabled (or it's a top-level window), then explore */
1619 /* its children. Otherwise, go to the next window. */
1620
1621 if( (dwStyle & WS_VISIBLE) &&
1622 ((dwExStyle & (WS_EX_LAYERED | WS_EX_TRANSPARENT)) != (WS_EX_LAYERED | WS_EX_TRANSPARENT)) &&
1623 (!(dwStyle & WS_DISABLED) || ((dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)) &&
1624 ((point.x >= rectWindow.left) && (point.x < rectWindow.right) &&
1625 (point.y >= rectWindow.top) && (point.y < rectWindow.bottom))
1626#if 1
1627 )
1628#else
1629 &&
1630 (wndPtr->hrgnWnd ? PtInRegion(wndPtr->hrgnWnd, 1))
1631#endif
1632 {
1633 hittest = SendMessageA(hwnd, WM_NCHITTEST, 0, MAKELONG(point.x, point.y));
1634 if(hittest != HTTRANSPARENT) {
1635 return TRUE;
1636 }
1637 }
1638 return FALSE;
1639}
1640//******************************************************************************
1641//TODO: Does this return handles of hidden or disabled windows?
1642//******************************************************************************
1643HWND WIN32API WindowFromPoint( POINT point)
1644{
1645 HWND hwndOS2, hwnd;
1646 POINT wPoint;
1647
1648 wPoint.x = point.x;
1649 wPoint.y = mapScreenY(point.y);
1650
1651 hwndOS2 = OSLibWinWindowFromPoint(OSLIB_HWND_DESKTOP, (PVOID)&wPoint);
1652 if(hwndOS2)
1653 {
1654 hwnd = OS2ToWin32Handle(hwndOS2);
1655 while(hwnd)
1656 {
1657 if(IsPointInWindow(hwnd, point)) {
1658 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwnd));
1659 return hwnd;
1660 }
1661 //try siblings
1662 HWND hwndSibling;
1663 HWND hwndParent = GetParent(hwnd);
1664
1665 if(hwndParent) {
1666 hwndSibling = GetWindow(hwndParent, GW_CHILD);
1667 while(hwndSibling) {
1668 if(hwndSibling != hwnd) {
1669 if(IsPointInWindow(hwndSibling, point)) {
1670 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwndSibling));
1671 return hwndSibling;
1672 }
1673 }
1674 hwndSibling = GetWindow(hwndSibling, GW_HWNDNEXT);
1675 }
1676 }
1677 hwnd = hwndParent;
1678 }
1679 }
1680 dprintf(("WindowFromPoint (%d,%d) %x->1\n", point.x, point.y, hwndOS2));
1681 return windowDesktop->getWindowHandle();
1682}
1683//******************************************************************************
1684//******************************************************************************
1685BOOL WIN32API IsWindowUnicode(HWND hwnd)
1686{
1687 Win32BaseWindow *window;
1688
1689 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1690 if(!window) {
1691 dprintf(("IsWindowUnicode, window %x not found", hwnd));
1692 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1693 return 0;
1694 }
1695 BOOL ret = window->IsWindowUnicode();
1696 RELEASE_WNDOBJ(window);
1697 return ret;
1698}
1699/***********************************************************************
1700 * SwitchToThisWindow (USER32.539)
1701 */
1702DWORD WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
1703{
1704 return ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
1705}
1706//******************************************************************************
1707//******************************************************************************
1708BOOL WIN32API EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
1709{
1710 return windowDesktop->EnumThreadWindows(dwThreadId, lpfn, lParam);
1711}
1712//******************************************************************************
1713//******************************************************************************
1714BOOL WIN32API EnumChildWindows(HWND hwnd, WNDENUMPROC lpfn, LPARAM lParam)
1715{
1716 Win32BaseWindow *window;
1717 BOOL ret = TRUE;
1718 ULONG henum;
1719 HWND hwndNext;
1720
1721 if(lpfn == NULL) {
1722 dprintf(("EnumChildWindows invalid parameter %x %x\n", hwnd, lParam));
1723 SetLastError(ERROR_INVALID_PARAMETER);
1724 return FALSE;
1725 }
1726 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1727 if(!window) {
1728 dprintf(("EnumChildWindows, window %x not found", hwnd));
1729 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1730 return FALSE;
1731 }
1732 ret = window->EnumChildWindows(lpfn, lParam);
1733 RELEASE_WNDOBJ(window);
1734 return ret;
1735}
1736//******************************************************************************
1737//******************************************************************************
1738BOOL WIN32API EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
1739{
1740 return windowDesktop->EnumWindows(lpfn, lParam);
1741}
1742//******************************************************************************
1743//******************************************************************************
1744UINT WIN32API ArrangeIconicWindows( HWND parent)
1745{
1746 RECT rectParent;
1747 HWND hwndChild;
1748 INT x, y, xspacing, yspacing;
1749
1750 dprintf(("USER32: ArrangeIconicWindows %x", parent));
1751 dprintf(("USER32: TODO: icon title!!"));
1752
1753 GetClientRect(parent, &rectParent);
1754 x = rectParent.left;
1755 y = rectParent.bottom;
1756 xspacing = GetSystemMetrics(SM_CXICONSPACING);
1757 yspacing = GetSystemMetrics(SM_CYICONSPACING);
1758
1759 hwndChild = GetWindow( parent, GW_CHILD );
1760 while (hwndChild)
1761 {
1762 if( IsIconic( hwndChild ) )
1763 {
1764// WND *wndPtr = WIN_FindWndPtr(hwndChild);
1765
1766// WINPOS_ShowIconTitle( wndPtr, FALSE );
1767
1768 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
1769 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
1770 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1771// if( IsWindow(hwndChild) )
1772// WINPOS_ShowIconTitle(wndPtr , TRUE );
1773// WIN_ReleaseWndPtr(wndPtr);
1774
1775 if (x <= rectParent.right - xspacing) x += xspacing;
1776 else
1777 {
1778 x = rectParent.left;
1779 y -= yspacing;
1780 }
1781 }
1782 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
1783 }
1784 return yspacing;
1785}
1786//******************************************************************************
1787//restores iconized window to previous size/position
1788//******************************************************************************
1789BOOL WIN32API OpenIcon(HWND hwnd)
1790{
1791 dprintf(("USER32: OpenIcon %x", hwnd));
1792
1793 if(!IsIconic(hwnd))
1794 return FALSE;
1795 ShowWindow(hwnd, SW_SHOWNORMAL);
1796 return TRUE;
1797}
1798//******************************************************************************
1799//SDK: Windows can only be shown with ShowOwnedPopups if they were previously
1800// hidden with the same api
1801//TODO: -> needs testing
1802//******************************************************************************
1803ODINFUNCTION2(BOOL, ShowOwnedPopups,
1804 HWND, hwndOwner,
1805 BOOL, fShow)
1806{
1807 Win32BaseWindow *window, *owner;
1808 HWND hwnd;
1809
1810 owner = Win32BaseWindow::GetWindowFromHandle(hwndOwner);
1811 if(!owner) {
1812 dprintf(("ShowOwnedPopups, window %x not found", hwndOwner));
1813 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1814 return FALSE;
1815 }
1816 dprintf(("USER32: ShowOwnedPopups %x %d", hwndOwner, fShow));
1817
1818 hwnd = GetWindow(GetDesktopWindow(), GW_CHILD);
1819 while(hwnd) {
1820 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1821 if(window) {
1822 if(window == owner && (window->getStyle() & WS_POPUP))
1823 {
1824 if(fShow) {
1825 if(window->getFlags() & WIN_NEEDS_SHOW_OWNEDPOPUP)
1826 {
1827 /*
1828 * In Windows, ShowOwnedPopups(TRUE) generates WM_SHOWWINDOW messages with SW_PARENTOPENING,
1829 * regardless of the state of the owner
1830 */
1831 SendMessageA(hwnd, WM_SHOWWINDOW, SW_SHOW, SW_PARENTOPENING);
1832 window->setFlags(window->getFlags() & ~WIN_NEEDS_SHOW_OWNEDPOPUP);
1833 }
1834 }
1835 else
1836 {
1837 if(IsWindowVisible(hwnd))
1838 {
1839 /*
1840 * In Windows, ShowOwnedPopups(FALSE) generates WM_SHOWWINDOW messages with SW_PARENTCLOSING,
1841 * regardless of the state of the owner
1842 */
1843 SendMessageA(hwnd, WM_SHOWWINDOW, SW_HIDE, SW_PARENTCLOSING);
1844 window->setFlags(window->getFlags() | WIN_NEEDS_SHOW_OWNEDPOPUP);
1845 }
1846 }
1847 }
1848 RELEASE_WNDOBJ(window);
1849 }
1850 else dprintf(("WARNING: window %x is not valid", hwnd));
1851
1852 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1853 }
1854 RELEASE_WNDOBJ(owner);
1855 return TRUE;
1856}
1857//******************************************************************************
1858//******************************************************************************
1859ODINFUNCTION0(HWND, GetForegroundWindow)
1860{
1861 HWND hwnd;
1862
1863 hwnd = OS2ToWin32Handle(OSLibWinQueryActiveWindow());
1864 return hwnd;
1865}
1866//******************************************************************************
1867
1868/******************************************************************************
1869 * The return value identifies the most recently active pop-up window.
1870 * The return value is the same as the hWnd parameter, if any of the
1871 * following conditions are met:
1872 *
1873 * - The window identified by hWnd was most recently active.
1874 * - The window identified by hWnd does not own any pop-up windows.
1875 * - The window identified by hWnd is not a top-level window or it is
1876 * owned by another window.
1877 */
1878ODINFUNCTION1(HWND, GetLastActivePopup,
1879 HWND, hWnd)
1880{
1881 Win32BaseWindow *owner;
1882
1883 owner = Win32BaseWindow::GetWindowFromHandle(hWnd);
1884 if(!owner)
1885 {
1886 dprintf(("GetLastActivePopup, window %x not found", hWnd));
1887 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1888 return hWnd;
1889 }
1890
1891 HWND hwndRetVal = owner->getLastActive();
1892 if (!IsWindow( hwndRetVal ))
1893 hwndRetVal = owner->getWindowHandle();
1894
1895 RELEASE_WNDOBJ(owner);
1896
1897 return hwndRetVal;
1898}
1899//******************************************************************************
1900//******************************************************************************
1901ODINFUNCTION2(DWORD, GetWindowThreadProcessId,
1902 HWND, hWnd,
1903 PDWORD, lpdwProcessId)
1904{
1905 hWnd = Win32ToOS2Handle(hWnd);
1906 return O32_GetWindowThreadProcessId(hWnd,lpdwProcessId);
1907}
1908//******************************************************************************
1909//******************************************************************************
1910ODINFUNCTION1(DWORD, GetWindowContextHelpId,
1911 HWND, hwnd)
1912{
1913 Win32BaseWindow *window;
1914
1915 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1916 if(!window) {
1917 dprintf(("GetWindowContextHelpId, window %x not found", hwnd));
1918 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1919 return 0;
1920 }
1921 dprintf(("GetWindowContextHelpId %x", hwnd));
1922 DWORD ret = window->getWindowContextHelpId();
1923 RELEASE_WNDOBJ(window);
1924 return ret;
1925}
1926//******************************************************************************
1927//******************************************************************************
1928ODINFUNCTION2(BOOL, SetWindowContextHelpId,
1929 HWND, hwnd,
1930 DWORD, dwContextHelpId)
1931{
1932 Win32BaseWindow *window;
1933
1934 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1935 if(!window) {
1936 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
1937 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1938 return 0;
1939 }
1940 dprintf(("SetWindowContextHelpId %x %d", hwnd, dwContextHelpId));
1941 window->setWindowContextHelpId(dwContextHelpId);
1942 RELEASE_WNDOBJ(window);
1943 return(TRUE);
1944}
1945//******************************************************************************
1946//******************************************************************************
1947ODINFUNCTION2(HANDLE, GetPropA,
1948 HWND, hwnd,
1949 LPCSTR, str )
1950{
1951 Win32BaseWindow *window;
1952
1953 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1954 if(!window) {
1955 dprintf(("GetPropA, window %x not found", hwnd));
1956 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1957 return 0;
1958 }
1959 HANDLE ret = window->getProp(str);
1960 RELEASE_WNDOBJ(window);
1961 return ret;
1962}
1963//******************************************************************************
1964//******************************************************************************
1965ODINFUNCTION2(HANDLE, GetPropW,
1966 HWND, hwnd,
1967 LPCWSTR, str )
1968{
1969 Win32BaseWindow *window;
1970 LPSTR strA;
1971 HANDLE ret;
1972
1973 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1974 if(!window) {
1975 dprintf(("GetPropW, window %x not found", hwnd));
1976 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1977 return 0;
1978 }
1979
1980 if(HIWORD(str)) {
1981 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
1982 }
1983 else strA = (LPSTR)str;
1984
1985 ret = window->getProp(strA);
1986
1987 RELEASE_WNDOBJ(window);
1988 if(HIWORD(str)) HeapFree( GetProcessHeap(), 0, strA );
1989 return ret;
1990}
1991//******************************************************************************
1992//******************************************************************************
1993ODINFUNCTION3(BOOL, SetPropA,
1994 HWND, hwnd,
1995 LPCSTR, str,
1996 HANDLE, handle )
1997{
1998 Win32BaseWindow *window;
1999
2000 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2001 if(!window) {
2002 dprintf(("SetPropA, window %x not found", hwnd));
2003 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2004 return FALSE;
2005 }
2006 BOOL ret = window->setProp(str, handle);
2007 RELEASE_WNDOBJ(window);
2008 return ret;
2009}
2010//******************************************************************************
2011//******************************************************************************
2012ODINFUNCTION3(BOOL, SetPropW,
2013 HWND, hwnd,
2014 LPCWSTR, str,
2015 HANDLE, handle )
2016{
2017 BOOL ret;
2018 LPSTR strA;
2019
2020 if (!HIWORD(str))
2021 return SetPropA( hwnd, (LPCSTR)(UINT)LOWORD(str), handle );
2022 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
2023 ret = SetPropA( hwnd, strA, handle );
2024 HeapFree( GetProcessHeap(), 0, strA );
2025 return ret;
2026}
2027//******************************************************************************
2028//******************************************************************************
2029ODINFUNCTION2(HANDLE, RemovePropA,
2030 HWND, hwnd,
2031 LPCSTR, str )
2032{
2033 Win32BaseWindow *window;
2034
2035 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2036 if(!window) {
2037 dprintf(("RemovePropA, window %x not found", hwnd));
2038 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2039 return 0;
2040 }
2041 HANDLE ret = window->removeProp(str);
2042 RELEASE_WNDOBJ(window);
2043 return ret;
2044}
2045//******************************************************************************
2046//******************************************************************************
2047ODINFUNCTION2(HANDLE, RemovePropW,
2048 HWND, hwnd,
2049 LPCWSTR, str )
2050{
2051 LPSTR strA;
2052 HANDLE ret;
2053
2054 if (!HIWORD(str))
2055 return RemovePropA( hwnd, (LPCSTR)(UINT)LOWORD(str) );
2056 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
2057 ret = RemovePropA( hwnd, strA );
2058 HeapFree( GetProcessHeap(), 0, strA );
2059 return ret;
2060}
2061//******************************************************************************
2062//******************************************************************************
2063ODINFUNCTION2(INT, EnumPropsA,
2064 HWND, hwnd,
2065 PROPENUMPROCA, func )
2066{
2067 return EnumPropsExA( hwnd, (PROPENUMPROCEXA)func, 0 );
2068}
2069//******************************************************************************
2070//******************************************************************************
2071ODINFUNCTION2(INT, EnumPropsW,
2072 HWND, hwnd,
2073 PROPENUMPROCW, func )
2074{
2075 return EnumPropsExW( hwnd, (PROPENUMPROCEXW)func, 0 );
2076}
2077//******************************************************************************
2078//******************************************************************************
2079ODINFUNCTION3(INT, EnumPropsExA,
2080 HWND, hwnd,
2081 PROPENUMPROCEXA, func,
2082 LPARAM, lParam)
2083{
2084 Win32BaseWindow *window;
2085
2086 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2087 if(!window) {
2088 dprintf(("EnumPropsExA, window %x not found", hwnd));
2089 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2090 return -1;
2091 }
2092 INT ret = window->enumPropsExA(func, lParam);
2093 RELEASE_WNDOBJ(window);
2094 return ret;
2095}
2096//******************************************************************************
2097//******************************************************************************
2098ODINFUNCTION3(INT, EnumPropsExW,
2099 HWND, hwnd,
2100 PROPENUMPROCEXW, func,
2101 LPARAM, lParam)
2102{
2103 Win32BaseWindow *window;
2104
2105 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2106 if(!window) {
2107 dprintf(("EnumPropsExA, window %x not found", hwnd));
2108 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2109 return -1;
2110 }
2111 INT ret = window->enumPropsExW(func, lParam);
2112 RELEASE_WNDOBJ(window);
2113 return ret;
2114}
2115//******************************************************************************
2116//******************************************************************************
2117
2118
2119/*****************************************************************************
2120 * Name : BOOL WIN32API AnyPopup
2121 * Purpose : The AnyPopup function indicates whether an owned, visible,
2122 * top-level pop-up, or overlapped window exists on the screen. The
2123 * function searches the entire Windows screen, not just the calling
2124 * application's client area.
2125 * Parameters: VOID
2126 * Variables :
2127 * Result : If a pop-up window exists, the return value is TRUE even if the
2128 * pop-up window is completely covered by other windows. Otherwise,
2129 * it is FALSE.
2130 * Remark : AnyPopup is a Windows version 1.x function and is retained for
2131 * compatibility purposes. It is generally not useful.
2132 * Status : UNTESTED STUB
2133 *
2134 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
2135 *****************************************************************************/
2136ODINFUNCTION0(BOOL, AnyPopup)
2137{
2138 dprintf(("USER32:AnyPopup() not implemented.\n"));
2139
2140 return (FALSE);
2141}
Note: See TracBrowser for help on using the repository browser.