source: trunk/src/user32/new/window.cpp@ 2410

Last change on this file since 2410 was 2410, checked in by cbratschi, 26 years ago

fixed dialog rect

File size: 52.1 KB
Line 
1/* $Id: window.cpp,v 1.30 2000-01-11 17:34:44 cbratschi Exp $ */
2/*
3 * Win32 window apis for OS/2
4 *
5 * Copyright 1999 Sander van Leeuwen
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)
10 *
11 * Copyright 1993, 1994 Alexandre Julliard
12 *
13 * Project Odin Software License can be found in LICENSE.TXT
14 *
15 *
16 * TODO: Decide what to do about commands for OS/2 windows (non-Win32 apps)
17 *
18 */
19
20#include <os2win.h>
21#include <misc.h>
22#include <string.h>
23#include <stdio.h>
24#include <win32wbase.h>
25#include <win32wmdiclient.h>
26#include <win32wdesktop.h>
27#include "win32dlg.h"
28#include <oslibwin.h>
29#include <oslibgdi.h>
30#include "user32.h"
31#include "winicon.h"
32#include <win\winpos.h>
33
34//******************************************************************************
35//******************************************************************************
36HWND WIN32API CreateWindowExA(DWORD exStyle, LPCSTR className,
37 LPCSTR windowName, DWORD style, INT x,
38 INT y, INT width, INT height,
39 HWND parent, HMENU menu,
40 HINSTANCE instance, LPVOID data )
41{
42 Win32BaseWindow *window;
43 ATOM classAtom;
44 CREATESTRUCTA cs;
45 char tmpClass[20];
46
47 if(exStyle & WS_EX_MDICHILD)
48 return CreateMDIWindowA(className, windowName, style, x, y, width, height, parent, instance, (LPARAM)data);
49
50#if 1
51 /* Find the class atom */
52 if (!(classAtom = GlobalFindAtomA(className)))
53 {
54 if (!HIWORD(className))
55 dprintf(("CreateWindowEx32A: bad class name %04x\n",LOWORD(className)));
56 else
57 dprintf(("CreateWindowEx32A: bad class name '%s'\n", className));
58
59 SetLastError(ERROR_INVALID_PARAMETER);
60 return 0;
61 }
62
63 if (!HIWORD(className))
64 {
65 sprintf(tmpClass,"#%d", (int) className);
66 className = tmpClass;
67 }
68#else
69 /* Find the class atom */
70 if (!HIWORD(className) || !(classAtom = GlobalFindAtomA(className)))
71 {
72 if (!HIWORD(className))
73 {
74 sprintf(tmpClass,"#%d", (int) className);
75 classAtom = GlobalFindAtomA(tmpClass);
76 className = tmpClass;
77 }
78 if (!classAtom)
79 {
80 if (!HIWORD(className)) {
81 dprintf(("CreateWindowEx32A: bad class name %04x\n", LOWORD(className)));
82 }
83 else dprintf(("CreateWindowEx32A: bad class name '%s'\n", className ));
84
85 SetLastError(ERROR_INVALID_PARAMETER);
86 return 0;
87 }
88 }
89#endif
90
91 /* Create the window */
92 cs.lpCreateParams = data;
93 cs.hInstance = instance;
94 cs.hMenu = menu;
95 cs.hwndParent = parent;
96 cs.x = x;
97 cs.y = y;
98 cs.cx = width;
99 cs.cy = height;
100 cs.style = style;
101 cs.lpszName = windowName;
102 cs.lpszClass = className;
103 cs.dwExStyle = exStyle;
104 if(HIWORD(className)) {
105 dprintf(("CreateWindowExA: class %s parent %x (%d,%d) (%d,%d), %x %x", className, parent, x, y, width, height, style, exStyle));
106 }
107 else dprintf(("CreateWindowExA: class %d parent %x (%d,%d) (%d,%d), %x %x", className, parent, x, y, width, height, style, exStyle));
108
109 if(!strcmpi(className, MDICLIENTCLASSNAMEA)) {
110 window = (Win32BaseWindow *) new Win32MDIClientWindow(&cs, classAtom, FALSE);
111 }
112 else
113 if(!strcmpi((char *) className, DIALOG_CLASS_NAMEA))
114 {
115 DLG_TEMPLATE dlgTemplate = {0};
116 dlgTemplate.style = cs.style;
117 dlgTemplate.exStyle = cs.dwExStyle;
118 dlgTemplate.x = cs.x;
119 dlgTemplate.y = cs.y;
120 dlgTemplate.cx = cs.cx;
121 dlgTemplate.cy = cs.cy;
122 dlgTemplate.className = cs.lpszClass;
123 dlgTemplate.caption = cs.lpszName;
124 window = (Win32BaseWindow *) new Win32Dialog(cs.hInstance,
125 (LPCSTR) &dlgTemplate,
126 cs.hwndParent,
127 NULL,
128 (LPARAM) data,
129 FALSE);
130 }
131 else {
132 window = new Win32BaseWindow( &cs, classAtom, FALSE );
133 }
134 if(window == NULL)
135 {
136 dprintf(("Win32BaseWindow creation failed!!"));
137 return 0;
138 }
139 if(GetLastError() != 0)
140 {
141 dprintf(("Win32BaseWindow error found!!"));
142 delete window;
143 return 0;
144 }
145 return window->getWindowHandle();
146}
147//******************************************************************************
148//******************************************************************************
149HWND WIN32API CreateWindowExW(DWORD exStyle, LPCWSTR className,
150 LPCWSTR windowName, DWORD style, INT x,
151 INT y, INT width, INT height,
152 HWND parent, HMENU menu,
153 HINSTANCE instance, LPVOID data )
154{
155 Win32BaseWindow *window;
156 ATOM classAtom;
157 CREATESTRUCTA cs;
158 char tmpClassA[20];
159 WCHAR tmpClassW[20];
160
161 if(exStyle & WS_EX_MDICHILD)
162 return CreateMDIWindowW(className, windowName, style, x, y, width, height, parent, instance, (LPARAM)data);
163
164 /* Find the class atom */
165 if (!HIWORD(className) || !(classAtom = GlobalFindAtomW(className)))
166 {
167 if (!HIWORD(className))
168 {
169 sprintf(tmpClassA,"#%d", (int) className);
170 AsciiToUnicode(tmpClassA, tmpClassW);
171 classAtom = GlobalFindAtomW(tmpClassW);
172 className = (LPCWSTR)tmpClassW;
173 }
174 if (!classAtom)
175 {
176 if (!HIWORD(className)) {
177 dprintf(("CreateWindowEx32W: bad class name %04x\n", LOWORD(className)));
178 }
179 else dprintf(("CreateWindowEx32W: bad class name "));
180
181 SetLastError(ERROR_INVALID_PARAMETER);
182 return 0;
183 }
184 }
185 if(HIWORD(className)) {
186 dprintf(("CreateWindowExW: class %s parent %x (%d,%d) (%d,%d), %x %x", className, parent, x, y, width, height, style, exStyle));
187 }
188 else dprintf(("CreateWindowExW: class %d parent %x (%d,%d) (%d,%d), %x %x", className, parent, x, y, width, height, style, exStyle));
189
190 /* Create the window */
191 cs.lpCreateParams = data;
192 cs.hInstance = instance;
193 cs.hMenu = menu;
194 cs.hwndParent = parent;
195 cs.x = x;
196 cs.y = y;
197 cs.cx = width;
198 cs.cy = height;
199 cs.style = style;
200 cs.lpszName = (LPSTR)windowName;
201 cs.lpszClass = (LPSTR)className;
202 cs.dwExStyle = exStyle;
203
204 if(!lstrcmpiW(className, (LPWSTR)MDICLIENTCLASSNAMEW)) {
205 window = (Win32BaseWindow *) new Win32MDIClientWindow(&cs, classAtom, TRUE);
206 }
207 else
208 if(!lstrcmpiW(className, (LPWSTR)DIALOG_CLASS_NAMEW))
209 {
210 DLG_TEMPLATE dlgTemplate = {0};
211 dlgTemplate.style = cs.style;
212 dlgTemplate.exStyle = cs.dwExStyle;
213 dlgTemplate.x = cs.x;
214 dlgTemplate.y = cs.y;
215 dlgTemplate.cx = cs.cx;
216 dlgTemplate.cy = cs.cy;
217 dlgTemplate.className = cs.lpszClass;
218 dlgTemplate.caption = cs.lpszName;
219 window = (Win32BaseWindow *) new Win32Dialog(cs.hInstance,
220 (LPCSTR) &dlgTemplate,
221 cs.hwndParent,
222 NULL,
223 (LPARAM) data,
224 TRUE);
225 }
226 else {
227 window = new Win32BaseWindow( &cs, classAtom, TRUE );
228 }
229 if(window == NULL)
230 {
231 dprintf(("Win32BaseWindow creation failed!!"));
232 return 0;
233 }
234 if(GetLastError() != 0)
235 {
236 dprintf(("Win32BaseWindow error found!!"));
237 delete window;
238 return 0;
239 }
240 return window->getWindowHandle();
241}
242//******************************************************************************
243//******************************************************************************
244HWND WIN32API CreateMDIWindowA(LPCSTR lpszClassName, LPCSTR lpszWindowName,
245 DWORD dwStyle, int x, int y, int nWidth,
246 int nHeight, HWND hwndParent,
247 HINSTANCE hInstance, LPARAM lParam )
248{
249 HWND hwnd;
250 MDICREATESTRUCTA cs;
251 Win32BaseWindow *window;
252
253 window = Win32BaseWindow::GetWindowFromHandle(hwndParent);
254 if(!window) {
255 dprintf(("CreateMDIWindowA, window %x not found", hwndParent));
256 return 0;
257 }
258
259 dprintf(("USER32: CreateMDIWindowA\n"));
260 cs.szClass = lpszClassName;
261 cs.szTitle = lpszWindowName;
262 cs.hOwner = hInstance;
263 cs.x = x;
264 cs.y = y;
265 cs.cx = nHeight;
266 cs.cy = nWidth;
267 cs.style = dwStyle;
268 cs.lParam = lParam;
269
270 return window->SendMessageA(WM_MDICREATE, 0, (LPARAM)&cs);
271}
272//******************************************************************************
273//******************************************************************************
274HWND WIN32API CreateMDIWindowW(LPCWSTR lpszClassName, LPCWSTR lpszWindowName,
275 DWORD dwStyle, int x, int y, int nWidth,
276 int nHeight, HWND hwndParent,
277 HINSTANCE hInstance, LPARAM lParam )
278{
279 HWND hwnd;
280 MDICREATESTRUCTW cs;
281 Win32BaseWindow *window;
282
283 window = Win32BaseWindow::GetWindowFromHandle(hwndParent);
284 if(!window) {
285 dprintf(("CreateMDIWindowW, window %x not found", hwndParent));
286 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
287 return 0;
288 }
289
290 dprintf(("USER32: CreateMDIWindowW\n"));
291 cs.szClass = lpszClassName;
292 cs.szTitle = lpszWindowName;
293 cs.hOwner = hInstance;
294 cs.x = x;
295 cs.y = y;
296 cs.cx = nHeight;
297 cs.cy = nWidth;
298 cs.style = dwStyle;
299 cs.lParam = lParam;
300
301 return window->SendMessageW(WM_MDICREATE, 0, (LPARAM)&cs);
302}
303//******************************************************************************
304//******************************************************************************
305BOOL WIN32API DestroyWindow(HWND hwnd)
306{
307 Win32BaseWindow *window;
308
309 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
310 if(!window) {
311 dprintf(("DestroyWindow, window %x not found", hwnd));
312 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
313 return 0;
314 }
315 dprintf(("DestroyWindow %x", hwnd));
316 return window->DestroyWindow();
317}
318//******************************************************************************
319//******************************************************************************
320HWND WIN32API SetActiveWindow( HWND hwnd)
321{
322 Win32BaseWindow *window;
323
324 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
325 if(!window) {
326 dprintf(("SetActiveWindow, window %x not found", hwnd));
327 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
328 return 0;
329 }
330 dprintf(("SetActiveWindow %x", hwnd));
331 return window->SetActiveWindow();
332}
333//******************************************************************************
334//******************************************************************************
335HWND WIN32API GetParent( HWND hwnd)
336{
337 Win32BaseWindow *window;
338
339 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
340 if(!window) {
341 dprintf(("GetParent, window %x not found", hwnd));
342 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
343 return 0;
344 }
345// dprintf(("GetParent %x", hwnd));
346 return window->GetParent();
347}
348//******************************************************************************
349//******************************************************************************
350HWND WIN32API SetParent( HWND hwndChild, HWND hwndNewParent)
351{
352 Win32BaseWindow *window;
353
354 window = Win32BaseWindow::GetWindowFromHandle(hwndChild);
355 if(!window) {
356 dprintf(("SetParent, window %x not found", hwndChild));
357 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
358 return 0;
359 }
360 dprintf(("SetParent %x %x", hwndChild, hwndNewParent));
361 return window->SetParent(hwndNewParent);
362}
363//******************************************************************************
364//******************************************************************************
365BOOL WIN32API IsChild( HWND hwndParent, HWND hwnd)
366{
367 Win32BaseWindow *window;
368
369 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
370 if(!window) {
371 dprintf(("IsChild, window %x not found", hwnd));
372 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
373 return 0;
374 }
375 dprintf(("IsChild %x %x", hwndParent, hwnd));
376 return window->IsChild(hwndParent);
377}
378//******************************************************************************
379//******************************************************************************
380HWND WIN32API GetTopWindow( HWND hwnd)
381{
382 Win32BaseWindow *window;
383
384 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
385 if(!window) {
386 dprintf(("GetTopWindow, window %x not found", hwnd));
387 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
388 return 0;
389 }
390 return window->GetTopWindow();
391}
392//******************************************************************************
393//******************************************************************************
394BOOL WIN32API IsIconic( HWND hwnd)
395{
396 Win32BaseWindow *window;
397 BOOL rc;
398
399 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
400 if(!window) {
401 dprintf(("IsIconic, window %x not found", hwnd));
402 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
403 return 0;
404 }
405 rc = window->IsIconic();
406 dprintf(("IsIconic %x returned %d", hwnd, rc));
407 return rc;
408}
409//******************************************************************************
410//******************************************************************************
411HWND WIN32API GetWindow(HWND hwnd, UINT uCmd)
412{
413 Win32BaseWindow *window;
414 HWND rc;
415
416 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
417 if(!window) {
418 dprintf(("GetWindow, window %x not found", hwnd));
419 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
420 return 0;
421 }
422 rc = window->GetWindow(uCmd);
423 return rc;
424}
425//******************************************************************************
426//******************************************************************************
427BOOL WIN32API EnableWindow( HWND hwnd, BOOL fEnable)
428{
429 Win32BaseWindow *window;
430
431 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
432 if(!window) {
433 dprintf(("EnableWindow, window %x not found", hwnd));
434 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
435 return 0;
436 }
437 dprintf(("EnableWindow %x %d", hwnd, fEnable));
438 return window->EnableWindow(fEnable);
439}
440//******************************************************************************
441//******************************************************************************
442BOOL WIN32API BringWindowToTop(HWND hwnd)
443{
444 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
445}
446//******************************************************************************
447//******************************************************************************
448HWND WIN32API GetActiveWindow()
449{
450 return Win32BaseWindow::GetActiveWindow();
451}
452//******************************************************************************
453//******************************************************************************
454BOOL WIN32API ShowWindow(HWND hwnd, int nCmdShow)
455{
456 Win32BaseWindow *window;
457
458 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
459 if(!window) {
460 dprintf(("ShowWindow, window %x not found", hwnd));
461 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
462 return 0;
463 }
464 dprintf(("ShowWindow %x", hwnd));
465 return window->ShowWindow(nCmdShow);
466}
467/*****************************************************************************
468 * Name : BOOL WIN32API ShowWindowAsync
469 * Purpose : The ShowWindowAsync function sets the show state of a window
470 * created by a different thread.
471 * Parameters: HWND hwnd handle of window
472 * int nCmdShow show state of window
473 * Variables :
474 * Result : If the window was previously visible, the return value is TRUE.
475 * If the window was previously hidden, the return value is FALSE.
476 * Remark :
477 * Status : UNTESTED STUB
478 *
479 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
480 *****************************************************************************/
481BOOL WIN32API ShowWindowAsync (HWND hwnd,
482 int nCmdShow)
483{
484 dprintf(("USER32:ShowWindowAsync (%08xh,%08x) not correctly implemented.\n",
485 hwnd,
486 nCmdShow));
487
488 return ShowWindow(hwnd, nCmdShow);
489}
490//******************************************************************************
491//******************************************************************************
492BOOL WIN32API SetWindowPos(HWND hwnd, HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
493{
494 Win32BaseWindow *window;
495
496 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
497 if(!window) {
498 dprintf(("SetWindowPos, window %x not found", hwnd));
499 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
500 return 0;
501 }
502 dprintf(("SetWindowPos %x %x x=%d y=%d cx=%d cy=%d %x", hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
503 return window->SetWindowPos(hwndInsertAfter, x, y, cx, cy, fuFlags);
504}
505//******************************************************************************
506//******************************************************************************
507BOOL WIN32API SetWindowPlacement(HWND hwnd, const WINDOWPLACEMENT *winpos)
508{
509 Win32BaseWindow *window;
510
511 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
512 if(!window) {
513 dprintf(("SetWindowPlacement, window %x not found", hwnd));
514 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
515 return 0;
516 }
517 return window->SetWindowPlacement((WINDOWPLACEMENT *)winpos);
518}
519//******************************************************************************
520//******************************************************************************
521BOOL WIN32API GetWindowPlacement(HWND hwnd, LPWINDOWPLACEMENT arg2)
522{
523 dprintf(("USER32: GetWindowPlacement\n"));
524 return O32_GetWindowPlacement(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd), arg2);
525}
526//******************************************************************************
527//******************************************************************************
528BOOL WIN32API IsWindow( HWND hwnd)
529{
530 Win32BaseWindow *window;
531
532 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
533 if(!window) {
534 dprintf(("IsWindow, window %x not found", hwnd));
535 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
536 return FALSE;
537 }
538 dprintf(("IsWindow %x", hwnd));
539 return window->IsWindow();
540}
541//******************************************************************************
542//******************************************************************************
543BOOL WIN32API IsWindowEnabled( HWND hwnd)
544{
545 Win32BaseWindow *window;
546
547 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
548 if(!window) {
549 dprintf(("IsWindowEnabled, window %x not found", hwnd));
550 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
551 return 0;
552 }
553 dprintf(("IsWindowEnabled %x", hwnd));
554 return window->IsWindowEnabled();
555}
556//******************************************************************************
557//******************************************************************************
558BOOL WIN32API IsWindowVisible( HWND hwnd)
559{
560 Win32BaseWindow *window;
561 BOOL rc;
562
563 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
564 if(!window) {
565 dprintf(("IsWindowVisible, window %x not found", hwnd));
566 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
567 return 0;
568 }
569 rc = window->IsWindowVisible();
570 dprintf(("IsWindowVisible %x returned %d", hwnd, rc));
571 return rc;
572}
573//******************************************************************************
574//******************************************************************************
575HWND WIN32API SetFocus (HWND hwnd)
576{
577 HWND lastFocus, lastFocus_W, hwnd_O;
578 BOOL activate;
579
580 hwnd_O = Win32BaseWindow::Win32ToOS2Handle (hwnd);
581 lastFocus = OSLibWinQueryFocus (OSLIB_HWND_DESKTOP);
582 activate = ((hwnd_O == lastFocus) || OSLibWinIsChild (lastFocus, hwnd_O));
583 lastFocus_W = Win32BaseWindow::OS2ToWin32Handle (lastFocus);
584
585 dprintf(("SetFocus %x (%x) -> %x (%x)\n", lastFocus_W, lastFocus, hwnd, hwnd_O));
586
587 return (OSLibWinSetFocus (OSLIB_HWND_DESKTOP, hwnd_O, activate)) ? lastFocus_W : 0;
588}
589//******************************************************************************
590//******************************************************************************
591HWND WIN32API GetFocus(void)
592{
593 HWND hwnd;
594
595 hwnd = OSLibWinQueryFocus(OSLIB_HWND_DESKTOP);
596 dprintf(("USER32: GetFocus %x\n", hwnd));
597 hwnd = Win32BaseWindow::OS2ToWin32Handle(hwnd);
598 return hwnd;
599}
600//******************************************************************************
601//******************************************************************************
602/***********************************************************************
603 * GetInternalWindowPos (USER32.245)
604 */
605UINT WIN32API GetInternalWindowPos(HWND hwnd,
606 LPRECT rectWnd,
607 LPPOINT ptIcon )
608{
609 WINDOWPLACEMENT wndpl;
610
611 dprintf(("USER32: GetInternalWindowPos(%08xh,%08xh,%08xh)\n",
612 hwnd,
613 rectWnd,
614 ptIcon));
615
616 if (GetWindowPlacement( hwnd, &wndpl ))
617 {
618 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
619 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
620 return wndpl.showCmd;
621 }
622 return 0;
623}
624//******************************************************************************
625//******************************************************************************
626BOOL WIN32API IsZoomed(HWND hwnd)
627{
628 dprintf(("USER32: IsZoomed\n"));
629 return O32_IsZoomed(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd));
630}
631//******************************************************************************
632//******************************************************************************
633BOOL WIN32API LockWindowUpdate(HWND hwnd)
634{
635 dprintf(("USER32: LockWindowUpdate\n"));
636 return O32_LockWindowUpdate(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd));
637}
638//******************************************************************************
639//******************************************************************************
640BOOL WIN32API GetWindowRect( HWND hwnd, PRECT pRect)
641{
642 Win32BaseWindow *window;
643 BOOL rc;
644
645 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
646 if(!window) {
647 dprintf(("GetWindowRect, window %x not found", hwnd));
648 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
649 return 0;
650 }
651 if(pRect == NULL) {
652 SetLastError(ERROR_INVALID_PARAMETER);
653 return 0;
654 }
655 *pRect = *window->getWindowRect();
656 dprintf(("GetWindowRect %x (%d,%d) (%d,%d)", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom));
657 return rc;
658}
659//******************************************************************************
660//******************************************************************************
661int WIN32API GetWindowTextLengthA( HWND hwnd)
662{
663 Win32BaseWindow *window;
664
665 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
666 if(!window) {
667 dprintf(("GetWindowTextLength, window %x not found", hwnd));
668 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
669 return 0;
670 }
671 dprintf(("GetWindowTextLength %x", hwnd));
672 return window->GetWindowTextLength();
673}
674//******************************************************************************
675//******************************************************************************
676int WIN32API GetWindowTextA( HWND hwnd, LPSTR lpsz, int cch)
677{
678 Win32BaseWindow *window;
679 int rc;
680
681 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
682 if(!window) {
683 dprintf(("GetWindowTextA, window %x not found", hwnd));
684 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
685 return 0;
686 }
687 rc = window->GetWindowTextA(lpsz, cch);
688 dprintf(("GetWindowTextA %x %s", hwnd, lpsz));
689 return rc;
690}
691//******************************************************************************
692//******************************************************************************
693int WIN32API GetWindowTextLengthW( HWND hwnd)
694{
695 dprintf(("USER32: GetWindowTextLengthW\n"));
696 return GetWindowTextLengthA(hwnd);
697}
698//******************************************************************************
699//******************************************************************************
700int WIN32API GetWindowTextW(HWND hwnd, LPWSTR lpsz, int cch)
701{
702 Win32BaseWindow *window;
703
704 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
705 if(!window) {
706 dprintf(("GetWindowTextW, window %x not found", hwnd));
707 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
708 return 0;
709 }
710 dprintf(("GetWindowTextW %x", hwnd));
711 return window->GetWindowTextW(lpsz, cch);
712}
713//******************************************************************************
714//******************************************************************************
715BOOL WIN32API SetWindowTextA(HWND hwnd, LPCSTR lpsz)
716{
717 Win32BaseWindow *window;
718
719 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
720 if(!window) {
721 dprintf(("SetWindowTextA, window %x not found", hwnd));
722 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
723 return 0;
724 }
725 dprintf(("SetWindowTextA %x %s", hwnd, lpsz));
726 return window->SetWindowTextA((LPSTR)lpsz);
727}
728//******************************************************************************
729//******************************************************************************
730BOOL WIN32API SetWindowTextW( HWND hwnd, LPCWSTR lpsz)
731{
732 Win32BaseWindow *window;
733
734 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
735 if(!window) {
736 dprintf(("SetWindowTextA, window %x not found", hwnd));
737 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
738 return 0;
739 }
740 dprintf(("SetWindowTextW %x", hwnd));
741 return window->SetWindowTextW((LPWSTR)lpsz);
742}
743/*******************************************************************
744 * InternalGetWindowText (USER32.326)
745 */
746int WIN32API InternalGetWindowText(HWND hwnd,
747 LPWSTR lpString,
748 INT nMaxCount )
749{
750 dprintf(("USER32: InternalGetWindowText(%08xh,%08xh,%08xh) not properly implemented.\n",
751 hwnd,
752 lpString,
753 nMaxCount));
754
755 return GetWindowTextW(hwnd,lpString,nMaxCount);
756}
757//******************************************************************************
758//TODO: Correct?
759//******************************************************************************
760BOOL WIN32API SetForegroundWindow(HWND hwnd)
761{
762 dprintf((" SetForegroundWindow %x", hwnd));
763
764 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER );
765}
766//******************************************************************************
767//******************************************************************************
768BOOL WIN32API GetClientRect( HWND hwnd, PRECT pRect)
769{
770 BOOL rc;
771 HWND hwndWin32 = hwnd;
772
773 Win32BaseWindow *window;
774
775 if (!pRect)
776 {
777 SetLastError(ERROR_INVALID_PARAMETER);
778 return FALSE;
779 }
780 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
781 if(!window) {
782 dprintf(("GetClientRect, window %x not found", hwnd));
783 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
784 return FALSE;
785 }
786 window->getClientRect(pRect);
787 dprintf(("GetClientRect of %X returned (%d,%d) (%d,%d)\n", hwndWin32, pRect->left, pRect->top, pRect->right, pRect->bottom));
788 return TRUE;
789}
790//******************************************************************************
791//******************************************************************************
792BOOL WIN32API AdjustWindowRect(PRECT rect, DWORD style, BOOL menu)
793{
794 return AdjustWindowRectEx(rect, style, menu, 0);
795}
796//******************************************************************************
797//******************************************************************************
798BOOL WIN32API AdjustWindowRectEx( PRECT rect, DWORD style, BOOL menu, DWORD exStyle)
799{
800 dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d)\n", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
801
802 /* Correct the window style */
803 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
804 style |= WS_CAPTION;
805
806 style &= (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME | WS_CHILD | WS_VSCROLL | WS_HSCROLL);
807 exStyle &= (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE |
808 WS_EX_STATICEDGE | WS_EX_TOOLWINDOW);
809 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
810
811 //Adjust rect outer (Win32BaseWindow::AdjustRectOuter)
812 /* Decide if the window will be managed (see CreateWindowEx) */
813 //if (!WindowNeedsWMBorder()) //CB: check Options.managed
814 {
815 if (HAS_THICKFRAME(style,exStyle))
816 InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
817 else
818 if (HAS_DLGFRAME(style,exStyle))
819 InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
820 else
821 if (HAS_THINFRAME(style))
822 InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
823
824 if ((style & WS_CAPTION) == WS_CAPTION)
825 {
826 if (exStyle & WS_EX_TOOLWINDOW)
827 rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
828 else
829 rect->top -= GetSystemMetrics(SM_CYCAPTION);
830 }
831 }
832
833 if (menu)
834 rect->top -= GetSystemMetrics(SM_CYMENU);
835
836 //Adjust rect inner (Win32BaseWindow::AdjustRectInner)
837 if (exStyle & WS_EX_CLIENTEDGE)
838 InflateRect (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
839
840 if (exStyle & WS_EX_STATICEDGE)
841 InflateRect (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
842
843 if (style & WS_VSCROLL) rect->right += GetSystemMetrics(SM_CXVSCROLL);
844 if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
845
846 dprintf(("AdjustWindowRectEx returned (%d,%d)(%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom));
847 return TRUE;
848}
849//******************************************************************************
850/* Coordinate Space and Transformation Functions */
851//******************************************************************************
852int WIN32API MapWindowPoints(HWND hwndFrom, HWND hwndTo, LPPOINT lpPoints,
853 UINT cPoints)
854{
855 Win32BaseWindow *wndfrom, *wndto;
856 int retval = 0;
857 OSLIBPOINT point;
858
859 if(lpPoints == NULL || cPoints == 0) {
860 SetLastError(ERROR_INVALID_PARAMETER);
861 return 0;
862 }
863 if(hwndFrom)
864 {
865 wndfrom = Win32BaseWindow::GetWindowFromHandle(hwndFrom);
866 if(!wndfrom) {
867 dprintf(("MapWindowPoints, window %x not found", hwndFrom));
868 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
869 return 0;
870 }
871 }
872 else wndfrom = windowDesktop;
873
874 if(hwndTo)
875 {
876 wndto = Win32BaseWindow::GetWindowFromHandle(hwndTo);
877 if(!wndto) {
878 dprintf(("MapWindowPoints, window %x not found", hwndTo));
879 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
880 return 0;
881 }
882 }
883 else wndto = windowDesktop;
884
885 if(wndto == wndfrom)
886 return 0; //nothing to do
887
888 dprintf(("USER32: MapWindowPoints %x to %x (%d,%d) (%d)", hwndFrom, hwndTo, lpPoints->x, lpPoints->y, cPoints));
889 point.x = lpPoints->x;
890 point.y = lpPoints->y;
891 if (!mapWin32Point(wndfrom,wndto,&point))
892 {
893 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
894 return 0;
895 }
896
897 short int xinc = point.x - lpPoints->x;
898 short int yinc = point.y - lpPoints->y;
899
900 for(int i=0;i<cPoints;i++)
901 {
902 lpPoints[i].x += xinc;
903 lpPoints[i].y += yinc;
904 }
905 retval = ((LONG)yinc << 16) | xinc;
906 return retval;
907}
908//******************************************************************************
909//******************************************************************************
910BOOL WIN32API ScreenToClient (HWND hwnd, LPPOINT pt)
911{
912 Win32BaseWindow *wnd;
913 PRECT rcl;
914
915 dprintf(("ScreenToClient %x (%d,%d)\n", hwnd, pt->x, pt->y));
916
917 if (!hwnd) return (TRUE);
918 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
919 if (!wnd) return (TRUE);
920 return mapWin32Point(OSLIB_HWND_DESKTOP,wnd->getOS2WindowHandle(),(OSLIBPOINT*)pt);
921}
922//******************************************************************************
923//******************************************************************************
924HWND WIN32API GetDesktopWindow(void)
925{
926 HWND DesktopWindow = windowDesktop->getWindowHandle();
927 dprintf(("USER32: GetDesktopWindow, return %d\n", DesktopWindow));
928 return DesktopWindow;
929}
930//******************************************************************************
931//******************************************************************************
932HWND WIN32API FindWindowA(LPCSTR lpszClass, LPCSTR lpszWindow)
933{
934 if(!lpszClass) {
935 SetLastError(ERROR_INVALID_PARAMETER);
936 return 0;
937 }
938 if(HIWORD(lpszClass)) {
939 dprintf(("USER32: FindWindow %s %s\n", lpszClass, lpszWindow));
940 }
941 else dprintf(("USER32: FindWindow %x %s\n", lpszClass, lpszWindow));
942
943 return Win32BaseWindow::FindWindowEx(OSLIB_HWND_DESKTOP, 0, (LPSTR)lpszClass, (LPSTR)lpszWindow);
944}
945//******************************************************************************
946//******************************************************************************
947HWND WIN32API FindWindowW( LPCWSTR lpClassName, LPCWSTR lpWindowName)
948{
949 char *astring1 = UnicodeToAsciiString((LPWSTR)lpClassName);
950 char *astring2 = UnicodeToAsciiString((LPWSTR)lpWindowName);
951 HWND rc;
952
953 rc = FindWindowA(astring1, astring2);
954 FreeAsciiString(astring1);
955 FreeAsciiString(astring2);
956 return rc;
957}
958//******************************************************************************
959//******************************************************************************
960HWND WIN32API FindWindowExA(HWND hwndParent, HWND hwndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow)
961{
962 if(!lpszClass) {
963 SetLastError(ERROR_INVALID_PARAMETER);
964 return 0;
965 }
966 if(HIWORD(lpszClass)) {
967 dprintf(("USER32: FindWindowExA (%x,%x) %s %s\n", hwndParent, hwndChildAfter, lpszClass, lpszWindow));
968 }
969 else dprintf(("USER32: FindWindowExA (%x,%x)%x %s\n", hwndParent, hwndChildAfter, lpszClass, lpszWindow));
970
971 return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, (LPSTR)lpszClass, (LPSTR)lpszWindow);
972}
973/*****************************************************************************
974 * Name : HWND WIN32API FindWindowExW
975 * Purpose : The FindWindowEx function retrieves the handle of a window whose
976 * class name and window name match the specified strings. The
977 * function searches child windows, beginning with the one following
978 * the given child window.
979 * Parameters: HWND hwndParent handle of parent window
980 * HWND hwndChildAfter handle of a child window
981 * LPCTSTR lpszClass address of class name
982 * LPCTSTR lpszWindow address of window name
983 * Variables :
984 * Result : If the function succeeds, the return value is the handle of the
985 * window that has the specified class and window names.
986 * If the function fails, the return value is NULL. To get extended
987 * error information, call GetLastError.
988 * Remark :
989 * Status : UNTESTED STUB
990 *
991 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
992 *****************************************************************************/
993
994HWND WIN32API FindWindowExW(HWND hwndParent,
995 HWND hwndChildAfter,
996 LPCWSTR lpszClass,
997 LPCWSTR lpszWindow)
998{
999 if(!lpszClass) {
1000 SetLastError(ERROR_INVALID_PARAMETER);
1001 return 0;
1002 }
1003 dprintf(("USER32: FindWindowExW (%x,%x) %x %s\n", hwndParent, hwndChildAfter, lpszClass, lpszWindow));
1004
1005 return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, (LPSTR)lpszClass, (LPSTR)lpszWindow);
1006}
1007//******************************************************************************
1008//******************************************************************************
1009BOOL WIN32API FlashWindow(HWND hwnd, BOOL fFlash)
1010{
1011 dprintf(("FlashWindow %x %d\n", hwnd, fFlash));
1012 return OSLibWinFlashWindow(Win32BaseWindow::Win32ToOS2Handle(hwnd), fFlash);
1013}
1014//******************************************************************************
1015//******************************************************************************
1016BOOL WIN32API MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
1017 BOOL repaint )
1018{
1019 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
1020
1021 if (!repaint) flags |= SWP_NOREDRAW;
1022 dprintf(("MoveWindow: %x %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint ));
1023
1024 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
1025}
1026//******************************************************************************
1027//******************************************************************************
1028BOOL WIN32API ClientToScreen (HWND hwnd, PPOINT pt)
1029{
1030 Win32BaseWindow *wnd;
1031 PRECT rcl;
1032
1033 dprintf(("ClientToScreen (%d,%d)\n", pt->x, pt->y));
1034 if (!hwnd) {
1035 SetLastError(ERROR_INVALID_PARAMETER);
1036 return (FALSE);
1037 }
1038 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1039 if (!wnd) {
1040 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1041 return (FALSE);
1042 }
1043 return mapWin32Point(wnd->getOS2WindowHandle(),OSLIB_HWND_DESKTOP,(OSLIBPOINT*)pt);
1044}
1045//******************************************************************************
1046//******************************************************************************
1047HDWP WIN32API BeginDeferWindowPos(int count)
1048{
1049 HDWP handle;
1050 DWP *pDWP;
1051
1052 dprintf(("USER32: BeginDeferWindowPos\n"));
1053 if (count <= 0)
1054 {
1055 SetLastError(ERROR_INVALID_PARAMETER);
1056 return 0;
1057 }
1058 handle = (HDWP)HeapAlloc(GetProcessHeap(), 0, sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
1059 if (!handle)
1060 return 0;
1061
1062 pDWP = (DWP *) handle;
1063 pDWP->actualCount = 0;
1064 pDWP->suggestedCount = count;
1065 pDWP->valid = TRUE;
1066 pDWP->wMagic = DWP_MAGIC;
1067 pDWP->hwndParent = 0;
1068 return handle;
1069}
1070/***********************************************************************
1071 * DeferWindowPos (USER32.128)
1072 */
1073HDWP WIN32API DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1074 INT x, INT y, INT cx, INT cy,
1075 UINT flags )
1076{
1077 DWP *pDWP;
1078 int i;
1079 HDWP newhdwp = hdwp,retvalue;
1080 Win32BaseWindow *window;
1081
1082 pDWP = (DWP *)hdwp;
1083 if (!pDWP) {
1084 SetLastError(ERROR_INVALID_PARAMETER);
1085 return 0;
1086 }
1087
1088 if (hwnd == GetDesktopWindow())
1089 return 0;
1090
1091 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1092 if(!window) {
1093 dprintf(("DeferWindowPos, window %x not found", hwnd));
1094 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1095 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1096 return 0;
1097 }
1098
1099
1100/* Numega Bounds Checker Demo dislikes the following code.
1101 In fact, I've not been able to find any "same parent" requirement in any docu
1102 [AM 980509]
1103 */
1104#if 0
1105 /* All the windows of a DeferWindowPos() must have the same parent */
1106 parent = pWnd->parent->hwndSelf;
1107 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
1108 else if (parent != pDWP->hwndParent)
1109 {
1110 USER_HEAP_FREE( hdwp );
1111 retvalue = 0;
1112 goto END;
1113 }
1114#endif
1115
1116 for (i = 0; i < pDWP->actualCount; i++)
1117 {
1118 if (pDWP->winPos[i].hwnd == hwnd)
1119 {
1120 /* Merge with the other changes */
1121 if (!(flags & SWP_NOZORDER))
1122 {
1123 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1124 }
1125 if (!(flags & SWP_NOMOVE))
1126 {
1127 pDWP->winPos[i].x = x;
1128 pDWP->winPos[i].y = y;
1129 }
1130 if (!(flags & SWP_NOSIZE))
1131 {
1132 pDWP->winPos[i].cx = cx;
1133 pDWP->winPos[i].cy = cy;
1134 }
1135 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1136 SWP_NOZORDER | SWP_NOREDRAW |
1137 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1138 SWP_NOOWNERZORDER);
1139 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1140 SWP_FRAMECHANGED);
1141 retvalue = hdwp;
1142 goto END;
1143 }
1144 }
1145 if (pDWP->actualCount >= pDWP->suggestedCount)
1146 {
1147 newhdwp = (HDWP)HeapReAlloc(GetProcessHeap(), 0, (LPVOID)hdwp,
1148 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS));
1149 if (!newhdwp)
1150 {
1151 retvalue = 0;
1152 goto END;
1153 }
1154 pDWP = (DWP *) newhdwp;
1155 pDWP->suggestedCount++;
1156 }
1157 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1158 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1159 pDWP->winPos[pDWP->actualCount].x = x;
1160 pDWP->winPos[pDWP->actualCount].y = y;
1161 pDWP->winPos[pDWP->actualCount].cx = cx;
1162 pDWP->winPos[pDWP->actualCount].cy = cy;
1163 pDWP->winPos[pDWP->actualCount].flags = flags;
1164 pDWP->actualCount++;
1165 retvalue = newhdwp;
1166END:
1167 return retvalue;
1168}
1169//******************************************************************************
1170//******************************************************************************
1171BOOL WIN32API EndDeferWindowPos( HDWP hdwp)
1172{
1173 DWP *pDWP;
1174 WINDOWPOS *winpos;
1175 BOOL res = TRUE;
1176 int i;
1177
1178 pDWP = (DWP *) hdwp;
1179 if (!pDWP) {
1180 dprintf(("**EndDeferWindowPos invalid parameter\n"));
1181 SetLastError(ERROR_INVALID_PARAMETER);
1182 return FALSE;
1183 }
1184 dprintf(("**EndDeferWindowPos for %d windows", pDWP->actualCount));
1185 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1186 {
1187 dprintf(("**EndDeferWindowPos %x (%d,%d) (%d,%d) %x", winpos->hwnd, winpos->x, winpos->y, winpos->x, winpos->cy, winpos->flags));
1188 if (!(res = SetWindowPos(winpos->hwnd, winpos->hwndInsertAfter,
1189 winpos->x, winpos->y, winpos->cx,
1190 winpos->cy, winpos->flags )))
1191 break;
1192 }
1193 dprintf(("**EndDeferWindowPos DONE"));
1194 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1195 return res;
1196}
1197//******************************************************************************
1198//******************************************************************************
1199HWND WIN32API ChildWindowFromPoint( HWND hwnd, POINT pt)
1200{
1201 dprintf(("USER32: ChildWindowFromPoint\n"));
1202 return ChildWindowFromPointEx(hwnd, pt, 0);
1203}
1204/*****************************************************************************
1205 * Name : HWND WIN32API ChildWindowFromPointEx
1206 * Purpose : pt: client coordinates
1207 * Parameters:
1208 * Variables :
1209 * Result : If the function succeeds, the return value is the window handle.
1210 * If the function fails, the return value is zero
1211 * Remark :
1212 * Status : FULLY IMPLEMENTED AND TESTED
1213 *
1214 * Author : Rene Pronk [Sun, 1999/08/08 23:30]
1215 *****************************************************************************/
1216HWND WIN32API ChildWindowFromPointEx (HWND hwndParent, POINT pt, UINT uFlags)
1217{
1218 RECT rect;
1219 HWND hWnd;
1220
1221 dprintf(("ChildWindowFromPointEx(%08xh,%08xh,%08xh).\n",
1222 hwndParent, pt, uFlags));
1223
1224 if (GetWindowRect (hwndParent, &rect) == 0) {
1225 // oops, invalid handle
1226 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1227 return NULL;
1228 }
1229
1230 ClientToScreen(hwndParent, &pt);
1231 if (PtInRect (&rect, pt) == 0) {
1232 // point is outside window
1233 return NULL;
1234 }
1235
1236
1237 // get first child
1238 hWnd = GetWindow (hwndParent, GW_CHILD);
1239
1240 while (hWnd != NULL) {
1241
1242 // do I need to skip this window?
1243 if (((uFlags & CWP_SKIPINVISIBLE) &&
1244 (IsWindowVisible (hWnd) == FALSE)) ||
1245 ((uFlags & CWP_SKIPDISABLED) &&
1246 (IsWindowEnabled (hWnd) == FALSE)) ||
1247 ((uFlags & CWP_SKIPTRANSPARENT) &&
1248 (GetWindowLongA (hWnd, GWL_EXSTYLE) & WS_EX_TRANSPARENT)))
1249
1250 {
1251 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1252 continue;
1253 }
1254
1255 // is the point in this window's rect?
1256 GetWindowRect (hWnd, &rect);
1257 if (PtInRect (&rect,pt) == FALSE) {
1258 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1259 continue;
1260 }
1261
1262 dprintf(("ChildWindowFromPointEx returned %x", hWnd));
1263 // found it!
1264 return hWnd;
1265 }
1266
1267 // the point is in the parentwindow but the parentwindow has no child
1268 // at this coordinate
1269 dprintf(("ChildWindowFromPointEx returned parent %x", hwndParent));
1270 return hwndParent;
1271}
1272//******************************************************************************
1273//******************************************************************************
1274BOOL WIN32API CloseWindow(HWND hwnd)
1275{
1276 Win32BaseWindow *window;
1277
1278 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1279 if(!window) {
1280 dprintf(("CloseWindow, window %x not found", hwnd));
1281 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1282 return 0;
1283 }
1284 dprintf(("CloseWindow %x\n", hwnd));
1285 return window->CloseWindow();
1286}
1287//******************************************************************************
1288//TODO: Does this return handles of hidden or disabled windows?
1289//******************************************************************************
1290HWND WIN32API WindowFromPoint( POINT point)
1291{
1292 HWND hwndOS2, hwnd;
1293 POINT wPoint;
1294
1295 wPoint.x = point.x;
1296 wPoint.y = mapScreenY(point.y);
1297
1298 hwndOS2 = OSLibWinWindowFromPoint(OSLIB_HWND_DESKTOP, (PVOID)&wPoint);
1299 if(hwndOS2)
1300 {
1301 hwnd = Win32BaseWindow::OS2ToWin32Handle(hwndOS2);
1302 if (!hwnd)
1303 {
1304 //CB: could be a frame control
1305 hwndOS2 = OSLibWinQueryWindow(hwndOS2,QWOS_PARENT);
1306 hwnd = Win32BaseWindow::OS2ToWin32Handle(hwndOS2);
1307 }
1308 if(hwnd) {
1309 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwnd));
1310 return hwnd;
1311 }
1312 }
1313 dprintf(("WindowFromPoint (%d,%d) %x->1\n", point.x, point.y, hwndOS2));
1314 return windowDesktop->getWindowHandle();
1315}
1316//******************************************************************************
1317//******************************************************************************
1318BOOL WIN32API IsWindowUnicode(HWND hwnd)
1319{
1320 Win32BaseWindow *window;
1321
1322 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1323 if(!window) {
1324 dprintf(("IsWindowUnicode, window %x not found", hwnd));
1325 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1326 return 0;
1327 }
1328 return window->IsWindowUnicode();
1329}
1330/***********************************************************************
1331 * SwitchToThisWindow (USER32.539)
1332 */
1333DWORD WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
1334{
1335 return ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
1336}
1337//******************************************************************************
1338//******************************************************************************
1339BOOL WIN32API EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
1340{
1341 return windowDesktop->EnumThreadWindows(dwThreadId, lpfn, lParam);
1342}
1343//******************************************************************************
1344//******************************************************************************
1345BOOL WIN32API EnumChildWindows(HWND hwnd, WNDENUMPROC lpfn, LPARAM lParam)
1346{
1347 Win32BaseWindow *window;
1348 BOOL rc = TRUE;
1349 ULONG henum;
1350 HWND hwndNext;
1351
1352 if(lpfn == NULL) {
1353 dprintf(("EnumChildWindows invalid parameter %x %x\n", hwnd, lParam));
1354 SetLastError(ERROR_INVALID_PARAMETER);
1355 return FALSE;
1356 }
1357 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1358 if(!window) {
1359 dprintf(("EnumChildWindows, window %x not found", hwnd));
1360 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1361 return FALSE;
1362 }
1363 return window->EnumChildWindows(lpfn, lParam);
1364}
1365//******************************************************************************
1366//******************************************************************************
1367BOOL WIN32API EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
1368{
1369 return windowDesktop->EnumWindows(lpfn, lParam);
1370}
1371//******************************************************************************
1372//******************************************************************************
1373UINT WIN32API ArrangeIconicWindows( HWND hwnd)
1374{
1375 dprintf(("USER32: ArrangeIconicWindows %x", hwnd));
1376 return O32_ArrangeIconicWindows(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd));
1377}
1378//******************************************************************************
1379//restores iconized window to previous size/position
1380//******************************************************************************
1381BOOL WIN32API OpenIcon(HWND hwnd)
1382{
1383 dprintf(("USER32: OpenIcon"));
1384
1385 if(!IsIconic(hwnd))
1386 return FALSE;
1387 ShowWindow(hwnd, SW_SHOWNORMAL);
1388 return TRUE;
1389}
1390//******************************************************************************
1391//******************************************************************************
1392BOOL WIN32API ShowOwnedPopups( HWND hwnd, BOOL arg2)
1393{
1394 dprintf(("USER32: ShowOwnedPopups %x", hwnd));
1395 return O32_ShowOwnedPopups(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd), arg2);
1396}
1397//******************************************************************************
1398//******************************************************************************
1399HWND WIN32API GetForegroundWindow(void)
1400{
1401 dprintf(("USER32: GetForegroundWindow"));
1402 return Win32BaseWindow::OS2ToWin32Handle(O32_GetForegroundWindow());
1403}
1404//******************************************************************************
1405//******************************************************************************
1406HWND WIN32API GetLastActivePopup( HWND hWnd)
1407{
1408 HWND hwnd;
1409
1410 hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd);
1411
1412 hwnd = Win32BaseWindow::OS2ToWin32Handle(O32_GetLastActivePopup(hWnd));
1413
1414 dprintf(("GetLastActivePopup %x returned %x", hWnd, hwnd));
1415 return hwnd;
1416}
1417//******************************************************************************
1418//******************************************************************************
1419DWORD WIN32API GetWindowThreadProcessId(HWND hWnd, PDWORD lpdwProcessId)
1420{
1421 dprintf2(("USER32: GetWindowThreadProcessId"));
1422 hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd);
1423
1424 return O32_GetWindowThreadProcessId(hWnd,lpdwProcessId);
1425}
1426//******************************************************************************
1427//******************************************************************************
1428DWORD WIN32API GetWindowContextHelpId(HWND hwnd)
1429{
1430 Win32BaseWindow *window;
1431
1432 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1433 if(!window) {
1434 dprintf(("GetWindowContextHelpId, window %x not found", hwnd));
1435 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1436 return 0;
1437 }
1438 dprintf(("GetWindowContextHelpId %x", hwnd));
1439 return window->getWindowContextHelpId();
1440}
1441//******************************************************************************
1442//******************************************************************************
1443BOOL WIN32API SetWindowContextHelpId(HWND hwnd, DWORD dwContextHelpId)
1444{
1445 Win32BaseWindow *window;
1446
1447 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1448 if(!window) {
1449 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
1450 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1451 return 0;
1452 }
1453 dprintf(("SetWindowContextHelpId %x %d", hwnd, dwContextHelpId));
1454 window->setWindowContextHelpId(dwContextHelpId);
1455 return(TRUE);
1456}
1457//******************************************************************************
1458//******************************************************************************
Note: See TracBrowser for help on using the repository browser.