1 /*
2  * Unit tests for menus
3  *
4  * Copyright 2005 Robert Shearman
5  * Copyright 2007 Dmitry Timoshkov
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21 
22 //#define _WIN32_WINNT 0x0501
23 
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <assert.h>
28 
29 #define OEMRESOURCE         /* For OBM_MNARROW */
30 
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35 
36 #include "wine/test.h"
37 
38 static ATOM atomMenuCheckClass;
39 
40 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
41 static BOOL (WINAPI *pGetMenuBarInfo)(HWND,LONG,LONG,PMENUBARINFO);
42 static UINT (WINAPI *pSendInput)(UINT, INPUT*, size_t);
43 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
44 static BOOL (WINAPI *pEndMenu) (void);
45 
46 static void init_function_pointers(void)
47 {
48     HMODULE hdll = GetModuleHandleA("user32");
49 
50 #define GET_PROC(func) \
51     p ## func = (void*)GetProcAddress(hdll, #func); \
52     if(!p ## func) \
53       trace("GetProcAddress(%s) failed\n", #func);
54 
55     GET_PROC(GetMenuInfo)
56     GET_PROC(GetMenuBarInfo)
57     GET_PROC(SendInput)
58     GET_PROC(SetMenuInfo)
59     GET_PROC(EndMenu)
60 
61 #undef GET_PROC
62 }
63 
64 static BOOL correct_behavior(void)
65 {
66     HMENU hmenu;
67     MENUITEMINFOA info;
68     BOOL rc;
69 
70     hmenu = CreateMenu();
71 
72     memset(&info, 0, sizeof(MENUITEMINFOA));
73     info.cbSize= sizeof(MENUITEMINFOA);
74     SetLastError(0xdeadbeef);
75     rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info);
76     /* Win9x  : 0xdeadbeef
77      * NT4    : ERROR_INVALID_PARAMETER
78      * >= W2K : ERROR_MENU_ITEM_NOT_FOUND
79      */
80     if (!rc && GetLastError() != ERROR_MENU_ITEM_NOT_FOUND)
81     {
82         win_skip("NT4 and below can't handle a bigger MENUITEMINFO struct\n");
83         DestroyMenu(hmenu);
84         return FALSE;
85     }
86 
87     DestroyMenu(hmenu);
88     return TRUE;
89 }
90 
91 static LRESULT WINAPI menu_check_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
92 {
93     switch (msg)
94     {
95     case WM_ENTERMENULOOP:
96         /* mark window as having entered menu loop */
97         SetWindowLongPtrA(hwnd, GWLP_USERDATA, TRUE);
98         /* exit menu modal loop
99          * ( A SendMessage does not work on NT3.51 here ) */
100         return PostMessageA(hwnd, WM_CANCELMODE, 0, 0);
101     }
102     return DefWindowProcA(hwnd, msg, wparam, lparam);
103 }
104 
105 /* The MSVC headers ignore our NONAMELESSUNION requests so we have to define
106  * our own type */
107 typedef struct
108 {
109     DWORD type;
110     union
111     {
112         MOUSEINPUT      mi;
113         KEYBDINPUT      ki;
114         HARDWAREINPUT   hi;
115     } u;
116 } TEST_INPUT;
117 
118 /* globals to communicate between test and wndproc */
119 
120 static BOOL bMenuVisible;
121 static INT popmenu;
122 static BOOL got_input;
123 static HMENU hMenus[4];
124 
125 #define MOD_SIZE 10
126 #define MOD_NRMENUS 8
127 
128  /* menu texts with their sizes */
129 static struct {
130     LPCSTR text;
131     SIZE size; /* size of text up to any \t */
132     SIZE sc_size; /* size of the short-cut */
133 } MOD_txtsizes[] = {
134         { "Pinot &Noir" },
135         { "&Merlot\bF4" },
136         { "Shira&z\tAlt+S" },
137         { "" },
138         { NULL }
139 };
140 
141 static unsigned int MOD_maxid;
142 static RECT MOD_rc[MOD_NRMENUS];
143 static int MOD_avec, MOD_hic;
144 static int MOD_odheight;
145 static SIZE MODsizes[MOD_NRMENUS]= { {MOD_SIZE, MOD_SIZE},{MOD_SIZE, MOD_SIZE},
146     {MOD_SIZE, MOD_SIZE},{MOD_SIZE, MOD_SIZE}};
147 static BOOL MOD_GotDrawItemMsg = FALSE;
148 static int  gflag_initmenupopup,
149             gflag_entermenuloop,
150             gflag_initmenu,
151             gflag_enteridle;
152 static WPARAM selectitem_wp;
153 static LPARAM selectitem_lp;
154 
155 /* wndproc used by test_menu_ownerdraw() */
156 static LRESULT WINAPI menu_ownerdraw_wnd_proc(HWND hwnd, UINT msg,
157         WPARAM wparam, LPARAM lparam)
158 {
159     static HMENU hmenupopup;
160     switch (msg)
161     {
162         case WM_INITMENUPOPUP:
163             gflag_initmenupopup++;
164             hmenupopup = (HMENU) wparam;
165             break;
166         case WM_ENTERMENULOOP:
167             gflag_entermenuloop++;
168             break;
169         case WM_INITMENU:
170             gflag_initmenu++;
171             break;
172         case WM_MEASUREITEM:
173             {
174                 MEASUREITEMSTRUCT* pmis = (MEASUREITEMSTRUCT*)lparam;
175                 if (winetest_debug > 1)
176                     trace("WM_MEASUREITEM received data %lx size %dx%d\n",
177                             pmis->itemData, pmis->itemWidth, pmis->itemHeight);
178                 ok( !wparam, "wrong wparam %lx\n", wparam );
179                 ok( pmis->CtlType == ODT_MENU, "wrong type %x\n", pmis->CtlType );
180                 MOD_odheight = pmis->itemHeight;
181                 pmis->itemWidth = MODsizes[pmis->itemData].cx;
182                 pmis->itemHeight = MODsizes[pmis->itemData].cy;
183                 return TRUE;
184             }
185         case WM_DRAWITEM:
186             {
187                 DRAWITEMSTRUCT * pdis;
188                 TEXTMETRICA tm;
189                 HPEN oldpen;
190                 char chrs[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
191                 SIZE sz;
192                 int i;
193                 pdis = (DRAWITEMSTRUCT *) lparam;
194                 if (winetest_debug > 1) {
195                     RECT rc;
196                     GetMenuItemRect( hwnd, (HMENU)pdis->hwndItem, pdis->itemData ,&rc);
197                     trace("WM_DRAWITEM received hwnd %p hmenu %p itemdata %ld item %d rc %s itemrc:  %s\n",
198                             hwnd, pdis->hwndItem, pdis->itemData, pdis->itemID,
199                             wine_dbgstr_rect(&pdis->rcItem), wine_dbgstr_rect(&rc));
200                     oldpen=SelectObject( pdis->hDC, GetStockObject(
201                                 pdis->itemState & ODS_SELECTED ? WHITE_PEN :BLACK_PEN));
202                     Rectangle( pdis->hDC, pdis->rcItem.left,pdis->rcItem.top,
203                             pdis->rcItem.right,pdis->rcItem.bottom );
204                     SelectObject( pdis->hDC, oldpen);
205                 }
206                 ok( !wparam, "wrong wparam %lx\n", wparam );
207                 ok( pdis->CtlType == ODT_MENU, "wrong type %x\n", pdis->CtlType );
208                 /* calculate widths of some menu texts */
209                 if( ! MOD_txtsizes[0].size.cx)
210                     for(i = 0; MOD_txtsizes[i].text; i++) {
211                         char buf[100], *p;
212                         RECT rc={0,0,0,0};
213                         strcpy( buf, MOD_txtsizes[i].text);
214                         if( ( p = strchr( buf, '\t'))) {
215                             *p = '\0';
216                             DrawTextA( pdis->hDC, p + 1, -1, &rc,
217                                     DT_SINGLELINE|DT_CALCRECT);
218                             MOD_txtsizes[i].sc_size.cx= rc.right - rc.left;
219                             MOD_txtsizes[i].sc_size.cy= rc.bottom - rc.top;
220                         }
221                         DrawTextA( pdis->hDC, buf, -1, &rc,
222                                 DT_SINGLELINE|DT_CALCRECT);
223                         MOD_txtsizes[i].size.cx= rc.right - rc.left;
224                         MOD_txtsizes[i].size.cy= rc.bottom - rc.top;
225                     }
226 
227                 if( pdis->itemData > MOD_maxid) return TRUE;
228                 /* store the rectangle */
229                 MOD_rc[pdis->itemData] = pdis->rcItem;
230                 /* calculate average character width */
231                 GetTextExtentPointA( pdis->hDC, chrs, 52, &sz );
232                 MOD_avec = (sz.cx + 26)/52;
233                 GetTextMetricsA( pdis->hDC, &tm);
234                 MOD_hic = tm.tmHeight;
235                 MOD_GotDrawItemMsg = TRUE;
236                 return TRUE;
237             }
238         case WM_ENTERIDLE:
239             {
240                 gflag_enteridle++;
241                 ok( lparam || broken(!lparam), /* win9x, nt4 */
242                     "Menu window handle is NULL!\n");
243                 if( lparam) {
244                     HMENU hmenu = (HMENU)SendMessageA( (HWND)lparam, MN_GETHMENU, 0, 0);
245                     ok( hmenupopup == hmenu, "MN_GETHMENU returns %p expected %p\n",
246                         hmenu, hmenupopup);
247                 }
248                 PostMessageA(hwnd, WM_CANCELMODE, 0, 0);
249                 return TRUE;
250             }
251         case WM_MENUSELECT:
252             selectitem_wp = wparam;
253             selectitem_lp = lparam;
254             break;
255     }
256     return DefWindowProcA(hwnd, msg, wparam, lparam);
257 }
258 
259 static void register_menu_check_class(void)
260 {
261     WNDCLASSA wc =
262     {
263         0,
264         menu_check_wnd_proc,
265         0,
266         0,
267         GetModuleHandleA(NULL),
268         NULL,
269         LoadCursorA(NULL, (LPCSTR)IDC_ARROW),
270         (HBRUSH)(COLOR_BTNFACE+1),
271         NULL,
272         "WineMenuCheck",
273     };
274 
275     atomMenuCheckClass = RegisterClassA(&wc);
276 }
277 
278 static void test_getmenubarinfo(void)
279 {
280     BOOL ret;
281     HMENU hmenu;
282     MENUBARINFO mbi;
283     RECT rcw, rci;
284     HWND hwnd;
285     INT err;
286 
287     if (!pGetMenuBarInfo) {
288         win_skip("GetMenuBarInfo is not available\n");
289         return;
290     }
291 
292     mbi.cbSize = sizeof(MENUBARINFO);
293 
294     hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
295             WS_SYSMENU | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
296             NULL, NULL, NULL, NULL);
297     ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
298 
299     /* no menu: getmenubarinfo should fail */
300     SetLastError(0xdeadbeef);
301     ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
302     err = GetLastError();
303     ok(ret == FALSE, "GetMenuBarInfo should not have been successful\n");
304     ok(err == 0xdeadbeef, "err = %d\n", err);
305 
306     /* create menubar, no items yet */
307     hmenu = CreateMenu();
308     ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
309 
310     ret = SetMenu(hwnd, hmenu);
311     ok(ret, "SetMenu failed with error %d\n", GetLastError());
312 
313     SetLastError(0xdeadbeef);
314     ret = pGetMenuBarInfo(NULL, OBJID_CLIENT, 0, &mbi);
315     err = GetLastError();
316     ok(!ret, "GetMenuBarInfo succeeded\n");
317     ok(err == ERROR_INVALID_WINDOW_HANDLE, "err = %d\n", err);
318 
319     SetLastError(0xdeadbeef);
320     ret = pGetMenuBarInfo(hwnd, OBJID_CLIENT, 0, &mbi);
321     err = GetLastError();
322     ok(!ret, "GetMenuBarInfo succeeded\n");
323     ok(err==ERROR_INVALID_MENU_HANDLE || broken(err==0xdeadbeef) /* NT, W2K, XP */, "err = %d\n", err);
324 
325     SetLastError(0xdeadbeef);
326     ret = pGetMenuBarInfo(hwnd, OBJID_MENU, -1, &mbi);
327     err = GetLastError();
328     ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
329     ok(err == 0xdeadbeef, "err = %d\n", err);
330 
331     mbi.cbSize = 1000;
332     SetLastError(0xdeadbeef);
333     ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
334     err = GetLastError();
335     ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
336     ok(err == ERROR_INVALID_PARAMETER, "err = %d\n", err);
337     mbi.cbSize = sizeof(MENUBARINFO);
338 
339     SetLastError(0xdeadbeef);
340     ret = pGetMenuBarInfo(hwnd, 123, 0, &mbi);
341     err = GetLastError();
342     ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
343     ok(err == 0xdeadbeef, "err = %d\n", err);
344 
345     ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
346     ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
347 
348     ok(mbi.rcBar.left == 0 && mbi.rcBar.top == 0 && mbi.rcBar.bottom == 0 && mbi.rcBar.right == 0,
349             "rcBar: Expected (0,0)-(0,0), got: %s\n", wine_dbgstr_rect(&mbi.rcBar));
350     ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n",
351             mbi.hMenu, hmenu);
352     ok(mbi.fBarFocused == 0, "fBarFocused: Got %d instead of 0.\n", mbi.fBarFocused);
353     ok(mbi.fFocused == 0, "fFocused: Got %d instead of 0.\n", mbi.fFocused);
354 
355     /* add some items */
356     ret = AppendMenuA(hmenu, MF_STRING , 100, "item 1");
357     ok(ret, "AppendMenu failed.\n");
358     ret = AppendMenuA(hmenu, MF_STRING , 101, "item 2");
359     ok(ret, "AppendMenu failed.\n");
360     ret = SetMenu(hwnd, hmenu);
361     ok(ret, "SetMenu failed with error %d\n", GetLastError());
362 
363     SetLastError(0xdeadbeef);
364     ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 200, &mbi);
365     err = GetLastError();
366     ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
367     ok(err == 0xdeadbeef, "err = %d\n", err);
368 
369     /* get info for the whole menu */
370     ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
371     ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
372 
373     /* calculate menu rectangle, from window rectangle and the position of the first item  */
374     ret = GetWindowRect(hwnd, &rcw);
375     ok(ret, "GetWindowRect failed.\n");
376     ret = GetMenuItemRect(hwnd, hmenu, 0, &rci);
377     ok(ret, "GetMenuItemRect failed.\n");
378     todo_wine ok(mbi.rcBar.left == rci.left && mbi.rcBar.top == rci.top &&
379             mbi.rcBar.bottom == rci.bottom && mbi.rcBar.right == rcw.right - rci.left + rcw.left,
380             "rcBar: Got %s instead of (%d,%d)-(%d,%d)\n", wine_dbgstr_rect(&mbi.rcBar),
381             rci.left, rci.top, rcw.right - rci.left + rcw.left, rci.bottom);
382     ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n", mbi.hMenu, hmenu);
383     ok(mbi.fBarFocused == 0, "fBarFocused: got %d instead of 0\n", mbi.fBarFocused);
384     ok(mbi.fFocused == 0, "fFocused: got %d instead of 0\n", mbi.fFocused);
385 
386     /* get info for item nr.2 */
387     ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 2, &mbi);
388     ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
389     ret = GetMenuItemRect(hwnd, hmenu, 1, &rci);
390     ok(ret, "GetMenuItemRect failed.\n");
391     ok(EqualRect(&mbi.rcBar, &rci), "rcBar: Got %s instead of %s\n", wine_dbgstr_rect(&mbi.rcBar),
392             wine_dbgstr_rect(&rci));
393     ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n", mbi.hMenu, hmenu);
394     ok(mbi.fBarFocused == 0, "fBarFocused: got %d instead of 0\n", mbi.fBarFocused);
395     ok(mbi.fFocused == 0, "fFocused: got %d instead of 0\n", mbi.fFocused);
396 
397     DestroyWindow(hwnd);
398 }
399 
400 static void test_system_menu(void)
401 {
402     WCHAR testW[] = {'t','e','s','t',0};
403     BOOL ret;
404     HMENU menu;
405     HWND hwnd;
406     MENUITEMINFOA info;
407     MENUITEMINFOW infoW;
408     char buffer[80];
409     char found[0x200];
410     int i, res;
411 
412     hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
413                            WS_SYSMENU | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
414                            NULL, NULL, NULL, NULL);
415     ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
416     menu = GetSystemMenu( hwnd, FALSE );
417     ok( menu != NULL, "no system menu\n" );
418 
419     for (i = 0xf000; i < 0xf200; i++)
420     {
421         memset( &info, 0xcc, sizeof(info) );
422         info.cbSize = sizeof(info);
423         info.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID;
424         info.dwTypeData = buffer;
425         info.cch = sizeof( buffer );
426         ret = GetMenuItemInfoA( menu, i, FALSE, &info );
427         if (ret) trace( "found %x: '%s'\n", i, buffer );
428         switch (i)
429         {
430         case SC_RESTORE:
431         case SC_SIZE:
432         case SC_MOVE:
433         case SC_MINIMIZE:
434         case SC_MAXIMIZE:
435         case SC_CLOSE:
436             ok( ret, "%x menu item not found\n", i );
437             break;
438         case SC_SCREENSAVE+1:  /* used for the 'About Wine' entry, don't test */
439             break;
440         default:
441             ok( !ret, "%x menu item found\n", i );
442             break;
443         }
444         found[i - 0xf000] = ret;
445     }
446 
447     for (i = 0xf000; i < 0xf200; i++)
448     {
449         res = CheckMenuItem( menu, i, 0 );
450         if (res == -1) ok( !found[i - 0xf000], "could not check existent item %x\n", i );
451         else ok( found[i - 0xf000], "could check non-existent item %x\n", i );
452 
453         res = EnableMenuItem( menu, i, 0 );
454         if (res == -1) ok( !found[i - 0xf000], "could not enable existent item %x\n", i );
455         else ok( found[i - 0xf000], "could enable non-existent item %x\n", i );
456 
457         res = GetMenuState( menu, i, 0 );
458         if (res == -1) ok( !found[i - 0xf000], "could not get state existent item %x\n", i );
459         else ok( found[i - 0xf000], "could get state of non-existent item %x\n", i );
460 
461         if (!found[i - 0xf000])  /* don't remove the existing ones */
462         {
463             ret = RemoveMenu( menu, i, 0 );
464             ok( !ret, "could remove non-existent item %x\n", i );
465         }
466 
467         ret = ModifyMenuA( menu, i, 0, i, "test" );
468         if (i == SC_TASKLIST) ok( ret, "failed to modify SC_TASKLIST\n" );
469         else if (!ret) ok( !found[i - 0xf000], "could not modify existent item %x\n", i );
470         else ok( found[i - 0xf000], "could modify non-existent item %x\n", i );
471 
472         ret = ModifyMenuW( menu, i, 0, i, testW );
473         if (i == SC_TASKLIST) ok( ret, "failed to modify SC_TASKLIST\n" );
474         else if (!ret) ok( !found[i - 0xf000], "could not modify existent item %x\n", i );
475         else ok( found[i - 0xf000], "could modify non-existent item %x\n", i );
476 
477         ret = ModifyMenuA( menu, i, MF_BYPOSITION, i, "test" );
478         ok( !ret, "could modify non-existent item %x\n", i );
479 
480         strcpy( buffer, "test" );
481         memset( &info, 0xcc, sizeof(info) );
482         info.cbSize = sizeof(info);
483         info.fMask = MIIM_STRING | MIIM_ID;
484         info.wID = i;
485         info.dwTypeData = buffer;
486         info.cch = strlen( buffer );
487         ret = SetMenuItemInfoA( menu, i, FALSE, &info );
488         if (i == SC_TASKLIST) ok( ret, "failed to set SC_TASKLIST\n" );
489         else if (!ret) ok( !found[i - 0xf000], "could not set existent item %x\n", i );
490         else ok( found[i - 0xf000], "could set non-existent item %x\n", i );
491         ret = SetMenuItemInfoA( menu, i, TRUE, &info );
492         ok( !ret, "could modify non-existent item %x\n", i );
493 
494         memset( &infoW, 0xcc, sizeof(infoW) );
495         infoW.cbSize = sizeof(infoW);
496         infoW.fMask = MIIM_STRING | MIIM_ID;
497         infoW.wID = i;
498         infoW.dwTypeData = testW;
499         infoW.cch = lstrlenW( testW );
500         ret = SetMenuItemInfoW( menu, i, FALSE, &infoW );
501         if (i == SC_TASKLIST) ok( ret, "failed to set SC_TASKLIST\n" );
502         else if (!ret) ok( !found[i - 0xf000], "could not set existent item %x\n", i );
503         else ok( found[i - 0xf000], "could set non-existent item %x\n", i );
504         ret = SetMenuItemInfoW( menu, i, TRUE, &infoW );
505         ok( !ret, "could modify non-existent item %x\n", i );
506     }
507 
508     /* confirm that SC_TASKLIST still does not exist */
509     for (i = 0xf000; i < 0xf200; i++)
510     {
511         memset( &info, 0xcc, sizeof(info) );
512         info.cbSize = sizeof(info);
513         info.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID;
514         info.dwTypeData = buffer;
515         info.cch = sizeof( buffer );
516         ret = GetMenuItemInfoA( menu, i, FALSE, &info );
517         switch (i)
518         {
519         case SC_RESTORE:
520         case SC_SIZE:
521         case SC_MOVE:
522         case SC_MINIMIZE:
523         case SC_MAXIMIZE:
524         case SC_CLOSE:
525             ok( ret, "%x menu item not found\n", i );
526             break;
527         case SC_SCREENSAVE+1:  /* used for the 'About Wine' entry, don't test */
528             break;
529         default:
530             ok( !ret, "%x menu item found\n", i );
531             break;
532         }
533     }
534 
535     /* now a normal (non-system) menu */
536 
537     menu = CreateMenu();
538     ok( menu != NULL, "CreateMenu failed with error %d\n", GetLastError() );
539 
540     res = CheckMenuItem( menu, SC_TASKLIST, 0 );
541     ok( res == -1, "CheckMenuItem succeeded\n" );
542     res = EnableMenuItem( menu, SC_TASKLIST, 0 );
543     ok( res == -1, "EnableMenuItem succeeded\n" );
544     res = GetMenuState( menu, SC_TASKLIST, 0 );
545     ok( res == -1, "GetMenuState succeeded\n" );
546     ret = RemoveMenu( menu, SC_TASKLIST, 0 );
547     ok( !ret, "RemoveMenu succeeded\n" );
548     ret = ModifyMenuA( menu, SC_TASKLIST, 0, SC_TASKLIST, "test" );
549     ok( ret, "ModifyMenuA failed err %d\n", GetLastError() );
550     ret = ModifyMenuW( menu, SC_TASKLIST, 0, SC_TASKLIST, testW );
551     ok( ret, "ModifyMenuW failed err %d\n", GetLastError() );
552     ret = ModifyMenuA( menu, SC_TASKLIST-1, 0, SC_TASKLIST, "test" );
553     ok( !ret, "ModifyMenu succeeded on SC_TASKLIST-1\n" );
554     strcpy( buffer, "test" );
555     memset( &info, 0xcc, sizeof(info) );
556     info.cbSize = sizeof(info);
557     info.fMask = MIIM_STRING | MIIM_ID;
558     info.wID = SC_TASKLIST;
559     info.dwTypeData = buffer;
560     info.cch = strlen( buffer );
561     ret = SetMenuItemInfoA( menu, SC_TASKLIST, FALSE, &info );
562     ok( ret, "failed to set SC_TASKLIST\n" );
563     ret = SetMenuItemInfoA( menu, SC_TASKLIST+1, FALSE, &info );
564     ok( !ret, "succeeded setting SC_TASKLIST+1\n" );
565     ret = SetMenuItemInfoA( menu, SC_TASKLIST, TRUE, &info );
566     ok( !ret, "succeeded setting by position\n" );
567 
568     memset( &infoW, 0xcc, sizeof(infoW) );
569     infoW.cbSize = sizeof(infoW);
570     infoW.fMask = MIIM_STRING | MIIM_ID;
571     infoW.wID = SC_TASKLIST;
572     infoW.dwTypeData = testW;
573     infoW.cch = lstrlenW( testW );
574     ret = SetMenuItemInfoW( menu, SC_TASKLIST, FALSE, &infoW );
575     ok( ret, "failed to set SC_TASKLIST\n" );
576     ret = SetMenuItemInfoW( menu, SC_TASKLIST+1, FALSE, &infoW );
577     ok( !ret, "succeeded setting SC_TASKLIST+1\n" );
578     ret = SetMenuItemInfoW( menu, SC_TASKLIST, TRUE, &infoW );
579     ok( !ret, "succeeded setting by position\n" );
580 
581     DestroyMenu( menu );
582     DestroyWindow( hwnd );
583 }
584 
585 /* demonstrates that windows locks the menu object so that it is still valid
586  * even after a client calls DestroyMenu on it */
587 static void test_menu_locked_by_window(void)
588 {
589     BOOL ret;
590     HMENU hmenu;
591     HWND hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
592                                WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
593                                NULL, NULL, NULL, NULL);
594     ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
595     hmenu = CreateMenu();
596     ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
597     ret = InsertMenuA(hmenu, 0, MF_STRING, 0, "&Test");
598     ok(ret, "InsertMenu failed with error %d\n", GetLastError());
599     ret = SetMenu(hwnd, hmenu);
600     ok(ret, "SetMenu failed with error %d\n", GetLastError());
601     ret = DestroyMenu(hmenu);
602     ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
603 
604     ret = DrawMenuBar(hwnd);
605     ok(ret, "DrawMenuBar failed with error %d\n", GetLastError());
606     ret = IsMenu(GetMenu(hwnd));
607     ok(!ret || broken(ret) /* nt4 */, "Menu handle should have been destroyed\n");
608 
609     SendMessageA(hwnd, WM_SYSCOMMAND, SC_KEYMENU, 0);
610     /* did we process the WM_INITMENU message? */
611     ret = GetWindowLongPtrA(hwnd, GWLP_USERDATA);
612     todo_wine {
613     ok(ret, "WM_INITMENU should have been sent\n");
614     }
615 
616     DestroyWindow(hwnd);
617 }
618 
619 /* demonstrates that subpopup's are locked
620  * even after a client calls DestroyMenu on it */
621 static LRESULT WINAPI subpopuplocked_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
622 {
623     HWND hwndmenu;
624     switch (msg)
625     {
626     case WM_ENTERIDLE:
627         hwndmenu = GetCapture();
628         if( hwndmenu) {
629             PostMessageA( hwndmenu, WM_KEYDOWN, VK_DOWN, 0);
630             PostMessageA( hwndmenu, WM_KEYDOWN, VK_RIGHT, 0);
631             PostMessageA( hwndmenu, WM_KEYDOWN, VK_RETURN, 0);
632         }
633     }
634     return DefWindowProcA(hwnd, msg, wparam, lparam);
635 }
636 
637 static void test_subpopup_locked_by_menu(void)
638 {
639     DWORD gle;
640     BOOL ret;
641     HMENU hmenu, hsubmenu;
642     MENUINFO mi = { sizeof( MENUINFO)};
643     MENUITEMINFOA mii = { sizeof( MENUITEMINFOA)};
644     HWND hwnd;
645     const int itemid = 0x1234567;
646     if( !pGetMenuInfo)
647     {
648         win_skip("GetMenuInfo is not available\n");
649         return;
650     }
651     /* create window, popupmenu with one subpopup */
652     hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
653             WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
654             NULL, NULL, NULL, NULL);
655     ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
656     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR) subpopuplocked_wnd_proc);
657     hmenu = CreatePopupMenu();
658     ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
659     hsubmenu = CreatePopupMenu();
660     ok(hsubmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
661     ret = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hsubmenu,
662             "PopUpLockTest");
663     ok(ret, "InsertMenu failed with error %d\n", GetLastError());
664     ret = InsertMenuA(hsubmenu, 0, MF_BYPOSITION | MF_STRING, itemid, "PopUpMenu");
665     ok(ret, "InsertMenu failed with error %d\n", GetLastError());
666     /* first some tests that all this functions properly */
667     mii.fMask = MIIM_SUBMENU;
668     ret = GetMenuItemInfoA( hmenu, 0, TRUE, &mii);
669     ok( ret, "GetMenuItemInfo failed error %d\n", GetLastError());
670     ok( mii.hSubMenu == hsubmenu, "submenu is %p\n", mii.hSubMenu);
671     mi.fMask |= MIM_STYLE;
672     ret = pGetMenuInfo( hsubmenu, &mi);
673     ok( ret , "GetMenuInfo returned 0 with error %d\n", GetLastError());
674     ret = IsMenu( hsubmenu);
675     ok( ret , "Menu handle is not valid\n");
676     SetLastError( 0xdeadbeef);
677     ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
678     if( ret == (itemid & 0xffff)) {
679         win_skip("not on 16 bit menu subsystem\n");
680         DestroyMenu( hsubmenu);
681     } else {
682         gle = GetLastError();
683         ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, gle);
684         ok( gle == 0 ||
685                 broken( gle == 0xdeadbeef), /* win2k0 */
686                 "Last error is %d\n", gle);
687         /* then destroy the sub-popup */
688         ret = DestroyMenu( hsubmenu);
689         ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
690         /* and repeat the tests */
691         mii.fMask = MIIM_SUBMENU;
692         ret = GetMenuItemInfoA( hmenu, 0, TRUE, &mii);
693         ok( ret, "GetMenuItemInfo failed error %d\n", GetLastError());
694         /* GetMenuInfo fails now */
695         ok( mii.hSubMenu == hsubmenu, "submenu is %p\n", mii.hSubMenu);
696         mi.fMask |= MIM_STYLE;
697         ret = pGetMenuInfo( hsubmenu, &mi);
698         ok( !ret , "GetMenuInfo should have failed\n");
699         /* IsMenu says it is not */
700         ret = IsMenu( hsubmenu);
701         ok( !ret , "Menu handle should be invalid\n");
702         /* but TrackPopupMenu still works! */
703         SetLastError( 0xdeadbeef);
704         ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
705         gle = GetLastError();
706         todo_wine {
707             ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, gle);
708         }
709         ok( gle == 0 ||
710             broken(gle == 0xdeadbeef) || /* wow64 */
711             broken(gle == ERROR_INVALID_PARAMETER), /* win2k0 */
712             "Last error is %d\n", gle);
713     }
714     /* clean up */
715     DestroyMenu( hmenu);
716     DestroyWindow(hwnd);
717 }
718 
719 static void test_menu_ownerdraw(void)
720 {
721     int i,j,k;
722     BOOL ret;
723     HMENU hmenu;
724     MENUITEMINFOA mii;
725     LONG leftcol;
726     HWND hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
727                                WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
728                                NULL, NULL, NULL, NULL);
729     ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
730     if( !hwnd) return;
731     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
732     hmenu = CreatePopupMenu();
733     ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
734     if( !hmenu) { DestroyWindow(hwnd);return;}
735     k=0;
736     for( j=0;j<2;j++) /* create columns */
737         for(i=0;i<2;i++) { /* create rows */
738             ret = AppendMenuA( hmenu, MF_OWNERDRAW |
739                               (i==0 ? MF_MENUBREAK : 0), k, (LPCSTR)MAKEINTRESOURCE(k));
740             k++;
741             ok( ret, "AppendMenu failed for %d\n", k-1);
742         }
743     MOD_maxid = k-1;
744     assert( k <= sizeof(MOD_rc)/sizeof(RECT));
745     /* display the menu */
746     TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
747 
748     /* columns have a 4 pixel gap between them */
749     ok( MOD_rc[0].right + 4 ==  MOD_rc[2].left,
750             "item rectangles are not separated by 4 pixels space\n");
751     /* height should be what the MEASUREITEM message has returned */
752     ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
753             "menu item has wrong height: %d should be %d\n",
754             MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
755     /* no gaps between the rows */
756     ok( MOD_rc[0].bottom - MOD_rc[1].top == 0,
757             "There should not be a space between the rows, gap is %d\n",
758             MOD_rc[0].bottom - MOD_rc[1].top);
759     /* test the correct value of the item height that was sent
760      * by the WM_MEASUREITEM message */
761     ok( MOD_odheight == HIWORD( GetDialogBaseUnits()) || /* WinNT,2k,XP */
762             MOD_odheight == MOD_hic,                     /* Win95,98,ME */
763             "Wrong height field in MEASUREITEMSTRUCT, expected %d or %d actual %d\n",
764             HIWORD( GetDialogBaseUnits()), MOD_hic, MOD_odheight);
765     /* test what MF_MENUBREAK did at the first position. Also show
766      * that an MF_SEPARATOR is ignored in the height calculation. */
767     leftcol= MOD_rc[0].left;
768     ModifyMenuA( hmenu, 0, MF_BYCOMMAND| MF_OWNERDRAW| MF_SEPARATOR, 0, 0);
769     /* display the menu */
770     TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
771     /* left should be 4 pixels less now */
772     ok( leftcol == MOD_rc[0].left + 4,
773             "columns should be 4 pixels to the left (actual %d).\n",
774             leftcol - MOD_rc[0].left);
775     /* test width */
776     ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
777             "width of owner drawn menu item is wrong. Got %d expected %d\n",
778             MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
779     /* and height */
780     ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
781             "Height is incorrect. Got %d expected %d\n",
782             MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
783 
784     /* test owner-drawn callback bitmap */
785     ModifyMenuA( hmenu, 1, MF_BYPOSITION | MFT_BITMAP, 1, (LPCSTR)HBMMENU_CALLBACK );
786     mii.cbSize = sizeof(mii);
787     mii.fMask = MIIM_BITMAP | MIIM_FTYPE | MIIM_ID;
788     if (GetMenuItemInfoA( hmenu, 1, TRUE, &mii ))
789     {
790         ok( mii.fType == MFT_BITMAP, "wrong type %x\n", mii.fType );
791         ok( mii.wID == 1, "wrong id %x\n", mii.wID );
792         ok( mii.hbmpItem == HBMMENU_CALLBACK, "wrong data %p\n", mii.hbmpItem );
793     }
794     TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
795 
796     /* test width/height of an ownerdraw menu bar as well */
797     ret = DestroyMenu(hmenu);
798     ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
799     hmenu = CreateMenu();
800     ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
801     if( !hmenu) { DestroyWindow(hwnd);return;}
802     MOD_maxid=1;
803     for(i=0;i<2;i++) {
804         ret = AppendMenuA( hmenu, MF_OWNERDRAW, i, 0 );
805         ok( ret, "AppendMenu failed for %d\n", i);
806     }
807     ret = SetMenu( hwnd, hmenu);
808     UpdateWindow( hwnd); /* hack for wine to draw the window + menu */
809     ok(ret, "SetMenu failed with error %d\n", GetLastError());
810     /* test width */
811     ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
812             "width of owner drawn menu item is wrong. Got %d expected %d\n",
813             MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
814     /* test height */
815     ok( MOD_rc[0].bottom - MOD_rc[0].top == GetSystemMetrics( SM_CYMENU) - 1,
816             "Height of owner drawn menu item is wrong. Got %d expected %d\n",
817             MOD_rc[0].bottom - MOD_rc[0].top, GetSystemMetrics( SM_CYMENU) - 1);
818 
819     /* clean up */
820     ret = DestroyMenu(hmenu);
821     ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
822     DestroyWindow(hwnd);
823 }
824 
825 /* helper for test_menu_bmp_and_string() */
826 static void test_mbs_help( int ispop, int hassub, int mnuopt,
827         HWND hwnd, int arrowwidth, int count, HBITMAP hbmp,
828         SIZE bmpsize, LPCSTR text, SIZE size, SIZE sc_size)
829 {
830     BOOL ret;
831     HMENU hmenu, submenu;
832     MENUITEMINFOA mii={ sizeof( MENUITEMINFOA )};
833     MENUINFO mi;
834     RECT rc;
835     CHAR text_copy[16];
836     int hastab,  expect;
837     BOOL failed = FALSE;
838 
839     MOD_GotDrawItemMsg = FALSE;
840     mii.fMask = MIIM_FTYPE | MIIM_DATA | MIIM_STATE;
841     mii.fType = 0;
842     /* check the menu item unless MNS_CHECKORBMP is set */
843     mii.fState = (mnuopt != 2 ? MFS_CHECKED : MFS_UNCHECKED);
844     mii.dwItemData =0;
845     MODsizes[0] = bmpsize;
846     hastab = 0;
847     if( text ) {
848         char *p;
849         mii.fMask |= MIIM_STRING;
850         strcpy(text_copy, text);
851         mii.dwTypeData = text_copy; /* structure member declared non-const */
852         if( ( p = strchr( text, '\t'))) {
853             hastab = *(p + 1) ? 2 : 1;
854         }
855     }
856     /* tabs don't make sense in menubars */
857     if(hastab && !ispop) return;
858     if( hbmp) {
859         mii.fMask |= MIIM_BITMAP;
860         mii.hbmpItem = hbmp;
861     }
862     submenu = CreateMenu();
863     ok( submenu != 0, "CreateMenu failed with error %d\n", GetLastError());
864     if( ispop)
865         hmenu = CreatePopupMenu();
866     else
867         hmenu = CreateMenu();
868     ok( hmenu != 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
869     if( hassub) {
870         mii.fMask |= MIIM_SUBMENU;
871         mii.hSubMenu = submenu;
872     }
873     if( mnuopt) {
874         mi.cbSize = sizeof(mi);
875         mi.fMask = MIM_STYLE;
876         pGetMenuInfo( hmenu, &mi);
877         if( mnuopt) mi.dwStyle |= mnuopt == 1 ? MNS_NOCHECK : MNS_CHECKORBMP;
878         ret = pSetMenuInfo( hmenu, &mi);
879         ok( ret, "SetMenuInfo failed with error %d\n", GetLastError());
880     }
881     ret = InsertMenuItemA( hmenu, 0, FALSE, &mii);
882     ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
883     failed = !ret;
884     if( winetest_debug) {
885         HDC hdc=GetDC(hwnd);
886         RECT rc = {100, 50, 400, 70};
887         char buf[100];
888 
889         sprintf( buf,"%d text \"%s\" mnuopt %d", count, text ? text: "(nil)", mnuopt);
890         FillRect( hdc, &rc, (HBRUSH) COLOR_WINDOW);
891         TextOutA( hdc, 10, 50, buf, strlen( buf));
892         ReleaseDC( hwnd, hdc);
893     }
894     if(ispop)
895         TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
896     else {
897         ret = SetMenu( hwnd, hmenu);
898         ok(ret, "SetMenu failed with error %d\n", GetLastError());
899         DrawMenuBar( hwnd);
900     }
901     ret = GetMenuItemRect( hwnd, hmenu, 0, &rc);
902     ok(ret, "GetMenuItemRect failed with error %d\n", GetLastError());
903 
904     if (0)  /* comment out menu size checks, behavior is different in almost every Windows version */
905             /* the tests should however succeed on win2000, XP and Wine (at least up to 1.1.15) */
906             /* with a variety of dpis and desktop font sizes */
907     {
908         /* check menu width */
909         if( ispop)
910             expect = ( text || hbmp ?
911                        4 + (mnuopt != 1 ? GetSystemMetrics(SM_CXMENUCHECK) : 0)
912                        : 0) +
913                        arrowwidth  + MOD_avec + (hbmp ?
914                                     ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ? bmpsize.cx + 2 : GetSystemMetrics( SM_CXMENUSIZE) + 2)
915                                     : 0) +
916                 (text && hastab ? /* TAB space */
917                  MOD_avec + ( hastab==2 ? sc_size.cx : 0) : 0) +
918                 (text ?  2 + (text[0] ? size.cx :0): 0) ;
919         else
920             expect = !(text || hbmp) ? 0 :
921                 ( hbmp ? (text ? 2:0) + bmpsize.cx  : 0 ) +
922                 (text ? 2 * MOD_avec + (text[0] ? size.cx :0): 0) ;
923         ok( rc.right - rc.left == expect,
924             "menu width wrong, got %d expected %d\n", rc.right - rc.left, expect);
925         failed = failed || !(rc.right - rc.left == expect);
926         /* check menu height */
927         if( ispop)
928             expect = max( ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 : 0),
929                           max( (text ? max( 2 + size.cy, MOD_hic + 4) : 0),
930                                (hbmp ?
931                                    ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ?
932                                        bmpsize.cy + 2
933                                      : GetSystemMetrics( SM_CYMENUSIZE) + 2)
934                                  : 0)));
935         else
936             expect = ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 :
937                        max( GetSystemMetrics( SM_CYMENU) - 1, (hbmp ? bmpsize.cy : 0)));
938         ok( rc.bottom - rc.top == expect,
939             "menu height wrong, got %d expected %d (%d)\n",
940             rc.bottom - rc.top, expect, GetSystemMetrics( SM_CYMENU));
941         failed = failed || !(rc.bottom - rc.top == expect);
942         if( hbmp == HBMMENU_CALLBACK && MOD_GotDrawItemMsg) {
943             /* check the position of the bitmap */
944             /* horizontal */
945             if (!ispop)
946                 expect = 3;
947             else if (mnuopt == 0)
948                 expect = 4 + GetSystemMetrics(SM_CXMENUCHECK);
949             else if (mnuopt == 1)
950                 expect = 4;
951             else /* mnuopt == 2 */
952                 expect = 2;
953             ok( expect == MOD_rc[0].left,
954                 "bitmap left is %d expected %d\n", MOD_rc[0].left, expect);
955             failed = failed || !(expect == MOD_rc[0].left);
956             /* vertical */
957             expect = (rc.bottom - rc.top - MOD_rc[0].bottom + MOD_rc[0].top) / 2;
958             ok( expect == MOD_rc[0].top,
959                 "bitmap top is %d expected %d\n", MOD_rc[0].top, expect);
960             failed = failed || !(expect == MOD_rc[0].top);
961         }
962     }
963     /* if there was a failure, report details */
964     if( failed) {
965         trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
966                 count, (ispop? "POPUP": "MENUBAR"),text ? text: "(nil)", hbmp, bmpsize.cx, bmpsize.cy,
967                 size.cx, size.cy, sc_size.cx, mnuopt, hastab);
968         trace("    check %d,%d arrow %d avechar %d\n",
969                 GetSystemMetrics(SM_CXMENUCHECK ),
970                 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
971         if( hbmp == HBMMENU_CALLBACK)
972             trace( "    rc %s bmp.rc %s\n", wine_dbgstr_rect(&rc), wine_dbgstr_rect(&MOD_rc[0]));
973     }
974     /* clean up */
975     ret = DestroyMenu(submenu);
976     ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
977     ret = DestroyMenu(hmenu);
978     ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
979 }
980 
981 
982 static void test_menu_bmp_and_string(void)
983 {
984     BYTE bmfill[300];
985     HBITMAP hbm_arrow;
986     BITMAP bm;
987     INT arrowwidth;
988     HWND hwnd;
989     HMENU hsysmenu;
990     MENUINFO mi= {sizeof(MENUINFO)};
991     MENUITEMINFOA mii= {sizeof(MENUITEMINFOA)};
992     int count, szidx, txtidx, bmpidx, hassub, mnuopt, ispop;
993     BOOL got;
994 
995     if( !pGetMenuInfo)
996     {
997         win_skip("GetMenuInfo is not available\n");
998         return;
999     }
1000 
1001     memset( bmfill, 0xcc, sizeof( bmfill));
1002     hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL, WS_SYSMENU |
1003                           WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
1004                           NULL, NULL, NULL, NULL);
1005     hbm_arrow = LoadBitmapA( 0, (LPCSTR)OBM_MNARROW);
1006     GetObjectA( hbm_arrow, sizeof(bm), &bm);
1007     arrowwidth = bm.bmWidth;
1008     ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
1009     if( !hwnd) return;
1010     /* test system menu */
1011     hsysmenu = GetSystemMenu( hwnd, FALSE);
1012     ok( hsysmenu != NULL, "GetSystemMenu failed with error %d\n", GetLastError());
1013     mi.fMask = MIM_STYLE;
1014     mi.dwStyle = 0;
1015     got = pGetMenuInfo( hsysmenu, &mi);
1016     ok( got, "GetMenuInfo failed gle=%d\n", GetLastError());
1017     ok( MNS_CHECKORBMP == mi.dwStyle, "System Menu Style is %08x, without the bit %08x\n",
1018         mi.dwStyle, MNS_CHECKORBMP);
1019     mii.fMask = MIIM_BITMAP;
1020     mii.hbmpItem = NULL;
1021     got = GetMenuItemInfoA( hsysmenu, SC_CLOSE, FALSE, &mii);
1022     ok( got, "GetMenuItemInfoA failed gle=%d\n", GetLastError());
1023     ok( HBMMENU_POPUP_CLOSE == mii.hbmpItem, "Item info did not get the right hbitmap: got %p  expected %p\n",
1024         mii.hbmpItem, HBMMENU_POPUP_CLOSE);
1025 
1026     memset(&mii, 0x81, sizeof(mii));
1027     mii.cbSize = sizeof(mii);
1028     mii.fMask  = MIIM_STATE | MIIM_ID | MIIM_TYPE | MIIM_DATA;
1029     mii.dwTypeData = (LPSTR)bmfill;
1030     mii.cch = sizeof(bmfill);
1031     mii.dwItemData = 0x81818181;
1032     got = GetMenuItemInfoA(hsysmenu, SC_RESTORE, FALSE, &mii);
1033     ok(got, "GetMenuItemInfo failed\n");
1034     ok((mii.fType & ~(MFT_RIGHTJUSTIFY|MFT_RIGHTORDER)) == MFT_STRING, "expected MFT_STRING, got %#x\n", mii.fType);
1035     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
1036     ok(mii.wID == SC_RESTORE, "expected SC_RESTORE, got %#x\n", mii.wID);
1037     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
1038     ok(mii.dwItemData == 0, "expected 0, got %#lx\n", mii.dwItemData);
1039     ok(mii.dwTypeData == (LPSTR)bmfill, "expected %p, got %p\n", bmfill, mii.dwTypeData);
1040     ok(mii.cch != 0, "cch should not be 0\n");
1041     ok(mii.hbmpItem == HBMMENU_POPUP_RESTORE, "expected HBMMENU_POPUP_RESTORE, got %p\n", mii.hbmpItem);
1042 
1043     mii.cbSize = sizeof(mii);
1044     mii.fMask = MIIM_TYPE;
1045     mii.hbmpItem = (HBITMAP)0x81818181;
1046     got = GetMenuItemInfoA(hsysmenu, SC_CLOSE, FALSE, &mii);
1047     ok(got, "GetMenuItemInfo failed\n");
1048     ok((mii.fType & ~(MFT_RIGHTJUSTIFY|MFT_RIGHTORDER)) == MFT_STRING, "expected MFT_STRING, got %#x\n", mii.fType);
1049     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
1050     ok(mii.wID == SC_RESTORE, "expected SC_RESTORE, got %#x\n", mii.wID);
1051     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
1052     ok(mii.dwItemData == 0, "expected 0, got %#lx\n", mii.dwItemData);
1053     ok(mii.dwTypeData == (LPSTR)bmfill, "expected %p, got %p\n", bmfill, mii.dwTypeData);
1054     ok(mii.cch != 0, "cch should not be 0\n");
1055     ok(mii.hbmpItem == HBMMENU_POPUP_CLOSE, "expected HBMMENU_POPUP_CLOSE, got %p\n", mii.hbmpItem);
1056 
1057     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
1058 
1059     if( winetest_debug)
1060         trace("    check %d,%d arrow %d avechar %d\n",
1061                 GetSystemMetrics(SM_CXMENUCHECK ),
1062                 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
1063     count = 0;
1064     MOD_maxid = 0;
1065     for( ispop=1; ispop >= 0; ispop--){
1066         static SIZE bmsizes[]= {
1067             {10,10},{38,38},{1,30},{55,5}};
1068         for( szidx=0; szidx < sizeof( bmsizes) / sizeof( SIZE); szidx++) {
1069             HBITMAP hbm = CreateBitmap( bmsizes[szidx].cx, bmsizes[szidx].cy,1,1,bmfill);
1070             HBITMAP bitmaps[] = { HBMMENU_CALLBACK, hbm, HBMMENU_POPUP_CLOSE, NULL  };
1071             ok( hbm != 0, "CreateBitmap failed err %d\n", GetLastError());
1072             for( txtidx = 0; txtidx < sizeof(MOD_txtsizes)/sizeof(MOD_txtsizes[0]); txtidx++) {
1073                 for( hassub = 0; hassub < 2 ; hassub++) { /* add submenu item */
1074                     for( mnuopt = 0; mnuopt < 3 ; mnuopt++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
1075                         for( bmpidx = 0; bmpidx <sizeof(bitmaps)/sizeof(HBITMAP); bmpidx++) {
1076                             /* no need to test NULL bitmaps of several sizes */
1077                             if( !bitmaps[bmpidx] && szidx > 0) continue;
1078                             /* the HBMMENU_POPUP not to test for menu bars */
1079                             if( !ispop &&
1080                                 bitmaps[bmpidx] >= HBMMENU_POPUP_CLOSE &&
1081                                 bitmaps[bmpidx] <= HBMMENU_POPUP_MINIMIZE) continue;
1082                             if( !ispop && hassub) continue;
1083                             test_mbs_help( ispop, hassub, mnuopt,
1084                                     hwnd, arrowwidth, ++count,
1085                                     bitmaps[bmpidx],
1086                                     bmsizes[szidx],
1087                                     MOD_txtsizes[txtidx].text,
1088                                     MOD_txtsizes[txtidx].size,
1089                                     MOD_txtsizes[txtidx].sc_size);
1090                         }
1091                     }
1092                 }
1093             }
1094             DeleteObject( hbm);
1095         }
1096     }
1097     /* clean up */
1098     DestroyWindow(hwnd);
1099 }
1100 
1101 static void test_menu_add_string( void )
1102 {
1103     HMENU hmenu;
1104     MENUITEMINFOA info;
1105     BOOL rc;
1106     int ret;
1107 
1108     char string[0x80];
1109     char string2[0x80];
1110 
1111     char strback[0x80];
1112     WCHAR strbackW[0x80];
1113     static CHAR blah[] = "blah";
1114     static const WCHAR expectedString[] = {'D','u','m','m','y',' ','s','t','r','i','n','g', 0};
1115 
1116     hmenu = CreateMenu();
1117 
1118     memset( &info, 0, sizeof info );
1119     info.cbSize = sizeof info;
1120     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_ID;
1121     info.dwTypeData = blah;
1122     info.cch = 6;
1123     info.dwItemData = 0;
1124     info.wID = 1;
1125     info.fState = 0;
1126     InsertMenuItemA(hmenu, 0, TRUE, &info );
1127 
1128     memset( &info, 0, sizeof info );
1129     info.cbSize = sizeof info;
1130     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_DATA | MIIM_ID;
1131     info.dwTypeData = string;
1132     info.cch = sizeof string;
1133     string[0] = 0;
1134     GetMenuItemInfoA( hmenu, 0, TRUE, &info );
1135 
1136     ok( !strcmp( string, "blah" ), "menu item name differed\n");
1137 
1138     /* Test combination of ownerdraw and strings with GetMenuItemString(A/W) */
1139     strcpy(string, "Dummy string");
1140     memset(&info, 0x00, sizeof(info));
1141     info.cbSize= sizeof(MENUITEMINFOA);
1142     info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
1143     info.fType= MFT_OWNERDRAW;
1144     info.dwTypeData= string;
1145     rc = InsertMenuItemA( hmenu, 0, TRUE, &info );
1146     ok (rc, "InsertMenuItem failed\n");
1147 
1148     strcpy(string,"Garbage");
1149     ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1150     ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
1151 
1152     SetLastError(0xdeadbeef);
1153     ret = GetMenuStringW( hmenu, 0, strbackW, 99, MF_BYPOSITION );
1154     if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1155         win_skip("GetMenuStringW is not implemented\n");
1156     else
1157     {
1158         ok (ret, "GetMenuStringW on ownerdraw entry failed\n");
1159         ok (!lstrcmpW( strbackW, expectedString ), "Menu text from Unicode version incorrect\n");
1160     }
1161 
1162     /* Just try some invalid parameter tests */
1163     SetLastError(0xdeadbeef);
1164     rc = SetMenuItemInfoA( hmenu, 0, TRUE, NULL );
1165     ret = GetLastError();
1166     ok (!rc, "SetMenuItemInfoA succeeded unexpectedly\n");
1167     ok (ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
1168 
1169     SetLastError(0xdeadbeef);
1170     rc = SetMenuItemInfoA( hmenu, 0, FALSE, NULL );
1171     ret = GetLastError();
1172     ok (!rc, "SetMenuItemInfoA succeeded unexpectedly\n");
1173     ok (ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
1174 
1175     /* Just change ftype to string and see what text is stored */
1176     memset(&info, 0x00, sizeof(info));
1177     info.cbSize= sizeof(MENUITEMINFOA);
1178     info.fMask= MIIM_FTYPE; /* Set string type */
1179     info.fType= MFT_STRING;
1180     info.dwTypeData= (char *)0xdeadbeef;
1181     rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1182     ok (rc, "SetMenuItemInfo failed\n");
1183 
1184     /* Did we keep the old dwTypeData? */
1185     ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1186     ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
1187 
1188     /* Ensure change to bitmap type fails */
1189     memset(&info, 0x00, sizeof(info));
1190     info.cbSize= sizeof(MENUITEMINFOA);
1191     info.fMask= MIIM_FTYPE; /* Set as bitmap type */
1192     info.fType= MFT_BITMAP;
1193     info.dwTypeData= (char *)0xdeadbee2;
1194     rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1195     ok (!rc, "SetMenuItemInfo unexpectedly worked\n");
1196 
1197     /* Just change ftype back and ensure data hasn't been freed */
1198     info.fType= MFT_OWNERDRAW; /* Set as ownerdraw type */
1199     info.dwTypeData= (char *)0xdeadbee3;
1200     rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1201     ok (rc, "SetMenuItemInfo failed\n");
1202 
1203     /* Did we keep the old dwTypeData? */
1204     ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1205     ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
1206 
1207     /* Just change string value (not type) */
1208     memset(&info, 0x00, sizeof(info));
1209     info.cbSize= sizeof(MENUITEMINFOA);
1210     info.fMask= MIIM_STRING; /* Set typeData */
1211     strcpy(string2, "string2");
1212     info.dwTypeData= string2;
1213     rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1214     ok (rc, "SetMenuItemInfo failed\n");
1215 
1216     ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1217     ok (!strcmp( strback, "string2" ), "Menu text from Ansi version incorrect\n");
1218 
1219     /*  crashes with wine 0.9.5 */
1220     memset(&info, 0x00, sizeof(info));
1221     info.cbSize= sizeof(MENUITEMINFOA);
1222     info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
1223     info.fType= MFT_OWNERDRAW;
1224     rc = InsertMenuItemA( hmenu, 0, TRUE, &info );
1225     ok (rc, "InsertMenuItem failed\n");
1226     ok (!GetMenuStringA( hmenu, 0, NULL, 0, MF_BYPOSITION),
1227             "GetMenuString on ownerdraw entry succeeded.\n");
1228     SetLastError(0xdeadbeef);
1229     ret = GetMenuStringW( hmenu, 0, NULL, 0, MF_BYPOSITION);
1230     if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1231         win_skip("GetMenuStringW is not implemented\n");
1232     else
1233         ok (!ret, "GetMenuStringW on ownerdraw entry succeeded.\n");
1234 
1235     DestroyMenu( hmenu );
1236 }
1237 
1238 /* define building blocks for the menu item info tests */
1239 static int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
1240 {
1241     if (n <= 0) return 0;
1242     while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
1243     return *str1 - *str2;
1244 }
1245 
1246 static  WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
1247 {
1248     WCHAR *p = dst;
1249     while ((*p++ = *src++));
1250     return dst;
1251 }
1252 
1253 static void insert_menu_item( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state, UINT id,
1254                               HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
1255                               void *type_data, UINT len, HBITMAP item, BOOL expect )
1256 {
1257     MENUITEMINFOA info;
1258     BOOL ret;
1259 
1260     /* magic bitmap handle to test smaller cbSize */
1261     if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
1262         info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
1263     else
1264         info.cbSize = sizeof(info);
1265     info.fMask = mask;
1266     info.fType = type;
1267     info.fState = state;
1268     info.wID = id;
1269     info.hSubMenu = submenu;
1270     info.hbmpChecked = checked;
1271     info.hbmpUnchecked = unchecked;
1272     info.dwItemData = data;
1273     info.dwTypeData = type_data;
1274     info.cch = len;
1275     info.hbmpItem = item;
1276     SetLastError( 0xdeadbeef );
1277     if (ansi) ret = InsertMenuItemA( hmenu, 0, TRUE, &info );
1278     else ret = InsertMenuItemW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
1279     if (!expect) ok_(__FILE__, line)( !ret, "InsertMenuItem should have failed.\n" );
1280     else ok_(__FILE__, line)( ret, "InsertMenuItem failed, err %u\n", GetLastError());
1281 }
1282 
1283 static void check_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
1284                                   UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked,
1285                                   ULONG_PTR data, void *type_data, UINT in_len, UINT out_len,
1286                                   HBITMAP item, LPCSTR expname, BOOL expect, BOOL expstring )
1287 {
1288     MENUITEMINFOA info;
1289     BOOL ret;
1290     WCHAR buffer[80];
1291 
1292     SetLastError( 0xdeadbeef );
1293     memset( &info, 0xcc, sizeof(info) );
1294     info.cbSize = sizeof(info);
1295     info.fMask = mask;
1296     info.dwTypeData = type_data;
1297     info.cch = in_len;
1298 
1299     ret = ansi ? GetMenuItemInfoA( hmenu, 0, TRUE, &info ) :
1300                  GetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW *)&info );
1301     if (!expect)
1302     {
1303         ok_(__FILE__, line)( !ret, "GetMenuItemInfo should have failed.\n" );
1304         return;
1305     }
1306     ok_(__FILE__, line)( ret, "GetMenuItemInfo failed, err %u\n", GetLastError());
1307     if (mask & MIIM_TYPE)
1308         ok_(__FILE__, line)( info.fType == type || info.fType == LOWORD(type),
1309                              "wrong type %x/%x\n", info.fType, type );
1310     if (mask & MIIM_STATE)
1311         ok_(__FILE__, line)( info.fState == state || info.fState == LOWORD(state),
1312                              "wrong state %x/%x\n", info.fState, state );
1313     if (mask & MIIM_ID)
1314         ok_(__FILE__, line)( info.wID == id || info.wID == LOWORD(id),
1315                              "wrong id %x/%x\n", info.wID, id );
1316     if (mask & MIIM_SUBMENU)
1317         ok_(__FILE__, line)( info.hSubMenu == submenu || (ULONG_PTR)info.hSubMenu == LOWORD(submenu),
1318                              "wrong submenu %p/%p\n", info.hSubMenu, submenu );
1319     if (mask & MIIM_CHECKMARKS)
1320     {
1321         ok_(__FILE__, line)( info.hbmpChecked == checked || (ULONG_PTR)info.hbmpChecked == LOWORD(checked),
1322                              "wrong bmpchecked %p/%p\n", info.hbmpChecked, checked );
1323         ok_(__FILE__, line)( info.hbmpUnchecked == unchecked || (ULONG_PTR)info.hbmpUnchecked == LOWORD(unchecked),
1324                              "wrong bmpunchecked %p/%p\n", info.hbmpUnchecked, unchecked );
1325     }
1326     if (mask & MIIM_DATA)
1327         ok_(__FILE__, line)( info.dwItemData == data || info.dwItemData == LOWORD(data),
1328                              "wrong item data %lx/%lx\n", info.dwItemData, data );
1329     if (mask & MIIM_BITMAP)
1330         ok_(__FILE__, line)( info.hbmpItem == item || (ULONG_PTR)info.hbmpItem == LOWORD(item),
1331                              "wrong bmpitem %p/%p\n", info.hbmpItem, item );
1332     ok_(__FILE__, line)( info.dwTypeData == type_data || (ULONG_PTR)info.dwTypeData == LOWORD(type_data),
1333                          "wrong type data %p/%p\n", info.dwTypeData, type_data );
1334     ok_(__FILE__, line)( info.cch == out_len ||
1335                          broken(! ansi && info.cch == 2 * out_len) /* East-Asian */,
1336                          "wrong len %x/%x\n", info.cch, out_len );
1337     if (expname)
1338     {
1339         if(ansi)
1340             ok_(__FILE__, line)( !strncmp( expname, info.dwTypeData, out_len ),
1341                                  "menu item name differed from '%s' '%s'\n", expname, info.dwTypeData );
1342         else
1343             ok_(__FILE__, line)( !strncmpW( (WCHAR *)expname, (WCHAR *)info.dwTypeData, out_len ),
1344                                  "menu item name wrong\n" );
1345 
1346         SetLastError( 0xdeadbeef );
1347         ret = ansi ? GetMenuStringA( hmenu, 0, (char *)buffer, 80, MF_BYPOSITION ) :
1348             GetMenuStringW( hmenu, 0, buffer, 80, MF_BYPOSITION );
1349         if (expstring)
1350             ok_(__FILE__, line)( ret, "GetMenuString failed, err %u\n", GetLastError());
1351         else
1352             ok_(__FILE__, line)( !ret, "GetMenuString should have failed\n" );
1353     }
1354 }
1355 
1356 static void modify_menu( int line, HMENU hmenu, BOOL ansi, UINT flags, UINT_PTR id, void *data )
1357 {
1358     BOOL ret;
1359 
1360     SetLastError( 0xdeadbeef );
1361     if (ansi) ret = ModifyMenuA( hmenu, 0, flags, id, data );
1362     else ret = ModifyMenuW( hmenu, 0, flags, id, data );
1363     ok_(__FILE__,line)( ret, "ModifyMenuA failed, err %u\n", GetLastError());
1364 }
1365 
1366 static void set_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
1367                                 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
1368                                 void *type_data, UINT len, HBITMAP item )
1369 
1370 {
1371     MENUITEMINFOA info;
1372     BOOL ret;
1373 
1374     /* magic bitmap handle to test smaller cbSize */
1375     if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
1376         info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
1377     else
1378         info.cbSize = sizeof(info);
1379     info.fMask = mask;
1380     info.fType = type;
1381     info.fState = state;
1382     info.wID = id;
1383     info.hSubMenu = submenu;
1384     info.hbmpChecked = checked;
1385     info.hbmpUnchecked = unchecked;
1386     info.dwItemData = data;
1387     info.dwTypeData = type_data;
1388     info.cch = len;
1389     info.hbmpItem = item;
1390     SetLastError( 0xdeadbeef );
1391     if (ansi) ret = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1392     else ret = SetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
1393     ok_(__FILE__, line)( ret, "SetMenuItemInfo failed, err %u\n", GetLastError());
1394 }
1395 
1396 #define TMII_INSMI( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,eret1 )\
1397     hmenu = CreateMenu();\
1398     submenu = CreateMenu();\
1399     if(ansi)strcpy( string, init );\
1400     else strcpyW( string, init );\
1401     insert_menu_item( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, eret1 )
1402 
1403 /* GetMenuItemInfo + GetMenuString  */
1404 #define TMII_GMII( c2,l2,\
1405     d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,\
1406     expname, eret2, eret3)\
1407     check_menu_item_info( __LINE__, hmenu, ansi, c2, d3, e3, f3, g3, h3, i3, j3, k3, l2, l3, m3, \
1408                           expname, eret2, eret3 )
1409 
1410 #define TMII_DONE \
1411     RemoveMenu(hmenu, 0, TRUE );\
1412     DestroyMenu( hmenu );\
1413     DestroyMenu( submenu );
1414 
1415 /* modify menu */
1416 #define TMII_MODM( flags, id, data ) \
1417     modify_menu( __LINE__, hmenu, ansi, flags, id, data )
1418 
1419 /* SetMenuItemInfo */
1420 #define TMII_SMII( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1 ) \
1421     set_menu_item_info( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1 )
1422 
1423 
1424 #define OK 1
1425 #define ER 0
1426 
1427 
1428 static void test_menu_iteminfo( void )
1429 {
1430   BOOL ansi = TRUE;
1431   char txtA[]="wine";
1432   char initA[]="XYZ";
1433   char emptyA[]="";
1434   WCHAR txtW[]={'W','i','n','e',0};
1435   WCHAR initW[]={'X','Y','Z',0};
1436   WCHAR emptyW[]={0};
1437   void *txt, *init, *empty, *string;
1438   HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
1439   char stringA[0x80];
1440   HMENU hmenu, submenu;
1441   HBITMAP dummy_hbm = (HBITMAP)(ULONG_PTR)0xdeadbeef;
1442 
1443   do {
1444     if( ansi) {txt=txtA;init=initA;empty=emptyA;string=stringA;}
1445     else {txt=txtW;init=initW;empty=emptyW;string=stringA;}
1446     trace( "%s string %p hbm %p txt %p\n", ansi ?  "ANSI tests:   " : "Unicode tests:", string, hbm, txt);
1447     /* test all combinations of MFT_STRING, MFT_OWNERDRAW and MFT_BITMAP */
1448     /* (since MFT_STRING is zero, there are four of them) */
1449     TMII_INSMI( MIIM_TYPE, MFT_STRING, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1450     TMII_GMII ( MIIM_TYPE, 80,
1451         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1452         txt, OK, OK );
1453     TMII_DONE
1454     TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1455     TMII_GMII ( MIIM_TYPE, 80,
1456         MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1457         NULL, OK, ER );
1458     TMII_DONE
1459     TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1460     TMII_GMII ( MIIM_TYPE, 80,
1461         MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1462         NULL, OK, ER );
1463     TMII_DONE
1464     TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1465     TMII_GMII ( MIIM_TYPE, 80,
1466         MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1467         NULL, OK, ER );
1468     TMII_DONE
1469     /* not enough space for name*/
1470     TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1471     TMII_GMII ( MIIM_TYPE, 0,
1472         MFT_STRING, 0, 0, 0, 0, 0, 0, NULL, 4, 0,
1473         NULL, OK, OK );
1474     TMII_DONE
1475     TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1476     TMII_GMII ( MIIM_TYPE, 5,
1477         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1478         txt, OK, OK );
1479     TMII_DONE
1480     TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1481     TMII_GMII ( MIIM_TYPE, 4,
1482         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 3, 0,
1483         txt, OK, OK );
1484     TMII_DONE
1485     TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1486     TMII_GMII ( MIIM_TYPE, 0,
1487         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, 0,
1488         NULL, OK, ER );
1489     TMII_DONE
1490     /* cannot combine MIIM_TYPE with some other flags */
1491     TMII_INSMI( MIIM_TYPE|MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1492     TMII_DONE
1493     TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1494     TMII_GMII ( MIIM_TYPE|MIIM_STRING, 80,
1495         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1496         NULL, ER, OK );
1497     TMII_DONE
1498     TMII_INSMI( MIIM_TYPE|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1499     TMII_DONE
1500     TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1501     TMII_GMII ( MIIM_TYPE|MIIM_FTYPE, 80,
1502         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1503         NULL, ER, OK );
1504     TMII_DONE
1505     TMII_INSMI( MIIM_TYPE|MIIM_BITMAP, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, hbm, ER );
1506     TMII_DONE
1507         /* but succeeds with some others */
1508     TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1509     TMII_GMII ( MIIM_TYPE|MIIM_SUBMENU, 80,
1510         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1511         txt, OK, OK );
1512     TMII_DONE
1513     TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1514     TMII_GMII ( MIIM_TYPE|MIIM_STATE, 80,
1515         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1516         txt, OK, OK );
1517     TMII_DONE
1518     TMII_INSMI( MIIM_TYPE|MIIM_ID, MFT_STRING, -1, 888, 0, 0, 0, -1, txt, 6, 0, OK );
1519     TMII_GMII ( MIIM_TYPE|MIIM_ID, 80,
1520         MFT_STRING, 0, 888, 0, 0, 0, 0, string, 4, 0,
1521         txt, OK, OK );
1522     TMII_DONE
1523     TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING, -1, -1, 0, 0, 0, 999, txt, 6, 0, OK );
1524     TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1525         MFT_STRING, 0, 0, 0, 0, 0, 999, string, 4, 0,
1526         txt, OK, OK );
1527     TMII_DONE
1528     /* to be continued */
1529     /* set text with MIIM_TYPE and retrieve with MIIM_STRING */
1530     TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1531     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1532         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1533         txt, OK, OK );
1534     TMII_DONE
1535     /* set text with MIIM_TYPE and retrieve with MIIM_STRING; MFT_OWNERDRAW causes an empty string */
1536     TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1537     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1538         MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1539         empty, OK, ER );
1540     TMII_DONE
1541     TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1542     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1543         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1544         empty, OK, ER );
1545     TMII_DONE
1546     TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1547     TMII_GMII ( MIIM_FTYPE, 80,
1548         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, 0,
1549         init, OK, ER );
1550     TMII_DONE
1551     TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1552     TMII_GMII ( 0, 80,
1553         0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1554         init, OK, OK );
1555     TMII_DONE
1556     /* contrary to MIIM_TYPE,you can set the text for an owner draw menu */
1557     TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1558     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1559         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1560         txt, OK, OK );
1561     TMII_DONE
1562     /* same but retrieve with MIIM_TYPE */
1563     TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1564     TMII_GMII ( MIIM_TYPE, 80,
1565         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1566         NULL, OK, OK );
1567     TMII_DONE
1568     TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1569     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1570         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1571         empty, OK, ER );
1572     TMII_DONE
1573     TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1574     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1575         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1576         empty, OK, ER );
1577     TMII_DONE
1578     TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1579     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1580         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, 0,
1581         NULL, OK, ER );
1582     TMII_DONE
1583 
1584     /* How is that with bitmaps? */
1585     TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1586     TMII_GMII ( MIIM_TYPE, 80,
1587         MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1588         NULL, OK, ER );
1589     TMII_DONE
1590     TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1591     TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1592         0, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1593         init, OK, ER );
1594     TMII_DONE
1595         /* MIIM_BITMAP does not like MFT_BITMAP */
1596     TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, hbm, ER );
1597     TMII_DONE
1598         /* no problem with OWNERDRAWN */
1599     TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1600     TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1601         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1602         init, OK, ER );
1603     TMII_DONE
1604         /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1605     TMII_INSMI( MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER );
1606     TMII_DONE
1607 
1608     /* menu with submenu */
1609     TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1610     TMII_GMII ( MIIM_SUBMENU, 80,
1611         0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1612         init, OK, ER );
1613     TMII_DONE
1614     TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, empty, 0, 0, OK );
1615     TMII_GMII ( MIIM_SUBMENU, 80,
1616         0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1617         init, OK, ER );
1618     TMII_DONE
1619     /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1620     TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1621     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1622         MFT_STRING|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1623         empty, OK, ER );
1624     TMII_GMII ( MIIM_SUBMENU|MIIM_FTYPE, 80,
1625         MFT_SEPARATOR, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1626         empty, OK, ER );
1627     TMII_DONE
1628     /* menu with invalid submenu */
1629     TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, (HMENU)999, 0, 0, -1, txt, 0, 0, ER );
1630     TMII_DONE
1631     /* Separator */
1632     TMII_INSMI( MIIM_TYPE, MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1633     TMII_GMII ( MIIM_TYPE, 80,
1634         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1635         NULL, OK, ER );
1636     TMII_DONE
1637     TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1638     TMII_GMII ( MIIM_TYPE, 80,
1639         MFT_BITMAP|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1640         NULL, OK, ER );
1641     TMII_DONE
1642      /* SEPARATOR and STRING go well together */
1643     /* BITMAP and STRING go well together */
1644     TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1645     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1646         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1647         txt, OK, OK );
1648     TMII_DONE
1649      /* BITMAP, SEPARATOR and STRING go well together */
1650     TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1651     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1652         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1653         txt, OK, OK );
1654     TMII_DONE
1655      /* last two tests, but use MIIM_TYPE to retrieve info */
1656     TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1657     TMII_GMII ( MIIM_TYPE, 80,
1658         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1659         NULL, OK, OK );
1660     TMII_DONE
1661     TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1662     TMII_GMII ( MIIM_TYPE, 80,
1663         MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1664         NULL, OK, OK );
1665     TMII_DONE
1666     TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1667     TMII_GMII ( MIIM_TYPE, 80,
1668         MFT_SEPARATOR|MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1669         NULL, OK, OK );
1670     TMII_DONE
1671      /* same three with MFT_OWNERDRAW */
1672     TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1673     TMII_GMII ( MIIM_TYPE, 80,
1674         MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1675         NULL, OK, OK );
1676     TMII_DONE
1677     TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1678     TMII_GMII ( MIIM_TYPE, 80,
1679         MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1680         NULL, OK, OK );
1681     TMII_DONE
1682     TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1683     TMII_GMII ( MIIM_TYPE, 80,
1684         MFT_SEPARATOR|MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1685         NULL, OK, OK );
1686     TMII_DONE
1687 
1688     TMII_INSMI( MIIM_STRING|MIIM_FTYPE|MIIM_ID, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1689     TMII_GMII ( MIIM_TYPE, 80,
1690         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1691         NULL,  OK, OK );
1692     TMII_DONE
1693     /* test with modifymenu: string is preserved after setting OWNERDRAW */
1694     TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1695     TMII_MODM( MFT_OWNERDRAW, -1, (void*)787 );
1696     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_DATA, 80,
1697         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 787, string, 4, 0,
1698         txt,  OK, OK );
1699     TMII_DONE
1700     /* same with bitmap: now the text is cleared */
1701     TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1702     TMII_MODM( MFT_BITMAP, 545, hbm );
1703     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1704         MFT_BITMAP, 0, 545, 0, 0, 0, 0, string, 0, hbm,
1705         empty,  OK, ER );
1706     TMII_DONE
1707     /* start with bitmap: now setting text clears it (though he flag is raised) */
1708     TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1709     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1710         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 0, hbm,
1711         empty,  OK, ER );
1712     TMII_MODM( MFT_STRING, 545, txt );
1713     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1714         MFT_STRING, 0, 545, 0, 0, 0, 0, string, 4, 0,
1715         txt,  OK, OK );
1716     TMII_DONE
1717     /*repeat with text NULL */
1718     TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1719     TMII_MODM( MFT_STRING, 545, NULL );
1720     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1721         MFT_SEPARATOR, 0, 545, 0, 0, 0, 0, string, 0, 0,
1722         empty,  OK, ER );
1723     TMII_DONE
1724     /* repeat with text "" */
1725     TMII_INSMI( MIIM_BITMAP, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1726     TMII_MODM( MFT_STRING, 545, empty );
1727     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1728         MFT_STRING, 0, 545, 0, 0, 0, 0, string, 0, 0,
1729         empty,  OK, ER );
1730     TMII_DONE
1731     /* start with bitmap: set ownerdraw */
1732     TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1733     TMII_MODM( MFT_OWNERDRAW, -1, (void *)232 );
1734     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_DATA, 80,
1735         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 232, string, 0, hbm,
1736         empty,  OK, ER );
1737     TMII_DONE
1738     /* ask nothing */
1739     TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1740     TMII_GMII ( 0, 80,
1741                 0, 0, 0,  0, 0, 0, 0, string, 80, 0,
1742         init, OK, OK );
1743     TMII_DONE
1744     /* some tests with small cbSize: the hbmpItem is to be ignored */
1745     TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1746     TMII_GMII ( MIIM_TYPE, 80,
1747         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1748         NULL, OK, ER );
1749     TMII_DONE
1750     TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1751     TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1752         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, NULL,
1753         init, OK, ER );
1754     TMII_DONE
1755     TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1756     TMII_GMII ( MIIM_TYPE, 80,
1757         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, NULL,
1758         txt, OK, OK );
1759     TMII_DONE
1760     TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1761     TMII_GMII ( MIIM_TYPE, 80,
1762         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1763         NULL, OK, OK );
1764     TMII_DONE
1765     TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1766     TMII_GMII ( MIIM_TYPE, 80,
1767         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1768         NULL, OK, OK );
1769     TMII_DONE
1770     TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1771     TMII_GMII ( MIIM_TYPE, 80,
1772         MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1773         NULL, OK, OK );
1774     TMII_DONE
1775     /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus  */
1776     TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1777     TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1778         MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1779         NULL, OK, ER );
1780     TMII_DONE
1781     TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1782     TMII_GMII ( MIIM_TYPE, 80,
1783         MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1784         NULL, OK, ER );
1785     TMII_DONE
1786     TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1787     TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1788         MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1789         NULL, OK, ER );
1790     TMII_DONE
1791     /* set a string menu to ownerdraw with MIIM_TYPE */
1792     TMII_INSMI( MIIM_TYPE, MFT_STRING, -2, -2, 0, 0, 0, -2, txt, -2, 0, OK );
1793     TMII_SMII ( MIIM_TYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1794     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1795         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1796         txt, OK, OK );
1797     TMII_DONE
1798     /* test with modifymenu add submenu */
1799     TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1800     TMII_MODM( MF_POPUP, (UINT_PTR)submenu, txt );
1801     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_SUBMENU, 80,
1802         MFT_STRING, 0, 0, submenu, 0, 0, 0, string, 4, 0,
1803         txt,  OK, OK );
1804     TMII_GMII ( MIIM_TYPE, 80,
1805         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1806         txt,  OK, OK );
1807     TMII_DONE
1808     /* MFT_SEPARATOR bit is kept when the text is added */
1809     TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1810     TMII_SMII( MIIM_STRING, 0, 0, 0, 0, 0, 0, 0, txt, 0, 0 );
1811     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1812         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, 0,
1813         txt, OK, OK );
1814     TMII_DONE
1815     /* MFT_SEPARATOR bit is kept when bitmap is added */
1816     TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1817     TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm );
1818     TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1819         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1820         init, OK, ER );
1821     TMII_DONE
1822     /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1823        Only the low word of the dwTypeData is used.
1824        Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1825     TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1826                 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1827     TMII_GMII ( MIIM_TYPE, 80,
1828         MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1829         NULL, OK, OK );
1830     TMII_DONE
1831     /* Type flags */
1832     TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1833     TMII_GMII ( MIIM_TYPE, 80,
1834         MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1835         NULL, OK, OK );
1836     TMII_DONE
1837     /* State flags */
1838     TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1839     TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1840     TMII_GMII ( MIIM_STATE, 80,
1841         0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1842         NULL, OK, OK );
1843     TMII_DONE
1844     /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1845     TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1846     TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1847     TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1848         MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1849         NULL, OK, OK );
1850     TMII_DONE
1851     /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1852     TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1853     TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1854     TMII_GMII ( MIIM_FTYPE, 80,
1855         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1856         NULL, OK, OK );
1857     TMII_GMII ( MIIM_TYPE, 80,
1858         MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1859         NULL, OK, OK );
1860     TMII_GMII ( MIIM_FTYPE, 80,
1861         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1862         NULL, OK, OK );
1863     TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1864     TMII_GMII ( MIIM_TYPE, 80,
1865         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1866         NULL, OK, OK );
1867     TMII_DONE
1868     /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1869        Only the low word of the dwTypeData is used.
1870        Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1871     TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1872                 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1873     TMII_GMII ( MIIM_TYPE, 80,
1874         MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1875         NULL, OK, OK );
1876     TMII_DONE
1877     /* Type flags */
1878     TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1879     TMII_GMII ( MIIM_TYPE, 80,
1880         MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1881         NULL, OK, OK );
1882     TMII_DONE
1883     /* State flags */
1884     TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1885     TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1886     TMII_GMII ( MIIM_STATE, 80,
1887         0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1888         NULL, OK, OK );
1889     TMII_DONE
1890     /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1891     TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1892     TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1893     TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1894         MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1895         NULL, OK, OK );
1896     TMII_DONE
1897     /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1898     TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1899     TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1900     TMII_GMII ( MIIM_FTYPE, 80,
1901         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1902         NULL, OK, OK );
1903     TMII_GMII ( MIIM_TYPE, 80,
1904         MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1905         NULL, OK, OK );
1906     TMII_GMII ( MIIM_FTYPE, 80,
1907         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1908         NULL, OK, OK );
1909     TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1910     TMII_GMII ( MIIM_TYPE, 80,
1911         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1912         NULL, OK, OK );
1913     TMII_DONE
1914   } while( !(ansi = !ansi) );
1915   DeleteObject( hbm);
1916 }
1917 
1918 /*
1919    The following tests try to confirm the algorithm used to return the menu items
1920    when there is a collision between a menu item and a popup menu
1921  */
1922 static void test_menu_search_bycommand( void )
1923 {
1924     HMENU        hmenu, hmenuSub, hmenuSub2;
1925     MENUITEMINFOA info;
1926     BOOL         rc;
1927     UINT         id;
1928     char         strback[0x80];
1929     char         strIn[0x80];
1930     static CHAR menuitem[]  = "MenuItem",
1931                 menuitem2[] = "MenuItem 2";
1932 
1933     /* Case 1: Menu containing a menu item */
1934     hmenu = CreateMenu();
1935 
1936     memset( &info, 0, sizeof info );
1937     info.cbSize = sizeof info;
1938     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1939     info.fType = MFT_STRING;
1940     strcpy(strIn, "Case 1 MenuItem");
1941     info.dwTypeData = strIn;
1942     info.wID = (UINT) 0x1234;
1943 
1944     rc = InsertMenuItemA(hmenu, 0, TRUE, &info );
1945     ok (rc, "Inserting the menuitem failed\n");
1946 
1947     id = GetMenuItemID(hmenu, 0);
1948     ok (id == 0x1234, "Getting the menuitem id failed(gave %x)\n", id);
1949 
1950     /* Confirm the menuitem was given the id supplied (getting by position) */
1951     memset( &info, 0, sizeof info );
1952     strback[0] = 0x00;
1953     info.cbSize = sizeof(MENUITEMINFOA);
1954     info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1955     info.dwTypeData = strback;
1956     info.cch = sizeof(strback);
1957 
1958     rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info); /* Get by position */
1959     ok (rc, "Getting the menu items info failed\n");
1960     ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1961     ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1962 
1963     /* Search by id - Should return the item */
1964     memset( &info, 0, sizeof info );
1965     strback[0] = 0x00;
1966     info.cbSize = sizeof(MENUITEMINFOA);
1967     info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1968     info.dwTypeData = strback;
1969     info.cch = sizeof(strback);
1970     rc = GetMenuItemInfoA(hmenu, 0x1234, FALSE, &info); /* Get by ID */
1971 
1972     ok (rc, "Getting the menu items info failed\n");
1973     ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1974     ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1975 
1976     DestroyMenu( hmenu );
1977 
1978     /* Case 2: Menu containing a popup menu */
1979     hmenu = CreateMenu();
1980     hmenuSub = CreateMenu();
1981 
1982     strcpy(strIn, "Case 2 SubMenu");
1983     rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, strIn);
1984     ok (rc, "Inserting the popup menu into the main menu failed\n");
1985 
1986     id = GetMenuItemID(hmenu, 0);
1987     ok (id == -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id);
1988 
1989     /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
1990     memset( &info, 0, sizeof info );
1991     strback[0] = 0x00;
1992     info.cbSize = sizeof(MENUITEMINFOA);
1993     info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1994     info.dwTypeData = strback;
1995     info.cch = sizeof(strback);
1996     info.wID = 0xdeadbeef;
1997 
1998     rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info); /* Get by position */
1999     ok (rc, "Getting the menu items info failed\n");
2000     ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the menuitem\n");
2001     ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
2002 
2003     /* Search by id - returns the popup menu itself */
2004     memset( &info, 0, sizeof info );
2005     strback[0] = 0x00;
2006     info.cbSize = sizeof(MENUITEMINFOA);
2007     info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
2008     info.dwTypeData = strback;
2009     info.cch = sizeof(strback);
2010     rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
2011 
2012     ok (rc, "Getting the menu items info failed\n");
2013     ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
2014     ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
2015 
2016     /*
2017         Now add an item after it with the same id
2018      */
2019     memset( &info, 0, sizeof info );
2020     info.cbSize = sizeof info;
2021     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2022     info.fType = MFT_STRING;
2023     strcpy(strIn, "Case 2 MenuItem 1");
2024     info.dwTypeData = strIn;
2025     info.wID = (UINT_PTR) hmenuSub;
2026     rc = InsertMenuItemA(hmenu, -1, TRUE, &info );
2027     ok (rc, "Inserting the menuitem failed\n");
2028 
2029     /* Search by id - returns the item which follows the popup menu */
2030     memset( &info, 0, sizeof info );
2031     strback[0] = 0x00;
2032     info.cbSize = sizeof(MENUITEMINFOA);
2033     info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
2034     info.dwTypeData = strback;
2035     info.cch = sizeof(strback);
2036     rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
2037 
2038     ok (rc, "Getting the menu items info failed\n");
2039     ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
2040     ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2041 
2042     /*
2043         Now add an item before the popup (with the same id)
2044      */
2045     memset( &info, 0, sizeof info );
2046     info.cbSize = sizeof info;
2047     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2048     info.fType = MFT_STRING;
2049     strcpy(strIn, "Case 2 MenuItem 2");
2050     info.dwTypeData = strIn;
2051     info.wID = (UINT_PTR) hmenuSub;
2052     rc = InsertMenuItemA(hmenu, 0, TRUE, &info );
2053     ok (rc, "Inserting the menuitem failed\n");
2054 
2055     /* Search by id - returns the item which precedes the popup menu */
2056     memset( &info, 0, sizeof info );
2057     strback[0] = 0x00;
2058     info.cbSize = sizeof(MENUITEMINFOA);
2059     info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
2060     info.dwTypeData = strback;
2061     info.cch = sizeof(strback);
2062     rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
2063 
2064     ok (rc, "Getting the menu items info failed\n");
2065     ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
2066     ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2067 
2068     DestroyMenu( hmenu );
2069     DestroyMenu( hmenuSub );
2070 
2071     /*
2072         Case 3: Menu containing a popup menu which in turn
2073            contains 2 items with the same id as the popup itself
2074      */
2075 
2076     hmenu = CreateMenu();
2077     hmenuSub = CreateMenu();
2078 
2079     memset( &info, 0, sizeof info );
2080     info.cbSize = sizeof info;
2081     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2082     info.fType = MFT_STRING;
2083     info.dwTypeData = menuitem;
2084     info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2085 
2086     rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
2087     ok (rc, "Inserting the popup menu into the main menu failed\n");
2088 
2089     rc = InsertMenuItemA(hmenuSub, 0, TRUE, &info );
2090     ok (rc, "Inserting the sub menu menuitem failed\n");
2091 
2092     memset( &info, 0, sizeof info );
2093     info.cbSize = sizeof info;
2094     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2095     info.fType = MFT_STRING;
2096     info.dwTypeData = menuitem2;
2097     info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2098 
2099     rc = InsertMenuItemA(hmenuSub, 1, TRUE, &info );
2100     ok (rc, "Inserting the sub menu menuitem 2 failed\n");
2101 
2102     /* Prove that you can't query the id of a popup directly (By position) */
2103     id = GetMenuItemID(hmenu, 0);
2104     ok (id == -1, "Getting the sub menu id should have failed because it's a popup (gave %x)\n", id);
2105 
2106     /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
2107     memset( &info, 0, sizeof info );
2108     strback[0] = 0x00;
2109     info.cbSize = sizeof(MENUITEMINFOA);
2110     info.fMask = MIIM_STRING | MIIM_ID;
2111     info.dwTypeData = strback;
2112     info.cch = sizeof(strback);
2113 
2114     rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
2115     ok (rc, "Getting the menus info failed\n");
2116     ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
2117     ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2118     DestroyMenu( hmenu );
2119     DestroyMenu( hmenuSub );
2120 
2121     /*
2122         Case 4: Menu containing 2 popup menus, the second
2123            contains 2 items with the same id as the first popup menu
2124      */
2125     hmenu = CreateMenu();
2126     hmenuSub = CreateMenu();
2127     hmenuSub2 = CreateMenu();
2128 
2129     rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
2130     ok (rc, "Inserting the popup menu into the main menu failed\n");
2131 
2132     rc = InsertMenuA(hmenu, 1, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub2, "Submenu2");
2133     ok (rc, "Inserting the popup menu into the main menu failed\n");
2134 
2135     memset( &info, 0, sizeof info );
2136     info.cbSize = sizeof info;
2137     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2138     info.fType = MFT_STRING;
2139     info.dwTypeData = menuitem;
2140     info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2141 
2142     rc = InsertMenuItemA(hmenuSub2, 0, TRUE, &info );
2143     ok (rc, "Inserting the sub menu menuitem failed\n");
2144 
2145     memset( &info, 0, sizeof info );
2146     info.cbSize = sizeof info;
2147     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2148     info.fType = MFT_STRING;
2149     info.dwTypeData = menuitem2;
2150     info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2151 
2152     rc = InsertMenuItemA(hmenuSub2, 1, TRUE, &info );
2153     ok (rc, "Inserting the sub menu menuitem 2 failed\n");
2154 
2155     /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
2156     memset( &info, 0, sizeof info );
2157     strback[0] = 0x00;
2158     info.cbSize = sizeof(MENUITEMINFOA);
2159     info.fMask = MIIM_STRING | MIIM_ID;
2160     info.dwTypeData = strback;
2161     info.cch = sizeof(strback);
2162 
2163     rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
2164     ok (rc, "Getting the menus info failed\n");
2165     ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
2166     ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2167 
2168     memset( &info, 0, sizeof info );
2169     strback[0] = 0x00;
2170     info.cbSize = sizeof(MENUITEMINFOA);
2171     info.fMask = MIIM_STRING | MIIM_ID;
2172     info.dwTypeData = strback;
2173     info.cch = sizeof(strback);
2174 
2175     rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub2, FALSE, &info);
2176     ok (rc, "Getting the menus info failed\n");
2177     ok (info.wID == (UINT_PTR)hmenuSub2, "IDs differ for popup menu\n");
2178     ok (!strcmp(info.dwTypeData, "Submenu2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2179 
2180     DestroyMenu( hmenu );
2181     DestroyMenu( hmenuSub );
2182     DestroyMenu( hmenuSub2 );
2183 
2184 
2185     /*
2186         Case 5: Menu containing a popup menu which in turn
2187            contains an item with a different id than the popup menu.
2188            This tests the fallback to a popup menu ID.
2189      */
2190 
2191     hmenu = CreateMenu();
2192     hmenuSub = CreateMenu();
2193 
2194     rc = AppendMenuA(hmenu, MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
2195     ok (rc, "Appending the popup menu to the main menu failed\n");
2196 
2197     rc = AppendMenuA(hmenuSub, MF_STRING, 102, "Item");
2198     ok (rc, "Appending the item to the popup menu failed\n");
2199 
2200     /* Set the ID for hmenuSub */
2201     info.cbSize = sizeof(info);
2202     info.fMask = MIIM_ID;
2203     info.wID = 101;
2204 
2205     rc = SetMenuItemInfoA(hmenu, 0, TRUE, &info);
2206     ok(rc, "Setting the ID for the popup menu failed\n");
2207 
2208     /* Check if the ID has been set */
2209     info.wID = 0;
2210     rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info);
2211     ok(rc, "Getting the ID for the popup menu failed\n");
2212     ok(info.wID == 101, "The ID for the popup menu has not been set\n");
2213 
2214     /* Prove getting the item info via ID returns the popup menu */
2215     memset( &info, 0, sizeof(info));
2216     strback[0] = 0x00;
2217     info.cbSize = sizeof(MENUITEMINFOA);
2218     info.fMask = MIIM_STRING | MIIM_ID;
2219     info.dwTypeData = strback;
2220     info.cch = sizeof(strback);
2221 
2222     rc = GetMenuItemInfoA(hmenu, 101, FALSE, &info);
2223     ok (rc, "Getting the menu info failed\n");
2224     ok (info.wID == 101, "IDs differ\n");
2225     ok (!strcmp(info.dwTypeData, "Submenu"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2226 
2227     /* Also look for the menu item  */
2228     memset( &info, 0, sizeof(info));
2229     strback[0] = 0x00;
2230     info.cbSize = sizeof(MENUITEMINFOA);
2231     info.fMask = MIIM_STRING | MIIM_ID;
2232     info.dwTypeData = strback;
2233     info.cch = sizeof(strback);
2234 
2235     rc = GetMenuItemInfoA(hmenu, 102, FALSE, &info);
2236     ok (rc, "Getting the menu info failed\n");
2237     ok (info.wID == 102, "IDs differ\n");
2238     ok (!strcmp(info.dwTypeData, "Item"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2239 
2240     DestroyMenu(hmenu);
2241     DestroyMenu(hmenuSub);
2242 }
2243 
2244 struct menu_item_pair_s {
2245     UINT uMenu; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
2246                  * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
2247                  * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
2248     UINT uItem;
2249 };
2250 
2251 static struct menu_mouse_tests_s {
2252     DWORD type;
2253     struct menu_item_pair_s menu_item_pairs[5]; /* for mousing */
2254     WORD wVk[5]; /* keys */
2255     BOOL bMenuVisible;
2256     BOOL _todo_wine;
2257 } menu_tests[] = {
2258     /* for each test, send keys or clicks and check for menu visibility */
2259     { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE }, /* test 0 */
2260     { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
2261     { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
2262     { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2263     { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
2264     { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2265     { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2266     { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, VK_ESCAPE, 0}, FALSE, FALSE },
2267     { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', VK_ESCAPE, 0}, TRUE, FALSE },
2268     { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
2269     { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2270     { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2271     { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2272     { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2273     { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
2274     { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2275     { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
2276     { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2277     { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, TRUE, FALSE },
2278     { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, FALSE, FALSE },
2279 
2280     { INPUT_MOUSE, {{1, 2}, {0}}, {0}, TRUE, TRUE }, /* test 20 */
2281     { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2282     { INPUT_MOUSE, {{1, 0}, {0}}, {0}, TRUE, TRUE },
2283     { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2284     { INPUT_MOUSE, {{1, 0}, {2, 2}, {0}}, {0}, TRUE, TRUE },
2285     { INPUT_MOUSE, {{2, 1}, {0}}, {0}, FALSE, FALSE },
2286     { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
2287     { INPUT_MOUSE, {{3, 0}, {0}}, {0}, FALSE, FALSE },
2288     { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
2289     { INPUT_MOUSE, {{3, 1}, {0}}, {0}, TRUE, TRUE },
2290     { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2291     { -1 }
2292 };
2293 
2294 static void send_key(WORD wVk)
2295 {
2296     TEST_INPUT i[2];
2297     memset(i, 0, sizeof(i));
2298     i[0].type = i[1].type = INPUT_KEYBOARD;
2299     i[0].u.ki.wVk = i[1].u.ki.wVk = wVk;
2300     i[1].u.ki.dwFlags = KEYEVENTF_KEYUP;
2301     pSendInput(2, (INPUT *) i, sizeof(INPUT));
2302 }
2303 
2304 static BOOL click_menu(HANDLE hWnd, struct menu_item_pair_s *mi)
2305 {
2306     HMENU hMenu = hMenus[mi->uMenu];
2307     TEST_INPUT i[3];
2308     MSG msg;
2309     RECT r;
2310     int screen_w = GetSystemMetrics(SM_CXSCREEN);
2311     int screen_h = GetSystemMetrics(SM_CYSCREEN);
2312     BOOL ret = GetMenuItemRect(mi->uMenu > 2 ? NULL : hWnd, hMenu, mi->uItem, &r);
2313     if(!ret) return FALSE;
2314 
2315     memset(i, 0, sizeof(i));
2316     i[0].type = i[1].type = i[2].type = INPUT_MOUSE;
2317     i[0].u.mi.dx = i[1].u.mi.dx = i[2].u.mi.dx
2318             = ((r.left + 5) * 65535) / screen_w;
2319     i[0].u.mi.dy = i[1].u.mi.dy = i[2].u.mi.dy
2320             = ((r.top + 5) * 65535) / screen_h;
2321     i[0].u.mi.dwFlags = i[1].u.mi.dwFlags = i[2].u.mi.dwFlags
2322             = MOUSEEVENTF_ABSOLUTE;
2323     i[0].u.mi.dwFlags |= MOUSEEVENTF_MOVE;
2324     i[1].u.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
2325     i[2].u.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
2326     ret = pSendInput(3, (INPUT *) i, sizeof(INPUT));
2327 
2328     /* hack to prevent mouse message buildup in Wine */
2329     while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
2330     return ret;
2331 }
2332 
2333 static DWORD WINAPI test_menu_input_thread(LPVOID lpParameter)
2334 {
2335     int i, j;
2336     HANDLE hWnd = lpParameter;
2337 
2338     Sleep(500);
2339     /* mixed keyboard/mouse test */
2340     for (i = 0; menu_tests[i].type != -1; i++)
2341     {
2342         BOOL ret = TRUE;
2343         int elapsed = 0;
2344 
2345         got_input = i && menu_tests[i-1].bMenuVisible;
2346 
2347         if (menu_tests[i].type == INPUT_KEYBOARD)
2348             for (j = 0; menu_tests[i].wVk[j] != 0; j++)
2349                 send_key(menu_tests[i].wVk[j]);
2350         else
2351             for (j = 0; menu_tests[i].menu_item_pairs[j].uMenu != 0; j++)
2352                 if (!(ret = click_menu(hWnd, &menu_tests[i].menu_item_pairs[j]))) break;
2353 
2354         if (!ret)
2355         {
2356             skip( "test %u: failed to send input\n", i );
2357             PostMessageA( hWnd, WM_CANCELMODE, 0, 0 );
2358             return 0;
2359         }
2360         while (menu_tests[i].bMenuVisible != bMenuVisible)
2361         {
2362             if (elapsed > 200)
2363                 break;
2364             elapsed += 20;
2365             Sleep(20);
2366         }
2367 
2368         if (!got_input)
2369         {
2370             skip( "test %u: didn't receive input\n", i );
2371             PostMessageA( hWnd, WM_CANCELMODE, 0, 0 );
2372             return 0;
2373         }
2374 
2375         todo_wine_if (menu_tests[i]._todo_wine)
2376             ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
2377     }
2378     return 0;
2379 }
2380 
2381 static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam,
2382         LPARAM lParam)
2383 {
2384     switch (msg) {
2385         case WM_ENTERMENULOOP:
2386             bMenuVisible = TRUE;
2387             break;
2388         case WM_INITMENUPOPUP:
2389         case WM_UNINITMENUPOPUP:
2390         case WM_EXITMENULOOP:
2391         case WM_MENUSELECT:
2392             break;
2393 
2394         case WM_KEYDOWN:
2395         case WM_SYSKEYDOWN:
2396         case WM_MOUSEMOVE:
2397         case WM_LBUTTONDOWN:
2398         case WM_LBUTTONUP:
2399         case WM_NCMOUSEMOVE:
2400         case WM_NCLBUTTONDOWN:
2401         case WM_NCLBUTTONUP:
2402             got_input = TRUE;
2403             /* fall through */
2404         default:
2405             return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2406     }
2407 
2408     if(pGetMenuBarInfo)
2409     {
2410         MENUBARINFO mbi;
2411         HMENU hmenu;
2412         UINT state;
2413         BOOL br;
2414 
2415         mbi.cbSize = sizeof(MENUBARINFO);
2416 
2417         /* get info for the menu */
2418         br = pGetMenuBarInfo(hWnd, OBJID_MENU, 0, &mbi);
2419         ok(br, "msg %x: GetMenuBarInfo failed\n", msg);
2420         hmenu = GetMenu(hWnd);
2421         ok(!mbi.hwndMenu, "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected NULL\n",
2422                 msg, mbi.hwndMenu);
2423         ok(mbi.hMenu == hmenu, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2424                 msg, mbi.hMenu, hmenu);
2425         ok(!bMenuVisible == !mbi.fBarFocused, "msg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2426                 msg, mbi.fBarFocused != 0);
2427         ok(!bMenuVisible == !mbi.fFocused, "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n",
2428                 msg, mbi.fFocused != 0);
2429 
2430         /* get info for the menu's first item */
2431         br = pGetMenuBarInfo(hWnd, OBJID_MENU, 1, &mbi);
2432         ok(br, "msg %x: GetMenuBarInfo failed\n", msg);
2433         state = GetMenuState(hmenu, 0, MF_BYPOSITION);
2434         if (pGetMenuInfo) /* Skip on NT */
2435         {
2436             /* Native returns handle to destroyed window */
2437             todo_wine_if (msg==WM_UNINITMENUPOPUP && popmenu==1)
2438                 ok(!mbi.hwndMenu == !popmenu,
2439                         "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected %sNULL\n",
2440                         msg, mbi.hwndMenu, popmenu ? "not " : "");
2441         }
2442         ok(mbi.hMenu == hmenu, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2443                 msg, mbi.hMenu, hmenu);
2444         ok(!bMenuVisible == !mbi.fBarFocused, "nsg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2445                 msg, mbi.fBarFocused != 0);
2446         ok(!(bMenuVisible && (state & MF_HILITE)) == !mbi.fFocused,
2447                 "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n", msg, mbi.fFocused != 0);
2448     }
2449 
2450     if (msg == WM_EXITMENULOOP)
2451         bMenuVisible = FALSE;
2452     else if (msg == WM_INITMENUPOPUP)
2453         popmenu++;
2454     else if (msg == WM_UNINITMENUPOPUP)
2455         popmenu--;
2456     return 0;
2457 }
2458 
2459 static void test_menu_input(void) {
2460     MSG msg;
2461     WNDCLASSA  wclass;
2462     HINSTANCE hInstance = GetModuleHandleA( NULL );
2463     HANDLE hThread, hWnd;
2464     DWORD tid;
2465     ATOM aclass;
2466     POINT orig_pos;
2467 
2468     if (!pSendInput)
2469     {
2470         win_skip("SendInput is not available\n");
2471         return;
2472     }
2473 
2474     wclass.lpszClassName = "MenuTestClass";
2475     wclass.style         = CS_HREDRAW | CS_VREDRAW;
2476     wclass.lpfnWndProc   = WndProc;
2477     wclass.hInstance     = hInstance;
2478     wclass.hIcon         = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
2479     wclass.hCursor       = LoadCursorA( 0, (LPCSTR)IDC_ARROW );
2480     wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2481     wclass.lpszMenuName  = 0;
2482     wclass.cbClsExtra    = 0;
2483     wclass.cbWndExtra    = 0;
2484     aclass = RegisterClassA( &wclass );
2485     ok (aclass, "MenuTest class not created\n");
2486     if (!aclass) return;
2487     hWnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
2488                           WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2489                           400, 200, NULL, NULL, hInstance, NULL);
2490     ok (hWnd != NULL, "MenuTest window not created\n");
2491     if (!hWnd) return;
2492     /* fixed menus */
2493     hMenus[3] = CreatePopupMenu();
2494     AppendMenuA(hMenus[3], MF_STRING, 0, "&Enabled");
2495     AppendMenuA(hMenus[3], MF_STRING|MF_DISABLED, 0, "&Disabled");
2496 
2497     hMenus[2] = CreatePopupMenu();
2498     AppendMenuA(hMenus[2], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[3], "&Popup");
2499     AppendMenuA(hMenus[2], MF_STRING, 0, "&Enabled");
2500     AppendMenuA(hMenus[2], MF_STRING|MF_DISABLED, 0, "&Disabled");
2501 
2502     hMenus[1] = CreateMenu();
2503     AppendMenuA(hMenus[1], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[2], "&Menu");
2504     AppendMenuA(hMenus[1], MF_STRING, 0, "&Enabled");
2505     AppendMenuA(hMenus[1], MF_STRING|MF_DISABLED, 0, "&Disabled");
2506 
2507     SetMenu(hWnd, hMenus[1]);
2508     ShowWindow(hWnd, SW_SHOW);
2509     UpdateWindow(hWnd);
2510 
2511     GetCursorPos(&orig_pos);
2512 
2513     hThread = CreateThread(NULL, 0, test_menu_input_thread, hWnd, 0, &tid);
2514     while(1)
2515     {
2516         if (WAIT_TIMEOUT != WaitForSingleObject(hThread, 50))
2517             break;
2518         while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2519     }
2520     SetCursorPos(orig_pos.x, orig_pos.y);
2521     DestroyWindow(hWnd);
2522 }
2523 
2524 static void test_menu_flags( void )
2525 {
2526     HMENU hMenu, hPopupMenu;
2527 
2528     hMenu = CreateMenu();
2529     hPopupMenu = CreatePopupMenu();
2530 
2531     AppendMenuA(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2532 
2533     AppendMenuA(hPopupMenu, MF_STRING | MF_HILITE | MF_DEFAULT, 101, "Item 1");
2534     InsertMenuA(hPopupMenu, 1, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 102, "Item 2");
2535     AppendMenuA(hPopupMenu, MF_STRING, 103, "Item 3");
2536     ModifyMenuA(hPopupMenu, 2, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 103, "Item 3");
2537 
2538     ok(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_HILITE,
2539       "AppendMenu should accept MF_HILITE\n");
2540     ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2541       "InsertMenu should accept MF_HILITE\n");
2542     ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2543       "ModifyMenu should accept MF_HILITE\n");
2544 
2545     ok(!(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_DEFAULT),
2546       "AppendMenu must not accept MF_DEFAULT\n");
2547     ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_DEFAULT),
2548       "InsertMenu must not accept MF_DEFAULT\n");
2549     ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_DEFAULT),
2550       "ModifyMenu must not accept MF_DEFAULT\n");
2551 
2552     DestroyMenu(hMenu);
2553 }
2554 
2555 static void test_menu_hilitemenuitem( void )
2556 {
2557     HMENU hMenu, hPopupMenu;
2558     WNDCLASSA wclass;
2559     HWND hWnd;
2560     ATOM aclass;
2561 
2562     wclass.lpszClassName = "HiliteMenuTestClass";
2563     wclass.style         = CS_HREDRAW | CS_VREDRAW;
2564     wclass.lpfnWndProc   = WndProc;
2565     wclass.hInstance     = GetModuleHandleA( NULL );
2566     wclass.hIcon         = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
2567     wclass.hCursor       = LoadCursorA( 0, (LPCSTR)IDC_ARROW );
2568     wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2569     wclass.lpszMenuName  = 0;
2570     wclass.cbClsExtra    = 0;
2571     wclass.cbWndExtra    = 0;
2572     aclass = RegisterClassA( &wclass );
2573     ok (aclass, "HiliteMenuTest class could not be created\n");
2574     if (!aclass) return;
2575     hWnd = CreateWindowA( wclass.lpszClassName, "HiliteMenuTest",
2576                           WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2577                           400, 200, NULL, NULL, wclass.hInstance, NULL);
2578     ok (hWnd != NULL, "HiliteMenuTest window could not be created\n");
2579     if (!hWnd) return;
2580 
2581     hMenu = CreateMenu();
2582     hPopupMenu = CreatePopupMenu();
2583 
2584     AppendMenuA(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2585 
2586     AppendMenuA(hPopupMenu, MF_STRING, 101, "Item 1");
2587     AppendMenuA(hPopupMenu, MF_STRING, 102, "Item 2");
2588     AppendMenuA(hPopupMenu, MF_STRING, 103, "Item 3");
2589 
2590     SetMenu(hWnd, hMenu);
2591 
2592     /* test invalid arguments */
2593 
2594     ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2595       "HiliteMenuItem: Item 2 is hilited\n");
2596 
2597     SetLastError(0xdeadbeef);
2598     todo_wine
2599     {
2600     ok(!HiliteMenuItem(NULL, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2601       "HiliteMenuItem: call should have failed.\n");
2602     }
2603     ok(GetLastError() == 0xdeadbeef || /* 9x */
2604        GetLastError() == ERROR_INVALID_WINDOW_HANDLE /* NT */,
2605       "HiliteMenuItem: expected error ERROR_INVALID_WINDOW_HANDLE, got: %d\n", GetLastError());
2606 
2607     SetLastError(0xdeadbeef);
2608     ok(!HiliteMenuItem(hWnd, NULL, 1, MF_HILITE | MF_BYPOSITION),
2609       "HiliteMenuItem: call should have failed.\n");
2610     ok(GetLastError() == 0xdeadbeef || /* 9x */
2611        GetLastError() == ERROR_INVALID_MENU_HANDLE /* NT */,
2612       "HiliteMenuItem: expected error ERROR_INVALID_MENU_HANDLE, got: %d\n", GetLastError());
2613 
2614     ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2615       "HiliteMenuItem: Item 2 is hilited\n");
2616 
2617     /* either MF_HILITE or MF_UNHILITE *and* MF_BYCOMMAND or MF_BYPOSITION need to be set */
2618 
2619     SetLastError(0xdeadbeef);
2620     ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_BYPOSITION),
2621       "HiliteMenuItem: call should have succeeded.\n");
2622     ok(GetLastError() == 0xdeadbeef,
2623       "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2624 
2625     ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2626       "HiliteMenuItem: Item 2 is hilited\n");
2627 
2628     SetLastError(0xdeadbeef);
2629     todo_wine
2630     {
2631     ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE),
2632       "HiliteMenuItem: call should have succeeded.\n");
2633     }
2634     ok(GetLastError() == 0xdeadbeef,
2635       "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2636 
2637     ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2638       "HiliteMenuItem: Item 2 is hilited\n");
2639 
2640     /* hilite a menu item (by position) */
2641 
2642     SetLastError(0xdeadbeef);
2643     ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2644       "HiliteMenuItem: call should not have failed.\n");
2645     ok(GetLastError() == 0xdeadbeef,
2646       "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2647 
2648     todo_wine
2649     {
2650     ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2651       "HiliteMenuItem: Item 2 is not hilited\n");
2652     }
2653 
2654     /* unhilite a menu item (by position) */
2655 
2656     SetLastError(0xdeadbeef);
2657     ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_UNHILITE | MF_BYPOSITION),
2658       "HiliteMenuItem: call should not have failed.\n");
2659     ok(GetLastError() == 0xdeadbeef,
2660       "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2661 
2662     ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2663       "HiliteMenuItem: Item 2 is hilited\n");
2664 
2665     /* hilite a menu item (by command) */
2666 
2667     SetLastError(0xdeadbeef);
2668     ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_HILITE | MF_BYCOMMAND),
2669       "HiliteMenuItem: call should not have failed.\n");
2670     ok(GetLastError() == 0xdeadbeef,
2671       "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2672 
2673     todo_wine
2674     {
2675     ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2676       "HiliteMenuItem: Item 3 is not hilited\n");
2677     }
2678 
2679     /* unhilite a menu item (by command) */
2680 
2681     SetLastError(0xdeadbeef);
2682     ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_UNHILITE | MF_BYCOMMAND),
2683       "HiliteMenuItem: call should not have failed.\n");
2684     ok(GetLastError() == 0xdeadbeef,
2685       "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2686 
2687     ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE),
2688       "HiliteMenuItem: Item 3 is hilited\n");
2689 
2690     DestroyWindow(hWnd);
2691 }
2692 
2693 static void check_menu_items(HMENU hmenu, UINT checked_cmd, UINT checked_type,
2694                              UINT checked_state)
2695 {
2696     INT i, count;
2697 
2698     count = GetMenuItemCount(hmenu);
2699     ok (count != -1, "GetMenuItemCount returned -1\n");
2700 
2701     for (i = 0; i < count; i++)
2702     {
2703         BOOL ret;
2704         MENUITEMINFOA mii;
2705 
2706         memset(&mii, 0, sizeof(mii));
2707         mii.cbSize = sizeof(mii);
2708         mii.fMask  = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU;
2709         ret = GetMenuItemInfoA(hmenu, i, TRUE, &mii);
2710         ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2711 
2712         if (winetest_debug > 1)
2713             trace("item #%u: fType %04x, fState %04x, wID %u, hSubMenu %p\n",
2714                   i, mii.fType, mii.fState, mii.wID, mii.hSubMenu);
2715 
2716         if (mii.hSubMenu)
2717         {
2718             ok(mii.wID == (UINT_PTR)mii.hSubMenu, "id %u: wID %x should be equal to hSubMenu %p\n",
2719                checked_cmd, mii.wID, mii.hSubMenu);
2720             if (!GetMenuItemCount(mii.hSubMenu))
2721             {
2722                 ok(mii.fType == checked_type, "id %u: expected fType %04x, got %04x\n", checked_cmd, checked_type, mii.fType);
2723                 ok(mii.fState == checked_state, "id %u: expected fState %04x, got %04x\n", checked_cmd, checked_state, mii.fState);
2724             }
2725             check_menu_items(mii.hSubMenu, checked_cmd, checked_type, checked_state);
2726         }
2727         else
2728         {
2729             if (mii.wID == checked_cmd)
2730             {
2731                 ok(mii.fType == checked_type, "id %u: expected fType %04x, got %04x\n", checked_cmd, checked_type, mii.fType);
2732                 ok(mii.fState == checked_state, "id %u: expected fState %04x, got %04x\n", checked_cmd, checked_state, mii.fState);
2733                 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2734             }
2735             else
2736             {
2737                 ok(mii.fType != MFT_RADIOCHECK, "id %u: not expected fType MFT_RADIOCHECK on cmd %u\n", checked_cmd, mii.wID);
2738 
2739                 if (mii.fType == MFT_SEPARATOR)
2740                 {
2741                     ok(mii.fState == MFS_GRAYED, "id %u: expected fState MFS_GRAYED, got %04x\n", checked_cmd, mii.fState);
2742                     ok(mii.wID == 0, "id %u: expected wID 0, got %u\n", checked_cmd, mii.wID);
2743                 }
2744                 else
2745                 {
2746                     ok(mii.fState == 0, "id %u: expected fState 0, got %04x\n", checked_cmd, mii.fState);
2747                     ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2748                 }
2749             }
2750         }
2751     }
2752 }
2753 
2754 static void clear_ftype_and_state(HMENU hmenu, UINT id, UINT flags)
2755 {
2756     BOOL ret;
2757     MENUITEMINFOA mii;
2758 
2759     memset(&mii, 0, sizeof(mii));
2760     mii.cbSize = sizeof(mii);
2761     mii.fMask  = MIIM_FTYPE | MIIM_STATE;
2762     ret = SetMenuItemInfoA(hmenu, id, (flags & MF_BYPOSITION) != 0, &mii);
2763     ok(ret, "SetMenuItemInfo(%u) failed\n", id);
2764 }
2765 
2766 static void test_CheckMenuRadioItem(void)
2767 {
2768     BOOL ret;
2769     HMENU hmenu;
2770 
2771     hmenu = LoadMenuA(GetModuleHandleA(NULL), MAKEINTRESOURCEA(1));
2772     assert(hmenu != 0);
2773 
2774     check_menu_items(hmenu, -1, 0, 0);
2775 
2776     ret = CheckMenuRadioItem(hmenu, 100, 100, 100, MF_BYCOMMAND);
2777     ok(ret, "CheckMenuRadioItem failed\n");
2778     check_menu_items(hmenu, 100, MFT_RADIOCHECK, MFS_CHECKED);
2779 
2780     /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2781     ret = CheckMenuRadioItem(hmenu, 100, 100, -1, MF_BYCOMMAND);
2782     ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2783     check_menu_items(hmenu, 100, MFT_RADIOCHECK, 0);
2784 
2785     /* clear check */
2786     clear_ftype_and_state(hmenu, 100, MF_BYCOMMAND);
2787     check_menu_items(hmenu, -1, 0, 0);
2788 
2789     /* first and checked items are on different menus */
2790     ret = CheckMenuRadioItem(hmenu, 0, 300, 202, MF_BYCOMMAND);
2791     ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2792     check_menu_items(hmenu, -1, 0, 0);
2793 
2794     ret = CheckMenuRadioItem(hmenu, 200, 300, 202, MF_BYCOMMAND);
2795     ok(ret, "CheckMenuRadioItem failed\n");
2796     check_menu_items(hmenu, 202, MFT_RADIOCHECK, MFS_CHECKED);
2797 
2798     /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2799     ret = CheckMenuRadioItem(hmenu, 202, 202, -1, MF_BYCOMMAND);
2800     ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2801     check_menu_items(hmenu, 202, MFT_RADIOCHECK, 0);
2802 
2803     /* clear check */
2804     clear_ftype_and_state(hmenu, 202, MF_BYCOMMAND);
2805     check_menu_items(hmenu, -1, 0, 0);
2806 
2807     /* just for fun, try to check separator */
2808     ret = CheckMenuRadioItem(hmenu, 0, 300, 0, MF_BYCOMMAND);
2809     ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2810     check_menu_items(hmenu, -1, 0, 0);
2811 }
2812 
2813 static void test_menu_resource_layout(void)
2814 {
2815     static const struct
2816     {
2817         MENUITEMTEMPLATEHEADER mith;
2818         WORD data[14];
2819     } menu_template =
2820     {
2821         { 0, 0 }, /* versionNumber, offset */
2822         {
2823             /* mtOption, mtID, mtString[] '\0' terminated */
2824             MF_STRING, 1, 'F', 0,
2825             MF_STRING, 2, 0,
2826             MF_SEPARATOR, 3, 0,
2827             /* MF_SEPARATOR, 4, 'S', 0, FIXME: Wine ignores 'S' */
2828             MF_STRING|MF_GRAYED|MF_END, 5, 'E', 0
2829         }
2830     };
2831     static const struct
2832     {
2833         UINT type, state, id;
2834         const char *str;
2835     } menu_data[] =
2836     {
2837         { MF_STRING, MF_ENABLED, 1, "F" },
2838         { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 2, "" },
2839         { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 3, "" },
2840         /*{ MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 4, "S" }, FIXME: Wine ignores 'S'*/
2841         { MF_STRING, MF_GRAYED, 5, "E" },
2842         { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 6, "" },
2843         { MF_STRING, MF_ENABLED, 7, "" },
2844         { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 8, "" }
2845     };
2846     HMENU hmenu;
2847     INT count, i;
2848     BOOL ret;
2849 
2850     hmenu = LoadMenuIndirectA(&menu_template);
2851     ok(hmenu != 0, "LoadMenuIndirect error %u\n", GetLastError());
2852 
2853     ret = AppendMenuA(hmenu, MF_STRING, 6, NULL);
2854     ok(ret, "AppendMenu failed\n");
2855     ret = AppendMenuA(hmenu, MF_STRING, 7, "\0");
2856     ok(ret, "AppendMenu failed\n");
2857     ret = AppendMenuA(hmenu, MF_SEPARATOR, 8, "separator");
2858     ok(ret, "AppendMenu failed\n");
2859 
2860     count = GetMenuItemCount(hmenu);
2861     ok(count == sizeof(menu_data)/sizeof(menu_data[0]),
2862        "expected %u menu items, got %u\n",
2863        (UINT)(sizeof(menu_data)/sizeof(menu_data[0])), count);
2864 
2865     for (i = 0; i < count; i++)
2866     {
2867         char buf[20];
2868         MENUITEMINFOA mii;
2869 
2870         memset(&mii, 0, sizeof(mii));
2871         mii.cbSize = sizeof(mii);
2872         mii.dwTypeData = buf;
2873         mii.cch = sizeof(buf);
2874         mii.fMask  = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_STRING;
2875         ret = GetMenuItemInfoA(hmenu, i, TRUE, &mii);
2876         ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2877         if (winetest_debug > 1)
2878             trace("item #%u: fType %04x, fState %04x, wID %u, dwTypeData %s\n",
2879                   i, mii.fType, mii.fState, mii.wID, (LPCSTR)mii.dwTypeData);
2880 
2881         ok(mii.fType == menu_data[i].type,
2882            "%u: expected fType %04x, got %04x\n", i, menu_data[i].type, mii.fType);
2883         ok(mii.fState == menu_data[i].state,
2884            "%u: expected fState %04x, got %04x\n", i, menu_data[i].state, mii.fState);
2885         ok(mii.wID == menu_data[i].id,
2886            "%u: expected wID %04x, got %04x\n", i, menu_data[i].id, mii.wID);
2887         ok(mii.cch == strlen(menu_data[i].str),
2888            "%u: expected cch %u, got %u\n", i, (UINT)strlen(menu_data[i].str), mii.cch);
2889         ok(!strcmp(mii.dwTypeData, menu_data[i].str),
2890            "%u: expected dwTypeData %s, got %s\n", i, menu_data[i].str, (LPCSTR)mii.dwTypeData);
2891     }
2892 
2893     DestroyMenu(hmenu);
2894 }
2895 
2896 struct menu_data
2897 {
2898     UINT type, id;
2899     const char *str;
2900 };
2901 
2902 static HMENU create_menu_from_data(const struct menu_data *item, INT item_count)
2903 {
2904     HMENU hmenu;
2905     INT i;
2906     BOOL ret;
2907 
2908     hmenu = CreateMenu();
2909     assert(hmenu != 0);
2910 
2911     for (i = 0; i < item_count; i++)
2912     {
2913         SetLastError(0xdeadbeef);
2914         ret = AppendMenuA(hmenu, item[i].type, item[i].id, item[i].str);
2915         ok(ret, "%d: AppendMenu(%04x, %04x, %p) error %u\n",
2916            i, item[i].type, item[i].id, item[i].str, GetLastError());
2917     }
2918     return hmenu;
2919 }
2920 
2921 /* use InsertMenuItem: does not set the MFT_BITMAP flag,
2922  * and does not accept non-magic bitmaps with invalid
2923  * bitmap handles */
2924 static HMENU create_menuitem_from_data(const struct menu_data *item, INT item_count)
2925 {
2926     HMENU hmenu;
2927     INT i;
2928     BOOL ret;
2929     MENUITEMINFOA mii = { sizeof( MENUITEMINFOA) };
2930 
2931     hmenu = CreateMenu();
2932     assert(hmenu != 0);
2933 
2934     for (i = 0; i < item_count; i++)
2935     {
2936         SetLastError(0xdeadbeef);
2937 
2938         mii.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STATE;
2939         mii.fType = 0;
2940         if(  item[i].type & MFT_BITMAP)
2941         {
2942             mii.fMask |= MIIM_BITMAP;
2943             mii.hbmpItem =  (HBITMAP)item[i].str;
2944         }
2945         else if(  item[i].type & MFT_SEPARATOR)
2946             mii.fType = MFT_SEPARATOR;
2947         else
2948         {
2949             mii.fMask |= MIIM_STRING;
2950             mii.dwTypeData =  (LPSTR)item[i].str;
2951             mii.cch = strlen(  item[i].str);
2952         }
2953         mii.fState = 0;
2954         if(  item[i].type & MF_HELP) mii.fType |= MF_HELP;
2955         mii.wID = item[i].id;
2956         ret = InsertMenuItemA( hmenu, -1, TRUE, &mii);
2957         ok(ret, "%d: InsertMenuItem(%04x, %04x, %p) error %u\n",
2958            i, item[i].type, item[i].id, item[i].str, GetLastError());
2959     }
2960     return hmenu;
2961 }
2962 
2963 static void compare_menu_data(HMENU hmenu, const struct menu_data *item, INT item_count)
2964 {
2965     INT count, i;
2966     BOOL ret;
2967 
2968     count = GetMenuItemCount(hmenu);
2969     ok(count == item_count, "expected %d, got %d menu items\n", count, item_count);
2970 
2971     for (i = 0; i < count; i++)
2972     {
2973         char buf[20];
2974         MENUITEMINFOA mii;
2975 
2976         memset(&mii, 0, sizeof(mii));
2977         mii.cbSize = sizeof(mii);
2978         mii.dwTypeData = buf;
2979         mii.cch = sizeof(buf);
2980         mii.fMask  = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_BITMAP;
2981         ret = GetMenuItemInfoA(hmenu, i, TRUE, &mii);
2982         ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2983 
2984         if (winetest_debug > 1)
2985             trace("item #%u: fType %04x, fState %04x, wID %04x, hbmp %p\n",
2986                   i, mii.fType, mii.fState, mii.wID, mii.hbmpItem);
2987 
2988         ok(mii.fType == item[i].type,
2989            "%u: expected fType %04x, got %04x\n", i, item[i].type, mii.fType);
2990         ok(mii.wID == item[i].id,
2991            "%u: expected wID %04x, got %04x\n", i, item[i].id, mii.wID);
2992         if (mii.hbmpItem || !item[i].str)
2993             /* For some reason Windows sets high word to not 0 for
2994              * not "magic" ids.
2995              */
2996             ok(LOWORD(mii.hbmpItem) == LOWORD(item[i].str),
2997                "%u: expected hbmpItem %p, got %p\n", i, item[i].str, mii.hbmpItem);
2998         else
2999         {
3000             ok(mii.cch == strlen(item[i].str),
3001                "%u: expected cch %u, got %u\n", i, (UINT)strlen(item[i].str), mii.cch);
3002             ok(!strcmp(mii.dwTypeData, item[i].str),
3003                "%u: expected dwTypeData %s, got %s\n", i, item[i].str, (LPCSTR)mii.dwTypeData);
3004         }
3005     }
3006 }
3007 
3008 static void test_InsertMenu(void)
3009 {
3010     HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
3011     /* Note: XP treats only bitmap handles 1 - 6 as "magic" ones
3012      * regardless of their id.
3013      */
3014     static const struct menu_data in1[] =
3015     {
3016         { MF_STRING, 1, "File" },
3017         { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCEA(1) },
3018         { MF_STRING|MF_HELP, 2, "Help" }
3019     };
3020     static const struct menu_data out1[] =
3021     {
3022         { MF_STRING, 1, "File" },
3023         { MF_STRING|MF_HELP, 2, "Help" },
3024         { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCEA(1) }
3025     };
3026     static const struct menu_data out1a[] =
3027     {
3028         { MF_STRING, 1, "File" },
3029         { MF_STRING|MF_HELP, 2, "Help" },
3030         { MF_HELP, SC_CLOSE, MAKEINTRESOURCEA(1) }
3031     };
3032     const struct menu_data in2[] =
3033     {
3034         { MF_STRING, 1, "File" },
3035         { MF_BITMAP|MF_HELP, SC_CLOSE, (char*)hbm },
3036         { MF_STRING|MF_HELP, 2, "Help" }
3037     };
3038     const struct menu_data out2[] =
3039     {
3040         { MF_STRING, 1, "File" },
3041         { MF_BITMAP|MF_HELP, SC_CLOSE, (char*)hbm },
3042         { MF_STRING|MF_HELP, 2, "Help" }
3043     };
3044     const struct menu_data out2a[] =
3045     {
3046         { MF_STRING, 1, "File" },
3047         { MF_HELP, SC_CLOSE, (char*)hbm },
3048         { MF_STRING|MF_HELP, 2, "Help" }
3049     };
3050     static const struct menu_data in3[] =
3051     {
3052         { MF_STRING, 1, "File" },
3053         { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCEA(1) },
3054         { MF_STRING|MF_HELP, 2, "Help" }
3055     };
3056     static const struct menu_data out3[] =
3057     {
3058         { MF_STRING, 1, "File" },
3059         { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCEA(0) },
3060         { MF_STRING|MF_HELP, 2, "Help" },
3061     };
3062     static const struct menu_data in4[] =
3063     {
3064         { MF_STRING, 1, "File" },
3065         { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCEA(1) },
3066         { MF_STRING|MF_HELP, 2, "Help" }
3067     };
3068     static const struct menu_data out4[] =
3069     {
3070         { MF_STRING, 1, "File" },
3071         { MF_STRING|MF_HELP, 2, "Help" },
3072         { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCEA(1) }
3073     };
3074     static const struct menu_data out4a[] =
3075     {
3076         { MF_STRING, 1, "File" },
3077         { MF_STRING|MF_HELP, 2, "Help" },
3078         { MF_HELP, 1, MAKEINTRESOURCEA(1) }
3079     };
3080     HMENU hmenu;
3081 
3082 #define create_menu(a) create_menu_from_data((a), sizeof(a)/sizeof((a)[0]))
3083 #define create_menuitem(a) create_menuitem_from_data((a), sizeof(a)/sizeof((a)[0]))
3084 #define compare_menu(h, a) compare_menu_data((h), (a), sizeof(a)/sizeof((a)[0]))
3085 
3086     hmenu = create_menu(in1);
3087     compare_menu(hmenu, out1);
3088     DestroyMenu(hmenu);
3089 
3090     hmenu = create_menu(in2);
3091     compare_menu(hmenu, out2);
3092     DestroyMenu(hmenu);
3093 
3094     hmenu = create_menu(in3);
3095     compare_menu(hmenu, out3);
3096     DestroyMenu(hmenu);
3097 
3098     hmenu = create_menu(in4);
3099     compare_menu(hmenu, out4);
3100     DestroyMenu(hmenu);
3101 
3102     /* now using InsertMenuItemInfo */
3103     hmenu = create_menuitem(in1);
3104     compare_menu(hmenu, out1a);
3105     DestroyMenu(hmenu);
3106 
3107     hmenu = create_menuitem(in2);
3108     compare_menu(hmenu, out2a);
3109     DestroyMenu(hmenu);
3110 
3111     hmenu = create_menuitem(in3);
3112     compare_menu(hmenu, out3);
3113     DestroyMenu(hmenu);
3114 
3115     hmenu = create_menuitem(in4);
3116     compare_menu(hmenu, out4a);
3117     DestroyMenu(hmenu);
3118 
3119 #undef create_menu
3120 #undef create_menuitem
3121 #undef compare_menu
3122 }
3123 
3124 static void test_menu_getmenuinfo(void)
3125 {
3126     HMENU hmenu;
3127     MENUINFO mi = {0};
3128     BOOL ret;
3129     DWORD gle;
3130 
3131     if (!pGetMenuInfo)
3132     {
3133         win_skip("GetMenuInfo is not available\n");
3134         return;
3135     }
3136 
3137     /* create a menu */
3138     hmenu = CreateMenu();
3139     assert( hmenu);
3140     /* test some parameter errors */
3141     SetLastError(0xdeadbeef);
3142     ret = pGetMenuInfo( hmenu, NULL);
3143     gle= GetLastError();
3144     ok( !ret, "GetMenuInfo() should have failed\n");
3145     ok( gle == ERROR_INVALID_PARAMETER ||
3146         broken(gle == 0xdeadbeef), /* Win98, WinME */
3147         "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
3148     SetLastError(0xdeadbeef);
3149     mi.cbSize = 0;
3150     ret = pGetMenuInfo( hmenu, &mi);
3151     gle= GetLastError();
3152     ok( !ret, "GetMenuInfo() should have failed\n");
3153     ok( gle == ERROR_INVALID_PARAMETER ||
3154         broken(gle == 0xdeadbeef), /* Win98, WinME */
3155         "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
3156     SetLastError(0xdeadbeef);
3157     mi.cbSize = sizeof( MENUINFO);
3158     ret = pGetMenuInfo( hmenu, &mi);
3159     gle= GetLastError();
3160     ok( ret, "GetMenuInfo() should have succeeded\n");
3161     ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3162     SetLastError(0xdeadbeef);
3163     mi.cbSize = 0;
3164     ret = pGetMenuInfo( NULL, &mi);
3165     gle= GetLastError();
3166     ok( !ret, "GetMenuInfo() should have failed\n");
3167     ok( gle == ERROR_INVALID_PARAMETER ||
3168         broken(gle == 0xdeadbeef), /* Win98, WinME */
3169         "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
3170     /* clean up */
3171     DestroyMenu( hmenu);
3172     return;
3173 }
3174 
3175 static void test_menu_setmenuinfo(void)
3176 {
3177     HMENU hmenu, hsubmenu;
3178     MENUINFO mi = {0};
3179     MENUITEMINFOA mii = { sizeof(MENUITEMINFOA) };
3180     BOOL ret;
3181     DWORD gle;
3182     HBRUSH brush;
3183 
3184     if (!pGetMenuInfo || !pSetMenuInfo)
3185     {
3186         win_skip("Get/SetMenuInfo are not available\n");
3187         return;
3188     }
3189 
3190     /* create a menu with a submenu */
3191     hmenu = CreateMenu();
3192     hsubmenu = CreateMenu();
3193     assert( hmenu && hsubmenu);
3194     mii.fMask = MIIM_SUBMENU;
3195     mii.hSubMenu = hsubmenu;
3196     ret = InsertMenuItemA( hmenu, 0, FALSE, &mii);
3197     ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
3198     /* test some parameter errors */
3199     SetLastError(0xdeadbeef);
3200     ret = pSetMenuInfo( hmenu, NULL);
3201     gle= GetLastError();
3202     ok( !ret, "SetMenuInfo() should have failed\n");
3203     ok( gle == ERROR_INVALID_PARAMETER ||
3204         broken(gle == 0xdeadbeef), /* Win98, WinME */
3205         "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
3206     SetLastError(0xdeadbeef);
3207     mi.cbSize = 0;
3208     ret = pSetMenuInfo( hmenu, &mi);
3209     gle= GetLastError();
3210     ok( !ret, "SetMenuInfo() should have failed\n");
3211     ok( gle == ERROR_INVALID_PARAMETER ||
3212         broken(gle == 0xdeadbeef), /* Win98, WinME */
3213         "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
3214     SetLastError(0xdeadbeef);
3215     mi.cbSize = sizeof( MENUINFO);
3216     ret = pSetMenuInfo( hmenu, &mi);
3217     gle= GetLastError();
3218     ok( ret, "SetMenuInfo() should have succeeded\n");
3219     ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
3220     SetLastError(0xdeadbeef);
3221     mi.cbSize = 0;
3222     ret = pSetMenuInfo( NULL, &mi);
3223     gle= GetLastError();
3224     ok( !ret, "SetMenuInfo() should have failed\n");
3225     ok( gle == ERROR_INVALID_PARAMETER ||
3226         broken(gle == 0xdeadbeef), /* Win98, WinME */
3227         "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
3228     /* functional tests */
3229     /* menu and submenu should have the CHECKORBMP style bit cleared */
3230     SetLastError(0xdeadbeef);
3231     mi.cbSize = sizeof( MENUINFO);
3232     mi.fMask = MIM_STYLE;
3233     ret = pGetMenuInfo( hmenu, &mi);
3234     gle= GetLastError();
3235     ok( ret, "GetMenuInfo() should have succeeded\n");
3236     ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3237     ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
3238     SetLastError(0xdeadbeef);
3239     mi.cbSize = sizeof( MENUINFO);
3240     mi.fMask = MIM_STYLE;
3241     ret = pGetMenuInfo( hsubmenu, &mi);
3242     gle= GetLastError();
3243     ok( ret, "GetMenuInfo() should have succeeded\n");
3244     ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3245     ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
3246     /* SetMenuInfo() */
3247     SetLastError(0xdeadbeef);
3248     mi.cbSize = sizeof( MENUINFO);
3249     mi.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS;
3250     mi.dwStyle = MNS_CHECKORBMP;
3251     ret = pSetMenuInfo( hmenu, &mi);
3252     gle= GetLastError();
3253     ok( ret, "SetMenuInfo() should have succeeded\n");
3254     ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
3255     /* Now both menus should have the MNS_CHECKORBMP style bit set */
3256     SetLastError(0xdeadbeef);
3257     mi.cbSize = sizeof( MENUINFO);
3258     mi.fMask = MIM_STYLE;
3259     ret = pGetMenuInfo( hmenu, &mi);
3260     gle= GetLastError();
3261     ok( ret, "GetMenuInfo() should have succeeded\n");
3262     ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3263     ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
3264     SetLastError(0xdeadbeef);
3265     mi.cbSize = sizeof( MENUINFO);
3266     mi.fMask = MIM_STYLE;
3267     ret = pGetMenuInfo( hsubmenu, &mi);
3268     gle= GetLastError();
3269     ok( ret, "GetMenuInfo() should have succeeded\n");
3270     ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3271     ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
3272     /* now repeat that without the APPLYTOSUBMENUS flag and another style bit */
3273     SetLastError(0xdeadbeef);
3274     mi.cbSize = sizeof( MENUINFO);
3275     mi.fMask = MIM_STYLE ;
3276     mi.dwStyle = MNS_NOCHECK;
3277     ret = pSetMenuInfo( hmenu, &mi);
3278     gle= GetLastError();
3279     ok( ret, "SetMenuInfo() should have succeeded\n");
3280     ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
3281     /* Now only the top menu should have the MNS_NOCHECK style bit set */
3282     SetLastError(0xdeadbeef);
3283     mi.cbSize = sizeof( MENUINFO);
3284     mi.fMask = MIM_STYLE;
3285     ret = pGetMenuInfo( hmenu, &mi);
3286     gle= GetLastError();
3287     ok( ret, "GetMenuInfo() should have succeeded\n");
3288     ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3289     ok( mi.dwStyle & MNS_NOCHECK, "menustyle was expected to have the MNS_NOCHECK flag\n");
3290     SetLastError(0xdeadbeef);
3291     mi.cbSize = sizeof( MENUINFO);
3292     mi.fMask = MIM_STYLE;
3293     ret = pGetMenuInfo( hsubmenu, &mi);
3294     gle= GetLastError();
3295     ok( ret, "GetMenuInfo() should have succeeded\n");
3296     ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3297     ok( !(mi.dwStyle & MNS_NOCHECK), "menustyle was not expected to have the MNS_NOCHECK flag\n");
3298 
3299     /* test background brush */
3300     mi.cbSize = sizeof(mi);
3301     mi.fMask = MIM_BACKGROUND;
3302     ret = pGetMenuInfo( hmenu, &mi );
3303     ok( ret, "GetMenuInfo() should have succeeded\n" );
3304     ok( mi.hbrBack == NULL, "got %p\n", mi.hbrBack );
3305 
3306     brush = CreateSolidBrush( RGB(0xff, 0, 0) );
3307     mi.hbrBack = brush;
3308     ret = pSetMenuInfo( hmenu, &mi );
3309     ok( ret, "SetMenuInfo() should have succeeded\n" );
3310     mi.hbrBack = NULL;
3311     ret = pGetMenuInfo( hmenu, &mi );
3312     ok( ret, "GetMenuInfo() should have succeeded\n" );
3313     ok( mi.hbrBack == brush, "got %p original %p\n", mi.hbrBack, brush );
3314 
3315     mi.hbrBack = NULL;
3316     ret = pSetMenuInfo( hmenu, &mi );
3317     ok( ret, "SetMenuInfo() should have succeeded\n" );
3318     ret = pGetMenuInfo( hmenu, &mi );
3319     ok( ret, "GetMenuInfo() should have succeeded\n" );
3320     ok( mi.hbrBack == NULL, "got %p\n", mi.hbrBack );
3321     DeleteObject( brush );
3322 
3323     /* clean up */
3324     DestroyMenu( hsubmenu);
3325     DestroyMenu( hmenu);
3326     return;
3327 }
3328 
3329 /* little func to easy switch either TrackPopupMenu() or TrackPopupMenuEx() */
3330 static DWORD MyTrackPopupMenu( int ex, HMENU hmenu, UINT flags, INT x, INT y, HWND hwnd, LPTPMPARAMS ptpm)
3331 {
3332     return ex
3333         ? TrackPopupMenuEx( hmenu, flags, x, y, hwnd, ptpm)
3334         : TrackPopupMenu( hmenu, flags, x, y, 0, hwnd, NULL);
3335 }
3336 
3337 /* some TrackPopupMenu and TrackPopupMenuEx tests */
3338 /* the LastError values differ between NO_ERROR and invalid handle */
3339 /* between all windows versions tested. The first value is that valid on XP  */
3340 /* Vista was the only that made returned different error values */
3341 /* between the TrackPopupMenu and TrackPopupMenuEx functions */
3342 static void test_menu_trackpopupmenu(void)
3343 {
3344     BOOL ret;
3345     HMENU hmenu;
3346     DWORD gle;
3347     int Ex;
3348     HWND hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
3349             WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
3350             NULL, NULL, NULL, NULL);
3351     ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
3352     if (!hwnd) return;
3353     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
3354     for( Ex = 0; Ex < 2; Ex++)
3355     {
3356         hmenu = CreatePopupMenu();
3357         ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
3358         if (!hmenu)
3359         {
3360             DestroyWindow(hwnd);
3361             return;
3362         }
3363         /* display the menu */
3364         /* start with an invalid menu handle */
3365         SetLastError(0xdeadbeef);
3366 
3367         gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
3368         ret = MyTrackPopupMenu( Ex, NULL, TPM_RETURNCMD, 100,100, hwnd, NULL);
3369         gle = GetLastError();
3370         ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
3371         ok( gle == ERROR_INVALID_MENU_HANDLE
3372             || broken (gle == 0xdeadbeef) /* win95 */
3373             || broken (gle == NO_ERROR) /* win98/ME */
3374             ,"TrackPopupMenu%s error got %u expected %u\n",
3375             Ex ? "Ex" : "", gle, ERROR_INVALID_MENU_HANDLE);
3376         ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
3377                 "got unexpected message(s)%s%s%s\n",
3378                 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
3379                 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
3380                 gflag_initmenu ? "WM_INITMENU": "");
3381         /* another one but not NULL */
3382         SetLastError(0xdeadbeef);
3383         gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
3384         ret = MyTrackPopupMenu( Ex, (HMENU)hwnd, TPM_RETURNCMD, 100,100, hwnd, NULL);
3385         gle = GetLastError();
3386         ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
3387         ok( gle == ERROR_INVALID_MENU_HANDLE
3388             || broken (gle == 0xdeadbeef) /* win95 */
3389             || broken (gle == NO_ERROR) /* win98/ME */
3390             ,"TrackPopupMenu%s error got %u expected %u\n",
3391             Ex ? "Ex" : "", gle, ERROR_INVALID_MENU_HANDLE);
3392         ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
3393                 "got unexpected message(s)%s%s%s\n",
3394                 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
3395                 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
3396                 gflag_initmenu ? "WM_INITMENU": "");
3397 
3398         /* invalid window */
3399         SetLastError(0xdeadbeef);
3400         gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
3401         ret = MyTrackPopupMenu( Ex, hmenu, TPM_RETURNCMD, 100,100, 0, NULL);
3402         gle = GetLastError();
3403         ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
3404         ok( gle == ERROR_INVALID_WINDOW_HANDLE, "TrackPopupMenu%s error got %u\n", Ex ? "Ex" : "", gle );
3405         ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
3406                 "got unexpected message(s)%s%s%s\n",
3407                 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
3408                 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
3409                 gflag_initmenu ? "WM_INITMENU": "");
3410 
3411         /* now a somewhat successful call */
3412         SetLastError(0xdeadbeef);
3413         gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
3414         ret = MyTrackPopupMenu( Ex, hmenu, TPM_RETURNCMD, 100,100, hwnd, NULL);
3415         gle = GetLastError();
3416         ok( ret == 0, "TrackPopupMenu%s returned %d expected zero\n", Ex ? "Ex" : "", ret);
3417         ok( gle == NO_ERROR
3418             || gle == ERROR_INVALID_MENU_HANDLE /* NT4, win2k */
3419             || broken (gle == 0xdeadbeef) /* win95 */
3420             ,"TrackPopupMenu%s error got %u expected %u or %u\n",
3421             Ex ? "Ex" : "", gle, NO_ERROR, ERROR_INVALID_MENU_HANDLE);
3422         ok( gflag_initmenupopup && gflag_entermenuloop && gflag_initmenu,
3423                 "missed expected message(s)%s%s%s\n",
3424                 !gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
3425                 !gflag_entermenuloop ? "WM_INITMENULOOP ": "",
3426                 !gflag_initmenu ? "WM_INITMENU": "");
3427         /* and another */
3428         ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest");
3429         ok( ret, "AppendMenA has failed!\n");
3430         SetLastError(0xdeadbeef);
3431         gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
3432         ret = MyTrackPopupMenu( Ex, hmenu, TPM_RETURNCMD, 100,100, hwnd, NULL);
3433         gle = GetLastError();
3434         ok( ret == 0, "TrackPopupMenu%s returned %d expected zero\n", Ex ? "Ex" : "", ret);
3435         ok( gle == NO_ERROR
3436             || gle == ERROR_INVALID_MENU_HANDLE /* NT4, win2k and Vista in the TrackPopupMenuEx case */
3437             || broken (gle == 0xdeadbeef) /* win95 */
3438             ,"TrackPopupMenu%s error got %u expected %u or %u\n",
3439             Ex ? "Ex" : "", gle, NO_ERROR, ERROR_INVALID_MENU_HANDLE);
3440         ok( gflag_initmenupopup && gflag_entermenuloop && gflag_initmenu,
3441                 "missed expected message(s)%s%s%s\n",
3442                 !gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
3443                 !gflag_entermenuloop ? "WM_INITMENULOOP ": "",
3444                 !gflag_initmenu ? "WM_INITMENU": "");
3445         DestroyMenu(hmenu);
3446     }
3447     /* clean up */
3448     DestroyWindow(hwnd);
3449 }
3450 
3451 static HMENU g_hmenu;
3452 
3453 static LRESULT WINAPI menu_track_again_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3454 {
3455     switch (msg)
3456     {
3457     case WM_ENTERMENULOOP:
3458     {
3459         BOOL ret;
3460 
3461         /* try a recursive call */
3462         SetLastError(0xdeadbeef);
3463         ret = TrackPopupMenu(g_hmenu, 0, 100, 100, 0, hwnd, NULL);
3464         ok(ret == FALSE, "got %d\n", ret);
3465         ok(GetLastError() == ERROR_POPUP_ALREADY_ACTIVE ||
3466            broken(GetLastError() == 0xdeadbeef) /* W9x */, "got %d\n", GetLastError());
3467 
3468         /* exit menu modal loop
3469          * ( A SendMessage does not work on NT3.51 here ) */
3470         return PostMessageA(hwnd, WM_CANCELMODE, 0, 0);
3471     }
3472     }
3473     return DefWindowProcA(hwnd, msg, wparam, lparam);
3474 }
3475 
3476 static void test_menu_trackagain(void)
3477 {
3478     HWND hwnd;
3479     BOOL ret;
3480 
3481     hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
3482             WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
3483             NULL, NULL, NULL, NULL);
3484     ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
3485     if (!hwnd) return;
3486     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_track_again_wnd_proc);
3487 
3488     g_hmenu = CreatePopupMenu();
3489     ok(g_hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
3490 
3491     ret = AppendMenuA(g_hmenu, MF_STRING , 100, "item 1");
3492     ok(ret, "AppendMenu failed.\n");
3493     ret = AppendMenuA(g_hmenu, MF_STRING , 101, "item 2");
3494     ok(ret, "AppendMenu failed.\n");
3495 
3496     ret = TrackPopupMenu( g_hmenu, 0, 100, 100, 0, hwnd, NULL);
3497     ok(ret == TRUE, "got %d\n", ret);
3498 
3499     DestroyMenu(g_hmenu);
3500     DestroyWindow(hwnd);
3501 }
3502 
3503 /* test handling of WM_CANCELMODE messages */
3504 static int g_got_enteridle;
3505 static HWND g_hwndtosend;
3506 static LRESULT WINAPI menu_cancelmode_wnd_proc(HWND hwnd, UINT msg,
3507         WPARAM wparam, LPARAM lparam)
3508 {
3509     switch (msg)
3510     {
3511         case WM_ENTERMENULOOP:
3512             g_got_enteridle = 0;
3513             return SendMessageA( g_hwndtosend, WM_CANCELMODE, 0, 0);
3514         case WM_ENTERIDLE:
3515             {
3516                 if( g_got_enteridle++ == 0) {
3517                     /* little hack to get another WM_ENTERIDLE message */
3518                     PostMessageA( hwnd, WM_MOUSEMOVE, 0, 0);
3519                     return SendMessageA( g_hwndtosend, WM_CANCELMODE, 0, 0);
3520                 }
3521                 pEndMenu();
3522                 return TRUE;
3523             }
3524     }
3525     return DefWindowProcA( hwnd, msg, wparam, lparam);
3526 }
3527 
3528 static void test_menu_cancelmode(void)
3529 {
3530     DWORD ret;
3531     HWND hwnd, hwndchild;
3532     HMENU menu, menubar;
3533     MSG msg;
3534     if( !pEndMenu) { /* win95 */
3535         win_skip( "EndMenu is not available\n");
3536         return;
3537     }
3538     hwnd = CreateWindowExA( 0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
3539             WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
3540             NULL, NULL, NULL, NULL);
3541     hwndchild = CreateWindowExA( 0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
3542             WS_VISIBLE | WS_CHILD, 10, 10, 20, 20,
3543             hwnd, NULL, NULL, NULL);
3544     ok( hwnd != NULL && hwndchild != NULL,
3545             "CreateWindowEx failed with error %d\n", GetLastError());
3546     g_hwndtosend = hwnd;
3547     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_cancelmode_wnd_proc);
3548     SetWindowLongPtrA( hwndchild, GWLP_WNDPROC, (LONG_PTR)menu_cancelmode_wnd_proc);
3549     menu = CreatePopupMenu();
3550     ok( menu != NULL, "CreatePopupMenu failed with error %d\n", GetLastError());
3551     ret = AppendMenuA( menu, MF_STRING, 1, "winetest");
3552     ok( ret, "Functie failed lasterror is %u\n", GetLastError());
3553     /* seems to be needed only on wine :( */
3554     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
3555         DispatchMessageA(&msg);
3556     /* test the effect of sending a WM_CANCELMODE message in the WM_INITMENULOOP
3557      * handler of the menu owner */
3558     /* test results is extracted from variable g_got_enteridle. Possible values:
3559      * 0 : complete conformance. Sending WM_CANCELMODE cancels a menu initializing tracking
3560      * 1 : Sending WM_CANCELMODE cancels a menu that is in tracking state
3561      * 2 : Sending WM_CANCELMODE does not work
3562      */
3563     /* menu owner is top level window */
3564     g_hwndtosend = hwnd;
3565     TrackPopupMenu( menu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
3566     ok( g_got_enteridle == 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle);
3567     /* menu owner is child window */
3568     g_hwndtosend = hwndchild;
3569     TrackPopupMenu( menu, TPM_RETURNCMD, 100,100, 0, hwndchild, NULL);
3570     ok(g_got_enteridle == 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle);
3571     /* now send the WM_CANCELMODE messages to the WRONG window */
3572     /* those should fail ( to have any effect) */
3573     g_hwndtosend = hwnd;
3574     TrackPopupMenu( menu, TPM_RETURNCMD, 100,100, 0, hwndchild, NULL);
3575     ok( g_got_enteridle == 2, "received %d WM_ENTERIDLE messages, should be 2\n", g_got_enteridle);
3576 
3577     /* test canceling tracking in a window's menu bar */
3578     menubar = CreateMenu();
3579     ok( menubar != NULL, "CreateMenu failed with error %d\n", GetLastError());
3580     ret = AppendMenuA( menubar, MF_POPUP|MF_STRING, (UINT_PTR)menu, "winetest");
3581     ok( ret, "AppendMenuA failed lasterror is %u\n", GetLastError());
3582     ret = SetMenu( hwnd, menubar );
3583     ok( ret, "SetMenu failed lasterror is %u\n", GetLastError());
3584     /* initiate tracking */
3585     g_hwndtosend = hwnd;
3586     ret = SendMessageA( hwnd, WM_SYSCOMMAND, SC_KEYMENU, 0 );
3587     ok( ret == 0, "Sending WM_SYSCOMMAND/SC_KEYMENU failed lasterror is %u\n", GetLastError());
3588     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
3589         DispatchMessageA(&msg);
3590     ok(g_got_enteridle == 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle);
3591 
3592     /* cleanup */
3593     DestroyMenu( menubar );
3594     DestroyMenu( menu);
3595     DestroyWindow( hwndchild);
3596     DestroyWindow( hwnd);
3597 }
3598 
3599 /* show menu trees have a maximum depth */
3600 static void test_menu_maxdepth(void)
3601 {
3602 #define NR_MENUS 100
3603     HMENU hmenus[ NR_MENUS];
3604     int i;
3605     DWORD ret;
3606 
3607     SetLastError(12345678);
3608     for( i = 0; i < NR_MENUS; i++) {
3609         hmenus[i] = CreatePopupMenu();
3610         if( !hmenus[i]) break;
3611     }
3612     ok( i == NR_MENUS, "could not create more than %d menu's\n", i);
3613     for( i = 1; i < NR_MENUS; i++) {
3614         ret = AppendMenuA( hmenus[i], MF_POPUP, (UINT_PTR)hmenus[i-1],"test");
3615         if( !ret) break;
3616     }
3617     trace("Maximum depth is %d\n", i);
3618     ok( GetLastError() == 12345678, "unexpected error %d\n",  GetLastError());
3619     ok( i < NR_MENUS ||
3620            broken( i == NR_MENUS), /* win98, NT */
3621            "no ( or very large) limit on menu depth!\n");
3622 
3623     for( i = 0; i < NR_MENUS; i++)
3624         DestroyMenu( hmenus[i]);
3625 }
3626 
3627 /* bug #12171 */
3628 static void test_menu_circref(void)
3629 {
3630     HMENU menu1, menu2;
3631     DWORD ret;
3632 
3633     menu1 = CreatePopupMenu();
3634     menu2 = CreatePopupMenu();
3635     ok( menu1 && menu2, "error creating menus.\n");
3636     ret = AppendMenuA( menu1, MF_POPUP, (UINT_PTR)menu2, "winetest");
3637     ok( ret, "AppendMenu failed, error is %d\n", GetLastError());
3638     ret = AppendMenuA( menu1, MF_STRING | MF_HILITE, 123, "winetest");
3639     ok( ret, "AppendMenu failed, error is %d\n", GetLastError());
3640     /* app chooses an id that happens to clash with its own hmenu */
3641     ret = AppendMenuA( menu2, MF_STRING, (UINT_PTR)menu2, "winetest");
3642     ok( ret, "AppendMenu failed, error is %d\n", GetLastError());
3643     /* now attempt to change the string of the first item of menu1 */
3644     ret = ModifyMenuA( menu1, (UINT_PTR)menu2, MF_POPUP, (UINT_PTR)menu2, "menu 2");
3645     ok( !ret ||
3646             broken( ret), /* win98, NT */
3647             "ModifyMenu should have failed.\n");
3648     if( !ret) { /* will probably stack fault if the ModifyMenu succeeded */
3649         ret = GetMenuState( menu1, 123, 0);
3650         ok( ret == MF_HILITE, "GetMenuState returned %x\n",ret);
3651     }
3652     DestroyMenu( menu2);
3653     DestroyMenu( menu1);
3654 }
3655 
3656 /* test how the menu texts are aligned when the menu items have
3657  * different combinations of text and bitmaps (bug #13350) */
3658 static void test_menualign(void)
3659 {
3660     BYTE bmfill[300];
3661     HMENU menu;
3662     HBITMAP hbm1, hbm2, hbm3;
3663     MENUITEMINFOA mii = { sizeof(MENUITEMINFOA) };
3664     DWORD ret;
3665     HWND hwnd;
3666     MENUINFO mi = { sizeof( MENUINFO)};
3667 
3668     if( !winetest_interactive) {
3669         skip( "interactive alignment tests.\n");
3670         return;
3671     }
3672     hwnd = CreateWindowExA(0,
3673             "STATIC",
3674             "Menu text alignment Test\nPlease make a selection.",
3675             WS_OVERLAPPEDWINDOW,
3676             100, 100,
3677             300, 300,
3678             NULL, NULL, 0, NULL);
3679     ShowWindow( hwnd, SW_SHOW);
3680     /* create bitmaps */
3681     memset( bmfill, 0xcc, sizeof( bmfill));
3682     hbm1 = CreateBitmap( 10,10,1,1,bmfill);
3683     hbm2 = CreateBitmap( 20,20,1,1,bmfill);
3684     hbm3 = CreateBitmap( 50,6,1,1,bmfill);
3685     ok( hbm1 && hbm2 && hbm3, "Creating bitmaps failed\n");
3686     menu = CreatePopupMenu();
3687     ok( menu != NULL, "CreatePopupMenu() failed\n");
3688     if( pGetMenuInfo) {
3689         mi.fMask = MIM_STYLE;
3690         ret = pGetMenuInfo( menu, &mi);
3691         ok( ret, "GetMenuInfo failed: %d\n", GetLastError());
3692         ok( menu != NULL, "GetMenuInfo() failed\n");
3693         ok( 0 == mi.dwStyle, "menuinfo style is %x\n", mi.dwStyle);
3694     }
3695     /* test 1 */
3696     mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3697     mii.wID = 1;
3698     mii.hbmpItem = hbm1;
3699     mii.dwTypeData = (LPSTR) " OK: menu texts are correctly left-aligned.";
3700     ret = InsertMenuItemA( menu, -1, TRUE, &mii);
3701     ok( ret, "InsertMenuItem() failed\n");
3702     mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID ;
3703     mii.wID = 2;
3704     mii.hbmpItem = hbm2;
3705     mii.dwTypeData = (LPSTR) " FAIL: menu texts are NOT left-aligned.";
3706     ret = InsertMenuItemA( menu, -1, TRUE, &mii);
3707     ok( ret, "InsertMenuItem() failed\n");
3708     ret = TrackPopupMenu( menu, TPM_RETURNCMD, 110, 200, 0, hwnd, NULL);
3709     ok( ret != 2, "User indicated that menu text alignment test 1 failed %d\n", ret);
3710     /* test 2*/
3711     mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3712     mii.wID = 3;
3713     mii.hbmpItem = hbm3;
3714     mii.dwTypeData = NULL;
3715     ret = InsertMenuItemA( menu, 0, TRUE, &mii);
3716     ok( ret, "InsertMenuItem() failed\n");
3717     mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3718     mii.wID = 1;
3719     mii.hbmpItem = hbm1;
3720     /* make the text a bit longer, to keep it readable */
3721     /* this bug is on winXP and reproduced on wine */
3722     mii.dwTypeData = (LPSTR) " OK: menu texts are to the right of the bitmaps........";
3723     ret = SetMenuItemInfoA( menu, 1, TRUE, &mii);
3724     ok( ret, "SetMenuItemInfo() failed\n");
3725     mii.wID = 2;
3726     mii.hbmpItem = hbm2;
3727     mii.dwTypeData = (LPSTR) " FAIL: menu texts are below the first bitmap.  ";
3728     ret = SetMenuItemInfoA( menu, 2, TRUE, &mii);
3729     ok( ret, "SetMenuItemInfo() failed\n");
3730     ret = TrackPopupMenu( menu, TPM_RETURNCMD, 110, 200, 0, hwnd, NULL);
3731     ok( ret != 2, "User indicated that menu text alignment test 2 failed %d\n", ret);
3732     /* test 3 */
3733     mii.fMask = MIIM_TYPE | MIIM_ID;
3734     mii.wID = 3;
3735     mii.fType = MFT_BITMAP;
3736     mii.dwTypeData = (LPSTR) hbm3;
3737     ret = SetMenuItemInfoA( menu, 0, TRUE, &mii);
3738     ok( ret, "SetMenuItemInfo() failed\n");
3739     mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3740     mii.wID = 1;
3741     mii.hbmpItem = NULL;
3742     mii.dwTypeData = (LPSTR) " OK: menu texts are below the bitmap.";
3743     ret = SetMenuItemInfoA( menu, 1, TRUE, &mii);
3744     ok( ret, "SetMenuItemInfo() failed\n");
3745     mii.wID = 2;
3746     mii.hbmpItem = NULL;
3747     mii.dwTypeData = (LPSTR) " FAIL: menu texts are NOT below the bitmap.";
3748     ret = SetMenuItemInfoA( menu, 2, TRUE, &mii);
3749     ok( ret, "SetMenuItemInfo() failed\n");
3750     ret = TrackPopupMenu( menu, TPM_RETURNCMD, 110, 200, 0, hwnd, NULL);
3751     ok( ret != 2, "User indicated that menu text alignment test 3 failed %d\n", ret);
3752     /* cleanup */
3753     DeleteObject( hbm1);
3754     DeleteObject( hbm2);
3755     DeleteObject( hbm3);
3756     DestroyMenu( menu);
3757     DestroyWindow( hwnd);
3758 }
3759 
3760 static LRESULT WINAPI menu_fill_in_init(HWND hwnd, UINT msg,
3761         WPARAM wparam, LPARAM lparam)
3762 {
3763     HMENU hmenupopup;
3764     BOOL ret;
3765     switch (msg)
3766     {
3767         case WM_INITMENUPOPUP:
3768             gflag_initmenupopup++;
3769             hmenupopup = (HMENU) wparam;
3770             ret = AppendMenuA(hmenupopup, MF_STRING , 100, "item 1");
3771             ok(ret, "AppendMenu failed.\n");
3772             ret = AppendMenuA(hmenupopup, MF_STRING , 101, "item 2");
3773             ok(ret, "AppendMenu failed.\n");
3774             break;
3775         case WM_ENTERMENULOOP:
3776             gflag_entermenuloop++;
3777             break;
3778         case WM_INITMENU:
3779             gflag_initmenu++;
3780             break;
3781         case WM_ENTERIDLE:
3782             gflag_enteridle++;
3783             PostMessageA(hwnd, WM_CANCELMODE, 0, 0);
3784             return TRUE;
3785         case WM_MENUSELECT:
3786             selectitem_wp = wparam;
3787             selectitem_lp = lparam;
3788             break;
3789     }
3790     return DefWindowProcA(hwnd, msg, wparam, lparam);
3791 }
3792 
3793 static void test_emptypopup(void)
3794 {
3795     BOOL ret;
3796     HMENU hmenu;
3797 
3798     HWND hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
3799                                WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
3800                                NULL, NULL, NULL, NULL);
3801     ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
3802     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
3803 
3804     hmenu = CreatePopupMenu();
3805     ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
3806 
3807     gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = gflag_enteridle = 0;
3808     selectitem_wp = 0xdeadbeef;
3809     selectitem_lp = 0xdeadbeef;
3810 
3811     ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
3812     ok(ret == 0, "got %i\n", ret);
3813 
3814     ok(gflag_initmenupopup == 1, "got %i\n", gflag_initmenupopup);
3815     ok(gflag_entermenuloop == 1, "got %i\n", gflag_entermenuloop);
3816     ok(gflag_initmenu == 1, "got %i\n", gflag_initmenu);
3817     ok(gflag_enteridle == 0, "got %i\n", gflag_initmenu);
3818 
3819     ok(selectitem_wp == 0xdeadbeef, "got %lx\n", selectitem_wp);
3820     ok(selectitem_lp == 0xdeadbeef, "got %lx\n", selectitem_lp);
3821 
3822     gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = gflag_enteridle = 0;
3823     selectitem_wp = 0xdeadbeef;
3824     selectitem_lp = 0xdeadbeef;
3825 
3826     ret = TrackPopupMenu( hmenu, 0, 100,100, 0, hwnd, NULL);
3827     ok(ret == 0, "got %i\n", ret);
3828 
3829     ok(gflag_initmenupopup == 1, "got %i\n", gflag_initmenupopup);
3830     ok(gflag_entermenuloop == 1, "got %i\n", gflag_entermenuloop);
3831     ok(gflag_initmenu == 1, "got %i\n", gflag_initmenu);
3832     ok(gflag_enteridle == 0, "got %i\n", gflag_initmenu);
3833 
3834     ok(selectitem_wp == 0xdeadbeef, "got %lx\n", selectitem_wp);
3835     ok(selectitem_lp == 0xdeadbeef, "got %lx\n", selectitem_lp);
3836 
3837     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_fill_in_init);
3838 
3839     gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = gflag_enteridle = 0;
3840     selectitem_wp = 0xdeadbeef;
3841     selectitem_lp = 0xdeadbeef;
3842 
3843     ret = TrackPopupMenu( hmenu, 0, 100,100, 0, hwnd, NULL);
3844     ok(ret == 1, "got %i\n", ret);
3845 
3846     ok(gflag_initmenupopup == 1, "got %i\n", gflag_initmenupopup);
3847     ok(gflag_entermenuloop == 1, "got %i\n", gflag_entermenuloop);
3848     ok(gflag_initmenu == 1, "got %i\n", gflag_initmenu);
3849     ok(gflag_enteridle == 1, "got %i\n", gflag_initmenu);
3850 
3851     ok(selectitem_wp == 0xffff0000, "got %lx\n", selectitem_wp);
3852     ok(selectitem_lp == 0, "got %lx\n", selectitem_lp);
3853 
3854     DestroyWindow(hwnd);
3855 
3856     ret = DestroyMenu(hmenu);
3857     ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
3858 }
3859 
3860 static HMENU get_bad_hmenu( UINT_PTR id )
3861 {
3862     while (IsMenu( (HMENU)id )) id++;
3863     return (HMENU)id;
3864 }
3865 
3866 static void test_AppendMenu(void)
3867 {
3868     static char string[] = "string";
3869     MENUITEMINFOA mii;
3870     HMENU hmenu, hsubmenu;
3871     HBITMAP hbmp;
3872     char buf[16];
3873     BOOL ret;
3874 
3875     hmenu = CreateMenu();
3876     ok(hmenu != 0, "CreateMenu failed\n");
3877     ret = AppendMenuA(hmenu, MF_OWNERDRAW, 201, "item 1");
3878     ok(ret, "AppendMenu failed\n");
3879     check_menu_items(hmenu, 201, MF_OWNERDRAW, 0);
3880     DestroyMenu(hmenu);
3881 
3882     hmenu = CreateMenu();
3883     ok(hmenu != 0, "CreateMenu failed\n");
3884     hsubmenu = get_bad_hmenu( 202 );
3885     ret = AppendMenuA(hmenu, MF_POPUP, (UINT_PTR)hsubmenu, "item 1");
3886     ok(ret, "AppendMenu failed\n");
3887     check_menu_items(hmenu, (UINT_PTR)hsubmenu, MF_STRING, 0);
3888     DestroyMenu(hmenu);
3889 
3890     hmenu = CreateMenu();
3891     ok(hmenu != 0, "CreateMenu failed\n");
3892     hsubmenu = get_bad_hmenu( 203 );
3893     ret = AppendMenuA(hmenu, MF_OWNERDRAW | MF_POPUP, (UINT_PTR)hsubmenu, "item 1");
3894     ok(ret, "AppendMenu failed\n");
3895     check_menu_items(hmenu, (UINT_PTR)hsubmenu, MF_OWNERDRAW, 0);
3896     DestroyMenu(hmenu);
3897 
3898     hmenu = CreateMenu();
3899     ok(hmenu != 0, "CreateMenu failed\n");
3900     hsubmenu = CreateMenu();
3901     ok(hsubmenu != 0, "CreateMenu failed\n");
3902     ret = AppendMenuA(hmenu, MF_OWNERDRAW, (UINT_PTR)hsubmenu, "item 1");
3903     ok(ret, "AppendMenu failed\n");
3904     check_menu_items(hmenu, (UINT_PTR)hsubmenu, MF_OWNERDRAW, 0);
3905     DestroyMenu(hmenu);
3906     DestroyMenu(hsubmenu);
3907 
3908     hmenu = CreateMenu();
3909     ok(hmenu != 0, "CreateMenu failed\n");
3910     hsubmenu = CreateMenu();
3911     ok(hsubmenu != 0, "CreateMenu failed\n");
3912     ret = AppendMenuA(hmenu, MF_POPUP, (UINT_PTR)hsubmenu, "item 1");
3913     ok(ret, "AppendMenu failed\n");
3914     check_menu_items(hmenu, (UINT_PTR)hsubmenu, MF_STRING, 0);
3915     DestroyMenu(hmenu);
3916     DestroyMenu(hsubmenu);
3917 
3918     hmenu = CreateMenu();
3919     ok(hmenu != 0, "CreateMenu failed\n");
3920     hsubmenu = CreateMenu();
3921     ok(hsubmenu != 0, "CreateMenu failed\n");
3922     ret = AppendMenuA(hmenu, MF_OWNERDRAW | MF_POPUP, (UINT_PTR)hsubmenu, "item 1");
3923     ok(ret, "AppendMenu failed\n");
3924     check_menu_items(hmenu, (UINT_PTR)hsubmenu, MF_OWNERDRAW, 0);
3925     DestroyMenu(hmenu);
3926     DestroyMenu(hsubmenu);
3927 
3928     hmenu = CreateMenu();
3929     ok(hmenu != 0, "CreateMenu failed\n");
3930     hsubmenu = CreatePopupMenu();
3931     ok(hsubmenu != 0, "CreatePopupMenu failed\n");
3932     ret = AppendMenuA(hmenu, MF_OWNERDRAW, (UINT_PTR)hsubmenu, "item 1");
3933     ok(ret, "AppendMenu failed\n");
3934     check_menu_items(hmenu, (UINT_PTR)hsubmenu, MF_OWNERDRAW, 0);
3935     DestroyMenu(hmenu);
3936     DestroyMenu(hsubmenu);
3937 
3938     hmenu = CreateMenu();
3939     ok(hmenu != 0, "CreateMenu failed\n");
3940     hsubmenu = CreatePopupMenu();
3941     ok(hsubmenu != 0, "CreatePopupMenu failed\n");
3942     ret = AppendMenuA(hmenu, MF_POPUP, (UINT_PTR)hsubmenu, "item 1");
3943     ok(ret, "AppendMenu failed\n");
3944     check_menu_items(hmenu, (UINT_PTR)hsubmenu, MF_STRING, 0);
3945     DestroyMenu(hmenu);
3946     DestroyMenu(hsubmenu);
3947 
3948     hmenu = CreateMenu();
3949     ok(hmenu != 0, "CreateMenu failed\n");
3950     hsubmenu = CreatePopupMenu();
3951     ok(hsubmenu != 0, "CreatePopupMenu failed\n");
3952     ret = AppendMenuA(hmenu, MF_OWNERDRAW | MF_POPUP, (UINT_PTR)hsubmenu, "item 1");
3953     ok(ret, "AppendMenu failed\n");
3954     check_menu_items(hmenu, (UINT_PTR)hsubmenu, MF_OWNERDRAW, 0);
3955     DestroyMenu(hmenu);
3956     DestroyMenu(hsubmenu);
3957 
3958     hmenu = CreateMenu();
3959     ok(hmenu != 0, "CreateMenu failed\n");
3960     ret = AppendMenuA(hmenu, MF_STRING, 204, "item 1");
3961     ok(ret, "AppendMenu failed\n");
3962     check_menu_items(hmenu, 204, MF_STRING, 0);
3963     hsubmenu = get_bad_hmenu( 205 );
3964     ret = ModifyMenuA(hmenu, 0, MF_POPUP | MF_BYPOSITION, (UINT_PTR)hsubmenu, "item 2");
3965     ok(ret, "ModifyMenu failed\n");
3966     check_menu_items(hmenu, (UINT_PTR)hsubmenu, MF_STRING, 0);
3967     memset(&mii, 0, sizeof(mii));
3968     mii.cbSize = sizeof(mii);
3969     mii.fMask = MIIM_SUBMENU;
3970     mii.hSubMenu = get_bad_hmenu( 204 );
3971     ret = InsertMenuItemA(hmenu, 0, TRUE, &mii);
3972     ok(!ret, "InsertMenuItem should fail\n");
3973     ret = SetMenuItemInfoA(hmenu, 0, TRUE, &mii);
3974     ok(!ret, "SetMenuItemInfo should fail\n");
3975     mii.fMask = MIIM_ID;
3976     mii.wID = 206;
3977     ret = InsertMenuItemA(hmenu, 0, TRUE, &mii);
3978     ok(ret, "InsertMenuItem failed\n");
3979 if (0) /* FIXME: uncomment once Wine is fixed */ {
3980     check_menu_items(hmenu, 206, MF_SEPARATOR, MFS_GRAYED);
3981 }
3982     mii.wID = 207;
3983     ret = SetMenuItemInfoA(hmenu, 0, TRUE, &mii);
3984     ok(ret, "SetMenuItemInfo failed\n");
3985 if (0) /* FIXME: uncomment once Wine is fixed */ {
3986     check_menu_items(hmenu, 207, MF_SEPARATOR, MFS_GRAYED);
3987 }
3988     DestroyMenu(hmenu);
3989 
3990     hbmp = CreateBitmap(1, 1, 1, 1, NULL);
3991     hmenu = CreateMenu();
3992     ok(hmenu != 0, "CreateMenu failed\n");
3993 
3994     /* menu item with a string and a bitmap */
3995     memset(&mii, 0, sizeof(mii));
3996     mii.cbSize = sizeof(mii);
3997     mii.fMask = MIIM_STRING | MIIM_BITMAP;
3998     mii.dwTypeData = string;
3999     mii.cch = strlen(string);
4000     mii.hbmpItem = hbmp;
4001     ret = InsertMenuItemA(hmenu, 0, TRUE, &mii);
4002     ok(ret, "InsertMenuItem failed\n");
4003     memset(&mii, 0x81, sizeof(mii));
4004     memset(buf, 0x81, sizeof(buf));
4005     mii.cbSize = sizeof(mii);
4006     mii.fMask  = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_STRING | MIIM_BITMAP;
4007     mii.dwTypeData = buf;
4008     mii.cch = sizeof(buf);
4009     mii.dwItemData = 0x81818181;
4010     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4011     ok(ret, "GetMenuItemInfo failed\n");
4012     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4013     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
4014     ok(mii.wID == 0, "expected 0, got %#x\n", mii.wID);
4015     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4016     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
4017     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4018     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4019     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4020     ok(mii.hbmpItem == hbmp, "expected %p, got %p\n", hbmp, mii.hbmpItem);
4021 
4022     memset(&mii, 0x81, sizeof(mii));
4023     mii.cbSize = sizeof(mii);
4024     mii.fMask  = MIIM_TYPE;
4025     mii.dwItemData = 0x81818181;
4026     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4027     ok(ret, "GetMenuItemInfo failed\n");
4028     ok(mii.fType == MF_BITMAP, "expected MF_BITMAP, got %#x\n", mii.fType);
4029     ok(mii.fState == 0x81818181, "expected 0x81818181, got %#x\n", mii.fState);
4030     ok(mii.wID == 0x81818181, "expected 0x81818181, got %#x\n", mii.wID);
4031     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4032     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
4033     ok(mii.dwTypeData == (LPSTR)hbmp, "expected %p, got %p\n", hbmp, mii.dwTypeData);
4034     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4035     ok(mii.hbmpItem == hbmp, "expected %p, got %p\n", hbmp, mii.hbmpItem);
4036 
4037     memset(&mii, 0x81, sizeof(mii));
4038     memset(buf, 0x81, sizeof(buf));
4039     mii.cbSize = sizeof(mii);
4040     mii.fMask  = MIIM_STATE | MIIM_ID | MIIM_TYPE | MIIM_DATA;
4041     mii.dwTypeData = buf;
4042     mii.cch = sizeof(buf);
4043     mii.dwItemData = 0x81818181;
4044     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4045     ok(ret, "GetMenuItemInfo failed\n");
4046     ok(mii.fType == MF_BITMAP, "expected MF_BITMAP, got %#x\n", mii.fType);
4047     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
4048     ok(mii.wID == 0, "expected 0, got %#x\n", mii.wID);
4049     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4050     ok(mii.dwItemData == 0, "expected 0, got %#lx\n", mii.dwItemData);
4051     ok(mii.dwTypeData == (LPSTR)hbmp, "expected %p, got %p\n", hbmp, mii.dwTypeData);
4052     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4053     ok(mii.hbmpItem == hbmp, "expected %p, got %p\n", hbmp, mii.hbmpItem);
4054 
4055     DestroyMenu(hmenu);
4056     DeleteObject(hbmp);
4057 
4058     hmenu = CreateMenu();
4059     ok(hmenu != 0, "CreateMenu failed\n");
4060 
4061     /* menu item with a string and a "magic" bitmap */
4062     memset(&mii, 0, sizeof(mii));
4063     mii.cbSize = sizeof(mii);
4064     mii.fMask = MIIM_STRING | MIIM_BITMAP;
4065     mii.dwTypeData = string;
4066     mii.cch = strlen(string);
4067     mii.hbmpItem = HBMMENU_POPUP_RESTORE;
4068     ret = InsertMenuItemA(hmenu, 0, TRUE, &mii);
4069     ok(ret, "InsertMenuItem failed\n");
4070     memset(&mii, 0x81, sizeof(mii));
4071     memset(buf, 0x81, sizeof(buf));
4072     mii.cbSize = sizeof(mii);
4073     mii.fMask  = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_STRING | MIIM_BITMAP;
4074     mii.dwTypeData = buf;
4075     mii.cch = sizeof(buf);
4076     mii.dwItemData = 0x81818181;
4077     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4078     ok(ret, "GetMenuItemInfo failed\n");
4079     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4080     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
4081     ok(mii.wID == 0, "expected 0, got %#x\n", mii.wID);
4082     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4083     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
4084     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4085     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4086     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4087     ok(mii.hbmpItem == HBMMENU_POPUP_RESTORE, "expected HBMMENU_POPUP_RESTORE, got %p\n", mii.hbmpItem);
4088 
4089     memset(&mii, 0x81, sizeof(mii));
4090     mii.cbSize = sizeof(mii);
4091     mii.fMask  = MIIM_TYPE;
4092     mii.dwTypeData = buf;
4093     mii.cch = sizeof(buf);
4094     mii.dwItemData = 0x81818181;
4095     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4096     ok(ret, "GetMenuItemInfo failed\n");
4097     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4098     ok(mii.fState == 0x81818181, "expected 0x81818181, got %#x\n", mii.fState);
4099     ok(mii.wID == 0x81818181, "expected 0x81818181, got %#x\n", mii.wID);
4100     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4101     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
4102     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4103     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4104     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4105     ok(mii.hbmpItem == HBMMENU_POPUP_RESTORE, "expected HBMMENU_POPUP_RESTORE, got %p\n", mii.hbmpItem);
4106 
4107     memset(&mii, 0x81, sizeof(mii));
4108     memset(buf, 0x81, sizeof(buf));
4109     mii.cbSize = sizeof(mii);
4110     mii.fMask  = MIIM_STATE | MIIM_ID | MIIM_TYPE | MIIM_DATA;
4111     mii.dwTypeData = buf;
4112     mii.cch = sizeof(buf);
4113     mii.dwItemData = 0x81818181;
4114     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4115     ok(ret, "GetMenuItemInfo failed\n");
4116     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4117     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
4118     ok(mii.wID == 0, "expected 0, got %#x\n", mii.wID);
4119     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4120     ok(mii.dwItemData == 0, "expected 0, got %#lx\n", mii.dwItemData);
4121     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4122     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4123     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4124     ok(mii.hbmpItem == HBMMENU_POPUP_RESTORE, "expected HBMMENU_POPUP_RESTORE, got %p\n", mii.hbmpItem);
4125 
4126     DestroyMenu(hmenu);
4127 
4128     hbmp = CreateBitmap(1, 1, 1, 1, NULL);
4129     hmenu = CreateMenu();
4130     ok(hmenu != 0, "CreateMenu failed\n");
4131 
4132     /* menu item with a string */
4133     memset(&mii, 0, sizeof(mii));
4134     mii.cbSize = sizeof(mii);
4135     mii.fMask  = MIIM_STATE | MIIM_ID | MIIM_TYPE | MIIM_DATA;
4136     mii.dwItemData = (ULONG_PTR)hbmp;
4137     mii.dwTypeData = string;
4138     mii.cch = strlen(string);
4139     mii.hbmpItem = hbmp;
4140     ret = InsertMenuItemA(hmenu, 0, TRUE, &mii);
4141     ok(ret, "InsertMenuItem failed\n");
4142     memset(&mii, 0x81, sizeof(mii));
4143     memset(buf, 0x81, sizeof(buf));
4144     mii.cbSize = sizeof(mii);
4145     mii.fMask  = MIIM_STATE | MIIM_ID | MIIM_TYPE | MIIM_DATA;
4146     mii.dwTypeData = buf;
4147     mii.cch = sizeof(buf);
4148     mii.dwItemData = 0x81818181;
4149     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4150     ok(ret, "GetMenuItemInfo failed\n");
4151     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4152     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
4153     ok(mii.wID == 0, "expected 0, got %#x\n", mii.wID);
4154     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4155     ok(mii.dwItemData == (ULONG_PTR)hbmp, "expected %p, got %#lx\n", hbmp, mii.dwItemData);
4156     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4157     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4158     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4159     ok(mii.hbmpItem == 0, "expected 0, got %p\n", mii.hbmpItem);
4160 
4161     memset(&mii, 0x81, sizeof(mii));
4162     memset(buf, 0x81, sizeof(buf));
4163     mii.cbSize = sizeof(mii);
4164     mii.fMask  = MIIM_TYPE;
4165     mii.dwTypeData = buf;
4166     mii.cch = sizeof(buf);
4167     mii.dwItemData = 0x81818181;
4168     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4169     ok(ret, "GetMenuItemInfo failed\n");
4170     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4171     ok(mii.fState == 0x81818181, "expected 0x81818181, got %#x\n", mii.fState);
4172     ok(mii.wID == 0x81818181, "expected 0x81818181, got %#x\n", mii.wID);
4173     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4174     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
4175     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4176     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4177     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4178     ok(mii.hbmpItem == 0, "expected 0, got %p\n", mii.hbmpItem);
4179 
4180     DestroyMenu(hmenu);
4181     DeleteObject(hbmp);
4182 
4183     /* menu item with a string */
4184     hbmp = CreateBitmap(1, 1, 1, 1, NULL);
4185     hmenu = CreateMenu();
4186     ok(hmenu != 0, "CreateMenu failed\n");
4187     memset(&mii, 0, sizeof(mii));
4188     mii.cbSize = sizeof(mii);
4189     mii.fMask = MIIM_STRING;
4190     mii.dwTypeData = string;
4191     mii.cch = strlen(string);
4192     ret = InsertMenuItemA(hmenu, 0, TRUE, &mii);
4193     ok(ret, "InsertMenuItem failed\n");
4194     memset(&mii, 0x81, sizeof(mii));
4195     memset(buf, 0x81, sizeof(buf));
4196     mii.cbSize = sizeof(mii);
4197     mii.fMask  = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_STRING | MIIM_BITMAP;
4198     mii.dwTypeData = buf;
4199     mii.cch = sizeof(buf);
4200     mii.dwItemData = 0x81818181;
4201     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4202     ok(ret, "GetMenuItemInfo failed\n");
4203     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4204     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
4205     ok(mii.wID == 0, "expected 0, got %#x\n", mii.wID);
4206     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4207     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
4208     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4209     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4210     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4211     ok(mii.hbmpItem == 0, "expected 0, got %p\n", mii.hbmpItem);
4212 
4213     /* add "magic" bitmap to a menu item */
4214     mii.fMask = MIIM_BITMAP;
4215     mii.hbmpItem = HBMMENU_POPUP_RESTORE;
4216     ret = SetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4217     ok(ret, "SetMenuItemInfo failed\n");
4218     memset(&mii, 0x81, sizeof(mii));
4219     memset(buf, 0x81, sizeof(buf));
4220     mii.cbSize = sizeof(mii);
4221     mii.fMask  = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_STRING | MIIM_BITMAP;
4222     mii.dwTypeData = buf;
4223     mii.cch = sizeof(buf);
4224     mii.dwItemData = 0x81818181;
4225     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4226     ok(ret, "GetMenuItemInfo failed\n");
4227     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4228     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
4229     ok(mii.wID == 0, "expected 0, got %#x\n", mii.wID);
4230     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4231     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
4232     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4233     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4234     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4235     ok(mii.hbmpItem == HBMMENU_POPUP_RESTORE, "expected HBMMENU_POPUP_RESTORE, got %p\n", mii.hbmpItem);
4236 
4237     memset(&mii, 0x81, sizeof(mii));
4238     memset(buf, 0x81, sizeof(buf));
4239     mii.cbSize = sizeof(mii);
4240     mii.fMask  = MIIM_TYPE;
4241     mii.dwTypeData = buf;
4242     mii.cch = sizeof(buf);
4243     mii.dwItemData = 0x81818181;
4244     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4245     ok(ret, "GetMenuItemInfo failed\n");
4246     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4247     ok(mii.fState == 0x81818181, "expected 0x81818181, got %#x\n", mii.fState);
4248     ok(mii.wID == 0x81818181, "expected 0x81818181, got %#x\n", mii.wID);
4249     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4250     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
4251     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4252     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4253     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4254     ok(mii.hbmpItem == HBMMENU_POPUP_RESTORE, "expected HBMMENU_POPUP_RESTORE, got %p\n", mii.hbmpItem);
4255 
4256     /* replace "magic" bitmap by a normal one */
4257     mii.fMask = MIIM_BITMAP;
4258     mii.hbmpItem = hbmp;
4259     ret = SetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4260     ok(ret, "SetMenuItemInfo failed\n");
4261     memset(&mii, 0x81, sizeof(mii));
4262     memset(buf, 0x81, sizeof(buf));
4263     mii.cbSize = sizeof(mii);
4264     mii.fMask  = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_STRING | MIIM_BITMAP;
4265     mii.dwTypeData = buf;
4266     mii.cch = sizeof(buf);
4267     mii.dwItemData = 0x81818181;
4268     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4269     ok(ret, "GetMenuItemInfo failed\n");
4270     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4271     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
4272     ok(mii.wID == 0, "expected 0, got %#x\n", mii.wID);
4273     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4274     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
4275     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4276     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4277     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4278     ok(mii.hbmpItem == hbmp, "expected %p, got %p\n", hbmp, mii.hbmpItem);
4279 
4280     memset(&mii, 0x81, sizeof(mii));
4281     memset(buf, 0x81, sizeof(buf));
4282     mii.cbSize = sizeof(mii);
4283     mii.fMask  = MIIM_TYPE;
4284     mii.dwTypeData = buf;
4285     mii.cch = sizeof(buf);
4286     mii.dwItemData = 0x81818181;
4287     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4288     ok(ret, "GetMenuItemInfo failed\n");
4289     ok(mii.fType == MF_BITMAP, "expected MF_BITMAP, got %#x\n", mii.fType);
4290     ok(mii.fState == 0x81818181, "expected 0x81818181, got %#x\n", mii.fState);
4291     ok(mii.wID == 0x81818181, "expected 0x81818181, got %#x\n", mii.wID);
4292     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4293     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
4294     ok(mii.dwTypeData == (LPSTR)hbmp, "expected %p, got %p\n", hbmp, mii.dwTypeData);
4295     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4296     ok(mii.hbmpItem == hbmp, "expected %p, got %p\n", hbmp, mii.hbmpItem);
4297 
4298     DestroyMenu(hmenu);
4299     DeleteObject(hbmp);
4300 }
4301 
4302 START_TEST(menu)
4303 {
4304     init_function_pointers();
4305     register_menu_check_class();
4306 
4307     /* Wine defines MENUITEMINFO for W2K and above. NT4 and below can't
4308      * handle that.
4309      */
4310     if (correct_behavior())
4311     {
4312         test_menu_add_string();
4313         test_menu_iteminfo();
4314         test_menu_search_bycommand();
4315         test_CheckMenuRadioItem();
4316         test_menu_resource_layout();
4317         test_InsertMenu();
4318         test_menualign();
4319         test_system_menu();
4320     }
4321 
4322     test_menu_locked_by_window();
4323     test_subpopup_locked_by_menu();
4324     test_menu_ownerdraw();
4325     test_getmenubarinfo();
4326     test_menu_bmp_and_string();
4327     test_menu_getmenuinfo();
4328     test_menu_setmenuinfo();
4329     test_menu_input();
4330     test_menu_flags();
4331 
4332     test_menu_hilitemenuitem();
4333     test_menu_trackpopupmenu();
4334     test_menu_trackagain();
4335     test_menu_cancelmode();
4336     test_menu_maxdepth();
4337     test_menu_circref();
4338     test_emptypopup();
4339     test_AppendMenu();
4340 }
4341