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

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

GetWindow + EB's message bugfixes

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