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

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

WM_CONTEXTMENU, sysmenu changes

File size: 52.1 KB
Line 
1/* $Id: window.cpp,v 1.50 2000-01-20 16:48:58 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 return window->SetActiveWindow();
331}
332//******************************************************************************
333//******************************************************************************
334HWND WIN32API GetParent( HWND hwnd)
335{
336 Win32BaseWindow *window;
337
338 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
339 if(!window) {
340 dprintf(("GetParent, window %x not found", hwnd));
341 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
342 return 0;
343 }
344// dprintf(("GetParent %x", hwnd));
345 return window->GetParent();
346}
347//******************************************************************************
348//******************************************************************************
349HWND WIN32API SetParent( HWND hwndChild, HWND hwndNewParent)
350{
351 Win32BaseWindow *window;
352
353 window = Win32BaseWindow::GetWindowFromHandle(hwndChild);
354 if(!window) {
355 dprintf(("SetParent, window %x not found", hwndChild));
356 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
357 return 0;
358 }
359 dprintf(("SetParent %x %x", hwndChild, hwndNewParent));
360 return window->SetParent(hwndNewParent);
361}
362//******************************************************************************
363//******************************************************************************
364BOOL WIN32API IsChild( HWND hwndParent, HWND hwnd)
365{
366 Win32BaseWindow *window;
367
368 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
369 if(!window) {
370 dprintf(("IsChild, window %x not found", hwnd));
371 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
372 return 0;
373 }
374 dprintf(("IsChild %x %x", hwndParent, hwnd));
375 return window->IsChild(hwndParent);
376}
377//******************************************************************************
378//******************************************************************************
379HWND WIN32API GetTopWindow( HWND hwnd)
380{
381 Win32BaseWindow *window;
382
383 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
384 if(!window) {
385 dprintf(("GetTopWindow, window %x not found", hwnd));
386 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
387 return 0;
388 }
389 return window->GetTopWindow();
390}
391//******************************************************************************
392//******************************************************************************
393BOOL WIN32API IsIconic( HWND hwnd)
394{
395 Win32BaseWindow *window;
396 BOOL rc;
397
398 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
399 if(!window) {
400 dprintf(("IsIconic, window %x not found", hwnd));
401 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
402 return 0;
403 }
404 rc = window->IsIconic();
405 dprintf(("IsIconic %x returned %d", hwnd, rc));
406 return rc;
407}
408//******************************************************************************
409//******************************************************************************
410HWND WIN32API GetWindow(HWND hwnd, UINT uCmd)
411{
412 Win32BaseWindow *window;
413 HWND rc;
414
415 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
416 if(!window) {
417 dprintf(("GetWindow, window %x not found", hwnd));
418 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
419 return 0;
420 }
421 rc = window->GetWindow(uCmd);
422 return rc;
423}
424//******************************************************************************
425//******************************************************************************
426BOOL WIN32API EnableWindow( HWND hwnd, BOOL fEnable)
427{
428 Win32BaseWindow *window;
429
430 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
431 if(!window) {
432 dprintf(("EnableWindow, window %x not found", hwnd));
433 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
434 return 0;
435 }
436 dprintf(("EnableWindow %x %d", hwnd, fEnable));
437 return window->EnableWindow(fEnable);
438}
439//******************************************************************************
440//******************************************************************************
441BOOL WIN32API BringWindowToTop(HWND hwnd)
442{
443 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
444}
445//******************************************************************************
446//******************************************************************************
447HWND WIN32API GetActiveWindow()
448{
449 return Win32BaseWindow::GetActiveWindow();
450}
451//******************************************************************************
452//******************************************************************************
453BOOL WIN32API ShowWindow(HWND hwnd, int nCmdShow)
454{
455 Win32BaseWindow *window;
456
457 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
458 if(!window) {
459 dprintf(("ShowWindow, window %x not found", hwnd));
460 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
461 return 0;
462 }
463 dprintf(("ShowWindow %x", hwnd));
464 return window->ShowWindow(nCmdShow);
465}
466/*****************************************************************************
467 * Name : BOOL WIN32API ShowWindowAsync
468 * Purpose : The ShowWindowAsync function sets the show state of a window
469 * created by a different thread.
470 * Parameters: HWND hwnd handle of window
471 * int nCmdShow show state of window
472 * Variables :
473 * Result : If the window was previously visible, the return value is TRUE.
474 * If the window was previously hidden, the return value is FALSE.
475 * Remark :
476 * Status : UNTESTED STUB
477 *
478 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
479 *****************************************************************************/
480BOOL WIN32API ShowWindowAsync (HWND hwnd,
481 int nCmdShow)
482{
483 dprintf(("USER32:ShowWindowAsync (%08xh,%08x) not correctly implemented.\n",
484 hwnd,
485 nCmdShow));
486
487 return ShowWindow(hwnd, nCmdShow);
488}
489//******************************************************************************
490//******************************************************************************
491BOOL WIN32API SetWindowPos(HWND hwnd, HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
492{
493 Win32BaseWindow *window;
494
495 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
496 if(!window) {
497 dprintf(("SetWindowPos, window %x not found", hwnd));
498 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
499 return 0;
500 }
501 dprintf(("SetWindowPos %x %x x=%d y=%d cx=%d cy=%d %x", hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
502 return window->SetWindowPos(hwndInsertAfter, x, y, cx, cy, fuFlags);
503}
504//******************************************************************************
505//******************************************************************************
506BOOL WIN32API SetWindowPlacement(HWND hwnd, const WINDOWPLACEMENT *winpos)
507{
508 Win32BaseWindow *window;
509
510 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
511 if(!window) {
512 dprintf(("SetWindowPlacement, window %x not found", hwnd));
513 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
514 return 0;
515 }
516 return window->SetWindowPlacement((WINDOWPLACEMENT *)winpos);
517}
518//******************************************************************************
519//******************************************************************************
520BOOL WIN32API GetWindowPlacement(HWND hwnd, LPWINDOWPLACEMENT arg2)
521{
522 dprintf(("USER32: GetWindowPlacement\n"));
523 return O32_GetWindowPlacement(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd), arg2);
524}
525//******************************************************************************
526//******************************************************************************
527BOOL WIN32API IsWindow( HWND hwnd)
528{
529 Win32BaseWindow *window;
530
531 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
532 if(!window) {
533 dprintf(("IsWindow, window %x not found", hwnd));
534 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
535 return FALSE;
536 }
537 dprintf(("IsWindow %x", hwnd));
538 return window->IsWindow();
539}
540//******************************************************************************
541//******************************************************************************
542BOOL WIN32API IsWindowEnabled( HWND hwnd)
543{
544 Win32BaseWindow *window;
545
546 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
547 if(!window) {
548 dprintf(("IsWindowEnabled, window %x not found", hwnd));
549 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
550 return 0;
551 }
552 dprintf(("IsWindowEnabled %x", hwnd));
553 return window->IsWindowEnabled();
554}
555//******************************************************************************
556//******************************************************************************
557BOOL WIN32API IsWindowVisible( HWND hwnd)
558{
559 Win32BaseWindow *window;
560 BOOL rc;
561
562 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
563 if(!window) {
564 dprintf(("IsWindowVisible, window %x not found", hwnd));
565 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
566 return 0;
567 }
568 rc = window->IsWindowVisible();
569 dprintf(("IsWindowVisible %x returned %d", hwnd, rc));
570 return rc;
571}
572//******************************************************************************
573//******************************************************************************
574HWND WIN32API SetFocus (HWND hwnd)
575{
576 HWND lastFocus, lastFocus_W, hwnd_O;
577 BOOL activate;
578
579 hwnd_O = Win32BaseWindow::Win32ToOS2Handle (hwnd);
580 lastFocus = OSLibWinQueryFocus (OSLIB_HWND_DESKTOP);
581 activate = ((hwnd_O == lastFocus) || OSLibWinIsChild (lastFocus, hwnd_O));
582 lastFocus_W = Win32BaseWindow::OS2ToWin32Handle (lastFocus);
583
584 dprintf(("SetFocus %x (%x) -> %x (%x)\n", lastFocus_W, lastFocus, hwnd, hwnd_O));
585
586 return (OSLibWinSetFocus (OSLIB_HWND_DESKTOP, hwnd_O, activate)) ? lastFocus_W : 0;
587}
588//******************************************************************************
589//******************************************************************************
590HWND WIN32API GetFocus(void)
591{
592 HWND hwnd;
593
594 hwnd = OSLibWinQueryFocus(OSLIB_HWND_DESKTOP);
595 dprintf(("USER32: GetFocus %x\n", hwnd));
596 hwnd = Win32BaseWindow::OS2ToWin32Handle(hwnd);
597 return hwnd;
598}
599//******************************************************************************
600//******************************************************************************
601/***********************************************************************
602 * GetInternalWindowPos (USER32.245)
603 */
604UINT WIN32API GetInternalWindowPos(HWND hwnd,
605 LPRECT rectWnd,
606 LPPOINT ptIcon )
607{
608 WINDOWPLACEMENT wndpl;
609
610 dprintf(("USER32: GetInternalWindowPos(%08xh,%08xh,%08xh)\n",
611 hwnd,
612 rectWnd,
613 ptIcon));
614
615 if (GetWindowPlacement( hwnd, &wndpl ))
616 {
617 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
618 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
619 return wndpl.showCmd;
620 }
621 return 0;
622}
623//******************************************************************************
624//******************************************************************************
625BOOL WIN32API IsZoomed(HWND hwnd)
626{
627 dprintf(("USER32: IsZoomed\n"));
628 return O32_IsZoomed(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd));
629}
630//******************************************************************************
631//******************************************************************************
632BOOL WIN32API LockWindowUpdate(HWND hwnd)
633{
634 dprintf(("USER32: LockWindowUpdate\n"));
635 return O32_LockWindowUpdate(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd));
636}
637//******************************************************************************
638//******************************************************************************
639BOOL WIN32API GetWindowRect( HWND hwnd, PRECT pRect)
640{
641 Win32BaseWindow *window;
642
643 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
644 if(!window) {
645 dprintf(("GetWindowRect, window %x not found", hwnd));
646 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
647 return FALSE;
648 }
649 if(pRect == NULL) {
650 SetLastError(ERROR_INVALID_PARAMETER);
651 return FALSE;
652 }
653 *pRect = *window->getWindowRect();
654 dprintf(("GetWindowRect %x (%d,%d) (%d,%d)", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom));
655 return TRUE;
656}
657//******************************************************************************
658//******************************************************************************
659int WIN32API GetWindowTextLengthA( HWND hwnd)
660{
661 Win32BaseWindow *window;
662
663 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
664 if(!window) {
665 dprintf(("GetWindowTextLength, window %x not found", hwnd));
666 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
667 return 0;
668 }
669 dprintf(("GetWindowTextLength %x", hwnd));
670 return window->GetWindowTextLength();
671}
672//******************************************************************************
673//******************************************************************************
674int WIN32API GetWindowTextA( HWND hwnd, LPSTR lpsz, int cch)
675{
676 Win32BaseWindow *window;
677 int rc;
678
679 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
680 if(!window) {
681 dprintf(("GetWindowTextA, window %x not found", hwnd));
682 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
683 return 0;
684 }
685 rc = window->GetWindowTextA(lpsz, cch);
686 dprintf(("GetWindowTextA %x %s", hwnd, lpsz));
687 return rc;
688}
689//******************************************************************************
690//******************************************************************************
691int WIN32API GetWindowTextLengthW( HWND hwnd)
692{
693 dprintf(("USER32: GetWindowTextLengthW\n"));
694 return GetWindowTextLengthA(hwnd);
695}
696//******************************************************************************
697//******************************************************************************
698int WIN32API GetWindowTextW(HWND hwnd, LPWSTR lpsz, int cch)
699{
700 Win32BaseWindow *window;
701
702 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
703 if(!window) {
704 dprintf(("GetWindowTextW, window %x not found", hwnd));
705 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
706 return 0;
707 }
708 dprintf(("GetWindowTextW %x", hwnd));
709 return window->GetWindowTextW(lpsz, cch);
710}
711//******************************************************************************
712//******************************************************************************
713BOOL WIN32API SetWindowTextA(HWND hwnd, LPCSTR lpsz)
714{
715 Win32BaseWindow *window;
716
717 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
718 if(!window) {
719 dprintf(("SetWindowTextA, window %x not found", hwnd));
720 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
721 return 0;
722 }
723 dprintf(("SetWindowTextA %x %s", hwnd, lpsz));
724 return window->SetWindowTextA((LPSTR)lpsz);
725}
726//******************************************************************************
727//******************************************************************************
728BOOL WIN32API SetWindowTextW( HWND hwnd, LPCWSTR lpsz)
729{
730 Win32BaseWindow *window;
731
732 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
733 if(!window) {
734 dprintf(("SetWindowTextA, window %x not found", hwnd));
735 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
736 return 0;
737 }
738 dprintf(("SetWindowTextW %x", hwnd));
739 return window->SetWindowTextW((LPWSTR)lpsz);
740}
741/*******************************************************************
742 * InternalGetWindowText (USER32.326)
743 */
744int WIN32API InternalGetWindowText(HWND hwnd,
745 LPWSTR lpString,
746 INT nMaxCount )
747{
748 dprintf(("USER32: InternalGetWindowText(%08xh,%08xh,%08xh) not properly implemented.\n",
749 hwnd,
750 lpString,
751 nMaxCount));
752
753 return GetWindowTextW(hwnd,lpString,nMaxCount);
754}
755//******************************************************************************
756//TODO: Correct?
757//******************************************************************************
758BOOL WIN32API SetForegroundWindow(HWND hwnd)
759{
760 dprintf((" SetForegroundWindow %x", hwnd));
761
762 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER );
763}
764//******************************************************************************
765//******************************************************************************
766BOOL WIN32API GetClientRect( HWND hwnd, PRECT pRect)
767{
768 HWND hwndWin32 = hwnd;
769 Win32BaseWindow *window;
770
771 if (!pRect)
772 {
773 SetLastError(ERROR_INVALID_PARAMETER);
774 return FALSE;
775 }
776 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
777 if(!window) {
778 dprintf(("GetClientRect, window %x not found", hwnd));
779 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
780 return FALSE;
781 }
782 window->getClientRect(pRect);
783 dprintf(("GetClientRect of %X returned (%d,%d) (%d,%d)\n", hwndWin32, pRect->left, pRect->top, pRect->right, pRect->bottom));
784 return TRUE;
785}
786//******************************************************************************
787//******************************************************************************
788BOOL WIN32API AdjustWindowRect(PRECT rect, DWORD style, BOOL menu)
789{
790 return AdjustWindowRectEx(rect, style, menu, 0);
791}
792//******************************************************************************
793//******************************************************************************
794BOOL WIN32API AdjustWindowRectEx( PRECT rect, DWORD style, BOOL menu, DWORD exStyle)
795{
796 dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d)\n", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
797
798 /* Correct the window style */
799 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
800 style |= WS_CAPTION;
801
802 style &= (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME | WS_CHILD | WS_VSCROLL | WS_HSCROLL);
803 exStyle &= (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE |
804 WS_EX_STATICEDGE | WS_EX_TOOLWINDOW);
805 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
806
807 //Adjust rect outer (Win32BaseWindow::AdjustRectOuter)
808 /* Decide if the window will be managed (see CreateWindowEx) */
809 //if (!WindowNeedsWMBorder()) //CB: check Options.managed
810 {
811 if (HAS_THICKFRAME(style,exStyle))
812 InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
813 else
814 if (HAS_DLGFRAME(style,exStyle))
815 InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
816 else
817 if (HAS_THINFRAME(style))
818 InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
819
820 if ((style & WS_CAPTION) == WS_CAPTION)
821 {
822 if (exStyle & WS_EX_TOOLWINDOW)
823 rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
824 else
825 rect->top -= GetSystemMetrics(SM_CYCAPTION);
826 }
827 }
828
829 if (menu)
830 rect->top -= GetSystemMetrics(SM_CYMENU);
831
832 //Adjust rect inner (Win32BaseWindow::AdjustRectInner)
833 if (exStyle & WS_EX_CLIENTEDGE)
834 InflateRect (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
835
836 if (exStyle & WS_EX_STATICEDGE)
837 InflateRect (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
838
839 if (style & WS_VSCROLL) rect->right += GetSystemMetrics(SM_CXVSCROLL);
840 if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
841
842 dprintf(("AdjustWindowRectEx returned (%d,%d)(%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom));
843 return TRUE;
844}
845//******************************************************************************
846/* Coordinate Space and Transformation Functions */
847//******************************************************************************
848int WIN32API MapWindowPoints(HWND hwndFrom, HWND hwndTo, LPPOINT lpPoints,
849 UINT cPoints)
850{
851 Win32BaseWindow *wndfrom, *wndto;
852 int retval = 0;
853 OSLIBPOINT point;
854
855 if(lpPoints == NULL || cPoints == 0) {
856 SetLastError(ERROR_INVALID_PARAMETER);
857 return 0;
858 }
859 if(hwndFrom)
860 {
861 wndfrom = Win32BaseWindow::GetWindowFromHandle(hwndFrom);
862 if(!wndfrom) {
863 dprintf(("MapWindowPoints, window %x not found", hwndFrom));
864 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
865 return 0;
866 }
867 }
868 else wndfrom = windowDesktop;
869
870 if(hwndTo)
871 {
872 wndto = Win32BaseWindow::GetWindowFromHandle(hwndTo);
873 if(!wndto) {
874 dprintf(("MapWindowPoints, window %x not found", hwndTo));
875 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
876 return 0;
877 }
878 }
879 else wndto = windowDesktop;
880
881 if(wndto == wndfrom)
882 return 0; //nothing to do
883
884 dprintf(("USER32: MapWindowPoints %x to %x (%d,%d) (%d)", hwndFrom, hwndTo, lpPoints->x, lpPoints->y, cPoints));
885 point.x = lpPoints->x;
886 point.y = lpPoints->y;
887 if (!mapWin32Point(wndfrom,wndto,&point))
888 {
889 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
890 return 0;
891 }
892
893 short int xinc = point.x - lpPoints->x;
894 short int yinc = point.y - lpPoints->y;
895
896 for(int i=0;i<cPoints;i++)
897 {
898 lpPoints[i].x += xinc;
899 lpPoints[i].y += yinc;
900 }
901 retval = ((LONG)yinc << 16) | xinc;
902 return retval;
903}
904//******************************************************************************
905//******************************************************************************
906BOOL WIN32API ScreenToClient (HWND hwnd, LPPOINT pt)
907{
908 Win32BaseWindow *wnd;
909 PRECT rcl;
910
911 dprintf(("ScreenToClient %x (%d,%d)\n", hwnd, pt->x, pt->y));
912
913 if (!hwnd) return (TRUE);
914 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
915 if (!wnd) return (TRUE);
916 return mapWin32Point(OSLIB_HWND_DESKTOP,wnd->getOS2WindowHandle(),(OSLIBPOINT*)pt);
917}
918//******************************************************************************
919//******************************************************************************
920HWND WIN32API GetDesktopWindow(void)
921{
922 HWND DesktopWindow = windowDesktop->getWindowHandle();
923 dprintf(("USER32: GetDesktopWindow, return %d\n", DesktopWindow));
924 return DesktopWindow;
925}
926//******************************************************************************
927//******************************************************************************
928HWND WIN32API FindWindowA(LPCSTR lpszClass, LPCSTR lpszWindow)
929{
930 if(!lpszClass) {
931 SetLastError(ERROR_INVALID_PARAMETER);
932 return 0;
933 }
934 if(HIWORD(lpszClass)) {
935 dprintf(("USER32: FindWindow %s %s\n", lpszClass, lpszWindow));
936 }
937 else dprintf(("USER32: FindWindow %x %s\n", lpszClass, lpszWindow));
938
939 return Win32BaseWindow::FindWindowEx(OSLIB_HWND_DESKTOP, 0, (LPSTR)lpszClass, (LPSTR)lpszWindow);
940}
941//******************************************************************************
942//******************************************************************************
943HWND WIN32API FindWindowW( LPCWSTR lpClassName, LPCWSTR lpWindowName)
944{
945 char *astring1 = UnicodeToAsciiString((LPWSTR)lpClassName);
946 char *astring2 = UnicodeToAsciiString((LPWSTR)lpWindowName);
947 HWND rc;
948
949 rc = FindWindowA(astring1, astring2);
950 FreeAsciiString(astring1);
951 FreeAsciiString(astring2);
952 return rc;
953}
954//******************************************************************************
955//******************************************************************************
956HWND WIN32API FindWindowExA(HWND hwndParent, HWND hwndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow)
957{
958 if(!lpszClass) {
959 SetLastError(ERROR_INVALID_PARAMETER);
960 return 0;
961 }
962 if(HIWORD(lpszClass)) {
963 dprintf(("USER32: FindWindowExA (%x,%x) %s %s\n", hwndParent, hwndChildAfter, lpszClass, lpszWindow));
964 }
965 else dprintf(("USER32: FindWindowExA (%x,%x)%x %s\n", hwndParent, hwndChildAfter, lpszClass, lpszWindow));
966
967 return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, (LPSTR)lpszClass, (LPSTR)lpszWindow);
968}
969/*****************************************************************************
970 * Name : HWND WIN32API FindWindowExW
971 * Purpose : The FindWindowEx function retrieves the handle of a window whose
972 * class name and window name match the specified strings. The
973 * function searches child windows, beginning with the one following
974 * the given child window.
975 * Parameters: HWND hwndParent handle of parent window
976 * HWND hwndChildAfter handle of a child window
977 * LPCTSTR lpszClass address of class name
978 * LPCTSTR lpszWindow address of window name
979 * Variables :
980 * Result : If the function succeeds, the return value is the handle of the
981 * window that has the specified class and window names.
982 * If the function fails, the return value is NULL. To get extended
983 * error information, call GetLastError.
984 * Remark :
985 * Status : UNTESTED STUB
986 *
987 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
988 *****************************************************************************/
989
990HWND WIN32API FindWindowExW(HWND hwndParent,
991 HWND hwndChildAfter,
992 LPCWSTR lpszClass,
993 LPCWSTR lpszWindow)
994{
995 if(!lpszClass) {
996 SetLastError(ERROR_INVALID_PARAMETER);
997 return 0;
998 }
999 dprintf(("USER32: FindWindowExW (%x,%x) %x %s\n", hwndParent, hwndChildAfter, lpszClass, lpszWindow));
1000
1001 return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, (LPSTR)lpszClass, (LPSTR)lpszWindow);
1002}
1003//******************************************************************************
1004//******************************************************************************
1005BOOL WIN32API FlashWindow(HWND hwnd, BOOL fFlash)
1006{
1007 dprintf(("FlashWindow %x %d\n", hwnd, fFlash));
1008 return OSLibWinFlashWindow(Win32BaseWindow::Win32ToOS2Handle(hwnd), fFlash);
1009}
1010//******************************************************************************
1011//******************************************************************************
1012BOOL WIN32API MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
1013 BOOL repaint )
1014{
1015 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
1016
1017 if (!repaint) flags |= SWP_NOREDRAW;
1018 dprintf(("MoveWindow: %x %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint ));
1019
1020 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
1021}
1022//******************************************************************************
1023//******************************************************************************
1024BOOL WIN32API ClientToScreen (HWND hwnd, PPOINT pt)
1025{
1026 Win32BaseWindow *wnd;
1027 PRECT rcl;
1028
1029 dprintf(("ClientToScreen (%d,%d)\n", pt->x, pt->y));
1030 if (!hwnd) {
1031 SetLastError(ERROR_INVALID_PARAMETER);
1032 return (FALSE);
1033 }
1034 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1035 if (!wnd) {
1036 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1037 return (FALSE);
1038 }
1039 return mapWin32Point(wnd->getOS2WindowHandle(),OSLIB_HWND_DESKTOP,(OSLIBPOINT*)pt);
1040}
1041//******************************************************************************
1042//******************************************************************************
1043HDWP WIN32API BeginDeferWindowPos(int count)
1044{
1045 HDWP handle;
1046 DWP *pDWP;
1047
1048 dprintf(("USER32: BeginDeferWindowPos\n"));
1049 if (count <= 0)
1050 {
1051 SetLastError(ERROR_INVALID_PARAMETER);
1052 return 0;
1053 }
1054 handle = (HDWP)HeapAlloc(GetProcessHeap(), 0, sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
1055 if (!handle)
1056 return 0;
1057
1058 pDWP = (DWP *) handle;
1059 pDWP->actualCount = 0;
1060 pDWP->suggestedCount = count;
1061 pDWP->valid = TRUE;
1062 pDWP->wMagic = DWP_MAGIC;
1063 pDWP->hwndParent = 0;
1064 return handle;
1065}
1066/***********************************************************************
1067 * DeferWindowPos (USER32.128)
1068 */
1069HDWP WIN32API DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1070 INT x, INT y, INT cx, INT cy,
1071 UINT flags )
1072{
1073 DWP *pDWP;
1074 int i;
1075 HDWP newhdwp = hdwp,retvalue;
1076 Win32BaseWindow *window;
1077
1078 pDWP = (DWP *)hdwp;
1079 if (!pDWP) {
1080 SetLastError(ERROR_INVALID_PARAMETER);
1081 return 0;
1082 }
1083
1084 if (hwnd == GetDesktopWindow())
1085 return 0;
1086
1087 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1088 if(!window) {
1089 dprintf(("DeferWindowPos, window %x not found", hwnd));
1090 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1091 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1092 return 0;
1093 }
1094
1095
1096/* Numega Bounds Checker Demo dislikes the following code.
1097 In fact, I've not been able to find any "same parent" requirement in any docu
1098 [AM 980509]
1099 */
1100#if 0
1101 /* All the windows of a DeferWindowPos() must have the same parent */
1102 parent = pWnd->parent->hwndSelf;
1103 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
1104 else if (parent != pDWP->hwndParent)
1105 {
1106 USER_HEAP_FREE( hdwp );
1107 retvalue = 0;
1108 goto END;
1109 }
1110#endif
1111
1112 for (i = 0; i < pDWP->actualCount; i++)
1113 {
1114 if (pDWP->winPos[i].hwnd == hwnd)
1115 {
1116 /* Merge with the other changes */
1117 if (!(flags & SWP_NOZORDER))
1118 {
1119 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1120 }
1121 if (!(flags & SWP_NOMOVE))
1122 {
1123 pDWP->winPos[i].x = x;
1124 pDWP->winPos[i].y = y;
1125 }
1126 if (!(flags & SWP_NOSIZE))
1127 {
1128 pDWP->winPos[i].cx = cx;
1129 pDWP->winPos[i].cy = cy;
1130 }
1131 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1132 SWP_NOZORDER | SWP_NOREDRAW |
1133 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1134 SWP_NOOWNERZORDER);
1135 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1136 SWP_FRAMECHANGED);
1137 retvalue = hdwp;
1138 goto END;
1139 }
1140 }
1141 if (pDWP->actualCount >= pDWP->suggestedCount)
1142 {
1143 newhdwp = (HDWP)HeapReAlloc(GetProcessHeap(), 0, (LPVOID)hdwp,
1144 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS));
1145 if (!newhdwp)
1146 {
1147 retvalue = 0;
1148 goto END;
1149 }
1150 pDWP = (DWP *) newhdwp;
1151 pDWP->suggestedCount++;
1152 }
1153 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1154 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1155 pDWP->winPos[pDWP->actualCount].x = x;
1156 pDWP->winPos[pDWP->actualCount].y = y;
1157 pDWP->winPos[pDWP->actualCount].cx = cx;
1158 pDWP->winPos[pDWP->actualCount].cy = cy;
1159 pDWP->winPos[pDWP->actualCount].flags = flags;
1160 pDWP->actualCount++;
1161 retvalue = newhdwp;
1162END:
1163 return retvalue;
1164}
1165//******************************************************************************
1166//******************************************************************************
1167BOOL WIN32API EndDeferWindowPos( HDWP hdwp)
1168{
1169 DWP *pDWP;
1170 WINDOWPOS *winpos;
1171 BOOL res = TRUE;
1172 int i;
1173
1174 pDWP = (DWP *) hdwp;
1175 if (!pDWP) {
1176 dprintf(("**EndDeferWindowPos invalid parameter\n"));
1177 SetLastError(ERROR_INVALID_PARAMETER);
1178 return FALSE;
1179 }
1180 dprintf(("**EndDeferWindowPos for %d windows", pDWP->actualCount));
1181 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1182 {
1183 dprintf(("**EndDeferWindowPos %x (%d,%d) (%d,%d) %x", winpos->hwnd, winpos->x, winpos->y, winpos->x, winpos->cy, winpos->flags));
1184 if (!(res = SetWindowPos(winpos->hwnd, winpos->hwndInsertAfter,
1185 winpos->x, winpos->y, winpos->cx,
1186 winpos->cy, winpos->flags )))
1187 break;
1188 }
1189 dprintf(("**EndDeferWindowPos DONE"));
1190 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1191 return res;
1192}
1193//******************************************************************************
1194//******************************************************************************
1195HWND WIN32API ChildWindowFromPoint( HWND hwnd, POINT pt)
1196{
1197 dprintf(("USER32: ChildWindowFromPoint\n"));
1198 return ChildWindowFromPointEx(hwnd, pt, 0);
1199}
1200/*****************************************************************************
1201 * Name : HWND WIN32API ChildWindowFromPointEx
1202 * Purpose : pt: client coordinates
1203 * Parameters:
1204 * Variables :
1205 * Result : If the function succeeds, the return value is the window handle.
1206 * If the function fails, the return value is zero
1207 * Remark :
1208 * Status : FULLY IMPLEMENTED AND TESTED
1209 *
1210 * Author : Rene Pronk [Sun, 1999/08/08 23:30]
1211 *****************************************************************************/
1212HWND WIN32API ChildWindowFromPointEx (HWND hwndParent, POINT pt, UINT uFlags)
1213{
1214 RECT rect;
1215 HWND hWnd;
1216
1217 dprintf(("ChildWindowFromPointEx(%08xh,%08xh,%08xh).\n",
1218 hwndParent, pt, uFlags));
1219
1220 if (GetWindowRect (hwndParent, &rect) == 0) {
1221 // oops, invalid handle
1222 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1223 return NULL;
1224 }
1225
1226 ClientToScreen(hwndParent, &pt);
1227 if (PtInRect (&rect, pt) == 0) {
1228 // point is outside window
1229 return NULL;
1230 }
1231
1232
1233 // get first child
1234 hWnd = GetWindow (hwndParent, GW_CHILD);
1235
1236 while (hWnd != NULL) {
1237
1238 // do I need to skip this window?
1239 if (((uFlags & CWP_SKIPINVISIBLE) &&
1240 (IsWindowVisible (hWnd) == FALSE)) ||
1241 ((uFlags & CWP_SKIPDISABLED) &&
1242 (IsWindowEnabled (hWnd) == FALSE)) ||
1243 ((uFlags & CWP_SKIPTRANSPARENT) &&
1244 (GetWindowLongA (hWnd, GWL_EXSTYLE) & WS_EX_TRANSPARENT)))
1245
1246 {
1247 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1248 continue;
1249 }
1250
1251 // is the point in this window's rect?
1252 GetWindowRect (hWnd, &rect);
1253 if (PtInRect (&rect,pt) == FALSE) {
1254 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1255 continue;
1256 }
1257
1258 dprintf(("ChildWindowFromPointEx returned %x", hWnd));
1259 // found it!
1260 return hWnd;
1261 }
1262
1263 // the point is in the parentwindow but the parentwindow has no child
1264 // at this coordinate
1265 dprintf(("ChildWindowFromPointEx returned parent %x", hwndParent));
1266 return hwndParent;
1267}
1268//******************************************************************************
1269//******************************************************************************
1270BOOL WIN32API CloseWindow(HWND hwnd)
1271{
1272 Win32BaseWindow *window;
1273
1274 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1275 if(!window) {
1276 dprintf(("CloseWindow, window %x not found", hwnd));
1277 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1278 return 0;
1279 }
1280 dprintf(("CloseWindow %x\n", hwnd));
1281 return window->CloseWindow();
1282}
1283//******************************************************************************
1284//TODO: Does this return handles of hidden or disabled windows?
1285//******************************************************************************
1286HWND WIN32API WindowFromPoint( POINT point)
1287{
1288 HWND hwndOS2, hwnd;
1289 POINT wPoint;
1290
1291 wPoint.x = point.x;
1292 wPoint.y = mapScreenY(point.y);
1293
1294 hwndOS2 = OSLibWinWindowFromPoint(OSLIB_HWND_DESKTOP, (PVOID)&wPoint);
1295 if(hwndOS2)
1296 {
1297 hwnd = Win32BaseWindow::OS2ToWin32Handle(hwndOS2);
1298 if (!hwnd)
1299 {
1300 //CB: could be a frame control
1301 hwndOS2 = OSLibWinQueryWindow(hwndOS2,QWOS_PARENT);
1302 hwnd = Win32BaseWindow::OS2ToWin32Handle(hwndOS2);
1303 }
1304 if(hwnd) {
1305 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwnd));
1306 return hwnd;
1307 }
1308 }
1309 dprintf(("WindowFromPoint (%d,%d) %x->1\n", point.x, point.y, hwndOS2));
1310 return windowDesktop->getWindowHandle();
1311}
1312//******************************************************************************
1313//******************************************************************************
1314BOOL WIN32API IsWindowUnicode(HWND hwnd)
1315{
1316 Win32BaseWindow *window;
1317
1318 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1319 if(!window) {
1320 dprintf(("IsWindowUnicode, window %x not found", hwnd));
1321 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1322 return 0;
1323 }
1324 return window->IsWindowUnicode();
1325}
1326/***********************************************************************
1327 * SwitchToThisWindow (USER32.539)
1328 */
1329DWORD WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
1330{
1331 return ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
1332}
1333//******************************************************************************
1334//******************************************************************************
1335BOOL WIN32API EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
1336{
1337 return windowDesktop->EnumThreadWindows(dwThreadId, lpfn, lParam);
1338}
1339//******************************************************************************
1340//******************************************************************************
1341BOOL WIN32API EnumChildWindows(HWND hwnd, WNDENUMPROC lpfn, LPARAM lParam)
1342{
1343 Win32BaseWindow *window;
1344 BOOL rc = TRUE;
1345 ULONG henum;
1346 HWND hwndNext;
1347
1348 if(lpfn == NULL) {
1349 dprintf(("EnumChildWindows invalid parameter %x %x\n", hwnd, lParam));
1350 SetLastError(ERROR_INVALID_PARAMETER);
1351 return FALSE;
1352 }
1353 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1354 if(!window) {
1355 dprintf(("EnumChildWindows, window %x not found", hwnd));
1356 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1357 return FALSE;
1358 }
1359 return window->EnumChildWindows(lpfn, lParam);
1360}
1361//******************************************************************************
1362//******************************************************************************
1363BOOL WIN32API EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
1364{
1365 return windowDesktop->EnumWindows(lpfn, lParam);
1366}
1367//******************************************************************************
1368//******************************************************************************
1369UINT WIN32API ArrangeIconicWindows( HWND hwnd)
1370{
1371 dprintf(("USER32: ArrangeIconicWindows %x", hwnd));
1372 return O32_ArrangeIconicWindows(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd));
1373}
1374//******************************************************************************
1375//restores iconized window to previous size/position
1376//******************************************************************************
1377BOOL WIN32API OpenIcon(HWND hwnd)
1378{
1379 dprintf(("USER32: OpenIcon"));
1380
1381 if(!IsIconic(hwnd))
1382 return FALSE;
1383 ShowWindow(hwnd, SW_SHOWNORMAL);
1384 return TRUE;
1385}
1386//******************************************************************************
1387//******************************************************************************
1388BOOL WIN32API ShowOwnedPopups( HWND hwnd, BOOL arg2)
1389{
1390 dprintf(("USER32: ShowOwnedPopups %x", hwnd));
1391 return O32_ShowOwnedPopups(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd), arg2);
1392}
1393//******************************************************************************
1394//******************************************************************************
1395HWND WIN32API GetForegroundWindow(void)
1396{
1397 dprintf(("USER32: GetForegroundWindow"));
1398 return Win32BaseWindow::OS2ToWin32Handle(O32_GetForegroundWindow());
1399}
1400//******************************************************************************
1401//******************************************************************************
1402HWND WIN32API GetLastActivePopup( HWND hWnd)
1403{
1404 HWND hwnd;
1405
1406 hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd);
1407
1408 hwnd = Win32BaseWindow::OS2ToWin32Handle(O32_GetLastActivePopup(hWnd));
1409
1410 dprintf(("GetLastActivePopup %x returned %x", hWnd, hwnd));
1411 return hwnd;
1412}
1413//******************************************************************************
1414//******************************************************************************
1415DWORD WIN32API GetWindowThreadProcessId(HWND hWnd, PDWORD lpdwProcessId)
1416{
1417 dprintf2(("USER32: GetWindowThreadProcessId"));
1418 hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd);
1419
1420 return O32_GetWindowThreadProcessId(hWnd,lpdwProcessId);
1421}
1422//******************************************************************************
1423//******************************************************************************
1424DWORD WIN32API GetWindowContextHelpId(HWND hwnd)
1425{
1426 Win32BaseWindow *window;
1427
1428 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1429 if(!window) {
1430 dprintf(("GetWindowContextHelpId, window %x not found", hwnd));
1431 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1432 return 0;
1433 }
1434 dprintf(("GetWindowContextHelpId %x", hwnd));
1435 return window->getWindowContextHelpId();
1436}
1437//******************************************************************************
1438//******************************************************************************
1439BOOL WIN32API SetWindowContextHelpId(HWND hwnd, DWORD dwContextHelpId)
1440{
1441 Win32BaseWindow *window;
1442
1443 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1444 if(!window) {
1445 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
1446 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1447 return 0;
1448 }
1449 dprintf(("SetWindowContextHelpId %x %d", hwnd, dwContextHelpId));
1450 window->setWindowContextHelpId(dwContextHelpId);
1451 return(TRUE);
1452}
1453//******************************************************************************
1454//******************************************************************************
Note: See TracBrowser for help on using the repository browser.