Added CS_DBLCLKS so that systray receives double clicks.
[wine] / dlls / user / user16.c
1 /*
2  * Misc 16-bit USER functions
3  *
4  * Copyright 2002 Patrik Stridvall
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <stdlib.h>
22 #include "wine/winuser16.h"
23 #include "winbase.h"
24 #include "wownt32.h"
25 #include "user.h"
26 #include "win.h"
27
28 /* handle to handle 16 conversions */
29 #define HANDLE_16(h32)          (LOWORD(h32))
30
31 /* handle16 to handle conversions */
32 #define HANDLE_32(h16)          ((HANDLE)(ULONG_PTR)(h16))
33 #define HINSTANCE_32(h16)       ((HINSTANCE)(ULONG_PTR)(h16))
34
35 #define IS_MENU_STRING_ITEM(flags) \
36     (((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR)) == MF_STRING)
37
38 WORD WINAPI DestroyIcon32(HGLOBAL16, UINT16);
39
40
41 /* ### start build ### */
42 extern WORD CALLBACK USER_CallTo16_word_wlw(GRAYSTRINGPROC16,WORD,LONG,WORD);
43 /* ### stop build ### */
44
45 struct gray_string_info
46 {
47     GRAYSTRINGPROC16 proc;
48     LPARAM           param;
49     char             str[1];
50 };
51
52 /* callback for 16-bit gray string proc with opaque pointer */
53 static BOOL CALLBACK gray_string_callback( HDC hdc, LPARAM param, INT len )
54 {
55     const struct gray_string_info *info = (struct gray_string_info *)param;
56     return USER_CallTo16_word_wlw( info->proc, HDC_16(hdc), info->param, len );
57 }
58
59 /* callback for 16-bit gray string proc with string pointer */
60 static BOOL CALLBACK gray_string_callback_ptr( HDC hdc, LPARAM param, INT len )
61 {
62     const struct gray_string_info *info;
63     char *str = (char *)param;
64
65     info = (struct gray_string_info *)(str - offsetof( struct gray_string_info, str ));
66     return USER_CallTo16_word_wlw( info->proc, HDC_16(hdc), info->param, len );
67 }
68
69 /***********************************************************************
70  *              SetCursor (USER.69)
71  */
72 HCURSOR16 WINAPI SetCursor16(HCURSOR16 hCursor)
73 {
74   return HCURSOR_16(SetCursor(HCURSOR_32(hCursor)));
75 }
76
77 /***********************************************************************
78  *              ShowCursor (USER.71)
79  */
80 INT16 WINAPI ShowCursor16(BOOL16 bShow)
81 {
82   return ShowCursor(bShow);
83 }
84
85 /***********************************************************************
86  *              DrawIcon (USER.84)
87  */
88 BOOL16 WINAPI DrawIcon16(HDC16 hdc, INT16 x, INT16 y, HICON16 hIcon)
89 {
90   return DrawIcon(HDC_32(hdc), x, y, HICON_32(hIcon));
91 }
92
93
94 /***********************************************************************
95  *           DrawText    (USER.85)
96  */
97 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 count, LPRECT16 rect, UINT16 flags )
98 {
99     INT16 ret;
100
101     if (rect)
102     {
103         RECT rect32;
104         CONV_RECT16TO32( rect, &rect32 );
105         ret = DrawTextA( HDC_32(hdc), str, count, &rect32, flags );
106         CONV_RECT32TO16( &rect32, rect );
107     }
108     else ret = DrawTextA( HDC_32(hdc), str, count, NULL, flags);
109     return ret;
110 }
111
112
113 /***********************************************************************
114  *              IconSize (USER.86)
115  *
116  * See "Undocumented Windows". Used by W2.0 paint.exe.
117  */
118 DWORD WINAPI IconSize16(void)
119 {
120   return MAKELONG(GetSystemMetrics(SM_CYICON), GetSystemMetrics(SM_CXICON));
121 }
122
123
124 /**********************************************************************
125  *         CreateMenu    (USER.151)
126  */
127 HMENU16 WINAPI CreateMenu16(void)
128 {
129     return HMENU_16( CreateMenu() );
130 }
131
132
133 /**********************************************************************
134  *         DestroyMenu    (USER.152)
135  */
136 BOOL16 WINAPI DestroyMenu16( HMENU16 hMenu )
137 {
138     return DestroyMenu( HMENU_32(hMenu) );
139 }
140
141
142 /*******************************************************************
143  *         ChangeMenu    (USER.153)
144  */
145 BOOL16 WINAPI ChangeMenu16( HMENU16 hMenu, UINT16 pos, SEGPTR data,
146                             UINT16 id, UINT16 flags )
147 {
148     if (flags & MF_APPEND) return AppendMenu16( hMenu, flags & ~MF_APPEND, id, data );
149
150     /* FIXME: Word passes the item id in 'pos' and 0 or 0xffff as id */
151     /* for MF_DELETE. We should check the parameters for all others */
152     /* MF_* actions also (anybody got a doc on ChangeMenu?). */
153
154     if (flags & MF_DELETE) return DeleteMenu16(hMenu, pos, flags & ~MF_DELETE);
155     if (flags & MF_CHANGE) return ModifyMenu16(hMenu, pos, flags & ~MF_CHANGE, id, data );
156     if (flags & MF_REMOVE) return RemoveMenu16(hMenu, flags & MF_BYPOSITION ? pos : id,
157                                                flags & ~MF_REMOVE );
158     /* Default: MF_INSERT */
159     return InsertMenu16( hMenu, pos, flags, id, data );
160 }
161
162
163 /*******************************************************************
164  *         CheckMenuItem    (USER.154)
165  */
166 BOOL16 WINAPI CheckMenuItem16( HMENU16 hMenu, UINT16 id, UINT16 flags )
167 {
168     return CheckMenuItem( HMENU_32(hMenu), id, flags );
169 }
170
171
172 /**********************************************************************
173  *         EnableMenuItem    (USER.155)
174  */
175 UINT16 WINAPI EnableMenuItem16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
176 {
177     return EnableMenuItem( HMENU_32(hMenu), wItemID, wFlags );
178 }
179
180
181 /**********************************************************************
182  *         GetSubMenu    (USER.159)
183  */
184 HMENU16 WINAPI GetSubMenu16( HMENU16 hMenu, INT16 nPos )
185 {
186     return HMENU_16( GetSubMenu( HMENU_32(hMenu), nPos ) );
187 }
188
189
190 /*******************************************************************
191  *         GetMenuString    (USER.161)
192  */
193 INT16 WINAPI GetMenuString16( HMENU16 hMenu, UINT16 wItemID,
194                               LPSTR str, INT16 nMaxSiz, UINT16 wFlags )
195 {
196     return GetMenuStringA( HMENU_32(hMenu), wItemID, str, nMaxSiz, wFlags );
197 }
198
199
200 /**********************************************************************
201  *              WinHelp (USER.171)
202  */
203 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
204                          DWORD dwData )
205 {
206     BOOL ret;
207     DWORD mutex_count;
208
209     /* We might call WinExec() */
210     ReleaseThunkLock(&mutex_count);
211
212     ret = WinHelpA(WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData));
213
214     RestoreThunkLock(mutex_count);
215     return ret;
216 }
217
218
219 /***********************************************************************
220  *              LoadCursor (USER.173)
221  */
222 HCURSOR16 WINAPI LoadCursor16(HINSTANCE16 hInstance, LPCSTR name)
223 {
224   return HCURSOR_16(LoadCursorA(HINSTANCE_32(hInstance), name));
225 }
226
227
228 /***********************************************************************
229  *              LoadIcon (USER.174)
230  */
231 HICON16 WINAPI LoadIcon16(HINSTANCE16 hInstance, LPCSTR name)
232 {
233   return HICON_16(LoadIconA(HINSTANCE_32(hInstance), name));
234 }
235
236 /**********************************************************************
237  *              LoadBitmap (USER.175)
238  */
239 HBITMAP16 WINAPI LoadBitmap16(HINSTANCE16 hInstance, LPCSTR name)
240 {
241   return HBITMAP_16(LoadBitmapA(HINSTANCE_32(hInstance), name));
242 }
243
244
245 /***********************************************************************
246  *           GrayString   (USER.185)
247  */
248 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
249                             LPARAM lParam, INT16 cch, INT16 x, INT16 y,
250                             INT16 cx, INT16 cy )
251 {
252     BOOL ret;
253
254     if (!gsprc) return GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), NULL,
255                                     (LPARAM)MapSL(lParam), cch, x, y, cx, cy );
256
257     if (cch == -1 || (cch && cx && cy))
258     {
259         /* lParam can be treated as an opaque pointer */
260         struct gray_string_info info;
261
262         info.proc  = gsprc;
263         info.param = lParam;
264         ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback,
265                            (LPARAM)&info, cch, x, y, cx, cy );
266     }
267     else  /* here we need some string conversions */
268     {
269         char *str16 = MapSL(lParam);
270         struct gray_string_info *info;
271
272         if (!cch) cch = strlen(str16);
273         if (!(info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) + cch ))) return FALSE;
274         info->proc  = gsprc;
275         info->param = lParam;
276         memcpy( info->str, str16, cch );
277         ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback_ptr,
278                            (LPARAM)info->str, cch, x, y, cx, cy );
279         HeapFree( GetProcessHeap(), 0, info );
280     }
281     return ret;
282 }
283
284
285 /***********************************************************************
286  *           TabbedTextOut    (USER.196)
287  */
288 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
289                              INT16 count, INT16 nb_tabs, const INT16 *tabs16, INT16 tab_org )
290 {
291     LONG ret;
292     INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(tabs) );
293     if (!tabs) return 0;
294     for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
295     ret = TabbedTextOutA( HDC_32(hdc), x, y, lpstr, count, nb_tabs, tabs, tab_org );
296     HeapFree( GetProcessHeap(), 0, tabs );
297     return ret;
298 }
299
300
301 /***********************************************************************
302  *           GetTabbedTextExtent    (USER.197)
303  */
304 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
305                                     INT16 nb_tabs, const INT16 *tabs16 )
306 {
307     LONG ret;
308     INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(tabs) );
309     if (!tabs) return 0;
310     for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
311     ret = GetTabbedTextExtentA( HDC_32(hdc), lpstr, count, nb_tabs, tabs );
312     HeapFree( GetProcessHeap(), 0, tabs );
313     return ret;
314 }
315
316
317 /*************************************************************************
318  *              ScrollDC (USER.221)
319  */
320 BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
321                           const RECT16 *cliprc, HRGN16 hrgnUpdate,
322                           LPRECT16 rcUpdate )
323 {
324     RECT rect32, clipRect32, rcUpdate32;
325     BOOL16 ret;
326
327     if (rect) CONV_RECT16TO32( rect, &rect32 );
328     if (cliprc) CONV_RECT16TO32( cliprc, &clipRect32 );
329     ret = ScrollDC( HDC_32(hdc), dx, dy, rect ? &rect32 : NULL,
330                     cliprc ? &clipRect32 : NULL, HRGN_32(hrgnUpdate),
331                     &rcUpdate32 );
332     if (rcUpdate) CONV_RECT32TO16( &rcUpdate32, rcUpdate );
333     return ret;
334 }
335
336 /***********************************************************************
337  *              GetCursor (USER.247)
338  */
339 HCURSOR16 WINAPI GetCursor16(void)
340 {
341   return HCURSOR_16(GetCursor());
342 }
343
344
345 /**********************************************************************
346  *         GetMenuState    (USER.250)
347  */
348 UINT16 WINAPI GetMenuState16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
349 {
350     return GetMenuState( HMENU_32(hMenu), wItemID, wFlags );
351 }
352
353
354 /**********************************************************************
355  *         GetMenuItemCount    (USER.263)
356  */
357 INT16 WINAPI GetMenuItemCount16( HMENU16 hMenu )
358 {
359     return GetMenuItemCount( HMENU_32(hMenu) );
360 }
361
362
363 /**********************************************************************
364  *         GetMenuItemID    (USER.264)
365  */
366 UINT16 WINAPI GetMenuItemID16( HMENU16 hMenu, INT16 nPos )
367 {
368     return GetMenuItemID( HMENU_32(hMenu), nPos );
369 }
370
371
372 /***********************************************************************
373  *              GlobalAddAtom (USER.268)
374  */
375 ATOM WINAPI GlobalAddAtom16(LPCSTR lpString)
376 {
377   return GlobalAddAtomA(lpString);
378 }
379
380 /***********************************************************************
381  *              GlobalDeleteAtom (USER.269)
382  */
383 ATOM WINAPI GlobalDeleteAtom16(ATOM nAtom)
384 {
385   return GlobalDeleteAtom(nAtom);
386 }
387
388 /***********************************************************************
389  *              GlobalFindAtom (USER.270)
390  */
391 ATOM WINAPI GlobalFindAtom16(LPCSTR lpString)
392 {
393   return GlobalFindAtomA(lpString);
394 }
395
396 /***********************************************************************
397  *              GlobalGetAtomName (USER.271)
398  */
399 UINT16 WINAPI GlobalGetAtomName16(ATOM nAtom, LPSTR lpBuffer, INT16 nSize)
400 {
401   return GlobalGetAtomNameA(nAtom, lpBuffer, nSize);
402 }
403
404
405 /***********************************************************************
406  *              GetSysColorBrush (USER.281)
407  */
408 HBRUSH16 WINAPI GetSysColorBrush16( INT16 index )
409 {
410     return HBRUSH_16( GetSysColorBrush(index) );
411 }
412
413
414 /***********************************************************************
415  *              SelectPalette (USER.282)
416  */
417 HPALETTE16 WINAPI SelectPalette16( HDC16 hdc, HPALETTE16 hpal, BOOL16 bForceBackground )
418 {
419     return HPALETTE_16( SelectPalette( HDC_32(hdc), HPALETTE_32(hpal), bForceBackground ));
420 }
421
422 /***********************************************************************
423  *              RealizePalette (USER.283)
424  */
425 UINT16 WINAPI RealizePalette16( HDC16 hdc )
426 {
427     return UserRealizePalette( HDC_32(hdc) );
428 }
429
430
431 /**********************************************************************
432  *              IsMenu    (USER.358)
433  */
434 BOOL16 WINAPI IsMenu16( HMENU16 hmenu )
435 {
436     return IsMenu( HMENU_32(hmenu) );
437 }
438
439
440 /**********************************************************************
441  *         SetMenuContextHelpId    (USER.384)
442  */
443 BOOL16 WINAPI SetMenuContextHelpId16( HMENU16 hMenu, DWORD dwContextHelpID)
444 {
445     return SetMenuContextHelpId( HMENU_32(hMenu), dwContextHelpID );
446 }
447
448
449 /**********************************************************************
450  *         GetMenuContextHelpId    (USER.385)
451  */
452 DWORD WINAPI GetMenuContextHelpId16( HMENU16 hMenu )
453 {
454     return GetMenuContextHelpId( HMENU_32(hMenu) );
455 }
456
457
458 /***********************************************************************
459  *              LoadImage (USER.389)
460  *
461  */
462 HANDLE16 WINAPI LoadImage16(HINSTANCE16 hinst, LPCSTR name, UINT16 type,
463                             INT16 desiredx, INT16 desiredy, UINT16 loadflags)
464 {
465   return HANDLE_16(LoadImageA(HINSTANCE_32(hinst), name, type, desiredx,
466                               desiredy, loadflags));
467 }
468
469 /******************************************************************************
470  *              CopyImage (USER.390) Creates new image and copies attributes to it
471  *
472  */
473 HICON16 WINAPI CopyImage16(HANDLE16 hnd, UINT16 type, INT16 desiredx,
474                            INT16 desiredy, UINT16 flags)
475 {
476   return HICON_16(CopyImage(HANDLE_32(hnd), (UINT)type, (INT)desiredx,
477                             (INT)desiredy, (UINT)flags));
478 }
479
480 /**********************************************************************
481  *              DrawIconEx (USER.394)
482  */
483 BOOL16 WINAPI DrawIconEx16(HDC16 hdc, INT16 xLeft, INT16 yTop, HICON16 hIcon,
484                            INT16 cxWidth, INT16 cyWidth, UINT16 istep,
485                            HBRUSH16 hbr, UINT16 flags)
486 {
487   return DrawIconEx(HDC_32(hdc), xLeft, yTop, HICON_32(hIcon), cxWidth, cyWidth,
488                     istep, HBRUSH_32(hbr), flags);
489 }
490
491 /**********************************************************************
492  *              GetIconInfo (USER.395)
493  */
494 BOOL16 WINAPI GetIconInfo16(HICON16 hIcon, LPICONINFO16 iconinfo)
495 {
496   ICONINFO ii32;
497   BOOL16 ret = GetIconInfo(HICON_32(hIcon), &ii32);
498
499   iconinfo->fIcon = ii32.fIcon;
500   iconinfo->xHotspot = ii32.xHotspot;
501   iconinfo->yHotspot = ii32.yHotspot;
502   iconinfo->hbmMask  = HBITMAP_16(ii32.hbmMask);
503   iconinfo->hbmColor = HBITMAP_16(ii32.hbmColor);
504   return ret;
505 }
506
507 /***********************************************************************
508  *              CreateCursor (USER.406)
509  */
510 HCURSOR16 WINAPI CreateCursor16(HINSTANCE16 hInstance,
511                                 INT16 xHotSpot, INT16 yHotSpot,
512                                 INT16 nWidth, INT16 nHeight,
513                                 LPCVOID lpANDbits, LPCVOID lpXORbits)
514 {
515   CURSORICONINFO info;
516
517   info.ptHotSpot.x = xHotSpot;
518   info.ptHotSpot.y = yHotSpot;
519   info.nWidth = nWidth;
520   info.nHeight = nHeight;
521   info.nWidthBytes = 0;
522   info.bPlanes = 1;
523   info.bBitsPerPixel = 1;
524
525   return CreateCursorIconIndirect16(hInstance, &info, lpANDbits, lpXORbits);
526 }
527
528
529 /*******************************************************************
530  *         InsertMenu    (USER.410)
531  */
532 BOOL16 WINAPI InsertMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
533                             UINT16 id, SEGPTR data )
534 {
535     UINT pos32 = (UINT)pos;
536     if ((pos == (UINT16)-1) && (flags & MF_BYPOSITION)) pos32 = (UINT)-1;
537     if (IS_MENU_STRING_ITEM(flags) && data)
538         return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, MapSL(data) );
539     return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, (LPSTR)data );
540 }
541
542
543 /*******************************************************************
544  *         AppendMenu    (USER.411)
545  */
546 BOOL16 WINAPI AppendMenu16(HMENU16 hMenu, UINT16 flags, UINT16 id, SEGPTR data)
547 {
548     return InsertMenu16( hMenu, -1, flags | MF_BYPOSITION, id, data );
549 }
550
551
552 /**********************************************************************
553  *         RemoveMenu   (USER.412)
554  */
555 BOOL16 WINAPI RemoveMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
556 {
557     return RemoveMenu( HMENU_32(hMenu), nPos, wFlags );
558 }
559
560
561 /**********************************************************************
562  *         DeleteMenu    (USER.413)
563  */
564 BOOL16 WINAPI DeleteMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
565 {
566     return DeleteMenu( HMENU_32(hMenu), nPos, wFlags );
567 }
568
569
570 /*******************************************************************
571  *         ModifyMenu    (USER.414)
572  */
573 BOOL16 WINAPI ModifyMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
574                             UINT16 id, SEGPTR data )
575 {
576     if (IS_MENU_STRING_ITEM(flags))
577         return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, MapSL(data) );
578     return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, (LPSTR)data );
579 }
580
581
582 /**********************************************************************
583  *         CreatePopupMenu    (USER.415)
584  */
585 HMENU16 WINAPI CreatePopupMenu16(void)
586 {
587     return HMENU_16( CreatePopupMenu() );
588 }
589
590
591 /**********************************************************************
592  *         SetMenuItemBitmaps    (USER.418)
593  */
594 BOOL16 WINAPI SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags,
595                                     HBITMAP16 hNewUnCheck, HBITMAP16 hNewCheck)
596 {
597     return SetMenuItemBitmaps( HMENU_32(hMenu), nPos, wFlags,
598                                HBITMAP_32(hNewUnCheck), HBITMAP_32(hNewCheck) );
599 }
600
601
602 /*******************************************************************
603  *              InsertMenuItem   (USER.441)
604  *
605  * FIXME: untested
606  */
607 BOOL16 WINAPI InsertMenuItem16( HMENU16 hmenu, UINT16 pos, BOOL16 byposition,
608                                 const MENUITEMINFO16 *mii )
609 {
610     MENUITEMINFOA miia;
611
612     miia.cbSize        = sizeof(miia);
613     miia.fMask         = mii->fMask;
614     miia.dwTypeData    = (LPSTR)mii->dwTypeData;
615     miia.fType         = mii->fType;
616     miia.fState        = mii->fState;
617     miia.wID           = mii->wID;
618     miia.hSubMenu      = HMENU_32(mii->hSubMenu);
619     miia.hbmpChecked   = HBITMAP_32(mii->hbmpChecked);
620     miia.hbmpUnchecked = HBITMAP_32(mii->hbmpUnchecked);
621     miia.dwItemData    = mii->dwItemData;
622     miia.cch           = mii->cch;
623     if (IS_MENU_STRING_ITEM(miia.fType))
624         miia.dwTypeData = MapSL(mii->dwTypeData);
625     return InsertMenuItemA( HMENU_32(hmenu), pos, byposition, &miia );
626 }
627
628
629 /**********************************************************************
630  *              CreateIconFromResourceEx (USER.450)
631  *
632  * FIXME: not sure about exact parameter types
633  */
634 HICON16 WINAPI CreateIconFromResourceEx16(LPBYTE bits, UINT16 cbSize,
635                                           BOOL16 bIcon, DWORD dwVersion,
636                                           INT16 width, INT16 height,
637                                           UINT16 cFlag)
638 {
639   return HICON_16(CreateIconFromResourceEx(bits, cbSize, bIcon, dwVersion,
640                                            width, height, cFlag));
641 }
642
643 /***********************************************************************
644  *              DestroyIcon (USER.457)
645  */
646 BOOL16 WINAPI DestroyIcon16(HICON16 hIcon)
647 {
648   return DestroyIcon32(hIcon, 0);
649 }
650
651 /***********************************************************************
652  *              DestroyCursor (USER.458)
653  */
654 BOOL16 WINAPI DestroyCursor16(HCURSOR16 hCursor)
655 {
656   return DestroyIcon32(hCursor, 0);
657 }
658
659 /*******************************************************************
660  *                      DRAG_QueryUpdate16
661  *
662  * Recursively find a child that contains spDragInfo->pt point
663  * and send WM_QUERYDROPOBJECT. Helper for DragObject16.
664  */
665 static BOOL DRAG_QueryUpdate16( HWND hQueryWnd, SEGPTR spDragInfo )
666 {
667     BOOL bResult = 0;
668     WPARAM wParam;
669     POINT pt, old_pt;
670     LPDRAGINFO16 ptrDragInfo = MapSL(spDragInfo);
671     RECT tempRect;
672     HWND child;
673
674     if (!IsWindowEnabled(hQueryWnd)) return FALSE;
675
676     old_pt.x = ptrDragInfo->pt.x;
677     old_pt.y = ptrDragInfo->pt.y;
678     pt = old_pt;
679     ScreenToClient( hQueryWnd, &pt );
680     child = ChildWindowFromPointEx( hQueryWnd, pt, CWP_SKIPINVISIBLE );
681     if (!child) return FALSE;
682
683     if (child != hQueryWnd)
684     {
685         wParam = 0;
686         if (DRAG_QueryUpdate16( child, spDragInfo )) return TRUE;
687     }
688     else
689     {
690         GetClientRect( hQueryWnd, &tempRect );
691         wParam = !PtInRect( &tempRect, pt );
692     }
693
694     ptrDragInfo->pt.x = pt.x;
695     ptrDragInfo->pt.y = pt.y;
696     ptrDragInfo->hScope = HWND_16(hQueryWnd);
697
698     bResult = SendMessage16( HWND_16(hQueryWnd), WM_QUERYDROPOBJECT, wParam, spDragInfo );
699
700     if (!bResult)
701     {
702         ptrDragInfo->pt.x = old_pt.x;
703         ptrDragInfo->pt.y = old_pt.y;
704     }
705     return bResult;
706 }
707
708
709 /******************************************************************************
710  *              DragObject (USER.464)
711  */
712 DWORD WINAPI DragObject16( HWND16 hwndScope, HWND16 hWnd, UINT16 wObj,
713                            HANDLE16 hOfStruct, WORD szList, HCURSOR16 hCursor )
714 {
715     MSG msg;
716     LPDRAGINFO16 lpDragInfo;
717     SEGPTR      spDragInfo;
718     HCURSOR     hOldCursor=0, hBummer=0;
719     HGLOBAL16   hDragInfo  = GlobalAlloc16( GMEM_SHARE | GMEM_ZEROINIT, 2*sizeof(DRAGINFO16));
720     HCURSOR     hCurrentCursor = 0;
721     HWND16      hCurrentWnd = 0;
722
723     lpDragInfo = (LPDRAGINFO16) GlobalLock16(hDragInfo);
724     spDragInfo = K32WOWGlobalLock16(hDragInfo);
725
726     if( !lpDragInfo || !spDragInfo ) return 0L;
727
728     if (!(hBummer = LoadCursorA(0, MAKEINTRESOURCEA(OCR_NO))))
729     {
730         GlobalFree16(hDragInfo);
731         return 0L;
732     }
733
734     if(hCursor) hOldCursor = SetCursor(HCURSOR_32(hCursor));
735
736     lpDragInfo->hWnd   = hWnd;
737     lpDragInfo->hScope = 0;
738     lpDragInfo->wFlags = wObj;
739     lpDragInfo->hList  = szList; /* near pointer! */
740     lpDragInfo->hOfStruct = hOfStruct;
741     lpDragInfo->l = 0L;
742
743     SetCapture( HWND_32(hWnd) );
744     ShowCursor( TRUE );
745
746     do
747     {
748         GetMessageW( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST );
749
750        *(lpDragInfo+1) = *lpDragInfo;
751
752         lpDragInfo->pt.x = msg.pt.x;
753         lpDragInfo->pt.y = msg.pt.y;
754
755         /* update DRAGINFO struct */
756         if( DRAG_QueryUpdate16(WIN_Handle32(hwndScope), spDragInfo) > 0 )
757             hCurrentCursor = HCURSOR_32(hCursor);
758         else
759         {
760             hCurrentCursor = hBummer;
761             lpDragInfo->hScope = 0;
762         }
763         if( hCurrentCursor )
764             SetCursor(hCurrentCursor);
765
766         /* send WM_DRAGLOOP */
767         SendMessage16( hWnd, WM_DRAGLOOP, (WPARAM16)(hCurrentCursor != hBummer),
768                                           (LPARAM) spDragInfo );
769         /* send WM_DRAGSELECT or WM_DRAGMOVE */
770         if( hCurrentWnd != lpDragInfo->hScope )
771         {
772             if( hCurrentWnd )
773                 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 0,
774                        (LPARAM)MAKELONG(LOWORD(spDragInfo)+sizeof(DRAGINFO16),
775                                         HIWORD(spDragInfo)) );
776             hCurrentWnd = lpDragInfo->hScope;
777             if( hCurrentWnd )
778                 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 1, (LPARAM)spDragInfo);
779         }
780         else
781             if( hCurrentWnd )
782                 SendMessage16( hCurrentWnd, WM_DRAGMOVE, 0, (LPARAM)spDragInfo);
783
784     } while( msg.message != WM_LBUTTONUP && msg.message != WM_NCLBUTTONUP );
785
786     ReleaseCapture();
787     ShowCursor( FALSE );
788
789     if( hCursor ) SetCursor(hOldCursor);
790
791     if( hCurrentCursor != hBummer )
792         msg.lParam = SendMessage16( lpDragInfo->hScope, WM_DROPOBJECT,
793                                    (WPARAM16)hWnd, (LPARAM)spDragInfo );
794     else
795         msg.lParam = 0;
796     GlobalFree16(hDragInfo);
797
798     return (DWORD)(msg.lParam);
799 }
800
801
802 /**********************************************************************
803  *          DrawFrameControl  (USER.656)
804  */
805 BOOL16 WINAPI DrawFrameControl16( HDC16 hdc, LPRECT16 rc, UINT16 uType, UINT16 uState )
806 {
807     RECT rect32;
808     BOOL ret;
809
810     CONV_RECT16TO32( rc, &rect32 );
811     ret = DrawFrameControl( HDC_32(hdc), &rect32, uType, uState );
812     CONV_RECT32TO16( &rect32, rc );
813     return ret;
814 }
815
816 /**********************************************************************
817  *          DrawEdge   (USER.659)
818  */
819 BOOL16 WINAPI DrawEdge16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
820 {
821     RECT rect32;
822     BOOL ret;
823
824     CONV_RECT16TO32( rc, &rect32 );
825     ret = DrawEdge( HDC_32(hdc), &rect32, edge, flags );
826     CONV_RECT32TO16( &rect32, rc );
827     return ret;
828 }
829
830 /**********************************************************************
831  *              CheckMenuRadioItem (USER.666)
832  */
833 BOOL16 WINAPI CheckMenuRadioItem16(HMENU16 hMenu, UINT16 first, UINT16 last,
834                                    UINT16 check, BOOL16 bypos)
835 {
836      return CheckMenuRadioItem( HMENU_32(hMenu), first, last, check, bypos );
837 }