Removed implementation of LoadDIBIconHandler16 and
[wine] / dlls / user / user16.c
1 /*
2  * Misc 16-bit USER functions
3  *
4  * Copyright 1993, 1996 Alexandre Julliard
5  * Copyright 2002 Patrik Stridvall
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <stdarg.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26
27 #include "wine/winuser16.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wownt32.h"
31 #include "user_private.h"
32 #include "win.h"
33 #include "winproc.h"
34 #include "cursoricon.h"
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(user);
38
39 /* handle to handle 16 conversions */
40 #define HANDLE_16(h32)          (LOWORD(h32))
41
42 /* handle16 to handle conversions */
43 #define HANDLE_32(h16)          ((HANDLE)(ULONG_PTR)(h16))
44 #define HINSTANCE_32(h16)       ((HINSTANCE)(ULONG_PTR)(h16))
45
46 #define IS_MENU_STRING_ITEM(flags) \
47     (((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR)) == MF_STRING)
48
49 WORD WINAPI DestroyIcon32(HGLOBAL16, UINT16);
50
51
52 struct gray_string_info
53 {
54     GRAYSTRINGPROC16 proc;
55     LPARAM           param;
56     char             str[1];
57 };
58
59 /* callback for 16-bit gray string proc with opaque pointer */
60 static BOOL CALLBACK gray_string_callback( HDC hdc, LPARAM param, INT len )
61 {
62     const struct gray_string_info *info = (struct gray_string_info *)param;
63     WORD args[4];
64     DWORD ret;
65
66     args[3] = HDC_16(hdc);
67     args[2] = HIWORD(info->param);
68     args[1] = LOWORD(info->param);
69     args[0] = len;
70     WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
71     return LOWORD(ret);
72 }
73
74 /* callback for 16-bit gray string proc with string pointer */
75 static BOOL CALLBACK gray_string_callback_ptr( HDC hdc, LPARAM param, INT len )
76 {
77     const struct gray_string_info *info;
78     char *str = (char *)param;
79
80     info = (struct gray_string_info *)(str - offsetof( struct gray_string_info, str ));
81     return gray_string_callback( hdc, (LPARAM)info, len );
82 }
83
84 struct draw_state_info
85 {
86     DRAWSTATEPROC16 proc;
87     LPARAM          param;
88 };
89
90 /* callback for 16-bit DrawState functions */
91 static BOOL CALLBACK draw_state_callback( HDC hdc, LPARAM lparam, WPARAM wparam, int cx, int cy )
92 {
93     const struct draw_state_info *info = (struct draw_state_info *)lparam;
94     WORD args[6];
95     DWORD ret;
96
97     args[5] = HDC_16(hdc);
98     args[4] = HIWORD(info->param);
99     args[3] = LOWORD(info->param);
100     args[2] = wparam;
101     args[1] = cx;
102     args[0] = cy;
103     WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
104     return LOWORD(ret);
105 }
106
107
108 /**********************************************************************
109  *              InitApp (USER.5)
110  */
111 INT16 WINAPI InitApp16( HINSTANCE16 hInstance )
112 {
113     /* Create task message queue */
114     return (InitThreadInput16( 0, 0 ) != 0);
115 }
116
117
118 /***********************************************************************
119  *              ExitWindows (USER.7)
120  */
121 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
122 {
123     return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
124 }
125
126
127 /***********************************************************************
128  *              ClipCursor (USER.16)
129  */
130 BOOL16 WINAPI ClipCursor16( const RECT16 *rect )
131 {
132     RECT rect32;
133
134     if (!rect) return ClipCursor( NULL );
135     rect32.left   = rect->left;
136     rect32.top    = rect->top;
137     rect32.right  = rect->right;
138     rect32.bottom = rect->bottom;
139     return ClipCursor( &rect32 );
140 }
141
142
143 /***********************************************************************
144  *              GetCursorPos (USER.17)
145  */
146 BOOL16 WINAPI GetCursorPos16( POINT16 *pt )
147 {
148     POINT pos;
149     if (!pt) return 0;
150     GetCursorPos(&pos);
151     pt->x = pos.x;
152     pt->y = pos.y;
153     return 1;
154 }
155
156
157 /***********************************************************************
158  *              SetCursor (USER.69)
159  */
160 HCURSOR16 WINAPI SetCursor16(HCURSOR16 hCursor)
161 {
162   return HCURSOR_16(SetCursor(HCURSOR_32(hCursor)));
163 }
164
165
166 /***********************************************************************
167  *              SetCursorPos (USER.70)
168  */
169 void WINAPI SetCursorPos16( INT16 x, INT16 y )
170 {
171     SetCursorPos( x, y );
172 }
173
174
175 /***********************************************************************
176  *              ShowCursor (USER.71)
177  */
178 INT16 WINAPI ShowCursor16(BOOL16 bShow)
179 {
180   return ShowCursor(bShow);
181 }
182
183
184 /***********************************************************************
185  *              SetRect (USER.72)
186  */
187 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top, INT16 right, INT16 bottom )
188 {
189     rect->left   = left;
190     rect->right  = right;
191     rect->top    = top;
192     rect->bottom = bottom;
193 }
194
195
196 /***********************************************************************
197  *              SetRectEmpty (USER.73)
198  */
199 void WINAPI SetRectEmpty16( LPRECT16 rect )
200 {
201     rect->left = rect->right = rect->top = rect->bottom = 0;
202 }
203
204
205 /***********************************************************************
206  *              CopyRect (USER.74)
207  */
208 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
209 {
210     *dest = *src;
211     return TRUE;
212 }
213
214
215 /***********************************************************************
216  *              IsRectEmpty (USER.75)
217  *
218  * Bug compat: Windows checks for 0 or negative width/height.
219  */
220 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
221 {
222     return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
223 }
224
225
226 /***********************************************************************
227  *              PtInRect (USER.76)
228  */
229 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
230 {
231     return ((pt.x >= rect->left) && (pt.x < rect->right) &&
232             (pt.y >= rect->top) && (pt.y < rect->bottom));
233 }
234
235
236 /***********************************************************************
237  *              OffsetRect (USER.77)
238  */
239 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
240 {
241     rect->left   += x;
242     rect->right  += x;
243     rect->top    += y;
244     rect->bottom += y;
245 }
246
247
248 /***********************************************************************
249  *              InflateRect (USER.78)
250  */
251 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
252 {
253     rect->left   -= x;
254     rect->top    -= y;
255     rect->right  += x;
256     rect->bottom += y;
257 }
258
259
260 /***********************************************************************
261  *              IntersectRect (USER.79)
262  */
263 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
264                                const RECT16 *src2 )
265 {
266     if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
267         (src1->left >= src2->right) || (src2->left >= src1->right) ||
268         (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
269     {
270         SetRectEmpty16( dest );
271         return FALSE;
272     }
273     dest->left   = max( src1->left, src2->left );
274     dest->right  = min( src1->right, src2->right );
275     dest->top    = max( src1->top, src2->top );
276     dest->bottom = min( src1->bottom, src2->bottom );
277     return TRUE;
278 }
279
280
281 /***********************************************************************
282  *              UnionRect (USER.80)
283  */
284 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
285                            const RECT16 *src2 )
286 {
287     if (IsRectEmpty16(src1))
288     {
289         if (IsRectEmpty16(src2))
290         {
291             SetRectEmpty16( dest );
292             return FALSE;
293         }
294         else *dest = *src2;
295     }
296     else
297     {
298         if (IsRectEmpty16(src2)) *dest = *src1;
299         else
300         {
301             dest->left   = min( src1->left, src2->left );
302             dest->right  = max( src1->right, src2->right );
303             dest->top    = min( src1->top, src2->top );
304             dest->bottom = max( src1->bottom, src2->bottom );
305         }
306     }
307     return TRUE;
308 }
309
310
311 /***********************************************************************
312  *              FillRect (USER.81)
313  * NOTE
314  *   The Win16 variant doesn't support special color brushes like
315  *   the Win32 one, despite the fact that Win16, as well as Win32,
316  *   supports special background brushes for a window class.
317  */
318 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
319 {
320     HBRUSH prevBrush;
321
322     /* coordinates are logical so we cannot fast-check 'rect',
323      * it will be done later in the PatBlt().
324      */
325
326     if (!(prevBrush = SelectObject( HDC_32(hdc), HBRUSH_32(hbrush) ))) return 0;
327     PatBlt( HDC_32(hdc), rect->left, rect->top,
328               rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
329     SelectObject( HDC_32(hdc), prevBrush );
330     return 1;
331 }
332
333
334 /***********************************************************************
335  *              InvertRect (USER.82)
336  */
337 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
338 {
339     PatBlt( HDC_32(hdc), rect->left, rect->top,
340               rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
341 }
342
343
344 /***********************************************************************
345  *              FrameRect (USER.83)
346  */
347 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect16, HBRUSH16 hbrush )
348 {
349     RECT rect;
350
351     rect.left   = rect16->left;
352     rect.top    = rect16->top;
353     rect.right  = rect16->right;
354     rect.bottom = rect16->bottom;
355     return FrameRect( HDC_32(hdc), &rect, HBRUSH_32(hbrush) );
356 }
357
358
359 /***********************************************************************
360  *              DrawIcon (USER.84)
361  */
362 BOOL16 WINAPI DrawIcon16(HDC16 hdc, INT16 x, INT16 y, HICON16 hIcon)
363 {
364   return DrawIcon(HDC_32(hdc), x, y, HICON_32(hIcon));
365 }
366
367
368 /***********************************************************************
369  *           DrawText    (USER.85)
370  */
371 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 count, LPRECT16 rect, UINT16 flags )
372 {
373     INT16 ret;
374
375     if (rect)
376     {
377         RECT rect32;
378
379         rect32.left   = rect->left;
380         rect32.top    = rect->top;
381         rect32.right  = rect->right;
382         rect32.bottom = rect->bottom;
383         ret = DrawTextA( HDC_32(hdc), str, count, &rect32, flags );
384         rect->left   = rect32.left;
385         rect->top    = rect32.top;
386         rect->right  = rect32.right;
387         rect->bottom = rect32.bottom;
388     }
389     else ret = DrawTextA( HDC_32(hdc), str, count, NULL, flags);
390     return ret;
391 }
392
393
394 /***********************************************************************
395  *              IconSize (USER.86)
396  *
397  * See "Undocumented Windows". Used by W2.0 paint.exe.
398  */
399 DWORD WINAPI IconSize16(void)
400 {
401   return MAKELONG(GetSystemMetrics(SM_CYICON), GetSystemMetrics(SM_CXICON));
402 }
403
404
405 /***********************************************************************
406  *              AdjustWindowRect (USER.102)
407  */
408 BOOL16 WINAPI AdjustWindowRect16( LPRECT16 rect, DWORD style, BOOL16 menu )
409 {
410     return AdjustWindowRectEx16( rect, style, menu, 0 );
411 }
412
413
414 /**************************************************************************
415  *              CloseClipboard (USER.138)
416  */
417 BOOL16 WINAPI CloseClipboard16(void)
418 {
419     return CloseClipboard();
420 }
421
422
423 /**************************************************************************
424  *              EmptyClipboard (USER.139)
425  */
426 BOOL16 WINAPI EmptyClipboard16(void)
427 {
428     return EmptyClipboard();
429 }
430
431
432 /**************************************************************************
433  *              CountClipboardFormats (USER.143)
434  */
435 INT16 WINAPI CountClipboardFormats16(void)
436 {
437     return CountClipboardFormats();
438 }
439
440
441 /**************************************************************************
442  *              EnumClipboardFormats (USER.144)
443  */
444 UINT16 WINAPI EnumClipboardFormats16( UINT16 id )
445 {
446     return EnumClipboardFormats( id );
447 }
448
449
450 /**************************************************************************
451  *              RegisterClipboardFormat (USER.145)
452  */
453 UINT16 WINAPI RegisterClipboardFormat16( LPCSTR name )
454 {
455     return RegisterClipboardFormatA( name );
456 }
457
458
459 /**************************************************************************
460  *              GetClipboardFormatName (USER.146)
461  */
462 INT16 WINAPI GetClipboardFormatName16( UINT16 id, LPSTR buffer, INT16 maxlen )
463 {
464     return GetClipboardFormatNameA( id, buffer, maxlen );
465 }
466
467
468 /**********************************************************************
469  *         CreateMenu    (USER.151)
470  */
471 HMENU16 WINAPI CreateMenu16(void)
472 {
473     return HMENU_16( CreateMenu() );
474 }
475
476
477 /**********************************************************************
478  *         DestroyMenu    (USER.152)
479  */
480 BOOL16 WINAPI DestroyMenu16( HMENU16 hMenu )
481 {
482     return DestroyMenu( HMENU_32(hMenu) );
483 }
484
485
486 /*******************************************************************
487  *         ChangeMenu    (USER.153)
488  */
489 BOOL16 WINAPI ChangeMenu16( HMENU16 hMenu, UINT16 pos, SEGPTR data,
490                             UINT16 id, UINT16 flags )
491 {
492     if (flags & MF_APPEND) return AppendMenu16( hMenu, flags & ~MF_APPEND, id, data );
493
494     /* FIXME: Word passes the item id in 'pos' and 0 or 0xffff as id */
495     /* for MF_DELETE. We should check the parameters for all others */
496     /* MF_* actions also (anybody got a doc on ChangeMenu?). */
497
498     if (flags & MF_DELETE) return DeleteMenu16(hMenu, pos, flags & ~MF_DELETE);
499     if (flags & MF_CHANGE) return ModifyMenu16(hMenu, pos, flags & ~MF_CHANGE, id, data );
500     if (flags & MF_REMOVE) return RemoveMenu16(hMenu, flags & MF_BYPOSITION ? pos : id,
501                                                flags & ~MF_REMOVE );
502     /* Default: MF_INSERT */
503     return InsertMenu16( hMenu, pos, flags, id, data );
504 }
505
506
507 /*******************************************************************
508  *         CheckMenuItem    (USER.154)
509  */
510 BOOL16 WINAPI CheckMenuItem16( HMENU16 hMenu, UINT16 id, UINT16 flags )
511 {
512     return CheckMenuItem( HMENU_32(hMenu), id, flags );
513 }
514
515
516 /**********************************************************************
517  *         EnableMenuItem    (USER.155)
518  */
519 UINT16 WINAPI EnableMenuItem16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
520 {
521     return EnableMenuItem( HMENU_32(hMenu), wItemID, wFlags );
522 }
523
524
525 /**********************************************************************
526  *         GetSubMenu    (USER.159)
527  */
528 HMENU16 WINAPI GetSubMenu16( HMENU16 hMenu, INT16 nPos )
529 {
530     return HMENU_16( GetSubMenu( HMENU_32(hMenu), nPos ) );
531 }
532
533
534 /*******************************************************************
535  *         GetMenuString    (USER.161)
536  */
537 INT16 WINAPI GetMenuString16( HMENU16 hMenu, UINT16 wItemID,
538                               LPSTR str, INT16 nMaxSiz, UINT16 wFlags )
539 {
540     return GetMenuStringA( HMENU_32(hMenu), wItemID, str, nMaxSiz, wFlags );
541 }
542
543
544 /**********************************************************************
545  *              WinHelp (USER.171)
546  */
547 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
548                          DWORD dwData )
549 {
550     BOOL ret;
551     DWORD mutex_count;
552
553     /* We might call WinExec() */
554     ReleaseThunkLock(&mutex_count);
555
556     ret = WinHelpA(WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData));
557
558     RestoreThunkLock(mutex_count);
559     return ret;
560 }
561
562
563 /***********************************************************************
564  *              LoadCursor (USER.173)
565  */
566 HCURSOR16 WINAPI LoadCursor16(HINSTANCE16 hInstance, LPCSTR name)
567 {
568   return HCURSOR_16(LoadCursorA(HINSTANCE_32(hInstance), name));
569 }
570
571
572 /***********************************************************************
573  *              LoadIcon (USER.174)
574  */
575 HICON16 WINAPI LoadIcon16(HINSTANCE16 hInstance, LPCSTR name)
576 {
577   return HICON_16(LoadIconA(HINSTANCE_32(hInstance), name));
578 }
579
580 /**********************************************************************
581  *              LoadBitmap (USER.175)
582  */
583 HBITMAP16 WINAPI LoadBitmap16(HINSTANCE16 hInstance, LPCSTR name)
584 {
585   return HBITMAP_16(LoadBitmapA(HINSTANCE_32(hInstance), name));
586 }
587
588
589 /***********************************************************************
590  *              GetSystemMetrics (USER.179)
591  */
592 INT16 WINAPI GetSystemMetrics16( INT16 index )
593 {
594     return GetSystemMetrics( index );
595 }
596
597
598 /*************************************************************************
599  *              GetSysColor (USER.180)
600  */
601 COLORREF WINAPI GetSysColor16( INT16 index )
602 {
603     return GetSysColor( index );
604 }
605
606
607 /*************************************************************************
608  *              SetSysColors (USER.181)
609  */
610 VOID WINAPI SetSysColors16( INT16 count, const INT16 *list16, const COLORREF *values )
611 {
612     INT i, *list;
613
614     if ((list = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*list) )))
615     {
616         for (i = 0; i < count; i++) list[i] = list16[i];
617         SetSysColors( count, list, values );
618         HeapFree( GetProcessHeap(), 0, list );
619     }
620 }
621
622
623 /***********************************************************************
624  *           GrayString   (USER.185)
625  */
626 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
627                             LPARAM lParam, INT16 cch, INT16 x, INT16 y,
628                             INT16 cx, INT16 cy )
629 {
630     BOOL ret;
631
632     if (!gsprc) return GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), NULL,
633                                     (LPARAM)MapSL(lParam), cch, x, y, cx, cy );
634
635     if (cch == -1 || (cch && cx && cy))
636     {
637         /* lParam can be treated as an opaque pointer */
638         struct gray_string_info info;
639
640         info.proc  = gsprc;
641         info.param = lParam;
642         ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback,
643                            (LPARAM)&info, cch, x, y, cx, cy );
644     }
645     else  /* here we need some string conversions */
646     {
647         char *str16 = MapSL(lParam);
648         struct gray_string_info *info;
649
650         if (!cch) cch = strlen(str16);
651         if (!(info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) + cch ))) return FALSE;
652         info->proc  = gsprc;
653         info->param = lParam;
654         memcpy( info->str, str16, cch );
655         ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback_ptr,
656                            (LPARAM)info->str, cch, x, y, cx, cy );
657         HeapFree( GetProcessHeap(), 0, info );
658     }
659     return ret;
660 }
661
662
663 /**************************************************************************
664  *              IsClipboardFormatAvailable (USER.193)
665  */
666 BOOL16 WINAPI IsClipboardFormatAvailable16( UINT16 wFormat )
667 {
668     return IsClipboardFormatAvailable( wFormat );
669 }
670
671
672 /***********************************************************************
673  *           TabbedTextOut    (USER.196)
674  */
675 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
676                              INT16 count, INT16 nb_tabs, const INT16 *tabs16, INT16 tab_org )
677 {
678     LONG ret;
679     INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(tabs) );
680     if (!tabs) return 0;
681     for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
682     ret = TabbedTextOutA( HDC_32(hdc), x, y, lpstr, count, nb_tabs, tabs, tab_org );
683     HeapFree( GetProcessHeap(), 0, tabs );
684     return ret;
685 }
686
687
688 /***********************************************************************
689  *           GetTabbedTextExtent    (USER.197)
690  */
691 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
692                                     INT16 nb_tabs, const INT16 *tabs16 )
693 {
694     LONG ret;
695     INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(tabs) );
696     if (!tabs) return 0;
697     for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
698     ret = GetTabbedTextExtentA( HDC_32(hdc), lpstr, count, nb_tabs, tabs );
699     HeapFree( GetProcessHeap(), 0, tabs );
700     return ret;
701 }
702
703
704 /*************************************************************************
705  *              ScrollDC (USER.221)
706  */
707 BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
708                           const RECT16 *cliprc, HRGN16 hrgnUpdate,
709                           LPRECT16 rcUpdate )
710 {
711     RECT rect32, clipRect32, rcUpdate32;
712     BOOL16 ret;
713
714     if (rect)
715     {
716         rect32.left   = rect->left;
717         rect32.top    = rect->top;
718         rect32.right  = rect->right;
719         rect32.bottom = rect->bottom;
720     }
721     if (cliprc)
722     {
723         clipRect32.left   = cliprc->left;
724         clipRect32.top    = cliprc->top;
725         clipRect32.right  = cliprc->right;
726         clipRect32.bottom = cliprc->bottom;
727     }
728     ret = ScrollDC( HDC_32(hdc), dx, dy, rect ? &rect32 : NULL,
729                     cliprc ? &clipRect32 : NULL, HRGN_32(hrgnUpdate),
730                     &rcUpdate32 );
731     if (rcUpdate)
732     {
733         rcUpdate->left   = rcUpdate32.left;
734         rcUpdate->top    = rcUpdate32.top;
735         rcUpdate->right  = rcUpdate32.right;
736         rcUpdate->bottom = rcUpdate32.bottom;
737     }
738     return ret;
739 }
740
741
742 /***********************************************************************
743  *              GetSystemDebugState (USER.231)
744  */
745 WORD WINAPI GetSystemDebugState16(void)
746 {
747     return 0;  /* FIXME */
748 }
749
750
751 /***********************************************************************
752  *              EqualRect (USER.244)
753  */
754 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
755 {
756     return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
757             (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
758 }
759
760
761 /***********************************************************************
762  *              ExitWindowsExec (USER.246)
763  */
764 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
765 {
766     TRACE("Should run the following in DOS-mode: \"%s %s\"\n",
767           lpszExe, lpszParams);
768     return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
769 }
770
771
772 /***********************************************************************
773  *              GetCursor (USER.247)
774  */
775 HCURSOR16 WINAPI GetCursor16(void)
776 {
777   return HCURSOR_16(GetCursor());
778 }
779
780
781 /**********************************************************************
782  *              GetAsyncKeyState (USER.249)
783  */
784 INT16 WINAPI GetAsyncKeyState16( INT16 key )
785 {
786     return GetAsyncKeyState( key );
787 }
788
789
790 /**********************************************************************
791  *         GetMenuState    (USER.250)
792  */
793 UINT16 WINAPI GetMenuState16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
794 {
795     return GetMenuState( HMENU_32(hMenu), wItemID, wFlags );
796 }
797
798
799 /**********************************************************************
800  *         GetMenuItemCount    (USER.263)
801  */
802 INT16 WINAPI GetMenuItemCount16( HMENU16 hMenu )
803 {
804     return GetMenuItemCount( HMENU_32(hMenu) );
805 }
806
807
808 /**********************************************************************
809  *         GetMenuItemID    (USER.264)
810  */
811 UINT16 WINAPI GetMenuItemID16( HMENU16 hMenu, INT16 nPos )
812 {
813     return GetMenuItemID( HMENU_32(hMenu), nPos );
814 }
815
816
817 /***********************************************************************
818  *              GlobalAddAtom (USER.268)
819  */
820 ATOM WINAPI GlobalAddAtom16(LPCSTR lpString)
821 {
822   return GlobalAddAtomA(lpString);
823 }
824
825 /***********************************************************************
826  *              GlobalDeleteAtom (USER.269)
827  */
828 ATOM WINAPI GlobalDeleteAtom16(ATOM nAtom)
829 {
830   return GlobalDeleteAtom(nAtom);
831 }
832
833 /***********************************************************************
834  *              GlobalFindAtom (USER.270)
835  */
836 ATOM WINAPI GlobalFindAtom16(LPCSTR lpString)
837 {
838   return GlobalFindAtomA(lpString);
839 }
840
841 /***********************************************************************
842  *              GlobalGetAtomName (USER.271)
843  */
844 UINT16 WINAPI GlobalGetAtomName16(ATOM nAtom, LPSTR lpBuffer, INT16 nSize)
845 {
846   return GlobalGetAtomNameA(nAtom, lpBuffer, nSize);
847 }
848
849
850 /***********************************************************************
851  *              GetSysColorBrush (USER.281)
852  */
853 HBRUSH16 WINAPI GetSysColorBrush16( INT16 index )
854 {
855     return HBRUSH_16( GetSysColorBrush(index) );
856 }
857
858
859 /***********************************************************************
860  *              SelectPalette (USER.282)
861  */
862 HPALETTE16 WINAPI SelectPalette16( HDC16 hdc, HPALETTE16 hpal, BOOL16 bForceBackground )
863 {
864     return HPALETTE_16( SelectPalette( HDC_32(hdc), HPALETTE_32(hpal), bForceBackground ));
865 }
866
867 /***********************************************************************
868  *              RealizePalette (USER.283)
869  */
870 UINT16 WINAPI RealizePalette16( HDC16 hdc )
871 {
872     return UserRealizePalette( HDC_32(hdc) );
873 }
874
875
876 /***********************************************************************
877  *              GetClipCursor (USER.309)
878  */
879 void WINAPI GetClipCursor16( RECT16 *rect )
880 {
881     if (rect)
882     {
883         RECT rect32;
884         GetClipCursor( &rect32 );
885         rect->left   = rect32.left;
886         rect->top    = rect32.top;
887         rect->right  = rect32.right;
888         rect->bottom = rect32.bottom;
889     }
890 }
891
892
893 /***********************************************************************
894  *              SignalProc (USER.314)
895  */
896 void WINAPI SignalProc16( HANDLE16 hModule, UINT16 code,
897                           UINT16 uExitFn, HINSTANCE16 hInstance, HQUEUE16 hQueue )
898 {
899     if (code == USIG16_DLL_UNLOAD)
900     {
901         /* HOOK_FreeModuleHooks( hModule ); */
902         CLASS_FreeModuleClasses( hModule );
903         CURSORICON_FreeModuleIcons( hModule );
904     }
905 }
906
907
908 /***********************************************************************
909  *              SetEventHook (USER.321)
910  *
911  *      Used by Turbo Debugger for Windows
912  */
913 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
914 {
915     FIXME("(lpfnEventHook=%p): stub\n", lpfnEventHook);
916     return 0;
917 }
918
919
920 /**********************************************************************
921  *              EnableHardwareInput (USER.331)
922  */
923 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
924 {
925     FIXME("(%d) - stub\n", bEnable);
926     return TRUE;
927 }
928
929
930 /***********************************************************************
931  *              IsUserIdle (USER.333)
932  */
933 BOOL16 WINAPI IsUserIdle16(void)
934 {
935     if ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
936         return FALSE;
937     if ( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 )
938         return FALSE;
939     if ( GetAsyncKeyState( VK_MBUTTON ) & 0x8000 )
940         return FALSE;
941     /* Should check for screen saver activation here ... */
942     return TRUE;
943 }
944
945
946 /**********************************************************************
947  *              LoadDIBIconHandler (USER.357)
948  *
949  * RT_ICON resource loader, installed by USER_SignalProc when module
950  * is initialized.
951  */
952 HGLOBAL16 WINAPI LoadDIBIconHandler16( HGLOBAL16 hMemObj, HMODULE16 hModule, HRSRC16 hRsrc )
953 {
954     /* If hResource is zero we must allocate a new memory block, if it's
955      * non-zero but GlobalLock() returns NULL then it was discarded and
956      * we have to recommit some memory, otherwise we just need to check
957      * the block size. See LoadProc() in 16-bit SDK for more.
958      */
959     FIXME( "%x %x %x: stub, not supported anymore\n", hMemObj, hModule, hRsrc );
960     return 0;
961 }
962
963 /**********************************************************************
964  *              LoadDIBCursorHandler (USER.356)
965  *
966  * RT_CURSOR resource loader. Same as above.
967  */
968 HGLOBAL16 WINAPI LoadDIBCursorHandler16( HGLOBAL16 hMemObj, HMODULE16 hModule, HRSRC16 hRsrc )
969 {
970     FIXME( "%x %x %x: stub, not supported anymore\n", hMemObj, hModule, hRsrc );
971     return 0;
972 }
973
974
975 /**********************************************************************
976  *              IsMenu    (USER.358)
977  */
978 BOOL16 WINAPI IsMenu16( HMENU16 hmenu )
979 {
980     return IsMenu( HMENU_32(hmenu) );
981 }
982
983
984 /***********************************************************************
985  *              DCHook (USER.362)
986  */
987 BOOL16 WINAPI DCHook16( HDC16 hdc, WORD code, DWORD data, LPARAM lParam )
988 {
989     FIXME( "hDC = %x, %i: stub\n", hdc, code );
990     return FALSE;
991 }
992
993
994 /***********************************************************************
995  *              SubtractRect (USER.373)
996  */
997 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
998                               const RECT16 *src2 )
999 {
1000     RECT16 tmp;
1001
1002     if (IsRectEmpty16( src1 ))
1003     {
1004         SetRectEmpty16( dest );
1005         return FALSE;
1006     }
1007     *dest = *src1;
1008     if (IntersectRect16( &tmp, src1, src2 ))
1009     {
1010         if (EqualRect16( &tmp, dest ))
1011         {
1012             SetRectEmpty16( dest );
1013             return FALSE;
1014         }
1015         if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
1016         {
1017             if (tmp.left == dest->left) dest->left = tmp.right;
1018             else if (tmp.right == dest->right) dest->right = tmp.left;
1019         }
1020         else if ((tmp.left == dest->left) && (tmp.right == dest->right))
1021         {
1022             if (tmp.top == dest->top) dest->top = tmp.bottom;
1023             else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
1024         }
1025     }
1026     return TRUE;
1027 }
1028
1029
1030 /**********************************************************************
1031  *         SetMenuContextHelpId    (USER.384)
1032  */
1033 BOOL16 WINAPI SetMenuContextHelpId16( HMENU16 hMenu, DWORD dwContextHelpID)
1034 {
1035     return SetMenuContextHelpId( HMENU_32(hMenu), dwContextHelpID );
1036 }
1037
1038
1039 /**********************************************************************
1040  *         GetMenuContextHelpId    (USER.385)
1041  */
1042 DWORD WINAPI GetMenuContextHelpId16( HMENU16 hMenu )
1043 {
1044     return GetMenuContextHelpId( HMENU_32(hMenu) );
1045 }
1046
1047
1048 /***********************************************************************
1049  *              LoadImage (USER.389)
1050  *
1051  */
1052 HANDLE16 WINAPI LoadImage16(HINSTANCE16 hinst, LPCSTR name, UINT16 type,
1053                             INT16 desiredx, INT16 desiredy, UINT16 loadflags)
1054 {
1055   return HANDLE_16(LoadImageA(HINSTANCE_32(hinst), name, type, desiredx,
1056                               desiredy, loadflags));
1057 }
1058
1059 /******************************************************************************
1060  *              CopyImage (USER.390) Creates new image and copies attributes to it
1061  *
1062  */
1063 HICON16 WINAPI CopyImage16(HANDLE16 hnd, UINT16 type, INT16 desiredx,
1064                            INT16 desiredy, UINT16 flags)
1065 {
1066   return HICON_16(CopyImage(HANDLE_32(hnd), (UINT)type, (INT)desiredx,
1067                             (INT)desiredy, (UINT)flags));
1068 }
1069
1070 /**********************************************************************
1071  *              DrawIconEx (USER.394)
1072  */
1073 BOOL16 WINAPI DrawIconEx16(HDC16 hdc, INT16 xLeft, INT16 yTop, HICON16 hIcon,
1074                            INT16 cxWidth, INT16 cyWidth, UINT16 istep,
1075                            HBRUSH16 hbr, UINT16 flags)
1076 {
1077   return DrawIconEx(HDC_32(hdc), xLeft, yTop, HICON_32(hIcon), cxWidth, cyWidth,
1078                     istep, HBRUSH_32(hbr), flags);
1079 }
1080
1081 /**********************************************************************
1082  *              GetIconInfo (USER.395)
1083  */
1084 BOOL16 WINAPI GetIconInfo16(HICON16 hIcon, LPICONINFO16 iconinfo)
1085 {
1086   ICONINFO ii32;
1087   BOOL16 ret = GetIconInfo(HICON_32(hIcon), &ii32);
1088
1089   iconinfo->fIcon = ii32.fIcon;
1090   iconinfo->xHotspot = ii32.xHotspot;
1091   iconinfo->yHotspot = ii32.yHotspot;
1092   iconinfo->hbmMask  = HBITMAP_16(ii32.hbmMask);
1093   iconinfo->hbmColor = HBITMAP_16(ii32.hbmColor);
1094   return ret;
1095 }
1096
1097
1098 /***********************************************************************
1099  *              FinalUserInit (USER.400)
1100  */
1101 void WINAPI FinalUserInit16( void )
1102 {
1103     /* FIXME: Should chain to FinalGdiInit */
1104 }
1105
1106
1107 /***********************************************************************
1108  *              CreateCursor (USER.406)
1109  */
1110 HCURSOR16 WINAPI CreateCursor16(HINSTANCE16 hInstance,
1111                                 INT16 xHotSpot, INT16 yHotSpot,
1112                                 INT16 nWidth, INT16 nHeight,
1113                                 LPCVOID lpANDbits, LPCVOID lpXORbits)
1114 {
1115   CURSORICONINFO info;
1116
1117   info.ptHotSpot.x = xHotSpot;
1118   info.ptHotSpot.y = yHotSpot;
1119   info.nWidth = nWidth;
1120   info.nHeight = nHeight;
1121   info.nWidthBytes = 0;
1122   info.bPlanes = 1;
1123   info.bBitsPerPixel = 1;
1124
1125   return CreateCursorIconIndirect16(hInstance, &info, lpANDbits, lpXORbits);
1126 }
1127
1128
1129 /***********************************************************************
1130  *              InitThreadInput   (USER.409)
1131  */
1132 HQUEUE16 WINAPI InitThreadInput16( WORD unknown, WORD flags )
1133 {
1134     /* nothing to do here */
1135     return 0xbeef;
1136 }
1137
1138
1139 /*******************************************************************
1140  *         InsertMenu    (USER.410)
1141  */
1142 BOOL16 WINAPI InsertMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
1143                             UINT16 id, SEGPTR data )
1144 {
1145     UINT pos32 = (UINT)pos;
1146     if ((pos == (UINT16)-1) && (flags & MF_BYPOSITION)) pos32 = (UINT)-1;
1147     if (IS_MENU_STRING_ITEM(flags) && data)
1148         return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, MapSL(data) );
1149     return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, (LPSTR)data );
1150 }
1151
1152
1153 /*******************************************************************
1154  *         AppendMenu    (USER.411)
1155  */
1156 BOOL16 WINAPI AppendMenu16(HMENU16 hMenu, UINT16 flags, UINT16 id, SEGPTR data)
1157 {
1158     return InsertMenu16( hMenu, -1, flags | MF_BYPOSITION, id, data );
1159 }
1160
1161
1162 /**********************************************************************
1163  *         RemoveMenu   (USER.412)
1164  */
1165 BOOL16 WINAPI RemoveMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
1166 {
1167     return RemoveMenu( HMENU_32(hMenu), nPos, wFlags );
1168 }
1169
1170
1171 /**********************************************************************
1172  *         DeleteMenu    (USER.413)
1173  */
1174 BOOL16 WINAPI DeleteMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
1175 {
1176     return DeleteMenu( HMENU_32(hMenu), nPos, wFlags );
1177 }
1178
1179
1180 /*******************************************************************
1181  *         ModifyMenu    (USER.414)
1182  */
1183 BOOL16 WINAPI ModifyMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
1184                             UINT16 id, SEGPTR data )
1185 {
1186     if (IS_MENU_STRING_ITEM(flags))
1187         return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, MapSL(data) );
1188     return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, (LPSTR)data );
1189 }
1190
1191
1192 /**********************************************************************
1193  *         CreatePopupMenu    (USER.415)
1194  */
1195 HMENU16 WINAPI CreatePopupMenu16(void)
1196 {
1197     return HMENU_16( CreatePopupMenu() );
1198 }
1199
1200
1201 /**********************************************************************
1202  *         SetMenuItemBitmaps    (USER.418)
1203  */
1204 BOOL16 WINAPI SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags,
1205                                     HBITMAP16 hNewUnCheck, HBITMAP16 hNewCheck)
1206 {
1207     return SetMenuItemBitmaps( HMENU_32(hMenu), nPos, wFlags,
1208                                HBITMAP_32(hNewUnCheck), HBITMAP_32(hNewCheck) );
1209 }
1210
1211
1212 /***********************************************************************
1213  *           lstrcmp   (USER.430)
1214  */
1215 INT16 WINAPI lstrcmp16( LPCSTR str1, LPCSTR str2 )
1216 {
1217     return strcmp( str1, str2 );
1218 }
1219
1220
1221 /***********************************************************************
1222  *           AnsiUpper   (USER.431)
1223  */
1224 SEGPTR WINAPI AnsiUpper16( SEGPTR strOrChar )
1225 {
1226     /* uppercase only one char if strOrChar < 0x10000 */
1227     if (HIWORD(strOrChar))
1228     {
1229         CharUpperA( MapSL(strOrChar) );
1230         return strOrChar;
1231     }
1232     else return (SEGPTR)CharUpperA( (LPSTR)strOrChar );
1233 }
1234
1235
1236 /***********************************************************************
1237  *           AnsiLower   (USER.432)
1238  */
1239 SEGPTR WINAPI AnsiLower16( SEGPTR strOrChar )
1240 {
1241     /* lowercase only one char if strOrChar < 0x10000 */
1242     if (HIWORD(strOrChar))
1243     {
1244         CharLowerA( MapSL(strOrChar) );
1245         return strOrChar;
1246     }
1247     else return (SEGPTR)CharLowerA( (LPSTR)strOrChar );
1248 }
1249
1250
1251 /***********************************************************************
1252  *           AnsiUpperBuff   (USER.437)
1253  */
1254 UINT16 WINAPI AnsiUpperBuff16( LPSTR str, UINT16 len )
1255 {
1256     CharUpperBuffA( str, len ? len : 65536 );
1257     return len;
1258 }
1259
1260
1261 /***********************************************************************
1262  *           AnsiLowerBuff   (USER.438)
1263  */
1264 UINT16 WINAPI AnsiLowerBuff16( LPSTR str, UINT16 len )
1265 {
1266     CharLowerBuffA( str, len ? len : 65536 );
1267     return len;
1268 }
1269
1270
1271 /*******************************************************************
1272  *              InsertMenuItem   (USER.441)
1273  *
1274  * FIXME: untested
1275  */
1276 BOOL16 WINAPI InsertMenuItem16( HMENU16 hmenu, UINT16 pos, BOOL16 byposition,
1277                                 const MENUITEMINFO16 *mii )
1278 {
1279     MENUITEMINFOA miia;
1280
1281     miia.cbSize        = sizeof(miia);
1282     miia.fMask         = mii->fMask;
1283     miia.dwTypeData    = (LPSTR)mii->dwTypeData;
1284     miia.fType         = mii->fType;
1285     miia.fState        = mii->fState;
1286     miia.wID           = mii->wID;
1287     miia.hSubMenu      = HMENU_32(mii->hSubMenu);
1288     miia.hbmpChecked   = HBITMAP_32(mii->hbmpChecked);
1289     miia.hbmpUnchecked = HBITMAP_32(mii->hbmpUnchecked);
1290     miia.dwItemData    = mii->dwItemData;
1291     miia.cch           = mii->cch;
1292     if (IS_MENU_STRING_ITEM(miia.fType))
1293         miia.dwTypeData = MapSL(mii->dwTypeData);
1294     return InsertMenuItemA( HMENU_32(hmenu), pos, byposition, &miia );
1295 }
1296
1297
1298 /**********************************************************************
1299  *           DrawState    (USER.449)
1300  */
1301 BOOL16 WINAPI DrawState16( HDC16 hdc, HBRUSH16 hbr, DRAWSTATEPROC16 func, LPARAM ldata,
1302                            WPARAM16 wdata, INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags )
1303 {
1304     struct draw_state_info info;
1305     UINT opcode = flags & 0xf;
1306
1307     if (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)
1308     {
1309         /* make sure DrawStateA doesn't try to use ldata as a pointer */
1310         if (!wdata) wdata = strlen( MapSL(ldata) );
1311         if (!cx || !cy)
1312         {
1313             SIZE s;
1314             if (!GetTextExtentPoint32A( HDC_32(hdc), MapSL(ldata), wdata, &s )) return FALSE;
1315             if (!cx) cx = s.cx;
1316             if (!cy) cy = s.cy;
1317         }
1318     }
1319     info.proc  = func;
1320     info.param = ldata;
1321     return DrawStateA( HDC_32(hdc), HBRUSH_32(hbr), draw_state_callback,
1322                        (LPARAM)&info, wdata, x, y, cx, cy, flags );
1323 }
1324
1325
1326 /**********************************************************************
1327  *              CreateIconFromResourceEx (USER.450)
1328  *
1329  * FIXME: not sure about exact parameter types
1330  */
1331 HICON16 WINAPI CreateIconFromResourceEx16(LPBYTE bits, UINT16 cbSize,
1332                                           BOOL16 bIcon, DWORD dwVersion,
1333                                           INT16 width, INT16 height,
1334                                           UINT16 cFlag)
1335 {
1336   return HICON_16(CreateIconFromResourceEx(bits, cbSize, bIcon, dwVersion,
1337                                            width, height, cFlag));
1338 }
1339
1340
1341 /***********************************************************************
1342  *              AdjustWindowRectEx (USER.454)
1343  */
1344 BOOL16 WINAPI AdjustWindowRectEx16( LPRECT16 rect, DWORD style, BOOL16 menu, DWORD exStyle )
1345 {
1346     RECT rect32;
1347     BOOL ret;
1348
1349     rect32.left   = rect->left;
1350     rect32.top    = rect->top;
1351     rect32.right  = rect->right;
1352     rect32.bottom = rect->bottom;
1353     ret = AdjustWindowRectEx( &rect32, style, menu, exStyle );
1354     rect->left   = rect32.left;
1355     rect->top    = rect32.top;
1356     rect->right  = rect32.right;
1357     rect->bottom = rect32.bottom;
1358     return ret;
1359 }
1360
1361
1362 /***********************************************************************
1363  *              DestroyIcon (USER.457)
1364  */
1365 BOOL16 WINAPI DestroyIcon16(HICON16 hIcon)
1366 {
1367   return DestroyIcon32(hIcon, 0);
1368 }
1369
1370 /***********************************************************************
1371  *              DestroyCursor (USER.458)
1372  */
1373 BOOL16 WINAPI DestroyCursor16(HCURSOR16 hCursor)
1374 {
1375   return DestroyIcon32(hCursor, 0);
1376 }
1377
1378 /*******************************************************************
1379  *                      DRAG_QueryUpdate16
1380  *
1381  * Recursively find a child that contains spDragInfo->pt point
1382  * and send WM_QUERYDROPOBJECT. Helper for DragObject16.
1383  */
1384 static BOOL DRAG_QueryUpdate16( HWND hQueryWnd, SEGPTR spDragInfo )
1385 {
1386     BOOL bResult = 0;
1387     WPARAM wParam;
1388     POINT pt, old_pt;
1389     LPDRAGINFO16 ptrDragInfo = MapSL(spDragInfo);
1390     RECT tempRect;
1391     HWND child;
1392
1393     if (!IsWindowEnabled(hQueryWnd)) return FALSE;
1394
1395     old_pt.x = ptrDragInfo->pt.x;
1396     old_pt.y = ptrDragInfo->pt.y;
1397     pt = old_pt;
1398     ScreenToClient( hQueryWnd, &pt );
1399     child = ChildWindowFromPointEx( hQueryWnd, pt, CWP_SKIPINVISIBLE );
1400     if (!child) return FALSE;
1401
1402     if (child != hQueryWnd)
1403     {
1404         wParam = 0;
1405         if (DRAG_QueryUpdate16( child, spDragInfo )) return TRUE;
1406     }
1407     else
1408     {
1409         GetClientRect( hQueryWnd, &tempRect );
1410         wParam = !PtInRect( &tempRect, pt );
1411     }
1412
1413     ptrDragInfo->pt.x = pt.x;
1414     ptrDragInfo->pt.y = pt.y;
1415     ptrDragInfo->hScope = HWND_16(hQueryWnd);
1416
1417     bResult = SendMessage16( HWND_16(hQueryWnd), WM_QUERYDROPOBJECT, wParam, spDragInfo );
1418
1419     if (!bResult)
1420     {
1421         ptrDragInfo->pt.x = old_pt.x;
1422         ptrDragInfo->pt.y = old_pt.y;
1423     }
1424     return bResult;
1425 }
1426
1427
1428 /******************************************************************************
1429  *              DragObject (USER.464)
1430  */
1431 DWORD WINAPI DragObject16( HWND16 hwndScope, HWND16 hWnd, UINT16 wObj,
1432                            HANDLE16 hOfStruct, WORD szList, HCURSOR16 hCursor )
1433 {
1434     MSG msg;
1435     LPDRAGINFO16 lpDragInfo;
1436     SEGPTR      spDragInfo;
1437     HCURSOR     hOldCursor=0, hBummer=0;
1438     HGLOBAL16   hDragInfo  = GlobalAlloc16( GMEM_SHARE | GMEM_ZEROINIT, 2*sizeof(DRAGINFO16));
1439     HCURSOR     hCurrentCursor = 0;
1440     HWND16      hCurrentWnd = 0;
1441
1442     lpDragInfo = (LPDRAGINFO16) GlobalLock16(hDragInfo);
1443     spDragInfo = K32WOWGlobalLock16(hDragInfo);
1444
1445     if( !lpDragInfo || !spDragInfo ) return 0L;
1446
1447     if (!(hBummer = LoadCursorA(0, MAKEINTRESOURCEA(OCR_NO))))
1448     {
1449         GlobalFree16(hDragInfo);
1450         return 0L;
1451     }
1452
1453     if(hCursor) hOldCursor = SetCursor(HCURSOR_32(hCursor));
1454
1455     lpDragInfo->hWnd   = hWnd;
1456     lpDragInfo->hScope = 0;
1457     lpDragInfo->wFlags = wObj;
1458     lpDragInfo->hList  = szList; /* near pointer! */
1459     lpDragInfo->hOfStruct = hOfStruct;
1460     lpDragInfo->l = 0L;
1461
1462     SetCapture( HWND_32(hWnd) );
1463     ShowCursor( TRUE );
1464
1465     do
1466     {
1467         GetMessageW( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST );
1468
1469        *(lpDragInfo+1) = *lpDragInfo;
1470
1471         lpDragInfo->pt.x = msg.pt.x;
1472         lpDragInfo->pt.y = msg.pt.y;
1473
1474         /* update DRAGINFO struct */
1475         if( DRAG_QueryUpdate16(WIN_Handle32(hwndScope), spDragInfo) > 0 )
1476             hCurrentCursor = HCURSOR_32(hCursor);
1477         else
1478         {
1479             hCurrentCursor = hBummer;
1480             lpDragInfo->hScope = 0;
1481         }
1482         if( hCurrentCursor )
1483             SetCursor(hCurrentCursor);
1484
1485         /* send WM_DRAGLOOP */
1486         SendMessage16( hWnd, WM_DRAGLOOP, (WPARAM16)(hCurrentCursor != hBummer),
1487                                           (LPARAM) spDragInfo );
1488         /* send WM_DRAGSELECT or WM_DRAGMOVE */
1489         if( hCurrentWnd != lpDragInfo->hScope )
1490         {
1491             if( hCurrentWnd )
1492                 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 0,
1493                        (LPARAM)MAKELONG(LOWORD(spDragInfo)+sizeof(DRAGINFO16),
1494                                         HIWORD(spDragInfo)) );
1495             hCurrentWnd = lpDragInfo->hScope;
1496             if( hCurrentWnd )
1497                 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 1, (LPARAM)spDragInfo);
1498         }
1499         else
1500             if( hCurrentWnd )
1501                 SendMessage16( hCurrentWnd, WM_DRAGMOVE, 0, (LPARAM)spDragInfo);
1502
1503     } while( msg.message != WM_LBUTTONUP && msg.message != WM_NCLBUTTONUP );
1504
1505     ReleaseCapture();
1506     ShowCursor( FALSE );
1507
1508     if( hCursor ) SetCursor(hOldCursor);
1509
1510     if( hCurrentCursor != hBummer )
1511         msg.lParam = SendMessage16( lpDragInfo->hScope, WM_DROPOBJECT,
1512                                    (WPARAM16)hWnd, (LPARAM)spDragInfo );
1513     else
1514         msg.lParam = 0;
1515     GlobalFree16(hDragInfo);
1516
1517     return (DWORD)(msg.lParam);
1518 }
1519
1520
1521 /***********************************************************************
1522  *              DrawFocusRect (USER.466)
1523  */
1524 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
1525 {
1526     RECT rect32;
1527
1528     rect32.left   = rc->left;
1529     rect32.top    = rc->top;
1530     rect32.right  = rc->right;
1531     rect32.bottom = rc->bottom;
1532     DrawFocusRect( HDC_32(hdc), &rect32 );
1533 }
1534
1535
1536 /***********************************************************************
1537  *           AnsiNext   (USER.472)
1538  */
1539 SEGPTR WINAPI AnsiNext16(SEGPTR current)
1540 {
1541     char *ptr = MapSL(current);
1542     return current + (CharNextA(ptr) - ptr);
1543 }
1544
1545
1546 /***********************************************************************
1547  *           AnsiPrev   (USER.473)
1548  */
1549 SEGPTR WINAPI AnsiPrev16( LPCSTR start, SEGPTR current )
1550 {
1551     char *ptr = MapSL(current);
1552     return current - (ptr - CharPrevA( start, ptr ));
1553 }
1554
1555
1556 /***********************************************************************
1557  *           FormatMessage   (USER.606)
1558  */
1559 DWORD WINAPI FormatMessage16(
1560     DWORD   dwFlags,
1561     SEGPTR lpSource,     /* [in] NOTE: not always a valid pointer */
1562     WORD   dwMessageId,
1563     WORD   dwLanguageId,
1564     LPSTR  lpBuffer,     /* [out] NOTE: *((HLOCAL16*)) for FORMAT_MESSAGE_ALLOCATE_BUFFER*/
1565     WORD   nSize,
1566     LPDWORD args )       /* [in] NOTE: va_list *args */
1567 {
1568 #ifdef __i386__
1569 /* This implementation is completely dependent on the format of the va_list on x86 CPUs */
1570     LPSTR       target,t;
1571     DWORD       talloced;
1572     LPSTR       from,f;
1573     DWORD       width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK;
1574     BOOL        eos = FALSE;
1575     LPSTR       allocstring = NULL;
1576
1577     TRACE("(0x%lx,%lx,%d,0x%x,%p,%d,%p)\n",
1578           dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args);
1579         if ((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
1580                 && (dwFlags & FORMAT_MESSAGE_FROM_HMODULE)) return 0;
1581         if ((dwFlags & FORMAT_MESSAGE_FROM_STRING)
1582                 &&((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
1583                         || (dwFlags & FORMAT_MESSAGE_FROM_HMODULE))) return 0;
1584
1585     if (width && width != FORMAT_MESSAGE_MAX_WIDTH_MASK)
1586         FIXME("line wrapping (%lu) not supported.\n", width);
1587     from = NULL;
1588     if (dwFlags & FORMAT_MESSAGE_FROM_STRING)
1589     {
1590         char *source = MapSL(lpSource);
1591         from = HeapAlloc( GetProcessHeap(), 0, strlen(source)+1 );
1592         strcpy( from, source );
1593     }
1594     else if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) {
1595         from = HeapAlloc( GetProcessHeap(),0,200 );
1596         sprintf(from,"Systemmessage, messageid = 0x%08x\n",dwMessageId);
1597     }
1598     else if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) {
1599         INT16   bufsize;
1600         HINSTANCE16 hinst16 = ((HINSTANCE16)lpSource & 0xffff);
1601
1602         dwMessageId &= 0xFFFF;
1603         bufsize=LoadString16(hinst16,dwMessageId,NULL,0);
1604         if (bufsize) {
1605             from = HeapAlloc( GetProcessHeap(), 0, bufsize +1);
1606             LoadString16(hinst16,dwMessageId,from,bufsize+1);
1607         }
1608     }
1609     target      = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 100);
1610     t   = target;
1611     talloced= 100;
1612
1613 #define ADD_TO_T(c) \
1614         *t++=c;\
1615         if (t-target == talloced) {\
1616                 target  = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,talloced*2);\
1617                 t       = target+talloced;\
1618                 talloced*=2;\
1619         }
1620
1621     if (from) {
1622         f=from;
1623         while (*f && !eos) {
1624             if (*f=='%') {
1625                 int     insertnr;
1626                 char    *fmtstr,*x,*lastf;
1627                 DWORD   *argliststart;
1628
1629                 fmtstr = NULL;
1630                 lastf = f;
1631                 f++;
1632                 if (!*f) {
1633                     ADD_TO_T('%');
1634                     continue;
1635                 }
1636                 switch (*f) {
1637                 case '1':case '2':case '3':case '4':case '5':
1638                 case '6':case '7':case '8':case '9':
1639                     insertnr=*f-'0';
1640                     switch (f[1]) {
1641                     case '0':case '1':case '2':case '3':
1642                     case '4':case '5':case '6':case '7':
1643                     case '8':case '9':
1644                         f++;
1645                         insertnr=insertnr*10+*f-'0';
1646                         f++;
1647                         break;
1648                     default:
1649                         f++;
1650                         break;
1651                     }
1652                     if (*f=='!') {
1653                         f++;
1654                         if (NULL!=(x=strchr(f,'!'))) {
1655                             *x='\0';
1656                             fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2);
1657                             sprintf(fmtstr,"%%%s",f);
1658                             f=x+1;
1659                         } else {
1660                             fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2);
1661                             sprintf(fmtstr,"%%%s",f);
1662                             f+=strlen(f); /*at \0*/
1663                         }
1664                     }
1665                     else
1666                     {
1667                         if(!args) break;
1668                         fmtstr=HeapAlloc( GetProcessHeap(), 0, 3 );
1669                         strcpy( fmtstr, "%s" );
1670                     }
1671                     if (args) {
1672                         int     ret;
1673                         int     sz;
1674                         LPSTR   b = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz = 100);
1675
1676                         argliststart=args+insertnr-1;
1677
1678                         /* CMF - This makes a BIG assumption about va_list */
1679                         while ((ret = vsnprintf(b, sz, fmtstr, (va_list) argliststart) < 0) || (ret >= sz)) {
1680                             sz = (ret == -1 ? sz + 100 : ret + 1);
1681                             b = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, b, sz);
1682                         }
1683                         for (x=b; *x; x++) ADD_TO_T(*x);
1684                         HeapFree(GetProcessHeap(), 0, b);
1685                     } else {
1686                         /* NULL args - copy formatstr
1687                          * (probably wrong)
1688                          */
1689                         while ((lastf<f)&&(*lastf)) {
1690                             ADD_TO_T(*lastf++);
1691                         }
1692                     }
1693                     HeapFree(GetProcessHeap(),0,fmtstr);
1694                     break;
1695                 case '0': /* Just stop processing format string */
1696                     eos = TRUE;
1697                     f++;
1698                     break;
1699                 case 'n': /* 16 bit version just outputs 'n' */
1700                 default:
1701                     ADD_TO_T(*f++);
1702                     break;
1703                 }
1704             } else { /* '\n' or '\r' gets mapped to "\r\n" */
1705                 if(*f == '\n' || *f == '\r') {
1706                     if (width == 0) {
1707                         ADD_TO_T('\r');
1708                         ADD_TO_T('\n');
1709                         if(*f++ == '\r' && *f == '\n')
1710                             f++;
1711                     }
1712                 } else {
1713                     ADD_TO_T(*f++);
1714                 }
1715             }
1716         }
1717         *t='\0';
1718     }
1719     talloced = strlen(target)+1;
1720     if (nSize && talloced<nSize) {
1721         target = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,nSize);
1722     }
1723     TRACE("-- %s\n",debugstr_a(target));
1724     if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) {
1725         /* nSize is the MINIMUM size */
1726         HLOCAL16 h = LocalAlloc16(LPTR,talloced);
1727         SEGPTR ptr = LocalLock16(h);
1728         allocstring = MapSL( ptr );
1729         memcpy( allocstring,target,talloced);
1730         LocalUnlock16( h );
1731         *((HLOCAL16*)lpBuffer) = h;
1732     } else
1733         lstrcpynA(lpBuffer,target,nSize);
1734     HeapFree(GetProcessHeap(),0,target);
1735     HeapFree(GetProcessHeap(),0,from);
1736     return (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) ?
1737         strlen(allocstring):
1738         strlen(lpBuffer);
1739 #else
1740         return 0;
1741 #endif /* __i386__ */
1742 }
1743 #undef ADD_TO_T
1744
1745
1746 /***********************************************************************
1747  *              ChangeDisplaySettings (USER.620)
1748  */
1749 LONG WINAPI ChangeDisplaySettings16( LPDEVMODEA devmode, DWORD flags )
1750 {
1751     return ChangeDisplaySettingsA( devmode, flags );
1752 }
1753
1754
1755 /***********************************************************************
1756  *              EnumDisplaySettings (USER.621)
1757  */
1758 BOOL16 WINAPI EnumDisplaySettings16( LPCSTR name, DWORD n, LPDEVMODEA devmode )
1759 {
1760     return EnumDisplaySettingsA( name, n, devmode );
1761 }
1762
1763 /**********************************************************************
1764  *          DrawFrameControl  (USER.656)
1765  */
1766 BOOL16 WINAPI DrawFrameControl16( HDC16 hdc, LPRECT16 rc, UINT16 uType, UINT16 uState )
1767 {
1768     RECT rect32;
1769     BOOL ret;
1770
1771     rect32.left   = rc->left;
1772     rect32.top    = rc->top;
1773     rect32.right  = rc->right;
1774     rect32.bottom = rc->bottom;
1775     ret = DrawFrameControl( HDC_32(hdc), &rect32, uType, uState );
1776     rc->left   = rect32.left;
1777     rc->top    = rect32.top;
1778     rc->right  = rect32.right;
1779     rc->bottom = rect32.bottom;
1780     return ret;
1781 }
1782
1783 /**********************************************************************
1784  *          DrawEdge   (USER.659)
1785  */
1786 BOOL16 WINAPI DrawEdge16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
1787 {
1788     RECT rect32;
1789     BOOL ret;
1790
1791     rect32.left   = rc->left;
1792     rect32.top    = rc->top;
1793     rect32.right  = rc->right;
1794     rect32.bottom = rc->bottom;
1795     ret = DrawEdge( HDC_32(hdc), &rect32, edge, flags );
1796     rc->left   = rect32.left;
1797     rc->top    = rect32.top;
1798     rc->right  = rect32.right;
1799     rc->bottom = rect32.bottom;
1800     return ret;
1801 }
1802
1803 /**********************************************************************
1804  *              CheckMenuRadioItem (USER.666)
1805  */
1806 BOOL16 WINAPI CheckMenuRadioItem16(HMENU16 hMenu, UINT16 first, UINT16 last,
1807                                    UINT16 check, BOOL16 bypos)
1808 {
1809      return CheckMenuRadioItem( HMENU_32(hMenu), first, last, check, bypos );
1810 }