ole32: Fix memory leaks in the storage test.
[wine] / dlls / user32 / wnd16.c
1 /*
2  * 16-bit windowing functions
3  *
4  * Copyright 2001 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "wine/winuser16.h"
22 #include "wownt32.h"
23 #include "win.h"
24 #include "user_private.h"
25 #include "wine/server.h"
26
27 /* size of buffer needed to store an atom string */
28 #define ATOM_BUFFER_SIZE 256
29
30 /* handle <--> handle16 conversions */
31 #define HANDLE_16(h32)          (LOWORD(h32))
32 #define HANDLE_32(h16)          ((HANDLE)(ULONG_PTR)(h16))
33
34 static HWND16 hwndSysModal;
35
36 struct wnd_enum_info
37 {
38     WNDENUMPROC16 proc;
39     LPARAM        param;
40 };
41
42 /* callback for 16-bit window enumeration functions */
43 static BOOL CALLBACK wnd_enum_callback( HWND hwnd, LPARAM param )
44 {
45     const struct wnd_enum_info *info = (struct wnd_enum_info *)param;
46     WORD args[3];
47     DWORD ret;
48
49     args[2] = HWND_16(hwnd);
50     args[1] = HIWORD(info->param);
51     args[0] = LOWORD(info->param);
52     WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
53     return LOWORD(ret);
54 }
55
56 /* convert insert after window handle to 32-bit */
57 static inline HWND full_insert_after_hwnd( HWND16 hwnd )
58 {
59     HWND ret = WIN_Handle32( hwnd );
60     if (ret == (HWND)0xffff) ret = HWND_TOPMOST;
61     return ret;
62 }
63
64 /**************************************************************************
65  *              MessageBox   (USER.1)
66  */
67 INT16 WINAPI MessageBox16( HWND16 hwnd, LPCSTR text, LPCSTR title, UINT16 type )
68 {
69     return MessageBoxA( WIN_Handle32(hwnd), text, title, type );
70 }
71
72
73 /***********************************************************************
74  *              SetTimer (USER.10)
75  */
76 UINT16 WINAPI SetTimer16( HWND16 hwnd, UINT16 id, UINT16 timeout, TIMERPROC16 proc )
77 {
78     TIMERPROC proc32 = (TIMERPROC)WINPROC_AllocProc16( (WNDPROC16)proc );
79     return SetTimer( WIN_Handle32(hwnd), id, timeout, proc32 );
80 }
81
82
83 /***********************************************************************
84  *              SetSystemTimer (USER.11)
85  */
86 UINT16 WINAPI SetSystemTimer16( HWND16 hwnd, UINT16 id, UINT16 timeout, TIMERPROC16 proc )
87 {
88     TIMERPROC proc32 = (TIMERPROC)WINPROC_AllocProc16( (WNDPROC16)proc );
89     return SetSystemTimer( WIN_Handle32(hwnd), id, timeout, proc32 );
90 }
91
92
93 /**************************************************************************
94  *              KillTimer   (USER.12)
95  */
96 BOOL16 WINAPI KillTimer16( HWND16 hwnd, UINT16 id )
97 {
98     return KillTimer( WIN_Handle32(hwnd), id );
99 }
100
101
102 /**************************************************************************
103  *              SetCapture   (USER.18)
104  */
105 HWND16 WINAPI SetCapture16( HWND16 hwnd )
106 {
107     return HWND_16( SetCapture( WIN_Handle32(hwnd) ));
108 }
109
110
111 /**************************************************************************
112  *              ReleaseCapture   (USER.19)
113  */
114 BOOL16 WINAPI ReleaseCapture16(void)
115 {
116     return ReleaseCapture();
117 }
118
119
120 /**************************************************************************
121  *              SetFocus   (USER.22)
122  */
123 HWND16 WINAPI SetFocus16( HWND16 hwnd )
124 {
125     return HWND_16( SetFocus( WIN_Handle32(hwnd) ));
126 }
127
128
129 /**************************************************************************
130  *              GetFocus   (USER.23)
131  */
132 HWND16 WINAPI GetFocus16(void)
133 {
134     return HWND_16( GetFocus() );
135 }
136
137
138 /**************************************************************************
139  *              RemoveProp   (USER.24)
140  */
141 HANDLE16 WINAPI RemoveProp16( HWND16 hwnd, LPCSTR str )
142 {
143     return HANDLE_16(RemovePropA( WIN_Handle32(hwnd), str ));
144 }
145
146
147 /**************************************************************************
148  *              GetProp   (USER.25)
149  */
150 HANDLE16 WINAPI GetProp16( HWND16 hwnd, LPCSTR str )
151 {
152     return HANDLE_16(GetPropA( WIN_Handle32(hwnd), str ));
153 }
154
155
156 /**************************************************************************
157  *              SetProp   (USER.26)
158  */
159 BOOL16 WINAPI SetProp16( HWND16 hwnd, LPCSTR str, HANDLE16 handle )
160 {
161     return SetPropA( WIN_Handle32(hwnd), str, HANDLE_32(handle) );
162 }
163
164
165 /***********************************************************************
166  *              EnumProps   (USER.27)
167  */
168 INT16 WINAPI EnumProps16( HWND16 hwnd, PROPENUMPROC16 func )
169 {
170     int ret = -1, i, count, total = 32;
171     property_data_t *list;
172
173     while (total)
174     {
175         if (!(list = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*list) ))) break;
176         count = 0;
177         SERVER_START_REQ( get_window_properties )
178         {
179             req->window = wine_server_user_handle( HWND_32(hwnd) );
180             wine_server_set_reply( req, list, total * sizeof(*list) );
181             if (!wine_server_call( req )) count = reply->total;
182         }
183         SERVER_END_REQ;
184
185         if (count && count <= total)
186         {
187             char string[ATOM_BUFFER_SIZE];
188             SEGPTR segptr = MapLS( string );
189             WORD args[4];
190             DWORD result;
191
192             for (i = 0; i < count; i++)
193             {
194                 if (list[i].string)  /* it was a string originally */
195                 {
196                     if (!GlobalGetAtomNameA( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
197                     args[3] = hwnd;
198                     args[2] = SELECTOROF(segptr);
199                     args[1] = OFFSETOF(segptr);
200                     args[0] = LOWORD(list[i].data);
201                 }
202                 else
203                 {
204                     args[3] = hwnd;
205                     args[2] = 0;
206                     args[1] = list[i].atom;
207                     args[0] = LOWORD(list[i].data);
208                 }
209                 WOWCallback16Ex( (DWORD)func, WCB16_PASCAL, sizeof(args), args, &result );
210                 if (!(ret = LOWORD(result))) break;
211             }
212             UnMapLS( segptr );
213             HeapFree( GetProcessHeap(), 0, list );
214             break;
215         }
216         HeapFree( GetProcessHeap(), 0, list );
217         total = count;  /* restart with larger buffer */
218     }
219     return ret;
220 }
221
222
223 /**************************************************************************
224  *              ClientToScreen   (USER.28)
225  */
226 void WINAPI ClientToScreen16( HWND16 hwnd, LPPOINT16 lppnt )
227 {
228     MapWindowPoints16( hwnd, 0, lppnt, 1 );
229 }
230
231
232 /**************************************************************************
233  *              ScreenToClient   (USER.29)
234  */
235 void WINAPI ScreenToClient16( HWND16 hwnd, LPPOINT16 lppnt )
236 {
237     MapWindowPoints16( 0, hwnd, lppnt, 1 );
238 }
239
240
241 /**************************************************************************
242  *              WindowFromPoint   (USER.30)
243  */
244 HWND16 WINAPI WindowFromPoint16( POINT16 pt )
245 {
246     POINT pt32;
247
248     pt32.x = pt.x;
249     pt32.y = pt.y;
250     return HWND_16( WindowFromPoint( pt32 ) );
251 }
252
253
254 /**************************************************************************
255  *              IsIconic   (USER.31)
256  */
257 BOOL16 WINAPI IsIconic16(HWND16 hwnd)
258 {
259     return IsIconic( WIN_Handle32(hwnd) );
260 }
261
262
263 /**************************************************************************
264  *              GetWindowRect   (USER.32)
265  */
266 void WINAPI GetWindowRect16( HWND16 hwnd, LPRECT16 rect )
267 {
268     RECT rect32;
269
270     GetWindowRect( WIN_Handle32(hwnd), &rect32 );
271     rect->left   = rect32.left;
272     rect->top    = rect32.top;
273     rect->right  = rect32.right;
274     rect->bottom = rect32.bottom;
275 }
276
277
278 /**************************************************************************
279  *              GetClientRect   (USER.33)
280  */
281 void WINAPI GetClientRect16( HWND16 hwnd, LPRECT16 rect )
282 {
283     RECT rect32;
284
285     GetClientRect( WIN_Handle32(hwnd), &rect32 );
286     rect->left   = rect32.left;
287     rect->top    = rect32.top;
288     rect->right  = rect32.right;
289     rect->bottom = rect32.bottom;
290 }
291
292
293 /**************************************************************************
294  *              EnableWindow   (USER.34)
295  */
296 BOOL16 WINAPI EnableWindow16( HWND16 hwnd, BOOL16 enable )
297 {
298     return EnableWindow( WIN_Handle32(hwnd), enable );
299 }
300
301
302 /**************************************************************************
303  *              IsWindowEnabled   (USER.35)
304  */
305 BOOL16 WINAPI IsWindowEnabled16(HWND16 hwnd)
306 {
307     return IsWindowEnabled( WIN_Handle32(hwnd) );
308 }
309
310
311 /**************************************************************************
312  *              GetWindowText   (USER.36)
313  */
314 INT16 WINAPI GetWindowText16( HWND16 hwnd, SEGPTR lpString, INT16 nMaxCount )
315 {
316     return SendMessage16( hwnd, WM_GETTEXT, nMaxCount, lpString );
317 }
318
319
320 /**************************************************************************
321  *              SetWindowText   (USER.37)
322  */
323 BOOL16 WINAPI SetWindowText16( HWND16 hwnd, SEGPTR lpString )
324 {
325     return SendMessage16( hwnd, WM_SETTEXT, 0, (LPARAM)lpString );
326 }
327
328
329 /**************************************************************************
330  *              GetWindowTextLength   (USER.38)
331  */
332 INT16 WINAPI GetWindowTextLength16( HWND16 hwnd )
333 {
334     return SendMessage16( hwnd, WM_GETTEXTLENGTH, 0, 0 );
335 }
336
337
338 /***********************************************************************
339  *              BeginPaint (USER.39)
340  */
341 HDC16 WINAPI BeginPaint16( HWND16 hwnd, LPPAINTSTRUCT16 lps )
342 {
343     PAINTSTRUCT ps;
344
345     BeginPaint( WIN_Handle32(hwnd), &ps );
346     lps->hdc            = HDC_16(ps.hdc);
347     lps->fErase         = ps.fErase;
348     lps->rcPaint.top    = ps.rcPaint.top;
349     lps->rcPaint.left   = ps.rcPaint.left;
350     lps->rcPaint.right  = ps.rcPaint.right;
351     lps->rcPaint.bottom = ps.rcPaint.bottom;
352     lps->fRestore       = ps.fRestore;
353     lps->fIncUpdate     = ps.fIncUpdate;
354     return lps->hdc;
355 }
356
357
358 /***********************************************************************
359  *              EndPaint (USER.40)
360  */
361 BOOL16 WINAPI EndPaint16( HWND16 hwnd, const PAINTSTRUCT16* lps )
362 {
363     PAINTSTRUCT ps;
364
365     ps.hdc = HDC_32(lps->hdc);
366     return EndPaint( WIN_Handle32(hwnd), &ps );
367 }
368
369
370 /***********************************************************************
371  *              CreateWindow (USER.41)
372  */
373 HWND16 WINAPI CreateWindow16( LPCSTR className, LPCSTR windowName,
374                               DWORD style, INT16 x, INT16 y, INT16 width,
375                               INT16 height, HWND16 parent, HMENU16 menu,
376                               HINSTANCE16 instance, LPVOID data )
377 {
378     return CreateWindowEx16( 0, className, windowName, style,
379                              x, y, width, height, parent, menu, instance, data );
380 }
381
382
383 /**************************************************************************
384  *              ShowWindow   (USER.42)
385  */
386 BOOL16 WINAPI ShowWindow16( HWND16 hwnd, INT16 cmd )
387 {
388     return ShowWindow( WIN_Handle32(hwnd), cmd );
389 }
390
391
392 /**************************************************************************
393  *              CloseWindow   (USER.43)
394  */
395 BOOL16 WINAPI CloseWindow16( HWND16 hwnd )
396 {
397     return CloseWindow( WIN_Handle32(hwnd) );
398 }
399
400
401 /**************************************************************************
402  *              OpenIcon   (USER.44)
403  */
404 BOOL16 WINAPI OpenIcon16( HWND16 hwnd )
405 {
406     return OpenIcon( WIN_Handle32(hwnd) );
407 }
408
409
410 /**************************************************************************
411  *              BringWindowToTop   (USER.45)
412  */
413 BOOL16 WINAPI BringWindowToTop16( HWND16 hwnd )
414 {
415     return BringWindowToTop( WIN_Handle32(hwnd) );
416 }
417
418
419 /**************************************************************************
420  *              GetParent   (USER.46)
421  */
422 HWND16 WINAPI GetParent16( HWND16 hwnd )
423 {
424     return HWND_16( GetParent( WIN_Handle32(hwnd) ));
425 }
426
427
428 /**************************************************************************
429  *              IsWindow   (USER.47)
430  */
431 BOOL16 WINAPI IsWindow16( HWND16 hwnd )
432 {
433     STACK16FRAME *frame = MapSL( (SEGPTR)NtCurrentTeb()->WOW32Reserved );
434     frame->es = USER_HeapSel;
435     /* don't use WIN_Handle32 here, we don't care about the full handle */
436     return IsWindow( HWND_32(hwnd) );
437 }
438
439
440 /**************************************************************************
441  *              IsChild   (USER.48)
442  */
443 BOOL16 WINAPI IsChild16( HWND16 parent, HWND16 child )
444 {
445     return IsChild( WIN_Handle32(parent), WIN_Handle32(child) );
446 }
447
448
449 /**************************************************************************
450  *              IsWindowVisible   (USER.49)
451  */
452 BOOL16 WINAPI IsWindowVisible16( HWND16 hwnd )
453 {
454     return IsWindowVisible( WIN_Handle32(hwnd) );
455 }
456
457
458 /**************************************************************************
459  *              FindWindow   (USER.50)
460  */
461 HWND16 WINAPI FindWindow16( LPCSTR className, LPCSTR title )
462 {
463     return HWND_16( FindWindowA( className, title ));
464 }
465
466
467 /**************************************************************************
468  *              DestroyWindow   (USER.53)
469  */
470 BOOL16 WINAPI DestroyWindow16( HWND16 hwnd )
471 {
472     return DestroyWindow( WIN_Handle32(hwnd) );
473 }
474
475
476 /*******************************************************************
477  *           EnumWindows   (USER.54)
478  */
479 BOOL16 WINAPI EnumWindows16( WNDENUMPROC16 func, LPARAM lParam )
480 {
481     struct wnd_enum_info info;
482
483     info.proc  = func;
484     info.param = lParam;
485     return EnumWindows( wnd_enum_callback, (LPARAM)&info );
486 }
487
488
489 /**********************************************************************
490  *           EnumChildWindows   (USER.55)
491  */
492 BOOL16 WINAPI EnumChildWindows16( HWND16 parent, WNDENUMPROC16 func, LPARAM lParam )
493 {
494     struct wnd_enum_info info;
495
496     info.proc  = func;
497     info.param = lParam;
498     return EnumChildWindows( WIN_Handle32(parent), wnd_enum_callback, (LPARAM)&info );
499 }
500
501
502 /**************************************************************************
503  *              MoveWindow   (USER.56)
504  */
505 BOOL16 WINAPI MoveWindow16( HWND16 hwnd, INT16 x, INT16 y, INT16 cx, INT16 cy, BOOL16 repaint )
506 {
507     return MoveWindow( WIN_Handle32(hwnd), x, y, cx, cy, repaint );
508 }
509
510
511 /***********************************************************************
512  *              RegisterClass (USER.57)
513  */
514 ATOM WINAPI RegisterClass16( const WNDCLASS16 *wc )
515 {
516     WNDCLASSEX16 wcex;
517
518     wcex.cbSize        = sizeof(wcex);
519     wcex.style         = wc->style;
520     wcex.lpfnWndProc   = wc->lpfnWndProc;
521     wcex.cbClsExtra    = wc->cbClsExtra;
522     wcex.cbWndExtra    = wc->cbWndExtra;
523     wcex.hInstance     = wc->hInstance;
524     wcex.hIcon         = wc->hIcon;
525     wcex.hCursor       = wc->hCursor;
526     wcex.hbrBackground = wc->hbrBackground;
527     wcex.lpszMenuName  = wc->lpszMenuName;
528     wcex.lpszClassName = wc->lpszClassName;
529     wcex.hIconSm       = 0;
530     return RegisterClassEx16( &wcex );
531 }
532
533
534 /**************************************************************************
535  *              GetClassName   (USER.58)
536  */
537 INT16 WINAPI GetClassName16( HWND16 hwnd, LPSTR buffer, INT16 count )
538 {
539     return GetClassNameA( WIN_Handle32(hwnd), buffer, count );
540 }
541
542
543 /**************************************************************************
544  *              SetActiveWindow   (USER.59)
545  */
546 HWND16 WINAPI SetActiveWindow16( HWND16 hwnd )
547 {
548     return HWND_16( SetActiveWindow( WIN_Handle32(hwnd) ));
549 }
550
551
552 /**************************************************************************
553  *              GetActiveWindow   (USER.60)
554  */
555 HWND16 WINAPI GetActiveWindow16(void)
556 {
557     return HWND_16( GetActiveWindow() );
558 }
559
560
561 /**************************************************************************
562  *              ScrollWindow   (USER.61)
563  */
564 void WINAPI ScrollWindow16( HWND16 hwnd, INT16 dx, INT16 dy, const RECT16 *rect,
565                             const RECT16 *clipRect )
566 {
567     RECT rect32, clipRect32;
568
569     if (rect)
570     {
571         rect32.left   = rect->left;
572         rect32.top    = rect->top;
573         rect32.right  = rect->right;
574         rect32.bottom = rect->bottom;
575     }
576     if (clipRect)
577     {
578         clipRect32.left   = clipRect->left;
579         clipRect32.top    = clipRect->top;
580         clipRect32.right  = clipRect->right;
581         clipRect32.bottom = clipRect->bottom;
582     }
583     ScrollWindow( WIN_Handle32(hwnd), dx, dy, rect ? &rect32 : NULL,
584                   clipRect ? &clipRect32 : NULL );
585 }
586
587
588 /**************************************************************************
589  *              SetScrollPos   (USER.62)
590  */
591 INT16 WINAPI SetScrollPos16( HWND16 hwnd, INT16 nBar, INT16 nPos, BOOL16 redraw )
592 {
593     return SetScrollPos( WIN_Handle32(hwnd), nBar, nPos, redraw );
594 }
595
596
597 /**************************************************************************
598  *              GetScrollPos   (USER.63)
599  */
600 INT16 WINAPI GetScrollPos16( HWND16 hwnd, INT16 nBar )
601 {
602     return GetScrollPos( WIN_Handle32(hwnd), nBar );
603 }
604
605
606 /**************************************************************************
607  *              SetScrollRange   (USER.64)
608  */
609 void WINAPI SetScrollRange16( HWND16 hwnd, INT16 nBar, INT16 MinVal, INT16 MaxVal, BOOL16 redraw )
610 {
611     /* Invalid range -> range is set to (0,0) */
612     if ((INT)MaxVal - (INT)MinVal > 0x7fff) MinVal = MaxVal = 0;
613     SetScrollRange( WIN_Handle32(hwnd), nBar, MinVal, MaxVal, redraw );
614 }
615
616
617 /**************************************************************************
618  *              GetScrollRange   (USER.65)
619  */
620 BOOL16 WINAPI GetScrollRange16( HWND16 hwnd, INT16 nBar, LPINT16 lpMin, LPINT16 lpMax)
621 {
622     INT min, max;
623     BOOL ret = GetScrollRange( WIN_Handle32(hwnd), nBar, &min, &max );
624     if (lpMin) *lpMin = min;
625     if (lpMax) *lpMax = max;
626     return ret;
627 }
628
629
630 /**************************************************************************
631  *              GetDC   (USER.66)
632  */
633 HDC16 WINAPI GetDC16( HWND16 hwnd )
634 {
635     return HDC_16(GetDC( WIN_Handle32(hwnd) ));
636 }
637
638
639 /**************************************************************************
640  *              GetWindowDC   (USER.67)
641  */
642 HDC16 WINAPI GetWindowDC16( HWND16 hwnd )
643 {
644     return GetDCEx16( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
645 }
646
647
648 /**************************************************************************
649  *              ReleaseDC   (USER.68)
650  */
651 INT16 WINAPI ReleaseDC16( HWND16 hwnd, HDC16 hdc )
652 {
653     return (INT16)ReleaseDC( WIN_Handle32(hwnd), HDC_32(hdc) );
654 }
655
656
657 /**************************************************************************
658  *              FlashWindow   (USER.105)
659  */
660 BOOL16 WINAPI FlashWindow16( HWND16 hwnd, BOOL16 bInvert )
661 {
662     return FlashWindow( WIN_Handle32(hwnd), bInvert );
663 }
664
665
666 /**************************************************************************
667  *              WindowFromDC   (USER.117)
668  */
669 HWND16 WINAPI WindowFromDC16( HDC16 hDC )
670 {
671     return HWND_16( WindowFromDC( HDC_32(hDC) ) );
672 }
673
674
675 /**************************************************************************
676  *              UpdateWindow   (USER.124)
677  */
678 void WINAPI UpdateWindow16( HWND16 hwnd )
679 {
680     RedrawWindow16( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
681 }
682
683
684 /**************************************************************************
685  *              InvalidateRect   (USER.125)
686  */
687 void WINAPI InvalidateRect16( HWND16 hwnd, const RECT16 *rect, BOOL16 erase )
688 {
689     RedrawWindow16( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
690 }
691
692
693 /**************************************************************************
694  *              InvalidateRgn   (USER.126)
695  */
696 void WINAPI InvalidateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
697 {
698     RedrawWindow16( hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
699 }
700
701
702 /**************************************************************************
703  *              ValidateRect   (USER.127)
704  */
705 void WINAPI ValidateRect16( HWND16 hwnd, const RECT16 *rect )
706 {
707     RedrawWindow16( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
708 }
709
710
711 /**************************************************************************
712  *              ValidateRgn   (USER.128)
713  */
714 void WINAPI ValidateRgn16( HWND16 hwnd, HRGN16 hrgn )
715 {
716     RedrawWindow16( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN );
717 }
718
719
720 /**************************************************************************
721  *              GetClassWord   (USER.129)
722  */
723 WORD WINAPI GetClassWord16( HWND16 hwnd, INT16 offset )
724 {
725     return GetClassWord( WIN_Handle32(hwnd), offset );
726 }
727
728
729 /**************************************************************************
730  *              SetClassWord   (USER.130)
731  */
732 WORD WINAPI SetClassWord16( HWND16 hwnd, INT16 offset, WORD newval )
733 {
734     return SetClassWord( WIN_Handle32(hwnd), offset, newval );
735 }
736
737
738 /***********************************************************************
739  *              GetClassLong (USER.131)
740  */
741 LONG WINAPI GetClassLong16( HWND16 hwnd16, INT16 offset )
742 {
743     LONG_PTR ret = GetClassLongA( WIN_Handle32(hwnd16), offset );
744
745     switch( offset )
746     {
747     case GCLP_WNDPROC:
748         return (LONG_PTR)WINPROC_GetProc16( (WNDPROC)ret, FALSE );
749     case GCLP_MENUNAME:
750         return MapLS( (void *)ret );  /* leak */
751     default:
752         return ret;
753     }
754 }
755
756
757 /***********************************************************************
758  *              SetClassLong (USER.132)
759  */
760 LONG WINAPI SetClassLong16( HWND16 hwnd16, INT16 offset, LONG newval )
761 {
762     switch( offset )
763     {
764     case GCLP_WNDPROC:
765         {
766             WNDPROC new_proc = WINPROC_AllocProc16( (WNDPROC16)newval );
767             WNDPROC old_proc = (WNDPROC)SetClassLongA( WIN_Handle32(hwnd16), offset, (LONG_PTR)new_proc );
768             return (LONG)WINPROC_GetProc16( old_proc, FALSE );
769         }
770     case GCLP_MENUNAME:
771         newval = (LONG)MapSL( newval );
772         /* fall through */
773     default:
774         return SetClassLongA( WIN_Handle32(hwnd16), offset, newval );
775     }
776 }
777
778
779 /**************************************************************************
780  *              GetWindowWord   (USER.133)
781  */
782 WORD WINAPI GetWindowWord16( HWND16 hwnd, INT16 offset )
783 {
784     return GetWindowWord( WIN_Handle32(hwnd), offset );
785 }
786
787
788 /**************************************************************************
789  *              SetWindowWord   (USER.134)
790  */
791 WORD WINAPI SetWindowWord16( HWND16 hwnd, INT16 offset, WORD newval )
792 {
793     return SetWindowWord( WIN_Handle32(hwnd), offset, newval );
794 }
795
796
797 /**********************************************************************
798  *              GetWindowLong (USER.135)
799  */
800 LONG WINAPI GetWindowLong16( HWND16 hwnd, INT16 offset )
801 {
802     WND *wndPtr;
803     LONG_PTR retvalue;
804     BOOL is_winproc = (offset == GWLP_WNDPROC);
805
806     if (offset >= 0)
807     {
808         if (!(wndPtr = WIN_GetPtr( WIN_Handle32(hwnd) )))
809         {
810             SetLastError( ERROR_INVALID_WINDOW_HANDLE );
811             return 0;
812         }
813         if (wndPtr != WND_OTHER_PROCESS && wndPtr != WND_DESKTOP)
814         {
815             if (offset > (int)(wndPtr->cbWndExtra - sizeof(LONG)))
816             {
817                 /*
818                  * Some programs try to access last element from 16 bit
819                  * code using illegal offset value. Hopefully this is
820                  * what those programs really expect.
821                  */
822                 if (wndPtr->cbWndExtra >= 4 && offset == wndPtr->cbWndExtra - sizeof(WORD))
823                 {
824                     offset = wndPtr->cbWndExtra - sizeof(LONG);
825                 }
826                 else
827                 {
828                     WIN_ReleasePtr( wndPtr );
829                     SetLastError( ERROR_INVALID_INDEX );
830                     return 0;
831                 }
832             }
833             is_winproc = ((offset == DWLP_DLGPROC) && (wndPtr->flags & WIN_ISDIALOG));
834             WIN_ReleasePtr( wndPtr );
835         }
836     }
837     retvalue = GetWindowLongA( WIN_Handle32(hwnd), offset );
838     if (is_winproc) retvalue = (LONG_PTR)WINPROC_GetProc16( (WNDPROC)retvalue, FALSE );
839     return retvalue;
840 }
841
842
843 /**********************************************************************
844  *              SetWindowLong (USER.136)
845  */
846 LONG WINAPI SetWindowLong16( HWND16 hwnd, INT16 offset, LONG newval )
847 {
848     WND *wndPtr;
849     BOOL is_winproc = (offset == GWLP_WNDPROC);
850
851     if (offset == DWLP_DLGPROC)
852     {
853         if (!(wndPtr = WIN_GetPtr( WIN_Handle32(hwnd) )))
854         {
855             SetLastError( ERROR_INVALID_WINDOW_HANDLE );
856             return 0;
857         }
858         if (wndPtr != WND_OTHER_PROCESS && wndPtr != WND_DESKTOP)
859         {
860             is_winproc = ((wndPtr->cbWndExtra - sizeof(LONG_PTR) >= DWLP_DLGPROC) &&
861                           (wndPtr->flags & WIN_ISDIALOG));
862             WIN_ReleasePtr( wndPtr );
863         }
864     }
865
866     if (is_winproc)
867     {
868         WNDPROC new_proc = WINPROC_AllocProc16( (WNDPROC16)newval );
869         WNDPROC old_proc = (WNDPROC)SetWindowLongPtrA( WIN_Handle32(hwnd), offset, (LONG_PTR)new_proc );
870         return (LONG)WINPROC_GetProc16( old_proc, FALSE );
871     }
872     else return SetWindowLongA( WIN_Handle32(hwnd), offset, newval );
873 }
874
875
876 /**************************************************************************
877  *              OpenClipboard   (USER.137)
878  */
879 BOOL16 WINAPI OpenClipboard16( HWND16 hwnd )
880 {
881     return OpenClipboard( WIN_Handle32(hwnd) );
882 }
883
884
885 /**************************************************************************
886  *              GetClipboardOwner   (USER.140)
887  */
888 HWND16 WINAPI GetClipboardOwner16(void)
889 {
890     return HWND_16( GetClipboardOwner() );
891 }
892
893
894 /**************************************************************************
895  *              SetClipboardViewer   (USER.147)
896  */
897 HWND16 WINAPI SetClipboardViewer16( HWND16 hwnd )
898 {
899     return HWND_16( SetClipboardViewer( WIN_Handle32(hwnd) ));
900 }
901
902
903 /**************************************************************************
904  *              GetClipboardViewer   (USER.148)
905  */
906 HWND16 WINAPI GetClipboardViewer16(void)
907 {
908     return HWND_16( GetClipboardViewer() );
909 }
910
911
912 /**************************************************************************
913  *              ChangeClipboardChain   (USER.149)
914  */
915 BOOL16 WINAPI ChangeClipboardChain16(HWND16 hwnd, HWND16 hwndNext)
916 {
917     return ChangeClipboardChain( WIN_Handle32(hwnd), WIN_Handle32(hwndNext) );
918 }
919
920
921 /**************************************************************************
922  *              GetSystemMenu   (USER.156)
923  */
924 HMENU16 WINAPI GetSystemMenu16( HWND16 hwnd, BOOL16 revert )
925 {
926     return HMENU_16(GetSystemMenu( WIN_Handle32(hwnd), revert ));
927 }
928
929
930 /**************************************************************************
931  *              GetMenu   (USER.157)
932  */
933 HMENU16 WINAPI GetMenu16( HWND16 hwnd )
934 {
935     return HMENU_16(GetMenu( WIN_Handle32(hwnd) ));
936 }
937
938
939 /**************************************************************************
940  *              SetMenu   (USER.158)
941  */
942 BOOL16 WINAPI SetMenu16( HWND16 hwnd, HMENU16 hMenu )
943 {
944     return SetMenu( WIN_Handle32(hwnd), HMENU_32(hMenu) );
945 }
946
947
948 /**************************************************************************
949  *              DrawMenuBar   (USER.160)
950  */
951 void WINAPI DrawMenuBar16( HWND16 hwnd )
952 {
953     DrawMenuBar( WIN_Handle32(hwnd) );
954 }
955
956
957 /**************************************************************************
958  *              HiliteMenuItem   (USER.162)
959  */
960 BOOL16 WINAPI HiliteMenuItem16( HWND16 hwnd, HMENU16 hMenu, UINT16 id, UINT16 wHilite )
961 {
962     return HiliteMenuItem( WIN_Handle32(hwnd), HMENU_32(hMenu), id, wHilite );
963 }
964
965
966 /**************************************************************************
967  *              CreateCaret   (USER.163)
968  */
969 void WINAPI CreateCaret16( HWND16 hwnd, HBITMAP16 bitmap, INT16 width, INT16 height )
970 {
971     CreateCaret( WIN_Handle32(hwnd), HBITMAP_32(bitmap), width, height );
972 }
973
974
975 /*****************************************************************
976  *              DestroyCaret (USER.164)
977  */
978 void WINAPI DestroyCaret16(void)
979 {
980     DestroyCaret();
981 }
982
983
984 /*****************************************************************
985  *              SetCaretPos (USER.165)
986  */
987 void WINAPI SetCaretPos16( INT16 x, INT16 y )
988 {
989     SetCaretPos( x, y );
990 }
991
992
993 /**************************************************************************
994  *              HideCaret   (USER.166)
995  */
996 void WINAPI HideCaret16( HWND16 hwnd )
997 {
998     HideCaret( WIN_Handle32(hwnd) );
999 }
1000
1001
1002 /**************************************************************************
1003  *              ShowCaret   (USER.167)
1004  */
1005 void WINAPI ShowCaret16( HWND16 hwnd )
1006 {
1007     ShowCaret( WIN_Handle32(hwnd) );
1008 }
1009
1010
1011 /*****************************************************************
1012  *              SetCaretBlinkTime (USER.168)
1013  */
1014 void WINAPI SetCaretBlinkTime16( UINT16 msecs )
1015 {
1016     SetCaretBlinkTime( msecs );
1017 }
1018
1019
1020 /*****************************************************************
1021  *              GetCaretBlinkTime (USER.169)
1022  */
1023 UINT16 WINAPI GetCaretBlinkTime16(void)
1024 {
1025     return GetCaretBlinkTime();
1026 }
1027
1028
1029 /**************************************************************************
1030  *              ArrangeIconicWindows   (USER.170)
1031  */
1032 UINT16 WINAPI ArrangeIconicWindows16( HWND16 parent)
1033 {
1034     return ArrangeIconicWindows( WIN_Handle32(parent) );
1035 }
1036
1037
1038 /**************************************************************************
1039  *              SwitchToThisWindow   (USER.172)
1040  */
1041 void WINAPI SwitchToThisWindow16( HWND16 hwnd, BOOL16 restore )
1042 {
1043     SwitchToThisWindow( WIN_Handle32(hwnd), restore );
1044 }
1045
1046
1047 /**************************************************************************
1048  *              KillSystemTimer   (USER.182)
1049  */
1050 BOOL16 WINAPI KillSystemTimer16( HWND16 hwnd, UINT16 id )
1051 {
1052     return KillSystemTimer( WIN_Handle32(hwnd), id );
1053 }
1054
1055
1056 /*****************************************************************
1057  *              GetCaretPos (USER.183)
1058  */
1059 void WINAPI GetCaretPos16( LPPOINT16 pt16 )
1060 {
1061     POINT pt;
1062     if (GetCaretPos( &pt ))
1063     {
1064         pt16->x = pt.x;
1065         pt16->y = pt.y;
1066     }
1067 }
1068
1069
1070 /**************************************************************************
1071  *              SetSysModalWindow   (USER.188)
1072  */
1073 HWND16 WINAPI SetSysModalWindow16( HWND16 hwnd )
1074 {
1075     HWND16 old = hwndSysModal;
1076     hwndSysModal = hwnd;
1077     return old;
1078 }
1079
1080
1081 /**************************************************************************
1082  *              GetSysModalWindow   (USER.189)
1083  */
1084 HWND16 WINAPI GetSysModalWindow16(void)
1085 {
1086     return hwndSysModal;
1087 }
1088
1089
1090 /**************************************************************************
1091  *              GetUpdateRect   (USER.190)
1092  */
1093 BOOL16 WINAPI GetUpdateRect16( HWND16 hwnd, LPRECT16 rect, BOOL16 erase )
1094 {
1095     RECT r;
1096     BOOL16 ret;
1097
1098     if (!rect) return GetUpdateRect( WIN_Handle32(hwnd), NULL, erase );
1099     ret = GetUpdateRect( WIN_Handle32(hwnd), &r, erase );
1100     rect->left   = r.left;
1101     rect->top    = r.top;
1102     rect->right  = r.right;
1103     rect->bottom = r.bottom;
1104     return ret;
1105 }
1106
1107
1108 /**************************************************************************
1109  *              ChildWindowFromPoint   (USER.191)
1110  */
1111 HWND16 WINAPI ChildWindowFromPoint16( HWND16 hwndParent, POINT16 pt )
1112 {
1113     POINT pt32;
1114
1115     pt32.x = pt.x;
1116     pt32.y = pt.y;
1117     return HWND_16( ChildWindowFromPoint( WIN_Handle32(hwndParent), pt32 ));
1118 }
1119
1120
1121 /***********************************************************************
1122  *              CascadeChildWindows (USER.198)
1123  */
1124 void WINAPI CascadeChildWindows16( HWND16 parent, WORD action )
1125 {
1126     CascadeWindows( WIN_Handle32(parent), action, NULL, 0, NULL );
1127 }
1128
1129
1130 /***********************************************************************
1131  *              TileChildWindows (USER.199)
1132  */
1133 void WINAPI TileChildWindows16( HWND16 parent, WORD action )
1134 {
1135     TileWindows( WIN_Handle32(parent), action, NULL, 0, NULL );
1136 }
1137
1138
1139 /***********************************************************************
1140  *              GetWindowTask   (USER.224)
1141  */
1142 HTASK16 WINAPI GetWindowTask16( HWND16 hwnd )
1143 {
1144     DWORD tid = GetWindowThreadProcessId( HWND_32(hwnd), NULL );
1145     if (!tid) return 0;
1146     return HTASK_16(tid);
1147 }
1148
1149 /**********************************************************************
1150  *              EnumTaskWindows   (USER.225)
1151  */
1152 BOOL16 WINAPI EnumTaskWindows16( HTASK16 hTask, WNDENUMPROC16 func, LPARAM lParam )
1153 {
1154     struct wnd_enum_info info;
1155     DWORD tid = HTASK_32( hTask );
1156
1157     if (!tid) return FALSE;
1158     info.proc  = func;
1159     info.param = lParam;
1160     return EnumThreadWindows( tid, wnd_enum_callback, (LPARAM)&info );
1161 }
1162
1163
1164 /**************************************************************************
1165  *              GetTopWindow   (USER.229)
1166  */
1167 HWND16 WINAPI GetTopWindow16( HWND16 hwnd )
1168 {
1169     return HWND_16( GetTopWindow( WIN_Handle32(hwnd) ));
1170 }
1171
1172
1173 /**************************************************************************
1174  *              GetNextWindow   (USER.230)
1175  */
1176 HWND16 WINAPI GetNextWindow16( HWND16 hwnd, WORD flag )
1177 {
1178     if ((flag != GW_HWNDNEXT) && (flag != GW_HWNDPREV)) return 0;
1179     return GetWindow16( hwnd, flag );
1180 }
1181
1182
1183 /**************************************************************************
1184  *              SetWindowPos   (USER.232)
1185  */
1186 BOOL16 WINAPI SetWindowPos16( HWND16 hwnd, HWND16 hwndInsertAfter,
1187                               INT16 x, INT16 y, INT16 cx, INT16 cy, WORD flags)
1188 {
1189     return SetWindowPos( WIN_Handle32(hwnd), full_insert_after_hwnd(hwndInsertAfter),
1190                          x, y, cx, cy, flags );
1191 }
1192
1193
1194 /**************************************************************************
1195  *              SetParent   (USER.233)
1196  */
1197 HWND16 WINAPI SetParent16( HWND16 hwndChild, HWND16 hwndNewParent )
1198 {
1199     return HWND_16( SetParent( WIN_Handle32(hwndChild), WIN_Handle32(hwndNewParent) ));
1200 }
1201
1202
1203 /**************************************************************************
1204  *              GetCapture   (USER.236)
1205  */
1206 HWND16 WINAPI GetCapture16(void)
1207 {
1208     return HWND_16( GetCapture() );
1209 }
1210
1211
1212 /**************************************************************************
1213  *              GetUpdateRgn   (USER.237)
1214  */
1215 INT16 WINAPI GetUpdateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
1216 {
1217     return GetUpdateRgn( WIN_Handle32(hwnd), HRGN_32(hrgn), erase );
1218 }
1219
1220
1221 /**************************************************************************
1222  *              ExcludeUpdateRgn   (USER.238)
1223  */
1224 INT16 WINAPI ExcludeUpdateRgn16( HDC16 hdc, HWND16 hwnd )
1225 {
1226     return ExcludeUpdateRgn( HDC_32(hdc), WIN_Handle32(hwnd) );
1227 }
1228
1229
1230 /**************************************************************************
1231  *              GetOpenClipboardWindow   (USER.248)
1232  */
1233 HWND16 WINAPI GetOpenClipboardWindow16(void)
1234 {
1235     return HWND_16( GetOpenClipboardWindow() );
1236 }
1237
1238
1239 /**************************************************************************
1240  *              BeginDeferWindowPos   (USER.259)
1241  */
1242 HDWP16 WINAPI BeginDeferWindowPos16( INT16 count )
1243 {
1244     return HDWP_16(BeginDeferWindowPos( count ));
1245 }
1246
1247
1248 /**************************************************************************
1249  *              DeferWindowPos   (USER.260)
1250  */
1251 HDWP16 WINAPI DeferWindowPos16( HDWP16 hdwp, HWND16 hwnd, HWND16 hwndAfter,
1252                                 INT16 x, INT16 y, INT16 cx, INT16 cy,
1253                                 UINT16 flags )
1254 {
1255     return HDWP_16(DeferWindowPos( HDWP_32(hdwp), WIN_Handle32(hwnd),
1256                    full_insert_after_hwnd(hwndAfter), x, y, cx, cy, flags ));
1257 }
1258
1259
1260 /**************************************************************************
1261  *              EndDeferWindowPos   (USER.261)
1262  */
1263 BOOL16 WINAPI EndDeferWindowPos16( HDWP16 hdwp )
1264 {
1265     return EndDeferWindowPos(HDWP_32(hdwp));
1266 }
1267
1268
1269 /**************************************************************************
1270  *              GetWindow   (USER.262)
1271  */
1272 HWND16 WINAPI GetWindow16( HWND16 hwnd, WORD rel )
1273 {
1274     return HWND_16( GetWindow( WIN_Handle32(hwnd), rel ) );
1275 }
1276
1277
1278 /**************************************************************************
1279  *              ShowOwnedPopups   (USER.265)
1280  */
1281 void WINAPI ShowOwnedPopups16( HWND16 owner, BOOL16 fShow )
1282 {
1283     ShowOwnedPopups( WIN_Handle32(owner), fShow );
1284 }
1285
1286
1287 /**************************************************************************
1288  *              ShowScrollBar   (USER.267)
1289  */
1290 void WINAPI ShowScrollBar16( HWND16 hwnd, INT16 nBar, BOOL16 fShow )
1291 {
1292     ShowScrollBar( WIN_Handle32(hwnd), nBar, fShow );
1293 }
1294
1295
1296 /**************************************************************************
1297  *              IsZoomed   (USER.272)
1298  */
1299 BOOL16 WINAPI IsZoomed16(HWND16 hwnd)
1300 {
1301     return IsZoomed( WIN_Handle32(hwnd) );
1302 }
1303
1304
1305 /**************************************************************************
1306  *              GetDlgCtrlID   (USER.277)
1307  */
1308 INT16 WINAPI GetDlgCtrlID16( HWND16 hwnd )
1309 {
1310     return GetDlgCtrlID( WIN_Handle32(hwnd) );
1311 }
1312
1313
1314 /**************************************************************************
1315  *              GetDesktopHwnd   (USER.278)
1316  *
1317  * Exactly the same thing as GetDesktopWindow(), but not documented.
1318  * Don't ask me why...
1319  */
1320 HWND16 WINAPI GetDesktopHwnd16(void)
1321 {
1322     return GetDesktopWindow16();
1323 }
1324
1325
1326 /**************************************************************************
1327  *              SetSystemMenu   (USER.280)
1328  */
1329 BOOL16 WINAPI SetSystemMenu16( HWND16 hwnd, HMENU16 hMenu )
1330 {
1331     return SetSystemMenu( WIN_Handle32(hwnd), HMENU_32(hMenu) );
1332 }
1333
1334
1335 /**************************************************************************
1336  *              GetDesktopWindow   (USER.286)
1337  */
1338 HWND16 WINAPI GetDesktopWindow16(void)
1339 {
1340     return HWND_16( GetDesktopWindow() );
1341 }
1342
1343
1344 /**************************************************************************
1345  *              GetLastActivePopup   (USER.287)
1346  */
1347 HWND16 WINAPI GetLastActivePopup16( HWND16 hwnd )
1348 {
1349     return HWND_16( GetLastActivePopup( WIN_Handle32(hwnd) ));
1350 }
1351
1352
1353 /**************************************************************************
1354  *              RedrawWindow   (USER.290)
1355  */
1356 BOOL16 WINAPI RedrawWindow16( HWND16 hwnd, const RECT16 *rectUpdate,
1357                               HRGN16 hrgnUpdate, UINT16 flags )
1358 {
1359     if (rectUpdate)
1360     {
1361         RECT r;
1362         r.left   = rectUpdate->left;
1363         r.top    = rectUpdate->top;
1364         r.right  = rectUpdate->right;
1365         r.bottom = rectUpdate->bottom;
1366         return RedrawWindow(WIN_Handle32(hwnd), &r, HRGN_32(hrgnUpdate), flags);
1367     }
1368     return RedrawWindow(WIN_Handle32(hwnd), NULL, HRGN_32(hrgnUpdate), flags);
1369 }
1370
1371
1372 /**************************************************************************
1373  *              LockWindowUpdate   (USER.294)
1374  */
1375 BOOL16 WINAPI LockWindowUpdate16( HWND16 hwnd )
1376 {
1377     return LockWindowUpdate( WIN_Handle32(hwnd) );
1378 }
1379
1380
1381 /**************************************************************************
1382  *              ScrollWindowEx   (USER.319)
1383  */
1384 INT16 WINAPI ScrollWindowEx16( HWND16 hwnd, INT16 dx, INT16 dy,
1385                                const RECT16 *rect, const RECT16 *clipRect,
1386                                HRGN16 hrgnUpdate, LPRECT16 rcUpdate,
1387                                UINT16 flags )
1388 {
1389     RECT rect32, clipRect32, rcUpdate32;
1390     BOOL16 ret;
1391
1392     if (rect)
1393     {
1394         rect32.left   = rect->left;
1395         rect32.top    = rect->top;
1396         rect32.right  = rect->right;
1397         rect32.bottom = rect->bottom;
1398     }
1399     if (clipRect)
1400     {
1401         clipRect32.left   = clipRect->left;
1402         clipRect32.top    = clipRect->top;
1403         clipRect32.right  = clipRect->right;
1404         clipRect32.bottom = clipRect->bottom;
1405     }
1406     ret = ScrollWindowEx( WIN_Handle32(hwnd), dx, dy, rect ? &rect32 : NULL,
1407                           clipRect ? &clipRect32 : NULL, HRGN_32(hrgnUpdate),
1408                           (rcUpdate) ? &rcUpdate32 : NULL, flags );
1409     if (rcUpdate)
1410     {
1411         rcUpdate->left   = rcUpdate32.left;
1412         rcUpdate->top    = rcUpdate32.top;
1413         rcUpdate->right  = rcUpdate32.right;
1414         rcUpdate->bottom = rcUpdate32.bottom;
1415     }
1416     return ret;
1417 }
1418
1419
1420 /**************************************************************************
1421  *              FillWindow   (USER.324)
1422  */
1423 void WINAPI FillWindow16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc, HBRUSH16 hbrush )
1424 {
1425     RECT rect;
1426     RECT16 rc16;
1427     GetClientRect( WIN_Handle32(hwnd), &rect );
1428     DPtoLP( HDC_32(hdc), (LPPOINT)&rect, 2 );
1429     rc16.left   = rect.left;
1430     rc16.top    = rect.top;
1431     rc16.right  = rect.right;
1432     rc16.bottom = rect.bottom;
1433     PaintRect16( hwndParent, hwnd, hdc, hbrush, &rc16 );
1434 }
1435
1436
1437 /**************************************************************************
1438  *              PaintRect   (USER.325)
1439  */
1440 void WINAPI PaintRect16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc,
1441                          HBRUSH16 hbrush, const RECT16 *rect)
1442 {
1443     if (hbrush <= CTLCOLOR_STATIC)
1444     {
1445         HWND parent = WIN_Handle32(hwndParent), hwnd32 = WIN_Handle32(hwnd);
1446
1447         if (!parent) return;
1448         hbrush = SendMessageW( parent, WM_CTLCOLORMSGBOX + hbrush, (WPARAM)hdc, (LPARAM)hwnd32 );
1449         if (!hbrush) hbrush = DefWindowProcW( parent, WM_CTLCOLORMSGBOX + hbrush,
1450                                               (WPARAM)hdc, (LPARAM)hwnd32 );
1451     }
1452     if (hbrush) FillRect16( hdc, rect, hbrush );
1453 }
1454
1455
1456 /**************************************************************************
1457  *              GetControlBrush   (USER.326)
1458  */
1459 HBRUSH16 WINAPI GetControlBrush16( HWND16 hwnd, HDC16 hdc, UINT16 ctlType )
1460 {
1461     HBRUSH16 ret;
1462     HWND hwnd32 = WIN_Handle32(hwnd);
1463     HWND parent = GetParent( hwnd32 );
1464
1465     if (!parent) parent = hwnd32;
1466     ret = SendMessageW( parent, WM_CTLCOLORMSGBOX + ctlType, (WPARAM)hdc, (LPARAM)hwnd32 );
1467     if (!ret) ret = DefWindowProcW( parent, WM_CTLCOLORMSGBOX + ctlType,
1468                                     (WPARAM)hdc, (LPARAM)hwnd32 );
1469     return ret;
1470 }
1471
1472
1473 /**************************************************************************
1474  *              GetDCEx   (USER.359)
1475  */
1476 HDC16 WINAPI GetDCEx16( HWND16 hwnd, HRGN16 hrgnClip, DWORD flags )
1477 {
1478     return HDC_16(GetDCEx(WIN_Handle32(hwnd), HRGN_32(hrgnClip), flags));
1479 }
1480
1481
1482 /**************************************************************************
1483  *              GetWindowPlacement   (USER.370)
1484  */
1485 BOOL16 WINAPI GetWindowPlacement16( HWND16 hwnd, WINDOWPLACEMENT16 *wp16 )
1486 {
1487     WINDOWPLACEMENT wpl;
1488
1489     wpl.length = sizeof(wpl);
1490     if (!GetWindowPlacement( WIN_Handle32(hwnd), &wpl )) return FALSE;
1491     wp16->length  = sizeof(*wp16);
1492     wp16->flags   = wpl.flags;
1493     wp16->showCmd = wpl.showCmd;
1494     wp16->ptMinPosition.x = wpl.ptMinPosition.x;
1495     wp16->ptMinPosition.y = wpl.ptMinPosition.y;
1496     wp16->ptMaxPosition.x = wpl.ptMaxPosition.x;
1497     wp16->ptMaxPosition.y = wpl.ptMaxPosition.y;
1498     wp16->rcNormalPosition.left   = wpl.rcNormalPosition.left;
1499     wp16->rcNormalPosition.top    = wpl.rcNormalPosition.top;
1500     wp16->rcNormalPosition.right  = wpl.rcNormalPosition.right;
1501     wp16->rcNormalPosition.bottom = wpl.rcNormalPosition.bottom;
1502     return TRUE;
1503 }
1504
1505
1506 /**************************************************************************
1507  *              SetWindowPlacement   (USER.371)
1508  */
1509 BOOL16 WINAPI SetWindowPlacement16( HWND16 hwnd, const WINDOWPLACEMENT16 *wp16 )
1510 {
1511     WINDOWPLACEMENT wpl;
1512
1513     if (!wp16) return FALSE;
1514     wpl.length  = sizeof(wpl);
1515     wpl.flags   = wp16->flags;
1516     wpl.showCmd = wp16->showCmd;
1517     wpl.ptMinPosition.x = wp16->ptMinPosition.x;
1518     wpl.ptMinPosition.y = wp16->ptMinPosition.y;
1519     wpl.ptMaxPosition.x = wp16->ptMaxPosition.x;
1520     wpl.ptMaxPosition.y = wp16->ptMaxPosition.y;
1521     wpl.rcNormalPosition.left   = wp16->rcNormalPosition.left;
1522     wpl.rcNormalPosition.top    = wp16->rcNormalPosition.top;
1523     wpl.rcNormalPosition.right  = wp16->rcNormalPosition.right;
1524     wpl.rcNormalPosition.bottom = wp16->rcNormalPosition.bottom;
1525     return SetWindowPlacement( WIN_Handle32(hwnd), &wpl );
1526 }
1527
1528
1529 /***********************************************************************
1530  *              RegisterClassEx (USER.397)
1531  */
1532 ATOM WINAPI RegisterClassEx16( const WNDCLASSEX16 *wc )
1533 {
1534     WNDCLASSEXA wc32;
1535
1536     wc32.cbSize        = sizeof(wc32);
1537     wc32.style         = wc->style;
1538     wc32.lpfnWndProc   = WINPROC_AllocProc16( wc->lpfnWndProc );
1539     wc32.cbClsExtra    = wc->cbClsExtra;
1540     wc32.cbWndExtra    = wc->cbWndExtra;
1541     wc32.hInstance     = HINSTANCE_32(GetExePtr(wc->hInstance));
1542     if (!wc32.hInstance) wc32.hInstance = HINSTANCE_32(GetModuleHandle16(NULL));
1543     wc32.hIcon         = HICON_32(wc->hIcon);
1544     wc32.hCursor       = HCURSOR_32(wc->hCursor);
1545     wc32.hbrBackground = HBRUSH_32(wc->hbrBackground);
1546     wc32.lpszMenuName  = MapSL(wc->lpszMenuName);
1547     wc32.lpszClassName = MapSL(wc->lpszClassName);
1548     wc32.hIconSm       = HICON_32(wc->hIconSm);
1549     return RegisterClassExA( &wc32 );
1550 }
1551
1552
1553 /***********************************************************************
1554  *              GetClassInfoEx (USER.398)
1555  *
1556  * FIXME: this is just a guess, I have no idea if GetClassInfoEx() is the
1557  * same in Win16 as in Win32. --AJ
1558  */
1559 BOOL16 WINAPI GetClassInfoEx16( HINSTANCE16 hInst16, SEGPTR name, WNDCLASSEX16 *wc )
1560 {
1561     WNDCLASSEXA wc32;
1562     HINSTANCE hInstance;
1563     BOOL ret;
1564
1565     if (hInst16 == GetModuleHandle16("user")) hInstance = user32_module;
1566     else hInstance = HINSTANCE_32(GetExePtr( hInst16 ));
1567
1568     ret = GetClassInfoExA( hInstance, MapSL(name), &wc32 );
1569
1570     if (ret)
1571     {
1572         wc->lpfnWndProc   = WINPROC_GetProc16( wc32.lpfnWndProc, FALSE );
1573         wc->style         = wc32.style;
1574         wc->cbClsExtra    = wc32.cbClsExtra;
1575         wc->cbWndExtra    = wc32.cbWndExtra;
1576         wc->hInstance     = (wc32.hInstance == user32_module) ? GetModuleHandle16("user") : HINSTANCE_16(wc32.hInstance);
1577         wc->hIcon         = HICON_16(wc32.hIcon);
1578         wc->hIconSm       = HICON_16(wc32.hIconSm);
1579         wc->hCursor       = HCURSOR_16(wc32.hCursor);
1580         wc->hbrBackground = HBRUSH_16(wc32.hbrBackground);
1581         wc->lpszClassName = 0;
1582         wc->lpszMenuName  = MapLS(wc32.lpszMenuName);  /* FIXME: leak */
1583     }
1584     return ret;
1585 }
1586
1587
1588 /**************************************************************************
1589  *              ChildWindowFromPointEx   (USER.399)
1590  */
1591 HWND16 WINAPI ChildWindowFromPointEx16( HWND16 hwndParent, POINT16 pt, UINT16 uFlags)
1592 {
1593     POINT pt32;
1594
1595     pt32.x = pt.x;
1596     pt32.y = pt.y;
1597     return HWND_16( ChildWindowFromPointEx( WIN_Handle32(hwndParent), pt32, uFlags ));
1598 }
1599
1600
1601 /**************************************************************************
1602  *              GetPriorityClipboardFormat   (USER.402)
1603  */
1604 INT16 WINAPI GetPriorityClipboardFormat16( UINT16 *list, INT16 count )
1605 {
1606     int i;
1607
1608     for (i = 0; i < count; i++)
1609         if (IsClipboardFormatAvailable( list[i] )) return list[i];
1610     return -1;
1611 }
1612
1613
1614 /***********************************************************************
1615  *              UnregisterClass (USER.403)
1616  */
1617 BOOL16 WINAPI UnregisterClass16( LPCSTR className, HINSTANCE16 hInstance )
1618 {
1619     if (hInstance == GetModuleHandle16("user")) hInstance = 0;
1620     return UnregisterClassA( className, HINSTANCE_32(GetExePtr( hInstance )) );
1621 }
1622
1623
1624 /***********************************************************************
1625  *              GetClassInfo (USER.404)
1626  */
1627 BOOL16 WINAPI GetClassInfo16( HINSTANCE16 hInst16, SEGPTR name, WNDCLASS16 *wc )
1628 {
1629     WNDCLASSEX16 wcex;
1630     UINT16 ret = GetClassInfoEx16( hInst16, name, &wcex );
1631
1632     if (ret)
1633     {
1634         wc->style         = wcex.style;
1635         wc->lpfnWndProc   = wcex.lpfnWndProc;
1636         wc->cbClsExtra    = wcex.cbClsExtra;
1637         wc->cbWndExtra    = wcex.cbWndExtra;
1638         wc->hInstance     = wcex.hInstance;
1639         wc->hIcon         = wcex.hIcon;
1640         wc->hCursor       = wcex.hCursor;
1641         wc->hbrBackground = wcex.hbrBackground;
1642         wc->lpszMenuName  = wcex.lpszMenuName;
1643         wc->lpszClassName = wcex.lpszClassName;
1644     }
1645     return ret;
1646 }
1647
1648
1649 /**************************************************************************
1650  *              TrackPopupMenu   (USER.416)
1651  */
1652 BOOL16 WINAPI TrackPopupMenu16( HMENU16 hMenu, UINT16 wFlags, INT16 x, INT16 y,
1653                                 INT16 nReserved, HWND16 hwnd, const RECT16 *lpRect )
1654 {
1655     RECT r;
1656     if (lpRect)
1657     {
1658         r.left   = lpRect->left;
1659         r.top    = lpRect->top;
1660         r.right  = lpRect->right;
1661         r.bottom = lpRect->bottom;
1662     }
1663     return TrackPopupMenu( HMENU_32(hMenu), wFlags, x, y, nReserved,
1664                            WIN_Handle32(hwnd), lpRect ? &r : NULL );
1665 }
1666
1667
1668 /**************************************************************************
1669  *              FindWindowEx   (USER.427)
1670  */
1671 HWND16 WINAPI FindWindowEx16( HWND16 parent, HWND16 child, LPCSTR className, LPCSTR title )
1672 {
1673     return HWND_16( FindWindowExA( WIN_Handle32(parent), WIN_Handle32(child),
1674                                         className, title ));
1675 }
1676
1677
1678 /***********************************************************************
1679  *              DefFrameProc (USER.445)
1680  */
1681 LRESULT WINAPI DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient,
1682                                UINT16 message, WPARAM16 wParam, LPARAM lParam )
1683 {
1684     switch (message)
1685     {
1686     case WM_SETTEXT:
1687         lParam = (LPARAM)MapSL(lParam);
1688         /* fall through */
1689     case WM_COMMAND:
1690     case WM_NCACTIVATE:
1691     case WM_SETFOCUS:
1692     case WM_SIZE:
1693         return DefFrameProcA( WIN_Handle32(hwnd), WIN_Handle32(hwndMDIClient),
1694                               message, wParam, lParam );
1695
1696     case WM_NEXTMENU:
1697         {
1698             MDINEXTMENU next_menu;
1699             DefFrameProcW( WIN_Handle32(hwnd), WIN_Handle32(hwndMDIClient),
1700                            message, wParam, (LPARAM)&next_menu );
1701             return MAKELONG( HMENU_16(next_menu.hmenuNext), HWND_16(next_menu.hwndNext) );
1702         }
1703     default:
1704         return DefWindowProc16(hwnd, message, wParam, lParam);
1705     }
1706 }
1707
1708
1709 /***********************************************************************
1710  *              DefMDIChildProc (USER.447)
1711  */
1712 LRESULT WINAPI DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1713                                   WPARAM16 wParam, LPARAM lParam )
1714 {
1715     switch (message)
1716     {
1717     case WM_SETTEXT:
1718         return DefMDIChildProcA( WIN_Handle32(hwnd), message, wParam, (LPARAM)MapSL(lParam) );
1719
1720     case WM_MENUCHAR:
1721     case WM_CLOSE:
1722     case WM_SETFOCUS:
1723     case WM_CHILDACTIVATE:
1724     case WM_SYSCOMMAND:
1725     case WM_SETVISIBLE:
1726     case WM_SIZE:
1727     case WM_SYSCHAR:
1728         return DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, lParam );
1729
1730     case WM_GETMINMAXINFO:
1731         {
1732             MINMAXINFO16 *mmi16 = MapSL(lParam);
1733             MINMAXINFO mmi;
1734
1735             mmi.ptReserved.x     = mmi16->ptReserved.x;
1736             mmi.ptReserved.y     = mmi16->ptReserved.y;
1737             mmi.ptMaxSize.x      = mmi16->ptMaxSize.x;
1738             mmi.ptMaxSize.y      = mmi16->ptMaxSize.y;
1739             mmi.ptMaxPosition.x  = mmi16->ptMaxPosition.x;
1740             mmi.ptMaxPosition.y  = mmi16->ptMaxPosition.y;
1741             mmi.ptMinTrackSize.x = mmi16->ptMinTrackSize.x;
1742             mmi.ptMinTrackSize.y = mmi16->ptMinTrackSize.y;
1743             mmi.ptMaxTrackSize.x = mmi16->ptMaxTrackSize.x;
1744             mmi.ptMaxTrackSize.y = mmi16->ptMaxTrackSize.y;
1745
1746             DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&mmi );
1747
1748             mmi16->ptReserved.x     = mmi.ptReserved.x;
1749             mmi16->ptReserved.y     = mmi.ptReserved.y;
1750             mmi16->ptMaxSize.x      = mmi.ptMaxSize.x;
1751             mmi16->ptMaxSize.y      = mmi.ptMaxSize.y;
1752             mmi16->ptMaxPosition.x  = mmi.ptMaxPosition.x;
1753             mmi16->ptMaxPosition.y  = mmi.ptMaxPosition.y;
1754             mmi16->ptMinTrackSize.x = mmi.ptMinTrackSize.x;
1755             mmi16->ptMinTrackSize.y = mmi.ptMinTrackSize.y;
1756             mmi16->ptMaxTrackSize.x = mmi.ptMaxTrackSize.x;
1757             mmi16->ptMaxTrackSize.y = mmi.ptMaxTrackSize.y;
1758             return 0;
1759         }
1760     case WM_NEXTMENU:
1761         {
1762             MDINEXTMENU next_menu;
1763             DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&next_menu );
1764             return MAKELONG( HMENU_16(next_menu.hmenuNext), HWND_16(next_menu.hwndNext) );
1765         }
1766     default:
1767         return DefWindowProc16(hwnd, message, wParam, lParam);
1768     }
1769 }
1770
1771
1772 /**************************************************************************
1773  *              DrawAnimatedRects   (USER.448)
1774  */
1775 BOOL16 WINAPI DrawAnimatedRects16( HWND16 hwnd, INT16 idAni,
1776                                    const RECT16* lprcFrom, const RECT16* lprcTo )
1777 {
1778     RECT rcFrom32, rcTo32;
1779     rcFrom32.left   = lprcFrom->left;
1780     rcFrom32.top    = lprcFrom->top;
1781     rcFrom32.right  = lprcFrom->right;
1782     rcFrom32.bottom = lprcFrom->bottom;
1783     rcTo32.left     = lprcTo->left;
1784     rcTo32.top      = lprcTo->top;
1785     rcTo32.right    = lprcTo->right;
1786     rcTo32.bottom   = lprcTo->bottom;
1787     return DrawAnimatedRects( WIN_Handle32(hwnd), idAni, &rcFrom32, &rcTo32 );
1788 }
1789
1790
1791 /***********************************************************************
1792  *              GetInternalWindowPos (USER.460)
1793  */
1794 UINT16 WINAPI GetInternalWindowPos16( HWND16 hwnd, LPRECT16 rectWnd, LPPOINT16 ptIcon )
1795 {
1796     WINDOWPLACEMENT16 wndpl;
1797
1798     if (!GetWindowPlacement16( hwnd, &wndpl )) return 0;
1799     if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
1800     if (ptIcon)  *ptIcon = wndpl.ptMinPosition;
1801     return wndpl.showCmd;
1802 }
1803
1804
1805 /**************************************************************************
1806  *              SetInternalWindowPos   (USER.461)
1807  */
1808 void WINAPI SetInternalWindowPos16( HWND16 hwnd, UINT16 showCmd, LPRECT16 rect, LPPOINT16 pt )
1809 {
1810     RECT rc32;
1811     POINT pt32;
1812
1813     if (rect)
1814     {
1815         rc32.left   = rect->left;
1816         rc32.top    = rect->top;
1817         rc32.right  = rect->right;
1818         rc32.bottom = rect->bottom;
1819     }
1820     if (pt)
1821     {
1822         pt32.x = pt->x;
1823         pt32.y = pt->y;
1824     }
1825     SetInternalWindowPos( WIN_Handle32(hwnd), showCmd,
1826                           rect ? &rc32 : NULL, pt ? &pt32 : NULL );
1827 }
1828
1829
1830 /**************************************************************************
1831  *              CalcChildScroll   (USER.462)
1832  */
1833 void WINAPI CalcChildScroll16( HWND16 hwnd, WORD scroll )
1834 {
1835     CalcChildScroll( WIN_Handle32(hwnd), scroll );
1836 }
1837
1838
1839 /**************************************************************************
1840  *              ScrollChildren   (USER.463)
1841  */
1842 void WINAPI ScrollChildren16(HWND16 hwnd, UINT16 uMsg, WPARAM16 wParam, LPARAM lParam)
1843 {
1844     ScrollChildren( WIN_Handle32(hwnd), uMsg, wParam, lParam );
1845 }
1846
1847
1848 /**************************************************************************
1849  *              DragDetect   (USER.465)
1850  */
1851 BOOL16 WINAPI DragDetect16( HWND16 hwnd, POINT16 pt )
1852 {
1853     POINT pt32;
1854
1855     pt32.x = pt.x;
1856     pt32.y = pt.y;
1857     return DragDetect( WIN_Handle32(hwnd), pt32 );
1858 }
1859
1860
1861 /**************************************************************************
1862  *              SetScrollInfo   (USER.475)
1863  */
1864 INT16 WINAPI SetScrollInfo16( HWND16 hwnd, INT16 nBar, const SCROLLINFO *info, BOOL16 redraw )
1865 {
1866     return SetScrollInfo( WIN_Handle32(hwnd), nBar, info, redraw );
1867 }
1868
1869
1870 /**************************************************************************
1871  *              GetScrollInfo   (USER.476)
1872  */
1873 BOOL16 WINAPI GetScrollInfo16( HWND16 hwnd, INT16 nBar, LPSCROLLINFO info )
1874 {
1875     return GetScrollInfo( WIN_Handle32(hwnd), nBar, info );
1876 }
1877
1878
1879 /**************************************************************************
1880  *              EnableScrollBar   (USER.482)
1881  */
1882 BOOL16 WINAPI EnableScrollBar16( HWND16 hwnd, INT16 nBar, UINT16 flags )
1883 {
1884     return EnableScrollBar( WIN_Handle32(hwnd), nBar, flags );
1885 }
1886
1887
1888 /**************************************************************************
1889  *              GetShellWindow   (USER.600)
1890  */
1891 HWND16 WINAPI GetShellWindow16(void)
1892 {
1893     return HWND_16( GetShellWindow() );
1894 }
1895
1896
1897 /**************************************************************************
1898  *              GetForegroundWindow   (USER.608)
1899  */
1900 HWND16 WINAPI GetForegroundWindow16(void)
1901 {
1902     return HWND_16( GetForegroundWindow() );
1903 }
1904
1905
1906 /**************************************************************************
1907  *              SetForegroundWindow   (USER.609)
1908  */
1909 BOOL16 WINAPI SetForegroundWindow16( HWND16 hwnd )
1910 {
1911     return SetForegroundWindow( WIN_Handle32(hwnd) );
1912 }
1913
1914
1915 /**************************************************************************
1916  *              DrawCaptionTemp   (USER.657)
1917  */
1918 BOOL16 WINAPI DrawCaptionTemp16( HWND16 hwnd, HDC16 hdc, const RECT16 *rect,
1919                                  HFONT16 hFont, HICON16 hIcon, LPCSTR str, UINT16 uFlags )
1920 {
1921     RECT rect32;
1922
1923     if (rect)
1924     {
1925         rect32.left   = rect->left;
1926         rect32.top    = rect->top;
1927         rect32.right  = rect->right;
1928         rect32.bottom = rect->bottom;
1929     }
1930     return DrawCaptionTempA( WIN_Handle32(hwnd), HDC_32(hdc),
1931                              rect ? &rect32 : NULL, HFONT_32(hFont),
1932                              HICON_32(hIcon), str, uFlags & 0x1f );
1933 }
1934
1935
1936 /**************************************************************************
1937  *              DrawCaption   (USER.660)
1938  */
1939 BOOL16 WINAPI DrawCaption16( HWND16 hwnd, HDC16 hdc, const RECT16 *rect, UINT16 flags )
1940 {
1941     RECT rect32;
1942
1943     if (rect)
1944     {
1945         rect32.left   = rect->left;
1946         rect32.top    = rect->top;
1947         rect32.right  = rect->right;
1948         rect32.bottom = rect->bottom;
1949     }
1950     return DrawCaption(WIN_Handle32(hwnd), HDC_32(hdc), rect ? &rect32 : NULL, flags);
1951 }
1952
1953
1954 /**************************************************************************
1955  *              GetMenuItemRect   (USER.665)
1956  */
1957 BOOL16 WINAPI GetMenuItemRect16( HWND16 hwnd, HMENU16 hMenu, UINT16 uItem,
1958                                  LPRECT16 rect)
1959 {
1960      RECT r32;
1961      BOOL res;
1962      if (!rect) return FALSE;
1963      res = GetMenuItemRect( WIN_Handle32(hwnd), HMENU_32(hMenu), uItem, &r32 );
1964      rect->left   = r32.left;
1965      rect->top    = r32.top;
1966      rect->right  = r32.right;
1967      rect->bottom = r32.bottom;
1968      return res;
1969 }
1970
1971
1972 /**************************************************************************
1973  *              SetWindowRgn   (USER.668)
1974  */
1975 INT16 WINAPI SetWindowRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 redraw )
1976 {
1977     return SetWindowRgn( WIN_Handle32(hwnd), HRGN_32(hrgn), redraw );
1978 }
1979
1980
1981 /**************************************************************************
1982  *              MessageBoxIndirect   (USER.827)
1983  */
1984 INT16 WINAPI MessageBoxIndirect16( LPMSGBOXPARAMS16 msgbox )
1985 {
1986     MSGBOXPARAMSA msgbox32;
1987
1988     msgbox32.cbSize             = msgbox->cbSize;
1989     msgbox32.hwndOwner          = WIN_Handle32( msgbox->hwndOwner );
1990     msgbox32.hInstance          = HINSTANCE_32(msgbox->hInstance);
1991     msgbox32.lpszText           = MapSL(msgbox->lpszText);
1992     msgbox32.lpszCaption        = MapSL(msgbox->lpszCaption);
1993     msgbox32.dwStyle            = msgbox->dwStyle;
1994     msgbox32.lpszIcon           = MapSL(msgbox->lpszIcon);
1995     msgbox32.dwContextHelpId    = msgbox->dwContextHelpId;
1996     msgbox32.lpfnMsgBoxCallback = msgbox->lpfnMsgBoxCallback;
1997     msgbox32.dwLanguageId       = msgbox->dwLanguageId;
1998     return MessageBoxIndirectA( &msgbox32 );
1999 }