4 * Copyright 2005 Robert Shearman
5 * Copyright 2007 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define _WIN32_WINNT 0x0501
29 #define OEMRESOURCE /* For OBM_MNARROW */
36 #include "wine/test.h"
38 static ATOM atomMenuCheckClass;
40 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
41 static UINT (WINAPI *pSendInput)(UINT, INPUT*, size_t);
42 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
43 static BOOL (WINAPI *pEndMenu) (void);
45 static void init_function_pointers(void)
47 HMODULE hdll = GetModuleHandleA("user32");
49 #define GET_PROC(func) \
50 p ## func = (void*)GetProcAddress(hdll, #func); \
52 trace("GetProcAddress(%s) failed\n", #func);
62 static BOOL correct_behavior(void)
70 memset(&info, 0, sizeof(MENUITEMINFO));
71 info.cbSize= sizeof(MENUITEMINFO);
72 SetLastError(0xdeadbeef);
73 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info);
75 * NT4 : ERROR_INVALID_PARAMETER
76 * >= W2K : ERROR_MENU_ITEM_NOT_FOUND
78 if (!rc && GetLastError() != ERROR_MENU_ITEM_NOT_FOUND)
80 win_skip("NT4 and below can't handle a bigger MENUITEMINFO struct\n");
89 static LRESULT WINAPI menu_check_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
93 case WM_ENTERMENULOOP:
94 /* mark window as having entered menu loop */
95 SetWindowLongPtr(hwnd, GWLP_USERDATA, TRUE);
96 /* exit menu modal loop
97 * ( A SendMessage does not work on NT3.51 here ) */
98 return PostMessage(hwnd, WM_CANCELMODE, 0, 0);
100 return DefWindowProc(hwnd, msg, wparam, lparam);
103 /* The MSVC headers ignore our NONAMELESSUNION requests so we have to define
116 /* globals to communicate between test and wndproc */
118 static BOOL bMenuVisible;
119 static BOOL got_input;
120 static HMENU hMenus[4];
123 #define MOD_NRMENUS 8
125 /* menu texts with their sizes */
128 SIZE size; /* size of text up to any \t */
129 SIZE sc_size; /* size of the short-cut */
133 { "Shira&z\tAlt+S" },
138 static unsigned int MOD_maxid;
139 static RECT MOD_rc[MOD_NRMENUS];
140 static int MOD_avec, MOD_hic;
141 static int MOD_odheight;
142 static SIZE MODsizes[MOD_NRMENUS]= { {MOD_SIZE, MOD_SIZE},{MOD_SIZE, MOD_SIZE},
143 {MOD_SIZE, MOD_SIZE},{MOD_SIZE, MOD_SIZE}};
144 static int MOD_GotDrawItemMsg = FALSE;
145 static int gflag_initmenupopup,
149 /* wndproc used by test_menu_ownerdraw() */
150 static LRESULT WINAPI menu_ownerdraw_wnd_proc(HWND hwnd, UINT msg,
151 WPARAM wparam, LPARAM lparam)
155 case WM_INITMENUPOPUP:
156 gflag_initmenupopup++;
158 case WM_ENTERMENULOOP:
159 gflag_entermenuloop++;
166 MEASUREITEMSTRUCT* pmis = (MEASUREITEMSTRUCT*)lparam;
168 trace("WM_MEASUREITEM received data %lx size %dx%d\n",
169 pmis->itemData, pmis->itemWidth, pmis->itemHeight);
170 MOD_odheight = pmis->itemHeight;
171 pmis->itemWidth = MODsizes[pmis->itemData].cx;
172 pmis->itemHeight = MODsizes[pmis->itemData].cy;
177 DRAWITEMSTRUCT * pdis;
180 char chrs[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
183 pdis = (DRAWITEMSTRUCT *) lparam;
184 if( winetest_debug) {
186 GetMenuItemRect( hwnd, (HMENU)pdis->hwndItem, pdis->itemData ,&rc);
187 trace("WM_DRAWITEM received hwnd %p hmenu %p itemdata %ld item %d rc %d,%d-%d,%d itemrc: %d,%d-%d,%d\n",
188 hwnd, pdis->hwndItem, pdis->itemData, pdis->itemID,
189 pdis->rcItem.left, pdis->rcItem.top,
190 pdis->rcItem.right,pdis->rcItem.bottom,
191 rc.left,rc.top,rc.right,rc.bottom);
192 oldpen=SelectObject( pdis->hDC, GetStockObject(
193 pdis->itemState & ODS_SELECTED ? WHITE_PEN :BLACK_PEN));
194 Rectangle( pdis->hDC, pdis->rcItem.left,pdis->rcItem.top,
195 pdis->rcItem.right,pdis->rcItem.bottom );
196 SelectObject( pdis->hDC, oldpen);
198 /* calculate widths of some menu texts */
199 if( ! MOD_txtsizes[0].size.cx)
200 for(i = 0; MOD_txtsizes[i].text; i++) {
203 strcpy( buf, MOD_txtsizes[i].text);
204 if( ( p = strchr( buf, '\t'))) {
206 DrawText( pdis->hDC, p + 1, -1, &rc,
207 DT_SINGLELINE|DT_CALCRECT);
208 MOD_txtsizes[i].sc_size.cx= rc.right - rc.left;
209 MOD_txtsizes[i].sc_size.cy= rc.bottom - rc.top;
211 DrawText( pdis->hDC, buf, -1, &rc,
212 DT_SINGLELINE|DT_CALCRECT);
213 MOD_txtsizes[i].size.cx= rc.right - rc.left;
214 MOD_txtsizes[i].size.cy= rc.bottom - rc.top;
217 if( pdis->itemData > MOD_maxid) return TRUE;
218 /* store the rectangl */
219 MOD_rc[pdis->itemData] = pdis->rcItem;
220 /* calculate average character width */
221 GetTextExtentPoint( pdis->hDC, chrs, 52, &sz );
222 MOD_avec = (sz.cx + 26)/52;
223 GetTextMetrics( pdis->hDC, &tm);
224 MOD_hic = tm.tmHeight;
225 MOD_GotDrawItemMsg = TRUE;
230 ok( lparam || broken(!lparam), /* win9x, nt4 */
231 "Menu window handle is NULL!\n");
232 PostMessage(hwnd, WM_CANCELMODE, 0, 0);
237 return DefWindowProc(hwnd, msg, wparam, lparam);
240 static void register_menu_check_class(void)
248 GetModuleHandle(NULL),
250 LoadCursor(NULL, IDC_ARROW),
251 (HBRUSH)(COLOR_BTNFACE+1),
253 TEXT("WineMenuCheck"),
256 atomMenuCheckClass = RegisterClass(&wc);
259 /* demonstrates that windows locks the menu object so that it is still valid
260 * even after a client calls DestroyMenu on it */
261 static void test_menu_locked_by_window(void)
265 HWND hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
266 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
267 NULL, NULL, NULL, NULL);
268 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
269 hmenu = CreateMenu();
270 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
271 ret = InsertMenu(hmenu, 0, MF_STRING, 0, TEXT("&Test"));
272 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
273 ret = SetMenu(hwnd, hmenu);
274 ok(ret, "SetMenu failed with error %d\n", GetLastError());
275 ret = DestroyMenu(hmenu);
276 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
278 ret = DrawMenuBar(hwnd);
280 ok(ret, "DrawMenuBar failed with error %d\n", GetLastError());
282 ret = IsMenu(GetMenu(hwnd));
283 ok(!ret || broken(ret) /* nt4 */, "Menu handle should have been destroyed\n");
285 SendMessage(hwnd, WM_SYSCOMMAND, SC_KEYMENU, 0);
286 /* did we process the WM_INITMENU message? */
287 ret = GetWindowLongPtr(hwnd, GWLP_USERDATA);
289 ok(ret, "WM_INITMENU should have been sent\n");
295 /* demonstrates that subpopup's are locked
296 * even after a client calls DestroyMenu on it */
297 static LRESULT WINAPI subpopuplocked_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
303 hwndmenu = GetCapture();
305 PostMessage( hwndmenu, WM_KEYDOWN, VK_DOWN, 0);
306 PostMessage( hwndmenu, WM_KEYDOWN, VK_RIGHT, 0);
307 PostMessage( hwndmenu, WM_KEYDOWN, VK_RETURN, 0);
310 return DefWindowProc(hwnd, msg, wparam, lparam);
313 static void test_subpopup_locked_by_menu(void)
317 HMENU hmenu, hsubmenu;
318 MENUINFO mi = { sizeof( MENUINFO)};
319 MENUITEMINFO mii = { sizeof( MENUITEMINFO)};
321 const int itemid = 0x1234567;
324 win_skip("GetMenuInfo is not available\n");
327 /* create window, popupmenu with one subpopup */
328 hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
329 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
330 NULL, NULL, NULL, NULL);
331 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
332 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR) subpopuplocked_wnd_proc);
333 hmenu = CreatePopupMenu();
334 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
335 hsubmenu = CreatePopupMenu();
336 ok(hsubmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
337 ret = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hsubmenu,
338 TEXT("PopUpLockTest"));
339 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
340 ret = InsertMenu(hsubmenu, 0, MF_BYPOSITION | MF_STRING, itemid, TEXT("PopUpMenu"));
341 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
342 /* first some tests that all this functions properly */
343 mii.fMask = MIIM_SUBMENU;
344 ret = GetMenuItemInfo( hmenu, 0, TRUE, &mii);
345 ok( ret, "GetMenuItemInfo failed error %d\n", GetLastError());
346 ok( mii.hSubMenu == hsubmenu, "submenu is %p\n", mii.hSubMenu);
347 mi.fMask |= MIM_STYLE;
348 ret = pGetMenuInfo( hsubmenu, &mi);
349 ok( ret , "GetMenuInfo returned 0 with error %d\n", GetLastError());
350 ret = IsMenu( hsubmenu);
351 ok( ret , "Menu handle is not valid\n");
352 SetLastError( 0xdeadbeef);
353 ret = TrackPopupMenu( hmenu, 0x100, 100,100, 0, hwnd, NULL);
354 if( ret == (itemid & 0xffff)) {
355 win_skip("not on 16 bit menu subsystem\n");
356 DestroyMenu( hsubmenu);
358 gle = GetLastError();
359 ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, gle);
361 broken( gle == 0xdeadbeef), /* win2k0 */
362 "Last error is %d\n", gle);
363 /* then destroy the sub-popup */
364 ret = DestroyMenu( hsubmenu);
365 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
366 /* and repeat the tests */
367 mii.fMask = MIIM_SUBMENU;
368 ret = GetMenuItemInfo( hmenu, 0, TRUE, &mii);
369 ok( ret, "GetMenuItemInfo failed error %d\n", GetLastError());
370 /* GetMenuInfo fails now */
371 ok( mii.hSubMenu == hsubmenu, "submenu is %p\n", mii.hSubMenu);
372 mi.fMask |= MIM_STYLE;
373 ret = pGetMenuInfo( hsubmenu, &mi);
374 ok( !ret , "GetMenuInfo should have failed\n");
375 /* IsMenu says it is not */
376 ret = IsMenu( hsubmenu);
377 ok( !ret , "Menu handle should be invalid\n");
378 /* but TrackPopupMenu still works! */
379 SetLastError( 0xdeadbeef);
380 ret = TrackPopupMenu( hmenu, 0x100, 100,100, 0, hwnd, NULL);
381 gle = GetLastError();
383 ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, gle);
386 broken( gle == ERROR_INVALID_PARAMETER), /* win2k0 */
387 "Last error is %d\n", gle);
394 static void test_menu_ownerdraw(void)
400 HWND hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
401 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
402 NULL, NULL, NULL, NULL);
403 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
405 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
406 hmenu = CreatePopupMenu();
407 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
408 if( !hmenu) { DestroyWindow(hwnd);return;}
410 for( j=0;j<2;j++) /* create columns */
411 for(i=0;i<2;i++) { /* create rows */
412 ret = AppendMenu( hmenu, MF_OWNERDRAW |
413 (i==0 ? MF_MENUBREAK : 0), k, MAKEINTRESOURCE(k));
415 ok( ret, "AppendMenu failed for %d\n", k-1);
418 assert( k <= sizeof(MOD_rc)/sizeof(RECT));
419 /* display the menu */
420 ret = TrackPopupMenu( hmenu, 0x100, 100,100, 0, hwnd, NULL);
422 /* columns have a 4 pixel gap between them */
423 ok( MOD_rc[0].right + 4 == MOD_rc[2].left,
424 "item rectangles are not separated by 4 pixels space\n");
425 /* height should be what the MEASUREITEM message has returned */
426 ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
427 "menu item has wrong height: %d should be %d\n",
428 MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
429 /* no gaps between the rows */
430 ok( MOD_rc[0].bottom - MOD_rc[1].top == 0,
431 "There should not be a space between the rows, gap is %d\n",
432 MOD_rc[0].bottom - MOD_rc[1].top);
433 /* test the correct value of the item height that was sent
434 * by the WM_MEASUREITEM message */
435 ok( MOD_odheight == HIWORD( GetDialogBaseUnits()) || /* WinNT,2k,XP */
436 MOD_odheight == MOD_hic, /* Win95,98,ME */
437 "Wrong height field in MEASUREITEMSTRUCT, expected %d or %d actual %d\n",
438 HIWORD( GetDialogBaseUnits()), MOD_hic, MOD_odheight);
439 /* test what MF_MENUBREAK did at the first position. Also show
440 * that an MF_SEPARATOR is ignored in the height calculation. */
441 leftcol= MOD_rc[0].left;
442 ModifyMenu( hmenu, 0, MF_BYCOMMAND| MF_OWNERDRAW| MF_SEPARATOR, 0, 0);
443 /* display the menu */
444 ret = TrackPopupMenu( hmenu, 0x100, 100,100, 0, hwnd, NULL);
445 /* left should be 4 pixels less now */
446 ok( leftcol == MOD_rc[0].left + 4,
447 "columns should be 4 pixels to the left (actual %d).\n",
448 leftcol - MOD_rc[0].left);
450 ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
451 "width of owner drawn menu item is wrong. Got %d expected %d\n",
452 MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
454 ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
455 "Height is incorrect. Got %d expected %d\n",
456 MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
458 /* test width/height of an ownerdraw menu bar as well */
459 ret = DestroyMenu(hmenu);
460 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
461 hmenu = CreateMenu();
462 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
463 if( !hmenu) { DestroyWindow(hwnd);return;}
466 ret = AppendMenu( hmenu, MF_OWNERDRAW , i, 0);
467 ok( ret, "AppendMenu failed for %d\n", i);
469 ret = SetMenu( hwnd, hmenu);
470 UpdateWindow( hwnd); /* hack for wine to draw the window + menu */
471 ok(ret, "SetMenu failed with error %d\n", GetLastError());
473 ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
474 "width of owner drawn menu item is wrong. Got %d expected %d\n",
475 MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
477 ok( MOD_rc[0].bottom - MOD_rc[0].top == GetSystemMetrics( SM_CYMENU) - 1,
478 "Height of owner drawn menu item is wrong. Got %d expected %d\n",
479 MOD_rc[0].bottom - MOD_rc[0].top, GetSystemMetrics( SM_CYMENU) - 1);
482 ret = DestroyMenu(hmenu);
483 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
487 /* helper for test_menu_bmp_and_string() */
488 static void test_mbs_help( int ispop, int hassub, int mnuopt,
489 HWND hwnd, int arrowwidth, int count, HBITMAP hbmp,
490 SIZE bmpsize, LPCSTR text, SIZE size, SIZE sc_size)
493 HMENU hmenu, submenu;
494 MENUITEMINFO mii={ sizeof( MENUITEMINFO )};
501 MOD_GotDrawItemMsg = FALSE;
502 mii.fMask = MIIM_FTYPE | MIIM_DATA | MIIM_STATE;
504 /* check the menu item unless MNS_CHECKORBMP is set */
505 mii.fState = (mnuopt != 2 ? MFS_CHECKED : MFS_UNCHECKED);
507 MODsizes[0] = bmpsize;
511 mii.fMask |= MIIM_STRING;
512 strcpy(text_copy, text);
513 mii.dwTypeData = text_copy; /* structure member declared non-const */
514 if( ( p = strchr( text, '\t'))) {
515 hastab = *(p + 1) ? 2 : 1;
518 /* tabs don't make sense in menubars */
519 if(hastab && !ispop) return;
521 mii.fMask |= MIIM_BITMAP;
524 submenu = CreateMenu();
525 ok( submenu != 0, "CreateMenu failed with error %d\n", GetLastError());
527 hmenu = CreatePopupMenu();
529 hmenu = CreateMenu();
530 ok( hmenu != 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
532 mii.fMask |= MIIM_SUBMENU;
533 mii.hSubMenu = submenu;
536 mi.cbSize = sizeof(mi);
537 mi.fMask = MIM_STYLE;
538 pGetMenuInfo( hmenu, &mi);
539 mi.dwStyle |= mnuopt == 1 ? MNS_NOCHECK : MNS_CHECKORBMP;
540 ret = pSetMenuInfo( hmenu, &mi);
541 ok( ret, "SetMenuInfo failed with error %d\n", GetLastError());
543 ret = InsertMenuItem( hmenu, 0, FALSE, &mii);
544 ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
546 if( winetest_debug) {
548 RECT rc = {100, 50, 400, 70};
551 sprintf( buf,"%d text \"%s\" mnuopt %d", count, text ? text: "(nil)", mnuopt);
552 FillRect( hdc, &rc, (HBRUSH) COLOR_WINDOW);
553 TextOut( hdc, 10, 50, buf, strlen( buf));
554 ReleaseDC( hwnd, hdc);
557 ret = TrackPopupMenu( hmenu, 0x100, 100,100, 0, hwnd, NULL);
559 ret = SetMenu( hwnd, hmenu);
560 ok(ret, "SetMenu failed with error %d\n", GetLastError());
563 ret = GetMenuItemRect( hwnd, hmenu, 0, &rc);
564 if (0) /* comment out menu size checks, behavior is different in almost every Windows version */
565 /* the tests should however succeed on win2000, XP and Wine (at least up to 1.1.15) */
566 /* with a variety of dpis and desktop font sizes */
568 /* check menu width */
570 expect = ( text || hbmp ?
571 4 + (mnuopt != 1 ? GetSystemMetrics(SM_CXMENUCHECK) : 0)
573 arrowwidth + MOD_avec + (hbmp ?
574 ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ? bmpsize.cx + 2 : GetSystemMetrics( SM_CXMENUSIZE) + 2)
576 (text && hastab ? /* TAB space */
577 MOD_avec + ( hastab==2 ? sc_size.cx : 0) : 0) +
578 (text ? 2 + (text[0] ? size.cx :0): 0) ;
580 expect = !(text || hbmp) ? 0 :
581 ( hbmp ? (text ? 2:0) + bmpsize.cx : 0 ) +
582 (text ? 2 * MOD_avec + (text[0] ? size.cx :0): 0) ;
583 ok( rc.right - rc.left == expect,
584 "menu width wrong, got %d expected %d\n", rc.right - rc.left, expect);
585 failed = failed || !(rc.right - rc.left == expect);
586 /* check menu height */
588 expect = max( ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 : 0),
589 max( (text ? max( 2 + size.cy, MOD_hic + 4) : 0),
591 ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ?
593 : GetSystemMetrics( SM_CYMENUSIZE) + 2)
596 expect = ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 :
597 max( GetSystemMetrics( SM_CYMENU) - 1, (hbmp ? bmpsize.cy : 0)));
598 ok( rc.bottom - rc.top == expect,
599 "menu height wrong, got %d expected %d (%d)\n",
600 rc.bottom - rc.top, expect, GetSystemMetrics( SM_CYMENU));
601 failed = failed || !(rc.bottom - rc.top == expect);
602 if( hbmp == HBMMENU_CALLBACK && MOD_GotDrawItemMsg) {
603 /* check the position of the bitmap */
607 else if (mnuopt == 0)
608 expect = 4 + GetSystemMetrics(SM_CXMENUCHECK);
609 else if (mnuopt == 1)
611 else /* mnuopt == 2 */
613 ok( expect == MOD_rc[0].left,
614 "bitmap left is %d expected %d\n", MOD_rc[0].left, expect);
615 failed = failed || !(expect == MOD_rc[0].left);
617 expect = (rc.bottom - rc.top - MOD_rc[0].bottom + MOD_rc[0].top) / 2;
618 ok( expect == MOD_rc[0].top,
619 "bitmap top is %d expected %d\n", MOD_rc[0].top, expect);
620 failed = failed || !(expect == MOD_rc[0].top);
623 /* if there was a failure, report details */
625 trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
626 count, (ispop? "POPUP": "MENUBAR"),text ? text: "(nil)", hbmp, bmpsize.cx, bmpsize.cy,
627 size.cx, size.cy, sc_size.cx, mnuopt, hastab);
628 trace(" check %d,%d arrow %d avechar %d\n",
629 GetSystemMetrics(SM_CXMENUCHECK ),
630 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
631 if( hbmp == HBMMENU_CALLBACK)
632 trace( " rc %d,%d-%d,%d bmp.rc %d,%d-%d,%d\n",
633 rc.left, rc.top, rc.top, rc.bottom, MOD_rc[0].left,
634 MOD_rc[0].top,MOD_rc[0].right, MOD_rc[0].bottom);
637 ret = DestroyMenu(submenu);
638 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
639 ret = DestroyMenu(hmenu);
640 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
644 static void test_menu_bmp_and_string(void)
652 MENUINFO mi= {sizeof(MENUINFO)};
653 MENUITEMINFOA mii= {sizeof(MENUITEMINFOA)};
654 int count, szidx, txtidx, bmpidx, hassub, mnuopt, ispop;
658 win_skip("GetMenuInfo is not available\n");
662 memset( bmfill, 0xcc, sizeof( bmfill));
663 hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL, WS_SYSMENU |
664 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
665 NULL, NULL, NULL, NULL);
666 hbm_arrow=LoadBitmap( 0, (CHAR*)OBM_MNARROW);
667 GetObject( hbm_arrow, sizeof(bm), &bm);
668 arrowwidth = bm.bmWidth;
669 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
671 /* test system menu */
672 hsysmenu = GetSystemMenu( hwnd, FALSE);
673 ok( hsysmenu != NULL, "GetSystemMenu failed with error %d\n", GetLastError());
674 mi.fMask = MIM_STYLE;
676 ok( pGetMenuInfo( hsysmenu, &mi), "GetMenuInfo failed gle=%d\n", GetLastError());
677 ok( MNS_CHECKORBMP == mi.dwStyle, "System Menu Style is %08x, without the bit %08x\n",
678 mi.dwStyle, MNS_CHECKORBMP);
679 mii.fMask = MIIM_BITMAP;
681 ok( GetMenuItemInfoA( hsysmenu, SC_CLOSE, FALSE, &mii), "GetMenuItemInfoA failed gle=%d\n", GetLastError());
682 ok( HBMMENU_POPUP_CLOSE == mii.hbmpItem, "Item info did not get the right hbitmap: got %p expected %p\n",
683 mii.hbmpItem, HBMMENU_POPUP_CLOSE);
685 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
688 trace(" check %d,%d arrow %d avechar %d\n",
689 GetSystemMetrics(SM_CXMENUCHECK ),
690 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
693 for( ispop=1; ispop >= 0; ispop--){
694 static SIZE bmsizes[]= {
695 {10,10},{38,38},{1,30},{55,5}};
696 for( szidx=0; szidx < sizeof( bmsizes) / sizeof( SIZE); szidx++) {
697 HBITMAP hbm = CreateBitmap( bmsizes[szidx].cx, bmsizes[szidx].cy,1,1,bmfill);
698 HBITMAP bitmaps[] = { HBMMENU_CALLBACK, hbm, HBMMENU_POPUP_CLOSE, NULL };
699 ok( hbm != 0, "CreateBitmap failed err %d\n", GetLastError());
700 for( txtidx = 0; txtidx < sizeof(MOD_txtsizes)/sizeof(MOD_txtsizes[0]); txtidx++) {
701 for( hassub = 0; hassub < 2 ; hassub++) { /* add submenu item */
702 for( mnuopt = 0; mnuopt < 3 ; mnuopt++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
703 for( bmpidx = 0; bmpidx <sizeof(bitmaps)/sizeof(HBITMAP); bmpidx++) {
704 /* no need to test NULL bitmaps of several sizes */
705 if( !bitmaps[bmpidx] && szidx > 0) continue;
706 /* the HBMMENU_POPUP not to test for menu bars */
708 bitmaps[bmpidx] >= HBMMENU_POPUP_CLOSE &&
709 bitmaps[bmpidx] <= HBMMENU_POPUP_MINIMIZE) continue;
710 if( !ispop && hassub) continue;
711 test_mbs_help( ispop, hassub, mnuopt,
712 hwnd, arrowwidth, ++count,
715 MOD_txtsizes[txtidx].text,
716 MOD_txtsizes[txtidx].size,
717 MOD_txtsizes[txtidx].sc_size);
729 static void test_menu_add_string( void )
740 WCHAR strbackW[0x80];
741 static CHAR blah[] = "blah";
742 static const WCHAR expectedString[] = {'D','u','m','m','y',' ','s','t','r','i','n','g', 0};
744 hmenu = CreateMenu();
746 memset( &info, 0, sizeof info );
747 info.cbSize = sizeof info;
748 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_ID;
749 info.dwTypeData = blah;
754 InsertMenuItem(hmenu, 0, TRUE, &info );
756 memset( &info, 0, sizeof info );
757 info.cbSize = sizeof info;
758 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_DATA | MIIM_ID;
759 info.dwTypeData = string;
760 info.cch = sizeof string;
762 GetMenuItemInfo( hmenu, 0, TRUE, &info );
764 ok( !strcmp( string, "blah" ), "menu item name differed\n");
766 /* Test combination of ownerdraw and strings with GetMenuItemString(A/W) */
767 strcpy(string, "Dummy string");
768 memset(&info, 0x00, sizeof(info));
769 info.cbSize= sizeof(MENUITEMINFO);
770 info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
771 info.fType= MFT_OWNERDRAW;
772 info.dwTypeData= string;
773 rc = InsertMenuItem( hmenu, 0, TRUE, &info );
774 ok (rc, "InsertMenuItem failed\n");
776 strcpy(string,"Garbage");
777 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
778 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
780 SetLastError(0xdeadbeef);
781 ret = GetMenuStringW( hmenu, 0, strbackW, 99, MF_BYPOSITION );
782 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
783 win_skip("GetMenuStringW is not implemented\n");
786 ok (ret, "GetMenuStringW on ownerdraw entry failed\n");
787 ok (!lstrcmpW( strbackW, expectedString ), "Menu text from Unicode version incorrect\n");
790 /* Just change ftype to string and see what text is stored */
791 memset(&info, 0x00, sizeof(info));
792 info.cbSize= sizeof(MENUITEMINFO);
793 info.fMask= MIIM_FTYPE; /* Set string type */
794 info.fType= MFT_STRING;
795 info.dwTypeData= (char *)0xdeadbeef;
796 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
797 ok (rc, "SetMenuItemInfo failed\n");
799 /* Did we keep the old dwTypeData? */
800 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
801 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
803 /* Ensure change to bitmap type fails */
804 memset(&info, 0x00, sizeof(info));
805 info.cbSize= sizeof(MENUITEMINFO);
806 info.fMask= MIIM_FTYPE; /* Set as bitmap type */
807 info.fType= MFT_BITMAP;
808 info.dwTypeData= (char *)0xdeadbee2;
809 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
810 ok (!rc, "SetMenuItemInfo unexpectedly worked\n");
812 /* Just change ftype back and ensure data hasn't been freed */
813 info.fType= MFT_OWNERDRAW; /* Set as ownerdraw type */
814 info.dwTypeData= (char *)0xdeadbee3;
815 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
816 ok (rc, "SetMenuItemInfo failed\n");
818 /* Did we keep the old dwTypeData? */
819 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
820 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
822 /* Just change string value (not type) */
823 memset(&info, 0x00, sizeof(info));
824 info.cbSize= sizeof(MENUITEMINFO);
825 info.fMask= MIIM_STRING; /* Set typeData */
826 strcpy(string2, "string2");
827 info.dwTypeData= string2;
828 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
829 ok (rc, "SetMenuItemInfo failed\n");
831 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
832 ok (!strcmp( strback, "string2" ), "Menu text from Ansi version incorrect\n");
834 /* crashes with wine 0.9.5 */
835 memset(&info, 0x00, sizeof(info));
836 info.cbSize= sizeof(MENUITEMINFO);
837 info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
838 info.fType= MFT_OWNERDRAW;
839 rc = InsertMenuItem( hmenu, 0, TRUE, &info );
840 ok (rc, "InsertMenuItem failed\n");
841 ok (!GetMenuString( hmenu, 0, NULL, 0, MF_BYPOSITION),
842 "GetMenuString on ownerdraw entry succeeded.\n");
843 SetLastError(0xdeadbeef);
844 ret = GetMenuStringW( hmenu, 0, NULL, 0, MF_BYPOSITION);
845 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
846 win_skip("GetMenuStringW is not implemented\n");
848 ok (!ret, "GetMenuStringW on ownerdraw entry succeeded.\n");
850 DestroyMenu( hmenu );
853 /* define building blocks for the menu item info tests */
854 static int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
856 if (n <= 0) return 0;
857 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
858 return *str1 - *str2;
861 static WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
864 while ((*p++ = *src++));
868 static void insert_menu_item( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state, UINT id,
869 HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
870 void *type_data, UINT len, HBITMAP item, BOOL expect )
875 /* magic bitmap handle to test smaller cbSize */
876 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
877 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
879 info.cbSize = sizeof(info);
884 info.hSubMenu = submenu;
885 info.hbmpChecked = checked;
886 info.hbmpUnchecked = unchecked;
887 info.dwItemData = data;
888 info.dwTypeData = type_data;
890 info.hbmpItem = item;
891 SetLastError( 0xdeadbeef );
892 if (ansi) ret = InsertMenuItemA( hmenu, 0, TRUE, &info );
893 else ret = InsertMenuItemW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
894 if (!expect) ok_(__FILE__, line)( !ret, "InsertMenuItem should have failed.\n" );
895 else ok_(__FILE__, line)( ret, "InsertMenuItem failed, err %u\n", GetLastError());
898 static void check_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
899 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked,
900 ULONG_PTR data, void *type_data, UINT in_len, UINT out_len,
901 HBITMAP item, LPCSTR expname, BOOL expect, BOOL expstring )
907 SetLastError( 0xdeadbeef );
908 memset( &info, 0xcc, sizeof(info) );
909 info.cbSize = sizeof(info);
911 info.dwTypeData = type_data;
914 ret = ansi ? GetMenuItemInfoA( hmenu, 0, TRUE, &info ) :
915 GetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW *)&info );
918 ok_(__FILE__, line)( !ret, "GetMenuItemInfo should have failed.\n" );
921 ok_(__FILE__, line)( ret, "GetMenuItemInfo failed, err %u\n", GetLastError());
922 if (mask & MIIM_TYPE)
923 ok_(__FILE__, line)( info.fType == type || info.fType == LOWORD(type),
924 "wrong type %x/%x\n", info.fType, type );
925 if (mask & MIIM_STATE)
926 ok_(__FILE__, line)( info.fState == state || info.fState == LOWORD(state),
927 "wrong state %x/%x\n", info.fState, state );
929 ok_(__FILE__, line)( info.wID == id || info.wID == LOWORD(id),
930 "wrong id %x/%x\n", info.wID, id );
931 if (mask & MIIM_SUBMENU)
932 ok_(__FILE__, line)( info.hSubMenu == submenu || (ULONG_PTR)info.hSubMenu == LOWORD(submenu),
933 "wrong submenu %p/%p\n", info.hSubMenu, submenu );
934 if (mask & MIIM_CHECKMARKS)
936 ok_(__FILE__, line)( info.hbmpChecked == checked || (ULONG_PTR)info.hbmpChecked == LOWORD(checked),
937 "wrong bmpchecked %p/%p\n", info.hbmpChecked, checked );
938 ok_(__FILE__, line)( info.hbmpUnchecked == unchecked || (ULONG_PTR)info.hbmpUnchecked == LOWORD(unchecked),
939 "wrong bmpunchecked %p/%p\n", info.hbmpUnchecked, unchecked );
941 if (mask & MIIM_DATA)
942 ok_(__FILE__, line)( info.dwItemData == data || info.dwItemData == LOWORD(data),
943 "wrong item data %lx/%lx\n", info.dwItemData, data );
944 if (mask & MIIM_BITMAP)
945 ok_(__FILE__, line)( info.hbmpItem == item || (ULONG_PTR)info.hbmpItem == LOWORD(item),
946 "wrong bmpitem %p/%p\n", info.hbmpItem, item );
947 ok_(__FILE__, line)( info.dwTypeData == type_data || (ULONG_PTR)info.dwTypeData == LOWORD(type_data),
948 "wrong type data %p/%p\n", info.dwTypeData, type_data );
949 ok_(__FILE__, line)( info.cch == out_len, "wrong len %x/%x\n", info.cch, out_len );
953 ok_(__FILE__, line)( !strncmp( expname, info.dwTypeData, out_len ),
954 "menu item name differed from '%s' '%s'\n", expname, info.dwTypeData );
956 ok_(__FILE__, line)( !strncmpW( (WCHAR *)expname, (WCHAR *)info.dwTypeData, out_len ),
957 "menu item name wrong\n" );
959 SetLastError( 0xdeadbeef );
960 ret = ansi ? GetMenuStringA( hmenu, 0, (char *)buffer, 80, MF_BYPOSITION ) :
961 GetMenuStringW( hmenu, 0, buffer, 80, MF_BYPOSITION );
963 ok_(__FILE__, line)( ret, "GetMenuString failed, err %u\n", GetLastError());
965 ok_(__FILE__, line)( !ret, "GetMenuString should have failed\n" );
969 static void modify_menu( int line, HMENU hmenu, BOOL ansi, UINT flags, UINT_PTR id, void *data )
973 SetLastError( 0xdeadbeef );
974 if (ansi) ret = ModifyMenuA( hmenu, 0, flags, id, data );
975 else ret = ModifyMenuW( hmenu, 0, flags, id, data );
976 ok_(__FILE__,line)( ret, "ModifyMenuA failed, err %u\n", GetLastError());
979 static void set_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
980 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
981 void *type_data, UINT len, HBITMAP item )
987 /* magic bitmap handle to test smaller cbSize */
988 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
989 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
991 info.cbSize = sizeof(info);
996 info.hSubMenu = submenu;
997 info.hbmpChecked = checked;
998 info.hbmpUnchecked = unchecked;
999 info.dwItemData = data;
1000 info.dwTypeData = type_data;
1002 info.hbmpItem = item;
1003 SetLastError( 0xdeadbeef );
1004 if (ansi) ret = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1005 else ret = SetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
1006 ok_(__FILE__, line)( ret, "SetMenuItemInfo failed, err %u\n", GetLastError());
1009 #define TMII_INSMI( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,eret1 )\
1010 hmenu = CreateMenu();\
1011 submenu = CreateMenu();\
1012 if(ansi)strcpy( string, init );\
1013 else strcpyW( string, init );\
1014 insert_menu_item( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, eret1 )
1016 /* GetMenuItemInfo + GetMenuString */
1017 #define TMII_GMII( c2,l2,\
1018 d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,\
1019 expname, eret2, eret3)\
1020 check_menu_item_info( __LINE__, hmenu, ansi, c2, d3, e3, f3, g3, h3, i3, j3, k3, l2, l3, m3, \
1021 expname, eret2, eret3 )
1024 RemoveMenu(hmenu, 0, TRUE );\
1025 DestroyMenu( hmenu );\
1026 DestroyMenu( submenu );
1029 #define TMII_MODM( flags, id, data ) \
1030 modify_menu( __LINE__, hmenu, ansi, flags, id, data )
1032 /* SetMenuItemInfo */
1033 #define TMII_SMII( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1 ) \
1034 set_menu_item_info( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1 )
1041 static void test_menu_iteminfo( void )
1047 WCHAR txtW[]={'W','i','n','e',0};
1048 WCHAR initW[]={'X','Y','Z',0};
1050 void *txt, *init, *empty, *string;
1051 HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
1053 HMENU hmenu, submenu=CreateMenu();
1054 HBITMAP dummy_hbm = (HBITMAP)(ULONG_PTR)0xdeadbeef;
1057 if( ansi) {txt=txtA;init=initA;empty=emptyA;string=stringA;}
1058 else {txt=txtW;init=initW;empty=emptyW;string=stringA;}
1059 trace( "%s string %p hbm %p txt %p\n", ansi ? "ANSI tests: " : "Unicode tests:", string, hbm, txt);
1060 /* test all combinations of MFT_STRING, MFT_OWNERDRAW and MFT_BITMAP */
1061 /* (since MFT_STRING is zero, there are four of them) */
1062 TMII_INSMI( MIIM_TYPE, MFT_STRING, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1063 TMII_GMII ( MIIM_TYPE, 80,
1064 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1067 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1068 TMII_GMII ( MIIM_TYPE, 80,
1069 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1072 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1073 TMII_GMII ( MIIM_TYPE, 80,
1074 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1077 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1078 TMII_GMII ( MIIM_TYPE, 80,
1079 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1082 /* not enough space for name*/
1083 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1084 TMII_GMII ( MIIM_TYPE, 0,
1085 MFT_STRING, 0, 0, 0, 0, 0, 0, NULL, 4, 0,
1088 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1089 TMII_GMII ( MIIM_TYPE, 5,
1090 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1093 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1094 TMII_GMII ( MIIM_TYPE, 4,
1095 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 3, 0,
1098 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1099 TMII_GMII ( MIIM_TYPE, 0,
1100 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, 0,
1103 /* cannot combine MIIM_TYPE with some other flags */
1104 TMII_INSMI( MIIM_TYPE|MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1106 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1107 TMII_GMII ( MIIM_TYPE|MIIM_STRING, 80,
1108 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1111 TMII_INSMI( MIIM_TYPE|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1113 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1114 TMII_GMII ( MIIM_TYPE|MIIM_FTYPE, 80,
1115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1118 TMII_INSMI( MIIM_TYPE|MIIM_BITMAP, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, hbm, ER );
1120 /* but succeeds with some others */
1121 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1122 TMII_GMII ( MIIM_TYPE|MIIM_SUBMENU, 80,
1123 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1126 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1127 TMII_GMII ( MIIM_TYPE|MIIM_STATE, 80,
1128 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1131 TMII_INSMI( MIIM_TYPE|MIIM_ID, MFT_STRING, -1, 888, 0, 0, 0, -1, txt, 6, 0, OK );
1132 TMII_GMII ( MIIM_TYPE|MIIM_ID, 80,
1133 MFT_STRING, 0, 888, 0, 0, 0, 0, string, 4, 0,
1136 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING, -1, -1, 0, 0, 0, 999, txt, 6, 0, OK );
1137 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1138 MFT_STRING, 0, 0, 0, 0, 0, 999, string, 4, 0,
1141 /* to be continued */
1142 /* set text with MIIM_TYPE and retrieve with MIIM_STRING */
1143 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1144 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1145 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1148 /* set text with MIIM_TYPE and retrieve with MIIM_STRING; MFT_OWNERDRAW causes an empty string */
1149 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1150 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1151 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1154 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1155 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1156 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1159 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1160 TMII_GMII ( MIIM_FTYPE, 80,
1161 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, 0,
1164 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1166 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1169 /* contrary to MIIM_TYPE,you can set the text for an owner draw menu */
1170 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1171 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1172 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1175 /* same but retrieve with MIIM_TYPE */
1176 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1177 TMII_GMII ( MIIM_TYPE, 80,
1178 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1181 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1182 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1183 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1186 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1187 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1188 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1192 /* How is that with bitmaps? */
1193 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1194 TMII_GMII ( MIIM_TYPE, 80,
1195 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1198 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1199 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1200 0, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1203 /* MIIM_BITMAP does not like MFT_BITMAP */
1204 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, hbm, ER );
1206 /* no problem with OWNERDRAWN */
1207 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1208 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1209 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1212 /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1213 TMII_INSMI( MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER );
1216 /* menu with submenu */
1217 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1218 TMII_GMII ( MIIM_SUBMENU, 80,
1219 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1222 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, empty, 0, 0, OK );
1223 TMII_GMII ( MIIM_SUBMENU, 80,
1224 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1227 /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1228 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1229 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1230 MFT_STRING|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1232 TMII_GMII ( MIIM_SUBMENU|MIIM_FTYPE, 80,
1233 MFT_SEPARATOR, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1236 /* menu with invalid submenu */
1237 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, (HMENU)999, 0, 0, -1, txt, 0, 0, ER );
1240 TMII_INSMI( MIIM_TYPE, MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1241 TMII_GMII ( MIIM_TYPE, 80,
1242 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1245 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1246 TMII_GMII ( MIIM_TYPE, 80,
1247 MFT_BITMAP|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1250 /* SEPARATOR and STRING go well together */
1251 /* BITMAP and STRING go well together */
1252 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1253 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1254 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1257 /* BITMAP, SEPARATOR and STRING go well together */
1258 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1259 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1260 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1263 /* last two tests, but use MIIM_TYPE to retrieve info */
1264 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1265 TMII_GMII ( MIIM_TYPE, 80,
1266 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1269 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1270 TMII_GMII ( MIIM_TYPE, 80,
1271 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1274 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1275 TMII_GMII ( MIIM_TYPE, 80,
1276 MFT_SEPARATOR|MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1279 /* same three with MFT_OWNERDRAW */
1280 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1281 TMII_GMII ( MIIM_TYPE, 80,
1282 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1285 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1286 TMII_GMII ( MIIM_TYPE, 80,
1287 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1290 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1291 TMII_GMII ( MIIM_TYPE, 80,
1292 MFT_SEPARATOR|MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1296 TMII_INSMI( MIIM_STRING|MIIM_FTYPE|MIIM_ID, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1297 TMII_GMII ( MIIM_TYPE, 80,
1298 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1301 /* test with modifymenu: string is preserved after setting OWNERDRAW */
1302 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1303 TMII_MODM( MFT_OWNERDRAW, -1, (void*)787 );
1304 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_DATA, 80,
1305 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 787, string, 4, 0,
1308 /* same with bitmap: now the text is cleared */
1309 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1310 TMII_MODM( MFT_BITMAP, 545, hbm );
1311 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1312 MFT_BITMAP, 0, 545, 0, 0, 0, 0, string, 0, hbm,
1315 /* start with bitmap: now setting text clears it (though he flag is raised) */
1316 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1317 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1318 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 0, hbm,
1320 TMII_MODM( MFT_STRING, 545, txt );
1321 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1322 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 4, 0,
1325 /*repeat with text NULL */
1326 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1327 TMII_MODM( MFT_STRING, 545, NULL );
1328 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1329 MFT_SEPARATOR, 0, 545, 0, 0, 0, 0, string, 0, 0,
1332 /* repeat with text "" */
1333 TMII_INSMI( MIIM_BITMAP, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1334 TMII_MODM( MFT_STRING, 545, empty );
1335 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1336 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 0, 0,
1339 /* start with bitmap: set ownerdraw */
1340 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1341 TMII_MODM( MFT_OWNERDRAW, -1, (void *)232 );
1342 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_DATA, 80,
1343 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 232, string, 0, hbm,
1347 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1349 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1352 /* some tests with small cbSize: the hbmpItem is to be ignored */
1353 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1354 TMII_GMII ( MIIM_TYPE, 80,
1355 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1358 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1359 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1360 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, NULL,
1363 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1364 TMII_GMII ( MIIM_TYPE, 80,
1365 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, NULL,
1368 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1369 TMII_GMII ( MIIM_TYPE, 80,
1370 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1373 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1374 TMII_GMII ( MIIM_TYPE, 80,
1375 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1378 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1379 TMII_GMII ( MIIM_TYPE, 80,
1380 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1383 /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus */
1384 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1385 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1386 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1389 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1390 TMII_GMII ( MIIM_TYPE, 80,
1391 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1394 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1395 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1396 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1399 /* set a string menu to ownerdraw with MIIM_TYPE */
1400 TMII_INSMI( MIIM_TYPE, MFT_STRING, -2, -2, 0, 0, 0, -2, txt, -2, 0, OK );
1401 TMII_SMII ( MIIM_TYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1402 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1403 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1406 /* test with modifymenu add submenu */
1407 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1408 TMII_MODM( MF_POPUP, (UINT_PTR)submenu, txt );
1409 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_SUBMENU, 80,
1410 MFT_STRING, 0, 0, submenu, 0, 0, 0, string, 4, 0,
1412 TMII_GMII ( MIIM_TYPE, 80,
1413 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1416 /* MFT_SEPARATOR bit is kept when the text is added */
1417 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1418 TMII_SMII( MIIM_STRING, 0, 0, 0, 0, 0, 0, 0, txt, 0, 0 );
1419 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1420 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, 0,
1423 /* MFT_SEPARATOR bit is kept when bitmap is added */
1424 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1425 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm );
1426 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1427 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1430 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1431 Only the low word of the dwTypeData is used.
1432 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1433 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1434 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1435 TMII_GMII ( MIIM_TYPE, 80,
1436 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1440 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1441 TMII_GMII ( MIIM_TYPE, 80,
1442 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1446 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1447 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1448 TMII_GMII ( MIIM_STATE, 80,
1449 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1452 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1453 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1454 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1455 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1456 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1459 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1460 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1461 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1462 TMII_GMII ( MIIM_FTYPE, 80,
1463 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1465 TMII_GMII ( MIIM_TYPE, 80,
1466 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1468 TMII_GMII ( MIIM_FTYPE, 80,
1469 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1471 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1472 TMII_GMII ( MIIM_TYPE, 80,
1473 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1476 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1477 Only the low word of the dwTypeData is used.
1478 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1479 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1480 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1481 TMII_GMII ( MIIM_TYPE, 80,
1482 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1486 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1487 TMII_GMII ( MIIM_TYPE, 80,
1488 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1492 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1493 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1494 TMII_GMII ( MIIM_STATE, 80,
1495 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1498 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1499 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1500 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1501 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1502 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1505 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1506 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1507 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1508 TMII_GMII ( MIIM_FTYPE, 80,
1509 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1511 TMII_GMII ( MIIM_TYPE, 80,
1512 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1514 TMII_GMII ( MIIM_FTYPE, 80,
1515 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1517 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1518 TMII_GMII ( MIIM_TYPE, 80,
1519 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1522 } while( !(ansi = !ansi) );
1527 The following tests try to confirm the algorithm used to return the menu items
1528 when there is a collision between a menu item and a popup menu
1530 static void test_menu_search_bycommand( void )
1532 HMENU hmenu, hmenuSub, hmenuSub2;
1538 static CHAR menuitem[] = "MenuItem",
1539 menuitem2[] = "MenuItem 2";
1541 /* Case 1: Menu containing a menu item */
1542 hmenu = CreateMenu();
1544 memset( &info, 0, sizeof info );
1545 info.cbSize = sizeof info;
1546 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1547 info.fType = MFT_STRING;
1548 strcpy(strIn, "Case 1 MenuItem");
1549 info.dwTypeData = strIn;
1550 info.wID = (UINT) 0x1234;
1552 rc = InsertMenuItem(hmenu, 0, TRUE, &info );
1553 ok (rc, "Inserting the menuitem failed\n");
1555 id = GetMenuItemID(hmenu, 0);
1556 ok (id == 0x1234, "Getting the menuitem id failed(gave %x)\n", id);
1558 /* Confirm the menuitem was given the id supplied (getting by position) */
1559 memset( &info, 0, sizeof info );
1561 info.cbSize = sizeof(MENUITEMINFO);
1562 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1563 info.dwTypeData = strback;
1564 info.cch = sizeof(strback);
1566 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info); /* Get by position */
1567 ok (rc, "Getting the menu items info failed\n");
1568 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1569 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1571 /* Search by id - Should return the item */
1572 memset( &info, 0, sizeof info );
1574 info.cbSize = sizeof(MENUITEMINFO);
1575 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1576 info.dwTypeData = strback;
1577 info.cch = sizeof(strback);
1578 rc = GetMenuItemInfo(hmenu, 0x1234, FALSE, &info); /* Get by ID */
1580 ok (rc, "Getting the menu items info failed\n");
1581 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1582 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1584 DestroyMenu( hmenu );
1586 /* Case 2: Menu containing a popup menu */
1587 hmenu = CreateMenu();
1588 hmenuSub = CreateMenu();
1590 strcpy(strIn, "Case 2 SubMenu");
1591 rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, strIn);
1592 ok (rc, "Inserting the popup menu into the main menu failed\n");
1594 id = GetMenuItemID(hmenu, 0);
1595 ok (id == -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id);
1597 /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
1598 memset( &info, 0, sizeof info );
1600 info.cbSize = sizeof(MENUITEMINFO);
1601 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1602 info.dwTypeData = strback;
1603 info.cch = sizeof(strback);
1604 info.wID = 0xdeadbeef;
1606 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info); /* Get by position */
1607 ok (rc, "Getting the menu items info failed\n");
1608 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the menuitem\n");
1609 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1611 /* Search by id - returns the popup menu itself */
1612 memset( &info, 0, sizeof info );
1614 info.cbSize = sizeof(MENUITEMINFO);
1615 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1616 info.dwTypeData = strback;
1617 info.cch = sizeof(strback);
1618 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1620 ok (rc, "Getting the menu items info failed\n");
1621 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1622 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1625 Now add an item after it with the same id
1627 memset( &info, 0, sizeof info );
1628 info.cbSize = sizeof info;
1629 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1630 info.fType = MFT_STRING;
1631 strcpy(strIn, "Case 2 MenuItem 1");
1632 info.dwTypeData = strIn;
1633 info.wID = (UINT_PTR) hmenuSub;
1634 rc = InsertMenuItem(hmenu, -1, TRUE, &info );
1635 ok (rc, "Inserting the menuitem failed\n");
1637 /* Search by id - returns the item which follows the popup menu */
1638 memset( &info, 0, sizeof info );
1640 info.cbSize = sizeof(MENUITEMINFO);
1641 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1642 info.dwTypeData = strback;
1643 info.cch = sizeof(strback);
1644 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1646 ok (rc, "Getting the menu items info failed\n");
1647 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1648 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1651 Now add an item before the popup (with the same id)
1653 memset( &info, 0, sizeof info );
1654 info.cbSize = sizeof info;
1655 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1656 info.fType = MFT_STRING;
1657 strcpy(strIn, "Case 2 MenuItem 2");
1658 info.dwTypeData = strIn;
1659 info.wID = (UINT_PTR) hmenuSub;
1660 rc = InsertMenuItem(hmenu, 0, TRUE, &info );
1661 ok (rc, "Inserting the menuitem failed\n");
1663 /* Search by id - returns the item which precedes the popup menu */
1664 memset( &info, 0, sizeof info );
1666 info.cbSize = sizeof(MENUITEMINFO);
1667 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1668 info.dwTypeData = strback;
1669 info.cch = sizeof(strback);
1670 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1672 ok (rc, "Getting the menu items info failed\n");
1673 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1674 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1676 DestroyMenu( hmenu );
1677 DestroyMenu( hmenuSub );
1680 Case 3: Menu containing a popup menu which in turn
1681 contains 2 items with the same id as the popup itself
1684 hmenu = CreateMenu();
1685 hmenuSub = CreateMenu();
1687 memset( &info, 0, sizeof info );
1688 info.cbSize = sizeof info;
1689 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1690 info.fType = MFT_STRING;
1691 info.dwTypeData = menuitem;
1692 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1694 rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1695 ok (rc, "Inserting the popup menu into the main menu failed\n");
1697 rc = InsertMenuItem(hmenuSub, 0, TRUE, &info );
1698 ok (rc, "Inserting the sub menu menuitem failed\n");
1700 memset( &info, 0, sizeof info );
1701 info.cbSize = sizeof info;
1702 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1703 info.fType = MFT_STRING;
1704 info.dwTypeData = menuitem2;
1705 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1707 rc = InsertMenuItem(hmenuSub, 1, TRUE, &info );
1708 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
1710 /* Prove that you can't query the id of a popup directly (By position) */
1711 id = GetMenuItemID(hmenu, 0);
1712 ok (id == -1, "Getting the sub menu id should have failed because its a popup (gave %x)\n", id);
1714 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1715 memset( &info, 0, sizeof info );
1717 info.cbSize = sizeof(MENUITEMINFO);
1718 info.fMask = MIIM_STRING | MIIM_ID;
1719 info.dwTypeData = strback;
1720 info.cch = sizeof(strback);
1722 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
1723 ok (rc, "Getting the menus info failed\n");
1724 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
1725 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1726 DestroyMenu( hmenu );
1727 DestroyMenu( hmenuSub );
1730 Case 4: Menu containing 2 popup menus, the second
1731 contains 2 items with the same id as the first popup menu
1733 hmenu = CreateMenu();
1734 hmenuSub = CreateMenu();
1735 hmenuSub2 = CreateMenu();
1737 rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1738 ok (rc, "Inserting the popup menu into the main menu failed\n");
1740 rc = InsertMenu(hmenu, 1, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub2, "Submenu2");
1741 ok (rc, "Inserting the popup menu into the main menu failed\n");
1743 memset( &info, 0, sizeof info );
1744 info.cbSize = sizeof info;
1745 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1746 info.fType = MFT_STRING;
1747 info.dwTypeData = menuitem;
1748 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1750 rc = InsertMenuItem(hmenuSub2, 0, TRUE, &info );
1751 ok (rc, "Inserting the sub menu menuitem failed\n");
1753 memset( &info, 0, sizeof info );
1754 info.cbSize = sizeof info;
1755 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1756 info.fType = MFT_STRING;
1757 info.dwTypeData = menuitem2;
1758 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1760 rc = InsertMenuItem(hmenuSub2, 1, TRUE, &info );
1761 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
1763 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1764 memset( &info, 0, sizeof info );
1766 info.cbSize = sizeof(MENUITEMINFO);
1767 info.fMask = MIIM_STRING | MIIM_ID;
1768 info.dwTypeData = strback;
1769 info.cch = sizeof(strback);
1771 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
1772 ok (rc, "Getting the menus info failed\n");
1773 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
1774 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1776 memset( &info, 0, sizeof info );
1778 info.cbSize = sizeof(MENUITEMINFO);
1779 info.fMask = MIIM_STRING | MIIM_ID;
1780 info.dwTypeData = strback;
1781 info.cch = sizeof(strback);
1783 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub2, FALSE, &info);
1784 ok (rc, "Getting the menus info failed\n");
1785 ok (info.wID == (UINT_PTR)hmenuSub2, "IDs differ for popup menu\n");
1786 ok (!strcmp(info.dwTypeData, "Submenu2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1788 DestroyMenu( hmenu );
1789 DestroyMenu( hmenuSub );
1790 DestroyMenu( hmenuSub2 );
1794 Case 5: Menu containing a popup menu which in turn
1795 contains an item with a different id than the popup menu.
1796 This tests the fallback to a popup menu ID.
1799 hmenu = CreateMenu();
1800 hmenuSub = CreateMenu();
1802 rc = AppendMenu(hmenu, MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1803 ok (rc, "Appending the popup menu to the main menu failed\n");
1805 rc = AppendMenu(hmenuSub, MF_STRING, 102, "Item");
1806 ok (rc, "Appending the item to the popup menu failed\n");
1808 /* Set the ID for hmenuSub */
1809 info.cbSize = sizeof(info);
1810 info.fMask = MIIM_ID;
1813 rc = SetMenuItemInfo(hmenu, 0, TRUE, &info);
1814 ok(rc, "Setting the ID for the popup menu failed\n");
1816 /* Check if the ID has been set */
1818 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info);
1819 ok(rc, "Getting the ID for the popup menu failed\n");
1820 ok(info.wID == 101, "The ID for the popup menu has not been set\n");
1822 /* Prove getting the item info via ID returns the popup menu */
1823 memset( &info, 0, sizeof(info));
1825 info.cbSize = sizeof(MENUITEMINFO);
1826 info.fMask = MIIM_STRING | MIIM_ID;
1827 info.dwTypeData = strback;
1828 info.cch = sizeof(strback);
1830 rc = GetMenuItemInfo(hmenu, 101, FALSE, &info);
1831 ok (rc, "Getting the menu info failed\n");
1832 ok (info.wID == 101, "IDs differ\n");
1833 ok (!strcmp(info.dwTypeData, "Submenu"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1835 /* Also look for the menu item */
1836 memset( &info, 0, sizeof(info));
1838 info.cbSize = sizeof(MENUITEMINFO);
1839 info.fMask = MIIM_STRING | MIIM_ID;
1840 info.dwTypeData = strback;
1841 info.cch = sizeof(strback);
1843 rc = GetMenuItemInfo(hmenu, 102, FALSE, &info);
1844 ok (rc, "Getting the menu info failed\n");
1845 ok (info.wID == 102, "IDs differ\n");
1846 ok (!strcmp(info.dwTypeData, "Item"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1849 DestroyMenu(hmenuSub);
1852 struct menu_item_pair_s {
1853 UINT uMenu; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
1854 * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
1855 * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
1859 static struct menu_mouse_tests_s {
1861 struct menu_item_pair_s menu_item_pairs[5]; /* for mousing */
1862 WORD wVk[5]; /* keys */
1866 /* for each test, send keys or clicks and check for menu visibility */
1867 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE }, /* test 0 */
1868 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
1869 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
1870 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
1871 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
1872 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
1873 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
1874 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, VK_ESCAPE, 0}, FALSE, FALSE },
1875 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', VK_ESCAPE, 0}, TRUE, FALSE },
1876 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
1877 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
1878 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
1879 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
1880 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
1881 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
1882 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
1883 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
1884 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
1886 { INPUT_MOUSE, {{1, 2}, {0}}, {0}, TRUE, TRUE }, /* test 18 */
1887 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
1888 { INPUT_MOUSE, {{1, 0}, {0}}, {0}, TRUE, TRUE },
1889 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
1890 { INPUT_MOUSE, {{1, 0}, {2, 2}, {0}}, {0}, TRUE, TRUE },
1891 { INPUT_MOUSE, {{2, 1}, {0}}, {0}, FALSE, FALSE },
1892 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
1893 { INPUT_MOUSE, {{3, 0}, {0}}, {0}, FALSE, FALSE },
1894 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
1895 { INPUT_MOUSE, {{3, 1}, {0}}, {0}, TRUE, TRUE },
1896 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
1900 static void send_key(WORD wVk)
1903 memset(i, 0, sizeof(i));
1904 i[0].type = i[1].type = INPUT_KEYBOARD;
1905 i[0].u.ki.wVk = i[1].u.ki.wVk = wVk;
1906 i[1].u.ki.dwFlags = KEYEVENTF_KEYUP;
1907 pSendInput(2, (INPUT *) i, sizeof(INPUT));
1910 static BOOL click_menu(HANDLE hWnd, struct menu_item_pair_s *mi)
1912 HMENU hMenu = hMenus[mi->uMenu];
1916 int screen_w = GetSystemMetrics(SM_CXSCREEN);
1917 int screen_h = GetSystemMetrics(SM_CYSCREEN);
1918 BOOL ret = GetMenuItemRect(mi->uMenu > 2 ? NULL : hWnd, hMenu, mi->uItem, &r);
1919 if(!ret) return FALSE;
1921 memset(i, 0, sizeof(i));
1922 i[0].type = i[1].type = i[2].type = INPUT_MOUSE;
1923 i[0].u.mi.dx = i[1].u.mi.dx = i[2].u.mi.dx
1924 = ((r.left + 5) * 65535) / screen_w;
1925 i[0].u.mi.dy = i[1].u.mi.dy = i[2].u.mi.dy
1926 = ((r.top + 5) * 65535) / screen_h;
1927 i[0].u.mi.dwFlags = i[1].u.mi.dwFlags = i[2].u.mi.dwFlags
1928 = MOUSEEVENTF_ABSOLUTE;
1929 i[0].u.mi.dwFlags |= MOUSEEVENTF_MOVE;
1930 i[1].u.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
1931 i[2].u.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
1932 ret = pSendInput(3, (INPUT *) i, sizeof(INPUT));
1934 /* hack to prevent mouse message buildup in Wine */
1935 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
1939 static DWORD WINAPI test_menu_input_thread(LPVOID lpParameter)
1942 HANDLE hWnd = lpParameter;
1945 /* mixed keyboard/mouse test */
1946 for (i = 0; menu_tests[i].type != -1; i++)
1948 int ret = TRUE, elapsed = 0;
1950 got_input = i && menu_tests[i-1].bMenuVisible;
1952 if (menu_tests[i].type == INPUT_KEYBOARD)
1953 for (j = 0; menu_tests[i].wVk[j] != 0; j++)
1954 send_key(menu_tests[i].wVk[j]);
1956 for (j = 0; menu_tests[i].menu_item_pairs[j].uMenu != 0; j++)
1957 if (!(ret = click_menu(hWnd, &menu_tests[i].menu_item_pairs[j]))) break;
1961 skip( "test %u: failed to send input\n", i );
1962 PostMessage( hWnd, WM_CANCELMODE, 0, 0 );
1965 while (menu_tests[i].bMenuVisible != bMenuVisible)
1975 skip( "test %u: didn't receive input\n", i );
1976 PostMessage( hWnd, WM_CANCELMODE, 0, 0 );
1980 if (menu_tests[i]._todo_wine)
1983 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
1987 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
1992 static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam,
1996 case WM_ENTERMENULOOP:
1997 bMenuVisible = TRUE;
1999 case WM_EXITMENULOOP:
2000 bMenuVisible = FALSE;
2005 case WM_LBUTTONDOWN:
2007 case WM_NCMOUSEMOVE:
2008 case WM_NCLBUTTONDOWN:
2009 case WM_NCLBUTTONUP:
2013 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2018 static void test_menu_input(void) {
2021 HINSTANCE hInstance = GetModuleHandleA( NULL );
2022 HANDLE hThread, hWnd;
2025 wclass.lpszClassName = "MenuTestClass";
2026 wclass.style = CS_HREDRAW | CS_VREDRAW;
2027 wclass.lpfnWndProc = WndProc;
2028 wclass.hInstance = hInstance;
2029 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
2030 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
2031 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2032 wclass.lpszMenuName = 0;
2033 wclass.cbClsExtra = 0;
2034 wclass.cbWndExtra = 0;
2035 assert (RegisterClassA( &wclass ));
2036 assert (hWnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
2037 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2038 400, 200, NULL, NULL, hInstance, NULL) );
2041 hMenus[3] = CreatePopupMenu();
2042 AppendMenu(hMenus[3], MF_STRING, 0, "&Enabled");
2043 AppendMenu(hMenus[3], MF_STRING|MF_DISABLED, 0, "&Disabled");
2045 hMenus[2] = CreatePopupMenu();
2046 AppendMenu(hMenus[2], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[3], "&Popup");
2047 AppendMenu(hMenus[2], MF_STRING, 0, "&Enabled");
2048 AppendMenu(hMenus[2], MF_STRING|MF_DISABLED, 0, "&Disabled");
2050 hMenus[1] = CreateMenu();
2051 AppendMenu(hMenus[1], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[2], "&Menu");
2052 AppendMenu(hMenus[1], MF_STRING, 0, "&Enabled");
2053 AppendMenu(hMenus[1], MF_STRING|MF_DISABLED, 0, "&Disabled");
2055 SetMenu(hWnd, hMenus[1]);
2056 ShowWindow(hWnd, SW_SHOW);
2059 hThread = CreateThread(NULL, 0, test_menu_input_thread, hWnd, 0, &tid);
2062 if (WAIT_TIMEOUT != WaitForSingleObject(hThread, 50))
2064 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2066 DestroyWindow(hWnd);
2069 static void test_menu_flags( void )
2071 HMENU hMenu, hPopupMenu;
2073 hMenu = CreateMenu();
2074 hPopupMenu = CreatePopupMenu();
2076 AppendMenu(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2078 AppendMenu(hPopupMenu, MF_STRING | MF_HILITE | MF_DEFAULT, 101, "Item 1");
2079 InsertMenu(hPopupMenu, 1, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 102, "Item 2");
2080 AppendMenu(hPopupMenu, MF_STRING, 103, "Item 3");
2081 ModifyMenu(hPopupMenu, 2, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 103, "Item 3");
2083 ok(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_HILITE,
2084 "AppendMenu should accept MF_HILITE\n");
2085 ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2086 "InsertMenu should accept MF_HILITE\n");
2087 ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2088 "ModifyMenu should accept MF_HILITE\n");
2090 ok(!(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_DEFAULT),
2091 "AppendMenu must not accept MF_DEFAULT\n");
2092 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_DEFAULT),
2093 "InsertMenu must not accept MF_DEFAULT\n");
2094 ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_DEFAULT),
2095 "ModifyMenu must not accept MF_DEFAULT\n");
2100 static void test_menu_hilitemenuitem( void )
2102 HMENU hMenu, hPopupMenu;
2106 wclass.lpszClassName = "HiliteMenuTestClass";
2107 wclass.style = CS_HREDRAW | CS_VREDRAW;
2108 wclass.lpfnWndProc = WndProc;
2109 wclass.hInstance = GetModuleHandleA( NULL );
2110 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
2111 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
2112 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2113 wclass.lpszMenuName = 0;
2114 wclass.cbClsExtra = 0;
2115 wclass.cbWndExtra = 0;
2116 assert (RegisterClassA( &wclass ));
2117 assert (hWnd = CreateWindowA( wclass.lpszClassName, "HiliteMenuTest",
2118 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2119 400, 200, NULL, NULL, wclass.hInstance, NULL) );
2121 hMenu = CreateMenu();
2122 hPopupMenu = CreatePopupMenu();
2124 AppendMenu(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2126 AppendMenu(hPopupMenu, MF_STRING, 101, "Item 1");
2127 AppendMenu(hPopupMenu, MF_STRING, 102, "Item 2");
2128 AppendMenu(hPopupMenu, MF_STRING, 103, "Item 3");
2130 SetMenu(hWnd, hMenu);
2132 /* test invalid arguments */
2134 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2135 "HiliteMenuItem: Item 2 is hilited\n");
2137 SetLastError(0xdeadbeef);
2140 ok(!HiliteMenuItem(NULL, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2141 "HiliteMenuItem: call should have failed.\n");
2143 ok(GetLastError() == 0xdeadbeef || /* 9x */
2144 GetLastError() == ERROR_INVALID_WINDOW_HANDLE /* NT */,
2145 "HiliteMenuItem: expected error ERROR_INVALID_WINDOW_HANDLE, got: %d\n", GetLastError());
2147 SetLastError(0xdeadbeef);
2148 ok(!HiliteMenuItem(hWnd, NULL, 1, MF_HILITE | MF_BYPOSITION),
2149 "HiliteMenuItem: call should have failed.\n");
2150 ok(GetLastError() == 0xdeadbeef || /* 9x */
2151 GetLastError() == ERROR_INVALID_MENU_HANDLE /* NT */,
2152 "HiliteMenuItem: expected error ERROR_INVALID_MENU_HANDLE, got: %d\n", GetLastError());
2154 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2155 "HiliteMenuItem: Item 2 is hilited\n");
2157 /* either MF_HILITE or MF_UNHILITE *and* MF_BYCOMMAND or MF_BYPOSITION need to be set */
2159 SetLastError(0xdeadbeef);
2160 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_BYPOSITION),
2161 "HiliteMenuItem: call should have succeeded.\n");
2162 ok(GetLastError() == 0xdeadbeef,
2163 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2165 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2166 "HiliteMenuItem: Item 2 is hilited\n");
2168 SetLastError(0xdeadbeef);
2171 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE),
2172 "HiliteMenuItem: call should have succeeded.\n");
2174 ok(GetLastError() == 0xdeadbeef,
2175 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2177 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2178 "HiliteMenuItem: Item 2 is hilited\n");
2180 /* hilite a menu item (by position) */
2182 SetLastError(0xdeadbeef);
2183 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2184 "HiliteMenuItem: call should not have failed.\n");
2185 ok(GetLastError() == 0xdeadbeef,
2186 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2190 ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2191 "HiliteMenuItem: Item 2 is not hilited\n");
2194 /* unhilite a menu item (by position) */
2196 SetLastError(0xdeadbeef);
2197 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_UNHILITE | MF_BYPOSITION),
2198 "HiliteMenuItem: call should not have failed.\n");
2199 ok(GetLastError() == 0xdeadbeef,
2200 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2202 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2203 "HiliteMenuItem: Item 2 is hilited\n");
2205 /* hilite a menu item (by command) */
2207 SetLastError(0xdeadbeef);
2208 ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_HILITE | MF_BYCOMMAND),
2209 "HiliteMenuItem: call should not have failed.\n");
2210 ok(GetLastError() == 0xdeadbeef,
2211 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2215 ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2216 "HiliteMenuItem: Item 3 is not hilited\n");
2219 /* unhilite a menu item (by command) */
2221 SetLastError(0xdeadbeef);
2222 ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_UNHILITE | MF_BYCOMMAND),
2223 "HiliteMenuItem: call should not have failed.\n");
2224 ok(GetLastError() == 0xdeadbeef,
2225 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2227 ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE),
2228 "HiliteMenuItem: Item 3 is hilited\n");
2230 DestroyWindow(hWnd);
2233 static void check_menu_items(HMENU hmenu, UINT checked_cmd, UINT checked_type,
2238 count = GetMenuItemCount(hmenu);
2239 ok (count != -1, "GetMenuItemCount returned -1\n");
2241 for (i = 0; i < count; i++)
2246 memset(&mii, 0, sizeof(mii));
2247 mii.cbSize = sizeof(mii);
2248 mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU;
2249 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2250 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2252 trace("item #%u: fType %04x, fState %04x, wID %u, hSubMenu %p\n",
2253 i, mii.fType, mii.fState, mii.wID, mii.hSubMenu);
2257 ok(mii.wID == (UINT_PTR)mii.hSubMenu, "id %u: wID should be equal to hSubMenu\n", checked_cmd);
2258 check_menu_items(mii.hSubMenu, checked_cmd, checked_type, checked_state);
2262 if (mii.wID == checked_cmd)
2264 ok(mii.fType == checked_type, "id %u: expected fType %04x, got %04x\n", checked_cmd, checked_type, mii.fType);
2265 ok(mii.fState == checked_state, "id %u: expected fState %04x, got %04x\n", checked_cmd, checked_state, mii.fState);
2266 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2270 ok(mii.fType != MFT_RADIOCHECK, "id %u: not expected fType MFT_RADIOCHECK on cmd %u\n", checked_cmd, mii.wID);
2272 if (mii.fType == MFT_SEPARATOR)
2274 ok(mii.fState == MFS_GRAYED, "id %u: expected fState MFS_GRAYED, got %04x\n", checked_cmd, mii.fState);
2275 ok(mii.wID == 0, "id %u: expected wID 0, got %u\n", checked_cmd, mii.wID);
2279 ok(mii.fState == 0, "id %u: expected fState 0, got %04x\n", checked_cmd, mii.fState);
2280 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2287 static void clear_ftype_and_state(HMENU hmenu, UINT id, UINT flags)
2292 memset(&mii, 0, sizeof(mii));
2293 mii.cbSize = sizeof(mii);
2294 mii.fMask = MIIM_FTYPE | MIIM_STATE;
2295 ret = SetMenuItemInfo(hmenu, id, (flags & MF_BYPOSITION) != 0, &mii);
2296 ok(ret, "SetMenuItemInfo(%u) failed\n", id);
2299 static void test_CheckMenuRadioItem(void)
2304 hmenu = LoadMenu(GetModuleHandle(0), MAKEINTRESOURCE(1));
2307 check_menu_items(hmenu, -1, 0, 0);
2309 ret = CheckMenuRadioItem(hmenu, 100, 100, 100, MF_BYCOMMAND);
2310 ok(ret, "CheckMenuRadioItem failed\n");
2311 check_menu_items(hmenu, 100, MFT_RADIOCHECK, MFS_CHECKED);
2313 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2314 ret = CheckMenuRadioItem(hmenu, 100, 100, -1, MF_BYCOMMAND);
2315 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2316 check_menu_items(hmenu, 100, MFT_RADIOCHECK, 0);
2319 clear_ftype_and_state(hmenu, 100, MF_BYCOMMAND);
2320 check_menu_items(hmenu, -1, 0, 0);
2322 /* first and checked items are on different menus */
2323 ret = CheckMenuRadioItem(hmenu, 0, 300, 202, MF_BYCOMMAND);
2324 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2325 check_menu_items(hmenu, -1, 0, 0);
2327 ret = CheckMenuRadioItem(hmenu, 200, 300, 202, MF_BYCOMMAND);
2328 ok(ret, "CheckMenuRadioItem failed\n");
2329 check_menu_items(hmenu, 202, MFT_RADIOCHECK, MFS_CHECKED);
2331 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2332 ret = CheckMenuRadioItem(hmenu, 202, 202, -1, MF_BYCOMMAND);
2333 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2334 check_menu_items(hmenu, 202, MFT_RADIOCHECK, 0);
2337 clear_ftype_and_state(hmenu, 202, MF_BYCOMMAND);
2338 check_menu_items(hmenu, -1, 0, 0);
2340 /* just for fun, try to check separator */
2341 ret = CheckMenuRadioItem(hmenu, 0, 300, 0, MF_BYCOMMAND);
2342 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2343 check_menu_items(hmenu, -1, 0, 0);
2346 static void test_menu_resource_layout(void)
2350 MENUITEMTEMPLATEHEADER mith;
2354 { 0, 0 }, /* versionNumber, offset */
2356 /* mtOption, mtID, mtString[] '\0' terminated */
2357 MF_STRING, 1, 'F', 0,
2360 /* MF_SEPARATOR, 4, 'S', 0, FIXME: Wine ignores 'S' */
2361 MF_STRING|MF_GRAYED|MF_END, 5, 'E', 0
2366 UINT type, state, id;
2370 { MF_STRING, MF_ENABLED, 1, "F" },
2371 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 2, "" },
2372 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 3, "" },
2373 /*{ MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 4, "S" }, FIXME: Wine ignores 'S'*/
2374 { MF_STRING, MF_GRAYED, 5, "E" },
2375 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 6, "" },
2376 { MF_STRING, MF_ENABLED, 7, "" },
2377 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 8, "" }
2383 hmenu = LoadMenuIndirect(&menu_template);
2384 ok(hmenu != 0, "LoadMenuIndirect error %u\n", GetLastError());
2386 ret = AppendMenu(hmenu, MF_STRING, 6, NULL);
2387 ok(ret, "AppendMenu failed\n");
2388 ret = AppendMenu(hmenu, MF_STRING, 7, "\0");
2389 ok(ret, "AppendMenu failed\n");
2390 ret = AppendMenu(hmenu, MF_SEPARATOR, 8, "separator");
2391 ok(ret, "AppendMenu failed\n");
2393 count = GetMenuItemCount(hmenu);
2394 ok(count == sizeof(menu_data)/sizeof(menu_data[0]),
2395 "expected %u menu items, got %u\n",
2396 (UINT)(sizeof(menu_data)/sizeof(menu_data[0])), count);
2398 for (i = 0; i < count; i++)
2403 memset(&mii, 0, sizeof(mii));
2404 mii.cbSize = sizeof(mii);
2405 mii.dwTypeData = buf;
2406 mii.cch = sizeof(buf);
2407 mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_STRING;
2408 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2409 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2411 trace("item #%u: fType %04x, fState %04x, wID %u, dwTypeData %s\n",
2412 i, mii.fType, mii.fState, mii.wID, (LPCSTR)mii.dwTypeData);
2414 ok(mii.fType == menu_data[i].type,
2415 "%u: expected fType %04x, got %04x\n", i, menu_data[i].type, mii.fType);
2416 ok(mii.fState == menu_data[i].state,
2417 "%u: expected fState %04x, got %04x\n", i, menu_data[i].state, mii.fState);
2418 ok(mii.wID == menu_data[i].id,
2419 "%u: expected wID %04x, got %04x\n", i, menu_data[i].id, mii.wID);
2420 ok(mii.cch == strlen(menu_data[i].str),
2421 "%u: expected cch %u, got %u\n", i, (UINT)strlen(menu_data[i].str), mii.cch);
2422 ok(!strcmp(mii.dwTypeData, menu_data[i].str),
2423 "%u: expected dwTypeData %s, got %s\n", i, menu_data[i].str, (LPCSTR)mii.dwTypeData);
2435 static HMENU create_menu_from_data(const struct menu_data *item, INT item_count)
2441 hmenu = CreateMenu();
2444 for (i = 0; i < item_count; i++)
2446 SetLastError(0xdeadbeef);
2447 ret = AppendMenu(hmenu, item[i].type, item[i].id, item[i].str);
2448 ok(ret, "%d: AppendMenu(%04x, %04x, %p) error %u\n",
2449 i, item[i].type, item[i].id, item[i].str, GetLastError());
2454 static void compare_menu_data(HMENU hmenu, const struct menu_data *item, INT item_count)
2459 count = GetMenuItemCount(hmenu);
2460 ok(count == item_count, "expected %d, got %d menu items\n", count, item_count);
2462 for (i = 0; i < count; i++)
2467 memset(&mii, 0, sizeof(mii));
2468 mii.cbSize = sizeof(mii);
2469 mii.dwTypeData = buf;
2470 mii.cch = sizeof(buf);
2471 mii.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_BITMAP;
2472 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2473 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2475 trace("item #%u: fType %04x, fState %04x, wID %04x, hbmp %p\n",
2476 i, mii.fType, mii.fState, mii.wID, mii.hbmpItem);
2478 ok(mii.fType == item[i].type,
2479 "%u: expected fType %04x, got %04x\n", i, item[i].type, mii.fType);
2480 ok(mii.wID == item[i].id,
2481 "%u: expected wID %04x, got %04x\n", i, item[i].id, mii.wID);
2482 if (item[i].type & (MF_BITMAP | MF_SEPARATOR))
2484 /* For some reason Windows sets high word to not 0 for
2487 ok(LOWORD(mii.hbmpItem) == LOWORD(item[i].str),
2488 "%u: expected hbmpItem %p, got %p\n", i, item[i].str, mii.hbmpItem);
2492 ok(mii.cch == strlen(item[i].str),
2493 "%u: expected cch %u, got %u\n", i, (UINT)strlen(item[i].str), mii.cch);
2494 ok(!strcmp(mii.dwTypeData, item[i].str),
2495 "%u: expected dwTypeData %s, got %s\n", i, item[i].str, (LPCSTR)mii.dwTypeData);
2500 static void test_InsertMenu(void)
2502 /* Note: XP treats only bitmap handles 1 - 6 as "magic" ones
2503 * regardless of their id.
2505 static const struct menu_data in1[] =
2507 { MF_STRING, 1, "File" },
2508 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) },
2509 { MF_STRING|MF_HELP, 2, "Help" }
2511 static const struct menu_data out1[] =
2513 { MF_STRING, 1, "File" },
2514 { MF_STRING|MF_HELP, 2, "Help" },
2515 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) }
2517 static const struct menu_data in2[] =
2519 { MF_STRING, 1, "File" },
2520 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(100) },
2521 { MF_STRING|MF_HELP, 2, "Help" }
2523 static const struct menu_data out2[] =
2525 { MF_STRING, 1, "File" },
2526 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(100) },
2527 { MF_STRING|MF_HELP, 2, "Help" }
2529 static const struct menu_data in3[] =
2531 { MF_STRING, 1, "File" },
2532 { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) },
2533 { MF_STRING|MF_HELP, 2, "Help" }
2535 static const struct menu_data out3[] =
2537 { MF_STRING, 1, "File" },
2538 { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(0) },
2539 { MF_STRING|MF_HELP, 2, "Help" },
2541 static const struct menu_data in4[] =
2543 { MF_STRING, 1, "File" },
2544 { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCE(1) },
2545 { MF_STRING|MF_HELP, 2, "Help" }
2547 static const struct menu_data out4[] =
2549 { MF_STRING, 1, "File" },
2550 { MF_STRING|MF_HELP, 2, "Help" },
2551 { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCE(1) }
2555 #define create_menu(a) create_menu_from_data((a), sizeof(a)/sizeof((a)[0]))
2556 #define compare_menu(h, a) compare_menu_data((h), (a), sizeof(a)/sizeof((a)[0]))
2558 hmenu = create_menu(in1);
2559 compare_menu(hmenu, out1);
2562 hmenu = create_menu(in2);
2563 compare_menu(hmenu, out2);
2566 hmenu = create_menu(in3);
2567 compare_menu(hmenu, out3);
2570 hmenu = create_menu(in4);
2571 compare_menu(hmenu, out4);
2578 static void test_menu_getmenuinfo(void)
2586 hmenu = CreateMenu();
2588 /* test some parameter errors */
2589 SetLastError(0xdeadbeef);
2590 ret = pGetMenuInfo( hmenu, NULL);
2591 gle= GetLastError();
2592 ok( !ret, "GetMenuInfo() should have failed\n");
2593 ok( gle == ERROR_INVALID_PARAMETER ||
2594 broken(gle == 0xdeadbeef), /* Win98, WinME */
2595 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2596 SetLastError(0xdeadbeef);
2598 ret = pGetMenuInfo( hmenu, &mi);
2599 gle= GetLastError();
2600 ok( !ret, "GetMenuInfo() should have failed\n");
2601 ok( gle == ERROR_INVALID_PARAMETER ||
2602 broken(gle == 0xdeadbeef), /* Win98, WinME */
2603 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2604 SetLastError(0xdeadbeef);
2605 mi.cbSize = sizeof( MENUINFO);
2606 ret = pGetMenuInfo( hmenu, &mi);
2607 gle= GetLastError();
2608 ok( ret, "GetMenuInfo() should have succeeded\n");
2609 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2610 SetLastError(0xdeadbeef);
2612 ret = pGetMenuInfo( NULL, &mi);
2613 gle= GetLastError();
2614 ok( !ret, "GetMenuInfo() should have failed\n");
2615 ok( gle == ERROR_INVALID_PARAMETER ||
2616 broken(gle == 0xdeadbeef), /* Win98, WinME */
2617 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2619 DestroyMenu( hmenu);
2623 static void test_menu_setmenuinfo(void)
2625 HMENU hmenu, hsubmenu;
2627 MENUITEMINFOA mii = {sizeof( MENUITEMINFOA)};
2631 /* create a menu with a submenu */
2632 hmenu = CreateMenu();
2633 hsubmenu = CreateMenu();
2634 assert( hmenu && hsubmenu);
2635 mii.fMask = MIIM_SUBMENU;
2636 mii.hSubMenu = hsubmenu;
2637 ret = InsertMenuItem( hmenu, 0, FALSE, &mii);
2638 ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
2639 /* test some parameter errors */
2640 SetLastError(0xdeadbeef);
2641 ret = pSetMenuInfo( hmenu, NULL);
2642 gle= GetLastError();
2643 ok( !ret, "SetMenuInfo() should have failed\n");
2644 ok( gle == ERROR_INVALID_PARAMETER ||
2645 broken(gle == 0xdeadbeef), /* Win98, WinME */
2646 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2647 SetLastError(0xdeadbeef);
2649 ret = pSetMenuInfo( hmenu, &mi);
2650 gle= GetLastError();
2651 ok( !ret, "SetMenuInfo() should have failed\n");
2652 ok( gle == ERROR_INVALID_PARAMETER ||
2653 broken(gle == 0xdeadbeef), /* Win98, WinME */
2654 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2655 SetLastError(0xdeadbeef);
2656 mi.cbSize = sizeof( MENUINFO);
2657 ret = pSetMenuInfo( hmenu, &mi);
2658 gle= GetLastError();
2659 ok( ret, "SetMenuInfo() should have succeeded\n");
2660 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2661 SetLastError(0xdeadbeef);
2663 ret = pSetMenuInfo( NULL, &mi);
2664 gle= GetLastError();
2665 ok( !ret, "SetMenuInfo() should have failed\n");
2666 ok( gle == ERROR_INVALID_PARAMETER ||
2667 broken(gle == 0xdeadbeef), /* Win98, WinME */
2668 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2669 /* functional tests */
2670 /* menu and submenu should have the CHECKORBMP style bit cleared */
2671 SetLastError(0xdeadbeef);
2672 mi.cbSize = sizeof( MENUINFO);
2673 mi.fMask = MIM_STYLE;
2674 ret = pGetMenuInfo( hmenu, &mi);
2675 gle= GetLastError();
2676 ok( ret, "GetMenuInfo() should have succeeded\n");
2677 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2678 ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2679 SetLastError(0xdeadbeef);
2680 mi.cbSize = sizeof( MENUINFO);
2681 mi.fMask = MIM_STYLE;
2682 ret = pGetMenuInfo( hsubmenu, &mi);
2683 gle= GetLastError();
2684 ok( ret, "GetMenuInfo() should have succeeded\n");
2685 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2686 ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2688 SetLastError(0xdeadbeef);
2689 mi.cbSize = sizeof( MENUINFO);
2690 mi.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS;
2691 mi.dwStyle = MNS_CHECKORBMP;
2692 ret = pSetMenuInfo( hmenu, &mi);
2693 gle= GetLastError();
2694 ok( ret, "SetMenuInfo() should have succeeded\n");
2695 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2696 /* Now both menus should have the MNS_CHECKORBMP style bit set */
2697 SetLastError(0xdeadbeef);
2698 mi.cbSize = sizeof( MENUINFO);
2699 mi.fMask = MIM_STYLE;
2700 ret = pGetMenuInfo( hmenu, &mi);
2701 gle= GetLastError();
2702 ok( ret, "GetMenuInfo() should have succeeded\n");
2703 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2704 ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2705 SetLastError(0xdeadbeef);
2706 mi.cbSize = sizeof( MENUINFO);
2707 mi.fMask = MIM_STYLE;
2708 ret = pGetMenuInfo( hsubmenu, &mi);
2709 gle= GetLastError();
2710 ok( ret, "GetMenuInfo() should have succeeded\n");
2711 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2712 ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2713 /* now repeat that without the APPLYTOSUBMENUS flag and another style bit */
2714 SetLastError(0xdeadbeef);
2715 mi.cbSize = sizeof( MENUINFO);
2716 mi.fMask = MIM_STYLE ;
2717 mi.dwStyle = MNS_NOCHECK;
2718 ret = pSetMenuInfo( hmenu, &mi);
2719 gle= GetLastError();
2720 ok( ret, "SetMenuInfo() should have succeeded\n");
2721 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2722 /* Now only the top menu should have the MNS_NOCHECK style bit set */
2723 SetLastError(0xdeadbeef);
2724 mi.cbSize = sizeof( MENUINFO);
2725 mi.fMask = MIM_STYLE;
2726 ret = pGetMenuInfo( hmenu, &mi);
2727 gle= GetLastError();
2728 ok( ret, "GetMenuInfo() should have succeeded\n");
2729 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2730 ok( mi.dwStyle & MNS_NOCHECK, "menustyle was expected to have the MNS_NOCHECK flag\n");
2731 SetLastError(0xdeadbeef);
2732 mi.cbSize = sizeof( MENUINFO);
2733 mi.fMask = MIM_STYLE;
2734 ret = pGetMenuInfo( hsubmenu, &mi);
2735 gle= GetLastError();
2736 ok( ret, "GetMenuInfo() should have succeeded\n");
2737 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2738 ok( !(mi.dwStyle & MNS_NOCHECK), "menustyle was not expected to have the MNS_NOCHECK flag\n");
2740 DestroyMenu( hsubmenu);
2741 DestroyMenu( hmenu);
2745 /* little func to easy switch either TrackPopupMenu() or TrackPopupMenuEx() */
2746 static DWORD MyTrackPopupMenu( int ex, HMENU hmenu, UINT flags, INT x, INT y, HWND hwnd, LPTPMPARAMS ptpm)
2749 ? TrackPopupMenuEx( hmenu, flags, x, y, hwnd, ptpm)
2750 : TrackPopupMenu( hmenu, flags, x, y, 0, hwnd, NULL);
2753 /* some TrackPopupMenu and TrackPopupMenuEx tests */
2754 /* the LastError values differ between NO_ERROR and invalid handle */
2755 /* between all windows versions tested. The first value is that valid on XP */
2756 /* Vista was the only that made returned different error values */
2757 /* between the TrackPopupMenu and TrackPopupMenuEx functions */
2758 static void test_menu_trackpopupmenu(void)
2764 HWND hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
2765 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
2766 NULL, NULL, NULL, NULL);
2767 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
2769 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
2770 for( Ex = 0; Ex < 2; Ex++)
2772 hmenu = CreatePopupMenu();
2773 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
2776 DestroyWindow(hwnd);
2779 /* display the menu */
2780 /* start with an invalid menu handle */
2782 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2783 ret = MyTrackPopupMenu( Ex, NULL, 0x100, 100,100, hwnd, NULL);
2784 gle = GetLastError();
2785 ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
2786 ok( gle == ERROR_INVALID_MENU_HANDLE
2787 || broken (gle == 0xdeadbeef) /* win95 */
2788 || broken (gle == NO_ERROR) /* win98/ME */
2789 ,"TrackPopupMenu%s error got %u expected %u\n",
2790 Ex ? "Ex" : "", gle, ERROR_INVALID_MENU_HANDLE);
2791 ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
2792 "got unexpected message(s)%s%s%s\n",
2793 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2794 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2795 gflag_initmenu ? "WM_INITMENU": "");
2796 /* another one but not NULL */
2798 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2799 ret = MyTrackPopupMenu( Ex, (HMENU)hwnd, 0x100, 100,100, hwnd, NULL);
2800 gle = GetLastError();
2801 ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
2802 ok( gle == ERROR_INVALID_MENU_HANDLE
2803 || broken (gle == 0xdeadbeef) /* win95 */
2804 || broken (gle == NO_ERROR) /* win98/ME */
2805 ,"TrackPopupMenu%s error got %u expected %u\n",
2806 Ex ? "Ex" : "", gle, ERROR_INVALID_MENU_HANDLE);
2807 ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
2808 "got unexpected message(s)%s%s%s\n",
2809 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2810 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2811 gflag_initmenu ? "WM_INITMENU": "");
2812 /* now a somewhat successful call */
2814 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2815 ret = MyTrackPopupMenu( Ex, hmenu, 0x100, 100,100, hwnd, NULL);
2816 gle = GetLastError();
2817 ok( ret == 0, "TrackPopupMenu%s returned %d expected zero\n", Ex ? "Ex" : "", ret);
2819 || gle == ERROR_INVALID_MENU_HANDLE /* NT4, win2k */
2820 || broken (gle == 0xdeadbeef) /* win95 */
2821 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
2822 Ex ? "Ex" : "", gle, NO_ERROR, ERROR_INVALID_MENU_HANDLE);
2823 ok( gflag_initmenupopup && gflag_entermenuloop && gflag_initmenu,
2824 "missed expected message(s)%s%s%s\n",
2825 !gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2826 !gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2827 !gflag_initmenu ? "WM_INITMENU": "");
2829 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest");
2830 ok( ret, "AppendMenA has failed!\n");
2832 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2833 ret = MyTrackPopupMenu( Ex, hmenu, 0x100, 100,100, hwnd, NULL);
2834 gle = GetLastError();
2835 ok( ret == 0, "TrackPopupMenu%s returned %d expected zero\n", Ex ? "Ex" : "", ret);
2837 || gle == ERROR_INVALID_MENU_HANDLE /* NT4, win2k and Vista in the TrackPopupMenuEx case */
2838 || broken (gle == 0xdeadbeef) /* win95 */
2839 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
2840 Ex ? "Ex" : "", gle, NO_ERROR, ERROR_INVALID_MENU_HANDLE);
2841 ok( gflag_initmenupopup && gflag_entermenuloop && gflag_initmenu,
2842 "missed expected message(s)%s%s%s\n",
2843 !gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2844 !gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2845 !gflag_initmenu ? "WM_INITMENU": "");
2849 DestroyWindow(hwnd);
2852 /* test handling of WM_CANCELMODE messages */
2853 static int g_got_enteridle;
2854 static HWND g_hwndtosend;
2855 static LRESULT WINAPI menu_cancelmode_wnd_proc(HWND hwnd, UINT msg,
2856 WPARAM wparam, LPARAM lparam)
2860 case WM_ENTERMENULOOP:
2861 g_got_enteridle = 0;
2862 return SendMessage( g_hwndtosend, WM_CANCELMODE, 0, 0);
2865 if( g_got_enteridle++ == 0) {
2866 /* little hack to get another WM_ENTERIDLE message */
2867 PostMessage( hwnd, WM_MOUSEMOVE, 0, 0);
2868 return SendMessage( g_hwndtosend, WM_CANCELMODE, 0, 0);
2874 return DefWindowProc( hwnd, msg, wparam, lparam);
2877 static void test_menu_cancelmode(void)
2880 HWND hwnd, hwndchild;
2882 if( !pEndMenu) { /* win95 */
2883 win_skip( "EndMenu is not available\n");
2886 hwnd = CreateWindowEx( 0, MAKEINTATOM(atomMenuCheckClass), NULL,
2887 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
2888 NULL, NULL, NULL, NULL);
2889 hwndchild = CreateWindowEx( 0, MAKEINTATOM(atomMenuCheckClass), NULL,
2890 WS_VISIBLE | WS_CHILD, 10, 10, 20, 20,
2891 hwnd, NULL, NULL, NULL);
2892 ok( hwnd != NULL && hwndchild != NULL,
2893 "CreateWindowEx failed with error %d\n", GetLastError());
2894 g_hwndtosend = hwnd;
2895 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_cancelmode_wnd_proc);
2896 SetWindowLongPtr( hwndchild, GWLP_WNDPROC, (LONG_PTR)menu_cancelmode_wnd_proc);
2897 menu = CreatePopupMenu();
2898 ok( menu != NULL, "CreatePopupMenu failed with error %d\n", GetLastError());
2899 ret = AppendMenuA( menu, MF_STRING, 1, "winetest");
2900 ok( ret, "Functie failed lasterror is %u\n", GetLastError());
2901 /* seems to be needed only on wine :( */
2902 {MSG msg; while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);}
2903 /* test the effect of sending a WM_CANCELMODE message in the WM_INITMENULOOP
2904 * handler of the menu owner */
2905 /* test results is exctracted from variable g_got_enteridle. Possible values:
2906 * 0 : complete conformance. Sending WM_CANCELMODE cancels a menu initializing tracking
2907 * 1 : Sending WM_CANCELMODE cancels a menu that is in tracking state
2908 * 2 : Sending WM_CANCELMODE does not work
2910 /* menu owner is top level window */
2911 g_hwndtosend = hwnd;
2912 ret = TrackPopupMenu( menu, 0x100, 100,100, 0, hwnd, NULL);
2914 ok( g_got_enteridle == 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle);
2916 ok( g_got_enteridle < 2, "received %d WM_ENTERIDLE messages, should be less than 2\n", g_got_enteridle);
2917 /* menu owner is child window */
2918 g_hwndtosend = hwndchild;
2919 ret = TrackPopupMenu( menu, 0x100, 100,100, 0, hwndchild, NULL);
2921 ok(g_got_enteridle == 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle);
2923 ok(g_got_enteridle < 2, "received %d WM_ENTERIDLE messages, should be less than 2\n", g_got_enteridle);
2924 /* now send the WM_CANCELMODE messages to the WRONG window */
2925 /* those should fail ( to have any effect) */
2926 g_hwndtosend = hwnd;
2927 ret = TrackPopupMenu( menu, 0x100, 100,100, 0, hwndchild, NULL);
2928 ok( g_got_enteridle == 2, "received %d WM_ENTERIDLE messages, should be 2\n", g_got_enteridle);
2931 DestroyWindow( hwndchild);
2932 DestroyWindow( hwnd);
2937 init_function_pointers();
2939 /* Wine defines MENUITEMINFO for W2K and above. NT4 and below can't
2942 if (correct_behavior())
2944 test_menu_add_string();
2945 test_menu_iteminfo();
2946 test_menu_search_bycommand();
2947 test_CheckMenuRadioItem();
2948 test_menu_resource_layout();
2952 register_menu_check_class();
2954 test_menu_locked_by_window();
2955 test_subpopup_locked_by_menu();
2956 test_menu_ownerdraw();
2957 test_menu_bmp_and_string();
2958 /* test Get/SetMenuInfo if available */
2959 if( pGetMenuInfo && pSetMenuInfo) {
2960 test_menu_getmenuinfo();
2961 test_menu_setmenuinfo();
2963 win_skip("Get/SetMenuInfo are not available\n");
2965 win_skip("SendInput is not available\n");
2970 test_menu_hilitemenuitem();
2971 test_menu_trackpopupmenu();
2972 test_menu_cancelmode();