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