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

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

Lots of changes

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