Moved 16-bit string functions to user16.c and kbd16.c.
[wine/wine-kai.git] / dlls / user / user16.c
blob98659949dd63fde89fadb0f11a8b1162920b16ee
1 /*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <stdarg.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
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"
37 WINE_DEFAULT_DEBUG_CHANNEL(user);
39 /* handle to handle 16 conversions */
40 #define HANDLE_16(h32) (LOWORD(h32))
42 /* handle16 to handle conversions */
43 #define HANDLE_32(h16) ((HANDLE)(ULONG_PTR)(h16))
44 #define HINSTANCE_32(h16) ((HINSTANCE)(ULONG_PTR)(h16))
46 #define IS_MENU_STRING_ITEM(flags) \
47 (((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR)) == MF_STRING)
49 WORD WINAPI DestroyIcon32(HGLOBAL16, UINT16);
52 struct gray_string_info
54 GRAYSTRINGPROC16 proc;
55 LPARAM param;
56 char str[1];
59 /* callback for 16-bit gray string proc with opaque pointer */
60 static BOOL CALLBACK gray_string_callback( HDC hdc, LPARAM param, INT len )
62 const struct gray_string_info *info = (struct gray_string_info *)param;
63 WORD args[4];
64 DWORD ret;
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);
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 )
77 const struct gray_string_info *info;
78 char *str = (char *)param;
80 info = (struct gray_string_info *)(str - offsetof( struct gray_string_info, str ));
81 return gray_string_callback( hdc, (LPARAM)info, len );
84 struct draw_state_info
86 DRAWSTATEPROC16 proc;
87 LPARAM param;
90 /* callback for 16-bit DrawState functions */
91 static BOOL CALLBACK draw_state_callback( HDC hdc, LPARAM lparam, WPARAM wparam, int cx, int cy )
93 const struct draw_state_info *info = (struct draw_state_info *)lparam;
94 WORD args[6];
95 DWORD ret;
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);
108 /**********************************************************************
109 * InitApp (USER.5)
111 INT16 WINAPI InitApp16( HINSTANCE16 hInstance )
113 /* Create task message queue */
114 return (InitThreadInput16( 0, 0 ) != 0);
118 /***********************************************************************
119 * ExitWindows (USER.7)
121 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
123 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
127 /***********************************************************************
128 * ClipCursor (USER.16)
130 BOOL16 WINAPI ClipCursor16( const RECT16 *rect )
132 RECT rect32;
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 );
143 /***********************************************************************
144 * GetCursorPos (USER.17)
146 BOOL16 WINAPI GetCursorPos16( POINT16 *pt )
148 POINT pos;
149 if (!pt) return 0;
150 GetCursorPos(&pos);
151 pt->x = pos.x;
152 pt->y = pos.y;
153 return 1;
157 /***********************************************************************
158 * SetCursor (USER.69)
160 HCURSOR16 WINAPI SetCursor16(HCURSOR16 hCursor)
162 return HCURSOR_16(SetCursor(HCURSOR_32(hCursor)));
166 /***********************************************************************
167 * SetCursorPos (USER.70)
169 void WINAPI SetCursorPos16( INT16 x, INT16 y )
171 SetCursorPos( x, y );
175 /***********************************************************************
176 * ShowCursor (USER.71)
178 INT16 WINAPI ShowCursor16(BOOL16 bShow)
180 return ShowCursor(bShow);
184 /***********************************************************************
185 * SetRect (USER.72)
187 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top, INT16 right, INT16 bottom )
189 rect->left = left;
190 rect->right = right;
191 rect->top = top;
192 rect->bottom = bottom;
196 /***********************************************************************
197 * SetRectEmpty (USER.73)
199 void WINAPI SetRectEmpty16( LPRECT16 rect )
201 rect->left = rect->right = rect->top = rect->bottom = 0;
205 /***********************************************************************
206 * CopyRect (USER.74)
208 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
210 *dest = *src;
211 return TRUE;
215 /***********************************************************************
216 * IsRectEmpty (USER.75)
218 * Bug compat: Windows checks for 0 or negative width/height.
220 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
222 return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
226 /***********************************************************************
227 * PtInRect (USER.76)
229 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
231 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
232 (pt.y >= rect->top) && (pt.y < rect->bottom));
236 /***********************************************************************
237 * OffsetRect (USER.77)
239 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
241 rect->left += x;
242 rect->right += x;
243 rect->top += y;
244 rect->bottom += y;
248 /***********************************************************************
249 * InflateRect (USER.78)
251 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
253 rect->left -= x;
254 rect->top -= y;
255 rect->right += x;
256 rect->bottom += y;
260 /***********************************************************************
261 * IntersectRect (USER.79)
263 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
264 const RECT16 *src2 )
266 if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
267 (src1->left >= src2->right) || (src2->left >= src1->right) ||
268 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
270 SetRectEmpty16( dest );
271 return FALSE;
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;
281 /***********************************************************************
282 * UnionRect (USER.80)
284 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
285 const RECT16 *src2 )
287 if (IsRectEmpty16(src1))
289 if (IsRectEmpty16(src2))
291 SetRectEmpty16( dest );
292 return FALSE;
294 else *dest = *src2;
296 else
298 if (IsRectEmpty16(src2)) *dest = *src1;
299 else
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 );
307 return TRUE;
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.
318 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
320 HBRUSH prevBrush;
322 /* coordinates are logical so we cannot fast-check 'rect',
323 * it will be done later in the PatBlt().
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;
334 /***********************************************************************
335 * InvertRect (USER.82)
337 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
339 PatBlt( HDC_32(hdc), rect->left, rect->top,
340 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
344 /***********************************************************************
345 * FrameRect (USER.83)
347 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect16, HBRUSH16 hbrush )
349 RECT rect;
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) );
359 /***********************************************************************
360 * DrawIcon (USER.84)
362 BOOL16 WINAPI DrawIcon16(HDC16 hdc, INT16 x, INT16 y, HICON16 hIcon)
364 return DrawIcon(HDC_32(hdc), x, y, HICON_32(hIcon));
368 /***********************************************************************
369 * DrawText (USER.85)
371 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 count, LPRECT16 rect, UINT16 flags )
373 INT16 ret;
375 if (rect)
377 RECT rect32;
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;
389 else ret = DrawTextA( HDC_32(hdc), str, count, NULL, flags);
390 return ret;
394 /***********************************************************************
395 * IconSize (USER.86)
397 * See "Undocumented Windows". Used by W2.0 paint.exe.
399 DWORD WINAPI IconSize16(void)
401 return MAKELONG(GetSystemMetrics(SM_CYICON), GetSystemMetrics(SM_CXICON));
405 /***********************************************************************
406 * AdjustWindowRect (USER.102)
408 BOOL16 WINAPI AdjustWindowRect16( LPRECT16 rect, DWORD style, BOOL16 menu )
410 return AdjustWindowRectEx16( rect, style, menu, 0 );
414 /**************************************************************************
415 * CloseClipboard (USER.138)
417 BOOL16 WINAPI CloseClipboard16(void)
419 return CloseClipboard();
423 /**************************************************************************
424 * EmptyClipboard (USER.139)
426 BOOL16 WINAPI EmptyClipboard16(void)
428 return EmptyClipboard();
432 /**************************************************************************
433 * CountClipboardFormats (USER.143)
435 INT16 WINAPI CountClipboardFormats16(void)
437 return CountClipboardFormats();
441 /**************************************************************************
442 * EnumClipboardFormats (USER.144)
444 UINT16 WINAPI EnumClipboardFormats16( UINT16 id )
446 return EnumClipboardFormats( id );
450 /**************************************************************************
451 * RegisterClipboardFormat (USER.145)
453 UINT16 WINAPI RegisterClipboardFormat16( LPCSTR name )
455 return RegisterClipboardFormatA( name );
459 /**************************************************************************
460 * GetClipboardFormatName (USER.146)
462 INT16 WINAPI GetClipboardFormatName16( UINT16 id, LPSTR buffer, INT16 maxlen )
464 return GetClipboardFormatNameA( id, buffer, maxlen );
468 /**********************************************************************
469 * CreateMenu (USER.151)
471 HMENU16 WINAPI CreateMenu16(void)
473 return HMENU_16( CreateMenu() );
477 /**********************************************************************
478 * DestroyMenu (USER.152)
480 BOOL16 WINAPI DestroyMenu16( HMENU16 hMenu )
482 return DestroyMenu( HMENU_32(hMenu) );
486 /*******************************************************************
487 * ChangeMenu (USER.153)
489 BOOL16 WINAPI ChangeMenu16( HMENU16 hMenu, UINT16 pos, SEGPTR data,
490 UINT16 id, UINT16 flags )
492 if (flags & MF_APPEND) return AppendMenu16( hMenu, flags & ~MF_APPEND, id, data );
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?). */
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 );
507 /*******************************************************************
508 * CheckMenuItem (USER.154)
510 BOOL16 WINAPI CheckMenuItem16( HMENU16 hMenu, UINT16 id, UINT16 flags )
512 return CheckMenuItem( HMENU_32(hMenu), id, flags );
516 /**********************************************************************
517 * EnableMenuItem (USER.155)
519 UINT16 WINAPI EnableMenuItem16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
521 return EnableMenuItem( HMENU_32(hMenu), wItemID, wFlags );
525 /**********************************************************************
526 * GetSubMenu (USER.159)
528 HMENU16 WINAPI GetSubMenu16( HMENU16 hMenu, INT16 nPos )
530 return HMENU_16( GetSubMenu( HMENU_32(hMenu), nPos ) );
534 /*******************************************************************
535 * GetMenuString (USER.161)
537 INT16 WINAPI GetMenuString16( HMENU16 hMenu, UINT16 wItemID,
538 LPSTR str, INT16 nMaxSiz, UINT16 wFlags )
540 return GetMenuStringA( HMENU_32(hMenu), wItemID, str, nMaxSiz, wFlags );
544 /**********************************************************************
545 * WinHelp (USER.171)
547 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
548 DWORD dwData )
550 BOOL ret;
551 DWORD mutex_count;
553 /* We might call WinExec() */
554 ReleaseThunkLock(&mutex_count);
556 ret = WinHelpA(WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData));
558 RestoreThunkLock(mutex_count);
559 return ret;
563 /***********************************************************************
564 * LoadCursor (USER.173)
566 HCURSOR16 WINAPI LoadCursor16(HINSTANCE16 hInstance, LPCSTR name)
568 return HCURSOR_16(LoadCursorA(HINSTANCE_32(hInstance), name));
572 /***********************************************************************
573 * LoadIcon (USER.174)
575 HICON16 WINAPI LoadIcon16(HINSTANCE16 hInstance, LPCSTR name)
577 return HICON_16(LoadIconA(HINSTANCE_32(hInstance), name));
580 /**********************************************************************
581 * LoadBitmap (USER.175)
583 HBITMAP16 WINAPI LoadBitmap16(HINSTANCE16 hInstance, LPCSTR name)
585 return HBITMAP_16(LoadBitmapA(HINSTANCE_32(hInstance), name));
589 /***********************************************************************
590 * GetSystemMetrics (USER.179)
592 INT16 WINAPI GetSystemMetrics16( INT16 index )
594 return GetSystemMetrics( index );
598 /*************************************************************************
599 * GetSysColor (USER.180)
601 COLORREF WINAPI GetSysColor16( INT16 index )
603 return GetSysColor( index );
607 /*************************************************************************
608 * SetSysColors (USER.181)
610 VOID WINAPI SetSysColors16( INT16 count, const INT16 *list16, const COLORREF *values )
612 INT i, *list;
614 if ((list = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*list) )))
616 for (i = 0; i < count; i++) list[i] = list16[i];
617 SetSysColors( count, list, values );
618 HeapFree( GetProcessHeap(), 0, list );
623 /***********************************************************************
624 * GrayString (USER.185)
626 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
627 LPARAM lParam, INT16 cch, INT16 x, INT16 y,
628 INT16 cx, INT16 cy )
630 BOOL ret;
632 if (!gsprc) return GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), NULL,
633 (LPARAM)MapSL(lParam), cch, x, y, cx, cy );
635 if (cch == -1 || (cch && cx && cy))
637 /* lParam can be treated as an opaque pointer */
638 struct gray_string_info info;
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 );
645 else /* here we need some string conversions */
647 char *str16 = MapSL(lParam);
648 struct gray_string_info *info;
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 );
659 return ret;
663 /**************************************************************************
664 * IsClipboardFormatAvailable (USER.193)
666 BOOL16 WINAPI IsClipboardFormatAvailable16( UINT16 wFormat )
668 return IsClipboardFormatAvailable( wFormat );
672 /***********************************************************************
673 * TabbedTextOut (USER.196)
675 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
676 INT16 count, INT16 nb_tabs, const INT16 *tabs16, INT16 tab_org )
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;
688 /***********************************************************************
689 * GetTabbedTextExtent (USER.197)
691 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
692 INT16 nb_tabs, const INT16 *tabs16 )
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;
704 /*************************************************************************
705 * ScrollDC (USER.221)
707 BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
708 const RECT16 *cliprc, HRGN16 hrgnUpdate,
709 LPRECT16 rcUpdate )
711 RECT rect32, clipRect32, rcUpdate32;
712 BOOL16 ret;
714 if (rect)
716 rect32.left = rect->left;
717 rect32.top = rect->top;
718 rect32.right = rect->right;
719 rect32.bottom = rect->bottom;
721 if (cliprc)
723 clipRect32.left = cliprc->left;
724 clipRect32.top = cliprc->top;
725 clipRect32.right = cliprc->right;
726 clipRect32.bottom = cliprc->bottom;
728 ret = ScrollDC( HDC_32(hdc), dx, dy, rect ? &rect32 : NULL,
729 cliprc ? &clipRect32 : NULL, HRGN_32(hrgnUpdate),
730 &rcUpdate32 );
731 if (rcUpdate)
733 rcUpdate->left = rcUpdate32.left;
734 rcUpdate->top = rcUpdate32.top;
735 rcUpdate->right = rcUpdate32.right;
736 rcUpdate->bottom = rcUpdate32.bottom;
738 return ret;
742 /***********************************************************************
743 * GetSystemDebugState (USER.231)
745 WORD WINAPI GetSystemDebugState16(void)
747 return 0; /* FIXME */
751 /***********************************************************************
752 * EqualRect (USER.244)
754 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
756 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
757 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
761 /***********************************************************************
762 * ExitWindowsExec (USER.246)
764 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
766 TRACE("Should run the following in DOS-mode: \"%s %s\"\n",
767 lpszExe, lpszParams);
768 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
772 /***********************************************************************
773 * GetCursor (USER.247)
775 HCURSOR16 WINAPI GetCursor16(void)
777 return HCURSOR_16(GetCursor());
781 /**********************************************************************
782 * GetAsyncKeyState (USER.249)
784 INT16 WINAPI GetAsyncKeyState16( INT16 key )
786 return GetAsyncKeyState( key );
790 /**********************************************************************
791 * GetMenuState (USER.250)
793 UINT16 WINAPI GetMenuState16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
795 return GetMenuState( HMENU_32(hMenu), wItemID, wFlags );
799 /**********************************************************************
800 * GetMenuItemCount (USER.263)
802 INT16 WINAPI GetMenuItemCount16( HMENU16 hMenu )
804 return GetMenuItemCount( HMENU_32(hMenu) );
808 /**********************************************************************
809 * GetMenuItemID (USER.264)
811 UINT16 WINAPI GetMenuItemID16( HMENU16 hMenu, INT16 nPos )
813 return GetMenuItemID( HMENU_32(hMenu), nPos );
817 /***********************************************************************
818 * GlobalAddAtom (USER.268)
820 ATOM WINAPI GlobalAddAtom16(LPCSTR lpString)
822 return GlobalAddAtomA(lpString);
825 /***********************************************************************
826 * GlobalDeleteAtom (USER.269)
828 ATOM WINAPI GlobalDeleteAtom16(ATOM nAtom)
830 return GlobalDeleteAtom(nAtom);
833 /***********************************************************************
834 * GlobalFindAtom (USER.270)
836 ATOM WINAPI GlobalFindAtom16(LPCSTR lpString)
838 return GlobalFindAtomA(lpString);
841 /***********************************************************************
842 * GlobalGetAtomName (USER.271)
844 UINT16 WINAPI GlobalGetAtomName16(ATOM nAtom, LPSTR lpBuffer, INT16 nSize)
846 return GlobalGetAtomNameA(nAtom, lpBuffer, nSize);
850 /***********************************************************************
851 * GetSysColorBrush (USER.281)
853 HBRUSH16 WINAPI GetSysColorBrush16( INT16 index )
855 return HBRUSH_16( GetSysColorBrush(index) );
859 /***********************************************************************
860 * SelectPalette (USER.282)
862 HPALETTE16 WINAPI SelectPalette16( HDC16 hdc, HPALETTE16 hpal, BOOL16 bForceBackground )
864 return HPALETTE_16( SelectPalette( HDC_32(hdc), HPALETTE_32(hpal), bForceBackground ));
867 /***********************************************************************
868 * RealizePalette (USER.283)
870 UINT16 WINAPI RealizePalette16( HDC16 hdc )
872 return UserRealizePalette( HDC_32(hdc) );
876 /***********************************************************************
877 * GetClipCursor (USER.309)
879 void WINAPI GetClipCursor16( RECT16 *rect )
881 if (rect)
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;
893 /***********************************************************************
894 * SignalProc (USER.314)
896 void WINAPI SignalProc16( HANDLE16 hModule, UINT16 code,
897 UINT16 uExitFn, HINSTANCE16 hInstance, HQUEUE16 hQueue )
899 if (code == USIG16_DLL_UNLOAD)
901 /* HOOK_FreeModuleHooks( hModule ); */
902 CLASS_FreeModuleClasses( hModule );
903 CURSORICON_FreeModuleIcons( hModule );
908 /***********************************************************************
909 * SetEventHook (USER.321)
911 * Used by Turbo Debugger for Windows
913 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
915 FIXME("(lpfnEventHook=%p): stub\n", lpfnEventHook);
916 return 0;
920 /**********************************************************************
921 * EnableHardwareInput (USER.331)
923 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
925 FIXME("(%d) - stub\n", bEnable);
926 return TRUE;
930 /***********************************************************************
931 * IsUserIdle (USER.333)
933 BOOL16 WINAPI IsUserIdle16(void)
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;
946 /**********************************************************************
947 * IsMenu (USER.358)
949 BOOL16 WINAPI IsMenu16( HMENU16 hmenu )
951 return IsMenu( HMENU_32(hmenu) );
955 /***********************************************************************
956 * DCHook (USER.362)
958 BOOL16 WINAPI DCHook16( HDC16 hdc, WORD code, DWORD data, LPARAM lParam )
960 FIXME( "hDC = %x, %i: stub\n", hdc, code );
961 return FALSE;
965 /***********************************************************************
966 * SubtractRect (USER.373)
968 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
969 const RECT16 *src2 )
971 RECT16 tmp;
973 if (IsRectEmpty16( src1 ))
975 SetRectEmpty16( dest );
976 return FALSE;
978 *dest = *src1;
979 if (IntersectRect16( &tmp, src1, src2 ))
981 if (EqualRect16( &tmp, dest ))
983 SetRectEmpty16( dest );
984 return FALSE;
986 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
988 if (tmp.left == dest->left) dest->left = tmp.right;
989 else if (tmp.right == dest->right) dest->right = tmp.left;
991 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
993 if (tmp.top == dest->top) dest->top = tmp.bottom;
994 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
997 return TRUE;
1001 /**********************************************************************
1002 * SetMenuContextHelpId (USER.384)
1004 BOOL16 WINAPI SetMenuContextHelpId16( HMENU16 hMenu, DWORD dwContextHelpID)
1006 return SetMenuContextHelpId( HMENU_32(hMenu), dwContextHelpID );
1010 /**********************************************************************
1011 * GetMenuContextHelpId (USER.385)
1013 DWORD WINAPI GetMenuContextHelpId16( HMENU16 hMenu )
1015 return GetMenuContextHelpId( HMENU_32(hMenu) );
1019 /***********************************************************************
1020 * LoadImage (USER.389)
1023 HANDLE16 WINAPI LoadImage16(HINSTANCE16 hinst, LPCSTR name, UINT16 type,
1024 INT16 desiredx, INT16 desiredy, UINT16 loadflags)
1026 return HANDLE_16(LoadImageA(HINSTANCE_32(hinst), name, type, desiredx,
1027 desiredy, loadflags));
1030 /******************************************************************************
1031 * CopyImage (USER.390) Creates new image and copies attributes to it
1034 HICON16 WINAPI CopyImage16(HANDLE16 hnd, UINT16 type, INT16 desiredx,
1035 INT16 desiredy, UINT16 flags)
1037 return HICON_16(CopyImage(HANDLE_32(hnd), (UINT)type, (INT)desiredx,
1038 (INT)desiredy, (UINT)flags));
1041 /**********************************************************************
1042 * DrawIconEx (USER.394)
1044 BOOL16 WINAPI DrawIconEx16(HDC16 hdc, INT16 xLeft, INT16 yTop, HICON16 hIcon,
1045 INT16 cxWidth, INT16 cyWidth, UINT16 istep,
1046 HBRUSH16 hbr, UINT16 flags)
1048 return DrawIconEx(HDC_32(hdc), xLeft, yTop, HICON_32(hIcon), cxWidth, cyWidth,
1049 istep, HBRUSH_32(hbr), flags);
1052 /**********************************************************************
1053 * GetIconInfo (USER.395)
1055 BOOL16 WINAPI GetIconInfo16(HICON16 hIcon, LPICONINFO16 iconinfo)
1057 ICONINFO ii32;
1058 BOOL16 ret = GetIconInfo(HICON_32(hIcon), &ii32);
1060 iconinfo->fIcon = ii32.fIcon;
1061 iconinfo->xHotspot = ii32.xHotspot;
1062 iconinfo->yHotspot = ii32.yHotspot;
1063 iconinfo->hbmMask = HBITMAP_16(ii32.hbmMask);
1064 iconinfo->hbmColor = HBITMAP_16(ii32.hbmColor);
1065 return ret;
1069 /***********************************************************************
1070 * FinalUserInit (USER.400)
1072 void WINAPI FinalUserInit16( void )
1074 /* FIXME: Should chain to FinalGdiInit */
1078 /***********************************************************************
1079 * CreateCursor (USER.406)
1081 HCURSOR16 WINAPI CreateCursor16(HINSTANCE16 hInstance,
1082 INT16 xHotSpot, INT16 yHotSpot,
1083 INT16 nWidth, INT16 nHeight,
1084 LPCVOID lpANDbits, LPCVOID lpXORbits)
1086 CURSORICONINFO info;
1088 info.ptHotSpot.x = xHotSpot;
1089 info.ptHotSpot.y = yHotSpot;
1090 info.nWidth = nWidth;
1091 info.nHeight = nHeight;
1092 info.nWidthBytes = 0;
1093 info.bPlanes = 1;
1094 info.bBitsPerPixel = 1;
1096 return CreateCursorIconIndirect16(hInstance, &info, lpANDbits, lpXORbits);
1100 /*******************************************************************
1101 * InsertMenu (USER.410)
1103 BOOL16 WINAPI InsertMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
1104 UINT16 id, SEGPTR data )
1106 UINT pos32 = (UINT)pos;
1107 if ((pos == (UINT16)-1) && (flags & MF_BYPOSITION)) pos32 = (UINT)-1;
1108 if (IS_MENU_STRING_ITEM(flags) && data)
1109 return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, MapSL(data) );
1110 return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, (LPSTR)data );
1114 /*******************************************************************
1115 * AppendMenu (USER.411)
1117 BOOL16 WINAPI AppendMenu16(HMENU16 hMenu, UINT16 flags, UINT16 id, SEGPTR data)
1119 return InsertMenu16( hMenu, -1, flags | MF_BYPOSITION, id, data );
1123 /**********************************************************************
1124 * RemoveMenu (USER.412)
1126 BOOL16 WINAPI RemoveMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
1128 return RemoveMenu( HMENU_32(hMenu), nPos, wFlags );
1132 /**********************************************************************
1133 * DeleteMenu (USER.413)
1135 BOOL16 WINAPI DeleteMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
1137 return DeleteMenu( HMENU_32(hMenu), nPos, wFlags );
1141 /*******************************************************************
1142 * ModifyMenu (USER.414)
1144 BOOL16 WINAPI ModifyMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
1145 UINT16 id, SEGPTR data )
1147 if (IS_MENU_STRING_ITEM(flags))
1148 return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, MapSL(data) );
1149 return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, (LPSTR)data );
1153 /**********************************************************************
1154 * CreatePopupMenu (USER.415)
1156 HMENU16 WINAPI CreatePopupMenu16(void)
1158 return HMENU_16( CreatePopupMenu() );
1162 /**********************************************************************
1163 * SetMenuItemBitmaps (USER.418)
1165 BOOL16 WINAPI SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags,
1166 HBITMAP16 hNewUnCheck, HBITMAP16 hNewCheck)
1168 return SetMenuItemBitmaps( HMENU_32(hMenu), nPos, wFlags,
1169 HBITMAP_32(hNewUnCheck), HBITMAP_32(hNewCheck) );
1173 /***********************************************************************
1174 * lstrcmp (USER.430)
1176 INT16 WINAPI lstrcmp16( LPCSTR str1, LPCSTR str2 )
1178 return strcmp( str1, str2 );
1182 /***********************************************************************
1183 * AnsiUpper (USER.431)
1185 SEGPTR WINAPI AnsiUpper16( SEGPTR strOrChar )
1187 /* uppercase only one char if strOrChar < 0x10000 */
1188 if (HIWORD(strOrChar))
1190 CharUpperA( MapSL(strOrChar) );
1191 return strOrChar;
1193 else return (SEGPTR)CharUpperA( (LPSTR)strOrChar );
1197 /***********************************************************************
1198 * AnsiLower (USER.432)
1200 SEGPTR WINAPI AnsiLower16( SEGPTR strOrChar )
1202 /* lowercase only one char if strOrChar < 0x10000 */
1203 if (HIWORD(strOrChar))
1205 CharLowerA( MapSL(strOrChar) );
1206 return strOrChar;
1208 else return (SEGPTR)CharLowerA( (LPSTR)strOrChar );
1212 /***********************************************************************
1213 * AnsiUpperBuff (USER.437)
1215 UINT16 WINAPI AnsiUpperBuff16( LPSTR str, UINT16 len )
1217 CharUpperBuffA( str, len ? len : 65536 );
1218 return len;
1222 /***********************************************************************
1223 * AnsiLowerBuff (USER.438)
1225 UINT16 WINAPI AnsiLowerBuff16( LPSTR str, UINT16 len )
1227 CharLowerBuffA( str, len ? len : 65536 );
1228 return len;
1232 /*******************************************************************
1233 * InsertMenuItem (USER.441)
1235 * FIXME: untested
1237 BOOL16 WINAPI InsertMenuItem16( HMENU16 hmenu, UINT16 pos, BOOL16 byposition,
1238 const MENUITEMINFO16 *mii )
1240 MENUITEMINFOA miia;
1242 miia.cbSize = sizeof(miia);
1243 miia.fMask = mii->fMask;
1244 miia.dwTypeData = (LPSTR)mii->dwTypeData;
1245 miia.fType = mii->fType;
1246 miia.fState = mii->fState;
1247 miia.wID = mii->wID;
1248 miia.hSubMenu = HMENU_32(mii->hSubMenu);
1249 miia.hbmpChecked = HBITMAP_32(mii->hbmpChecked);
1250 miia.hbmpUnchecked = HBITMAP_32(mii->hbmpUnchecked);
1251 miia.dwItemData = mii->dwItemData;
1252 miia.cch = mii->cch;
1253 if (IS_MENU_STRING_ITEM(miia.fType))
1254 miia.dwTypeData = MapSL(mii->dwTypeData);
1255 return InsertMenuItemA( HMENU_32(hmenu), pos, byposition, &miia );
1259 /**********************************************************************
1260 * DrawState (USER.449)
1262 BOOL16 WINAPI DrawState16( HDC16 hdc, HBRUSH16 hbr, DRAWSTATEPROC16 func, LPARAM ldata,
1263 WPARAM16 wdata, INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags )
1265 struct draw_state_info info;
1266 UINT opcode = flags & 0xf;
1268 if (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)
1270 /* make sure DrawStateA doesn't try to use ldata as a pointer */
1271 if (!wdata) wdata = strlen( MapSL(ldata) );
1272 if (!cx || !cy)
1274 SIZE s;
1275 if (!GetTextExtentPoint32A( HDC_32(hdc), MapSL(ldata), wdata, &s )) return FALSE;
1276 if (!cx) cx = s.cx;
1277 if (!cy) cy = s.cy;
1280 info.proc = func;
1281 info.param = ldata;
1282 return DrawStateA( HDC_32(hdc), HBRUSH_32(hbr), draw_state_callback,
1283 (LPARAM)&info, wdata, x, y, cx, cy, flags );
1287 /**********************************************************************
1288 * CreateIconFromResourceEx (USER.450)
1290 * FIXME: not sure about exact parameter types
1292 HICON16 WINAPI CreateIconFromResourceEx16(LPBYTE bits, UINT16 cbSize,
1293 BOOL16 bIcon, DWORD dwVersion,
1294 INT16 width, INT16 height,
1295 UINT16 cFlag)
1297 return HICON_16(CreateIconFromResourceEx(bits, cbSize, bIcon, dwVersion,
1298 width, height, cFlag));
1302 /***********************************************************************
1303 * AdjustWindowRectEx (USER.454)
1305 BOOL16 WINAPI AdjustWindowRectEx16( LPRECT16 rect, DWORD style, BOOL16 menu, DWORD exStyle )
1307 RECT rect32;
1308 BOOL ret;
1310 rect32.left = rect->left;
1311 rect32.top = rect->top;
1312 rect32.right = rect->right;
1313 rect32.bottom = rect->bottom;
1314 ret = AdjustWindowRectEx( &rect32, style, menu, exStyle );
1315 rect->left = rect32.left;
1316 rect->top = rect32.top;
1317 rect->right = rect32.right;
1318 rect->bottom = rect32.bottom;
1319 return ret;
1323 /***********************************************************************
1324 * DestroyIcon (USER.457)
1326 BOOL16 WINAPI DestroyIcon16(HICON16 hIcon)
1328 return DestroyIcon32(hIcon, 0);
1331 /***********************************************************************
1332 * DestroyCursor (USER.458)
1334 BOOL16 WINAPI DestroyCursor16(HCURSOR16 hCursor)
1336 return DestroyIcon32(hCursor, 0);
1339 /*******************************************************************
1340 * DRAG_QueryUpdate16
1342 * Recursively find a child that contains spDragInfo->pt point
1343 * and send WM_QUERYDROPOBJECT. Helper for DragObject16.
1345 static BOOL DRAG_QueryUpdate16( HWND hQueryWnd, SEGPTR spDragInfo )
1347 BOOL bResult = 0;
1348 WPARAM wParam;
1349 POINT pt, old_pt;
1350 LPDRAGINFO16 ptrDragInfo = MapSL(spDragInfo);
1351 RECT tempRect;
1352 HWND child;
1354 if (!IsWindowEnabled(hQueryWnd)) return FALSE;
1356 old_pt.x = ptrDragInfo->pt.x;
1357 old_pt.y = ptrDragInfo->pt.y;
1358 pt = old_pt;
1359 ScreenToClient( hQueryWnd, &pt );
1360 child = ChildWindowFromPointEx( hQueryWnd, pt, CWP_SKIPINVISIBLE );
1361 if (!child) return FALSE;
1363 if (child != hQueryWnd)
1365 wParam = 0;
1366 if (DRAG_QueryUpdate16( child, spDragInfo )) return TRUE;
1368 else
1370 GetClientRect( hQueryWnd, &tempRect );
1371 wParam = !PtInRect( &tempRect, pt );
1374 ptrDragInfo->pt.x = pt.x;
1375 ptrDragInfo->pt.y = pt.y;
1376 ptrDragInfo->hScope = HWND_16(hQueryWnd);
1378 bResult = SendMessage16( HWND_16(hQueryWnd), WM_QUERYDROPOBJECT, wParam, spDragInfo );
1380 if (!bResult)
1382 ptrDragInfo->pt.x = old_pt.x;
1383 ptrDragInfo->pt.y = old_pt.y;
1385 return bResult;
1389 /******************************************************************************
1390 * DragObject (USER.464)
1392 DWORD WINAPI DragObject16( HWND16 hwndScope, HWND16 hWnd, UINT16 wObj,
1393 HANDLE16 hOfStruct, WORD szList, HCURSOR16 hCursor )
1395 MSG msg;
1396 LPDRAGINFO16 lpDragInfo;
1397 SEGPTR spDragInfo;
1398 HCURSOR hOldCursor=0, hBummer=0;
1399 HGLOBAL16 hDragInfo = GlobalAlloc16( GMEM_SHARE | GMEM_ZEROINIT, 2*sizeof(DRAGINFO16));
1400 HCURSOR hCurrentCursor = 0;
1401 HWND16 hCurrentWnd = 0;
1403 lpDragInfo = (LPDRAGINFO16) GlobalLock16(hDragInfo);
1404 spDragInfo = K32WOWGlobalLock16(hDragInfo);
1406 if( !lpDragInfo || !spDragInfo ) return 0L;
1408 if (!(hBummer = LoadCursorA(0, MAKEINTRESOURCEA(OCR_NO))))
1410 GlobalFree16(hDragInfo);
1411 return 0L;
1414 if(hCursor) hOldCursor = SetCursor(HCURSOR_32(hCursor));
1416 lpDragInfo->hWnd = hWnd;
1417 lpDragInfo->hScope = 0;
1418 lpDragInfo->wFlags = wObj;
1419 lpDragInfo->hList = szList; /* near pointer! */
1420 lpDragInfo->hOfStruct = hOfStruct;
1421 lpDragInfo->l = 0L;
1423 SetCapture( HWND_32(hWnd) );
1424 ShowCursor( TRUE );
1428 GetMessageW( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST );
1430 *(lpDragInfo+1) = *lpDragInfo;
1432 lpDragInfo->pt.x = msg.pt.x;
1433 lpDragInfo->pt.y = msg.pt.y;
1435 /* update DRAGINFO struct */
1436 if( DRAG_QueryUpdate16(WIN_Handle32(hwndScope), spDragInfo) > 0 )
1437 hCurrentCursor = HCURSOR_32(hCursor);
1438 else
1440 hCurrentCursor = hBummer;
1441 lpDragInfo->hScope = 0;
1443 if( hCurrentCursor )
1444 SetCursor(hCurrentCursor);
1446 /* send WM_DRAGLOOP */
1447 SendMessage16( hWnd, WM_DRAGLOOP, (WPARAM16)(hCurrentCursor != hBummer),
1448 (LPARAM) spDragInfo );
1449 /* send WM_DRAGSELECT or WM_DRAGMOVE */
1450 if( hCurrentWnd != lpDragInfo->hScope )
1452 if( hCurrentWnd )
1453 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 0,
1454 (LPARAM)MAKELONG(LOWORD(spDragInfo)+sizeof(DRAGINFO16),
1455 HIWORD(spDragInfo)) );
1456 hCurrentWnd = lpDragInfo->hScope;
1457 if( hCurrentWnd )
1458 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 1, (LPARAM)spDragInfo);
1460 else
1461 if( hCurrentWnd )
1462 SendMessage16( hCurrentWnd, WM_DRAGMOVE, 0, (LPARAM)spDragInfo);
1464 } while( msg.message != WM_LBUTTONUP && msg.message != WM_NCLBUTTONUP );
1466 ReleaseCapture();
1467 ShowCursor( FALSE );
1469 if( hCursor ) SetCursor(hOldCursor);
1471 if( hCurrentCursor != hBummer )
1472 msg.lParam = SendMessage16( lpDragInfo->hScope, WM_DROPOBJECT,
1473 (WPARAM16)hWnd, (LPARAM)spDragInfo );
1474 else
1475 msg.lParam = 0;
1476 GlobalFree16(hDragInfo);
1478 return (DWORD)(msg.lParam);
1482 /***********************************************************************
1483 * DrawFocusRect (USER.466)
1485 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
1487 RECT rect32;
1489 rect32.left = rc->left;
1490 rect32.top = rc->top;
1491 rect32.right = rc->right;
1492 rect32.bottom = rc->bottom;
1493 DrawFocusRect( HDC_32(hdc), &rect32 );
1497 /***********************************************************************
1498 * AnsiNext (USER.472)
1500 SEGPTR WINAPI AnsiNext16(SEGPTR current)
1502 char *ptr = MapSL(current);
1503 return current + (CharNextA(ptr) - ptr);
1507 /***********************************************************************
1508 * AnsiPrev (USER.473)
1510 SEGPTR WINAPI AnsiPrev16( LPCSTR start, SEGPTR current )
1512 char *ptr = MapSL(current);
1513 return current - (ptr - CharPrevA( start, ptr ));
1517 /***********************************************************************
1518 * FormatMessage (USER.606)
1520 DWORD WINAPI FormatMessage16(
1521 DWORD dwFlags,
1522 SEGPTR lpSource, /* [in] NOTE: not always a valid pointer */
1523 WORD dwMessageId,
1524 WORD dwLanguageId,
1525 LPSTR lpBuffer, /* [out] NOTE: *((HLOCAL16*)) for FORMAT_MESSAGE_ALLOCATE_BUFFER*/
1526 WORD nSize,
1527 LPDWORD args ) /* [in] NOTE: va_list *args */
1529 #ifdef __i386__
1530 /* This implementation is completely dependent on the format of the va_list on x86 CPUs */
1531 LPSTR target,t;
1532 DWORD talloced;
1533 LPSTR from,f;
1534 DWORD width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK;
1535 BOOL eos = FALSE;
1536 LPSTR allocstring = NULL;
1538 TRACE("(0x%lx,%lx,%d,0x%x,%p,%d,%p)\n",
1539 dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args);
1540 if ((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
1541 && (dwFlags & FORMAT_MESSAGE_FROM_HMODULE)) return 0;
1542 if ((dwFlags & FORMAT_MESSAGE_FROM_STRING)
1543 &&((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
1544 || (dwFlags & FORMAT_MESSAGE_FROM_HMODULE))) return 0;
1546 if (width && width != FORMAT_MESSAGE_MAX_WIDTH_MASK)
1547 FIXME("line wrapping (%lu) not supported.\n", width);
1548 from = NULL;
1549 if (dwFlags & FORMAT_MESSAGE_FROM_STRING)
1551 char *source = MapSL(lpSource);
1552 from = HeapAlloc( GetProcessHeap(), 0, strlen(source)+1 );
1553 strcpy( from, source );
1555 else if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) {
1556 from = HeapAlloc( GetProcessHeap(),0,200 );
1557 sprintf(from,"Systemmessage, messageid = 0x%08x\n",dwMessageId);
1559 else if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) {
1560 INT16 bufsize;
1561 HINSTANCE16 hinst16 = ((HINSTANCE16)lpSource & 0xffff);
1563 dwMessageId &= 0xFFFF;
1564 bufsize=LoadString16(hinst16,dwMessageId,NULL,0);
1565 if (bufsize) {
1566 from = HeapAlloc( GetProcessHeap(), 0, bufsize +1);
1567 LoadString16(hinst16,dwMessageId,from,bufsize+1);
1570 target = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 100);
1571 t = target;
1572 talloced= 100;
1574 #define ADD_TO_T(c) \
1575 *t++=c;\
1576 if (t-target == talloced) {\
1577 target = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,talloced*2);\
1578 t = target+talloced;\
1579 talloced*=2;\
1582 if (from) {
1583 f=from;
1584 while (*f && !eos) {
1585 if (*f=='%') {
1586 int insertnr;
1587 char *fmtstr,*x,*lastf;
1588 DWORD *argliststart;
1590 fmtstr = NULL;
1591 lastf = f;
1592 f++;
1593 if (!*f) {
1594 ADD_TO_T('%');
1595 continue;
1597 switch (*f) {
1598 case '1':case '2':case '3':case '4':case '5':
1599 case '6':case '7':case '8':case '9':
1600 insertnr=*f-'0';
1601 switch (f[1]) {
1602 case '0':case '1':case '2':case '3':
1603 case '4':case '5':case '6':case '7':
1604 case '8':case '9':
1605 f++;
1606 insertnr=insertnr*10+*f-'0';
1607 f++;
1608 break;
1609 default:
1610 f++;
1611 break;
1613 if (*f=='!') {
1614 f++;
1615 if (NULL!=(x=strchr(f,'!'))) {
1616 *x='\0';
1617 fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2);
1618 sprintf(fmtstr,"%%%s",f);
1619 f=x+1;
1620 } else {
1621 fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2);
1622 sprintf(fmtstr,"%%%s",f);
1623 f+=strlen(f); /*at \0*/
1626 else
1628 if(!args) break;
1629 fmtstr=HeapAlloc( GetProcessHeap(), 0, 3 );
1630 strcpy( fmtstr, "%s" );
1632 if (args) {
1633 int ret;
1634 int sz;
1635 LPSTR b = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz = 100);
1637 argliststart=args+insertnr-1;
1639 /* CMF - This makes a BIG assumption about va_list */
1640 while ((ret = vsnprintf(b, sz, fmtstr, (va_list) argliststart) < 0) || (ret >= sz)) {
1641 sz = (ret == -1 ? sz + 100 : ret + 1);
1642 b = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, b, sz);
1644 for (x=b; *x; x++) ADD_TO_T(*x);
1645 HeapFree(GetProcessHeap(), 0, b);
1646 } else {
1647 /* NULL args - copy formatstr
1648 * (probably wrong)
1650 while ((lastf<f)&&(*lastf)) {
1651 ADD_TO_T(*lastf++);
1654 HeapFree(GetProcessHeap(),0,fmtstr);
1655 break;
1656 case '0': /* Just stop processing format string */
1657 eos = TRUE;
1658 f++;
1659 break;
1660 case 'n': /* 16 bit version just outputs 'n' */
1661 default:
1662 ADD_TO_T(*f++);
1663 break;
1665 } else { /* '\n' or '\r' gets mapped to "\r\n" */
1666 if(*f == '\n' || *f == '\r') {
1667 if (width == 0) {
1668 ADD_TO_T('\r');
1669 ADD_TO_T('\n');
1670 if(*f++ == '\r' && *f == '\n')
1671 f++;
1673 } else {
1674 ADD_TO_T(*f++);
1678 *t='\0';
1680 talloced = strlen(target)+1;
1681 if (nSize && talloced<nSize) {
1682 target = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,nSize);
1684 TRACE("-- %s\n",debugstr_a(target));
1685 if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) {
1686 /* nSize is the MINIMUM size */
1687 HLOCAL16 h = LocalAlloc16(LPTR,talloced);
1688 SEGPTR ptr = LocalLock16(h);
1689 allocstring = MapSL( ptr );
1690 memcpy( allocstring,target,talloced);
1691 LocalUnlock16( h );
1692 *((HLOCAL16*)lpBuffer) = h;
1693 } else
1694 lstrcpynA(lpBuffer,target,nSize);
1695 HeapFree(GetProcessHeap(),0,target);
1696 HeapFree(GetProcessHeap(),0,from);
1697 return (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) ?
1698 strlen(allocstring):
1699 strlen(lpBuffer);
1700 #else
1701 return 0;
1702 #endif /* __i386__ */
1704 #undef ADD_TO_T
1707 /***********************************************************************
1708 * ChangeDisplaySettings (USER.620)
1710 LONG WINAPI ChangeDisplaySettings16( LPDEVMODEA devmode, DWORD flags )
1712 return ChangeDisplaySettingsA( devmode, flags );
1716 /***********************************************************************
1717 * EnumDisplaySettings (USER.621)
1719 BOOL16 WINAPI EnumDisplaySettings16( LPCSTR name, DWORD n, LPDEVMODEA devmode )
1721 return EnumDisplaySettingsA( name, n, devmode );
1724 /**********************************************************************
1725 * DrawFrameControl (USER.656)
1727 BOOL16 WINAPI DrawFrameControl16( HDC16 hdc, LPRECT16 rc, UINT16 uType, UINT16 uState )
1729 RECT rect32;
1730 BOOL ret;
1732 rect32.left = rc->left;
1733 rect32.top = rc->top;
1734 rect32.right = rc->right;
1735 rect32.bottom = rc->bottom;
1736 ret = DrawFrameControl( HDC_32(hdc), &rect32, uType, uState );
1737 rc->left = rect32.left;
1738 rc->top = rect32.top;
1739 rc->right = rect32.right;
1740 rc->bottom = rect32.bottom;
1741 return ret;
1744 /**********************************************************************
1745 * DrawEdge (USER.659)
1747 BOOL16 WINAPI DrawEdge16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
1749 RECT rect32;
1750 BOOL ret;
1752 rect32.left = rc->left;
1753 rect32.top = rc->top;
1754 rect32.right = rc->right;
1755 rect32.bottom = rc->bottom;
1756 ret = DrawEdge( HDC_32(hdc), &rect32, edge, flags );
1757 rc->left = rect32.left;
1758 rc->top = rect32.top;
1759 rc->right = rect32.right;
1760 rc->bottom = rect32.bottom;
1761 return ret;
1764 /**********************************************************************
1765 * CheckMenuRadioItem (USER.666)
1767 BOOL16 WINAPI CheckMenuRadioItem16(HMENU16 hMenu, UINT16 first, UINT16 last,
1768 UINT16 check, BOOL16 bypos)
1770 return CheckMenuRadioItem( HMENU_32(hMenu), first, last, check, bypos );