gdi32: Add a partial implementation of GdiRealizationInfo.
[wine/hacks.git] / dlls / user32 / user16.c
blobb55c8ed1c979ae2a7f635709a8fac4d3f23fa816
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdarg.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
27 #define OEMRESOURCE
29 #include "wine/winuser16.h"
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wownt32.h"
33 #include "user_private.h"
34 #include "win.h"
35 #include "controls.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);
60 struct gray_string_info
62 GRAYSTRINGPROC16 proc;
63 LPARAM param;
64 char str[1];
67 /* callback for 16-bit gray string proc with opaque pointer */
68 static BOOL CALLBACK gray_string_callback( HDC hdc, LPARAM param, INT len )
70 const struct gray_string_info *info = (struct gray_string_info *)param;
71 WORD args[4];
72 DWORD ret;
74 args[3] = HDC_16(hdc);
75 args[2] = HIWORD(info->param);
76 args[1] = LOWORD(info->param);
77 args[0] = len;
78 WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
79 return LOWORD(ret);
82 /* callback for 16-bit gray string proc with string pointer */
83 static BOOL CALLBACK gray_string_callback_ptr( HDC hdc, LPARAM param, INT len )
85 const struct gray_string_info *info;
86 char *str = (char *)param;
88 info = (struct gray_string_info *)(str - offsetof( struct gray_string_info, str ));
89 return gray_string_callback( hdc, (LPARAM)info, len );
92 struct draw_state_info
94 DRAWSTATEPROC16 proc;
95 LPARAM param;
98 /* callback for 16-bit DrawState functions */
99 static BOOL CALLBACK draw_state_callback( HDC hdc, LPARAM lparam, WPARAM wparam, int cx, int cy )
101 const struct draw_state_info *info = (struct draw_state_info *)lparam;
102 WORD args[6];
103 DWORD ret;
105 args[5] = HDC_16(hdc);
106 args[4] = HIWORD(info->param);
107 args[3] = LOWORD(info->param);
108 args[2] = wparam;
109 args[1] = cx;
110 args[0] = cy;
111 WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
112 return LOWORD(ret);
116 /**********************************************************************
117 * InitApp (USER.5)
119 INT16 WINAPI InitApp16( HINSTANCE16 hInstance )
121 /* Create task message queue */
122 return (InitThreadInput16( 0, 0 ) != 0);
126 /***********************************************************************
127 * ExitWindows (USER.7)
129 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
131 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
135 /***********************************************************************
136 * GetTimerResolution (USER.14)
138 LONG WINAPI GetTimerResolution16(void)
140 return (1000);
144 /***********************************************************************
145 * ClipCursor (USER.16)
147 BOOL16 WINAPI ClipCursor16( const RECT16 *rect )
149 RECT rect32;
151 if (!rect) return ClipCursor( NULL );
152 rect32.left = rect->left;
153 rect32.top = rect->top;
154 rect32.right = rect->right;
155 rect32.bottom = rect->bottom;
156 return ClipCursor( &rect32 );
160 /***********************************************************************
161 * GetCursorPos (USER.17)
163 BOOL16 WINAPI GetCursorPos16( POINT16 *pt )
165 POINT pos;
166 if (!pt) return 0;
167 GetCursorPos(&pos);
168 pt->x = pos.x;
169 pt->y = pos.y;
170 return 1;
174 /***********************************************************************
175 * SetCursor (USER.69)
177 HCURSOR16 WINAPI SetCursor16(HCURSOR16 hCursor)
179 return HCURSOR_16(SetCursor(HCURSOR_32(hCursor)));
183 /***********************************************************************
184 * SetCursorPos (USER.70)
186 void WINAPI SetCursorPos16( INT16 x, INT16 y )
188 SetCursorPos( x, y );
192 /***********************************************************************
193 * ShowCursor (USER.71)
195 INT16 WINAPI ShowCursor16(BOOL16 bShow)
197 return ShowCursor(bShow);
201 /***********************************************************************
202 * SetRect (USER.72)
204 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top, INT16 right, INT16 bottom )
206 rect->left = left;
207 rect->right = right;
208 rect->top = top;
209 rect->bottom = bottom;
213 /***********************************************************************
214 * SetRectEmpty (USER.73)
216 void WINAPI SetRectEmpty16( LPRECT16 rect )
218 rect->left = rect->right = rect->top = rect->bottom = 0;
222 /***********************************************************************
223 * CopyRect (USER.74)
225 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
227 *dest = *src;
228 return TRUE;
232 /***********************************************************************
233 * IsRectEmpty (USER.75)
235 * Bug compat: Windows checks for 0 or negative width/height.
237 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
239 return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
243 /***********************************************************************
244 * PtInRect (USER.76)
246 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
248 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
249 (pt.y >= rect->top) && (pt.y < rect->bottom));
253 /***********************************************************************
254 * OffsetRect (USER.77)
256 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
258 rect->left += x;
259 rect->right += x;
260 rect->top += y;
261 rect->bottom += y;
265 /***********************************************************************
266 * InflateRect (USER.78)
268 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
270 rect->left -= x;
271 rect->top -= y;
272 rect->right += x;
273 rect->bottom += y;
277 /***********************************************************************
278 * IntersectRect (USER.79)
280 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
281 const RECT16 *src2 )
283 if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
284 (src1->left >= src2->right) || (src2->left >= src1->right) ||
285 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
287 SetRectEmpty16( dest );
288 return FALSE;
290 dest->left = max( src1->left, src2->left );
291 dest->right = min( src1->right, src2->right );
292 dest->top = max( src1->top, src2->top );
293 dest->bottom = min( src1->bottom, src2->bottom );
294 return TRUE;
298 /***********************************************************************
299 * UnionRect (USER.80)
301 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
302 const RECT16 *src2 )
304 if (IsRectEmpty16(src1))
306 if (IsRectEmpty16(src2))
308 SetRectEmpty16( dest );
309 return FALSE;
311 else *dest = *src2;
313 else
315 if (IsRectEmpty16(src2)) *dest = *src1;
316 else
318 dest->left = min( src1->left, src2->left );
319 dest->right = max( src1->right, src2->right );
320 dest->top = min( src1->top, src2->top );
321 dest->bottom = max( src1->bottom, src2->bottom );
324 return TRUE;
328 /***********************************************************************
329 * FillRect (USER.81)
330 * NOTE
331 * The Win16 variant doesn't support special color brushes like
332 * the Win32 one, despite the fact that Win16, as well as Win32,
333 * supports special background brushes for a window class.
335 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
337 HBRUSH prevBrush;
339 /* coordinates are logical so we cannot fast-check 'rect',
340 * it will be done later in the PatBlt().
343 if (!(prevBrush = SelectObject( HDC_32(hdc), HBRUSH_32(hbrush) ))) return 0;
344 PatBlt( HDC_32(hdc), rect->left, rect->top,
345 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
346 SelectObject( HDC_32(hdc), prevBrush );
347 return 1;
351 /***********************************************************************
352 * InvertRect (USER.82)
354 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
356 PatBlt( HDC_32(hdc), rect->left, rect->top,
357 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
361 /***********************************************************************
362 * FrameRect (USER.83)
364 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect16, HBRUSH16 hbrush )
366 RECT rect;
368 rect.left = rect16->left;
369 rect.top = rect16->top;
370 rect.right = rect16->right;
371 rect.bottom = rect16->bottom;
372 return FrameRect( HDC_32(hdc), &rect, HBRUSH_32(hbrush) );
376 /***********************************************************************
377 * DrawIcon (USER.84)
379 BOOL16 WINAPI DrawIcon16(HDC16 hdc, INT16 x, INT16 y, HICON16 hIcon)
381 return DrawIcon(HDC_32(hdc), x, y, HICON_32(hIcon));
385 /***********************************************************************
386 * DrawText (USER.85)
388 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 count, LPRECT16 rect, UINT16 flags )
390 INT16 ret;
392 if (rect)
394 RECT rect32;
396 rect32.left = rect->left;
397 rect32.top = rect->top;
398 rect32.right = rect->right;
399 rect32.bottom = rect->bottom;
400 ret = DrawTextA( HDC_32(hdc), str, count, &rect32, flags );
401 rect->left = rect32.left;
402 rect->top = rect32.top;
403 rect->right = rect32.right;
404 rect->bottom = rect32.bottom;
406 else ret = DrawTextA( HDC_32(hdc), str, count, NULL, flags);
407 return ret;
411 /***********************************************************************
412 * IconSize (USER.86)
414 * See "Undocumented Windows". Used by W2.0 paint.exe.
416 DWORD WINAPI IconSize16(void)
418 return MAKELONG(GetSystemMetrics(SM_CYICON), GetSystemMetrics(SM_CXICON));
422 /***********************************************************************
423 * AdjustWindowRect (USER.102)
425 BOOL16 WINAPI AdjustWindowRect16( LPRECT16 rect, DWORD style, BOOL16 menu )
427 return AdjustWindowRectEx16( rect, style, menu, 0 );
431 /**************************************************************************
432 * CloseClipboard (USER.138)
434 BOOL16 WINAPI CloseClipboard16(void)
436 return CloseClipboard();
440 /**************************************************************************
441 * EmptyClipboard (USER.139)
443 BOOL16 WINAPI EmptyClipboard16(void)
445 return EmptyClipboard();
449 /**************************************************************************
450 * CountClipboardFormats (USER.143)
452 INT16 WINAPI CountClipboardFormats16(void)
454 return CountClipboardFormats();
458 /**************************************************************************
459 * EnumClipboardFormats (USER.144)
461 UINT16 WINAPI EnumClipboardFormats16( UINT16 id )
463 return EnumClipboardFormats( id );
467 /**************************************************************************
468 * RegisterClipboardFormat (USER.145)
470 UINT16 WINAPI RegisterClipboardFormat16( LPCSTR name )
472 return RegisterClipboardFormatA( name );
476 /**************************************************************************
477 * GetClipboardFormatName (USER.146)
479 INT16 WINAPI GetClipboardFormatName16( UINT16 id, LPSTR buffer, INT16 maxlen )
481 return GetClipboardFormatNameA( id, buffer, maxlen );
485 /**********************************************************************
486 * CreateMenu (USER.151)
488 HMENU16 WINAPI CreateMenu16(void)
490 return HMENU_16( CreateMenu() );
494 /**********************************************************************
495 * DestroyMenu (USER.152)
497 BOOL16 WINAPI DestroyMenu16( HMENU16 hMenu )
499 return DestroyMenu( HMENU_32(hMenu) );
503 /*******************************************************************
504 * ChangeMenu (USER.153)
506 BOOL16 WINAPI ChangeMenu16( HMENU16 hMenu, UINT16 pos, SEGPTR data,
507 UINT16 id, UINT16 flags )
509 if (flags & MF_APPEND) return AppendMenu16( hMenu, flags & ~MF_APPEND, id, data );
511 /* FIXME: Word passes the item id in 'pos' and 0 or 0xffff as id */
512 /* for MF_DELETE. We should check the parameters for all others */
513 /* MF_* actions also (anybody got a doc on ChangeMenu?). */
515 if (flags & MF_DELETE) return DeleteMenu16(hMenu, pos, flags & ~MF_DELETE);
516 if (flags & MF_CHANGE) return ModifyMenu16(hMenu, pos, flags & ~MF_CHANGE, id, data );
517 if (flags & MF_REMOVE) return RemoveMenu16(hMenu, flags & MF_BYPOSITION ? pos : id,
518 flags & ~MF_REMOVE );
519 /* Default: MF_INSERT */
520 return InsertMenu16( hMenu, pos, flags, id, data );
524 /*******************************************************************
525 * CheckMenuItem (USER.154)
527 BOOL16 WINAPI CheckMenuItem16( HMENU16 hMenu, UINT16 id, UINT16 flags )
529 return CheckMenuItem( HMENU_32(hMenu), id, flags );
533 /**********************************************************************
534 * EnableMenuItem (USER.155)
536 BOOL16 WINAPI EnableMenuItem16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
538 return EnableMenuItem( HMENU_32(hMenu), wItemID, wFlags );
542 /**********************************************************************
543 * GetSubMenu (USER.159)
545 HMENU16 WINAPI GetSubMenu16( HMENU16 hMenu, INT16 nPos )
547 return HMENU_16( GetSubMenu( HMENU_32(hMenu), nPos ) );
551 /*******************************************************************
552 * GetMenuString (USER.161)
554 INT16 WINAPI GetMenuString16( HMENU16 hMenu, UINT16 wItemID,
555 LPSTR str, INT16 nMaxSiz, UINT16 wFlags )
557 return GetMenuStringA( HMENU_32(hMenu), wItemID, str, nMaxSiz, wFlags );
561 /**********************************************************************
562 * WinHelp (USER.171)
564 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
565 DWORD dwData )
567 BOOL ret;
568 DWORD mutex_count;
570 /* We might call WinExec() */
571 ReleaseThunkLock(&mutex_count);
573 ret = WinHelpA(WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData));
575 RestoreThunkLock(mutex_count);
576 return ret;
580 /***********************************************************************
581 * LoadCursor (USER.173)
583 HCURSOR16 WINAPI LoadCursor16(HINSTANCE16 hInstance, LPCSTR name)
585 return HCURSOR_16(LoadCursorA(HINSTANCE_32(hInstance), name));
589 /***********************************************************************
590 * LoadIcon (USER.174)
592 HICON16 WINAPI LoadIcon16(HINSTANCE16 hInstance, LPCSTR name)
594 return HICON_16(LoadIconA(HINSTANCE_32(hInstance), name));
597 /**********************************************************************
598 * LoadBitmap (USER.175)
600 HBITMAP16 WINAPI LoadBitmap16(HINSTANCE16 hInstance, LPCSTR name)
602 return HBITMAP_16(LoadBitmapA(HINSTANCE_32(hInstance), name));
606 /***********************************************************************
607 * GetSystemMetrics (USER.179)
609 INT16 WINAPI GetSystemMetrics16( INT16 index )
611 return GetSystemMetrics( index );
615 /*************************************************************************
616 * GetSysColor (USER.180)
618 COLORREF WINAPI GetSysColor16( INT16 index )
620 return GetSysColor( index );
624 /*************************************************************************
625 * SetSysColors (USER.181)
627 VOID WINAPI SetSysColors16( INT16 count, const INT16 *list16, const COLORREF *values )
629 INT i, *list;
631 if ((list = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*list) )))
633 for (i = 0; i < count; i++) list[i] = list16[i];
634 SetSysColors( count, list, values );
635 HeapFree( GetProcessHeap(), 0, list );
640 /***********************************************************************
641 * GrayString (USER.185)
643 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
644 LPARAM lParam, INT16 cch, INT16 x, INT16 y,
645 INT16 cx, INT16 cy )
647 BOOL ret;
649 if (!gsprc) return GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), NULL,
650 (LPARAM)MapSL(lParam), cch, x, y, cx, cy );
652 if (cch == -1 || (cch && cx && cy))
654 /* lParam can be treated as an opaque pointer */
655 struct gray_string_info info;
657 info.proc = gsprc;
658 info.param = lParam;
659 ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback,
660 (LPARAM)&info, cch, x, y, cx, cy );
662 else /* here we need some string conversions */
664 char *str16 = MapSL(lParam);
665 struct gray_string_info *info;
667 if (!cch) cch = strlen(str16);
668 if (!(info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) + cch ))) return FALSE;
669 info->proc = gsprc;
670 info->param = lParam;
671 memcpy( info->str, str16, cch );
672 ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback_ptr,
673 (LPARAM)info->str, cch, x, y, cx, cy );
674 HeapFree( GetProcessHeap(), 0, info );
676 return ret;
680 /**************************************************************************
681 * IsClipboardFormatAvailable (USER.193)
683 BOOL16 WINAPI IsClipboardFormatAvailable16( UINT16 wFormat )
685 return IsClipboardFormatAvailable( wFormat );
689 /***********************************************************************
690 * TabbedTextOut (USER.196)
692 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
693 INT16 count, INT16 nb_tabs, const INT16 *tabs16, INT16 tab_org )
695 LONG ret;
696 INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(tabs) );
697 if (!tabs) return 0;
698 for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
699 ret = TabbedTextOutA( HDC_32(hdc), x, y, lpstr, count, nb_tabs, tabs, tab_org );
700 HeapFree( GetProcessHeap(), 0, tabs );
701 return ret;
705 /***********************************************************************
706 * GetTabbedTextExtent (USER.197)
708 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
709 INT16 nb_tabs, const INT16 *tabs16 )
711 LONG ret;
712 INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(tabs) );
713 if (!tabs) return 0;
714 for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
715 ret = GetTabbedTextExtentA( HDC_32(hdc), lpstr, count, nb_tabs, tabs );
716 HeapFree( GetProcessHeap(), 0, tabs );
717 return ret;
721 /***********************************************************************
722 * UserSeeUserDo (USER.216)
724 DWORD WINAPI UserSeeUserDo16(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
726 STACK16FRAME* stack16 = MapSL((SEGPTR)NtCurrentTeb()->WOW32Reserved);
727 HANDLE16 oldDS = stack16->ds;
728 DWORD ret = (DWORD)-1;
730 stack16->ds = USER_HeapSel;
731 switch (wReqType)
733 case USUD_LOCALALLOC:
734 ret = LocalAlloc16(wParam1, wParam3);
735 break;
736 case USUD_LOCALFREE:
737 ret = LocalFree16(wParam1);
738 break;
739 case USUD_LOCALCOMPACT:
740 ret = LocalCompact16(wParam3);
741 break;
742 case USUD_LOCALHEAP:
743 ret = USER_HeapSel;
744 break;
745 case USUD_FIRSTCLASS:
746 FIXME("return a pointer to the first window class.\n");
747 break;
748 default:
749 WARN("wReqType %04x (unknown)\n", wReqType);
751 stack16->ds = oldDS;
752 return ret;
756 /*************************************************************************
757 * ScrollDC (USER.221)
759 BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
760 const RECT16 *cliprc, HRGN16 hrgnUpdate,
761 LPRECT16 rcUpdate )
763 RECT rect32, clipRect32, rcUpdate32;
764 BOOL16 ret;
766 if (rect)
768 rect32.left = rect->left;
769 rect32.top = rect->top;
770 rect32.right = rect->right;
771 rect32.bottom = rect->bottom;
773 if (cliprc)
775 clipRect32.left = cliprc->left;
776 clipRect32.top = cliprc->top;
777 clipRect32.right = cliprc->right;
778 clipRect32.bottom = cliprc->bottom;
780 ret = ScrollDC( HDC_32(hdc), dx, dy, rect ? &rect32 : NULL,
781 cliprc ? &clipRect32 : NULL, HRGN_32(hrgnUpdate),
782 &rcUpdate32 );
783 if (rcUpdate)
785 rcUpdate->left = rcUpdate32.left;
786 rcUpdate->top = rcUpdate32.top;
787 rcUpdate->right = rcUpdate32.right;
788 rcUpdate->bottom = rcUpdate32.bottom;
790 return ret;
794 /***********************************************************************
795 * GetSystemDebugState (USER.231)
797 WORD WINAPI GetSystemDebugState16(void)
799 return 0; /* FIXME */
803 /***********************************************************************
804 * EqualRect (USER.244)
806 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
808 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
809 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
813 /***********************************************************************
814 * ExitWindowsExec (USER.246)
816 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
818 TRACE("Should run the following in DOS-mode: \"%s %s\"\n",
819 lpszExe, lpszParams);
820 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
824 /***********************************************************************
825 * GetCursor (USER.247)
827 HCURSOR16 WINAPI GetCursor16(void)
829 return HCURSOR_16(GetCursor());
833 /**********************************************************************
834 * GetAsyncKeyState (USER.249)
836 INT16 WINAPI GetAsyncKeyState16( INT16 key )
838 return GetAsyncKeyState( key );
842 /**********************************************************************
843 * GetMenuState (USER.250)
845 UINT16 WINAPI GetMenuState16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
847 return GetMenuState( HMENU_32(hMenu), wItemID, wFlags );
851 /**********************************************************************
852 * GetMenuItemCount (USER.263)
854 INT16 WINAPI GetMenuItemCount16( HMENU16 hMenu )
856 return GetMenuItemCount( HMENU_32(hMenu) );
860 /**********************************************************************
861 * GetMenuItemID (USER.264)
863 UINT16 WINAPI GetMenuItemID16( HMENU16 hMenu, INT16 nPos )
865 return GetMenuItemID( HMENU_32(hMenu), nPos );
869 /***********************************************************************
870 * GlobalAddAtom (USER.268)
872 ATOM WINAPI GlobalAddAtom16(LPCSTR lpString)
874 return GlobalAddAtomA(lpString);
877 /***********************************************************************
878 * GlobalDeleteAtom (USER.269)
880 ATOM WINAPI GlobalDeleteAtom16(ATOM nAtom)
882 return GlobalDeleteAtom(nAtom);
885 /***********************************************************************
886 * GlobalFindAtom (USER.270)
888 ATOM WINAPI GlobalFindAtom16(LPCSTR lpString)
890 return GlobalFindAtomA(lpString);
893 /***********************************************************************
894 * GlobalGetAtomName (USER.271)
896 UINT16 WINAPI GlobalGetAtomName16(ATOM nAtom, LPSTR lpBuffer, INT16 nSize)
898 return GlobalGetAtomNameA(nAtom, lpBuffer, nSize);
902 /***********************************************************************
903 * ControlPanelInfo (USER.273)
905 void WINAPI ControlPanelInfo16( INT16 nInfoType, WORD wData, LPSTR lpBuffer )
907 FIXME("(%d, %04x, %p): stub.\n", nInfoType, wData, lpBuffer);
911 /***********************************************************************
912 * OldSetDeskPattern (USER.279)
914 BOOL16 WINAPI SetDeskPattern16(void)
916 return SystemParametersInfoA( SPI_SETDESKPATTERN, -1, NULL, FALSE );
920 /***********************************************************************
921 * GetSysColorBrush (USER.281)
923 HBRUSH16 WINAPI GetSysColorBrush16( INT16 index )
925 return HBRUSH_16( GetSysColorBrush(index) );
929 /***********************************************************************
930 * SelectPalette (USER.282)
932 HPALETTE16 WINAPI SelectPalette16( HDC16 hdc, HPALETTE16 hpal, BOOL16 bForceBackground )
934 return HPALETTE_16( SelectPalette( HDC_32(hdc), HPALETTE_32(hpal), bForceBackground ));
937 /***********************************************************************
938 * RealizePalette (USER.283)
940 UINT16 WINAPI RealizePalette16( HDC16 hdc )
942 return UserRealizePalette( HDC_32(hdc) );
946 /***********************************************************************
947 * GetFreeSystemResources (USER.284)
949 WORD WINAPI GetFreeSystemResources16( WORD resType )
951 STACK16FRAME* stack16 = MapSL((SEGPTR)NtCurrentTeb()->WOW32Reserved);
952 HANDLE16 oldDS = stack16->ds;
953 HINSTANCE16 gdi_inst;
954 WORD gdi_heap;
955 int userPercent, gdiPercent;
957 if ((gdi_inst = LoadLibrary16( "GDI" )) < 32) return 0;
958 gdi_heap = gdi_inst | 7;
960 switch(resType)
962 case GFSR_USERRESOURCES:
963 stack16->ds = USER_HeapSel;
964 userPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
965 gdiPercent = 100;
966 stack16->ds = oldDS;
967 break;
969 case GFSR_GDIRESOURCES:
970 stack16->ds = gdi_inst;
971 gdiPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
972 userPercent = 100;
973 stack16->ds = oldDS;
974 break;
976 case GFSR_SYSTEMRESOURCES:
977 stack16->ds = USER_HeapSel;
978 userPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
979 stack16->ds = gdi_inst;
980 gdiPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
981 stack16->ds = oldDS;
982 break;
984 default:
985 userPercent = gdiPercent = 0;
986 break;
988 FreeLibrary16( gdi_inst );
989 TRACE("<- userPercent %d, gdiPercent %d\n", userPercent, gdiPercent);
990 return (WORD)min( userPercent, gdiPercent );
994 /***********************************************************************
995 * SetDeskWallPaper (USER.285)
997 BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
999 return SetDeskWallPaper( filename );
1003 /***********************************************************************
1004 * GetClipCursor (USER.309)
1006 void WINAPI GetClipCursor16( RECT16 *rect )
1008 if (rect)
1010 RECT rect32;
1011 GetClipCursor( &rect32 );
1012 rect->left = rect32.left;
1013 rect->top = rect32.top;
1014 rect->right = rect32.right;
1015 rect->bottom = rect32.bottom;
1020 /***********************************************************************
1021 * SignalProc (USER.314)
1023 void WINAPI SignalProc16( HANDLE16 hModule, UINT16 code,
1024 UINT16 uExitFn, HINSTANCE16 hInstance, HQUEUE16 hQueue )
1026 if (code == USIG16_DLL_UNLOAD)
1028 /* HOOK_FreeModuleHooks( hModule ); */
1029 CLASS_FreeModuleClasses( hModule );
1030 CURSORICON_FreeModuleIcons( hModule );
1035 /***********************************************************************
1036 * SetEventHook (USER.321)
1038 * Used by Turbo Debugger for Windows
1040 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
1042 FIXME("(lpfnEventHook=%p): stub\n", lpfnEventHook);
1043 return 0;
1047 /**********************************************************************
1048 * EnableHardwareInput (USER.331)
1050 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
1052 FIXME("(%d) - stub\n", bEnable);
1053 return TRUE;
1057 /***********************************************************************
1058 * IsUserIdle (USER.333)
1060 BOOL16 WINAPI IsUserIdle16(void)
1062 if ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
1063 return FALSE;
1064 if ( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 )
1065 return FALSE;
1066 if ( GetAsyncKeyState( VK_MBUTTON ) & 0x8000 )
1067 return FALSE;
1068 /* Should check for screen saver activation here ... */
1069 return TRUE;
1073 /**********************************************************************
1074 * LoadDIBIconHandler (USER.357)
1076 * RT_ICON resource loader, installed by USER_SignalProc when module
1077 * is initialized.
1079 HGLOBAL16 WINAPI LoadDIBIconHandler16( HGLOBAL16 hMemObj, HMODULE16 hModule, HRSRC16 hRsrc )
1081 /* If hResource is zero we must allocate a new memory block, if it's
1082 * non-zero but GlobalLock() returns NULL then it was discarded and
1083 * we have to recommit some memory, otherwise we just need to check
1084 * the block size. See LoadProc() in 16-bit SDK for more.
1086 FIXME( "%x %x %x: stub, not supported anymore\n", hMemObj, hModule, hRsrc );
1087 return 0;
1090 /**********************************************************************
1091 * LoadDIBCursorHandler (USER.356)
1093 * RT_CURSOR resource loader. Same as above.
1095 HGLOBAL16 WINAPI LoadDIBCursorHandler16( HGLOBAL16 hMemObj, HMODULE16 hModule, HRSRC16 hRsrc )
1097 FIXME( "%x %x %x: stub, not supported anymore\n", hMemObj, hModule, hRsrc );
1098 return 0;
1102 /**********************************************************************
1103 * IsMenu (USER.358)
1105 BOOL16 WINAPI IsMenu16( HMENU16 hmenu )
1107 return IsMenu( HMENU_32(hmenu) );
1111 /***********************************************************************
1112 * DCHook (USER.362)
1114 BOOL16 WINAPI DCHook16( HDC16 hdc, WORD code, DWORD data, LPARAM lParam )
1116 FIXME( "hDC = %x, %i: stub\n", hdc, code );
1117 return FALSE;
1121 /***********************************************************************
1122 * SubtractRect (USER.373)
1124 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
1125 const RECT16 *src2 )
1127 RECT16 tmp;
1129 if (IsRectEmpty16( src1 ))
1131 SetRectEmpty16( dest );
1132 return FALSE;
1134 *dest = *src1;
1135 if (IntersectRect16( &tmp, src1, src2 ))
1137 if (EqualRect16( &tmp, dest ))
1139 SetRectEmpty16( dest );
1140 return FALSE;
1142 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
1144 if (tmp.left == dest->left) dest->left = tmp.right;
1145 else if (tmp.right == dest->right) dest->right = tmp.left;
1147 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
1149 if (tmp.top == dest->top) dest->top = tmp.bottom;
1150 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
1153 return TRUE;
1157 /**********************************************************************
1158 * SetMenuContextHelpId (USER.384)
1160 BOOL16 WINAPI SetMenuContextHelpId16( HMENU16 hMenu, DWORD dwContextHelpID)
1162 return SetMenuContextHelpId( HMENU_32(hMenu), dwContextHelpID );
1166 /**********************************************************************
1167 * GetMenuContextHelpId (USER.385)
1169 DWORD WINAPI GetMenuContextHelpId16( HMENU16 hMenu )
1171 return GetMenuContextHelpId( HMENU_32(hMenu) );
1175 /***********************************************************************
1176 * LoadImage (USER.389)
1179 HANDLE16 WINAPI LoadImage16(HINSTANCE16 hinst, LPCSTR name, UINT16 type,
1180 INT16 desiredx, INT16 desiredy, UINT16 loadflags)
1182 return HANDLE_16(LoadImageA(HINSTANCE_32(hinst), name, type, desiredx,
1183 desiredy, loadflags));
1186 /******************************************************************************
1187 * CopyImage (USER.390) Creates new image and copies attributes to it
1190 HICON16 WINAPI CopyImage16(HANDLE16 hnd, UINT16 type, INT16 desiredx,
1191 INT16 desiredy, UINT16 flags)
1193 return HICON_16(CopyImage(HANDLE_32(hnd), (UINT)type, (INT)desiredx,
1194 (INT)desiredy, (UINT)flags));
1197 /**********************************************************************
1198 * DrawIconEx (USER.394)
1200 BOOL16 WINAPI DrawIconEx16(HDC16 hdc, INT16 xLeft, INT16 yTop, HICON16 hIcon,
1201 INT16 cxWidth, INT16 cyWidth, UINT16 istep,
1202 HBRUSH16 hbr, UINT16 flags)
1204 return DrawIconEx(HDC_32(hdc), xLeft, yTop, HICON_32(hIcon), cxWidth, cyWidth,
1205 istep, HBRUSH_32(hbr), flags);
1208 /**********************************************************************
1209 * GetIconInfo (USER.395)
1211 BOOL16 WINAPI GetIconInfo16(HICON16 hIcon, LPICONINFO16 iconinfo)
1213 ICONINFO ii32;
1214 BOOL16 ret = GetIconInfo(HICON_32(hIcon), &ii32);
1216 iconinfo->fIcon = ii32.fIcon;
1217 iconinfo->xHotspot = ii32.xHotspot;
1218 iconinfo->yHotspot = ii32.yHotspot;
1219 iconinfo->hbmMask = HBITMAP_16(ii32.hbmMask);
1220 iconinfo->hbmColor = HBITMAP_16(ii32.hbmColor);
1221 return ret;
1225 /***********************************************************************
1226 * FinalUserInit (USER.400)
1228 void WINAPI FinalUserInit16( void )
1230 /* FIXME: Should chain to FinalGdiInit */
1234 /***********************************************************************
1235 * CreateCursor (USER.406)
1237 HCURSOR16 WINAPI CreateCursor16(HINSTANCE16 hInstance,
1238 INT16 xHotSpot, INT16 yHotSpot,
1239 INT16 nWidth, INT16 nHeight,
1240 LPCVOID lpANDbits, LPCVOID lpXORbits)
1242 CURSORICONINFO info;
1244 info.ptHotSpot.x = xHotSpot;
1245 info.ptHotSpot.y = yHotSpot;
1246 info.nWidth = nWidth;
1247 info.nHeight = nHeight;
1248 info.nWidthBytes = 0;
1249 info.bPlanes = 1;
1250 info.bBitsPerPixel = 1;
1252 return CreateCursorIconIndirect16(hInstance, &info, lpANDbits, lpXORbits);
1256 /***********************************************************************
1257 * InitThreadInput (USER.409)
1259 HQUEUE16 WINAPI InitThreadInput16( WORD unknown, WORD flags )
1261 /* nothing to do here */
1262 return 0xbeef;
1266 /*******************************************************************
1267 * InsertMenu (USER.410)
1269 BOOL16 WINAPI InsertMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
1270 UINT16 id, SEGPTR data )
1272 UINT pos32 = (UINT)pos;
1273 if ((pos == (UINT16)-1) && (flags & MF_BYPOSITION)) pos32 = (UINT)-1;
1274 if (IS_MENU_STRING_ITEM(flags) && data)
1275 return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, MapSL(data) );
1276 return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, (LPSTR)data );
1280 /*******************************************************************
1281 * AppendMenu (USER.411)
1283 BOOL16 WINAPI AppendMenu16(HMENU16 hMenu, UINT16 flags, UINT16 id, SEGPTR data)
1285 return InsertMenu16( hMenu, -1, flags | MF_BYPOSITION, id, data );
1289 /**********************************************************************
1290 * RemoveMenu (USER.412)
1292 BOOL16 WINAPI RemoveMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
1294 return RemoveMenu( HMENU_32(hMenu), nPos, wFlags );
1298 /**********************************************************************
1299 * DeleteMenu (USER.413)
1301 BOOL16 WINAPI DeleteMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
1303 return DeleteMenu( HMENU_32(hMenu), nPos, wFlags );
1307 /*******************************************************************
1308 * ModifyMenu (USER.414)
1310 BOOL16 WINAPI ModifyMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
1311 UINT16 id, SEGPTR data )
1313 if (IS_MENU_STRING_ITEM(flags))
1314 return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, MapSL(data) );
1315 return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, (LPSTR)data );
1319 /**********************************************************************
1320 * CreatePopupMenu (USER.415)
1322 HMENU16 WINAPI CreatePopupMenu16(void)
1324 return HMENU_16( CreatePopupMenu() );
1328 /**********************************************************************
1329 * SetMenuItemBitmaps (USER.418)
1331 BOOL16 WINAPI SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags,
1332 HBITMAP16 hNewUnCheck, HBITMAP16 hNewCheck)
1334 return SetMenuItemBitmaps( HMENU_32(hMenu), nPos, wFlags,
1335 HBITMAP_32(hNewUnCheck), HBITMAP_32(hNewCheck) );
1339 /***********************************************************************
1340 * lstrcmp (USER.430)
1342 INT16 WINAPI lstrcmp16( LPCSTR str1, LPCSTR str2 )
1344 return strcmp( str1, str2 );
1348 /***********************************************************************
1349 * AnsiUpper (USER.431)
1351 SEGPTR WINAPI AnsiUpper16( SEGPTR strOrChar )
1353 /* uppercase only one char if strOrChar < 0x10000 */
1354 if (HIWORD(strOrChar))
1356 CharUpperA( MapSL(strOrChar) );
1357 return strOrChar;
1359 else return (SEGPTR)CharUpperA( (LPSTR)strOrChar );
1363 /***********************************************************************
1364 * AnsiLower (USER.432)
1366 SEGPTR WINAPI AnsiLower16( SEGPTR strOrChar )
1368 /* lowercase only one char if strOrChar < 0x10000 */
1369 if (HIWORD(strOrChar))
1371 CharLowerA( MapSL(strOrChar) );
1372 return strOrChar;
1374 else return (SEGPTR)CharLowerA( (LPSTR)strOrChar );
1378 /***********************************************************************
1379 * AnsiUpperBuff (USER.437)
1381 UINT16 WINAPI AnsiUpperBuff16( LPSTR str, UINT16 len )
1383 CharUpperBuffA( str, len ? len : 65536 );
1384 return len;
1388 /***********************************************************************
1389 * AnsiLowerBuff (USER.438)
1391 UINT16 WINAPI AnsiLowerBuff16( LPSTR str, UINT16 len )
1393 CharLowerBuffA( str, len ? len : 65536 );
1394 return len;
1398 /*******************************************************************
1399 * InsertMenuItem (USER.441)
1401 * FIXME: untested
1403 BOOL16 WINAPI InsertMenuItem16( HMENU16 hmenu, UINT16 pos, BOOL16 byposition,
1404 const MENUITEMINFO16 *mii )
1406 MENUITEMINFOA miia;
1408 miia.cbSize = sizeof(miia);
1409 miia.fMask = mii->fMask;
1410 miia.dwTypeData = (LPSTR)mii->dwTypeData;
1411 miia.fType = mii->fType;
1412 miia.fState = mii->fState;
1413 miia.wID = mii->wID;
1414 miia.hSubMenu = HMENU_32(mii->hSubMenu);
1415 miia.hbmpChecked = HBITMAP_32(mii->hbmpChecked);
1416 miia.hbmpUnchecked = HBITMAP_32(mii->hbmpUnchecked);
1417 miia.dwItemData = mii->dwItemData;
1418 miia.cch = mii->cch;
1419 if (IS_MENU_STRING_ITEM(miia.fType))
1420 miia.dwTypeData = MapSL(mii->dwTypeData);
1421 return InsertMenuItemA( HMENU_32(hmenu), pos, byposition, &miia );
1425 /**********************************************************************
1426 * DrawState (USER.449)
1428 BOOL16 WINAPI DrawState16( HDC16 hdc, HBRUSH16 hbr, DRAWSTATEPROC16 func, LPARAM ldata,
1429 WPARAM16 wdata, INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags )
1431 struct draw_state_info info;
1432 UINT opcode = flags & 0xf;
1434 if (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)
1436 /* make sure DrawStateA doesn't try to use ldata as a pointer */
1437 if (!wdata) wdata = strlen( MapSL(ldata) );
1438 if (!cx || !cy)
1440 SIZE s;
1441 if (!GetTextExtentPoint32A( HDC_32(hdc), MapSL(ldata), wdata, &s )) return FALSE;
1442 if (!cx) cx = s.cx;
1443 if (!cy) cy = s.cy;
1446 info.proc = func;
1447 info.param = ldata;
1448 return DrawStateA( HDC_32(hdc), HBRUSH_32(hbr), draw_state_callback,
1449 (LPARAM)&info, wdata, x, y, cx, cy, flags );
1453 /**********************************************************************
1454 * CreateIconFromResourceEx (USER.450)
1456 * FIXME: not sure about exact parameter types
1458 HICON16 WINAPI CreateIconFromResourceEx16(LPBYTE bits, UINT16 cbSize,
1459 BOOL16 bIcon, DWORD dwVersion,
1460 INT16 width, INT16 height,
1461 UINT16 cFlag)
1463 return HICON_16(CreateIconFromResourceEx(bits, cbSize, bIcon, dwVersion,
1464 width, height, cFlag));
1468 /***********************************************************************
1469 * AdjustWindowRectEx (USER.454)
1471 BOOL16 WINAPI AdjustWindowRectEx16( LPRECT16 rect, DWORD style, BOOL16 menu, DWORD exStyle )
1473 RECT rect32;
1474 BOOL ret;
1476 rect32.left = rect->left;
1477 rect32.top = rect->top;
1478 rect32.right = rect->right;
1479 rect32.bottom = rect->bottom;
1480 ret = AdjustWindowRectEx( &rect32, style, menu, exStyle );
1481 rect->left = rect32.left;
1482 rect->top = rect32.top;
1483 rect->right = rect32.right;
1484 rect->bottom = rect32.bottom;
1485 return ret;
1489 /***********************************************************************
1490 * DestroyIcon (USER.457)
1492 BOOL16 WINAPI DestroyIcon16(HICON16 hIcon)
1494 return DestroyIcon32(hIcon, 0);
1497 /***********************************************************************
1498 * DestroyCursor (USER.458)
1500 BOOL16 WINAPI DestroyCursor16(HCURSOR16 hCursor)
1502 return DestroyIcon32(hCursor, 0);
1505 /*******************************************************************
1506 * DRAG_QueryUpdate16
1508 * Recursively find a child that contains spDragInfo->pt point
1509 * and send WM_QUERYDROPOBJECT. Helper for DragObject16.
1511 static BOOL DRAG_QueryUpdate16( HWND hQueryWnd, SEGPTR spDragInfo )
1513 BOOL bResult = 0;
1514 WPARAM wParam;
1515 POINT pt, old_pt;
1516 LPDRAGINFO16 ptrDragInfo = MapSL(spDragInfo);
1517 RECT tempRect;
1518 HWND child;
1520 if (!IsWindowEnabled(hQueryWnd)) return FALSE;
1522 old_pt.x = ptrDragInfo->pt.x;
1523 old_pt.y = ptrDragInfo->pt.y;
1524 pt = old_pt;
1525 ScreenToClient( hQueryWnd, &pt );
1526 child = ChildWindowFromPointEx( hQueryWnd, pt, CWP_SKIPINVISIBLE );
1527 if (!child) return FALSE;
1529 if (child != hQueryWnd)
1531 wParam = 0;
1532 if (DRAG_QueryUpdate16( child, spDragInfo )) return TRUE;
1534 else
1536 GetClientRect( hQueryWnd, &tempRect );
1537 wParam = !PtInRect( &tempRect, pt );
1540 ptrDragInfo->pt.x = pt.x;
1541 ptrDragInfo->pt.y = pt.y;
1542 ptrDragInfo->hScope = HWND_16(hQueryWnd);
1544 bResult = SendMessage16( HWND_16(hQueryWnd), WM_QUERYDROPOBJECT, wParam, spDragInfo );
1546 if (!bResult)
1548 ptrDragInfo->pt.x = old_pt.x;
1549 ptrDragInfo->pt.y = old_pt.y;
1551 return bResult;
1555 /******************************************************************************
1556 * DragObject (USER.464)
1558 DWORD WINAPI DragObject16( HWND16 hwndScope, HWND16 hWnd, UINT16 wObj,
1559 HANDLE16 hOfStruct, WORD szList, HCURSOR16 hCursor )
1561 MSG msg;
1562 LPDRAGINFO16 lpDragInfo;
1563 SEGPTR spDragInfo;
1564 HCURSOR hOldCursor=0, hBummer=0;
1565 HGLOBAL16 hDragInfo = GlobalAlloc16( GMEM_SHARE | GMEM_ZEROINIT, 2*sizeof(DRAGINFO16));
1566 HCURSOR hCurrentCursor = 0;
1567 HWND16 hCurrentWnd = 0;
1569 lpDragInfo = (LPDRAGINFO16) GlobalLock16(hDragInfo);
1570 spDragInfo = WOWGlobalLock16(hDragInfo);
1572 if( !lpDragInfo || !spDragInfo ) return 0L;
1574 if (!(hBummer = LoadCursorA(0, MAKEINTRESOURCEA(OCR_NO))))
1576 GlobalFree16(hDragInfo);
1577 return 0L;
1580 if(hCursor) hOldCursor = SetCursor(HCURSOR_32(hCursor));
1582 lpDragInfo->hWnd = hWnd;
1583 lpDragInfo->hScope = 0;
1584 lpDragInfo->wFlags = wObj;
1585 lpDragInfo->hList = szList; /* near pointer! */
1586 lpDragInfo->hOfStruct = hOfStruct;
1587 lpDragInfo->l = 0L;
1589 SetCapture( HWND_32(hWnd) );
1590 ShowCursor( TRUE );
1594 GetMessageW( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST );
1596 *(lpDragInfo+1) = *lpDragInfo;
1598 lpDragInfo->pt.x = msg.pt.x;
1599 lpDragInfo->pt.y = msg.pt.y;
1601 /* update DRAGINFO struct */
1602 if( DRAG_QueryUpdate16(WIN_Handle32(hwndScope), spDragInfo) > 0 )
1603 hCurrentCursor = HCURSOR_32(hCursor);
1604 else
1606 hCurrentCursor = hBummer;
1607 lpDragInfo->hScope = 0;
1609 if( hCurrentCursor )
1610 SetCursor(hCurrentCursor);
1612 /* send WM_DRAGLOOP */
1613 SendMessage16( hWnd, WM_DRAGLOOP, (WPARAM16)(hCurrentCursor != hBummer),
1614 (LPARAM) spDragInfo );
1615 /* send WM_DRAGSELECT or WM_DRAGMOVE */
1616 if( hCurrentWnd != lpDragInfo->hScope )
1618 if( hCurrentWnd )
1619 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 0,
1620 (LPARAM)MAKELONG(LOWORD(spDragInfo)+sizeof(DRAGINFO16),
1621 HIWORD(spDragInfo)) );
1622 hCurrentWnd = lpDragInfo->hScope;
1623 if( hCurrentWnd )
1624 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 1, (LPARAM)spDragInfo);
1626 else
1627 if( hCurrentWnd )
1628 SendMessage16( hCurrentWnd, WM_DRAGMOVE, 0, (LPARAM)spDragInfo);
1630 } while( msg.message != WM_LBUTTONUP && msg.message != WM_NCLBUTTONUP );
1632 ReleaseCapture();
1633 ShowCursor( FALSE );
1635 if( hCursor ) SetCursor(hOldCursor);
1637 if( hCurrentCursor != hBummer )
1638 msg.lParam = SendMessage16( lpDragInfo->hScope, WM_DROPOBJECT,
1639 (WPARAM16)hWnd, (LPARAM)spDragInfo );
1640 else
1641 msg.lParam = 0;
1642 GlobalFree16(hDragInfo);
1644 return (DWORD)(msg.lParam);
1648 /***********************************************************************
1649 * DrawFocusRect (USER.466)
1651 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
1653 RECT rect32;
1655 rect32.left = rc->left;
1656 rect32.top = rc->top;
1657 rect32.right = rc->right;
1658 rect32.bottom = rc->bottom;
1659 DrawFocusRect( HDC_32(hdc), &rect32 );
1663 /***********************************************************************
1664 * AnsiNext (USER.472)
1666 SEGPTR WINAPI AnsiNext16(SEGPTR current)
1668 char *ptr = MapSL(current);
1669 return current + (CharNextA(ptr) - ptr);
1673 /***********************************************************************
1674 * AnsiPrev (USER.473)
1676 SEGPTR WINAPI AnsiPrev16( LPCSTR start, SEGPTR current )
1678 char *ptr = MapSL(current);
1679 return current - (ptr - CharPrevA( start, ptr ));
1683 /***********************************************************************
1684 * FormatMessage (USER.606)
1686 DWORD WINAPI FormatMessage16(
1687 DWORD dwFlags,
1688 SEGPTR lpSource, /* [in] NOTE: not always a valid pointer */
1689 WORD dwMessageId,
1690 WORD dwLanguageId,
1691 LPSTR lpBuffer, /* [out] NOTE: *((HLOCAL16*)) for FORMAT_MESSAGE_ALLOCATE_BUFFER*/
1692 WORD nSize,
1693 LPDWORD args ) /* [in] NOTE: va_list *args */
1695 #ifdef __i386__
1696 /* This implementation is completely dependent on the format of the va_list on x86 CPUs */
1697 LPSTR target,t;
1698 DWORD talloced;
1699 LPSTR from,f;
1700 DWORD width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK;
1701 BOOL eos = FALSE;
1702 LPSTR allocstring = NULL;
1704 TRACE("(0x%x,%x,%d,0x%x,%p,%d,%p)\n",
1705 dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args);
1706 if ((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
1707 && (dwFlags & FORMAT_MESSAGE_FROM_HMODULE)) return 0;
1708 if ((dwFlags & FORMAT_MESSAGE_FROM_STRING)
1709 &&((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
1710 || (dwFlags & FORMAT_MESSAGE_FROM_HMODULE))) return 0;
1712 if (width && width != FORMAT_MESSAGE_MAX_WIDTH_MASK)
1713 FIXME("line wrapping (%u) not supported.\n", width);
1714 from = NULL;
1715 if (dwFlags & FORMAT_MESSAGE_FROM_STRING)
1717 char *source = MapSL(lpSource);
1718 from = HeapAlloc( GetProcessHeap(), 0, strlen(source)+1 );
1719 strcpy( from, source );
1721 else if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) {
1722 from = HeapAlloc( GetProcessHeap(),0,200 );
1723 sprintf(from,"Systemmessage, messageid = 0x%08x\n",dwMessageId);
1725 else if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) {
1726 INT16 bufsize;
1727 HINSTANCE16 hinst16 = ((HINSTANCE16)lpSource & 0xffff);
1729 dwMessageId &= 0xFFFF;
1730 bufsize=LoadString16(hinst16,dwMessageId,NULL,0);
1731 if (bufsize) {
1732 from = HeapAlloc( GetProcessHeap(), 0, bufsize +1);
1733 LoadString16(hinst16,dwMessageId,from,bufsize+1);
1736 target = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 100);
1737 t = target;
1738 talloced= 100;
1740 #define ADD_TO_T(c) \
1741 *t++=c;\
1742 if (t-target == talloced) {\
1743 target = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,talloced*2);\
1744 t = target+talloced;\
1745 talloced*=2;\
1748 if (from) {
1749 f=from;
1750 while (*f && !eos) {
1751 if (*f=='%') {
1752 int insertnr;
1753 char *fmtstr,*x,*lastf;
1754 DWORD *argliststart;
1756 fmtstr = NULL;
1757 lastf = f;
1758 f++;
1759 if (!*f) {
1760 ADD_TO_T('%');
1761 continue;
1763 switch (*f) {
1764 case '1':case '2':case '3':case '4':case '5':
1765 case '6':case '7':case '8':case '9':
1766 insertnr=*f-'0';
1767 switch (f[1]) {
1768 case '0':case '1':case '2':case '3':
1769 case '4':case '5':case '6':case '7':
1770 case '8':case '9':
1771 f++;
1772 insertnr=insertnr*10+*f-'0';
1773 f++;
1774 break;
1775 default:
1776 f++;
1777 break;
1779 if (*f=='!') {
1780 f++;
1781 if (NULL!=(x=strchr(f,'!'))) {
1782 *x='\0';
1783 fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2);
1784 sprintf(fmtstr,"%%%s",f);
1785 f=x+1;
1786 } else {
1787 fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2);
1788 sprintf(fmtstr,"%%%s",f);
1789 f+=strlen(f); /*at \0*/
1792 else
1794 if(!args) break;
1795 fmtstr=HeapAlloc( GetProcessHeap(), 0, 3 );
1796 strcpy( fmtstr, "%s" );
1798 if (args) {
1799 int ret;
1800 int sz;
1801 LPSTR b = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz = 100);
1803 argliststart=args+insertnr-1;
1805 /* CMF - This makes a BIG assumption about va_list */
1806 while ((ret = vsnprintf(b, sz, fmtstr, (va_list) argliststart) < 0) || (ret >= sz)) {
1807 sz = (ret == -1 ? sz + 100 : ret + 1);
1808 b = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, b, sz);
1810 for (x=b; *x; x++) ADD_TO_T(*x);
1811 HeapFree(GetProcessHeap(), 0, b);
1812 } else {
1813 /* NULL args - copy formatstr
1814 * (probably wrong)
1816 while ((lastf<f)&&(*lastf)) {
1817 ADD_TO_T(*lastf++);
1820 HeapFree(GetProcessHeap(),0,fmtstr);
1821 break;
1822 case '0': /* Just stop processing format string */
1823 eos = TRUE;
1824 f++;
1825 break;
1826 case 'n': /* 16 bit version just outputs 'n' */
1827 default:
1828 ADD_TO_T(*f++);
1829 break;
1831 } else { /* '\n' or '\r' gets mapped to "\r\n" */
1832 if(*f == '\n' || *f == '\r') {
1833 if (width == 0) {
1834 ADD_TO_T('\r');
1835 ADD_TO_T('\n');
1836 if(*f++ == '\r' && *f == '\n')
1837 f++;
1839 } else {
1840 ADD_TO_T(*f++);
1844 *t='\0';
1846 talloced = strlen(target)+1;
1847 if (nSize && talloced<nSize) {
1848 target = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,nSize);
1850 TRACE("-- %s\n",debugstr_a(target));
1851 if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) {
1852 /* nSize is the MINIMUM size */
1853 HLOCAL16 h = LocalAlloc16(LPTR,talloced);
1854 SEGPTR ptr = LocalLock16(h);
1855 allocstring = MapSL( ptr );
1856 memcpy( allocstring,target,talloced);
1857 LocalUnlock16( h );
1858 *((HLOCAL16*)lpBuffer) = h;
1859 } else
1860 lstrcpynA(lpBuffer,target,nSize);
1861 HeapFree(GetProcessHeap(),0,target);
1862 HeapFree(GetProcessHeap(),0,from);
1863 return (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) ?
1864 strlen(allocstring):
1865 strlen(lpBuffer);
1866 #else
1867 return 0;
1868 #endif /* __i386__ */
1870 #undef ADD_TO_T
1873 /***********************************************************************
1874 * ChangeDisplaySettings (USER.620)
1876 LONG WINAPI ChangeDisplaySettings16( LPDEVMODEA devmode, DWORD flags )
1878 return ChangeDisplaySettingsA( devmode, flags );
1882 /***********************************************************************
1883 * EnumDisplaySettings (USER.621)
1885 BOOL16 WINAPI EnumDisplaySettings16( LPCSTR name, DWORD n, LPDEVMODEA devmode )
1887 return EnumDisplaySettingsA( name, n, devmode );
1890 /**********************************************************************
1891 * DrawFrameControl (USER.656)
1893 BOOL16 WINAPI DrawFrameControl16( HDC16 hdc, LPRECT16 rc, UINT16 uType, UINT16 uState )
1895 RECT rect32;
1896 BOOL ret;
1898 rect32.left = rc->left;
1899 rect32.top = rc->top;
1900 rect32.right = rc->right;
1901 rect32.bottom = rc->bottom;
1902 ret = DrawFrameControl( HDC_32(hdc), &rect32, uType, uState );
1903 rc->left = rect32.left;
1904 rc->top = rect32.top;
1905 rc->right = rect32.right;
1906 rc->bottom = rect32.bottom;
1907 return ret;
1910 /**********************************************************************
1911 * DrawEdge (USER.659)
1913 BOOL16 WINAPI DrawEdge16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
1915 RECT rect32;
1916 BOOL ret;
1918 rect32.left = rc->left;
1919 rect32.top = rc->top;
1920 rect32.right = rc->right;
1921 rect32.bottom = rc->bottom;
1922 ret = DrawEdge( HDC_32(hdc), &rect32, edge, flags );
1923 rc->left = rect32.left;
1924 rc->top = rect32.top;
1925 rc->right = rect32.right;
1926 rc->bottom = rect32.bottom;
1927 return ret;
1930 /**********************************************************************
1931 * CheckMenuRadioItem (USER.666)
1933 BOOL16 WINAPI CheckMenuRadioItem16(HMENU16 hMenu, UINT16 first, UINT16 last,
1934 UINT16 check, BOOL16 bypos)
1936 return CheckMenuRadioItem( HMENU_32(hMenu), first, last, check, bypos );