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

Last change on this file since 1256 was 1256, checked in by sandervl, 26 years ago

MDI fix, extra message support etc

File size: 44.3 KB
Line 
1/* $Id: window.cpp,v 1.14 1999-10-12 14:47:24 sandervl 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 *
8 * Parts based on Wine Windows code (windows\win.c)
9 *
10 * Copyright 1993, 1994 Alexandre Julliard
11 *
12 * Project Odin Software License can be found in LICENSE.TXT
13 *
14 *
15 * TODO: Decide what to do about commands for OS/2 windows (non-Win32 apps)
16 *
17 */
18
19#include <os2win.h>
20#include <misc.h>
21#include <string.h>
22#include <stdio.h>
23#include <win32wbase.h>
24#include <win32wmdiclient.h>
25#include <win32wdesktop.h>
26#include "win32dlg.h"
27#include <oslibwin.h>
28#include <oslibgdi.h>
29#include "user32.h"
30#include "winicon.h"
31
32//******************************************************************************
33//******************************************************************************
34HWND WIN32API CreateWindowExA(DWORD exStyle, LPCSTR className,
35 LPCSTR windowName, DWORD style, INT x,
36 INT y, INT width, INT height,
37 HWND parent, HMENU menu,
38 HINSTANCE instance, LPVOID data )
39{
40 Win32BaseWindow *window;
41 ATOM classAtom;
42 CREATESTRUCTA cs;
43 char tmpClass[20];
44
45 if(exStyle & WS_EX_MDICHILD)
46 return CreateMDIWindowA(className, windowName, style, x, y, width, height, parent, instance, (LPARAM)data);
47
48 /* Find the class atom */
49 if (!(classAtom = GlobalFindAtomA(className)))
50 {
51 if (!HIWORD(className))
52 {
53 sprintf(tmpClass,"#%d", (int) className);
54 classAtom = GlobalFindAtomA(tmpClass);
55 className = tmpClass;
56 }
57 if (!classAtom)
58 {
59 if (!HIWORD(className)) {
60 dprintf(("CreateWindowEx32W: bad class name %04x\n", LOWORD(className)));
61 }
62 else dprintf(("CreateWindowEx32W: bad class name '%s'\n", className ));
63
64 SetLastError(ERROR_INVALID_PARAMETER);
65 return 0;
66 }
67 }
68
69 /* Create the window */
70 cs.lpCreateParams = data;
71 cs.hInstance = instance;
72 cs.hMenu = menu;
73 cs.hwndParent = parent;
74 cs.x = x;
75 cs.y = y;
76 cs.cx = width;
77 cs.cy = height;
78 cs.style = style;
79 cs.lpszName = windowName;
80 cs.lpszClass = className;
81 cs.dwExStyle = exStyle;
82 if(HIWORD(className)) {
83 dprintf(("CreateWindowExA: class %s parent %x (%d,%d) (%d,%d), %x %x", className, parent, x, y, width, height, style, exStyle));
84 }
85 else dprintf(("CreateWindowExA: class %d parent %x (%d,%d) (%d,%d), %x %x", className, parent, x, y, width, height, style, exStyle));
86
87 if(!strcmpi(className, MDICLIENTCLASSNAMEA)) {
88 window = (Win32BaseWindow *) new Win32MDIClientWindow(&cs, classAtom, FALSE);
89 }
90 else
91 if(!strcmpi((char *) className, DIALOG_CLASS_NAMEA))
92 {
93 DLG_TEMPLATE dlgTemplate = {0};
94 dlgTemplate.style = cs.style;
95 dlgTemplate.exStyle = cs.dwExStyle;
96 dlgTemplate.x = cs.x;
97 dlgTemplate.y = cs.y;
98 dlgTemplate.cx = cs.cx;
99 dlgTemplate.cy = cs.cy;
100 dlgTemplate.className = cs.lpszClass;
101 dlgTemplate.caption = cs.lpszName;
102 window = (Win32BaseWindow *) new Win32Dialog(cs.hInstance,
103 (LPCSTR) &dlgTemplate,
104 cs.hwndParent,
105 NULL,
106 (LPARAM) data,
107 FALSE);
108 }
109 else {
110 window = new Win32BaseWindow( &cs, classAtom, FALSE );
111 }
112 if(window == NULL)
113 {
114 dprintf(("Win32BaseWindow creation failed!!"));
115 return 0;
116 }
117 if(GetLastError() != 0)
118 {
119 dprintf(("Win32BaseWindow error found!!"));
120 delete window;
121 return 0;
122 }
123 return window->getWindowHandle();
124}
125//******************************************************************************
126//******************************************************************************
127HWND WIN32API CreateWindowExW(DWORD exStyle, LPCWSTR className,
128 LPCWSTR windowName, DWORD style, INT x,
129 INT y, INT width, INT height,
130 HWND parent, HMENU menu,
131 HINSTANCE instance, LPVOID data )
132{
133 Win32BaseWindow *window;
134 ATOM classAtom;
135 CREATESTRUCTA cs;
136 char tmpClassA[20];
137 WCHAR tmpClassW[20];
138
139 if(exStyle & WS_EX_MDICHILD)
140 return CreateMDIWindowW(className, windowName, style, x, y, width, height, parent, instance, (LPARAM)data);
141
142 /* Find the class atom */
143 if (!(classAtom = GlobalFindAtomW(className)))
144 {
145 if (!HIWORD(className))
146 {
147 sprintf(tmpClassA,"#%d", (int) className);
148 AsciiToUnicode(tmpClassA, tmpClassW);
149 classAtom = GlobalFindAtomW(tmpClassW);
150 className = (LPCWSTR)tmpClassW;
151 }
152 if (!classAtom)
153 {
154 if (!HIWORD(className)) {
155 dprintf(("CreateWindowEx32W: bad class name %04x\n", LOWORD(className)));
156 }
157 else dprintf(("CreateWindowEx32W: bad class name "));
158
159 SetLastError(ERROR_INVALID_PARAMETER);
160 return 0;
161 }
162 }
163
164 /* Create the window */
165 cs.lpCreateParams = data;
166 cs.hInstance = instance;
167 cs.hMenu = menu;
168 cs.hwndParent = parent;
169 cs.x = x;
170 cs.y = y;
171 cs.cx = width;
172 cs.cy = height;
173 cs.style = style;
174 cs.lpszName = (LPSTR)windowName;
175 cs.lpszClass = (LPSTR)className;
176 cs.dwExStyle = exStyle;
177
178 if(!lstrcmpiW(className, (LPWSTR)MDICLIENTCLASSNAMEW)) {
179 window = (Win32BaseWindow *) new Win32MDIClientWindow(&cs, classAtom, TRUE);
180 }
181 else
182 if(!lstrcmpiW(className, (LPWSTR)DIALOG_CLASS_NAMEW))
183 {
184 DLG_TEMPLATE dlgTemplate = {0};
185 dlgTemplate.style = cs.style;
186 dlgTemplate.exStyle = cs.dwExStyle;
187 dlgTemplate.x = cs.x;
188 dlgTemplate.y = cs.y;
189 dlgTemplate.cx = cs.cx;
190 dlgTemplate.cy = cs.cy;
191 dlgTemplate.className = cs.lpszClass;
192 dlgTemplate.caption = cs.lpszName;
193 window = (Win32BaseWindow *) new Win32Dialog(cs.hInstance,
194 (LPCSTR) &dlgTemplate,
195 cs.hwndParent,
196 NULL,
197 (LPARAM) data,
198 TRUE);
199 }
200 else {
201 window = new Win32BaseWindow( &cs, classAtom, TRUE );
202 }
203 if(window == NULL)
204 {
205 dprintf(("Win32BaseWindow creation failed!!"));
206 return 0;
207 }
208 if(GetLastError() != 0)
209 {
210 dprintf(("Win32BaseWindow error found!!"));
211 delete window;
212 return 0;
213 }
214 return window->getWindowHandle();
215}
216//******************************************************************************
217//******************************************************************************
218HWND WIN32API CreateMDIWindowA(LPCSTR lpszClassName, LPCSTR lpszWindowName,
219 DWORD dwStyle, int x, int y, int nWidth,
220 int nHeight, HWND hwndParent,
221 HINSTANCE hInstance, LPARAM lParam )
222{
223 HWND hwnd;
224 MDICREATESTRUCTA cs;
225 Win32BaseWindow *window;
226
227 window = Win32BaseWindow::GetWindowFromHandle(hwndParent);
228 if(!window) {
229 dprintf(("CreateMDIWindowA, window %x not found", hwndParent));
230 return 0;
231 }
232
233 dprintf(("USER32: CreateMDIWindowA\n"));
234 cs.szClass = lpszClassName;
235 cs.szTitle = lpszWindowName;
236 cs.hOwner = hInstance;
237 cs.x = x;
238 cs.y = y;
239 cs.cx = nHeight;
240 cs.cy = nWidth;
241 cs.style = dwStyle;
242 cs.lParam = lParam;
243
244 return window->SendMessageA(WM_MDICREATE, 0, (LPARAM)&cs);
245}
246//******************************************************************************
247//******************************************************************************
248HWND WIN32API CreateMDIWindowW(LPCWSTR lpszClassName, LPCWSTR lpszWindowName,
249 DWORD dwStyle, int x, int y, int nWidth,
250 int nHeight, HWND hwndParent,
251 HINSTANCE hInstance, LPARAM lParam )
252{
253 HWND hwnd;
254 MDICREATESTRUCTW cs;
255 Win32BaseWindow *window;
256
257 window = Win32BaseWindow::GetWindowFromHandle(hwndParent);
258 if(!window) {
259 dprintf(("CreateMDIWindowW, window %x not found", hwndParent));
260 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
261 return 0;
262 }
263
264 dprintf(("USER32: CreateMDIWindowW\n"));
265 cs.szClass = lpszClassName;
266 cs.szTitle = lpszWindowName;
267 cs.hOwner = hInstance;
268 cs.x = x;
269 cs.y = y;
270 cs.cx = nHeight;
271 cs.cy = nWidth;
272 cs.style = dwStyle;
273 cs.lParam = lParam;
274
275 return window->SendMessageW(WM_MDICREATE, 0, (LPARAM)&cs);
276}
277//******************************************************************************
278//******************************************************************************
279BOOL WIN32API DestroyWindow(HWND hwnd)
280{
281 Win32BaseWindow *window;
282
283 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
284 if(!window) {
285 dprintf(("DestroyWindow, window %x not found", hwnd));
286 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
287 return 0;
288 }
289 dprintf(("DestroyWindow %x", hwnd));
290 return window->DestroyWindow();
291}
292//******************************************************************************
293//******************************************************************************
294HWND WIN32API SetActiveWindow( HWND hwnd)
295{
296 Win32BaseWindow *window;
297
298 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
299 if(!window) {
300 dprintf(("SetActiveWindow, window %x not found", hwnd));
301 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
302 return 0;
303 }
304 dprintf(("SetActiveWindow %x", hwnd));
305 return window->SetActiveWindow();
306}
307//******************************************************************************
308//******************************************************************************
309HWND WIN32API GetParent( HWND hwnd)
310{
311 Win32BaseWindow *window;
312
313 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
314 if(!window) {
315 dprintf(("GetParent, window %x not found", hwnd));
316 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
317 return 0;
318 }
319 dprintf(("GetParent %x", hwnd));
320 return window->GetParent();
321}
322//******************************************************************************
323//******************************************************************************
324HWND WIN32API SetParent( HWND hwndChild, HWND hwndNewParent)
325{
326 Win32BaseWindow *window;
327
328 window = Win32BaseWindow::GetWindowFromHandle(hwndChild);
329 if(!window) {
330 dprintf(("SetParent, window %x not found", hwndChild));
331 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
332 return 0;
333 }
334 dprintf(("SetParent %x %x", hwndChild, hwndNewParent));
335 return window->SetParent(hwndNewParent);
336}
337//******************************************************************************
338//******************************************************************************
339BOOL WIN32API IsChild( HWND hwndParent, HWND hwnd)
340{
341 Win32BaseWindow *window;
342
343 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
344 if(!window) {
345 dprintf(("IsChild, window %x not found", hwnd));
346 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
347 return 0;
348 }
349 dprintf(("IsChild %x %x", hwndParent, hwnd));
350 return window->IsChild(hwndParent);
351}
352//******************************************************************************
353//******************************************************************************
354HWND WIN32API GetTopWindow( HWND hwnd)
355{
356 Win32BaseWindow *window;
357
358 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
359 if(!window) {
360 dprintf(("GetTopWindow, window %x not found", hwnd));
361 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
362 return 0;
363 }
364 return window->GetTopWindow();
365}
366//******************************************************************************
367//******************************************************************************
368#if 0
369BOOL WIN32API UpdateWindow(HWND hwnd)
370{
371 Win32BaseWindow *window;
372
373 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
374 if(!window) {
375 dprintf(("UpdateWindow, window %x not found", hwnd));
376 return 0;
377 }
378 dprintf(("UpdateWindow %x", hwnd));
379 return window->UpdateWindow();
380}
381#endif
382//******************************************************************************
383//******************************************************************************
384BOOL WIN32API IsIconic( HWND hwnd)
385{
386 Win32BaseWindow *window;
387
388 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
389 if(!window) {
390 dprintf(("IsIconic, window %x not found", hwnd));
391 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
392 return 0;
393 }
394 dprintf(("IsIconic %x", hwnd));
395 return window->IsIconic();
396}
397//******************************************************************************
398//******************************************************************************
399HWND WIN32API GetWindow(HWND hwnd, UINT uCmd)
400{
401 Win32BaseWindow *window;
402
403 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
404 if(!window) {
405 dprintf(("GetWindow, window %x not found", hwnd));
406 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
407 return 0;
408 }
409 dprintf(("GetWindow %x %d", hwnd, uCmd));
410 return window->GetWindow(uCmd);
411}
412//******************************************************************************
413//******************************************************************************
414BOOL WIN32API EnableWindow( HWND hwnd, BOOL fEnable)
415{
416 Win32BaseWindow *window;
417
418 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
419 if(!window) {
420 dprintf(("EnableWindow, window %x not found", hwnd));
421 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
422 return 0;
423 }
424 dprintf(("EnableWindow %x %d", hwnd, fEnable));
425 return window->EnableWindow(fEnable);
426}
427//******************************************************************************
428//******************************************************************************
429BOOL WIN32API BringWindowToTop(HWND hwnd)
430{
431 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
432}
433//******************************************************************************
434//******************************************************************************
435HWND WIN32API GetActiveWindow()
436{
437 return Win32BaseWindow::GetActiveWindow();
438}
439//******************************************************************************
440//******************************************************************************
441BOOL WIN32API ShowWindow(HWND hwnd, int nCmdShow)
442{
443 Win32BaseWindow *window;
444
445 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
446 if(!window) {
447 dprintf(("ShowWindow, window %x not found", hwnd));
448 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
449 return 0;
450 }
451 dprintf(("ShowWindow %x", hwnd));
452 return window->ShowWindow(nCmdShow);
453}
454//******************************************************************************
455//******************************************************************************
456BOOL WIN32API SetWindowPos(HWND hwnd, HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
457{
458 Win32BaseWindow *window;
459
460 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
461 if(!window) {
462 dprintf(("SetWindowPos, window %x not found", hwnd));
463 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
464 return 0;
465 }
466 dprintf(("SetWindowPos %x %x x=%d y=%d cx=%d cy=%d %x", hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
467 return window->SetWindowPos(hwndInsertAfter, x, y, cx, cy, fuFlags);
468}
469//******************************************************************************
470//******************************************************************************
471BOOL WIN32API SetWindowPlacement( HWND arg1, const WINDOWPLACEMENT * arg2)
472{
473 dprintf(("USER32: SetWindowPlacement\n"));
474 return O32_SetWindowPlacement(arg1, arg2);
475}
476//******************************************************************************
477//******************************************************************************
478BOOL WIN32API GetWindowPlacement( HWND arg1, LPWINDOWPLACEMENT arg2)
479{
480#ifdef DEBUG
481 WriteLog("USER32: GetWindowPlacement\n");
482#endif
483 return O32_GetWindowPlacement(arg1, arg2);
484}
485//******************************************************************************
486//******************************************************************************
487BOOL WIN32API IsWindow( HWND hwnd)
488{
489 Win32BaseWindow *window;
490
491 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
492 if(!window) {
493 dprintf(("IsWindow, window %x not found", hwnd));
494 return FALSE;
495 }
496 dprintf(("IsWindow %x", hwnd));
497 return window->IsWindow();
498}
499//******************************************************************************
500//******************************************************************************
501BOOL WIN32API IsWindowEnabled( HWND hwnd)
502{
503 Win32BaseWindow *window;
504
505 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
506 if(!window) {
507 dprintf(("IsWindowEnabled, window %x not found", hwnd));
508 return 0;
509 }
510 dprintf(("IsWindowEnabled %x", hwnd));
511 return window->IsWindowEnabled();
512}
513//******************************************************************************
514//******************************************************************************
515BOOL WIN32API IsWindowVisible( HWND hwnd)
516{
517 Win32BaseWindow *window;
518
519 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
520 if(!window) {
521 dprintf(("IsWindowVisible, window %x not found", hwnd));
522 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
523 return 0;
524 }
525 dprintf(("IsWindowVisible %x", hwnd));
526 return window->IsWindowVisible();
527}
528//******************************************************************************
529//******************************************************************************
530HWND WIN32API SetFocus (HWND hwnd)
531{
532 HWND lastFocus, lastFocus_W, hwnd_O;
533 BOOL activate;
534
535 hwnd_O = Win32BaseWindow::Win32ToOS2Handle (hwnd);
536 lastFocus = OSLibWinQueryFocus (OSLIB_HWND_DESKTOP);
537 activate = ((hwnd_O == lastFocus) || OSLibWinIsChild (lastFocus, hwnd_O));
538 lastFocus_W = Win32BaseWindow::OS2ToWin32Handle (lastFocus);
539
540 dprintf(("SetFocus %x (%x) -> %x (%x)\n", lastFocus_W, lastFocus, hwnd, hwnd_O));
541
542 return (OSLibWinSetFocus (OSLIB_HWND_DESKTOP, hwnd_O, activate)) ? lastFocus_W : 0;
543}
544//******************************************************************************
545//******************************************************************************
546HWND WIN32API GetFocus(void)
547{
548 HWND hwnd;
549
550 hwnd = OSLibWinQueryFocus(OSLIB_HWND_DESKTOP);
551 dprintf(("USER32: GetFocus %x\n", hwnd));
552 hwnd = Win32BaseWindow::OS2ToWin32Handle(hwnd);
553 return hwnd;
554}
555//******************************************************************************
556//******************************************************************************
557/***********************************************************************
558 * GetInternalWindowPos (USER32.245)
559 */
560UINT WIN32API GetInternalWindowPos(HWND hwnd,
561 LPRECT rectWnd,
562 LPPOINT ptIcon )
563{
564 WINDOWPLACEMENT wndpl;
565
566 dprintf(("USER32: GetInternalWindowPos(%08xh,%08xh,%08xh)\n",
567 hwnd,
568 rectWnd,
569 ptIcon));
570
571 if (GetWindowPlacement( hwnd, &wndpl ))
572 {
573 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
574 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
575 return wndpl.showCmd;
576 }
577 return 0;
578}
579//******************************************************************************
580//******************************************************************************
581BOOL WIN32API IsZoomed( HWND arg1)
582{
583#ifdef DEBUG
584 WriteLog("USER32: IsZoomed\n");
585#endif
586 return O32_IsZoomed(arg1);
587}
588//******************************************************************************
589//******************************************************************************
590BOOL WIN32API LockWindowUpdate( HWND arg1)
591{
592#ifdef DEBUG
593 WriteLog("USER32: LockWindowUpdate\n");
594#endif
595 return O32_LockWindowUpdate(arg1);
596}
597//******************************************************************************
598//******************************************************************************
599
600#if 0
601BOOL WIN32API RedrawWindow( HWND arg1, const RECT * arg2, HRGN arg3, UINT arg4)
602{
603 BOOL rc;
604
605 rc = O32_RedrawWindow(arg1, arg2, arg3, arg4);
606#ifdef DEBUG
607 WriteLog("USER32: RedrawWindow %X , %X, %X, %X returned %d\n", arg1, arg2, arg3, arg4, rc);
608#endif
609 InvalidateRect(arg1, arg2, TRUE);
610 UpdateWindow(arg1);
611 SendMessageA(arg1, WM_PAINT, 0, 0);
612 return(rc);
613}
614#endif
615//******************************************************************************
616//******************************************************************************
617BOOL WIN32API GetWindowRect( HWND hwnd, PRECT pRect)
618{
619 Win32BaseWindow *window;
620
621 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
622 if(!window) {
623 dprintf(("GetWindowRect, window %x not found", hwnd));
624 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
625 return 0;
626 }
627 dprintf(("GetWindowRect %x", hwnd));
628 return window->GetWindowRect(pRect);
629}
630//******************************************************************************
631//******************************************************************************
632int WIN32API GetWindowTextLengthA( HWND hwnd)
633{
634 Win32BaseWindow *window;
635
636 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
637 if(!window) {
638 dprintf(("GetWindowTextLength, window %x not found", hwnd));
639 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
640 return 0;
641 }
642 dprintf(("GetWindowTextLength %x", hwnd));
643 return window->GetWindowTextLength();
644}
645//******************************************************************************
646//******************************************************************************
647int WIN32API GetWindowTextA( HWND hwnd, LPSTR lpsz, int cch)
648{
649 Win32BaseWindow *window;
650 int rc;
651
652 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
653 if(!window) {
654 dprintf(("GetWindowTextA, window %x not found", hwnd));
655 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
656 return 0;
657 }
658 rc = window->GetWindowTextA(lpsz, cch);
659 dprintf(("GetWindowTextA %x %s", hwnd, lpsz));
660 return rc;
661}
662//******************************************************************************
663//******************************************************************************
664int WIN32API GetWindowTextLengthW( HWND hwnd)
665{
666 dprintf(("USER32: GetWindowTextLengthW\n"));
667 return GetWindowTextLengthA(hwnd);
668}
669//******************************************************************************
670//******************************************************************************
671int WIN32API GetWindowTextW(HWND hwnd, LPWSTR lpsz, int cch)
672{
673 Win32BaseWindow *window;
674
675 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
676 if(!window) {
677 dprintf(("GetWindowTextW, window %x not found", hwnd));
678 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
679 return 0;
680 }
681 dprintf(("GetWindowTextW %x", hwnd));
682 return window->GetWindowTextW(lpsz, cch);
683}
684//******************************************************************************
685//******************************************************************************
686BOOL WIN32API SetWindowTextA(HWND hwnd, LPCSTR lpsz)
687{
688 Win32BaseWindow *window;
689
690 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
691 if(!window) {
692 dprintf(("SetWindowTextA, window %x not found", hwnd));
693 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
694 return 0;
695 }
696 dprintf(("SetWindowTextA %x %s", hwnd, lpsz));
697 return window->SetWindowTextA((LPSTR)lpsz);
698}
699//******************************************************************************
700//******************************************************************************
701BOOL WIN32API SetWindowTextW( HWND hwnd, LPCWSTR lpsz)
702{
703 Win32BaseWindow *window;
704
705 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
706 if(!window) {
707 dprintf(("SetWindowTextA, window %x not found", hwnd));
708 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
709 return 0;
710 }
711 dprintf(("SetWindowTextW %x", hwnd));
712 return window->SetWindowTextW((LPWSTR)lpsz);
713}
714/*******************************************************************
715 * InternalGetWindowText (USER32.326)
716 */
717int WIN32API InternalGetWindowText(HWND hwnd,
718 LPWSTR lpString,
719 INT nMaxCount )
720{
721 dprintf(("USER32: InternalGetWindowText(%08xh,%08xh,%08xh) not properly implemented.\n",
722 hwnd,
723 lpString,
724 nMaxCount));
725
726 return GetWindowTextW(hwnd,lpString,nMaxCount);
727}
728//******************************************************************************
729//TODO: Correct?
730//******************************************************************************
731BOOL WIN32API SetForegroundWindow(HWND hwnd)
732{
733 dprintf((" SetForegroundWindow %x", hwnd));
734
735 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER );
736}
737//******************************************************************************
738//******************************************************************************
739BOOL WIN32API GetClientRect( HWND hwnd, PRECT pRect)
740{
741 BOOL rc;
742 HWND hwndWin32 = hwnd;
743
744 hwnd = Win32BaseWindow::Win32ToOS2Handle(hwnd);
745 rc = OSLibWinQueryWindowRect(hwnd, pRect);
746 dprintf(("GetClientRect of %X returned (%d,%d) (%d,%d)\n", hwndWin32, pRect->left, pRect->top, pRect->right, pRect->bottom));
747 return rc;
748}
749//******************************************************************************
750//******************************************************************************
751BOOL WIN32API AdjustWindowRect( PRECT arg1, DWORD arg2, BOOL arg3)
752{
753#ifdef DEBUG
754 WriteLog("USER32: AdjustWindowRect\n");
755#endif
756 return O32_AdjustWindowRect(arg1, arg2, arg3);
757}
758//******************************************************************************
759//******************************************************************************
760BOOL WIN32API AdjustWindowRectEx( PRECT arg1, DWORD arg2, BOOL arg3, DWORD arg4)
761{
762#ifdef DEBUG
763 WriteLog("USER32: AdjustWindowRectEx\n");
764#endif
765 return O32_AdjustWindowRectEx(arg1, arg2, arg3, arg4);
766}
767//******************************************************************************
768//******************************************************************************
769HWND WIN32API GetDesktopWindow(void)
770{
771 dprintf(("USER32: GetDesktopWindow\n"));
772 return windowDesktop->getWindowHandle();
773}
774//******************************************************************************
775//******************************************************************************
776HWND WIN32API FindWindowA(LPCSTR lpszClass, LPCSTR lpszWindow)
777{
778 if(!lpszClass) {
779 SetLastError(ERROR_INVALID_PARAMETER);
780 return 0;
781 }
782 if(HIWORD(lpszClass)) {
783 dprintf(("USER32: FindWindow %s %s\n", lpszClass, lpszWindow));
784 }
785 else dprintf(("USER32: FindWindow %x %s\n", lpszClass, lpszWindow));
786
787 return Win32BaseWindow::FindWindowEx(OSLIB_HWND_DESKTOP, 0, (LPSTR)lpszClass, (LPSTR)lpszWindow);
788}
789//******************************************************************************
790//******************************************************************************
791HWND WIN32API FindWindowExA(HWND hwndParent, HWND hwndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow)
792{
793 if(!lpszClass) {
794 SetLastError(ERROR_INVALID_PARAMETER);
795 return 0;
796 }
797 if(HIWORD(lpszClass)) {
798 dprintf(("USER32: FindWindowExA (%x,%x) %s %s\n", hwndParent, hwndChildAfter, lpszClass, lpszWindow));
799 }
800 else dprintf(("USER32: FindWindowExA (%x,%x)%x %s\n", hwndParent, hwndChildAfter, lpszClass, lpszWindow));
801
802 return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, (LPSTR)lpszClass, (LPSTR)lpszWindow);
803}
804/*****************************************************************************
805 * Name : HWND WIN32API FindWindowExW
806 * Purpose : The FindWindowEx function retrieves the handle of a window whose
807 * class name and window name match the specified strings. The
808 * function searches child windows, beginning with the one following
809 * the given child window.
810 * Parameters: HWND hwndParent handle of parent window
811 * HWND hwndChildAfter handle of a child window
812 * LPCTSTR lpszClass address of class name
813 * LPCTSTR lpszWindow address of window name
814 * Variables :
815 * Result : If the function succeeds, the return value is the handle of the
816 * window that has the specified class and window names.
817 * If the function fails, the return value is NULL. To get extended
818 * error information, call GetLastError.
819 * Remark :
820 * Status : UNTESTED STUB
821 *
822 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
823 *****************************************************************************/
824
825HWND WIN32API FindWindowExW(HWND hwndParent,
826 HWND hwndChildAfter,
827 LPCWSTR lpszClass,
828 LPCWSTR lpszWindow)
829{
830 if(!lpszClass) {
831 SetLastError(ERROR_INVALID_PARAMETER);
832 return 0;
833 }
834 dprintf(("USER32: FindWindowExW (%x,%x) %x %s\n", hwndParent, hwndChildAfter, lpszClass, lpszWindow));
835
836 return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, (LPSTR)lpszClass, (LPSTR)lpszWindow);
837}
838//******************************************************************************
839//******************************************************************************
840BOOL WIN32API FlashWindow(HWND hwnd, BOOL fFlash)
841{
842 dprintf(("FlashWindow %x %d\n", hwnd, fFlash));
843 return OSLibWinFlashWindow(Win32BaseWindow::Win32ToOS2Handle(hwnd), fFlash);
844}
845//******************************************************************************
846//******************************************************************************
847BOOL WIN32API MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
848 BOOL repaint )
849{
850 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
851
852 if (!repaint) flags |= SWP_NOREDRAW;
853 dprintf(("MoveWindow: %04x %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint ));
854
855 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
856}
857//******************************************************************************
858//******************************************************************************
859BOOL WIN32API ClientToScreen (HWND hwnd, PPOINT pt)
860{
861#ifdef DEBUG
862 WriteLog("USER32: ClientToScreen\n");
863#endif
864 Win32BaseWindow *wnd;
865 PRECT rcl;
866
867 if (!hwnd) {
868 SetLastError(ERROR_INVALID_PARAMETER);
869 return (FALSE);
870 }
871 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
872 if (!wnd) {
873 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
874 return (FALSE);
875 }
876
877 rcl = wnd->getClientRect();
878 pt->y = (rcl->bottom - rcl->top) - pt->y;
879 OSLibWinMapWindowPoints (wnd->getOS2WindowHandle(), OSLIB_HWND_DESKTOP, (OSLIBPOINT *)pt, 1);
880 pt->y = ScreenHeight - pt->y;
881 return (TRUE);
882}
883//******************************************************************************
884//******************************************************************************
885HDWP WIN32API BeginDeferWindowPos( int arg1)
886{
887#ifdef DEBUG
888 WriteLog("USER32: BeginDeferWindowPos\n");
889#endif
890 return O32_BeginDeferWindowPos(arg1);
891}
892//******************************************************************************
893//******************************************************************************
894HDWP WIN32API DeferWindowPos( HDWP arg1, HWND arg2, HWND arg3, int arg4, int arg5, int arg6, int arg7, UINT arg8)
895{
896#ifdef DEBUG
897 WriteLog("USER32: DeferWindowPos\n");
898#endif
899 return O32_DeferWindowPos(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
900}
901//******************************************************************************
902//******************************************************************************
903HWND WIN32API ChildWindowFromPoint( HWND hwnd, POINT pt)
904{
905 dprintf(("USER32: ChildWindowFromPoint\n"));
906// return O32_ChildWindowFromPoint(arg1, arg2);
907 return ChildWindowFromPointEx(hwnd, pt, 0);
908}
909//******************************************************************************
910//******************************************************************************
911/*****************************************************************************
912 * Name : HWND WIN32API ChildWindowFromPointEx
913 * Purpose : The GetWindowRect function retrieves the dimensions of the
914 * bounding rectangle of the specified window. The dimensions are
915 * given in screen coordinates that are relative to the upper-left
916 * corner of the screen.
917 * Parameters:
918 * Variables :
919 * Result : If the function succeeds, the return value is the window handle.
920 * If the function fails, the return value is zero
921 * Remark :
922 * Status : FULLY IMPLEMENTED AND TESTED
923 *
924 * Author : Rene Pronk [Sun, 1999/08/08 23:30]
925 *****************************************************************************/
926
927HWND WIN32API ChildWindowFromPointEx (HWND hwndParent, POINT pt, UINT uFlags)
928{
929 RECT rect;
930 HWND hWnd;
931 POINT absolutePt;
932
933 dprintf(("ChildWindowFromPointEx(%08xh,%08xh,%08xh).\n",
934 hwndParent, pt, uFlags));
935
936 if (GetWindowRect (hwndParent, &rect) == 0) {
937 // oops, invalid handle
938 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
939 return NULL;
940 }
941
942 // absolutePt has its top in the upper-left corner of the screen
943 absolutePt = pt;
944 ClientToScreen (hwndParent, &absolutePt);
945
946 // make rect the size of the parent window
947 GetWindowRect (hwndParent, &rect);
948 rect.right = rect.right - rect.left;
949 rect.bottom = rect.bottom - rect.top;
950 rect.left = 0;
951 rect.top = 0;
952
953 if (PtInRect (&rect, pt) == 0) {
954 // point is outside window
955 return NULL;
956 }
957
958 // get first child
959 hWnd = GetWindow (hwndParent, GW_CHILD);
960
961 while (hWnd != NULL) {
962
963 // do I need to skip this window?
964 if (((uFlags & CWP_SKIPINVISIBLE) &&
965 (IsWindowVisible (hWnd) == FALSE)) ||
966 ((uFlags & CWP_SKIPDISABLED) &&
967 (IsWindowEnabled (hWnd) == FALSE)) ||
968 ((uFlags & CWP_SKIPTRANSPARENT) &&
969 (GetWindowLongA (hWnd, GWL_EXSTYLE) & WS_EX_TRANSPARENT)))
970
971 {
972 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
973 continue;
974 }
975
976 // is the point in this window's rect?
977 GetWindowRect (hWnd, &rect);
978 if (PtInRect (&rect, absolutePt) == FALSE) {
979 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
980 continue;
981 }
982
983 dprintf(("ChildWindowFromPointEx returned %x", hWnd));
984 // found it!
985 return hWnd;
986 }
987
988 // the point is in the parentwindow but the parentwindow has no child
989 // at this coordinate
990 dprintf(("ChildWindowFromPointEx returned parent %x", hwndParent));
991 return hwndParent;
992}
993//******************************************************************************
994//******************************************************************************
995BOOL WIN32API CloseWindow(HWND hwnd)
996{
997 Win32BaseWindow *window;
998
999 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1000 if(!window) {
1001 dprintf(("CloseWindow, window %x not found", hwnd));
1002 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1003 return 0;
1004 }
1005 dprintf(("CloseWindow %x\n", hwnd));
1006 return window->CloseWindow();
1007}
1008//******************************************************************************
1009//TODO: Does this return handles of hidden or disabled windows?
1010//******************************************************************************
1011HWND WIN32API WindowFromPoint( POINT point)
1012{
1013 HWND hwnd;
1014
1015 dprintf(("WindowFromPoint (%d,%d)\n", point.x, point.y));
1016 hwnd = OSLibWinWindowFromPoint(OSLIB_HWND_DESKTOP, (PVOID)&point);
1017 if(hwnd) {
1018 return Win32BaseWindow::OS2ToWin32Handle(hwnd);
1019 }
1020 return 0;
1021}
1022//******************************************************************************
1023//******************************************************************************
1024BOOL WIN32API IsWindowUnicode(HWND hwnd)
1025{
1026 Win32BaseWindow *window;
1027
1028 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1029 if(!window) {
1030 dprintf(("IsWindowUnicode, window %x not found", hwnd));
1031 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1032 return 0;
1033 }
1034 return window->IsUnicode();
1035}
1036/*****************************************************************************
1037 * Name : WORD WIN32API CascadeWindows
1038 * Purpose : The CascadeWindows function cascades the specified windows or
1039 * the child windows of the specified parent window.
1040 * Parameters: HWND hwndParent handle of parent window
1041 * UINT wHow types of windows not to arrange
1042 * CONST RECT * lpRect rectangle to arrange windows in
1043 * UINT cKids number of windows to arrange
1044 * const HWND FAR * lpKids array of window handles
1045 * Variables :
1046 * Result : If the function succeeds, the return value is the number of windows arranged.
1047 * If the function fails, the return value is zero.
1048 * Remark :
1049 * Status : UNTESTED STUB
1050 *
1051 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1052 *****************************************************************************/
1053
1054WORD WIN32API CascadeWindows(HWND hwndParent,
1055 UINT wHow,
1056 CONST LPRECT lpRect,
1057 UINT cKids,
1058 const HWND *lpKids)
1059{
1060 dprintf(("USER32:CascadeWindows(%08xh,%u,%08xh,%u,%08x) not implemented.\n",
1061 hwndParent,
1062 wHow,
1063 lpRect,
1064 cKids,
1065 lpKids));
1066
1067 return (0);
1068}
1069/*****************************************************************************
1070 * Name : BOOL WIN32API SwitchToThisWindow
1071 * Purpose : Unknown
1072 * Parameters: Unknown
1073 * Variables :
1074 * Result :
1075 * Remark :
1076 * Status : UNTESTED UNKNOWN STUB
1077 *
1078 * Author : Patrick Haller [Wed, 1998/06/16 11:55]
1079 *****************************************************************************/
1080
1081BOOL WIN32API SwitchToThisWindow(HWND hwnd,
1082 BOOL x2)
1083{
1084 dprintf(("USER32: SwitchToThisWindow(%08xh,%08xh) not implemented.\n",
1085 hwnd,
1086 x2));
1087
1088 return (FALSE); /* default */
1089}
1090//******************************************************************************
1091//******************************************************************************
1092BOOL WIN32API EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
1093{
1094 Win32BaseWindow *window;
1095 BOOL rc;
1096 ULONG henum;
1097 HWND hwndNext;
1098 ULONG tid;
1099 ULONG pid, curpid;
1100
1101 dprintf(("EnumThreadWindows\n"));
1102
1103 curpid = GetCurrentProcessId();
1104
1105 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
1106 while ((hwndNext = OSLibWinGetNextWindow(henum)) != 0)
1107 {
1108 OSLibWinQueryWindowProcess(hwndNext, &pid, &tid);
1109 if(!(curpid == pid && dwThreadId == tid))
1110 continue;
1111
1112 window = Win32BaseWindow::GetWindowFromHandle(hwndNext);
1113 if(window == NULL) {
1114 //OS/2 window or non-frame window, so skip it
1115 continue;
1116 }
1117 if((rc = lpfn(window->getWindowHandle(), lParam)) == FALSE)
1118 break;
1119 }
1120 OSLibWinEndEnumWindows (henum);
1121 return TRUE;
1122}
1123//******************************************************************************
1124//******************************************************************************
1125BOOL WIN32API EnumChildWindows(HWND hwnd, WNDENUMPROC lpfn, LPARAM lParam)
1126{
1127 Win32BaseWindow *window, *parentwindow;
1128 BOOL rc = TRUE;
1129 ULONG henum;
1130 HWND hwndNext;
1131
1132 dprintf(("EnumChildWindows %x %x\n", hwnd, lParam));
1133
1134 parentwindow = Win32BaseWindow::GetWindowFromHandle(hwnd);
1135 if(!parentwindow) {
1136 dprintf(("EnumChildWindows, window %x not found", hwnd));
1137 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1138 return FALSE;
1139 }
1140
1141 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
1142 while ((hwndNext = OSLibWinGetNextWindow(henum)) != 0)
1143 {
1144 window = Win32BaseWindow::GetWindowFromHandle(hwndNext);
1145 if(window == NULL) {
1146 //OS/2 window or non-frame window, so skip it
1147 continue;
1148 }
1149 if((rc = lpfn(window->getWindowHandle(), lParam)) == FALSE)
1150 {
1151 rc = FALSE;
1152 break;
1153 }
1154 }
1155 OSLibWinEndEnumWindows(henum);
1156 return rc;
1157}
1158//******************************************************************************
1159//******************************************************************************
1160BOOL WIN32API EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
1161{
1162 Win32BaseWindow *window;
1163 BOOL rc;
1164 ULONG henum;
1165 HWND hwndNext, hwndParent = OSLIB_HWND_DESKTOP;
1166
1167 dprintf(("EnumThreadWindows\n"));
1168
1169 do {
1170 henum = OSLibWinBeginEnumWindows(hwndParent);
1171 while ((hwndNext = OSLibWinGetNextWindow(henum)) != 0)
1172 {
1173 window = Win32BaseWindow::GetWindowFromHandle(hwndNext);
1174 if(window == NULL) {
1175 //OS/2 window or non-frame window, so skip it
1176 continue;
1177 }
1178 if((rc = lpfn(window->getWindowHandle(), lParam)) == FALSE) {
1179 goto Abort;
1180 }
1181 }
1182 if(hwndParent == OSLIB_HWND_OBJECT)
1183 break;
1184 hwndParent = OSLIB_HWND_OBJECT;
1185 OSLibWinEndEnumWindows(henum);
1186 }
1187 while(TRUE);
1188
1189Abort:
1190 OSLibWinEndEnumWindows(henum);
1191 return TRUE;
1192}
1193//******************************************************************************
1194//******************************************************************************
1195#if 0
1196BOOL WIN32API GetUpdateRect( HWND hwnd, PRECT lpRect, BOOL bErase)
1197{
1198 dprintf(("GetUpdateRect %x %d\n", hwnd, bErase));
1199 if (!lpRect) return FALSE;
1200
1201 return OSLibWinQueryUpdateRect(Win32BaseWindow::Win32ToOS2Handle(hwnd), lpRect);
1202}
1203#endif
1204//******************************************************************************
1205//******************************************************************************
1206#if 0
1207BOOL WIN32API InvalidateRect(HWND hWnd, const RECT *lpRect, BOOL bErase)
1208{
1209#ifdef DEBUG
1210 if(lpRect)
1211 WriteLog("USER32: InvalidateRect for window %X (%d,%d)(%d,%d) %d\n", hWnd, lpRect->left, lpRect->top, lpRect->right, lpRect->bottom, bErase);
1212 else WriteLog("USER32: InvalidateRect for window %X NULL, %d\n", hWnd, bErase);
1213#endif
1214
1215 //CB: bErase no quite the same
1216 hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd);
1217 if (lpRect)
1218 {
1219 return OSLibWinInvalidateRect(hWnd, (PRECT)lpRect, bErase);
1220 }
1221 else return OSLibWinInvalidateRect(hWnd,NULL,bErase);
1222}
1223#endif
1224//******************************************************************************
1225//******************************************************************************
1226UINT WIN32API ArrangeIconicWindows( HWND arg1)
1227{
1228#ifdef DEBUG
1229 WriteLog("USER32: ArrangeIconicWindows\n");
1230#endif
1231 return O32_ArrangeIconicWindows(arg1);
1232}
1233//******************************************************************************
1234//restores iconized window to previous size/position
1235//******************************************************************************
1236BOOL WIN32API OpenIcon(HWND hwnd)
1237{
1238#ifdef DEBUG
1239 WriteLog("USER32: OpenIcon\n");
1240#endif
1241 if(!IsIconic(hwnd))
1242 return FALSE;
1243 ShowWindow(hwnd, SW_SHOWNORMAL);
1244 return TRUE;
1245}
1246//******************************************************************************
1247//******************************************************************************
1248BOOL WIN32API ShowOwnedPopups( HWND arg1, BOOL arg2)
1249{
1250 dprintf(("USER32: ShowOwnedPopups\n"));
1251 return O32_ShowOwnedPopups(arg1, arg2);
1252}
1253//******************************************************************************
1254//******************************************************************************
1255
Note: See TracBrowser for help on using the repository browser.