2 * Misc 16-bit USER functions
4 * Copyright 1993, 1996 Alexandre Julliard
5 * Copyright 2002 Patrik Stridvall
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/winuser16.h"
33 #include "user_private.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(user);
40 /* handle to handle 16 conversions */
41 #define HANDLE_16(h32) (LOWORD(h32))
43 /* handle16 to handle conversions */
44 #define HANDLE_32(h16) ((HANDLE)(ULONG_PTR)(h16))
45 #define HINSTANCE_32(h16) ((HINSTANCE)(ULONG_PTR)(h16))
47 #define IS_MENU_STRING_ITEM(flags) \
48 (((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR)) == MF_STRING)
50 /* UserSeeUserDo parameters */
51 #define USUD_LOCALALLOC 0x0001
52 #define USUD_LOCALFREE 0x0002
53 #define USUD_LOCALCOMPACT 0x0003
54 #define USUD_LOCALHEAP 0x0004
55 #define USUD_FIRSTCLASS 0x0005
57 WORD WINAPI DestroyIcon32(HGLOBAL16, UINT16);
59 WORD USER_HeapSel = 0; /* USER heap selector */
61 struct gray_string_info
63 GRAYSTRINGPROC16 proc;
68 /* callback for 16-bit gray string proc with opaque pointer */
69 static BOOL CALLBACK gray_string_callback( HDC hdc, LPARAM param, INT len )
71 const struct gray_string_info *info = (struct gray_string_info *)param;
75 args[3] = HDC_16(hdc);
76 args[2] = HIWORD(info->param);
77 args[1] = LOWORD(info->param);
79 WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
83 /* callback for 16-bit gray string proc with string pointer */
84 static BOOL CALLBACK gray_string_callback_ptr( HDC hdc, LPARAM param, INT len )
86 const struct gray_string_info *info;
87 char *str = (char *)param;
89 info = (struct gray_string_info *)(str - offsetof( struct gray_string_info, str ));
90 return gray_string_callback( hdc, (LPARAM)info, len );
93 struct draw_state_info
99 /* callback for 16-bit DrawState functions */
100 static BOOL CALLBACK draw_state_callback( HDC hdc, LPARAM lparam, WPARAM wparam, int cx, int cy )
102 const struct draw_state_info *info = (struct draw_state_info *)lparam;
106 args[5] = HDC_16(hdc);
107 args[4] = HIWORD(info->param);
108 args[3] = LOWORD(info->param);
112 WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
116 /* This function is a copy of the one in objects/font.c */
117 static void logfont_32_to_16( const LOGFONTA* font32, LPLOGFONT16 font16 )
119 font16->lfHeight = font32->lfHeight;
120 font16->lfWidth = font32->lfWidth;
121 font16->lfEscapement = font32->lfEscapement;
122 font16->lfOrientation = font32->lfOrientation;
123 font16->lfWeight = font32->lfWeight;
124 font16->lfItalic = font32->lfItalic;
125 font16->lfUnderline = font32->lfUnderline;
126 font16->lfStrikeOut = font32->lfStrikeOut;
127 font16->lfCharSet = font32->lfCharSet;
128 font16->lfOutPrecision = font32->lfOutPrecision;
129 font16->lfClipPrecision = font32->lfClipPrecision;
130 font16->lfQuality = font32->lfQuality;
131 font16->lfPitchAndFamily = font32->lfPitchAndFamily;
132 lstrcpynA( font16->lfFaceName, font32->lfFaceName, LF_FACESIZE );
135 /**********************************************************************
138 INT16 WINAPI InitApp16( HINSTANCE16 hInstance )
140 /* Create task message queue */
141 return (InitThreadInput16( 0, 0 ) != 0);
145 /***********************************************************************
146 * ExitWindows (USER.7)
148 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
150 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
154 /***********************************************************************
155 * GetTimerResolution (USER.14)
157 LONG WINAPI GetTimerResolution16(void)
163 /***********************************************************************
164 * ClipCursor (USER.16)
166 BOOL16 WINAPI ClipCursor16( const RECT16 *rect )
170 if (!rect) return ClipCursor( NULL );
171 rect32.left = rect->left;
172 rect32.top = rect->top;
173 rect32.right = rect->right;
174 rect32.bottom = rect->bottom;
175 return ClipCursor( &rect32 );
179 /***********************************************************************
180 * GetCursorPos (USER.17)
182 BOOL16 WINAPI GetCursorPos16( POINT16 *pt )
193 /*******************************************************************
196 BOOL16 WINAPI AnyPopup16(void)
202 /***********************************************************************
203 * SetCursor (USER.69)
205 HCURSOR16 WINAPI SetCursor16(HCURSOR16 hCursor)
207 return HCURSOR_16(SetCursor(HCURSOR_32(hCursor)));
211 /***********************************************************************
212 * SetCursorPos (USER.70)
214 void WINAPI SetCursorPos16( INT16 x, INT16 y )
216 SetCursorPos( x, y );
220 /***********************************************************************
221 * ShowCursor (USER.71)
223 INT16 WINAPI ShowCursor16(BOOL16 bShow)
225 return ShowCursor(bShow);
229 /***********************************************************************
232 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top, INT16 right, INT16 bottom )
237 rect->bottom = bottom;
241 /***********************************************************************
242 * SetRectEmpty (USER.73)
244 void WINAPI SetRectEmpty16( LPRECT16 rect )
246 rect->left = rect->right = rect->top = rect->bottom = 0;
250 /***********************************************************************
253 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
260 /***********************************************************************
261 * IsRectEmpty (USER.75)
263 * Bug compat: Windows checks for 0 or negative width/height.
265 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
267 return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
271 /***********************************************************************
274 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
276 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
277 (pt.y >= rect->top) && (pt.y < rect->bottom));
281 /***********************************************************************
282 * OffsetRect (USER.77)
284 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
293 /***********************************************************************
294 * InflateRect (USER.78)
296 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
305 /***********************************************************************
306 * IntersectRect (USER.79)
308 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
311 if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
312 (src1->left >= src2->right) || (src2->left >= src1->right) ||
313 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
315 SetRectEmpty16( dest );
318 dest->left = max( src1->left, src2->left );
319 dest->right = min( src1->right, src2->right );
320 dest->top = max( src1->top, src2->top );
321 dest->bottom = min( src1->bottom, src2->bottom );
326 /***********************************************************************
327 * UnionRect (USER.80)
329 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
332 if (IsRectEmpty16(src1))
334 if (IsRectEmpty16(src2))
336 SetRectEmpty16( dest );
343 if (IsRectEmpty16(src2)) *dest = *src1;
346 dest->left = min( src1->left, src2->left );
347 dest->right = max( src1->right, src2->right );
348 dest->top = min( src1->top, src2->top );
349 dest->bottom = max( src1->bottom, src2->bottom );
356 /***********************************************************************
359 * The Win16 variant doesn't support special color brushes like
360 * the Win32 one, despite the fact that Win16, as well as Win32,
361 * supports special background brushes for a window class.
363 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
367 /* coordinates are logical so we cannot fast-check 'rect',
368 * it will be done later in the PatBlt().
371 if (!(prevBrush = SelectObject( HDC_32(hdc), HBRUSH_32(hbrush) ))) return 0;
372 PatBlt( HDC_32(hdc), rect->left, rect->top,
373 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
374 SelectObject( HDC_32(hdc), prevBrush );
379 /***********************************************************************
380 * InvertRect (USER.82)
382 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
384 PatBlt( HDC_32(hdc), rect->left, rect->top,
385 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
389 /***********************************************************************
390 * FrameRect (USER.83)
392 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect16, HBRUSH16 hbrush )
396 rect.left = rect16->left;
397 rect.top = rect16->top;
398 rect.right = rect16->right;
399 rect.bottom = rect16->bottom;
400 return FrameRect( HDC_32(hdc), &rect, HBRUSH_32(hbrush) );
404 /***********************************************************************
407 BOOL16 WINAPI DrawIcon16(HDC16 hdc, INT16 x, INT16 y, HICON16 hIcon)
409 return DrawIcon(HDC_32(hdc), x, y, HICON_32(hIcon));
413 /***********************************************************************
416 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 count, LPRECT16 rect, UINT16 flags )
424 rect32.left = rect->left;
425 rect32.top = rect->top;
426 rect32.right = rect->right;
427 rect32.bottom = rect->bottom;
428 ret = DrawTextA( HDC_32(hdc), str, count, &rect32, flags );
429 rect->left = rect32.left;
430 rect->top = rect32.top;
431 rect->right = rect32.right;
432 rect->bottom = rect32.bottom;
434 else ret = DrawTextA( HDC_32(hdc), str, count, NULL, flags);
439 /***********************************************************************
442 * See "Undocumented Windows". Used by W2.0 paint.exe.
444 DWORD WINAPI IconSize16(void)
446 return MAKELONG(GetSystemMetrics(SM_CYICON), GetSystemMetrics(SM_CXICON));
450 /***********************************************************************
451 * AdjustWindowRect (USER.102)
453 BOOL16 WINAPI AdjustWindowRect16( LPRECT16 rect, DWORD style, BOOL16 menu )
455 return AdjustWindowRectEx16( rect, style, menu, 0 );
459 /***********************************************************************
460 * MessageBeep (USER.104)
462 void WINAPI MessageBeep16( UINT16 i )
468 /**************************************************************************
469 * CloseClipboard (USER.138)
471 BOOL16 WINAPI CloseClipboard16(void)
473 return CloseClipboard();
477 /**************************************************************************
478 * EmptyClipboard (USER.139)
480 BOOL16 WINAPI EmptyClipboard16(void)
482 return EmptyClipboard();
486 /**************************************************************************
487 * CountClipboardFormats (USER.143)
489 INT16 WINAPI CountClipboardFormats16(void)
491 return CountClipboardFormats();
495 /**************************************************************************
496 * EnumClipboardFormats (USER.144)
498 UINT16 WINAPI EnumClipboardFormats16( UINT16 id )
500 return EnumClipboardFormats( id );
504 /**************************************************************************
505 * RegisterClipboardFormat (USER.145)
507 UINT16 WINAPI RegisterClipboardFormat16( LPCSTR name )
509 return RegisterClipboardFormatA( name );
513 /**************************************************************************
514 * GetClipboardFormatName (USER.146)
516 INT16 WINAPI GetClipboardFormatName16( UINT16 id, LPSTR buffer, INT16 maxlen )
518 return GetClipboardFormatNameA( id, buffer, maxlen );
522 /**********************************************************************
523 * LoadMenu (USER.150)
525 HMENU16 WINAPI LoadMenu16( HINSTANCE16 instance, LPCSTR name )
531 if (HIWORD(name) && name[0] == '#') name = ULongToPtr(atoi( name + 1 ));
534 instance = GetExePtr( instance );
535 if (!(hRsrc = FindResource16( instance, name, (LPSTR)RT_MENU ))) return 0;
536 if (!(handle = LoadResource16( instance, hRsrc ))) return 0;
537 hMenu = LoadMenuIndirect16(LockResource16(handle));
538 FreeResource16( handle );
543 /**********************************************************************
544 * CreateMenu (USER.151)
546 HMENU16 WINAPI CreateMenu16(void)
548 return HMENU_16( CreateMenu() );
552 /**********************************************************************
553 * DestroyMenu (USER.152)
555 BOOL16 WINAPI DestroyMenu16( HMENU16 hMenu )
557 return DestroyMenu( HMENU_32(hMenu) );
561 /*******************************************************************
562 * ChangeMenu (USER.153)
564 BOOL16 WINAPI ChangeMenu16( HMENU16 hMenu, UINT16 pos, SEGPTR data,
565 UINT16 id, UINT16 flags )
567 if (flags & MF_APPEND) return AppendMenu16( hMenu, flags & ~MF_APPEND, id, data );
569 /* FIXME: Word passes the item id in 'pos' and 0 or 0xffff as id */
570 /* for MF_DELETE. We should check the parameters for all others */
571 /* MF_* actions also (anybody got a doc on ChangeMenu?). */
573 if (flags & MF_DELETE) return DeleteMenu16(hMenu, pos, flags & ~MF_DELETE);
574 if (flags & MF_CHANGE) return ModifyMenu16(hMenu, pos, flags & ~MF_CHANGE, id, data );
575 if (flags & MF_REMOVE) return RemoveMenu16(hMenu, flags & MF_BYPOSITION ? pos : id,
576 flags & ~MF_REMOVE );
577 /* Default: MF_INSERT */
578 return InsertMenu16( hMenu, pos, flags, id, data );
582 /*******************************************************************
583 * CheckMenuItem (USER.154)
585 BOOL16 WINAPI CheckMenuItem16( HMENU16 hMenu, UINT16 id, UINT16 flags )
587 return CheckMenuItem( HMENU_32(hMenu), id, flags );
591 /**********************************************************************
592 * EnableMenuItem (USER.155)
594 BOOL16 WINAPI EnableMenuItem16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
596 return EnableMenuItem( HMENU_32(hMenu), wItemID, wFlags );
600 /**********************************************************************
601 * GetSubMenu (USER.159)
603 HMENU16 WINAPI GetSubMenu16( HMENU16 hMenu, INT16 nPos )
605 return HMENU_16( GetSubMenu( HMENU_32(hMenu), nPos ) );
609 /*******************************************************************
610 * GetMenuString (USER.161)
612 INT16 WINAPI GetMenuString16( HMENU16 hMenu, UINT16 wItemID,
613 LPSTR str, INT16 nMaxSiz, UINT16 wFlags )
615 return GetMenuStringA( HMENU_32(hMenu), wItemID, str, nMaxSiz, wFlags );
619 /**********************************************************************
622 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
628 /* We might call WinExec() */
629 ReleaseThunkLock(&mutex_count);
631 ret = WinHelpA(WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData));
633 RestoreThunkLock(mutex_count);
638 /***********************************************************************
639 * LoadCursor (USER.173)
641 HCURSOR16 WINAPI LoadCursor16(HINSTANCE16 hInstance, LPCSTR name)
643 return HCURSOR_16(LoadCursorA(HINSTANCE_32(hInstance), name));
647 /***********************************************************************
648 * LoadIcon (USER.174)
650 HICON16 WINAPI LoadIcon16(HINSTANCE16 hInstance, LPCSTR name)
652 return HICON_16(LoadIconA(HINSTANCE_32(hInstance), name));
655 /**********************************************************************
656 * LoadBitmap (USER.175)
658 HBITMAP16 WINAPI LoadBitmap16(HINSTANCE16 hInstance, LPCSTR name)
660 return HBITMAP_16(LoadBitmapA(HINSTANCE_32(hInstance), name));
663 /**********************************************************************
664 * LoadString (USER.176)
666 INT16 WINAPI LoadString16( HINSTANCE16 instance, UINT16 resource_id, LPSTR buffer, INT16 buflen )
674 TRACE("inst=%04x id=%04x buff=%p len=%d\n", instance, resource_id, buffer, buflen);
676 hrsrc = FindResource16( instance, MAKEINTRESOURCEA((resource_id>>4)+1), (LPSTR)RT_STRING );
677 if (!hrsrc) return 0;
678 hmem = LoadResource16( instance, hrsrc );
681 p = LockResource16(hmem);
682 string_num = resource_id & 0x000f;
683 while (string_num--) p += *p + 1;
685 if (buffer == NULL) ret = *p;
688 ret = min(buflen - 1, *p);
691 memcpy(buffer, p + 1, ret);
699 TRACE( "%s loaded\n", debugstr_a(buffer));
701 FreeResource16( hmem );
705 /**********************************************************************
706 * LoadAccelerators (USER.177)
708 HACCEL16 WINAPI LoadAccelerators16(HINSTANCE16 instance, LPCSTR lpTableName)
715 TRACE("%04x %s\n", instance, debugstr_a(lpTableName) );
717 if (!(hRsrc = FindResource16( instance, lpTableName, (LPSTR)RT_ACCELERATOR )) ||
718 !(hMem = LoadResource16(instance,hRsrc)))
720 WARN("couldn't find %04x %s\n", instance, debugstr_a(lpTableName));
723 if ((table16 = LockResource16( hMem )))
725 DWORD i, count = SizeofResource16( instance, hRsrc ) / sizeof(*table16);
726 ACCEL *table = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*table) );
729 for (i = 0; i < count; i++)
731 table[i].fVirt = table16[i].fVirt & 0x7f;
732 table[i].key = table16[i].key;
733 table[i].cmd = table16[i].cmd;
735 ret = CreateAcceleratorTableA( table, count );
736 HeapFree( GetProcessHeap(), 0, table );
739 FreeResource16( hMem );
740 return HACCEL_16(ret);
743 /***********************************************************************
744 * GetSystemMetrics (USER.179)
746 INT16 WINAPI GetSystemMetrics16( INT16 index )
748 return GetSystemMetrics( index );
752 /*************************************************************************
753 * GetSysColor (USER.180)
755 COLORREF WINAPI GetSysColor16( INT16 index )
757 return GetSysColor( index );
761 /*************************************************************************
762 * SetSysColors (USER.181)
764 VOID WINAPI SetSysColors16( INT16 count, const INT16 *list16, const COLORREF *values )
768 if ((list = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*list) )))
770 for (i = 0; i < count; i++) list[i] = list16[i];
771 SetSysColors( count, list, values );
772 HeapFree( GetProcessHeap(), 0, list );
777 /***********************************************************************
778 * GrayString (USER.185)
780 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
781 LPARAM lParam, INT16 cch, INT16 x, INT16 y,
786 if (!gsprc) return GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), NULL,
787 (LPARAM)MapSL(lParam), cch, x, y, cx, cy );
789 if (cch == -1 || (cch && cx && cy))
791 /* lParam can be treated as an opaque pointer */
792 struct gray_string_info info;
796 ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback,
797 (LPARAM)&info, cch, x, y, cx, cy );
799 else /* here we need some string conversions */
801 char *str16 = MapSL(lParam);
802 struct gray_string_info *info;
804 if (!cch) cch = strlen(str16);
805 if (!(info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) + cch ))) return FALSE;
807 info->param = lParam;
808 memcpy( info->str, str16, cch );
809 ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback_ptr,
810 (LPARAM)info->str, cch, x, y, cx, cy );
811 HeapFree( GetProcessHeap(), 0, info );
817 /***********************************************************************
818 * SwapMouseButton (USER.186)
820 BOOL16 WINAPI SwapMouseButton16( BOOL16 fSwap )
822 return SwapMouseButton( fSwap );
826 /**************************************************************************
827 * IsClipboardFormatAvailable (USER.193)
829 BOOL16 WINAPI IsClipboardFormatAvailable16( UINT16 wFormat )
831 return IsClipboardFormatAvailable( wFormat );
835 /***********************************************************************
836 * TabbedTextOut (USER.196)
838 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
839 INT16 count, INT16 nb_tabs, const INT16 *tabs16, INT16 tab_org )
842 INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(tabs) );
844 for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
845 ret = TabbedTextOutA( HDC_32(hdc), x, y, lpstr, count, nb_tabs, tabs, tab_org );
846 HeapFree( GetProcessHeap(), 0, tabs );
851 /***********************************************************************
852 * GetTabbedTextExtent (USER.197)
854 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
855 INT16 nb_tabs, const INT16 *tabs16 )
858 INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(tabs) );
860 for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
861 ret = GetTabbedTextExtentA( HDC_32(hdc), lpstr, count, nb_tabs, tabs );
862 HeapFree( GetProcessHeap(), 0, tabs );
867 /***********************************************************************
868 * UserSeeUserDo (USER.216)
870 DWORD WINAPI UserSeeUserDo16(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
872 STACK16FRAME* stack16 = MapSL((SEGPTR)NtCurrentTeb()->WOW32Reserved);
873 HANDLE16 oldDS = stack16->ds;
874 DWORD ret = (DWORD)-1;
876 stack16->ds = USER_HeapSel;
879 case USUD_LOCALALLOC:
880 ret = LocalAlloc16(wParam1, wParam3);
883 ret = LocalFree16(wParam1);
885 case USUD_LOCALCOMPACT:
886 ret = LocalCompact16(wParam3);
891 case USUD_FIRSTCLASS:
892 FIXME("return a pointer to the first window class.\n");
895 WARN("wReqType %04x (unknown)\n", wReqType);
902 /***********************************************************************
903 * LookupMenuHandle (USER.217)
905 HMENU16 WINAPI LookupMenuHandle16( HMENU16 hmenu, INT16 id )
907 FIXME( "%04x %04x: stub\n", hmenu, id );
912 static LPCSTR parse_menu_resource( LPCSTR res, HMENU hMenu )
920 flags = GET_WORD(res);
921 end_flag = flags & MF_END;
922 /* Remove MF_END because it has the same value as MF_HILITE */
925 if (!(flags & MF_POPUP))
931 res += strlen(str) + 1;
932 if (flags & MF_POPUP)
934 HMENU hSubMenu = CreatePopupMenu();
935 if (!hSubMenu) return NULL;
936 if (!(res = parse_menu_resource( res, hSubMenu ))) return NULL;
937 AppendMenuA( hMenu, flags, (UINT_PTR)hSubMenu, str );
939 else /* Not a popup */
941 AppendMenuA( hMenu, flags, id, *str ? str : NULL );
947 /**********************************************************************
948 * LoadMenuIndirect (USER.220)
950 HMENU16 WINAPI LoadMenuIndirect16( LPCVOID template )
953 WORD version, offset;
956 TRACE("(%p)\n", template );
957 version = GET_WORD(p);
961 WARN("version must be 0 for Win16\n" );
964 offset = GET_WORD(p);
965 p += sizeof(WORD) + offset;
966 if (!(hMenu = CreateMenu())) return 0;
967 if (!parse_menu_resource( p, hMenu ))
969 DestroyMenu( hMenu );
972 return HMENU_16(hMenu);
976 /*************************************************************************
977 * ScrollDC (USER.221)
979 BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
980 const RECT16 *cliprc, HRGN16 hrgnUpdate,
983 RECT rect32, clipRect32, rcUpdate32;
988 rect32.left = rect->left;
989 rect32.top = rect->top;
990 rect32.right = rect->right;
991 rect32.bottom = rect->bottom;
995 clipRect32.left = cliprc->left;
996 clipRect32.top = cliprc->top;
997 clipRect32.right = cliprc->right;
998 clipRect32.bottom = cliprc->bottom;
1000 ret = ScrollDC( HDC_32(hdc), dx, dy, rect ? &rect32 : NULL,
1001 cliprc ? &clipRect32 : NULL, HRGN_32(hrgnUpdate),
1005 rcUpdate->left = rcUpdate32.left;
1006 rcUpdate->top = rcUpdate32.top;
1007 rcUpdate->right = rcUpdate32.right;
1008 rcUpdate->bottom = rcUpdate32.bottom;
1014 /***********************************************************************
1015 * GetSystemDebugState (USER.231)
1017 WORD WINAPI GetSystemDebugState16(void)
1019 return 0; /* FIXME */
1023 /***********************************************************************
1024 * EqualRect (USER.244)
1026 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
1028 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
1029 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
1033 /***********************************************************************
1034 * ExitWindowsExec (USER.246)
1036 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
1038 TRACE("Should run the following in DOS-mode: \"%s %s\"\n",
1039 lpszExe, lpszParams);
1040 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
1044 /***********************************************************************
1045 * GetCursor (USER.247)
1047 HCURSOR16 WINAPI GetCursor16(void)
1049 return HCURSOR_16(GetCursor());
1053 /**********************************************************************
1054 * GetAsyncKeyState (USER.249)
1056 INT16 WINAPI GetAsyncKeyState16( INT16 key )
1058 return GetAsyncKeyState( key );
1062 /**********************************************************************
1063 * GetMenuState (USER.250)
1065 UINT16 WINAPI GetMenuState16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
1067 return GetMenuState( HMENU_32(hMenu), wItemID, wFlags );
1071 /**************************************************************************
1072 * SendDriverMessage (USER.251)
1074 LRESULT WINAPI SendDriverMessage16(HDRVR16 hDriver, UINT16 msg, LPARAM lParam1,
1077 FIXME("(%04x, %04x, %08lx, %08lx): stub\n", hDriver, msg, lParam1, lParam2);
1082 /**************************************************************************
1083 * OpenDriver (USER.252)
1085 HDRVR16 WINAPI OpenDriver16(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam2)
1087 FIXME( "(%s, %s, %08lx): stub\n", debugstr_a(lpDriverName), debugstr_a(lpSectionName), lParam2);
1092 /**************************************************************************
1093 * CloseDriver (USER.253)
1095 LRESULT WINAPI CloseDriver16(HDRVR16 hDrvr, LPARAM lParam1, LPARAM lParam2)
1097 FIXME( "(%04x, %08lx, %08lx): stub\n", hDrvr, lParam1, lParam2);
1102 /**************************************************************************
1103 * GetDriverModuleHandle (USER.254)
1105 HMODULE16 WINAPI GetDriverModuleHandle16(HDRVR16 hDrvr)
1107 FIXME("(%04x): stub\n", hDrvr);
1112 /**************************************************************************
1113 * DefDriverProc (USER.255)
1115 LRESULT WINAPI DefDriverProc16(DWORD dwDevID, HDRVR16 hDriv, UINT16 wMsg,
1116 LPARAM lParam1, LPARAM lParam2)
1118 FIXME( "devID=0x%08x hDrv=0x%04x wMsg=%04x lP1=0x%08lx lP2=0x%08lx: stub\n",
1119 dwDevID, hDriv, wMsg, lParam1, lParam2);
1124 /**************************************************************************
1125 * GetDriverInfo (USER.256)
1127 struct DRIVERINFOSTRUCT16;
1128 BOOL16 WINAPI GetDriverInfo16(HDRVR16 hDrvr, struct DRIVERINFOSTRUCT16 *lpDrvInfo)
1130 FIXME( "(%04x, %p): stub\n", hDrvr, lpDrvInfo);
1135 /**************************************************************************
1136 * GetNextDriver (USER.257)
1138 HDRVR16 WINAPI GetNextDriver16(HDRVR16 hDrvr, DWORD dwFlags)
1140 FIXME( "(%04x, %08x): stub\n", hDrvr, dwFlags);
1145 /**********************************************************************
1146 * GetMenuItemCount (USER.263)
1148 INT16 WINAPI GetMenuItemCount16( HMENU16 hMenu )
1150 return GetMenuItemCount( HMENU_32(hMenu) );
1154 /**********************************************************************
1155 * GetMenuItemID (USER.264)
1157 UINT16 WINAPI GetMenuItemID16( HMENU16 hMenu, INT16 nPos )
1159 return GetMenuItemID( HMENU_32(hMenu), nPos );
1163 /***********************************************************************
1164 * GlobalAddAtom (USER.268)
1166 ATOM WINAPI GlobalAddAtom16(LPCSTR lpString)
1168 return GlobalAddAtomA(lpString);
1171 /***********************************************************************
1172 * GlobalDeleteAtom (USER.269)
1174 ATOM WINAPI GlobalDeleteAtom16(ATOM nAtom)
1176 return GlobalDeleteAtom(nAtom);
1179 /***********************************************************************
1180 * GlobalFindAtom (USER.270)
1182 ATOM WINAPI GlobalFindAtom16(LPCSTR lpString)
1184 return GlobalFindAtomA(lpString);
1187 /***********************************************************************
1188 * GlobalGetAtomName (USER.271)
1190 UINT16 WINAPI GlobalGetAtomName16(ATOM nAtom, LPSTR lpBuffer, INT16 nSize)
1192 return GlobalGetAtomNameA(nAtom, lpBuffer, nSize);
1196 /***********************************************************************
1197 * ControlPanelInfo (USER.273)
1199 void WINAPI ControlPanelInfo16( INT16 nInfoType, WORD wData, LPSTR lpBuffer )
1201 FIXME("(%d, %04x, %p): stub.\n", nInfoType, wData, lpBuffer);
1205 /***********************************************************************
1206 * OldSetDeskPattern (USER.279)
1208 BOOL16 WINAPI SetDeskPattern16(void)
1210 return SystemParametersInfoA( SPI_SETDESKPATTERN, -1, NULL, FALSE );
1214 /***********************************************************************
1215 * GetSysColorBrush (USER.281)
1217 HBRUSH16 WINAPI GetSysColorBrush16( INT16 index )
1219 return HBRUSH_16( GetSysColorBrush(index) );
1223 /***********************************************************************
1224 * SelectPalette (USER.282)
1226 HPALETTE16 WINAPI SelectPalette16( HDC16 hdc, HPALETTE16 hpal, BOOL16 bForceBackground )
1228 return HPALETTE_16( SelectPalette( HDC_32(hdc), HPALETTE_32(hpal), bForceBackground ));
1231 /***********************************************************************
1232 * RealizePalette (USER.283)
1234 UINT16 WINAPI RealizePalette16( HDC16 hdc )
1236 return UserRealizePalette( HDC_32(hdc) );
1240 /***********************************************************************
1241 * GetFreeSystemResources (USER.284)
1243 WORD WINAPI GetFreeSystemResources16( WORD resType )
1245 STACK16FRAME* stack16 = MapSL((SEGPTR)NtCurrentTeb()->WOW32Reserved);
1246 HANDLE16 oldDS = stack16->ds;
1247 HINSTANCE16 gdi_inst;
1248 int userPercent, gdiPercent;
1250 if ((gdi_inst = LoadLibrary16( "GDI" )) < 32) return 0;
1254 case GFSR_USERRESOURCES:
1255 stack16->ds = USER_HeapSel;
1256 userPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
1258 stack16->ds = oldDS;
1261 case GFSR_GDIRESOURCES:
1262 stack16->ds = gdi_inst;
1263 gdiPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
1265 stack16->ds = oldDS;
1268 case GFSR_SYSTEMRESOURCES:
1269 stack16->ds = USER_HeapSel;
1270 userPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
1271 stack16->ds = gdi_inst;
1272 gdiPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
1273 stack16->ds = oldDS;
1277 userPercent = gdiPercent = 0;
1280 FreeLibrary16( gdi_inst );
1281 TRACE("<- userPercent %d, gdiPercent %d\n", userPercent, gdiPercent);
1282 return (WORD)min( userPercent, gdiPercent );
1286 /***********************************************************************
1287 * SetDeskWallPaper (USER.285)
1289 BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
1291 return SetDeskWallPaper( filename );
1295 /***********************************************************************
1296 * keybd_event (USER.289)
1298 void WINAPI keybd_event16( CONTEXT86 *context )
1302 if (HIBYTE(context->Eax) & 0x80) dwFlags |= KEYEVENTF_KEYUP;
1303 if (HIBYTE(context->Ebx) & 0x01) dwFlags |= KEYEVENTF_EXTENDEDKEY;
1305 keybd_event( LOBYTE(context->Eax), LOBYTE(context->Ebx),
1306 dwFlags, MAKELONG(LOWORD(context->Esi), LOWORD(context->Edi)) );
1310 /***********************************************************************
1311 * mouse_event (USER.299)
1313 void WINAPI mouse_event16( CONTEXT86 *context )
1315 mouse_event( LOWORD(context->Eax), LOWORD(context->Ebx), LOWORD(context->Ecx),
1316 LOWORD(context->Edx), MAKELONG(context->Esi, context->Edi) );
1320 /***********************************************************************
1321 * GetClipCursor (USER.309)
1323 void WINAPI GetClipCursor16( RECT16 *rect )
1328 GetClipCursor( &rect32 );
1329 rect->left = rect32.left;
1330 rect->top = rect32.top;
1331 rect->right = rect32.right;
1332 rect->bottom = rect32.bottom;
1337 /***********************************************************************
1338 * SignalProc (USER.314)
1340 void WINAPI SignalProc16( HANDLE16 hModule, UINT16 code,
1341 UINT16 uExitFn, HINSTANCE16 hInstance, HQUEUE16 hQueue )
1343 if (code == USIG16_DLL_UNLOAD)
1345 /* HOOK_FreeModuleHooks( hModule ); */
1346 CLASS_FreeModuleClasses( hModule );
1347 CURSORICON_FreeModuleIcons( hModule );
1352 /***********************************************************************
1353 * SetEventHook (USER.321)
1355 * Used by Turbo Debugger for Windows
1357 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
1359 FIXME("(lpfnEventHook=%p): stub\n", lpfnEventHook);
1364 /**********************************************************************
1365 * EnableHardwareInput (USER.331)
1367 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
1369 FIXME("(%d) - stub\n", bEnable);
1374 /***********************************************************************
1375 * GetMouseEventProc (USER.337)
1377 FARPROC16 WINAPI GetMouseEventProc16(void)
1379 HMODULE16 hmodule = GetModuleHandle16("USER");
1380 return GetProcAddress16( hmodule, "mouse_event" );
1384 /***********************************************************************
1385 * IsUserIdle (USER.333)
1387 BOOL16 WINAPI IsUserIdle16(void)
1389 if ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
1391 if ( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 )
1393 if ( GetAsyncKeyState( VK_MBUTTON ) & 0x8000 )
1395 /* Should check for screen saver activation here ... */
1400 /**********************************************************************
1401 * LoadDIBIconHandler (USER.357)
1403 * RT_ICON resource loader, installed by USER_SignalProc when module
1406 HGLOBAL16 WINAPI LoadDIBIconHandler16( HGLOBAL16 hMemObj, HMODULE16 hModule, HRSRC16 hRsrc )
1408 /* If hResource is zero we must allocate a new memory block, if it's
1409 * non-zero but GlobalLock() returns NULL then it was discarded and
1410 * we have to recommit some memory, otherwise we just need to check
1411 * the block size. See LoadProc() in 16-bit SDK for more.
1413 FIXME( "%x %x %x: stub, not supported anymore\n", hMemObj, hModule, hRsrc );
1417 /**********************************************************************
1418 * LoadDIBCursorHandler (USER.356)
1420 * RT_CURSOR resource loader. Same as above.
1422 HGLOBAL16 WINAPI LoadDIBCursorHandler16( HGLOBAL16 hMemObj, HMODULE16 hModule, HRSRC16 hRsrc )
1424 FIXME( "%x %x %x: stub, not supported anymore\n", hMemObj, hModule, hRsrc );
1429 /**********************************************************************
1432 BOOL16 WINAPI IsMenu16( HMENU16 hmenu )
1434 return IsMenu( HMENU_32(hmenu) );
1438 /***********************************************************************
1441 BOOL16 WINAPI DCHook16( HDC16 hdc, WORD code, DWORD data, LPARAM lParam )
1443 FIXME( "hDC = %x, %i: stub\n", hdc, code );
1448 /***********************************************************************
1449 * SubtractRect (USER.373)
1451 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
1452 const RECT16 *src2 )
1456 if (IsRectEmpty16( src1 ))
1458 SetRectEmpty16( dest );
1462 if (IntersectRect16( &tmp, src1, src2 ))
1464 if (EqualRect16( &tmp, dest ))
1466 SetRectEmpty16( dest );
1469 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
1471 if (tmp.left == dest->left) dest->left = tmp.right;
1472 else if (tmp.right == dest->right) dest->right = tmp.left;
1474 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
1476 if (tmp.top == dest->top) dest->top = tmp.bottom;
1477 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
1484 /**********************************************************************
1485 * DllEntryPoint (USER.374)
1487 BOOL WINAPI DllEntryPoint( DWORD reason, HINSTANCE16 inst, WORD ds,
1488 WORD heap, DWORD reserved1, WORD reserved2 )
1490 if (reason != DLL_PROCESS_ATTACH) return TRUE;
1491 if (USER_HeapSel) return TRUE; /* already called */
1494 register_wow_handlers();
1499 /**********************************************************************
1500 * SetMenuContextHelpId (USER.384)
1502 BOOL16 WINAPI SetMenuContextHelpId16( HMENU16 hMenu, DWORD dwContextHelpID)
1504 return SetMenuContextHelpId( HMENU_32(hMenu), dwContextHelpID );
1508 /**********************************************************************
1509 * GetMenuContextHelpId (USER.385)
1511 DWORD WINAPI GetMenuContextHelpId16( HMENU16 hMenu )
1513 return GetMenuContextHelpId( HMENU_32(hMenu) );
1517 /***********************************************************************
1518 * LoadImage (USER.389)
1521 HANDLE16 WINAPI LoadImage16(HINSTANCE16 hinst, LPCSTR name, UINT16 type,
1522 INT16 desiredx, INT16 desiredy, UINT16 loadflags)
1524 return HANDLE_16(LoadImageA(HINSTANCE_32(hinst), name, type, desiredx,
1525 desiredy, loadflags));
1528 /******************************************************************************
1529 * CopyImage (USER.390) Creates new image and copies attributes to it
1532 HICON16 WINAPI CopyImage16(HANDLE16 hnd, UINT16 type, INT16 desiredx,
1533 INT16 desiredy, UINT16 flags)
1535 return HICON_16(CopyImage(HANDLE_32(hnd), (UINT)type, (INT)desiredx,
1536 (INT)desiredy, (UINT)flags));
1539 /**********************************************************************
1540 * DrawIconEx (USER.394)
1542 BOOL16 WINAPI DrawIconEx16(HDC16 hdc, INT16 xLeft, INT16 yTop, HICON16 hIcon,
1543 INT16 cxWidth, INT16 cyWidth, UINT16 istep,
1544 HBRUSH16 hbr, UINT16 flags)
1546 return DrawIconEx(HDC_32(hdc), xLeft, yTop, HICON_32(hIcon), cxWidth, cyWidth,
1547 istep, HBRUSH_32(hbr), flags);
1550 /**********************************************************************
1551 * GetIconInfo (USER.395)
1553 BOOL16 WINAPI GetIconInfo16(HICON16 hIcon, LPICONINFO16 iconinfo)
1556 BOOL16 ret = GetIconInfo(HICON_32(hIcon), &ii32);
1558 iconinfo->fIcon = ii32.fIcon;
1559 iconinfo->xHotspot = ii32.xHotspot;
1560 iconinfo->yHotspot = ii32.yHotspot;
1561 iconinfo->hbmMask = HBITMAP_16(ii32.hbmMask);
1562 iconinfo->hbmColor = HBITMAP_16(ii32.hbmColor);
1567 /***********************************************************************
1568 * FinalUserInit (USER.400)
1570 void WINAPI FinalUserInit16( void )
1572 /* FIXME: Should chain to FinalGdiInit */
1576 /***********************************************************************
1577 * CreateCursor (USER.406)
1579 HCURSOR16 WINAPI CreateCursor16(HINSTANCE16 hInstance,
1580 INT16 xHotSpot, INT16 yHotSpot,
1581 INT16 nWidth, INT16 nHeight,
1582 LPCVOID lpANDbits, LPCVOID lpXORbits)
1584 CURSORICONINFO info;
1586 info.ptHotSpot.x = xHotSpot;
1587 info.ptHotSpot.y = yHotSpot;
1588 info.nWidth = nWidth;
1589 info.nHeight = nHeight;
1590 info.nWidthBytes = 0;
1592 info.bBitsPerPixel = 1;
1594 return CreateCursorIconIndirect16(hInstance, &info, lpANDbits, lpXORbits);
1598 /***********************************************************************
1599 * InitThreadInput (USER.409)
1601 HQUEUE16 WINAPI InitThreadInput16( WORD unknown, WORD flags )
1603 /* nothing to do here */
1608 /*******************************************************************
1609 * InsertMenu (USER.410)
1611 BOOL16 WINAPI InsertMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
1612 UINT16 id, SEGPTR data )
1614 UINT pos32 = (UINT)pos;
1615 if ((pos == (UINT16)-1) && (flags & MF_BYPOSITION)) pos32 = (UINT)-1;
1616 if (IS_MENU_STRING_ITEM(flags) && data)
1617 return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, MapSL(data) );
1618 return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, (LPSTR)data );
1622 /*******************************************************************
1623 * AppendMenu (USER.411)
1625 BOOL16 WINAPI AppendMenu16(HMENU16 hMenu, UINT16 flags, UINT16 id, SEGPTR data)
1627 return InsertMenu16( hMenu, -1, flags | MF_BYPOSITION, id, data );
1631 /**********************************************************************
1632 * RemoveMenu (USER.412)
1634 BOOL16 WINAPI RemoveMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
1636 return RemoveMenu( HMENU_32(hMenu), nPos, wFlags );
1640 /**********************************************************************
1641 * DeleteMenu (USER.413)
1643 BOOL16 WINAPI DeleteMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
1645 return DeleteMenu( HMENU_32(hMenu), nPos, wFlags );
1649 /*******************************************************************
1650 * ModifyMenu (USER.414)
1652 BOOL16 WINAPI ModifyMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
1653 UINT16 id, SEGPTR data )
1655 if (IS_MENU_STRING_ITEM(flags))
1656 return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, MapSL(data) );
1657 return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, (LPSTR)data );
1661 /**********************************************************************
1662 * CreatePopupMenu (USER.415)
1664 HMENU16 WINAPI CreatePopupMenu16(void)
1666 return HMENU_16( CreatePopupMenu() );
1670 /**********************************************************************
1671 * SetMenuItemBitmaps (USER.418)
1673 BOOL16 WINAPI SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags,
1674 HBITMAP16 hNewUnCheck, HBITMAP16 hNewCheck)
1676 return SetMenuItemBitmaps( HMENU_32(hMenu), nPos, wFlags,
1677 HBITMAP_32(hNewUnCheck), HBITMAP_32(hNewCheck) );
1681 /***********************************************************************
1682 * lstrcmp (USER.430)
1684 INT16 WINAPI lstrcmp16( LPCSTR str1, LPCSTR str2 )
1686 return strcmp( str1, str2 );
1690 /***********************************************************************
1691 * AnsiUpper (USER.431)
1693 SEGPTR WINAPI AnsiUpper16( SEGPTR strOrChar )
1695 /* uppercase only one char if strOrChar < 0x10000 */
1696 if (HIWORD(strOrChar))
1698 CharUpperA( MapSL(strOrChar) );
1701 else return (SEGPTR)CharUpperA( (LPSTR)strOrChar );
1705 /***********************************************************************
1706 * AnsiLower (USER.432)
1708 SEGPTR WINAPI AnsiLower16( SEGPTR strOrChar )
1710 /* lowercase only one char if strOrChar < 0x10000 */
1711 if (HIWORD(strOrChar))
1713 CharLowerA( MapSL(strOrChar) );
1716 else return (SEGPTR)CharLowerA( (LPSTR)strOrChar );
1720 /***********************************************************************
1721 * AnsiUpperBuff (USER.437)
1723 UINT16 WINAPI AnsiUpperBuff16( LPSTR str, UINT16 len )
1725 CharUpperBuffA( str, len ? len : 65536 );
1730 /***********************************************************************
1731 * AnsiLowerBuff (USER.438)
1733 UINT16 WINAPI AnsiLowerBuff16( LPSTR str, UINT16 len )
1735 CharLowerBuffA( str, len ? len : 65536 );
1740 /*******************************************************************
1741 * InsertMenuItem (USER.441)
1745 BOOL16 WINAPI InsertMenuItem16( HMENU16 hmenu, UINT16 pos, BOOL16 byposition,
1746 const MENUITEMINFO16 *mii )
1750 miia.cbSize = sizeof(miia);
1751 miia.fMask = mii->fMask;
1752 miia.dwTypeData = (LPSTR)mii->dwTypeData;
1753 miia.fType = mii->fType;
1754 miia.fState = mii->fState;
1755 miia.wID = mii->wID;
1756 miia.hSubMenu = HMENU_32(mii->hSubMenu);
1757 miia.hbmpChecked = HBITMAP_32(mii->hbmpChecked);
1758 miia.hbmpUnchecked = HBITMAP_32(mii->hbmpUnchecked);
1759 miia.dwItemData = mii->dwItemData;
1760 miia.cch = mii->cch;
1761 if (IS_MENU_STRING_ITEM(miia.fType))
1762 miia.dwTypeData = MapSL(mii->dwTypeData);
1763 return InsertMenuItemA( HMENU_32(hmenu), pos, byposition, &miia );
1767 /**********************************************************************
1768 * DrawState (USER.449)
1770 BOOL16 WINAPI DrawState16( HDC16 hdc, HBRUSH16 hbr, DRAWSTATEPROC16 func, LPARAM ldata,
1771 WPARAM16 wdata, INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags )
1773 struct draw_state_info info;
1774 UINT opcode = flags & 0xf;
1776 if (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)
1778 /* make sure DrawStateA doesn't try to use ldata as a pointer */
1779 if (!wdata) wdata = strlen( MapSL(ldata) );
1783 if (!GetTextExtentPoint32A( HDC_32(hdc), MapSL(ldata), wdata, &s )) return FALSE;
1790 return DrawStateA( HDC_32(hdc), HBRUSH_32(hbr), draw_state_callback,
1791 (LPARAM)&info, wdata, x, y, cx, cy, flags );
1795 /**********************************************************************
1796 * CreateIconFromResourceEx (USER.450)
1798 * FIXME: not sure about exact parameter types
1800 HICON16 WINAPI CreateIconFromResourceEx16(LPBYTE bits, UINT16 cbSize,
1801 BOOL16 bIcon, DWORD dwVersion,
1802 INT16 width, INT16 height,
1805 return HICON_16(CreateIconFromResourceEx(bits, cbSize, bIcon, dwVersion,
1806 width, height, cFlag));
1810 /***********************************************************************
1811 * AdjustWindowRectEx (USER.454)
1813 BOOL16 WINAPI AdjustWindowRectEx16( LPRECT16 rect, DWORD style, BOOL16 menu, DWORD exStyle )
1818 rect32.left = rect->left;
1819 rect32.top = rect->top;
1820 rect32.right = rect->right;
1821 rect32.bottom = rect->bottom;
1822 ret = AdjustWindowRectEx( &rect32, style, menu, exStyle );
1823 rect->left = rect32.left;
1824 rect->top = rect32.top;
1825 rect->right = rect32.right;
1826 rect->bottom = rect32.bottom;
1831 /***********************************************************************
1832 * DestroyIcon (USER.457)
1834 BOOL16 WINAPI DestroyIcon16(HICON16 hIcon)
1836 return DestroyIcon32(hIcon, 0);
1839 /***********************************************************************
1840 * DestroyCursor (USER.458)
1842 BOOL16 WINAPI DestroyCursor16(HCURSOR16 hCursor)
1844 return DestroyIcon32(hCursor, 0);
1847 /*******************************************************************
1848 * DRAG_QueryUpdate16
1850 * Recursively find a child that contains spDragInfo->pt point
1851 * and send WM_QUERYDROPOBJECT. Helper for DragObject16.
1853 static BOOL DRAG_QueryUpdate16( HWND hQueryWnd, SEGPTR spDragInfo )
1858 LPDRAGINFO16 ptrDragInfo = MapSL(spDragInfo);
1862 if (!IsWindowEnabled(hQueryWnd)) return FALSE;
1864 old_pt.x = ptrDragInfo->pt.x;
1865 old_pt.y = ptrDragInfo->pt.y;
1867 ScreenToClient( hQueryWnd, &pt );
1868 child = ChildWindowFromPointEx( hQueryWnd, pt, CWP_SKIPINVISIBLE );
1869 if (!child) return FALSE;
1871 if (child != hQueryWnd)
1874 if (DRAG_QueryUpdate16( child, spDragInfo )) return TRUE;
1878 GetClientRect( hQueryWnd, &tempRect );
1879 wParam = !PtInRect( &tempRect, pt );
1882 ptrDragInfo->pt.x = pt.x;
1883 ptrDragInfo->pt.y = pt.y;
1884 ptrDragInfo->hScope = HWND_16(hQueryWnd);
1886 bResult = SendMessage16( HWND_16(hQueryWnd), WM_QUERYDROPOBJECT, wParam, spDragInfo );
1890 ptrDragInfo->pt.x = old_pt.x;
1891 ptrDragInfo->pt.y = old_pt.y;
1897 /******************************************************************************
1898 * DragObject (USER.464)
1900 DWORD WINAPI DragObject16( HWND16 hwndScope, HWND16 hWnd, UINT16 wObj,
1901 HANDLE16 hOfStruct, WORD szList, HCURSOR16 hCursor )
1904 LPDRAGINFO16 lpDragInfo;
1906 HCURSOR hOldCursor=0, hBummer=0;
1907 HGLOBAL16 hDragInfo = GlobalAlloc16( GMEM_SHARE | GMEM_ZEROINIT, 2*sizeof(DRAGINFO16));
1908 HCURSOR hCurrentCursor = 0;
1909 HWND16 hCurrentWnd = 0;
1911 lpDragInfo = (LPDRAGINFO16) GlobalLock16(hDragInfo);
1912 spDragInfo = WOWGlobalLock16(hDragInfo);
1914 if( !lpDragInfo || !spDragInfo ) return 0L;
1916 if (!(hBummer = LoadCursorA(0, MAKEINTRESOURCEA(OCR_NO))))
1918 GlobalFree16(hDragInfo);
1922 if(hCursor) hOldCursor = SetCursor(HCURSOR_32(hCursor));
1924 lpDragInfo->hWnd = hWnd;
1925 lpDragInfo->hScope = 0;
1926 lpDragInfo->wFlags = wObj;
1927 lpDragInfo->hList = szList; /* near pointer! */
1928 lpDragInfo->hOfStruct = hOfStruct;
1931 SetCapture( HWND_32(hWnd) );
1936 GetMessageW( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST );
1938 *(lpDragInfo+1) = *lpDragInfo;
1940 lpDragInfo->pt.x = msg.pt.x;
1941 lpDragInfo->pt.y = msg.pt.y;
1943 /* update DRAGINFO struct */
1944 if( DRAG_QueryUpdate16(WIN_Handle32(hwndScope), spDragInfo) > 0 )
1945 hCurrentCursor = HCURSOR_32(hCursor);
1948 hCurrentCursor = hBummer;
1949 lpDragInfo->hScope = 0;
1951 if( hCurrentCursor )
1952 SetCursor(hCurrentCursor);
1954 /* send WM_DRAGLOOP */
1955 SendMessage16( hWnd, WM_DRAGLOOP, (WPARAM16)(hCurrentCursor != hBummer),
1956 (LPARAM) spDragInfo );
1957 /* send WM_DRAGSELECT or WM_DRAGMOVE */
1958 if( hCurrentWnd != lpDragInfo->hScope )
1961 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 0,
1962 (LPARAM)MAKELONG(LOWORD(spDragInfo)+sizeof(DRAGINFO16),
1963 HIWORD(spDragInfo)) );
1964 hCurrentWnd = lpDragInfo->hScope;
1966 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 1, (LPARAM)spDragInfo);
1970 SendMessage16( hCurrentWnd, WM_DRAGMOVE, 0, (LPARAM)spDragInfo);
1972 } while( msg.message != WM_LBUTTONUP && msg.message != WM_NCLBUTTONUP );
1975 ShowCursor( FALSE );
1977 if( hCursor ) SetCursor(hOldCursor);
1979 if( hCurrentCursor != hBummer )
1980 msg.lParam = SendMessage16( lpDragInfo->hScope, WM_DROPOBJECT,
1981 (WPARAM16)hWnd, (LPARAM)spDragInfo );
1984 GlobalFree16(hDragInfo);
1986 return (DWORD)(msg.lParam);
1990 /***********************************************************************
1991 * DrawFocusRect (USER.466)
1993 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
1997 rect32.left = rc->left;
1998 rect32.top = rc->top;
1999 rect32.right = rc->right;
2000 rect32.bottom = rc->bottom;
2001 DrawFocusRect( HDC_32(hdc), &rect32 );
2005 /***********************************************************************
2006 * AnsiNext (USER.472)
2008 SEGPTR WINAPI AnsiNext16(SEGPTR current)
2010 char *ptr = MapSL(current);
2011 return current + (CharNextA(ptr) - ptr);
2015 /***********************************************************************
2016 * AnsiPrev (USER.473)
2018 SEGPTR WINAPI AnsiPrev16( LPCSTR start, SEGPTR current )
2020 char *ptr = MapSL(current);
2021 return current - (ptr - CharPrevA( start, ptr ));
2025 /****************************************************************************
2026 * GetKeyboardLayoutName (USER.477)
2028 INT16 WINAPI GetKeyboardLayoutName16( LPSTR name )
2030 return GetKeyboardLayoutNameA( name );
2034 /***********************************************************************
2035 * SystemParametersInfo (USER.483)
2037 BOOL16 WINAPI SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
2038 LPVOID lpvParam, UINT16 fuWinIni )
2042 TRACE("(%u, %u, %p, %u)\n", uAction, uParam, lpvParam, fuWinIni);
2047 case SPI_GETSCREENSAVEACTIVE:
2048 case SPI_GETICONTITLEWRAP:
2049 case SPI_GETMENUDROPALIGNMENT:
2050 case SPI_GETFASTTASKSWITCH:
2051 case SPI_GETDRAGFULLWINDOWS:
2054 ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2055 if (ret && lpvParam) *(BOOL16 *)lpvParam = tmp;
2060 case SPI_ICONHORIZONTALSPACING:
2061 case SPI_GETSCREENSAVETIMEOUT:
2062 case SPI_GETGRIDGRANULARITY:
2063 case SPI_GETKEYBOARDDELAY:
2064 case SPI_ICONVERTICALSPACING:
2067 ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2068 if (ret && lpvParam) *(INT16 *)lpvParam = tmp;
2072 case SPI_GETKEYBOARDSPEED:
2073 case SPI_GETMOUSEHOVERWIDTH:
2074 case SPI_GETMOUSEHOVERHEIGHT:
2075 case SPI_GETMOUSEHOVERTIME:
2078 ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2079 if (ret && lpvParam) *(WORD *)lpvParam = tmp;
2083 case SPI_GETICONTITLELOGFONT:
2086 ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2087 if (ret && lpvParam) logfont_32_to_16( &tmp, (LPLOGFONT16)lpvParam );
2091 case SPI_GETNONCLIENTMETRICS:
2093 NONCLIENTMETRICSA tmp;
2094 LPNONCLIENTMETRICS16 lpnm16 = (LPNONCLIENTMETRICS16)lpvParam;
2095 if (lpnm16 && lpnm16->cbSize == sizeof(NONCLIENTMETRICS16))
2097 tmp.cbSize = sizeof(NONCLIENTMETRICSA);
2098 ret = SystemParametersInfoA( uAction, uParam, &tmp, fuWinIni );
2101 lpnm16->iBorderWidth = tmp.iBorderWidth;
2102 lpnm16->iScrollWidth = tmp.iScrollWidth;
2103 lpnm16->iScrollHeight = tmp.iScrollHeight;
2104 lpnm16->iCaptionWidth = tmp.iCaptionWidth;
2105 lpnm16->iCaptionHeight = tmp.iCaptionHeight;
2106 lpnm16->iSmCaptionWidth = tmp.iSmCaptionWidth;
2107 lpnm16->iSmCaptionHeight = tmp.iSmCaptionHeight;
2108 lpnm16->iMenuWidth = tmp.iMenuWidth;
2109 lpnm16->iMenuHeight = tmp.iMenuHeight;
2110 logfont_32_to_16( &tmp.lfCaptionFont, &lpnm16->lfCaptionFont );
2111 logfont_32_to_16( &tmp.lfSmCaptionFont, &lpnm16->lfSmCaptionFont );
2112 logfont_32_to_16( &tmp.lfMenuFont, &lpnm16->lfMenuFont );
2113 logfont_32_to_16( &tmp.lfStatusFont, &lpnm16->lfStatusFont );
2114 logfont_32_to_16( &tmp.lfMessageFont, &lpnm16->lfMessageFont );
2117 else /* winfile 95 sets cbSize to 340 */
2118 ret = SystemParametersInfoA( uAction, uParam, lpvParam, fuWinIni );
2122 case SPI_GETWORKAREA:
2125 ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2126 if (ret && lpvParam)
2128 RECT16 *r16 = lpvParam;
2129 r16->left = tmp.left;
2131 r16->right = tmp.right;
2132 r16->bottom = tmp.bottom;
2138 ret = SystemParametersInfoA( uAction, uParam, lpvParam, fuWinIni );
2146 /***********************************************************************
2147 * FormatMessage (USER.606)
2149 DWORD WINAPI FormatMessage16(
2151 SEGPTR lpSource, /* [in] NOTE: not always a valid pointer */
2154 LPSTR lpBuffer, /* [out] NOTE: *((HLOCAL16*)) for FORMAT_MESSAGE_ALLOCATE_BUFFER*/
2156 LPDWORD args ) /* [in] NOTE: va_list *args */
2159 /* This implementation is completely dependent on the format of the va_list on x86 CPUs */
2163 DWORD width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK;
2165 LPSTR allocstring = NULL;
2167 TRACE("(0x%x,%x,%d,0x%x,%p,%d,%p)\n",
2168 dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args);
2169 if ((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
2170 && (dwFlags & FORMAT_MESSAGE_FROM_HMODULE)) return 0;
2171 if ((dwFlags & FORMAT_MESSAGE_FROM_STRING)
2172 &&((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
2173 || (dwFlags & FORMAT_MESSAGE_FROM_HMODULE))) return 0;
2175 if (width && width != FORMAT_MESSAGE_MAX_WIDTH_MASK)
2176 FIXME("line wrapping (%u) not supported.\n", width);
2178 if (dwFlags & FORMAT_MESSAGE_FROM_STRING)
2180 char *source = MapSL(lpSource);
2181 from = HeapAlloc( GetProcessHeap(), 0, strlen(source)+1 );
2182 strcpy( from, source );
2184 else if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) {
2185 from = HeapAlloc( GetProcessHeap(),0,200 );
2186 sprintf(from,"Systemmessage, messageid = 0x%08x\n",dwMessageId);
2188 else if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) {
2190 HINSTANCE16 hinst16 = ((HINSTANCE16)lpSource & 0xffff);
2192 dwMessageId &= 0xFFFF;
2193 bufsize=LoadString16(hinst16,dwMessageId,NULL,0);
2195 from = HeapAlloc( GetProcessHeap(), 0, bufsize +1);
2196 LoadString16(hinst16,dwMessageId,from,bufsize+1);
2199 target = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 100);
2203 #define ADD_TO_T(c) \
2205 if (t-target == talloced) {\
2206 target = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,talloced*2);\
2207 t = target+talloced;\
2213 while (*f && !eos) {
2216 char *fmtstr,*x,*lastf;
2217 DWORD *argliststart;
2227 case '1':case '2':case '3':case '4':case '5':
2228 case '6':case '7':case '8':case '9':
2231 case '0':case '1':case '2':case '3':
2232 case '4':case '5':case '6':case '7':
2235 insertnr=insertnr*10+*f-'0';
2244 if (NULL!=(x=strchr(f,'!'))) {
2246 fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2);
2247 sprintf(fmtstr,"%%%s",f);
2250 fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2);
2251 sprintf(fmtstr,"%%%s",f);
2252 f+=strlen(f); /*at \0*/
2258 fmtstr=HeapAlloc( GetProcessHeap(), 0, 3 );
2259 strcpy( fmtstr, "%s" );
2264 LPSTR b = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz = 100);
2266 argliststart=args+insertnr-1;
2268 /* CMF - This makes a BIG assumption about va_list */
2269 while ((ret = vsnprintf(b, sz, fmtstr, (va_list) argliststart) < 0) || (ret >= sz)) {
2270 sz = (ret == -1 ? sz + 100 : ret + 1);
2271 b = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, b, sz);
2273 for (x=b; *x; x++) ADD_TO_T(*x);
2274 HeapFree(GetProcessHeap(), 0, b);
2276 /* NULL args - copy formatstr
2279 while ((lastf<f)&&(*lastf)) {
2283 HeapFree(GetProcessHeap(),0,fmtstr);
2285 case '0': /* Just stop processing format string */
2289 case 'n': /* 16 bit version just outputs 'n' */
2294 } else { /* '\n' or '\r' gets mapped to "\r\n" */
2295 if(*f == '\n' || *f == '\r') {
2299 if(*f++ == '\r' && *f == '\n')
2309 talloced = strlen(target)+1;
2310 if (nSize && talloced<nSize) {
2311 target = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,nSize);
2313 TRACE("-- %s\n",debugstr_a(target));
2314 if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) {
2315 /* nSize is the MINIMUM size */
2316 HLOCAL16 h = LocalAlloc16(LPTR,talloced);
2317 SEGPTR ptr = LocalLock16(h);
2318 allocstring = MapSL( ptr );
2319 memcpy( allocstring,target,talloced);
2321 *((HLOCAL16*)lpBuffer) = h;
2323 lstrcpynA(lpBuffer,target,nSize);
2324 HeapFree(GetProcessHeap(),0,target);
2325 HeapFree(GetProcessHeap(),0,from);
2326 return (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) ?
2327 strlen(allocstring):
2331 #endif /* __i386__ */
2336 /***********************************************************************
2337 * ChangeDisplaySettings (USER.620)
2339 LONG WINAPI ChangeDisplaySettings16( LPDEVMODEA devmode, DWORD flags )
2341 return ChangeDisplaySettingsA( devmode, flags );
2345 /***********************************************************************
2346 * EnumDisplaySettings (USER.621)
2348 BOOL16 WINAPI EnumDisplaySettings16( LPCSTR name, DWORD n, LPDEVMODEA devmode )
2350 return EnumDisplaySettingsA( name, n, devmode );
2353 /**********************************************************************
2354 * DrawFrameControl (USER.656)
2356 BOOL16 WINAPI DrawFrameControl16( HDC16 hdc, LPRECT16 rc, UINT16 uType, UINT16 uState )
2361 rect32.left = rc->left;
2362 rect32.top = rc->top;
2363 rect32.right = rc->right;
2364 rect32.bottom = rc->bottom;
2365 ret = DrawFrameControl( HDC_32(hdc), &rect32, uType, uState );
2366 rc->left = rect32.left;
2367 rc->top = rect32.top;
2368 rc->right = rect32.right;
2369 rc->bottom = rect32.bottom;
2373 /**********************************************************************
2374 * DrawEdge (USER.659)
2376 BOOL16 WINAPI DrawEdge16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
2381 rect32.left = rc->left;
2382 rect32.top = rc->top;
2383 rect32.right = rc->right;
2384 rect32.bottom = rc->bottom;
2385 ret = DrawEdge( HDC_32(hdc), &rect32, edge, flags );
2386 rc->left = rect32.left;
2387 rc->top = rect32.top;
2388 rc->right = rect32.right;
2389 rc->bottom = rect32.bottom;
2393 /**********************************************************************
2394 * CheckMenuRadioItem (USER.666)
2396 BOOL16 WINAPI CheckMenuRadioItem16(HMENU16 hMenu, UINT16 first, UINT16 last,
2397 UINT16 check, BOOL16 bypos)
2399 return CheckMenuRadioItem( HMENU_32(hMenu), first, last, check, bypos );