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)
153 static HMENU hmenupopup;
156 case WM_INITMENUPOPUP:
157 gflag_initmenupopup++;
158 hmenupopup = (HMENU) wparam;
160 case WM_ENTERMENULOOP:
161 gflag_entermenuloop++;
168 MEASUREITEMSTRUCT* pmis = (MEASUREITEMSTRUCT*)lparam;
170 trace("WM_MEASUREITEM received data %lx size %dx%d\n",
171 pmis->itemData, pmis->itemWidth, pmis->itemHeight);
172 MOD_odheight = pmis->itemHeight;
173 pmis->itemWidth = MODsizes[pmis->itemData].cx;
174 pmis->itemHeight = MODsizes[pmis->itemData].cy;
179 DRAWITEMSTRUCT * pdis;
182 char chrs[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
185 pdis = (DRAWITEMSTRUCT *) lparam;
186 if( winetest_debug) {
188 GetMenuItemRect( hwnd, (HMENU)pdis->hwndItem, pdis->itemData ,&rc);
189 trace("WM_DRAWITEM received hwnd %p hmenu %p itemdata %ld item %d rc %d,%d-%d,%d itemrc: %d,%d-%d,%d\n",
190 hwnd, pdis->hwndItem, pdis->itemData, pdis->itemID,
191 pdis->rcItem.left, pdis->rcItem.top,
192 pdis->rcItem.right,pdis->rcItem.bottom,
193 rc.left,rc.top,rc.right,rc.bottom);
194 oldpen=SelectObject( pdis->hDC, GetStockObject(
195 pdis->itemState & ODS_SELECTED ? WHITE_PEN :BLACK_PEN));
196 Rectangle( pdis->hDC, pdis->rcItem.left,pdis->rcItem.top,
197 pdis->rcItem.right,pdis->rcItem.bottom );
198 SelectObject( pdis->hDC, oldpen);
200 /* calculate widths of some menu texts */
201 if( ! MOD_txtsizes[0].size.cx)
202 for(i = 0; MOD_txtsizes[i].text; i++) {
205 strcpy( buf, MOD_txtsizes[i].text);
206 if( ( p = strchr( buf, '\t'))) {
208 DrawText( pdis->hDC, p + 1, -1, &rc,
209 DT_SINGLELINE|DT_CALCRECT);
210 MOD_txtsizes[i].sc_size.cx= rc.right - rc.left;
211 MOD_txtsizes[i].sc_size.cy= rc.bottom - rc.top;
213 DrawText( pdis->hDC, buf, -1, &rc,
214 DT_SINGLELINE|DT_CALCRECT);
215 MOD_txtsizes[i].size.cx= rc.right - rc.left;
216 MOD_txtsizes[i].size.cy= rc.bottom - rc.top;
219 if( pdis->itemData > MOD_maxid) return TRUE;
220 /* store the rectangl */
221 MOD_rc[pdis->itemData] = pdis->rcItem;
222 /* calculate average character width */
223 GetTextExtentPoint( pdis->hDC, chrs, 52, &sz );
224 MOD_avec = (sz.cx + 26)/52;
225 GetTextMetrics( pdis->hDC, &tm);
226 MOD_hic = tm.tmHeight;
227 MOD_GotDrawItemMsg = TRUE;
232 ok( lparam || broken(!lparam), /* win9x, nt4 */
233 "Menu window handle is NULL!\n");
235 HMENU hmenu = (HMENU)SendMessageA( (HWND)lparam, MN_GETHMENU, 0, 0);
236 ok( hmenupopup == hmenu, "MN_GETHMENU returns %p expected %p\n",
239 PostMessage(hwnd, WM_CANCELMODE, 0, 0);
244 return DefWindowProc(hwnd, msg, wparam, lparam);
247 static void register_menu_check_class(void)
255 GetModuleHandle(NULL),
257 LoadCursor(NULL, IDC_ARROW),
258 (HBRUSH)(COLOR_BTNFACE+1),
260 TEXT("WineMenuCheck"),
263 atomMenuCheckClass = RegisterClass(&wc);
266 /* demonstrates that windows locks the menu object so that it is still valid
267 * even after a client calls DestroyMenu on it */
268 static void test_menu_locked_by_window(void)
272 HWND hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
273 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
274 NULL, NULL, NULL, NULL);
275 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
276 hmenu = CreateMenu();
277 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
278 ret = InsertMenu(hmenu, 0, MF_STRING, 0, TEXT("&Test"));
279 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
280 ret = SetMenu(hwnd, hmenu);
281 ok(ret, "SetMenu failed with error %d\n", GetLastError());
282 ret = DestroyMenu(hmenu);
283 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
285 ret = DrawMenuBar(hwnd);
287 ok(ret, "DrawMenuBar failed with error %d\n", GetLastError());
289 ret = IsMenu(GetMenu(hwnd));
290 ok(!ret || broken(ret) /* nt4 */, "Menu handle should have been destroyed\n");
292 SendMessage(hwnd, WM_SYSCOMMAND, SC_KEYMENU, 0);
293 /* did we process the WM_INITMENU message? */
294 ret = GetWindowLongPtr(hwnd, GWLP_USERDATA);
296 ok(ret, "WM_INITMENU should have been sent\n");
302 /* demonstrates that subpopup's are locked
303 * even after a client calls DestroyMenu on it */
304 static LRESULT WINAPI subpopuplocked_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
310 hwndmenu = GetCapture();
312 PostMessage( hwndmenu, WM_KEYDOWN, VK_DOWN, 0);
313 PostMessage( hwndmenu, WM_KEYDOWN, VK_RIGHT, 0);
314 PostMessage( hwndmenu, WM_KEYDOWN, VK_RETURN, 0);
317 return DefWindowProc(hwnd, msg, wparam, lparam);
320 static void test_subpopup_locked_by_menu(void)
324 HMENU hmenu, hsubmenu;
325 MENUINFO mi = { sizeof( MENUINFO)};
326 MENUITEMINFO mii = { sizeof( MENUITEMINFO)};
328 const int itemid = 0x1234567;
331 win_skip("GetMenuInfo is not available\n");
334 /* create window, popupmenu with one subpopup */
335 hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
336 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
337 NULL, NULL, NULL, NULL);
338 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
339 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR) subpopuplocked_wnd_proc);
340 hmenu = CreatePopupMenu();
341 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
342 hsubmenu = CreatePopupMenu();
343 ok(hsubmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
344 ret = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hsubmenu,
345 TEXT("PopUpLockTest"));
346 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
347 ret = InsertMenu(hsubmenu, 0, MF_BYPOSITION | MF_STRING, itemid, TEXT("PopUpMenu"));
348 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
349 /* first some tests that all this functions properly */
350 mii.fMask = MIIM_SUBMENU;
351 ret = GetMenuItemInfo( hmenu, 0, TRUE, &mii);
352 ok( ret, "GetMenuItemInfo failed error %d\n", GetLastError());
353 ok( mii.hSubMenu == hsubmenu, "submenu is %p\n", mii.hSubMenu);
354 mi.fMask |= MIM_STYLE;
355 ret = pGetMenuInfo( hsubmenu, &mi);
356 ok( ret , "GetMenuInfo returned 0 with error %d\n", GetLastError());
357 ret = IsMenu( hsubmenu);
358 ok( ret , "Menu handle is not valid\n");
359 SetLastError( 0xdeadbeef);
360 ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
361 if( ret == (itemid & 0xffff)) {
362 win_skip("not on 16 bit menu subsystem\n");
363 DestroyMenu( hsubmenu);
365 gle = GetLastError();
366 ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, gle);
368 broken( gle == 0xdeadbeef), /* win2k0 */
369 "Last error is %d\n", gle);
370 /* then destroy the sub-popup */
371 ret = DestroyMenu( hsubmenu);
372 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
373 /* and repeat the tests */
374 mii.fMask = MIIM_SUBMENU;
375 ret = GetMenuItemInfo( hmenu, 0, TRUE, &mii);
376 ok( ret, "GetMenuItemInfo failed error %d\n", GetLastError());
377 /* GetMenuInfo fails now */
378 ok( mii.hSubMenu == hsubmenu, "submenu is %p\n", mii.hSubMenu);
379 mi.fMask |= MIM_STYLE;
380 ret = pGetMenuInfo( hsubmenu, &mi);
381 ok( !ret , "GetMenuInfo should have failed\n");
382 /* IsMenu says it is not */
383 ret = IsMenu( hsubmenu);
384 ok( !ret , "Menu handle should be invalid\n");
385 /* but TrackPopupMenu still works! */
386 SetLastError( 0xdeadbeef);
387 ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
388 gle = GetLastError();
390 ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, gle);
393 broken(gle == 0xdeadbeef) || /* wow64 */
394 broken(gle == ERROR_INVALID_PARAMETER), /* win2k0 */
395 "Last error is %d\n", gle);
402 static void test_menu_ownerdraw(void)
408 HWND hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
409 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
410 NULL, NULL, NULL, NULL);
411 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
413 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
414 hmenu = CreatePopupMenu();
415 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
416 if( !hmenu) { DestroyWindow(hwnd);return;}
418 for( j=0;j<2;j++) /* create columns */
419 for(i=0;i<2;i++) { /* create rows */
420 ret = AppendMenu( hmenu, MF_OWNERDRAW |
421 (i==0 ? MF_MENUBREAK : 0), k, MAKEINTRESOURCE(k));
423 ok( ret, "AppendMenu failed for %d\n", k-1);
426 assert( k <= sizeof(MOD_rc)/sizeof(RECT));
427 /* display the menu */
428 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
430 /* columns have a 4 pixel gap between them */
431 ok( MOD_rc[0].right + 4 == MOD_rc[2].left,
432 "item rectangles are not separated by 4 pixels space\n");
433 /* height should be what the MEASUREITEM message has returned */
434 ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
435 "menu item has wrong height: %d should be %d\n",
436 MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
437 /* no gaps between the rows */
438 ok( MOD_rc[0].bottom - MOD_rc[1].top == 0,
439 "There should not be a space between the rows, gap is %d\n",
440 MOD_rc[0].bottom - MOD_rc[1].top);
441 /* test the correct value of the item height that was sent
442 * by the WM_MEASUREITEM message */
443 ok( MOD_odheight == HIWORD( GetDialogBaseUnits()) || /* WinNT,2k,XP */
444 MOD_odheight == MOD_hic, /* Win95,98,ME */
445 "Wrong height field in MEASUREITEMSTRUCT, expected %d or %d actual %d\n",
446 HIWORD( GetDialogBaseUnits()), MOD_hic, MOD_odheight);
447 /* test what MF_MENUBREAK did at the first position. Also show
448 * that an MF_SEPARATOR is ignored in the height calculation. */
449 leftcol= MOD_rc[0].left;
450 ModifyMenu( hmenu, 0, MF_BYCOMMAND| MF_OWNERDRAW| MF_SEPARATOR, 0, 0);
451 /* display the menu */
452 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
453 /* left should be 4 pixels less now */
454 ok( leftcol == MOD_rc[0].left + 4,
455 "columns should be 4 pixels to the left (actual %d).\n",
456 leftcol - MOD_rc[0].left);
458 ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
459 "width of owner drawn menu item is wrong. Got %d expected %d\n",
460 MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
462 ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
463 "Height is incorrect. Got %d expected %d\n",
464 MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
466 /* test width/height of an ownerdraw menu bar as well */
467 ret = DestroyMenu(hmenu);
468 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
469 hmenu = CreateMenu();
470 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
471 if( !hmenu) { DestroyWindow(hwnd);return;}
474 ret = AppendMenu( hmenu, MF_OWNERDRAW , i, 0);
475 ok( ret, "AppendMenu failed for %d\n", i);
477 ret = SetMenu( hwnd, hmenu);
478 UpdateWindow( hwnd); /* hack for wine to draw the window + menu */
479 ok(ret, "SetMenu failed with error %d\n", GetLastError());
481 ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
482 "width of owner drawn menu item is wrong. Got %d expected %d\n",
483 MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
485 ok( MOD_rc[0].bottom - MOD_rc[0].top == GetSystemMetrics( SM_CYMENU) - 1,
486 "Height of owner drawn menu item is wrong. Got %d expected %d\n",
487 MOD_rc[0].bottom - MOD_rc[0].top, GetSystemMetrics( SM_CYMENU) - 1);
490 ret = DestroyMenu(hmenu);
491 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
495 /* helper for test_menu_bmp_and_string() */
496 static void test_mbs_help( int ispop, int hassub, int mnuopt,
497 HWND hwnd, int arrowwidth, int count, HBITMAP hbmp,
498 SIZE bmpsize, LPCSTR text, SIZE size, SIZE sc_size)
501 HMENU hmenu, submenu;
502 MENUITEMINFO mii={ sizeof( MENUITEMINFO )};
509 MOD_GotDrawItemMsg = FALSE;
510 mii.fMask = MIIM_FTYPE | MIIM_DATA | MIIM_STATE;
512 /* check the menu item unless MNS_CHECKORBMP is set */
513 mii.fState = (mnuopt != 2 ? MFS_CHECKED : MFS_UNCHECKED);
515 MODsizes[0] = bmpsize;
519 mii.fMask |= MIIM_STRING;
520 strcpy(text_copy, text);
521 mii.dwTypeData = text_copy; /* structure member declared non-const */
522 if( ( p = strchr( text, '\t'))) {
523 hastab = *(p + 1) ? 2 : 1;
526 /* tabs don't make sense in menubars */
527 if(hastab && !ispop) return;
529 mii.fMask |= MIIM_BITMAP;
532 submenu = CreateMenu();
533 ok( submenu != 0, "CreateMenu failed with error %d\n", GetLastError());
535 hmenu = CreatePopupMenu();
537 hmenu = CreateMenu();
538 ok( hmenu != 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
540 mii.fMask |= MIIM_SUBMENU;
541 mii.hSubMenu = submenu;
544 mi.cbSize = sizeof(mi);
545 mi.fMask = MIM_STYLE;
546 pGetMenuInfo( hmenu, &mi);
547 if( mnuopt) mi.dwStyle |= mnuopt == 1 ? MNS_NOCHECK : MNS_CHECKORBMP;
548 ret = pSetMenuInfo( hmenu, &mi);
549 ok( ret, "SetMenuInfo failed with error %d\n", GetLastError());
551 ret = InsertMenuItem( hmenu, 0, FALSE, &mii);
552 ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
554 if( winetest_debug) {
556 RECT rc = {100, 50, 400, 70};
559 sprintf( buf,"%d text \"%s\" mnuopt %d", count, text ? text: "(nil)", mnuopt);
560 FillRect( hdc, &rc, (HBRUSH) COLOR_WINDOW);
561 TextOut( hdc, 10, 50, buf, strlen( buf));
562 ReleaseDC( hwnd, hdc);
565 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
567 ret = SetMenu( hwnd, hmenu);
568 ok(ret, "SetMenu failed with error %d\n", GetLastError());
571 ret = GetMenuItemRect( hwnd, hmenu, 0, &rc);
572 ok(ret, "GetMenuItemRect failed with error %d\n", GetLastError());
574 if (0) /* comment out menu size checks, behavior is different in almost every Windows version */
575 /* the tests should however succeed on win2000, XP and Wine (at least up to 1.1.15) */
576 /* with a variety of dpis and desktop font sizes */
578 /* check menu width */
580 expect = ( text || hbmp ?
581 4 + (mnuopt != 1 ? GetSystemMetrics(SM_CXMENUCHECK) : 0)
583 arrowwidth + MOD_avec + (hbmp ?
584 ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ? bmpsize.cx + 2 : GetSystemMetrics( SM_CXMENUSIZE) + 2)
586 (text && hastab ? /* TAB space */
587 MOD_avec + ( hastab==2 ? sc_size.cx : 0) : 0) +
588 (text ? 2 + (text[0] ? size.cx :0): 0) ;
590 expect = !(text || hbmp) ? 0 :
591 ( hbmp ? (text ? 2:0) + bmpsize.cx : 0 ) +
592 (text ? 2 * MOD_avec + (text[0] ? size.cx :0): 0) ;
593 ok( rc.right - rc.left == expect,
594 "menu width wrong, got %d expected %d\n", rc.right - rc.left, expect);
595 failed = failed || !(rc.right - rc.left == expect);
596 /* check menu height */
598 expect = max( ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 : 0),
599 max( (text ? max( 2 + size.cy, MOD_hic + 4) : 0),
601 ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ?
603 : GetSystemMetrics( SM_CYMENUSIZE) + 2)
606 expect = ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 :
607 max( GetSystemMetrics( SM_CYMENU) - 1, (hbmp ? bmpsize.cy : 0)));
608 ok( rc.bottom - rc.top == expect,
609 "menu height wrong, got %d expected %d (%d)\n",
610 rc.bottom - rc.top, expect, GetSystemMetrics( SM_CYMENU));
611 failed = failed || !(rc.bottom - rc.top == expect);
612 if( hbmp == HBMMENU_CALLBACK && MOD_GotDrawItemMsg) {
613 /* check the position of the bitmap */
617 else if (mnuopt == 0)
618 expect = 4 + GetSystemMetrics(SM_CXMENUCHECK);
619 else if (mnuopt == 1)
621 else /* mnuopt == 2 */
623 ok( expect == MOD_rc[0].left,
624 "bitmap left is %d expected %d\n", MOD_rc[0].left, expect);
625 failed = failed || !(expect == MOD_rc[0].left);
627 expect = (rc.bottom - rc.top - MOD_rc[0].bottom + MOD_rc[0].top) / 2;
628 ok( expect == MOD_rc[0].top,
629 "bitmap top is %d expected %d\n", MOD_rc[0].top, expect);
630 failed = failed || !(expect == MOD_rc[0].top);
633 /* if there was a failure, report details */
635 trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
636 count, (ispop? "POPUP": "MENUBAR"),text ? text: "(nil)", hbmp, bmpsize.cx, bmpsize.cy,
637 size.cx, size.cy, sc_size.cx, mnuopt, hastab);
638 trace(" check %d,%d arrow %d avechar %d\n",
639 GetSystemMetrics(SM_CXMENUCHECK ),
640 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
641 if( hbmp == HBMMENU_CALLBACK)
642 trace( " rc %d,%d-%d,%d bmp.rc %d,%d-%d,%d\n",
643 rc.left, rc.top, rc.top, rc.bottom, MOD_rc[0].left,
644 MOD_rc[0].top,MOD_rc[0].right, MOD_rc[0].bottom);
647 ret = DestroyMenu(submenu);
648 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
649 ret = DestroyMenu(hmenu);
650 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
654 static void test_menu_bmp_and_string(void)
662 MENUINFO mi= {sizeof(MENUINFO)};
663 MENUITEMINFOA mii= {sizeof(MENUITEMINFOA)};
664 int count, szidx, txtidx, bmpidx, hassub, mnuopt, ispop;
669 win_skip("GetMenuInfo is not available\n");
673 memset( bmfill, 0xcc, sizeof( bmfill));
674 hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL, WS_SYSMENU |
675 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
676 NULL, NULL, NULL, NULL);
677 hbm_arrow=LoadBitmap( 0, (CHAR*)OBM_MNARROW);
678 GetObject( hbm_arrow, sizeof(bm), &bm);
679 arrowwidth = bm.bmWidth;
680 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
682 /* test system menu */
683 hsysmenu = GetSystemMenu( hwnd, FALSE);
684 ok( hsysmenu != NULL, "GetSystemMenu failed with error %d\n", GetLastError());
685 mi.fMask = MIM_STYLE;
687 got = pGetMenuInfo( hsysmenu, &mi);
688 ok( got, "GetMenuInfo failed gle=%d\n", GetLastError());
689 ok( MNS_CHECKORBMP == mi.dwStyle, "System Menu Style is %08x, without the bit %08x\n",
690 mi.dwStyle, MNS_CHECKORBMP);
691 mii.fMask = MIIM_BITMAP;
693 got = GetMenuItemInfoA( hsysmenu, SC_CLOSE, FALSE, &mii);
694 ok( got, "GetMenuItemInfoA failed gle=%d\n", GetLastError());
695 ok( HBMMENU_POPUP_CLOSE == mii.hbmpItem, "Item info did not get the right hbitmap: got %p expected %p\n",
696 mii.hbmpItem, HBMMENU_POPUP_CLOSE);
698 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
701 trace(" check %d,%d arrow %d avechar %d\n",
702 GetSystemMetrics(SM_CXMENUCHECK ),
703 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
706 for( ispop=1; ispop >= 0; ispop--){
707 static SIZE bmsizes[]= {
708 {10,10},{38,38},{1,30},{55,5}};
709 for( szidx=0; szidx < sizeof( bmsizes) / sizeof( SIZE); szidx++) {
710 HBITMAP hbm = CreateBitmap( bmsizes[szidx].cx, bmsizes[szidx].cy,1,1,bmfill);
711 HBITMAP bitmaps[] = { HBMMENU_CALLBACK, hbm, HBMMENU_POPUP_CLOSE, NULL };
712 ok( hbm != 0, "CreateBitmap failed err %d\n", GetLastError());
713 for( txtidx = 0; txtidx < sizeof(MOD_txtsizes)/sizeof(MOD_txtsizes[0]); txtidx++) {
714 for( hassub = 0; hassub < 2 ; hassub++) { /* add submenu item */
715 for( mnuopt = 0; mnuopt < 3 ; mnuopt++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
716 for( bmpidx = 0; bmpidx <sizeof(bitmaps)/sizeof(HBITMAP); bmpidx++) {
717 /* no need to test NULL bitmaps of several sizes */
718 if( !bitmaps[bmpidx] && szidx > 0) continue;
719 /* the HBMMENU_POPUP not to test for menu bars */
721 bitmaps[bmpidx] >= HBMMENU_POPUP_CLOSE &&
722 bitmaps[bmpidx] <= HBMMENU_POPUP_MINIMIZE) continue;
723 if( !ispop && hassub) continue;
724 test_mbs_help( ispop, hassub, mnuopt,
725 hwnd, arrowwidth, ++count,
728 MOD_txtsizes[txtidx].text,
729 MOD_txtsizes[txtidx].size,
730 MOD_txtsizes[txtidx].sc_size);
742 static void test_menu_add_string( void )
753 WCHAR strbackW[0x80];
754 static CHAR blah[] = "blah";
755 static const WCHAR expectedString[] = {'D','u','m','m','y',' ','s','t','r','i','n','g', 0};
757 hmenu = CreateMenu();
759 memset( &info, 0, sizeof info );
760 info.cbSize = sizeof info;
761 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_ID;
762 info.dwTypeData = blah;
767 InsertMenuItem(hmenu, 0, TRUE, &info );
769 memset( &info, 0, sizeof info );
770 info.cbSize = sizeof info;
771 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_DATA | MIIM_ID;
772 info.dwTypeData = string;
773 info.cch = sizeof string;
775 GetMenuItemInfo( hmenu, 0, TRUE, &info );
777 ok( !strcmp( string, "blah" ), "menu item name differed\n");
779 /* Test combination of ownerdraw and strings with GetMenuItemString(A/W) */
780 strcpy(string, "Dummy string");
781 memset(&info, 0x00, sizeof(info));
782 info.cbSize= sizeof(MENUITEMINFO);
783 info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
784 info.fType= MFT_OWNERDRAW;
785 info.dwTypeData= string;
786 rc = InsertMenuItem( hmenu, 0, TRUE, &info );
787 ok (rc, "InsertMenuItem failed\n");
789 strcpy(string,"Garbage");
790 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
791 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
793 SetLastError(0xdeadbeef);
794 ret = GetMenuStringW( hmenu, 0, strbackW, 99, MF_BYPOSITION );
795 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
796 win_skip("GetMenuStringW is not implemented\n");
799 ok (ret, "GetMenuStringW on ownerdraw entry failed\n");
800 ok (!lstrcmpW( strbackW, expectedString ), "Menu text from Unicode version incorrect\n");
803 /* Just change ftype to string and see what text is stored */
804 memset(&info, 0x00, sizeof(info));
805 info.cbSize= sizeof(MENUITEMINFO);
806 info.fMask= MIIM_FTYPE; /* Set string type */
807 info.fType= MFT_STRING;
808 info.dwTypeData= (char *)0xdeadbeef;
809 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
810 ok (rc, "SetMenuItemInfo failed\n");
812 /* Did we keep the old dwTypeData? */
813 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
814 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
816 /* Ensure change to bitmap type fails */
817 memset(&info, 0x00, sizeof(info));
818 info.cbSize= sizeof(MENUITEMINFO);
819 info.fMask= MIIM_FTYPE; /* Set as bitmap type */
820 info.fType= MFT_BITMAP;
821 info.dwTypeData= (char *)0xdeadbee2;
822 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
823 ok (!rc, "SetMenuItemInfo unexpectedly worked\n");
825 /* Just change ftype back and ensure data hasn't been freed */
826 info.fType= MFT_OWNERDRAW; /* Set as ownerdraw type */
827 info.dwTypeData= (char *)0xdeadbee3;
828 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
829 ok (rc, "SetMenuItemInfo failed\n");
831 /* Did we keep the old dwTypeData? */
832 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
833 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
835 /* Just change string value (not type) */
836 memset(&info, 0x00, sizeof(info));
837 info.cbSize= sizeof(MENUITEMINFO);
838 info.fMask= MIIM_STRING; /* Set typeData */
839 strcpy(string2, "string2");
840 info.dwTypeData= string2;
841 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
842 ok (rc, "SetMenuItemInfo failed\n");
844 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
845 ok (!strcmp( strback, "string2" ), "Menu text from Ansi version incorrect\n");
847 /* crashes with wine 0.9.5 */
848 memset(&info, 0x00, sizeof(info));
849 info.cbSize= sizeof(MENUITEMINFO);
850 info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
851 info.fType= MFT_OWNERDRAW;
852 rc = InsertMenuItem( hmenu, 0, TRUE, &info );
853 ok (rc, "InsertMenuItem failed\n");
854 ok (!GetMenuString( hmenu, 0, NULL, 0, MF_BYPOSITION),
855 "GetMenuString on ownerdraw entry succeeded.\n");
856 SetLastError(0xdeadbeef);
857 ret = GetMenuStringW( hmenu, 0, NULL, 0, MF_BYPOSITION);
858 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
859 win_skip("GetMenuStringW is not implemented\n");
861 ok (!ret, "GetMenuStringW on ownerdraw entry succeeded.\n");
863 DestroyMenu( hmenu );
866 /* define building blocks for the menu item info tests */
867 static int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
869 if (n <= 0) return 0;
870 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
871 return *str1 - *str2;
874 static WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
877 while ((*p++ = *src++));
881 static void insert_menu_item( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state, UINT id,
882 HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
883 void *type_data, UINT len, HBITMAP item, BOOL expect )
888 /* magic bitmap handle to test smaller cbSize */
889 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
890 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
892 info.cbSize = sizeof(info);
897 info.hSubMenu = submenu;
898 info.hbmpChecked = checked;
899 info.hbmpUnchecked = unchecked;
900 info.dwItemData = data;
901 info.dwTypeData = type_data;
903 info.hbmpItem = item;
904 SetLastError( 0xdeadbeef );
905 if (ansi) ret = InsertMenuItemA( hmenu, 0, TRUE, &info );
906 else ret = InsertMenuItemW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
907 if (!expect) ok_(__FILE__, line)( !ret, "InsertMenuItem should have failed.\n" );
908 else ok_(__FILE__, line)( ret, "InsertMenuItem failed, err %u\n", GetLastError());
911 static void check_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
912 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked,
913 ULONG_PTR data, void *type_data, UINT in_len, UINT out_len,
914 HBITMAP item, LPCSTR expname, BOOL expect, BOOL expstring )
920 SetLastError( 0xdeadbeef );
921 memset( &info, 0xcc, sizeof(info) );
922 info.cbSize = sizeof(info);
924 info.dwTypeData = type_data;
927 ret = ansi ? GetMenuItemInfoA( hmenu, 0, TRUE, &info ) :
928 GetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW *)&info );
931 ok_(__FILE__, line)( !ret, "GetMenuItemInfo should have failed.\n" );
934 ok_(__FILE__, line)( ret, "GetMenuItemInfo failed, err %u\n", GetLastError());
935 if (mask & MIIM_TYPE)
936 ok_(__FILE__, line)( info.fType == type || info.fType == LOWORD(type),
937 "wrong type %x/%x\n", info.fType, type );
938 if (mask & MIIM_STATE)
939 ok_(__FILE__, line)( info.fState == state || info.fState == LOWORD(state),
940 "wrong state %x/%x\n", info.fState, state );
942 ok_(__FILE__, line)( info.wID == id || info.wID == LOWORD(id),
943 "wrong id %x/%x\n", info.wID, id );
944 if (mask & MIIM_SUBMENU)
945 ok_(__FILE__, line)( info.hSubMenu == submenu || (ULONG_PTR)info.hSubMenu == LOWORD(submenu),
946 "wrong submenu %p/%p\n", info.hSubMenu, submenu );
947 if (mask & MIIM_CHECKMARKS)
949 ok_(__FILE__, line)( info.hbmpChecked == checked || (ULONG_PTR)info.hbmpChecked == LOWORD(checked),
950 "wrong bmpchecked %p/%p\n", info.hbmpChecked, checked );
951 ok_(__FILE__, line)( info.hbmpUnchecked == unchecked || (ULONG_PTR)info.hbmpUnchecked == LOWORD(unchecked),
952 "wrong bmpunchecked %p/%p\n", info.hbmpUnchecked, unchecked );
954 if (mask & MIIM_DATA)
955 ok_(__FILE__, line)( info.dwItemData == data || info.dwItemData == LOWORD(data),
956 "wrong item data %lx/%lx\n", info.dwItemData, data );
957 if (mask & MIIM_BITMAP)
958 ok_(__FILE__, line)( info.hbmpItem == item || (ULONG_PTR)info.hbmpItem == LOWORD(item),
959 "wrong bmpitem %p/%p\n", info.hbmpItem, item );
960 ok_(__FILE__, line)( info.dwTypeData == type_data || (ULONG_PTR)info.dwTypeData == LOWORD(type_data),
961 "wrong type data %p/%p\n", info.dwTypeData, type_data );
962 ok_(__FILE__, line)( info.cch == out_len ||
963 broken(! ansi && info.cch == 2 * out_len) /* East-Asian */,
964 "wrong len %x/%x\n", info.cch, out_len );
968 ok_(__FILE__, line)( !strncmp( expname, info.dwTypeData, out_len ),
969 "menu item name differed from '%s' '%s'\n", expname, info.dwTypeData );
971 ok_(__FILE__, line)( !strncmpW( (WCHAR *)expname, (WCHAR *)info.dwTypeData, out_len ),
972 "menu item name wrong\n" );
974 SetLastError( 0xdeadbeef );
975 ret = ansi ? GetMenuStringA( hmenu, 0, (char *)buffer, 80, MF_BYPOSITION ) :
976 GetMenuStringW( hmenu, 0, buffer, 80, MF_BYPOSITION );
978 ok_(__FILE__, line)( ret, "GetMenuString failed, err %u\n", GetLastError());
980 ok_(__FILE__, line)( !ret, "GetMenuString should have failed\n" );
984 static void modify_menu( int line, HMENU hmenu, BOOL ansi, UINT flags, UINT_PTR id, void *data )
988 SetLastError( 0xdeadbeef );
989 if (ansi) ret = ModifyMenuA( hmenu, 0, flags, id, data );
990 else ret = ModifyMenuW( hmenu, 0, flags, id, data );
991 ok_(__FILE__,line)( ret, "ModifyMenuA failed, err %u\n", GetLastError());
994 static void set_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
995 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
996 void *type_data, UINT len, HBITMAP item )
1002 /* magic bitmap handle to test smaller cbSize */
1003 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
1004 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
1006 info.cbSize = sizeof(info);
1009 info.fState = state;
1011 info.hSubMenu = submenu;
1012 info.hbmpChecked = checked;
1013 info.hbmpUnchecked = unchecked;
1014 info.dwItemData = data;
1015 info.dwTypeData = type_data;
1017 info.hbmpItem = item;
1018 SetLastError( 0xdeadbeef );
1019 if (ansi) ret = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1020 else ret = SetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
1021 ok_(__FILE__, line)( ret, "SetMenuItemInfo failed, err %u\n", GetLastError());
1024 #define TMII_INSMI( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,eret1 )\
1025 hmenu = CreateMenu();\
1026 submenu = CreateMenu();\
1027 if(ansi)strcpy( string, init );\
1028 else strcpyW( string, init );\
1029 insert_menu_item( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, eret1 )
1031 /* GetMenuItemInfo + GetMenuString */
1032 #define TMII_GMII( c2,l2,\
1033 d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,\
1034 expname, eret2, eret3)\
1035 check_menu_item_info( __LINE__, hmenu, ansi, c2, d3, e3, f3, g3, h3, i3, j3, k3, l2, l3, m3, \
1036 expname, eret2, eret3 )
1039 RemoveMenu(hmenu, 0, TRUE );\
1040 DestroyMenu( hmenu );\
1041 DestroyMenu( submenu );
1044 #define TMII_MODM( flags, id, data ) \
1045 modify_menu( __LINE__, hmenu, ansi, flags, id, data )
1047 /* SetMenuItemInfo */
1048 #define TMII_SMII( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1 ) \
1049 set_menu_item_info( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1 )
1056 static void test_menu_iteminfo( void )
1062 WCHAR txtW[]={'W','i','n','e',0};
1063 WCHAR initW[]={'X','Y','Z',0};
1065 void *txt, *init, *empty, *string;
1066 HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
1068 HMENU hmenu, submenu=CreateMenu();
1069 HBITMAP dummy_hbm = (HBITMAP)(ULONG_PTR)0xdeadbeef;
1072 if( ansi) {txt=txtA;init=initA;empty=emptyA;string=stringA;}
1073 else {txt=txtW;init=initW;empty=emptyW;string=stringA;}
1074 trace( "%s string %p hbm %p txt %p\n", ansi ? "ANSI tests: " : "Unicode tests:", string, hbm, txt);
1075 /* test all combinations of MFT_STRING, MFT_OWNERDRAW and MFT_BITMAP */
1076 /* (since MFT_STRING is zero, there are four of them) */
1077 TMII_INSMI( MIIM_TYPE, MFT_STRING, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1078 TMII_GMII ( MIIM_TYPE, 80,
1079 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1082 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1083 TMII_GMII ( MIIM_TYPE, 80,
1084 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1087 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1088 TMII_GMII ( MIIM_TYPE, 80,
1089 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1092 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1093 TMII_GMII ( MIIM_TYPE, 80,
1094 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1097 /* not enough space for name*/
1098 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1099 TMII_GMII ( MIIM_TYPE, 0,
1100 MFT_STRING, 0, 0, 0, 0, 0, 0, NULL, 4, 0,
1103 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1104 TMII_GMII ( MIIM_TYPE, 5,
1105 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1108 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1109 TMII_GMII ( MIIM_TYPE, 4,
1110 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 3, 0,
1113 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1114 TMII_GMII ( MIIM_TYPE, 0,
1115 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, 0,
1118 /* cannot combine MIIM_TYPE with some other flags */
1119 TMII_INSMI( MIIM_TYPE|MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1121 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1122 TMII_GMII ( MIIM_TYPE|MIIM_STRING, 80,
1123 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1126 TMII_INSMI( MIIM_TYPE|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1128 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1129 TMII_GMII ( MIIM_TYPE|MIIM_FTYPE, 80,
1130 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1133 TMII_INSMI( MIIM_TYPE|MIIM_BITMAP, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, hbm, ER );
1135 /* but succeeds with some others */
1136 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1137 TMII_GMII ( MIIM_TYPE|MIIM_SUBMENU, 80,
1138 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1141 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1142 TMII_GMII ( MIIM_TYPE|MIIM_STATE, 80,
1143 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1146 TMII_INSMI( MIIM_TYPE|MIIM_ID, MFT_STRING, -1, 888, 0, 0, 0, -1, txt, 6, 0, OK );
1147 TMII_GMII ( MIIM_TYPE|MIIM_ID, 80,
1148 MFT_STRING, 0, 888, 0, 0, 0, 0, string, 4, 0,
1151 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING, -1, -1, 0, 0, 0, 999, txt, 6, 0, OK );
1152 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1153 MFT_STRING, 0, 0, 0, 0, 0, 999, string, 4, 0,
1156 /* to be continued */
1157 /* set text with MIIM_TYPE and retrieve with MIIM_STRING */
1158 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1159 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1160 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1163 /* set text with MIIM_TYPE and retrieve with MIIM_STRING; MFT_OWNERDRAW causes an empty string */
1164 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1165 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1166 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1169 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1170 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1171 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1174 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1175 TMII_GMII ( MIIM_FTYPE, 80,
1176 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, 0,
1179 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1181 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1184 /* contrary to MIIM_TYPE,you can set the text for an owner draw menu */
1185 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1186 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1187 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1190 /* same but retrieve with MIIM_TYPE */
1191 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1192 TMII_GMII ( MIIM_TYPE, 80,
1193 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1196 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1197 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1198 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1201 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1202 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1203 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1207 /* How is that with bitmaps? */
1208 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1209 TMII_GMII ( MIIM_TYPE, 80,
1210 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1213 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1214 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1215 0, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1218 /* MIIM_BITMAP does not like MFT_BITMAP */
1219 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, hbm, ER );
1221 /* no problem with OWNERDRAWN */
1222 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1223 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1224 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1227 /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1228 TMII_INSMI( MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER );
1231 /* menu with submenu */
1232 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1233 TMII_GMII ( MIIM_SUBMENU, 80,
1234 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1237 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, empty, 0, 0, OK );
1238 TMII_GMII ( MIIM_SUBMENU, 80,
1239 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1242 /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1243 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1244 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1245 MFT_STRING|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1247 TMII_GMII ( MIIM_SUBMENU|MIIM_FTYPE, 80,
1248 MFT_SEPARATOR, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1251 /* menu with invalid submenu */
1252 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, (HMENU)999, 0, 0, -1, txt, 0, 0, ER );
1255 TMII_INSMI( MIIM_TYPE, MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1256 TMII_GMII ( MIIM_TYPE, 80,
1257 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1260 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1261 TMII_GMII ( MIIM_TYPE, 80,
1262 MFT_BITMAP|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1265 /* SEPARATOR and STRING go well together */
1266 /* BITMAP and STRING go well together */
1267 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1268 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1269 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1272 /* BITMAP, SEPARATOR and STRING go well together */
1273 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1274 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1275 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1278 /* last two tests, but use MIIM_TYPE to retrieve info */
1279 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1280 TMII_GMII ( MIIM_TYPE, 80,
1281 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1284 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1285 TMII_GMII ( MIIM_TYPE, 80,
1286 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1289 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1290 TMII_GMII ( MIIM_TYPE, 80,
1291 MFT_SEPARATOR|MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1294 /* same three with MFT_OWNERDRAW */
1295 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1296 TMII_GMII ( MIIM_TYPE, 80,
1297 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1300 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1301 TMII_GMII ( MIIM_TYPE, 80,
1302 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1305 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1306 TMII_GMII ( MIIM_TYPE, 80,
1307 MFT_SEPARATOR|MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1311 TMII_INSMI( MIIM_STRING|MIIM_FTYPE|MIIM_ID, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1312 TMII_GMII ( MIIM_TYPE, 80,
1313 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1316 /* test with modifymenu: string is preserved after setting OWNERDRAW */
1317 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1318 TMII_MODM( MFT_OWNERDRAW, -1, (void*)787 );
1319 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_DATA, 80,
1320 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 787, string, 4, 0,
1323 /* same with bitmap: now the text is cleared */
1324 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1325 TMII_MODM( MFT_BITMAP, 545, hbm );
1326 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1327 MFT_BITMAP, 0, 545, 0, 0, 0, 0, string, 0, hbm,
1330 /* start with bitmap: now setting text clears it (though he flag is raised) */
1331 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1332 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1333 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 0, hbm,
1335 TMII_MODM( MFT_STRING, 545, txt );
1336 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1337 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 4, 0,
1340 /*repeat with text NULL */
1341 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1342 TMII_MODM( MFT_STRING, 545, NULL );
1343 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1344 MFT_SEPARATOR, 0, 545, 0, 0, 0, 0, string, 0, 0,
1347 /* repeat with text "" */
1348 TMII_INSMI( MIIM_BITMAP, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1349 TMII_MODM( MFT_STRING, 545, empty );
1350 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1351 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 0, 0,
1354 /* start with bitmap: set ownerdraw */
1355 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1356 TMII_MODM( MFT_OWNERDRAW, -1, (void *)232 );
1357 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_DATA, 80,
1358 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 232, string, 0, hbm,
1362 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1364 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1367 /* some tests with small cbSize: the hbmpItem is to be ignored */
1368 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1369 TMII_GMII ( MIIM_TYPE, 80,
1370 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1373 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1374 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1375 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, NULL,
1378 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1379 TMII_GMII ( MIIM_TYPE, 80,
1380 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, NULL,
1383 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1384 TMII_GMII ( MIIM_TYPE, 80,
1385 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1388 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1389 TMII_GMII ( MIIM_TYPE, 80,
1390 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1393 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1394 TMII_GMII ( MIIM_TYPE, 80,
1395 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1398 /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus */
1399 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1400 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1401 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1404 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1405 TMII_GMII ( MIIM_TYPE, 80,
1406 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1409 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1410 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1411 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1414 /* set a string menu to ownerdraw with MIIM_TYPE */
1415 TMII_INSMI( MIIM_TYPE, MFT_STRING, -2, -2, 0, 0, 0, -2, txt, -2, 0, OK );
1416 TMII_SMII ( MIIM_TYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1417 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1418 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1421 /* test with modifymenu add submenu */
1422 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1423 TMII_MODM( MF_POPUP, (UINT_PTR)submenu, txt );
1424 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_SUBMENU, 80,
1425 MFT_STRING, 0, 0, submenu, 0, 0, 0, string, 4, 0,
1427 TMII_GMII ( MIIM_TYPE, 80,
1428 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1431 /* MFT_SEPARATOR bit is kept when the text is added */
1432 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1433 TMII_SMII( MIIM_STRING, 0, 0, 0, 0, 0, 0, 0, txt, 0, 0 );
1434 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1435 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, 0,
1438 /* MFT_SEPARATOR bit is kept when bitmap is added */
1439 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1440 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm );
1441 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1442 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1445 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1446 Only the low word of the dwTypeData is used.
1447 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1448 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1449 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1450 TMII_GMII ( MIIM_TYPE, 80,
1451 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1455 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1456 TMII_GMII ( MIIM_TYPE, 80,
1457 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1461 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1462 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1463 TMII_GMII ( MIIM_STATE, 80,
1464 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1467 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1468 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1469 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1470 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1471 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1474 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1475 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1476 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1477 TMII_GMII ( MIIM_FTYPE, 80,
1478 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1480 TMII_GMII ( MIIM_TYPE, 80,
1481 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1483 TMII_GMII ( MIIM_FTYPE, 80,
1484 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1486 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1487 TMII_GMII ( MIIM_TYPE, 80,
1488 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1491 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1492 Only the low word of the dwTypeData is used.
1493 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1494 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1495 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1496 TMII_GMII ( MIIM_TYPE, 80,
1497 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1501 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1502 TMII_GMII ( MIIM_TYPE, 80,
1503 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1507 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1508 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1509 TMII_GMII ( MIIM_STATE, 80,
1510 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1513 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1514 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1515 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1516 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1517 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1520 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1521 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1522 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1523 TMII_GMII ( MIIM_FTYPE, 80,
1524 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1526 TMII_GMII ( MIIM_TYPE, 80,
1527 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1529 TMII_GMII ( MIIM_FTYPE, 80,
1530 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1532 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1533 TMII_GMII ( MIIM_TYPE, 80,
1534 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1537 } while( !(ansi = !ansi) );
1542 The following tests try to confirm the algorithm used to return the menu items
1543 when there is a collision between a menu item and a popup menu
1545 static void test_menu_search_bycommand( void )
1547 HMENU hmenu, hmenuSub, hmenuSub2;
1553 static CHAR menuitem[] = "MenuItem",
1554 menuitem2[] = "MenuItem 2";
1556 /* Case 1: Menu containing a menu item */
1557 hmenu = CreateMenu();
1559 memset( &info, 0, sizeof info );
1560 info.cbSize = sizeof info;
1561 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1562 info.fType = MFT_STRING;
1563 strcpy(strIn, "Case 1 MenuItem");
1564 info.dwTypeData = strIn;
1565 info.wID = (UINT) 0x1234;
1567 rc = InsertMenuItem(hmenu, 0, TRUE, &info );
1568 ok (rc, "Inserting the menuitem failed\n");
1570 id = GetMenuItemID(hmenu, 0);
1571 ok (id == 0x1234, "Getting the menuitem id failed(gave %x)\n", id);
1573 /* Confirm the menuitem was given the id supplied (getting by position) */
1574 memset( &info, 0, sizeof info );
1576 info.cbSize = sizeof(MENUITEMINFO);
1577 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1578 info.dwTypeData = strback;
1579 info.cch = sizeof(strback);
1581 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info); /* Get by position */
1582 ok (rc, "Getting the menu items info failed\n");
1583 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1584 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1586 /* Search by id - Should return the item */
1587 memset( &info, 0, sizeof info );
1589 info.cbSize = sizeof(MENUITEMINFO);
1590 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1591 info.dwTypeData = strback;
1592 info.cch = sizeof(strback);
1593 rc = GetMenuItemInfo(hmenu, 0x1234, FALSE, &info); /* Get by ID */
1595 ok (rc, "Getting the menu items info failed\n");
1596 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1597 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1599 DestroyMenu( hmenu );
1601 /* Case 2: Menu containing a popup menu */
1602 hmenu = CreateMenu();
1603 hmenuSub = CreateMenu();
1605 strcpy(strIn, "Case 2 SubMenu");
1606 rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, strIn);
1607 ok (rc, "Inserting the popup menu into the main menu failed\n");
1609 id = GetMenuItemID(hmenu, 0);
1610 ok (id == -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id);
1612 /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
1613 memset( &info, 0, sizeof info );
1615 info.cbSize = sizeof(MENUITEMINFO);
1616 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1617 info.dwTypeData = strback;
1618 info.cch = sizeof(strback);
1619 info.wID = 0xdeadbeef;
1621 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info); /* Get by position */
1622 ok (rc, "Getting the menu items info failed\n");
1623 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the menuitem\n");
1624 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1626 /* Search by id - returns the popup menu itself */
1627 memset( &info, 0, sizeof info );
1629 info.cbSize = sizeof(MENUITEMINFO);
1630 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1631 info.dwTypeData = strback;
1632 info.cch = sizeof(strback);
1633 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1635 ok (rc, "Getting the menu items info failed\n");
1636 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1637 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1640 Now add an item after it with the same id
1642 memset( &info, 0, sizeof info );
1643 info.cbSize = sizeof info;
1644 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1645 info.fType = MFT_STRING;
1646 strcpy(strIn, "Case 2 MenuItem 1");
1647 info.dwTypeData = strIn;
1648 info.wID = (UINT_PTR) hmenuSub;
1649 rc = InsertMenuItem(hmenu, -1, TRUE, &info );
1650 ok (rc, "Inserting the menuitem failed\n");
1652 /* Search by id - returns the item which follows the popup menu */
1653 memset( &info, 0, sizeof info );
1655 info.cbSize = sizeof(MENUITEMINFO);
1656 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1657 info.dwTypeData = strback;
1658 info.cch = sizeof(strback);
1659 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1661 ok (rc, "Getting the menu items info failed\n");
1662 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1663 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1666 Now add an item before the popup (with the same id)
1668 memset( &info, 0, sizeof info );
1669 info.cbSize = sizeof info;
1670 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1671 info.fType = MFT_STRING;
1672 strcpy(strIn, "Case 2 MenuItem 2");
1673 info.dwTypeData = strIn;
1674 info.wID = (UINT_PTR) hmenuSub;
1675 rc = InsertMenuItem(hmenu, 0, TRUE, &info );
1676 ok (rc, "Inserting the menuitem failed\n");
1678 /* Search by id - returns the item which precedes the popup menu */
1679 memset( &info, 0, sizeof info );
1681 info.cbSize = sizeof(MENUITEMINFO);
1682 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1683 info.dwTypeData = strback;
1684 info.cch = sizeof(strback);
1685 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1687 ok (rc, "Getting the menu items info failed\n");
1688 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1689 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1691 DestroyMenu( hmenu );
1692 DestroyMenu( hmenuSub );
1695 Case 3: Menu containing a popup menu which in turn
1696 contains 2 items with the same id as the popup itself
1699 hmenu = CreateMenu();
1700 hmenuSub = CreateMenu();
1702 memset( &info, 0, sizeof info );
1703 info.cbSize = sizeof info;
1704 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1705 info.fType = MFT_STRING;
1706 info.dwTypeData = menuitem;
1707 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1709 rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1710 ok (rc, "Inserting the popup menu into the main menu failed\n");
1712 rc = InsertMenuItem(hmenuSub, 0, TRUE, &info );
1713 ok (rc, "Inserting the sub menu menuitem failed\n");
1715 memset( &info, 0, sizeof info );
1716 info.cbSize = sizeof info;
1717 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1718 info.fType = MFT_STRING;
1719 info.dwTypeData = menuitem2;
1720 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1722 rc = InsertMenuItem(hmenuSub, 1, TRUE, &info );
1723 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
1725 /* Prove that you can't query the id of a popup directly (By position) */
1726 id = GetMenuItemID(hmenu, 0);
1727 ok (id == -1, "Getting the sub menu id should have failed because its a popup (gave %x)\n", id);
1729 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1730 memset( &info, 0, sizeof info );
1732 info.cbSize = sizeof(MENUITEMINFO);
1733 info.fMask = MIIM_STRING | MIIM_ID;
1734 info.dwTypeData = strback;
1735 info.cch = sizeof(strback);
1737 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
1738 ok (rc, "Getting the menus info failed\n");
1739 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
1740 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1741 DestroyMenu( hmenu );
1742 DestroyMenu( hmenuSub );
1745 Case 4: Menu containing 2 popup menus, the second
1746 contains 2 items with the same id as the first popup menu
1748 hmenu = CreateMenu();
1749 hmenuSub = CreateMenu();
1750 hmenuSub2 = CreateMenu();
1752 rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1753 ok (rc, "Inserting the popup menu into the main menu failed\n");
1755 rc = InsertMenu(hmenu, 1, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub2, "Submenu2");
1756 ok (rc, "Inserting the popup menu into the main menu failed\n");
1758 memset( &info, 0, sizeof info );
1759 info.cbSize = sizeof info;
1760 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1761 info.fType = MFT_STRING;
1762 info.dwTypeData = menuitem;
1763 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1765 rc = InsertMenuItem(hmenuSub2, 0, TRUE, &info );
1766 ok (rc, "Inserting the sub menu menuitem failed\n");
1768 memset( &info, 0, sizeof info );
1769 info.cbSize = sizeof info;
1770 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1771 info.fType = MFT_STRING;
1772 info.dwTypeData = menuitem2;
1773 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1775 rc = InsertMenuItem(hmenuSub2, 1, TRUE, &info );
1776 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
1778 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1779 memset( &info, 0, sizeof info );
1781 info.cbSize = sizeof(MENUITEMINFO);
1782 info.fMask = MIIM_STRING | MIIM_ID;
1783 info.dwTypeData = strback;
1784 info.cch = sizeof(strback);
1786 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
1787 ok (rc, "Getting the menus info failed\n");
1788 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
1789 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1791 memset( &info, 0, sizeof info );
1793 info.cbSize = sizeof(MENUITEMINFO);
1794 info.fMask = MIIM_STRING | MIIM_ID;
1795 info.dwTypeData = strback;
1796 info.cch = sizeof(strback);
1798 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub2, FALSE, &info);
1799 ok (rc, "Getting the menus info failed\n");
1800 ok (info.wID == (UINT_PTR)hmenuSub2, "IDs differ for popup menu\n");
1801 ok (!strcmp(info.dwTypeData, "Submenu2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1803 DestroyMenu( hmenu );
1804 DestroyMenu( hmenuSub );
1805 DestroyMenu( hmenuSub2 );
1809 Case 5: Menu containing a popup menu which in turn
1810 contains an item with a different id than the popup menu.
1811 This tests the fallback to a popup menu ID.
1814 hmenu = CreateMenu();
1815 hmenuSub = CreateMenu();
1817 rc = AppendMenu(hmenu, MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1818 ok (rc, "Appending the popup menu to the main menu failed\n");
1820 rc = AppendMenu(hmenuSub, MF_STRING, 102, "Item");
1821 ok (rc, "Appending the item to the popup menu failed\n");
1823 /* Set the ID for hmenuSub */
1824 info.cbSize = sizeof(info);
1825 info.fMask = MIIM_ID;
1828 rc = SetMenuItemInfo(hmenu, 0, TRUE, &info);
1829 ok(rc, "Setting the ID for the popup menu failed\n");
1831 /* Check if the ID has been set */
1833 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info);
1834 ok(rc, "Getting the ID for the popup menu failed\n");
1835 ok(info.wID == 101, "The ID for the popup menu has not been set\n");
1837 /* Prove getting the item info via ID returns the popup menu */
1838 memset( &info, 0, sizeof(info));
1840 info.cbSize = sizeof(MENUITEMINFO);
1841 info.fMask = MIIM_STRING | MIIM_ID;
1842 info.dwTypeData = strback;
1843 info.cch = sizeof(strback);
1845 rc = GetMenuItemInfo(hmenu, 101, FALSE, &info);
1846 ok (rc, "Getting the menu info failed\n");
1847 ok (info.wID == 101, "IDs differ\n");
1848 ok (!strcmp(info.dwTypeData, "Submenu"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1850 /* Also look for the menu item */
1851 memset( &info, 0, sizeof(info));
1853 info.cbSize = sizeof(MENUITEMINFO);
1854 info.fMask = MIIM_STRING | MIIM_ID;
1855 info.dwTypeData = strback;
1856 info.cch = sizeof(strback);
1858 rc = GetMenuItemInfo(hmenu, 102, FALSE, &info);
1859 ok (rc, "Getting the menu info failed\n");
1860 ok (info.wID == 102, "IDs differ\n");
1861 ok (!strcmp(info.dwTypeData, "Item"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1864 DestroyMenu(hmenuSub);
1867 struct menu_item_pair_s {
1868 UINT uMenu; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
1869 * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
1870 * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
1874 static struct menu_mouse_tests_s {
1876 struct menu_item_pair_s menu_item_pairs[5]; /* for mousing */
1877 WORD wVk[5]; /* keys */
1881 /* for each test, send keys or clicks and check for menu visibility */
1882 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE }, /* test 0 */
1883 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
1884 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
1885 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
1886 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
1887 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
1888 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
1889 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, VK_ESCAPE, 0}, FALSE, FALSE },
1890 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', VK_ESCAPE, 0}, TRUE, FALSE },
1891 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
1892 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
1893 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
1894 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
1895 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
1896 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
1897 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
1898 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
1899 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
1900 { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, TRUE, FALSE },
1901 { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, FALSE, FALSE },
1903 { INPUT_MOUSE, {{1, 2}, {0}}, {0}, TRUE, TRUE }, /* test 20 */
1904 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
1905 { INPUT_MOUSE, {{1, 0}, {0}}, {0}, TRUE, TRUE },
1906 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
1907 { INPUT_MOUSE, {{1, 0}, {2, 2}, {0}}, {0}, TRUE, TRUE },
1908 { INPUT_MOUSE, {{2, 1}, {0}}, {0}, FALSE, FALSE },
1909 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
1910 { INPUT_MOUSE, {{3, 0}, {0}}, {0}, FALSE, FALSE },
1911 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
1912 { INPUT_MOUSE, {{3, 1}, {0}}, {0}, TRUE, TRUE },
1913 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
1917 static void send_key(WORD wVk)
1920 memset(i, 0, sizeof(i));
1921 i[0].type = i[1].type = INPUT_KEYBOARD;
1922 i[0].u.ki.wVk = i[1].u.ki.wVk = wVk;
1923 i[1].u.ki.dwFlags = KEYEVENTF_KEYUP;
1924 pSendInput(2, (INPUT *) i, sizeof(INPUT));
1927 static BOOL click_menu(HANDLE hWnd, struct menu_item_pair_s *mi)
1929 HMENU hMenu = hMenus[mi->uMenu];
1933 int screen_w = GetSystemMetrics(SM_CXSCREEN);
1934 int screen_h = GetSystemMetrics(SM_CYSCREEN);
1935 BOOL ret = GetMenuItemRect(mi->uMenu > 2 ? NULL : hWnd, hMenu, mi->uItem, &r);
1936 if(!ret) return FALSE;
1938 memset(i, 0, sizeof(i));
1939 i[0].type = i[1].type = i[2].type = INPUT_MOUSE;
1940 i[0].u.mi.dx = i[1].u.mi.dx = i[2].u.mi.dx
1941 = ((r.left + 5) * 65535) / screen_w;
1942 i[0].u.mi.dy = i[1].u.mi.dy = i[2].u.mi.dy
1943 = ((r.top + 5) * 65535) / screen_h;
1944 i[0].u.mi.dwFlags = i[1].u.mi.dwFlags = i[2].u.mi.dwFlags
1945 = MOUSEEVENTF_ABSOLUTE;
1946 i[0].u.mi.dwFlags |= MOUSEEVENTF_MOVE;
1947 i[1].u.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
1948 i[2].u.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
1949 ret = pSendInput(3, (INPUT *) i, sizeof(INPUT));
1951 /* hack to prevent mouse message buildup in Wine */
1952 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
1956 static DWORD WINAPI test_menu_input_thread(LPVOID lpParameter)
1959 HANDLE hWnd = lpParameter;
1962 /* mixed keyboard/mouse test */
1963 for (i = 0; menu_tests[i].type != -1; i++)
1965 int ret = TRUE, elapsed = 0;
1967 got_input = i && menu_tests[i-1].bMenuVisible;
1969 if (menu_tests[i].type == INPUT_KEYBOARD)
1970 for (j = 0; menu_tests[i].wVk[j] != 0; j++)
1971 send_key(menu_tests[i].wVk[j]);
1973 for (j = 0; menu_tests[i].menu_item_pairs[j].uMenu != 0; j++)
1974 if (!(ret = click_menu(hWnd, &menu_tests[i].menu_item_pairs[j]))) break;
1978 skip( "test %u: failed to send input\n", i );
1979 PostMessage( hWnd, WM_CANCELMODE, 0, 0 );
1982 while (menu_tests[i].bMenuVisible != bMenuVisible)
1992 skip( "test %u: didn't receive input\n", i );
1993 PostMessage( hWnd, WM_CANCELMODE, 0, 0 );
1997 if (menu_tests[i]._todo_wine)
2000 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
2004 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
2009 static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam,
2013 case WM_ENTERMENULOOP:
2014 bMenuVisible = TRUE;
2016 case WM_EXITMENULOOP:
2017 bMenuVisible = FALSE;
2022 case WM_LBUTTONDOWN:
2024 case WM_NCMOUSEMOVE:
2025 case WM_NCLBUTTONDOWN:
2026 case WM_NCLBUTTONUP:
2030 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2035 static void test_menu_input(void) {
2038 HINSTANCE hInstance = GetModuleHandleA( NULL );
2039 HANDLE hThread, hWnd;
2045 win_skip("SendInput is not available\n");
2049 wclass.lpszClassName = "MenuTestClass";
2050 wclass.style = CS_HREDRAW | CS_VREDRAW;
2051 wclass.lpfnWndProc = WndProc;
2052 wclass.hInstance = hInstance;
2053 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
2054 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
2055 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2056 wclass.lpszMenuName = 0;
2057 wclass.cbClsExtra = 0;
2058 wclass.cbWndExtra = 0;
2059 aclass = RegisterClassA( &wclass );
2060 ok (aclass, "MenuTest class not created\n");
2061 if (!aclass) return;
2062 hWnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
2063 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2064 400, 200, NULL, NULL, hInstance, NULL);
2065 ok (hWnd != NULL, "MenuTest window not created\n");
2068 hMenus[3] = CreatePopupMenu();
2069 AppendMenu(hMenus[3], MF_STRING, 0, "&Enabled");
2070 AppendMenu(hMenus[3], MF_STRING|MF_DISABLED, 0, "&Disabled");
2072 hMenus[2] = CreatePopupMenu();
2073 AppendMenu(hMenus[2], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[3], "&Popup");
2074 AppendMenu(hMenus[2], MF_STRING, 0, "&Enabled");
2075 AppendMenu(hMenus[2], MF_STRING|MF_DISABLED, 0, "&Disabled");
2077 hMenus[1] = CreateMenu();
2078 AppendMenu(hMenus[1], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[2], "&Menu");
2079 AppendMenu(hMenus[1], MF_STRING, 0, "&Enabled");
2080 AppendMenu(hMenus[1], MF_STRING|MF_DISABLED, 0, "&Disabled");
2082 SetMenu(hWnd, hMenus[1]);
2083 ShowWindow(hWnd, SW_SHOW);
2086 hThread = CreateThread(NULL, 0, test_menu_input_thread, hWnd, 0, &tid);
2089 if (WAIT_TIMEOUT != WaitForSingleObject(hThread, 50))
2091 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2093 DestroyWindow(hWnd);
2096 static void test_menu_flags( void )
2098 HMENU hMenu, hPopupMenu;
2100 hMenu = CreateMenu();
2101 hPopupMenu = CreatePopupMenu();
2103 AppendMenu(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2105 AppendMenu(hPopupMenu, MF_STRING | MF_HILITE | MF_DEFAULT, 101, "Item 1");
2106 InsertMenu(hPopupMenu, 1, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 102, "Item 2");
2107 AppendMenu(hPopupMenu, MF_STRING, 103, "Item 3");
2108 ModifyMenu(hPopupMenu, 2, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 103, "Item 3");
2110 ok(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_HILITE,
2111 "AppendMenu should accept MF_HILITE\n");
2112 ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2113 "InsertMenu should accept MF_HILITE\n");
2114 ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2115 "ModifyMenu should accept MF_HILITE\n");
2117 ok(!(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_DEFAULT),
2118 "AppendMenu must not accept MF_DEFAULT\n");
2119 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_DEFAULT),
2120 "InsertMenu must not accept MF_DEFAULT\n");
2121 ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_DEFAULT),
2122 "ModifyMenu must not accept MF_DEFAULT\n");
2127 static void test_menu_hilitemenuitem( void )
2129 HMENU hMenu, hPopupMenu;
2134 wclass.lpszClassName = "HiliteMenuTestClass";
2135 wclass.style = CS_HREDRAW | CS_VREDRAW;
2136 wclass.lpfnWndProc = WndProc;
2137 wclass.hInstance = GetModuleHandleA( NULL );
2138 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
2139 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
2140 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2141 wclass.lpszMenuName = 0;
2142 wclass.cbClsExtra = 0;
2143 wclass.cbWndExtra = 0;
2144 aclass = RegisterClassA( &wclass );
2145 ok (aclass, "HiliteMenuTest class could not be created\n");
2146 if (!aclass) return;
2147 hWnd = CreateWindowA( wclass.lpszClassName, "HiliteMenuTest",
2148 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2149 400, 200, NULL, NULL, wclass.hInstance, NULL);
2150 ok (hWnd != NULL, "HiliteMenuTest window could not be created\n");
2153 hMenu = CreateMenu();
2154 hPopupMenu = CreatePopupMenu();
2156 AppendMenu(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2158 AppendMenu(hPopupMenu, MF_STRING, 101, "Item 1");
2159 AppendMenu(hPopupMenu, MF_STRING, 102, "Item 2");
2160 AppendMenu(hPopupMenu, MF_STRING, 103, "Item 3");
2162 SetMenu(hWnd, hMenu);
2164 /* test invalid arguments */
2166 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2167 "HiliteMenuItem: Item 2 is hilited\n");
2169 SetLastError(0xdeadbeef);
2172 ok(!HiliteMenuItem(NULL, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2173 "HiliteMenuItem: call should have failed.\n");
2175 ok(GetLastError() == 0xdeadbeef || /* 9x */
2176 GetLastError() == ERROR_INVALID_WINDOW_HANDLE /* NT */,
2177 "HiliteMenuItem: expected error ERROR_INVALID_WINDOW_HANDLE, got: %d\n", GetLastError());
2179 SetLastError(0xdeadbeef);
2180 ok(!HiliteMenuItem(hWnd, NULL, 1, MF_HILITE | MF_BYPOSITION),
2181 "HiliteMenuItem: call should have failed.\n");
2182 ok(GetLastError() == 0xdeadbeef || /* 9x */
2183 GetLastError() == ERROR_INVALID_MENU_HANDLE /* NT */,
2184 "HiliteMenuItem: expected error ERROR_INVALID_MENU_HANDLE, got: %d\n", GetLastError());
2186 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2187 "HiliteMenuItem: Item 2 is hilited\n");
2189 /* either MF_HILITE or MF_UNHILITE *and* MF_BYCOMMAND or MF_BYPOSITION need to be set */
2191 SetLastError(0xdeadbeef);
2192 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_BYPOSITION),
2193 "HiliteMenuItem: call should have succeeded.\n");
2194 ok(GetLastError() == 0xdeadbeef,
2195 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2197 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2198 "HiliteMenuItem: Item 2 is hilited\n");
2200 SetLastError(0xdeadbeef);
2203 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE),
2204 "HiliteMenuItem: call should have succeeded.\n");
2206 ok(GetLastError() == 0xdeadbeef,
2207 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2209 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2210 "HiliteMenuItem: Item 2 is hilited\n");
2212 /* hilite a menu item (by position) */
2214 SetLastError(0xdeadbeef);
2215 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2216 "HiliteMenuItem: call should not have failed.\n");
2217 ok(GetLastError() == 0xdeadbeef,
2218 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2222 ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2223 "HiliteMenuItem: Item 2 is not hilited\n");
2226 /* unhilite a menu item (by position) */
2228 SetLastError(0xdeadbeef);
2229 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_UNHILITE | MF_BYPOSITION),
2230 "HiliteMenuItem: call should not have failed.\n");
2231 ok(GetLastError() == 0xdeadbeef,
2232 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2234 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2235 "HiliteMenuItem: Item 2 is hilited\n");
2237 /* hilite a menu item (by command) */
2239 SetLastError(0xdeadbeef);
2240 ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_HILITE | MF_BYCOMMAND),
2241 "HiliteMenuItem: call should not have failed.\n");
2242 ok(GetLastError() == 0xdeadbeef,
2243 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2247 ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2248 "HiliteMenuItem: Item 3 is not hilited\n");
2251 /* unhilite a menu item (by command) */
2253 SetLastError(0xdeadbeef);
2254 ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_UNHILITE | MF_BYCOMMAND),
2255 "HiliteMenuItem: call should not have failed.\n");
2256 ok(GetLastError() == 0xdeadbeef,
2257 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2259 ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE),
2260 "HiliteMenuItem: Item 3 is hilited\n");
2262 DestroyWindow(hWnd);
2265 static void check_menu_items(HMENU hmenu, UINT checked_cmd, UINT checked_type,
2270 count = GetMenuItemCount(hmenu);
2271 ok (count != -1, "GetMenuItemCount returned -1\n");
2273 for (i = 0; i < count; i++)
2278 memset(&mii, 0, sizeof(mii));
2279 mii.cbSize = sizeof(mii);
2280 mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU;
2281 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2282 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2284 trace("item #%u: fType %04x, fState %04x, wID %u, hSubMenu %p\n",
2285 i, mii.fType, mii.fState, mii.wID, mii.hSubMenu);
2289 ok(mii.wID == (UINT_PTR)mii.hSubMenu, "id %u: wID should be equal to hSubMenu\n", checked_cmd);
2290 check_menu_items(mii.hSubMenu, checked_cmd, checked_type, checked_state);
2294 if (mii.wID == checked_cmd)
2296 ok(mii.fType == checked_type, "id %u: expected fType %04x, got %04x\n", checked_cmd, checked_type, mii.fType);
2297 ok(mii.fState == checked_state, "id %u: expected fState %04x, got %04x\n", checked_cmd, checked_state, mii.fState);
2298 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2302 ok(mii.fType != MFT_RADIOCHECK, "id %u: not expected fType MFT_RADIOCHECK on cmd %u\n", checked_cmd, mii.wID);
2304 if (mii.fType == MFT_SEPARATOR)
2306 ok(mii.fState == MFS_GRAYED, "id %u: expected fState MFS_GRAYED, got %04x\n", checked_cmd, mii.fState);
2307 ok(mii.wID == 0, "id %u: expected wID 0, got %u\n", checked_cmd, mii.wID);
2311 ok(mii.fState == 0, "id %u: expected fState 0, got %04x\n", checked_cmd, mii.fState);
2312 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2319 static void clear_ftype_and_state(HMENU hmenu, UINT id, UINT flags)
2324 memset(&mii, 0, sizeof(mii));
2325 mii.cbSize = sizeof(mii);
2326 mii.fMask = MIIM_FTYPE | MIIM_STATE;
2327 ret = SetMenuItemInfo(hmenu, id, (flags & MF_BYPOSITION) != 0, &mii);
2328 ok(ret, "SetMenuItemInfo(%u) failed\n", id);
2331 static void test_CheckMenuRadioItem(void)
2336 hmenu = LoadMenu(GetModuleHandle(0), MAKEINTRESOURCE(1));
2339 check_menu_items(hmenu, -1, 0, 0);
2341 ret = CheckMenuRadioItem(hmenu, 100, 100, 100, MF_BYCOMMAND);
2342 ok(ret, "CheckMenuRadioItem failed\n");
2343 check_menu_items(hmenu, 100, MFT_RADIOCHECK, MFS_CHECKED);
2345 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2346 ret = CheckMenuRadioItem(hmenu, 100, 100, -1, MF_BYCOMMAND);
2347 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2348 check_menu_items(hmenu, 100, MFT_RADIOCHECK, 0);
2351 clear_ftype_and_state(hmenu, 100, MF_BYCOMMAND);
2352 check_menu_items(hmenu, -1, 0, 0);
2354 /* first and checked items are on different menus */
2355 ret = CheckMenuRadioItem(hmenu, 0, 300, 202, MF_BYCOMMAND);
2356 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2357 check_menu_items(hmenu, -1, 0, 0);
2359 ret = CheckMenuRadioItem(hmenu, 200, 300, 202, MF_BYCOMMAND);
2360 ok(ret, "CheckMenuRadioItem failed\n");
2361 check_menu_items(hmenu, 202, MFT_RADIOCHECK, MFS_CHECKED);
2363 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2364 ret = CheckMenuRadioItem(hmenu, 202, 202, -1, MF_BYCOMMAND);
2365 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2366 check_menu_items(hmenu, 202, MFT_RADIOCHECK, 0);
2369 clear_ftype_and_state(hmenu, 202, MF_BYCOMMAND);
2370 check_menu_items(hmenu, -1, 0, 0);
2372 /* just for fun, try to check separator */
2373 ret = CheckMenuRadioItem(hmenu, 0, 300, 0, MF_BYCOMMAND);
2374 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2375 check_menu_items(hmenu, -1, 0, 0);
2378 static void test_menu_resource_layout(void)
2382 MENUITEMTEMPLATEHEADER mith;
2386 { 0, 0 }, /* versionNumber, offset */
2388 /* mtOption, mtID, mtString[] '\0' terminated */
2389 MF_STRING, 1, 'F', 0,
2392 /* MF_SEPARATOR, 4, 'S', 0, FIXME: Wine ignores 'S' */
2393 MF_STRING|MF_GRAYED|MF_END, 5, 'E', 0
2398 UINT type, state, id;
2402 { MF_STRING, MF_ENABLED, 1, "F" },
2403 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 2, "" },
2404 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 3, "" },
2405 /*{ MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 4, "S" }, FIXME: Wine ignores 'S'*/
2406 { MF_STRING, MF_GRAYED, 5, "E" },
2407 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 6, "" },
2408 { MF_STRING, MF_ENABLED, 7, "" },
2409 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 8, "" }
2415 hmenu = LoadMenuIndirect(&menu_template);
2416 ok(hmenu != 0, "LoadMenuIndirect error %u\n", GetLastError());
2418 ret = AppendMenu(hmenu, MF_STRING, 6, NULL);
2419 ok(ret, "AppendMenu failed\n");
2420 ret = AppendMenu(hmenu, MF_STRING, 7, "\0");
2421 ok(ret, "AppendMenu failed\n");
2422 ret = AppendMenu(hmenu, MF_SEPARATOR, 8, "separator");
2423 ok(ret, "AppendMenu failed\n");
2425 count = GetMenuItemCount(hmenu);
2426 ok(count == sizeof(menu_data)/sizeof(menu_data[0]),
2427 "expected %u menu items, got %u\n",
2428 (UINT)(sizeof(menu_data)/sizeof(menu_data[0])), count);
2430 for (i = 0; i < count; i++)
2435 memset(&mii, 0, sizeof(mii));
2436 mii.cbSize = sizeof(mii);
2437 mii.dwTypeData = buf;
2438 mii.cch = sizeof(buf);
2439 mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_STRING;
2440 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2441 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2443 trace("item #%u: fType %04x, fState %04x, wID %u, dwTypeData %s\n",
2444 i, mii.fType, mii.fState, mii.wID, (LPCSTR)mii.dwTypeData);
2446 ok(mii.fType == menu_data[i].type,
2447 "%u: expected fType %04x, got %04x\n", i, menu_data[i].type, mii.fType);
2448 ok(mii.fState == menu_data[i].state,
2449 "%u: expected fState %04x, got %04x\n", i, menu_data[i].state, mii.fState);
2450 ok(mii.wID == menu_data[i].id,
2451 "%u: expected wID %04x, got %04x\n", i, menu_data[i].id, mii.wID);
2452 ok(mii.cch == strlen(menu_data[i].str),
2453 "%u: expected cch %u, got %u\n", i, (UINT)strlen(menu_data[i].str), mii.cch);
2454 ok(!strcmp(mii.dwTypeData, menu_data[i].str),
2455 "%u: expected dwTypeData %s, got %s\n", i, menu_data[i].str, (LPCSTR)mii.dwTypeData);
2467 static HMENU create_menu_from_data(const struct menu_data *item, INT item_count)
2473 hmenu = CreateMenu();
2476 for (i = 0; i < item_count; i++)
2478 SetLastError(0xdeadbeef);
2479 ret = AppendMenu(hmenu, item[i].type, item[i].id, item[i].str);
2480 ok(ret, "%d: AppendMenu(%04x, %04x, %p) error %u\n",
2481 i, item[i].type, item[i].id, item[i].str, GetLastError());
2486 /* use InsertMenuItem: does not set the MFT_BITMAP flag,
2487 * and does not accept non-magic bitmaps with invalid
2489 static HMENU create_menuitem_from_data(const struct menu_data *item, INT item_count)
2494 MENUITEMINFO mii = { sizeof( MENUITEMINFO)};
2496 hmenu = CreateMenu();
2499 for (i = 0; i < item_count; i++)
2501 SetLastError(0xdeadbeef);
2503 mii.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STATE;
2505 if( item[i].type & MFT_BITMAP)
2507 mii.fMask |= MIIM_BITMAP;
2508 mii.hbmpItem = (HBITMAP)item[i].str;
2510 else if( item[i].type & MFT_SEPARATOR)
2511 mii.fType = MFT_SEPARATOR;
2514 mii.fMask |= MIIM_STRING;
2515 mii.dwTypeData = (LPSTR)item[i].str;
2516 mii.cch = strlen( item[i].str);
2519 if( item[i].type & MF_HELP) mii.fType |= MF_HELP;
2520 mii.wID = item[i].id;
2521 ret = InsertMenuItem( hmenu, -1, TRUE, &mii);
2522 ok(ret, "%d: InsertMenuItem(%04x, %04x, %p) error %u\n",
2523 i, item[i].type, item[i].id, item[i].str, GetLastError());
2528 static void compare_menu_data(HMENU hmenu, const struct menu_data *item, INT item_count)
2533 count = GetMenuItemCount(hmenu);
2534 ok(count == item_count, "expected %d, got %d menu items\n", count, item_count);
2536 for (i = 0; i < count; i++)
2541 memset(&mii, 0, sizeof(mii));
2542 mii.cbSize = sizeof(mii);
2543 mii.dwTypeData = buf;
2544 mii.cch = sizeof(buf);
2545 mii.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_BITMAP;
2546 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2547 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2549 trace("item #%u: fType %04x, fState %04x, wID %04x, hbmp %p\n",
2550 i, mii.fType, mii.fState, mii.wID, mii.hbmpItem);
2552 ok(mii.fType == item[i].type,
2553 "%u: expected fType %04x, got %04x\n", i, item[i].type, mii.fType);
2554 ok(mii.wID == item[i].id,
2555 "%u: expected wID %04x, got %04x\n", i, item[i].id, mii.wID);
2556 if (mii.hbmpItem || !item[i].str)
2557 /* For some reason Windows sets high word to not 0 for
2560 ok(LOWORD(mii.hbmpItem) == LOWORD(item[i].str),
2561 "%u: expected hbmpItem %p, got %p\n", i, item[i].str, mii.hbmpItem);
2564 ok(mii.cch == strlen(item[i].str),
2565 "%u: expected cch %u, got %u\n", i, (UINT)strlen(item[i].str), mii.cch);
2566 ok(!strcmp(mii.dwTypeData, item[i].str),
2567 "%u: expected dwTypeData %s, got %s\n", i, item[i].str, (LPCSTR)mii.dwTypeData);
2572 static void test_InsertMenu(void)
2574 HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
2575 /* Note: XP treats only bitmap handles 1 - 6 as "magic" ones
2576 * regardless of their id.
2578 static const struct menu_data in1[] =
2580 { MF_STRING, 1, "File" },
2581 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) },
2582 { MF_STRING|MF_HELP, 2, "Help" }
2584 static const struct menu_data out1[] =
2586 { MF_STRING, 1, "File" },
2587 { MF_STRING|MF_HELP, 2, "Help" },
2588 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) }
2590 static const struct menu_data out1a[] =
2592 { MF_STRING, 1, "File" },
2593 { MF_STRING|MF_HELP, 2, "Help" },
2594 { MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) }
2596 const struct menu_data in2[] =
2598 { MF_STRING, 1, "File" },
2599 { MF_BITMAP|MF_HELP, SC_CLOSE, (char*)hbm },
2600 { MF_STRING|MF_HELP, 2, "Help" }
2602 const struct menu_data out2[] =
2604 { MF_STRING, 1, "File" },
2605 { MF_BITMAP|MF_HELP, SC_CLOSE, (char*)hbm },
2606 { MF_STRING|MF_HELP, 2, "Help" }
2608 const struct menu_data out2a[] =
2610 { MF_STRING, 1, "File" },
2611 { MF_HELP, SC_CLOSE, (char*)hbm },
2612 { MF_STRING|MF_HELP, 2, "Help" }
2614 static const struct menu_data in3[] =
2616 { MF_STRING, 1, "File" },
2617 { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) },
2618 { MF_STRING|MF_HELP, 2, "Help" }
2620 static const struct menu_data out3[] =
2622 { MF_STRING, 1, "File" },
2623 { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(0) },
2624 { MF_STRING|MF_HELP, 2, "Help" },
2626 static const struct menu_data in4[] =
2628 { MF_STRING, 1, "File" },
2629 { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCE(1) },
2630 { MF_STRING|MF_HELP, 2, "Help" }
2632 static const struct menu_data out4[] =
2634 { MF_STRING, 1, "File" },
2635 { MF_STRING|MF_HELP, 2, "Help" },
2636 { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCE(1) }
2638 static const struct menu_data out4a[] =
2640 { MF_STRING, 1, "File" },
2641 { MF_STRING|MF_HELP, 2, "Help" },
2642 { MF_HELP, 1, MAKEINTRESOURCE(1) }
2646 #define create_menu(a) create_menu_from_data((a), sizeof(a)/sizeof((a)[0]))
2647 #define create_menuitem(a) create_menuitem_from_data((a), sizeof(a)/sizeof((a)[0]))
2648 #define compare_menu(h, a) compare_menu_data((h), (a), sizeof(a)/sizeof((a)[0]))
2650 hmenu = create_menu(in1);
2651 compare_menu(hmenu, out1);
2654 hmenu = create_menu(in2);
2655 compare_menu(hmenu, out2);
2658 hmenu = create_menu(in3);
2659 compare_menu(hmenu, out3);
2662 hmenu = create_menu(in4);
2663 compare_menu(hmenu, out4);
2666 /* now using InsertMenuItemInfo */
2667 hmenu = create_menuitem(in1);
2668 compare_menu(hmenu, out1a);
2671 hmenu = create_menuitem(in2);
2672 compare_menu(hmenu, out2a);
2675 hmenu = create_menuitem(in3);
2676 compare_menu(hmenu, out3);
2679 hmenu = create_menuitem(in4);
2680 compare_menu(hmenu, out4a);
2684 #undef create_menuitem
2688 static void test_menu_getmenuinfo(void)
2697 win_skip("GetMenuInfo is not available\n");
2702 hmenu = CreateMenu();
2704 /* test some parameter errors */
2705 SetLastError(0xdeadbeef);
2706 ret = pGetMenuInfo( hmenu, NULL);
2707 gle= GetLastError();
2708 ok( !ret, "GetMenuInfo() should have failed\n");
2709 ok( gle == ERROR_INVALID_PARAMETER ||
2710 broken(gle == 0xdeadbeef), /* Win98, WinME */
2711 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2712 SetLastError(0xdeadbeef);
2714 ret = pGetMenuInfo( hmenu, &mi);
2715 gle= GetLastError();
2716 ok( !ret, "GetMenuInfo() should have failed\n");
2717 ok( gle == ERROR_INVALID_PARAMETER ||
2718 broken(gle == 0xdeadbeef), /* Win98, WinME */
2719 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2720 SetLastError(0xdeadbeef);
2721 mi.cbSize = sizeof( MENUINFO);
2722 ret = pGetMenuInfo( hmenu, &mi);
2723 gle= GetLastError();
2724 ok( ret, "GetMenuInfo() should have succeeded\n");
2725 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2726 SetLastError(0xdeadbeef);
2728 ret = pGetMenuInfo( NULL, &mi);
2729 gle= GetLastError();
2730 ok( !ret, "GetMenuInfo() should have failed\n");
2731 ok( gle == ERROR_INVALID_PARAMETER ||
2732 broken(gle == 0xdeadbeef), /* Win98, WinME */
2733 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2735 DestroyMenu( hmenu);
2739 static void test_menu_setmenuinfo(void)
2741 HMENU hmenu, hsubmenu;
2743 MENUITEMINFOA mii = {sizeof( MENUITEMINFOA)};
2747 if (!pGetMenuInfo || !pSetMenuInfo)
2749 win_skip("Get/SetMenuInfo are not available\n");
2753 /* create a menu with a submenu */
2754 hmenu = CreateMenu();
2755 hsubmenu = CreateMenu();
2756 assert( hmenu && hsubmenu);
2757 mii.fMask = MIIM_SUBMENU;
2758 mii.hSubMenu = hsubmenu;
2759 ret = InsertMenuItem( hmenu, 0, FALSE, &mii);
2760 ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
2761 /* test some parameter errors */
2762 SetLastError(0xdeadbeef);
2763 ret = pSetMenuInfo( hmenu, NULL);
2764 gle= GetLastError();
2765 ok( !ret, "SetMenuInfo() should have failed\n");
2766 ok( gle == ERROR_INVALID_PARAMETER ||
2767 broken(gle == 0xdeadbeef), /* Win98, WinME */
2768 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2769 SetLastError(0xdeadbeef);
2771 ret = pSetMenuInfo( hmenu, &mi);
2772 gle= GetLastError();
2773 ok( !ret, "SetMenuInfo() should have failed\n");
2774 ok( gle == ERROR_INVALID_PARAMETER ||
2775 broken(gle == 0xdeadbeef), /* Win98, WinME */
2776 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2777 SetLastError(0xdeadbeef);
2778 mi.cbSize = sizeof( MENUINFO);
2779 ret = pSetMenuInfo( hmenu, &mi);
2780 gle= GetLastError();
2781 ok( ret, "SetMenuInfo() should have succeeded\n");
2782 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2783 SetLastError(0xdeadbeef);
2785 ret = pSetMenuInfo( NULL, &mi);
2786 gle= GetLastError();
2787 ok( !ret, "SetMenuInfo() should have failed\n");
2788 ok( gle == ERROR_INVALID_PARAMETER ||
2789 broken(gle == 0xdeadbeef), /* Win98, WinME */
2790 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2791 /* functional tests */
2792 /* menu and submenu should have the CHECKORBMP style bit cleared */
2793 SetLastError(0xdeadbeef);
2794 mi.cbSize = sizeof( MENUINFO);
2795 mi.fMask = MIM_STYLE;
2796 ret = pGetMenuInfo( hmenu, &mi);
2797 gle= GetLastError();
2798 ok( ret, "GetMenuInfo() should have succeeded\n");
2799 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2800 ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2801 SetLastError(0xdeadbeef);
2802 mi.cbSize = sizeof( MENUINFO);
2803 mi.fMask = MIM_STYLE;
2804 ret = pGetMenuInfo( hsubmenu, &mi);
2805 gle= GetLastError();
2806 ok( ret, "GetMenuInfo() should have succeeded\n");
2807 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2808 ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2810 SetLastError(0xdeadbeef);
2811 mi.cbSize = sizeof( MENUINFO);
2812 mi.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS;
2813 mi.dwStyle = MNS_CHECKORBMP;
2814 ret = pSetMenuInfo( hmenu, &mi);
2815 gle= GetLastError();
2816 ok( ret, "SetMenuInfo() should have succeeded\n");
2817 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2818 /* Now both menus should have the MNS_CHECKORBMP style bit set */
2819 SetLastError(0xdeadbeef);
2820 mi.cbSize = sizeof( MENUINFO);
2821 mi.fMask = MIM_STYLE;
2822 ret = pGetMenuInfo( hmenu, &mi);
2823 gle= GetLastError();
2824 ok( ret, "GetMenuInfo() should have succeeded\n");
2825 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2826 ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2827 SetLastError(0xdeadbeef);
2828 mi.cbSize = sizeof( MENUINFO);
2829 mi.fMask = MIM_STYLE;
2830 ret = pGetMenuInfo( hsubmenu, &mi);
2831 gle= GetLastError();
2832 ok( ret, "GetMenuInfo() should have succeeded\n");
2833 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2834 ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2835 /* now repeat that without the APPLYTOSUBMENUS flag and another style bit */
2836 SetLastError(0xdeadbeef);
2837 mi.cbSize = sizeof( MENUINFO);
2838 mi.fMask = MIM_STYLE ;
2839 mi.dwStyle = MNS_NOCHECK;
2840 ret = pSetMenuInfo( hmenu, &mi);
2841 gle= GetLastError();
2842 ok( ret, "SetMenuInfo() should have succeeded\n");
2843 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2844 /* Now only the top menu should have the MNS_NOCHECK style bit set */
2845 SetLastError(0xdeadbeef);
2846 mi.cbSize = sizeof( MENUINFO);
2847 mi.fMask = MIM_STYLE;
2848 ret = pGetMenuInfo( hmenu, &mi);
2849 gle= GetLastError();
2850 ok( ret, "GetMenuInfo() should have succeeded\n");
2851 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2852 ok( mi.dwStyle & MNS_NOCHECK, "menustyle was expected to have the MNS_NOCHECK flag\n");
2853 SetLastError(0xdeadbeef);
2854 mi.cbSize = sizeof( MENUINFO);
2855 mi.fMask = MIM_STYLE;
2856 ret = pGetMenuInfo( hsubmenu, &mi);
2857 gle= GetLastError();
2858 ok( ret, "GetMenuInfo() should have succeeded\n");
2859 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2860 ok( !(mi.dwStyle & MNS_NOCHECK), "menustyle was not expected to have the MNS_NOCHECK flag\n");
2862 DestroyMenu( hsubmenu);
2863 DestroyMenu( hmenu);
2867 /* little func to easy switch either TrackPopupMenu() or TrackPopupMenuEx() */
2868 static DWORD MyTrackPopupMenu( int ex, HMENU hmenu, UINT flags, INT x, INT y, HWND hwnd, LPTPMPARAMS ptpm)
2871 ? TrackPopupMenuEx( hmenu, flags, x, y, hwnd, ptpm)
2872 : TrackPopupMenu( hmenu, flags, x, y, 0, hwnd, NULL);
2875 /* some TrackPopupMenu and TrackPopupMenuEx tests */
2876 /* the LastError values differ between NO_ERROR and invalid handle */
2877 /* between all windows versions tested. The first value is that valid on XP */
2878 /* Vista was the only that made returned different error values */
2879 /* between the TrackPopupMenu and TrackPopupMenuEx functions */
2880 static void test_menu_trackpopupmenu(void)
2886 HWND hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
2887 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
2888 NULL, NULL, NULL, NULL);
2889 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
2891 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
2892 for( Ex = 0; Ex < 2; Ex++)
2894 hmenu = CreatePopupMenu();
2895 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
2898 DestroyWindow(hwnd);
2901 /* display the menu */
2902 /* start with an invalid menu handle */
2903 SetLastError(0xdeadbeef);
2905 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2906 ret = MyTrackPopupMenu( Ex, NULL, TPM_RETURNCMD, 100,100, hwnd, NULL);
2907 gle = GetLastError();
2908 ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
2909 ok( gle == ERROR_INVALID_MENU_HANDLE
2910 || broken (gle == 0xdeadbeef) /* win95 */
2911 || broken (gle == NO_ERROR) /* win98/ME */
2912 ,"TrackPopupMenu%s error got %u expected %u\n",
2913 Ex ? "Ex" : "", gle, ERROR_INVALID_MENU_HANDLE);
2914 ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
2915 "got unexpected message(s)%s%s%s\n",
2916 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2917 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2918 gflag_initmenu ? "WM_INITMENU": "");
2919 /* another one but not NULL */
2920 SetLastError(0xdeadbeef);
2921 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2922 ret = MyTrackPopupMenu( Ex, (HMENU)hwnd, TPM_RETURNCMD, 100,100, hwnd, NULL);
2923 gle = GetLastError();
2924 ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
2925 ok( gle == ERROR_INVALID_MENU_HANDLE
2926 || broken (gle == 0xdeadbeef) /* win95 */
2927 || broken (gle == NO_ERROR) /* win98/ME */
2928 ,"TrackPopupMenu%s error got %u expected %u\n",
2929 Ex ? "Ex" : "", gle, ERROR_INVALID_MENU_HANDLE);
2930 ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
2931 "got unexpected message(s)%s%s%s\n",
2932 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2933 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2934 gflag_initmenu ? "WM_INITMENU": "");
2936 /* invalid window */
2937 SetLastError(0xdeadbeef);
2938 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2939 ret = MyTrackPopupMenu( Ex, hmenu, TPM_RETURNCMD, 100,100, 0, NULL);
2940 gle = GetLastError();
2941 ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
2942 ok( gle == ERROR_INVALID_WINDOW_HANDLE, "TrackPopupMenu%s error got %u\n", Ex ? "Ex" : "", gle );
2943 ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
2944 "got unexpected message(s)%s%s%s\n",
2945 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2946 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2947 gflag_initmenu ? "WM_INITMENU": "");
2949 /* now a somewhat successful call */
2950 SetLastError(0xdeadbeef);
2951 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2952 ret = MyTrackPopupMenu( Ex, hmenu, TPM_RETURNCMD, 100,100, hwnd, NULL);
2953 gle = GetLastError();
2954 ok( ret == 0, "TrackPopupMenu%s returned %d expected zero\n", Ex ? "Ex" : "", ret);
2956 || gle == ERROR_INVALID_MENU_HANDLE /* NT4, win2k */
2957 || broken (gle == 0xdeadbeef) /* win95 */
2958 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
2959 Ex ? "Ex" : "", gle, NO_ERROR, ERROR_INVALID_MENU_HANDLE);
2960 ok( gflag_initmenupopup && gflag_entermenuloop && gflag_initmenu,
2961 "missed expected message(s)%s%s%s\n",
2962 !gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2963 !gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2964 !gflag_initmenu ? "WM_INITMENU": "");
2966 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest");
2967 ok( ret, "AppendMenA has failed!\n");
2968 SetLastError(0xdeadbeef);
2969 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2970 ret = MyTrackPopupMenu( Ex, hmenu, TPM_RETURNCMD, 100,100, hwnd, NULL);
2971 gle = GetLastError();
2972 ok( ret == 0, "TrackPopupMenu%s returned %d expected zero\n", Ex ? "Ex" : "", ret);
2974 || gle == ERROR_INVALID_MENU_HANDLE /* NT4, win2k and Vista in the TrackPopupMenuEx case */
2975 || broken (gle == 0xdeadbeef) /* win95 */
2976 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
2977 Ex ? "Ex" : "", gle, NO_ERROR, ERROR_INVALID_MENU_HANDLE);
2978 ok( gflag_initmenupopup && gflag_entermenuloop && gflag_initmenu,
2979 "missed expected message(s)%s%s%s\n",
2980 !gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2981 !gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2982 !gflag_initmenu ? "WM_INITMENU": "");
2986 DestroyWindow(hwnd);
2989 static HMENU g_hmenu;
2991 static LRESULT WINAPI menu_track_again_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2995 case WM_ENTERMENULOOP:
2999 /* try a recursive call */
3000 SetLastError(0xdeadbeef);
3001 ret = TrackPopupMenu(g_hmenu, 0, 100, 100, 0, hwnd, NULL);
3002 ok(ret == FALSE, "got %d\n", ret);
3003 ok(GetLastError() == ERROR_POPUP_ALREADY_ACTIVE ||
3004 broken(GetLastError() == 0xdeadbeef) /* W9x */, "got %d\n", GetLastError());
3006 /* exit menu modal loop
3007 * ( A SendMessage does not work on NT3.51 here ) */
3008 return PostMessage(hwnd, WM_CANCELMODE, 0, 0);
3011 return DefWindowProc(hwnd, msg, wparam, lparam);
3014 static void test_menu_trackagain(void)
3019 hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
3020 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
3021 NULL, NULL, NULL, NULL);
3022 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
3024 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_track_again_wnd_proc);
3026 g_hmenu = CreatePopupMenu();
3027 ok(g_hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
3029 ret = TrackPopupMenu( g_hmenu, 0, 100, 100, 0, hwnd, NULL);
3030 todo_wine ok(ret == FALSE, "got %d\n", ret);
3032 DestroyMenu(g_hmenu);
3033 DestroyWindow(hwnd);
3036 /* test handling of WM_CANCELMODE messages */
3037 static int g_got_enteridle;
3038 static HWND g_hwndtosend;
3039 static LRESULT WINAPI menu_cancelmode_wnd_proc(HWND hwnd, UINT msg,
3040 WPARAM wparam, LPARAM lparam)
3044 case WM_ENTERMENULOOP:
3045 g_got_enteridle = 0;
3046 return SendMessage( g_hwndtosend, WM_CANCELMODE, 0, 0);
3049 if( g_got_enteridle++ == 0) {
3050 /* little hack to get another WM_ENTERIDLE message */
3051 PostMessage( hwnd, WM_MOUSEMOVE, 0, 0);
3052 return SendMessage( g_hwndtosend, WM_CANCELMODE, 0, 0);
3058 return DefWindowProc( hwnd, msg, wparam, lparam);
3061 static void test_menu_cancelmode(void)
3064 HWND hwnd, hwndchild;
3066 if( !pEndMenu) { /* win95 */
3067 win_skip( "EndMenu is not available\n");
3070 hwnd = CreateWindowEx( 0, MAKEINTATOM(atomMenuCheckClass), NULL,
3071 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
3072 NULL, NULL, NULL, NULL);
3073 hwndchild = CreateWindowEx( 0, MAKEINTATOM(atomMenuCheckClass), NULL,
3074 WS_VISIBLE | WS_CHILD, 10, 10, 20, 20,
3075 hwnd, NULL, NULL, NULL);
3076 ok( hwnd != NULL && hwndchild != NULL,
3077 "CreateWindowEx failed with error %d\n", GetLastError());
3078 g_hwndtosend = hwnd;
3079 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_cancelmode_wnd_proc);
3080 SetWindowLongPtr( hwndchild, GWLP_WNDPROC, (LONG_PTR)menu_cancelmode_wnd_proc);
3081 menu = CreatePopupMenu();
3082 ok( menu != NULL, "CreatePopupMenu failed with error %d\n", GetLastError());
3083 ret = AppendMenuA( menu, MF_STRING, 1, "winetest");
3084 ok( ret, "Functie failed lasterror is %u\n", GetLastError());
3085 /* seems to be needed only on wine :( */
3086 {MSG msg; while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);}
3087 /* test the effect of sending a WM_CANCELMODE message in the WM_INITMENULOOP
3088 * handler of the menu owner */
3089 /* test results is exctracted from variable g_got_enteridle. Possible values:
3090 * 0 : complete conformance. Sending WM_CANCELMODE cancels a menu initializing tracking
3091 * 1 : Sending WM_CANCELMODE cancels a menu that is in tracking state
3092 * 2 : Sending WM_CANCELMODE does not work
3094 /* menu owner is top level window */
3095 g_hwndtosend = hwnd;
3096 TrackPopupMenu( menu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
3098 ok( g_got_enteridle == 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle);
3100 ok( g_got_enteridle < 2, "received %d WM_ENTERIDLE messages, should be less than 2\n", g_got_enteridle);
3101 /* menu owner is child window */
3102 g_hwndtosend = hwndchild;
3103 TrackPopupMenu( menu, TPM_RETURNCMD, 100,100, 0, hwndchild, NULL);
3105 ok(g_got_enteridle == 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle);
3107 ok(g_got_enteridle < 2, "received %d WM_ENTERIDLE messages, should be less than 2\n", g_got_enteridle);
3108 /* now send the WM_CANCELMODE messages to the WRONG window */
3109 /* those should fail ( to have any effect) */
3110 g_hwndtosend = hwnd;
3111 TrackPopupMenu( menu, TPM_RETURNCMD, 100,100, 0, hwndchild, NULL);
3112 ok( g_got_enteridle == 2, "received %d WM_ENTERIDLE messages, should be 2\n", g_got_enteridle);
3115 DestroyWindow( hwndchild);
3116 DestroyWindow( hwnd);
3119 /* show menu trees have a maximum depth */
3120 static void test_menu_maxdepth(void)
3122 #define NR_MENUS 100
3123 HMENU hmenus[ NR_MENUS];
3127 SetLastError(12345678);
3128 for( i = 0; i < NR_MENUS; i++) {
3129 hmenus[i] = CreatePopupMenu();
3130 if( !hmenus[i]) break;
3132 ok( i == NR_MENUS, "could not create more than %d menu's\n", i);
3133 for( i = 1; i < NR_MENUS; i++) {
3134 ret = AppendMenuA( hmenus[i], MF_POPUP, (UINT_PTR)hmenus[i-1],"test");
3137 trace("Maximum depth is %d\n", i);
3138 ok( GetLastError() == 12345678, "unexpected error %d\n", GetLastError());
3140 broken( i == NR_MENUS), /* win98, NT */
3141 "no ( or very large) limit on menu depth!\n");
3143 for( i = 0; i < NR_MENUS; i++)
3144 DestroyMenu( hmenus[i]);
3148 static void test_menu_circref(void)
3153 menu1 = CreatePopupMenu();
3154 menu2 = CreatePopupMenu();
3155 ok( menu1 && menu2, "error creating menus.\n");
3156 ret = AppendMenuA( menu1, MF_POPUP, (UINT_PTR)menu2, "winetest");
3157 ok( ret, "AppendMenu failed, error is %d\n", GetLastError());
3158 ret = AppendMenuA( menu1, MF_STRING | MF_HILITE, 123, "winetest");
3159 ok( ret, "AppendMenu failed, error is %d\n", GetLastError());
3160 /* app chooses an id that happens to clash with its own hmenu */
3161 ret = AppendMenuA( menu2, MF_STRING, (UINT_PTR)menu2, "winetest");
3162 ok( ret, "AppendMenu failed, error is %d\n", GetLastError());
3163 /* now attempt to change the string of the first item of menu1 */
3164 ret = ModifyMenuA( menu1, (UINT_PTR)menu2, MF_POPUP, (UINT_PTR)menu2, "menu 2");
3166 broken( ret), /* win98, NT */
3167 "ModifyMenu should have failed.\n");
3168 if( !ret) { /* will probably stack fault if the ModifyMenu succeeded */
3169 ret = GetMenuState( menu1, 123, 0);
3170 ok( ret == MF_HILITE, "GetMenuState returned %x\n",ret);
3172 DestroyMenu( menu2);
3173 DestroyMenu( menu1);
3176 /* test how the menu texts are aligned when the menu items have
3177 * different combinations of text and bitmaps (bug #13350) */
3178 static void test_menualign(void)
3182 HBITMAP hbm1, hbm2, hbm3;
3183 MENUITEMINFO mii = { sizeof(MENUITEMINFO)};
3186 MENUINFO mi = { sizeof( MENUINFO)};
3188 if( !winetest_interactive) {
3189 skip( "interactive alignment tests.\n");
3192 hwnd = CreateWindowEx(0,
3194 "Menu text alignment Test\nPlease make a selection.",
3195 WS_OVERLAPPEDWINDOW,
3198 NULL, NULL, 0, NULL);
3199 ShowWindow( hwnd, SW_SHOW);
3200 /* create bitmaps */
3201 memset( bmfill, 0xcc, sizeof( bmfill));
3202 hbm1 = CreateBitmap( 10,10,1,1,bmfill);
3203 hbm2 = CreateBitmap( 20,20,1,1,bmfill);
3204 hbm3 = CreateBitmap( 50,6,1,1,bmfill);
3205 ok( hbm1 && hbm2 && hbm3, "Creating bitmaps failed\n");
3206 menu = CreatePopupMenu();
3207 ok( menu != NULL, "CreatePopupMenu() failed\n");
3209 mi.fMask = MIM_STYLE;
3210 ret = pGetMenuInfo( menu, &mi);
3211 ok( ret, "GetMenuInfo failed: %d\n", GetLastError());
3212 ok( menu != NULL, "GetMenuInfo() failed\n");
3213 ok( 0 == mi.dwStyle, "menuinfo style is %x\n", mi.dwStyle);
3216 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3218 mii.hbmpItem = hbm1;
3219 mii.dwTypeData = (LPSTR) " OK: menu texts are correctly left-aligned.";
3220 ret = InsertMenuItem( menu, -1, TRUE, &mii);
3221 ok( ret, "InsertMenuItem() failed\n");
3222 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID ;
3224 mii.hbmpItem = hbm2;
3225 mii.dwTypeData = (LPSTR) " FAIL: menu texts are NOT left-aligned.";
3226 ret = InsertMenuItem( menu, -1, TRUE, &mii);
3227 ok( ret, "InsertMenuItem() failed\n");
3228 ret = TrackPopupMenu( menu, TPM_RETURNCMD, 110, 200, 0, hwnd, NULL);
3229 ok( ret != 2, "User indicated that menu text alignment test 1 failed %d\n", ret);
3231 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3233 mii.hbmpItem = hbm3;
3234 mii.dwTypeData = NULL;
3235 ret = InsertMenuItem( menu, 0, TRUE, &mii);
3236 ok( ret, "InsertMenuItem() failed\n");
3237 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3239 mii.hbmpItem = hbm1;
3240 /* make the text a bit longer, to keep it readable */
3241 /* this bug is on winXP and reproduced on wine */
3242 mii.dwTypeData = (LPSTR) " OK: menu texts are to the right of the bitmaps........";
3243 ret = SetMenuItemInfo( menu, 1, TRUE, &mii);
3244 ok( ret, "SetMenuItemInfo() failed\n");
3246 mii.hbmpItem = hbm2;
3247 mii.dwTypeData = (LPSTR) " FAIL: menu texts are below the first bitmap. ";
3248 ret = SetMenuItemInfo( menu, 2, TRUE, &mii);
3249 ok( ret, "SetMenuItemInfo() failed\n");
3250 ret = TrackPopupMenu( menu, TPM_RETURNCMD, 110, 200, 0, hwnd, NULL);
3251 ok( ret != 2, "User indicated that menu text alignment test 2 failed %d\n", ret);
3253 mii.fMask = MIIM_TYPE | MIIM_ID;
3255 mii.fType = MFT_BITMAP;
3256 mii.dwTypeData = (LPSTR) hbm3;
3257 ret = SetMenuItemInfo( menu, 0, TRUE, &mii);
3258 ok( ret, "SetMenuItemInfo() failed\n");
3259 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3261 mii.hbmpItem = NULL;
3262 mii.dwTypeData = (LPSTR) " OK: menu texts are below the bitmap.";
3263 ret = SetMenuItemInfo( menu, 1, TRUE, &mii);
3264 ok( ret, "SetMenuItemInfo() failed\n");
3266 mii.hbmpItem = NULL;
3267 mii.dwTypeData = (LPSTR) " FAIL: menu texts are NOT below the bitmap.";
3268 ret = SetMenuItemInfo( menu, 2, TRUE, &mii);
3269 ok( ret, "SetMenuItemInfo() failed\n");
3270 ret = TrackPopupMenu( menu, TPM_RETURNCMD, 110, 200, 0, hwnd, NULL);
3271 ok( ret != 2, "User indicated that menu text alignment test 3 failed %d\n", ret);
3273 DeleteObject( hbm1);
3274 DeleteObject( hbm2);
3275 DeleteObject( hbm3);
3277 DestroyWindow( hwnd);
3282 init_function_pointers();
3284 /* Wine defines MENUITEMINFO for W2K and above. NT4 and below can't
3287 if (correct_behavior())
3289 test_menu_add_string();
3290 test_menu_iteminfo();
3291 test_menu_search_bycommand();
3292 test_CheckMenuRadioItem();
3293 test_menu_resource_layout();
3298 register_menu_check_class();
3300 test_menu_locked_by_window();
3301 test_subpopup_locked_by_menu();
3302 test_menu_ownerdraw();
3303 test_menu_bmp_and_string();
3304 test_menu_getmenuinfo();
3305 test_menu_setmenuinfo();
3309 test_menu_hilitemenuitem();
3310 test_menu_trackpopupmenu();
3311 test_menu_trackagain();
3312 test_menu_cancelmode();
3313 test_menu_maxdepth();
3314 test_menu_circref();