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