push 8b07bf1f08b23b9893a622b47d2be359556765b1
[wine/hacks.git] / dlls / user32 / tests / menu.c
blob56535ae40dd62fd410c45bcff9c3dd52c513d306
1 /*
2 * Unit tests for menus
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
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <assert.h>
29 #define OEMRESOURCE /* For OBM_MNARROW */
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
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); \
51 if(!p ## func) \
52 trace("GetProcAddress(%s) failed\n", #func);
54 GET_PROC(GetMenuInfo)
55 GET_PROC(SendInput)
56 GET_PROC(SetMenuInfo)
57 GET_PROC(EndMenu)
59 #undef GET_PROC
62 static BOOL correct_behavior(void)
64 HMENU hmenu;
65 MENUITEMINFO info;
66 BOOL rc;
68 hmenu = CreateMenu();
70 memset(&info, 0, sizeof(MENUITEMINFO));
71 info.cbSize= sizeof(MENUITEMINFO);
72 SetLastError(0xdeadbeef);
73 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info);
74 /* Win9x : 0xdeadbeef
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");
81 DestroyMenu(hmenu);
82 return FALSE;
85 DestroyMenu(hmenu);
86 return TRUE;
89 static LRESULT WINAPI menu_check_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
91 switch (msg)
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
104 * our own type */
105 typedef struct
107 DWORD type;
108 union
110 MOUSEINPUT mi;
111 KEYBDINPUT ki;
112 HARDWAREINPUT hi;
113 } u;
114 } TEST_INPUT;
116 /* globals to communicate between test and wndproc */
118 static BOOL bMenuVisible;
119 static BOOL got_input;
120 static HMENU hMenus[4];
122 #define MOD_SIZE 10
123 #define MOD_NRMENUS 8
125 /* menu texts with their sizes */
126 static struct {
127 LPCSTR text;
128 SIZE size; /* size of text up to any \t */
129 SIZE sc_size; /* size of the short-cut */
130 } MOD_txtsizes[] = {
131 { "Pinot &Noir" },
132 { "&Merlot\bF4" },
133 { "Shira&z\tAlt+S" },
134 { "" },
135 { NULL }
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,
146 gflag_entermenuloop,
147 gflag_initmenu;
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;
154 switch (msg)
156 case WM_INITMENUPOPUP:
157 gflag_initmenupopup++;
158 hmenupopup = (HMENU) wparam;
159 break;
160 case WM_ENTERMENULOOP:
161 gflag_entermenuloop++;
162 break;
163 case WM_INITMENU:
164 gflag_initmenu++;
165 break;
166 case WM_MEASUREITEM:
168 MEASUREITEMSTRUCT* pmis = (MEASUREITEMSTRUCT*)lparam;
169 if( winetest_debug)
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;
175 return TRUE;
177 case WM_DRAWITEM:
179 DRAWITEMSTRUCT * pdis;
180 TEXTMETRIC tm;
181 HPEN oldpen;
182 char chrs[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
183 SIZE sz;
184 int i;
185 pdis = (DRAWITEMSTRUCT *) lparam;
186 if( winetest_debug) {
187 RECT rc;
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++) {
203 char buf[100], *p;
204 RECT rc={0,0,0,0};
205 strcpy( buf, MOD_txtsizes[i].text);
206 if( ( p = strchr( buf, '\t'))) {
207 *p = '\0';
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;
228 return TRUE;
230 case WM_ENTERIDLE:
232 ok( lparam || broken(!lparam), /* win9x, nt4 */
233 "Menu window handle is NULL!\n");
234 if( lparam) {
235 HMENU hmenu = (HMENU)SendMessageA( (HWND)lparam, MN_GETHMENU, 0, 0);
236 ok( hmenupopup == hmenu, "MN_GETHMENU returns %p expected %p\n",
237 hmenu, hmenupopup);
239 PostMessage(hwnd, WM_CANCELMODE, 0, 0);
240 return TRUE;
244 return DefWindowProc(hwnd, msg, wparam, lparam);
247 static void register_menu_check_class(void)
249 WNDCLASS wc =
252 menu_check_wnd_proc,
255 GetModuleHandle(NULL),
256 NULL,
257 LoadCursor(NULL, IDC_ARROW),
258 (HBRUSH)(COLOR_BTNFACE+1),
259 NULL,
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)
270 BOOL ret;
271 HMENU hmenu;
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);
286 todo_wine {
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);
295 todo_wine {
296 ok(ret, "WM_INITMENU should have been sent\n");
299 DestroyWindow(hwnd);
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)
306 HWND hwndmenu;
307 switch (msg)
309 case WM_ENTERIDLE:
310 hwndmenu = GetCapture();
311 if( hwndmenu) {
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)
322 DWORD gle;
323 BOOL ret;
324 HMENU hmenu, hsubmenu;
325 MENUINFO mi = { sizeof( MENUINFO)};
326 MENUITEMINFO mii = { sizeof( MENUITEMINFO)};
327 HWND hwnd;
328 const int itemid = 0x1234567;
329 if( !pGetMenuInfo)
331 win_skip("GetMenuInfo is not available\n");
332 return;
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, 0x100, 100,100, 0, hwnd, NULL);
361 if( ret == (itemid & 0xffff)) {
362 win_skip("not on 16 bit menu subsystem\n");
363 DestroyMenu( hsubmenu);
364 } else {
365 gle = GetLastError();
366 ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, gle);
367 ok( gle == 0 ||
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, 0x100, 100,100, 0, hwnd, NULL);
388 gle = GetLastError();
389 todo_wine {
390 ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, gle);
392 ok( gle == 0 ||
393 broken( gle == ERROR_INVALID_PARAMETER), /* win2k0 */
394 "Last error is %d\n", gle);
396 /* clean up */
397 DestroyMenu( hmenu);
398 DestroyWindow(hwnd);
401 static void test_menu_ownerdraw(void)
403 int i,j,k;
404 BOOL ret;
405 HMENU hmenu;
406 LONG leftcol;
407 HWND hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
408 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
409 NULL, NULL, NULL, NULL);
410 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
411 if( !hwnd) return;
412 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
413 hmenu = CreatePopupMenu();
414 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
415 if( !hmenu) { DestroyWindow(hwnd);return;}
416 k=0;
417 for( j=0;j<2;j++) /* create columns */
418 for(i=0;i<2;i++) { /* create rows */
419 ret = AppendMenu( hmenu, MF_OWNERDRAW |
420 (i==0 ? MF_MENUBREAK : 0), k, MAKEINTRESOURCE(k));
421 k++;
422 ok( ret, "AppendMenu failed for %d\n", k-1);
424 MOD_maxid = k-1;
425 assert( k <= sizeof(MOD_rc)/sizeof(RECT));
426 /* display the menu */
427 ret = TrackPopupMenu( hmenu, 0x100, 100,100, 0, hwnd, NULL);
429 /* columns have a 4 pixel gap between them */
430 ok( MOD_rc[0].right + 4 == MOD_rc[2].left,
431 "item rectangles are not separated by 4 pixels space\n");
432 /* height should be what the MEASUREITEM message has returned */
433 ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
434 "menu item has wrong height: %d should be %d\n",
435 MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
436 /* no gaps between the rows */
437 ok( MOD_rc[0].bottom - MOD_rc[1].top == 0,
438 "There should not be a space between the rows, gap is %d\n",
439 MOD_rc[0].bottom - MOD_rc[1].top);
440 /* test the correct value of the item height that was sent
441 * by the WM_MEASUREITEM message */
442 ok( MOD_odheight == HIWORD( GetDialogBaseUnits()) || /* WinNT,2k,XP */
443 MOD_odheight == MOD_hic, /* Win95,98,ME */
444 "Wrong height field in MEASUREITEMSTRUCT, expected %d or %d actual %d\n",
445 HIWORD( GetDialogBaseUnits()), MOD_hic, MOD_odheight);
446 /* test what MF_MENUBREAK did at the first position. Also show
447 * that an MF_SEPARATOR is ignored in the height calculation. */
448 leftcol= MOD_rc[0].left;
449 ModifyMenu( hmenu, 0, MF_BYCOMMAND| MF_OWNERDRAW| MF_SEPARATOR, 0, 0);
450 /* display the menu */
451 ret = TrackPopupMenu( hmenu, 0x100, 100,100, 0, hwnd, NULL);
452 /* left should be 4 pixels less now */
453 ok( leftcol == MOD_rc[0].left + 4,
454 "columns should be 4 pixels to the left (actual %d).\n",
455 leftcol - MOD_rc[0].left);
456 /* test width */
457 ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
458 "width of owner drawn menu item is wrong. Got %d expected %d\n",
459 MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
460 /* and height */
461 ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
462 "Height is incorrect. Got %d expected %d\n",
463 MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
465 /* test width/height of an ownerdraw menu bar as well */
466 ret = DestroyMenu(hmenu);
467 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
468 hmenu = CreateMenu();
469 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
470 if( !hmenu) { DestroyWindow(hwnd);return;}
471 MOD_maxid=1;
472 for(i=0;i<2;i++) {
473 ret = AppendMenu( hmenu, MF_OWNERDRAW , i, 0);
474 ok( ret, "AppendMenu failed for %d\n", i);
476 ret = SetMenu( hwnd, hmenu);
477 UpdateWindow( hwnd); /* hack for wine to draw the window + menu */
478 ok(ret, "SetMenu failed with error %d\n", GetLastError());
479 /* test width */
480 ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
481 "width of owner drawn menu item is wrong. Got %d expected %d\n",
482 MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
483 /* test hight */
484 ok( MOD_rc[0].bottom - MOD_rc[0].top == GetSystemMetrics( SM_CYMENU) - 1,
485 "Height of owner drawn menu item is wrong. Got %d expected %d\n",
486 MOD_rc[0].bottom - MOD_rc[0].top, GetSystemMetrics( SM_CYMENU) - 1);
488 /* clean up */
489 ret = DestroyMenu(hmenu);
490 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
491 DestroyWindow(hwnd);
494 /* helper for test_menu_bmp_and_string() */
495 static void test_mbs_help( int ispop, int hassub, int mnuopt,
496 HWND hwnd, int arrowwidth, int count, HBITMAP hbmp,
497 SIZE bmpsize, LPCSTR text, SIZE size, SIZE sc_size)
499 BOOL ret;
500 HMENU hmenu, submenu;
501 MENUITEMINFO mii={ sizeof( MENUITEMINFO )};
502 MENUINFO mi;
503 RECT rc;
504 CHAR text_copy[16];
505 int hastab, expect;
506 int failed = 0;
508 MOD_GotDrawItemMsg = FALSE;
509 mii.fMask = MIIM_FTYPE | MIIM_DATA | MIIM_STATE;
510 mii.fType = 0;
511 /* check the menu item unless MNS_CHECKORBMP is set */
512 mii.fState = (mnuopt != 2 ? MFS_CHECKED : MFS_UNCHECKED);
513 mii.dwItemData =0;
514 MODsizes[0] = bmpsize;
515 hastab = 0;
516 if( text ) {
517 char *p;
518 mii.fMask |= MIIM_STRING;
519 strcpy(text_copy, text);
520 mii.dwTypeData = text_copy; /* structure member declared non-const */
521 if( ( p = strchr( text, '\t'))) {
522 hastab = *(p + 1) ? 2 : 1;
525 /* tabs don't make sense in menubars */
526 if(hastab && !ispop) return;
527 if( hbmp) {
528 mii.fMask |= MIIM_BITMAP;
529 mii.hbmpItem = hbmp;
531 submenu = CreateMenu();
532 ok( submenu != 0, "CreateMenu failed with error %d\n", GetLastError());
533 if( ispop)
534 hmenu = CreatePopupMenu();
535 else
536 hmenu = CreateMenu();
537 ok( hmenu != 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
538 if( hassub) {
539 mii.fMask |= MIIM_SUBMENU;
540 mii.hSubMenu = submenu;
542 if( mnuopt) {
543 mi.cbSize = sizeof(mi);
544 mi.fMask = MIM_STYLE;
545 pGetMenuInfo( hmenu, &mi);
546 if( mnuopt) mi.dwStyle |= mnuopt == 1 ? MNS_NOCHECK : MNS_CHECKORBMP;
547 ret = pSetMenuInfo( hmenu, &mi);
548 ok( ret, "SetMenuInfo failed with error %d\n", GetLastError());
550 ret = InsertMenuItem( hmenu, 0, FALSE, &mii);
551 ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
552 failed = !ret;
553 if( winetest_debug) {
554 HDC hdc=GetDC(hwnd);
555 RECT rc = {100, 50, 400, 70};
556 char buf[100];
558 sprintf( buf,"%d text \"%s\" mnuopt %d", count, text ? text: "(nil)", mnuopt);
559 FillRect( hdc, &rc, (HBRUSH) COLOR_WINDOW);
560 TextOut( hdc, 10, 50, buf, strlen( buf));
561 ReleaseDC( hwnd, hdc);
563 if(ispop)
564 ret = TrackPopupMenu( hmenu, 0x100, 100,100, 0, hwnd, NULL);
565 else {
566 ret = SetMenu( hwnd, hmenu);
567 ok(ret, "SetMenu failed with error %d\n", GetLastError());
568 DrawMenuBar( hwnd);
570 ret = GetMenuItemRect( hwnd, hmenu, 0, &rc);
571 if (0) /* comment out menu size checks, behavior is different in almost every Windows version */
572 /* the tests should however succeed on win2000, XP and Wine (at least up to 1.1.15) */
573 /* with a variety of dpis and desktop font sizes */
575 /* check menu width */
576 if( ispop)
577 expect = ( text || hbmp ?
578 4 + (mnuopt != 1 ? GetSystemMetrics(SM_CXMENUCHECK) : 0)
579 : 0) +
580 arrowwidth + MOD_avec + (hbmp ?
581 ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ? bmpsize.cx + 2 : GetSystemMetrics( SM_CXMENUSIZE) + 2)
582 : 0) +
583 (text && hastab ? /* TAB space */
584 MOD_avec + ( hastab==2 ? sc_size.cx : 0) : 0) +
585 (text ? 2 + (text[0] ? size.cx :0): 0) ;
586 else
587 expect = !(text || hbmp) ? 0 :
588 ( hbmp ? (text ? 2:0) + bmpsize.cx : 0 ) +
589 (text ? 2 * MOD_avec + (text[0] ? size.cx :0): 0) ;
590 ok( rc.right - rc.left == expect,
591 "menu width wrong, got %d expected %d\n", rc.right - rc.left, expect);
592 failed = failed || !(rc.right - rc.left == expect);
593 /* check menu height */
594 if( ispop)
595 expect = max( ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 : 0),
596 max( (text ? max( 2 + size.cy, MOD_hic + 4) : 0),
597 (hbmp ?
598 ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ?
599 bmpsize.cy + 2
600 : GetSystemMetrics( SM_CYMENUSIZE) + 2)
601 : 0)));
602 else
603 expect = ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 :
604 max( GetSystemMetrics( SM_CYMENU) - 1, (hbmp ? bmpsize.cy : 0)));
605 ok( rc.bottom - rc.top == expect,
606 "menu height wrong, got %d expected %d (%d)\n",
607 rc.bottom - rc.top, expect, GetSystemMetrics( SM_CYMENU));
608 failed = failed || !(rc.bottom - rc.top == expect);
609 if( hbmp == HBMMENU_CALLBACK && MOD_GotDrawItemMsg) {
610 /* check the position of the bitmap */
611 /* horizontal */
612 if (!ispop)
613 expect = 3;
614 else if (mnuopt == 0)
615 expect = 4 + GetSystemMetrics(SM_CXMENUCHECK);
616 else if (mnuopt == 1)
617 expect = 4;
618 else /* mnuopt == 2 */
619 expect = 2;
620 ok( expect == MOD_rc[0].left,
621 "bitmap left is %d expected %d\n", MOD_rc[0].left, expect);
622 failed = failed || !(expect == MOD_rc[0].left);
623 /* vertical */
624 expect = (rc.bottom - rc.top - MOD_rc[0].bottom + MOD_rc[0].top) / 2;
625 ok( expect == MOD_rc[0].top,
626 "bitmap top is %d expected %d\n", MOD_rc[0].top, expect);
627 failed = failed || !(expect == MOD_rc[0].top);
630 /* if there was a failure, report details */
631 if( failed) {
632 trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
633 count, (ispop? "POPUP": "MENUBAR"),text ? text: "(nil)", hbmp, bmpsize.cx, bmpsize.cy,
634 size.cx, size.cy, sc_size.cx, mnuopt, hastab);
635 trace(" check %d,%d arrow %d avechar %d\n",
636 GetSystemMetrics(SM_CXMENUCHECK ),
637 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
638 if( hbmp == HBMMENU_CALLBACK)
639 trace( " rc %d,%d-%d,%d bmp.rc %d,%d-%d,%d\n",
640 rc.left, rc.top, rc.top, rc.bottom, MOD_rc[0].left,
641 MOD_rc[0].top,MOD_rc[0].right, MOD_rc[0].bottom);
643 /* clean up */
644 ret = DestroyMenu(submenu);
645 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
646 ret = DestroyMenu(hmenu);
647 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
651 static void test_menu_bmp_and_string(void)
653 BYTE bmfill[300];
654 HBITMAP hbm_arrow;
655 BITMAP bm;
656 INT arrowwidth;
657 HWND hwnd;
658 HMENU hsysmenu;
659 MENUINFO mi= {sizeof(MENUINFO)};
660 MENUITEMINFOA mii= {sizeof(MENUITEMINFOA)};
661 int count, szidx, txtidx, bmpidx, hassub, mnuopt, ispop;
663 if( !pGetMenuInfo)
665 win_skip("GetMenuInfo is not available\n");
666 return;
669 memset( bmfill, 0xcc, sizeof( bmfill));
670 hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL, WS_SYSMENU |
671 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
672 NULL, NULL, NULL, NULL);
673 hbm_arrow=LoadBitmap( 0, (CHAR*)OBM_MNARROW);
674 GetObject( hbm_arrow, sizeof(bm), &bm);
675 arrowwidth = bm.bmWidth;
676 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
677 if( !hwnd) return;
678 /* test system menu */
679 hsysmenu = GetSystemMenu( hwnd, FALSE);
680 ok( hsysmenu != NULL, "GetSystemMenu failed with error %d\n", GetLastError());
681 mi.fMask = MIM_STYLE;
682 mi.dwStyle = 0;
683 ok( pGetMenuInfo( hsysmenu, &mi), "GetMenuInfo failed gle=%d\n", GetLastError());
684 ok( MNS_CHECKORBMP == mi.dwStyle, "System Menu Style is %08x, without the bit %08x\n",
685 mi.dwStyle, MNS_CHECKORBMP);
686 mii.fMask = MIIM_BITMAP;
687 mii.hbmpItem = NULL;
688 ok( GetMenuItemInfoA( hsysmenu, SC_CLOSE, FALSE, &mii), "GetMenuItemInfoA failed gle=%d\n", GetLastError());
689 ok( HBMMENU_POPUP_CLOSE == mii.hbmpItem, "Item info did not get the right hbitmap: got %p expected %p\n",
690 mii.hbmpItem, HBMMENU_POPUP_CLOSE);
692 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
694 if( winetest_debug)
695 trace(" check %d,%d arrow %d avechar %d\n",
696 GetSystemMetrics(SM_CXMENUCHECK ),
697 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
698 count = 0;
699 MOD_maxid = 0;
700 for( ispop=1; ispop >= 0; ispop--){
701 static SIZE bmsizes[]= {
702 {10,10},{38,38},{1,30},{55,5}};
703 for( szidx=0; szidx < sizeof( bmsizes) / sizeof( SIZE); szidx++) {
704 HBITMAP hbm = CreateBitmap( bmsizes[szidx].cx, bmsizes[szidx].cy,1,1,bmfill);
705 HBITMAP bitmaps[] = { HBMMENU_CALLBACK, hbm, HBMMENU_POPUP_CLOSE, NULL };
706 ok( hbm != 0, "CreateBitmap failed err %d\n", GetLastError());
707 for( txtidx = 0; txtidx < sizeof(MOD_txtsizes)/sizeof(MOD_txtsizes[0]); txtidx++) {
708 for( hassub = 0; hassub < 2 ; hassub++) { /* add submenu item */
709 for( mnuopt = 0; mnuopt < 3 ; mnuopt++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
710 for( bmpidx = 0; bmpidx <sizeof(bitmaps)/sizeof(HBITMAP); bmpidx++) {
711 /* no need to test NULL bitmaps of several sizes */
712 if( !bitmaps[bmpidx] && szidx > 0) continue;
713 /* the HBMMENU_POPUP not to test for menu bars */
714 if( !ispop &&
715 bitmaps[bmpidx] >= HBMMENU_POPUP_CLOSE &&
716 bitmaps[bmpidx] <= HBMMENU_POPUP_MINIMIZE) continue;
717 if( !ispop && hassub) continue;
718 test_mbs_help( ispop, hassub, mnuopt,
719 hwnd, arrowwidth, ++count,
720 bitmaps[bmpidx],
721 bmsizes[szidx],
722 MOD_txtsizes[txtidx].text,
723 MOD_txtsizes[txtidx].size,
724 MOD_txtsizes[txtidx].sc_size);
729 DeleteObject( hbm);
732 /* clean up */
733 DestroyWindow(hwnd);
736 static void test_menu_add_string( void )
738 HMENU hmenu;
739 MENUITEMINFO info;
740 BOOL rc;
741 int ret;
743 char string[0x80];
744 char string2[0x80];
746 char strback[0x80];
747 WCHAR strbackW[0x80];
748 static CHAR blah[] = "blah";
749 static const WCHAR expectedString[] = {'D','u','m','m','y',' ','s','t','r','i','n','g', 0};
751 hmenu = CreateMenu();
753 memset( &info, 0, sizeof info );
754 info.cbSize = sizeof info;
755 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_ID;
756 info.dwTypeData = blah;
757 info.cch = 6;
758 info.dwItemData = 0;
759 info.wID = 1;
760 info.fState = 0;
761 InsertMenuItem(hmenu, 0, TRUE, &info );
763 memset( &info, 0, sizeof info );
764 info.cbSize = sizeof info;
765 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_DATA | MIIM_ID;
766 info.dwTypeData = string;
767 info.cch = sizeof string;
768 string[0] = 0;
769 GetMenuItemInfo( hmenu, 0, TRUE, &info );
771 ok( !strcmp( string, "blah" ), "menu item name differed\n");
773 /* Test combination of ownerdraw and strings with GetMenuItemString(A/W) */
774 strcpy(string, "Dummy string");
775 memset(&info, 0x00, sizeof(info));
776 info.cbSize= sizeof(MENUITEMINFO);
777 info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
778 info.fType= MFT_OWNERDRAW;
779 info.dwTypeData= string;
780 rc = InsertMenuItem( hmenu, 0, TRUE, &info );
781 ok (rc, "InsertMenuItem failed\n");
783 strcpy(string,"Garbage");
784 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
785 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
787 SetLastError(0xdeadbeef);
788 ret = GetMenuStringW( hmenu, 0, strbackW, 99, MF_BYPOSITION );
789 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
790 win_skip("GetMenuStringW is not implemented\n");
791 else
793 ok (ret, "GetMenuStringW on ownerdraw entry failed\n");
794 ok (!lstrcmpW( strbackW, expectedString ), "Menu text from Unicode version incorrect\n");
797 /* Just change ftype to string and see what text is stored */
798 memset(&info, 0x00, sizeof(info));
799 info.cbSize= sizeof(MENUITEMINFO);
800 info.fMask= MIIM_FTYPE; /* Set string type */
801 info.fType= MFT_STRING;
802 info.dwTypeData= (char *)0xdeadbeef;
803 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
804 ok (rc, "SetMenuItemInfo failed\n");
806 /* Did we keep the old dwTypeData? */
807 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
808 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
810 /* Ensure change to bitmap type fails */
811 memset(&info, 0x00, sizeof(info));
812 info.cbSize= sizeof(MENUITEMINFO);
813 info.fMask= MIIM_FTYPE; /* Set as bitmap type */
814 info.fType= MFT_BITMAP;
815 info.dwTypeData= (char *)0xdeadbee2;
816 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
817 ok (!rc, "SetMenuItemInfo unexpectedly worked\n");
819 /* Just change ftype back and ensure data hasn't been freed */
820 info.fType= MFT_OWNERDRAW; /* Set as ownerdraw type */
821 info.dwTypeData= (char *)0xdeadbee3;
822 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
823 ok (rc, "SetMenuItemInfo failed\n");
825 /* Did we keep the old dwTypeData? */
826 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
827 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
829 /* Just change string value (not type) */
830 memset(&info, 0x00, sizeof(info));
831 info.cbSize= sizeof(MENUITEMINFO);
832 info.fMask= MIIM_STRING; /* Set typeData */
833 strcpy(string2, "string2");
834 info.dwTypeData= string2;
835 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
836 ok (rc, "SetMenuItemInfo failed\n");
838 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
839 ok (!strcmp( strback, "string2" ), "Menu text from Ansi version incorrect\n");
841 /* crashes with wine 0.9.5 */
842 memset(&info, 0x00, sizeof(info));
843 info.cbSize= sizeof(MENUITEMINFO);
844 info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
845 info.fType= MFT_OWNERDRAW;
846 rc = InsertMenuItem( hmenu, 0, TRUE, &info );
847 ok (rc, "InsertMenuItem failed\n");
848 ok (!GetMenuString( hmenu, 0, NULL, 0, MF_BYPOSITION),
849 "GetMenuString on ownerdraw entry succeeded.\n");
850 SetLastError(0xdeadbeef);
851 ret = GetMenuStringW( hmenu, 0, NULL, 0, MF_BYPOSITION);
852 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
853 win_skip("GetMenuStringW is not implemented\n");
854 else
855 ok (!ret, "GetMenuStringW on ownerdraw entry succeeded.\n");
857 DestroyMenu( hmenu );
860 /* define building blocks for the menu item info tests */
861 static int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
863 if (n <= 0) return 0;
864 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
865 return *str1 - *str2;
868 static WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
870 WCHAR *p = dst;
871 while ((*p++ = *src++));
872 return dst;
875 static void insert_menu_item( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state, UINT id,
876 HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
877 void *type_data, UINT len, HBITMAP item, BOOL expect )
879 MENUITEMINFOA info;
880 BOOL ret;
882 /* magic bitmap handle to test smaller cbSize */
883 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
884 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
885 else
886 info.cbSize = sizeof(info);
887 info.fMask = mask;
888 info.fType = type;
889 info.fState = state;
890 info.wID = id;
891 info.hSubMenu = submenu;
892 info.hbmpChecked = checked;
893 info.hbmpUnchecked = unchecked;
894 info.dwItemData = data;
895 info.dwTypeData = type_data;
896 info.cch = len;
897 info.hbmpItem = item;
898 SetLastError( 0xdeadbeef );
899 if (ansi) ret = InsertMenuItemA( hmenu, 0, TRUE, &info );
900 else ret = InsertMenuItemW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
901 if (!expect) ok_(__FILE__, line)( !ret, "InsertMenuItem should have failed.\n" );
902 else ok_(__FILE__, line)( ret, "InsertMenuItem failed, err %u\n", GetLastError());
905 static void check_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
906 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked,
907 ULONG_PTR data, void *type_data, UINT in_len, UINT out_len,
908 HBITMAP item, LPCSTR expname, BOOL expect, BOOL expstring )
910 MENUITEMINFOA info;
911 BOOL ret;
912 WCHAR buffer[80];
914 SetLastError( 0xdeadbeef );
915 memset( &info, 0xcc, sizeof(info) );
916 info.cbSize = sizeof(info);
917 info.fMask = mask;
918 info.dwTypeData = type_data;
919 info.cch = in_len;
921 ret = ansi ? GetMenuItemInfoA( hmenu, 0, TRUE, &info ) :
922 GetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW *)&info );
923 if (!expect)
925 ok_(__FILE__, line)( !ret, "GetMenuItemInfo should have failed.\n" );
926 return;
928 ok_(__FILE__, line)( ret, "GetMenuItemInfo failed, err %u\n", GetLastError());
929 if (mask & MIIM_TYPE)
930 ok_(__FILE__, line)( info.fType == type || info.fType == LOWORD(type),
931 "wrong type %x/%x\n", info.fType, type );
932 if (mask & MIIM_STATE)
933 ok_(__FILE__, line)( info.fState == state || info.fState == LOWORD(state),
934 "wrong state %x/%x\n", info.fState, state );
935 if (mask & MIIM_ID)
936 ok_(__FILE__, line)( info.wID == id || info.wID == LOWORD(id),
937 "wrong id %x/%x\n", info.wID, id );
938 if (mask & MIIM_SUBMENU)
939 ok_(__FILE__, line)( info.hSubMenu == submenu || (ULONG_PTR)info.hSubMenu == LOWORD(submenu),
940 "wrong submenu %p/%p\n", info.hSubMenu, submenu );
941 if (mask & MIIM_CHECKMARKS)
943 ok_(__FILE__, line)( info.hbmpChecked == checked || (ULONG_PTR)info.hbmpChecked == LOWORD(checked),
944 "wrong bmpchecked %p/%p\n", info.hbmpChecked, checked );
945 ok_(__FILE__, line)( info.hbmpUnchecked == unchecked || (ULONG_PTR)info.hbmpUnchecked == LOWORD(unchecked),
946 "wrong bmpunchecked %p/%p\n", info.hbmpUnchecked, unchecked );
948 if (mask & MIIM_DATA)
949 ok_(__FILE__, line)( info.dwItemData == data || info.dwItemData == LOWORD(data),
950 "wrong item data %lx/%lx\n", info.dwItemData, data );
951 if (mask & MIIM_BITMAP)
952 ok_(__FILE__, line)( info.hbmpItem == item || (ULONG_PTR)info.hbmpItem == LOWORD(item),
953 "wrong bmpitem %p/%p\n", info.hbmpItem, item );
954 ok_(__FILE__, line)( info.dwTypeData == type_data || (ULONG_PTR)info.dwTypeData == LOWORD(type_data),
955 "wrong type data %p/%p\n", info.dwTypeData, type_data );
956 ok_(__FILE__, line)( info.cch == out_len, "wrong len %x/%x\n", info.cch, out_len );
957 if (expname)
959 if(ansi)
960 ok_(__FILE__, line)( !strncmp( expname, info.dwTypeData, out_len ),
961 "menu item name differed from '%s' '%s'\n", expname, info.dwTypeData );
962 else
963 ok_(__FILE__, line)( !strncmpW( (WCHAR *)expname, (WCHAR *)info.dwTypeData, out_len ),
964 "menu item name wrong\n" );
966 SetLastError( 0xdeadbeef );
967 ret = ansi ? GetMenuStringA( hmenu, 0, (char *)buffer, 80, MF_BYPOSITION ) :
968 GetMenuStringW( hmenu, 0, buffer, 80, MF_BYPOSITION );
969 if (expstring)
970 ok_(__FILE__, line)( ret, "GetMenuString failed, err %u\n", GetLastError());
971 else
972 ok_(__FILE__, line)( !ret, "GetMenuString should have failed\n" );
976 static void modify_menu( int line, HMENU hmenu, BOOL ansi, UINT flags, UINT_PTR id, void *data )
978 BOOL ret;
980 SetLastError( 0xdeadbeef );
981 if (ansi) ret = ModifyMenuA( hmenu, 0, flags, id, data );
982 else ret = ModifyMenuW( hmenu, 0, flags, id, data );
983 ok_(__FILE__,line)( ret, "ModifyMenuA failed, err %u\n", GetLastError());
986 static void set_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
987 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
988 void *type_data, UINT len, HBITMAP item )
991 MENUITEMINFOA info;
992 BOOL ret;
994 /* magic bitmap handle to test smaller cbSize */
995 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
996 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
997 else
998 info.cbSize = sizeof(info);
999 info.fMask = mask;
1000 info.fType = type;
1001 info.fState = state;
1002 info.wID = id;
1003 info.hSubMenu = submenu;
1004 info.hbmpChecked = checked;
1005 info.hbmpUnchecked = unchecked;
1006 info.dwItemData = data;
1007 info.dwTypeData = type_data;
1008 info.cch = len;
1009 info.hbmpItem = item;
1010 SetLastError( 0xdeadbeef );
1011 if (ansi) ret = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1012 else ret = SetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
1013 ok_(__FILE__, line)( ret, "SetMenuItemInfo failed, err %u\n", GetLastError());
1016 #define TMII_INSMI( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,eret1 )\
1017 hmenu = CreateMenu();\
1018 submenu = CreateMenu();\
1019 if(ansi)strcpy( string, init );\
1020 else strcpyW( string, init );\
1021 insert_menu_item( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, eret1 )
1023 /* GetMenuItemInfo + GetMenuString */
1024 #define TMII_GMII( c2,l2,\
1025 d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,\
1026 expname, eret2, eret3)\
1027 check_menu_item_info( __LINE__, hmenu, ansi, c2, d3, e3, f3, g3, h3, i3, j3, k3, l2, l3, m3, \
1028 expname, eret2, eret3 )
1030 #define TMII_DONE \
1031 RemoveMenu(hmenu, 0, TRUE );\
1032 DestroyMenu( hmenu );\
1033 DestroyMenu( submenu );
1035 /* modify menu */
1036 #define TMII_MODM( flags, id, data ) \
1037 modify_menu( __LINE__, hmenu, ansi, flags, id, data )
1039 /* SetMenuItemInfo */
1040 #define TMII_SMII( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1 ) \
1041 set_menu_item_info( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1 )
1044 #define OK 1
1045 #define ER 0
1048 static void test_menu_iteminfo( void )
1050 int ansi = TRUE;
1051 char txtA[]="wine";
1052 char initA[]="XYZ";
1053 char emptyA[]="";
1054 WCHAR txtW[]={'W','i','n','e',0};
1055 WCHAR initW[]={'X','Y','Z',0};
1056 WCHAR emptyW[]={0};
1057 void *txt, *init, *empty, *string;
1058 HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
1059 char stringA[0x80];
1060 HMENU hmenu, submenu=CreateMenu();
1061 HBITMAP dummy_hbm = (HBITMAP)(ULONG_PTR)0xdeadbeef;
1063 do {
1064 if( ansi) {txt=txtA;init=initA;empty=emptyA;string=stringA;}
1065 else {txt=txtW;init=initW;empty=emptyW;string=stringA;}
1066 trace( "%s string %p hbm %p txt %p\n", ansi ? "ANSI tests: " : "Unicode tests:", string, hbm, txt);
1067 /* test all combinations of MFT_STRING, MFT_OWNERDRAW and MFT_BITMAP */
1068 /* (since MFT_STRING is zero, there are four of them) */
1069 TMII_INSMI( MIIM_TYPE, MFT_STRING, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1070 TMII_GMII ( MIIM_TYPE, 80,
1071 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1072 txt, OK, OK );
1073 TMII_DONE
1074 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1075 TMII_GMII ( MIIM_TYPE, 80,
1076 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1077 NULL, OK, ER );
1078 TMII_DONE
1079 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1080 TMII_GMII ( MIIM_TYPE, 80,
1081 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1082 NULL, OK, ER );
1083 TMII_DONE
1084 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1085 TMII_GMII ( MIIM_TYPE, 80,
1086 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1087 NULL, OK, ER );
1088 TMII_DONE
1089 /* not enough space for name*/
1090 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1091 TMII_GMII ( MIIM_TYPE, 0,
1092 MFT_STRING, 0, 0, 0, 0, 0, 0, NULL, 4, 0,
1093 NULL, OK, OK );
1094 TMII_DONE
1095 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1096 TMII_GMII ( MIIM_TYPE, 5,
1097 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1098 txt, OK, OK );
1099 TMII_DONE
1100 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1101 TMII_GMII ( MIIM_TYPE, 4,
1102 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 3, 0,
1103 txt, OK, OK );
1104 TMII_DONE
1105 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1106 TMII_GMII ( MIIM_TYPE, 0,
1107 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, 0,
1108 NULL, OK, ER );
1109 TMII_DONE
1110 /* cannot combine MIIM_TYPE with some other flags */
1111 TMII_INSMI( MIIM_TYPE|MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1112 TMII_DONE
1113 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1114 TMII_GMII ( MIIM_TYPE|MIIM_STRING, 80,
1115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1116 NULL, ER, OK );
1117 TMII_DONE
1118 TMII_INSMI( MIIM_TYPE|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1119 TMII_DONE
1120 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1121 TMII_GMII ( MIIM_TYPE|MIIM_FTYPE, 80,
1122 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1123 NULL, ER, OK );
1124 TMII_DONE
1125 TMII_INSMI( MIIM_TYPE|MIIM_BITMAP, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, hbm, ER );
1126 TMII_DONE
1127 /* but succeeds with some others */
1128 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1129 TMII_GMII ( MIIM_TYPE|MIIM_SUBMENU, 80,
1130 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1131 txt, OK, OK );
1132 TMII_DONE
1133 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1134 TMII_GMII ( MIIM_TYPE|MIIM_STATE, 80,
1135 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1136 txt, OK, OK );
1137 TMII_DONE
1138 TMII_INSMI( MIIM_TYPE|MIIM_ID, MFT_STRING, -1, 888, 0, 0, 0, -1, txt, 6, 0, OK );
1139 TMII_GMII ( MIIM_TYPE|MIIM_ID, 80,
1140 MFT_STRING, 0, 888, 0, 0, 0, 0, string, 4, 0,
1141 txt, OK, OK );
1142 TMII_DONE
1143 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING, -1, -1, 0, 0, 0, 999, txt, 6, 0, OK );
1144 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1145 MFT_STRING, 0, 0, 0, 0, 0, 999, string, 4, 0,
1146 txt, OK, OK );
1147 TMII_DONE
1148 /* to be continued */
1149 /* set text with MIIM_TYPE and retrieve with MIIM_STRING */
1150 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1151 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1152 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1153 txt, OK, OK );
1154 TMII_DONE
1155 /* set text with MIIM_TYPE and retrieve with MIIM_STRING; MFT_OWNERDRAW causes an empty string */
1156 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1157 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1158 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1159 empty, OK, ER );
1160 TMII_DONE
1161 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1162 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1163 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1164 empty, OK, ER );
1165 TMII_DONE
1166 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1167 TMII_GMII ( MIIM_FTYPE, 80,
1168 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, 0,
1169 init, OK, ER );
1170 TMII_DONE
1171 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1172 TMII_GMII ( 0, 80,
1173 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1174 init, OK, OK );
1175 TMII_DONE
1176 /* contrary to MIIM_TYPE,you can set the text for an owner draw menu */
1177 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1178 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1179 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1180 txt, OK, OK );
1181 TMII_DONE
1182 /* same but retrieve with MIIM_TYPE */
1183 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1184 TMII_GMII ( MIIM_TYPE, 80,
1185 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1186 NULL, OK, OK );
1187 TMII_DONE
1188 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1189 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1190 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1191 empty, OK, ER );
1192 TMII_DONE
1193 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1194 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1195 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1196 empty, OK, ER );
1197 TMII_DONE
1199 /* How is that with bitmaps? */
1200 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1201 TMII_GMII ( MIIM_TYPE, 80,
1202 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1203 NULL, OK, ER );
1204 TMII_DONE
1205 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1206 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1207 0, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1208 init, OK, ER );
1209 TMII_DONE
1210 /* MIIM_BITMAP does not like MFT_BITMAP */
1211 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, hbm, ER );
1212 TMII_DONE
1213 /* no problem with OWNERDRAWN */
1214 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1215 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1216 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1217 init, OK, ER );
1218 TMII_DONE
1219 /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1220 TMII_INSMI( MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER );
1221 TMII_DONE
1223 /* menu with submenu */
1224 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1225 TMII_GMII ( MIIM_SUBMENU, 80,
1226 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1227 init, OK, ER );
1228 TMII_DONE
1229 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, empty, 0, 0, OK );
1230 TMII_GMII ( MIIM_SUBMENU, 80,
1231 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1232 init, OK, ER );
1233 TMII_DONE
1234 /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1235 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1236 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1237 MFT_STRING|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1238 empty, OK, ER );
1239 TMII_GMII ( MIIM_SUBMENU|MIIM_FTYPE, 80,
1240 MFT_SEPARATOR, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1241 empty, OK, ER );
1242 TMII_DONE
1243 /* menu with invalid submenu */
1244 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, (HMENU)999, 0, 0, -1, txt, 0, 0, ER );
1245 TMII_DONE
1246 /* Separator */
1247 TMII_INSMI( MIIM_TYPE, MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1248 TMII_GMII ( MIIM_TYPE, 80,
1249 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1250 NULL, OK, ER );
1251 TMII_DONE
1252 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1253 TMII_GMII ( MIIM_TYPE, 80,
1254 MFT_BITMAP|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1255 NULL, OK, ER );
1256 TMII_DONE
1257 /* SEPARATOR and STRING go well together */
1258 /* BITMAP and STRING go well together */
1259 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1260 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1261 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1262 txt, OK, OK );
1263 TMII_DONE
1264 /* BITMAP, SEPARATOR and STRING go well together */
1265 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1266 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1267 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1268 txt, OK, OK );
1269 TMII_DONE
1270 /* last two tests, but use MIIM_TYPE to retrieve info */
1271 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1272 TMII_GMII ( MIIM_TYPE, 80,
1273 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1274 NULL, OK, OK );
1275 TMII_DONE
1276 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1277 TMII_GMII ( MIIM_TYPE, 80,
1278 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1279 NULL, OK, OK );
1280 TMII_DONE
1281 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1282 TMII_GMII ( MIIM_TYPE, 80,
1283 MFT_SEPARATOR|MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1284 NULL, OK, OK );
1285 TMII_DONE
1286 /* same three with MFT_OWNERDRAW */
1287 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1288 TMII_GMII ( MIIM_TYPE, 80,
1289 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1290 NULL, OK, OK );
1291 TMII_DONE
1292 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1293 TMII_GMII ( MIIM_TYPE, 80,
1294 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1295 NULL, OK, OK );
1296 TMII_DONE
1297 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1298 TMII_GMII ( MIIM_TYPE, 80,
1299 MFT_SEPARATOR|MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1300 NULL, OK, OK );
1301 TMII_DONE
1303 TMII_INSMI( MIIM_STRING|MIIM_FTYPE|MIIM_ID, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1304 TMII_GMII ( MIIM_TYPE, 80,
1305 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1306 NULL, OK, OK );
1307 TMII_DONE
1308 /* test with modifymenu: string is preserved after setting OWNERDRAW */
1309 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1310 TMII_MODM( MFT_OWNERDRAW, -1, (void*)787 );
1311 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_DATA, 80,
1312 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 787, string, 4, 0,
1313 txt, OK, OK );
1314 TMII_DONE
1315 /* same with bitmap: now the text is cleared */
1316 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1317 TMII_MODM( MFT_BITMAP, 545, hbm );
1318 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1319 MFT_BITMAP, 0, 545, 0, 0, 0, 0, string, 0, hbm,
1320 empty, OK, ER );
1321 TMII_DONE
1322 /* start with bitmap: now setting text clears it (though he flag is raised) */
1323 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1324 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1325 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 0, hbm,
1326 empty, OK, ER );
1327 TMII_MODM( MFT_STRING, 545, txt );
1328 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1329 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 4, 0,
1330 txt, OK, OK );
1331 TMII_DONE
1332 /*repeat with text NULL */
1333 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1334 TMII_MODM( MFT_STRING, 545, NULL );
1335 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1336 MFT_SEPARATOR, 0, 545, 0, 0, 0, 0, string, 0, 0,
1337 empty, OK, ER );
1338 TMII_DONE
1339 /* repeat with text "" */
1340 TMII_INSMI( MIIM_BITMAP, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1341 TMII_MODM( MFT_STRING, 545, empty );
1342 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1343 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 0, 0,
1344 empty, OK, ER );
1345 TMII_DONE
1346 /* start with bitmap: set ownerdraw */
1347 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1348 TMII_MODM( MFT_OWNERDRAW, -1, (void *)232 );
1349 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_DATA, 80,
1350 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 232, string, 0, hbm,
1351 empty, OK, ER );
1352 TMII_DONE
1353 /* ask nothing */
1354 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1355 TMII_GMII ( 0, 80,
1356 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1357 init, OK, OK );
1358 TMII_DONE
1359 /* some tests with small cbSize: the hbmpItem is to be ignored */
1360 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1361 TMII_GMII ( MIIM_TYPE, 80,
1362 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1363 NULL, OK, ER );
1364 TMII_DONE
1365 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1366 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1367 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, NULL,
1368 init, OK, ER );
1369 TMII_DONE
1370 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1371 TMII_GMII ( MIIM_TYPE, 80,
1372 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, NULL,
1373 txt, OK, OK );
1374 TMII_DONE
1375 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1376 TMII_GMII ( MIIM_TYPE, 80,
1377 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1378 NULL, OK, OK );
1379 TMII_DONE
1380 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1381 TMII_GMII ( MIIM_TYPE, 80,
1382 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1383 NULL, OK, OK );
1384 TMII_DONE
1385 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1386 TMII_GMII ( MIIM_TYPE, 80,
1387 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1388 NULL, OK, OK );
1389 TMII_DONE
1390 /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus */
1391 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1392 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1393 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1394 NULL, OK, ER );
1395 TMII_DONE
1396 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1397 TMII_GMII ( MIIM_TYPE, 80,
1398 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1399 NULL, OK, ER );
1400 TMII_DONE
1401 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1402 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1403 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1404 NULL, OK, ER );
1405 TMII_DONE
1406 /* set a string menu to ownerdraw with MIIM_TYPE */
1407 TMII_INSMI( MIIM_TYPE, MFT_STRING, -2, -2, 0, 0, 0, -2, txt, -2, 0, OK );
1408 TMII_SMII ( MIIM_TYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1409 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1410 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1411 txt, OK, OK );
1412 TMII_DONE
1413 /* test with modifymenu add submenu */
1414 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1415 TMII_MODM( MF_POPUP, (UINT_PTR)submenu, txt );
1416 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_SUBMENU, 80,
1417 MFT_STRING, 0, 0, submenu, 0, 0, 0, string, 4, 0,
1418 txt, OK, OK );
1419 TMII_GMII ( MIIM_TYPE, 80,
1420 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1421 txt, OK, OK );
1422 TMII_DONE
1423 /* MFT_SEPARATOR bit is kept when the text is added */
1424 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1425 TMII_SMII( MIIM_STRING, 0, 0, 0, 0, 0, 0, 0, txt, 0, 0 );
1426 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1427 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, 0,
1428 txt, OK, OK );
1429 TMII_DONE
1430 /* MFT_SEPARATOR bit is kept when bitmap is added */
1431 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1432 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm );
1433 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1434 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1435 init, OK, ER );
1436 TMII_DONE
1437 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1438 Only the low word of the dwTypeData is used.
1439 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1440 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1441 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1442 TMII_GMII ( MIIM_TYPE, 80,
1443 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1444 NULL, OK, OK );
1445 TMII_DONE
1446 /* Type flags */
1447 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1448 TMII_GMII ( MIIM_TYPE, 80,
1449 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1450 NULL, OK, OK );
1451 TMII_DONE
1452 /* State flags */
1453 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1454 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1455 TMII_GMII ( MIIM_STATE, 80,
1456 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1457 NULL, OK, OK );
1458 TMII_DONE
1459 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1460 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1461 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1462 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1463 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1464 NULL, OK, OK );
1465 TMII_DONE
1466 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1467 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1468 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1469 TMII_GMII ( MIIM_FTYPE, 80,
1470 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1471 NULL, OK, OK );
1472 TMII_GMII ( MIIM_TYPE, 80,
1473 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1474 NULL, OK, OK );
1475 TMII_GMII ( MIIM_FTYPE, 80,
1476 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1477 NULL, OK, OK );
1478 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1479 TMII_GMII ( MIIM_TYPE, 80,
1480 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1481 NULL, OK, OK );
1482 TMII_DONE
1483 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1484 Only the low word of the dwTypeData is used.
1485 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1486 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1487 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1488 TMII_GMII ( MIIM_TYPE, 80,
1489 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1490 NULL, OK, OK );
1491 TMII_DONE
1492 /* Type flags */
1493 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1494 TMII_GMII ( MIIM_TYPE, 80,
1495 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1496 NULL, OK, OK );
1497 TMII_DONE
1498 /* State flags */
1499 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1500 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1501 TMII_GMII ( MIIM_STATE, 80,
1502 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1503 NULL, OK, OK );
1504 TMII_DONE
1505 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1506 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1507 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1508 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1509 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1510 NULL, OK, OK );
1511 TMII_DONE
1512 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1513 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1514 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1515 TMII_GMII ( MIIM_FTYPE, 80,
1516 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1517 NULL, OK, OK );
1518 TMII_GMII ( MIIM_TYPE, 80,
1519 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1520 NULL, OK, OK );
1521 TMII_GMII ( MIIM_FTYPE, 80,
1522 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1523 NULL, OK, OK );
1524 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1525 TMII_GMII ( MIIM_TYPE, 80,
1526 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1527 NULL, OK, OK );
1528 TMII_DONE
1529 } while( !(ansi = !ansi) );
1530 DeleteObject( hbm);
1534 The following tests try to confirm the algorithm used to return the menu items
1535 when there is a collision between a menu item and a popup menu
1537 static void test_menu_search_bycommand( void )
1539 HMENU hmenu, hmenuSub, hmenuSub2;
1540 MENUITEMINFO info;
1541 BOOL rc;
1542 UINT id;
1543 char strback[0x80];
1544 char strIn[0x80];
1545 static CHAR menuitem[] = "MenuItem",
1546 menuitem2[] = "MenuItem 2";
1548 /* Case 1: Menu containing a menu item */
1549 hmenu = CreateMenu();
1551 memset( &info, 0, sizeof info );
1552 info.cbSize = sizeof info;
1553 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1554 info.fType = MFT_STRING;
1555 strcpy(strIn, "Case 1 MenuItem");
1556 info.dwTypeData = strIn;
1557 info.wID = (UINT) 0x1234;
1559 rc = InsertMenuItem(hmenu, 0, TRUE, &info );
1560 ok (rc, "Inserting the menuitem failed\n");
1562 id = GetMenuItemID(hmenu, 0);
1563 ok (id == 0x1234, "Getting the menuitem id failed(gave %x)\n", id);
1565 /* Confirm the menuitem was given the id supplied (getting by position) */
1566 memset( &info, 0, sizeof info );
1567 strback[0] = 0x00;
1568 info.cbSize = sizeof(MENUITEMINFO);
1569 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1570 info.dwTypeData = strback;
1571 info.cch = sizeof(strback);
1573 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info); /* Get by position */
1574 ok (rc, "Getting the menu items info failed\n");
1575 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1576 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1578 /* Search by id - Should return the item */
1579 memset( &info, 0, sizeof info );
1580 strback[0] = 0x00;
1581 info.cbSize = sizeof(MENUITEMINFO);
1582 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1583 info.dwTypeData = strback;
1584 info.cch = sizeof(strback);
1585 rc = GetMenuItemInfo(hmenu, 0x1234, FALSE, &info); /* Get by ID */
1587 ok (rc, "Getting the menu items info failed\n");
1588 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1589 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1591 DestroyMenu( hmenu );
1593 /* Case 2: Menu containing a popup menu */
1594 hmenu = CreateMenu();
1595 hmenuSub = CreateMenu();
1597 strcpy(strIn, "Case 2 SubMenu");
1598 rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, strIn);
1599 ok (rc, "Inserting the popup menu into the main menu failed\n");
1601 id = GetMenuItemID(hmenu, 0);
1602 ok (id == -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id);
1604 /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
1605 memset( &info, 0, sizeof info );
1606 strback[0] = 0x00;
1607 info.cbSize = sizeof(MENUITEMINFO);
1608 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1609 info.dwTypeData = strback;
1610 info.cch = sizeof(strback);
1611 info.wID = 0xdeadbeef;
1613 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info); /* Get by position */
1614 ok (rc, "Getting the menu items info failed\n");
1615 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the menuitem\n");
1616 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1618 /* Search by id - returns the popup menu itself */
1619 memset( &info, 0, sizeof info );
1620 strback[0] = 0x00;
1621 info.cbSize = sizeof(MENUITEMINFO);
1622 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1623 info.dwTypeData = strback;
1624 info.cch = sizeof(strback);
1625 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1627 ok (rc, "Getting the menu items info failed\n");
1628 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1629 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1632 Now add an item after it with the same id
1634 memset( &info, 0, sizeof info );
1635 info.cbSize = sizeof info;
1636 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1637 info.fType = MFT_STRING;
1638 strcpy(strIn, "Case 2 MenuItem 1");
1639 info.dwTypeData = strIn;
1640 info.wID = (UINT_PTR) hmenuSub;
1641 rc = InsertMenuItem(hmenu, -1, TRUE, &info );
1642 ok (rc, "Inserting the menuitem failed\n");
1644 /* Search by id - returns the item which follows the popup menu */
1645 memset( &info, 0, sizeof info );
1646 strback[0] = 0x00;
1647 info.cbSize = sizeof(MENUITEMINFO);
1648 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1649 info.dwTypeData = strback;
1650 info.cch = sizeof(strback);
1651 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1653 ok (rc, "Getting the menu items info failed\n");
1654 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1655 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1658 Now add an item before the popup (with the same id)
1660 memset( &info, 0, sizeof info );
1661 info.cbSize = sizeof info;
1662 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1663 info.fType = MFT_STRING;
1664 strcpy(strIn, "Case 2 MenuItem 2");
1665 info.dwTypeData = strIn;
1666 info.wID = (UINT_PTR) hmenuSub;
1667 rc = InsertMenuItem(hmenu, 0, TRUE, &info );
1668 ok (rc, "Inserting the menuitem failed\n");
1670 /* Search by id - returns the item which precedes the popup menu */
1671 memset( &info, 0, sizeof info );
1672 strback[0] = 0x00;
1673 info.cbSize = sizeof(MENUITEMINFO);
1674 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1675 info.dwTypeData = strback;
1676 info.cch = sizeof(strback);
1677 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1679 ok (rc, "Getting the menu items info failed\n");
1680 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1681 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1683 DestroyMenu( hmenu );
1684 DestroyMenu( hmenuSub );
1687 Case 3: Menu containing a popup menu which in turn
1688 contains 2 items with the same id as the popup itself
1691 hmenu = CreateMenu();
1692 hmenuSub = CreateMenu();
1694 memset( &info, 0, sizeof info );
1695 info.cbSize = sizeof info;
1696 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1697 info.fType = MFT_STRING;
1698 info.dwTypeData = menuitem;
1699 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1701 rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1702 ok (rc, "Inserting the popup menu into the main menu failed\n");
1704 rc = InsertMenuItem(hmenuSub, 0, TRUE, &info );
1705 ok (rc, "Inserting the sub menu menuitem failed\n");
1707 memset( &info, 0, sizeof info );
1708 info.cbSize = sizeof info;
1709 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1710 info.fType = MFT_STRING;
1711 info.dwTypeData = menuitem2;
1712 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1714 rc = InsertMenuItem(hmenuSub, 1, TRUE, &info );
1715 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
1717 /* Prove that you can't query the id of a popup directly (By position) */
1718 id = GetMenuItemID(hmenu, 0);
1719 ok (id == -1, "Getting the sub menu id should have failed because its a popup (gave %x)\n", id);
1721 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1722 memset( &info, 0, sizeof info );
1723 strback[0] = 0x00;
1724 info.cbSize = sizeof(MENUITEMINFO);
1725 info.fMask = MIIM_STRING | MIIM_ID;
1726 info.dwTypeData = strback;
1727 info.cch = sizeof(strback);
1729 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
1730 ok (rc, "Getting the menus info failed\n");
1731 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
1732 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1733 DestroyMenu( hmenu );
1734 DestroyMenu( hmenuSub );
1737 Case 4: Menu containing 2 popup menus, the second
1738 contains 2 items with the same id as the first popup menu
1740 hmenu = CreateMenu();
1741 hmenuSub = CreateMenu();
1742 hmenuSub2 = CreateMenu();
1744 rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1745 ok (rc, "Inserting the popup menu into the main menu failed\n");
1747 rc = InsertMenu(hmenu, 1, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub2, "Submenu2");
1748 ok (rc, "Inserting the popup menu into the main menu failed\n");
1750 memset( &info, 0, sizeof info );
1751 info.cbSize = sizeof info;
1752 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1753 info.fType = MFT_STRING;
1754 info.dwTypeData = menuitem;
1755 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1757 rc = InsertMenuItem(hmenuSub2, 0, TRUE, &info );
1758 ok (rc, "Inserting the sub menu menuitem failed\n");
1760 memset( &info, 0, sizeof info );
1761 info.cbSize = sizeof info;
1762 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1763 info.fType = MFT_STRING;
1764 info.dwTypeData = menuitem2;
1765 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1767 rc = InsertMenuItem(hmenuSub2, 1, TRUE, &info );
1768 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
1770 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1771 memset( &info, 0, sizeof info );
1772 strback[0] = 0x00;
1773 info.cbSize = sizeof(MENUITEMINFO);
1774 info.fMask = MIIM_STRING | MIIM_ID;
1775 info.dwTypeData = strback;
1776 info.cch = sizeof(strback);
1778 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
1779 ok (rc, "Getting the menus info failed\n");
1780 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
1781 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1783 memset( &info, 0, sizeof info );
1784 strback[0] = 0x00;
1785 info.cbSize = sizeof(MENUITEMINFO);
1786 info.fMask = MIIM_STRING | MIIM_ID;
1787 info.dwTypeData = strback;
1788 info.cch = sizeof(strback);
1790 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub2, FALSE, &info);
1791 ok (rc, "Getting the menus info failed\n");
1792 ok (info.wID == (UINT_PTR)hmenuSub2, "IDs differ for popup menu\n");
1793 ok (!strcmp(info.dwTypeData, "Submenu2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1795 DestroyMenu( hmenu );
1796 DestroyMenu( hmenuSub );
1797 DestroyMenu( hmenuSub2 );
1801 Case 5: Menu containing a popup menu which in turn
1802 contains an item with a different id than the popup menu.
1803 This tests the fallback to a popup menu ID.
1806 hmenu = CreateMenu();
1807 hmenuSub = CreateMenu();
1809 rc = AppendMenu(hmenu, MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1810 ok (rc, "Appending the popup menu to the main menu failed\n");
1812 rc = AppendMenu(hmenuSub, MF_STRING, 102, "Item");
1813 ok (rc, "Appending the item to the popup menu failed\n");
1815 /* Set the ID for hmenuSub */
1816 info.cbSize = sizeof(info);
1817 info.fMask = MIIM_ID;
1818 info.wID = 101;
1820 rc = SetMenuItemInfo(hmenu, 0, TRUE, &info);
1821 ok(rc, "Setting the ID for the popup menu failed\n");
1823 /* Check if the ID has been set */
1824 info.wID = 0;
1825 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info);
1826 ok(rc, "Getting the ID for the popup menu failed\n");
1827 ok(info.wID == 101, "The ID for the popup menu has not been set\n");
1829 /* Prove getting the item info via ID returns the popup menu */
1830 memset( &info, 0, sizeof(info));
1831 strback[0] = 0x00;
1832 info.cbSize = sizeof(MENUITEMINFO);
1833 info.fMask = MIIM_STRING | MIIM_ID;
1834 info.dwTypeData = strback;
1835 info.cch = sizeof(strback);
1837 rc = GetMenuItemInfo(hmenu, 101, FALSE, &info);
1838 ok (rc, "Getting the menu info failed\n");
1839 ok (info.wID == 101, "IDs differ\n");
1840 ok (!strcmp(info.dwTypeData, "Submenu"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1842 /* Also look for the menu item */
1843 memset( &info, 0, sizeof(info));
1844 strback[0] = 0x00;
1845 info.cbSize = sizeof(MENUITEMINFO);
1846 info.fMask = MIIM_STRING | MIIM_ID;
1847 info.dwTypeData = strback;
1848 info.cch = sizeof(strback);
1850 rc = GetMenuItemInfo(hmenu, 102, FALSE, &info);
1851 ok (rc, "Getting the menu info failed\n");
1852 ok (info.wID == 102, "IDs differ\n");
1853 ok (!strcmp(info.dwTypeData, "Item"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1855 DestroyMenu(hmenu);
1856 DestroyMenu(hmenuSub);
1859 struct menu_item_pair_s {
1860 UINT uMenu; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
1861 * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
1862 * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
1863 UINT uItem;
1866 static struct menu_mouse_tests_s {
1867 DWORD type;
1868 struct menu_item_pair_s menu_item_pairs[5]; /* for mousing */
1869 WORD wVk[5]; /* keys */
1870 BOOL bMenuVisible;
1871 BOOL _todo_wine;
1872 } menu_tests[] = {
1873 /* for each test, send keys or clicks and check for menu visibility */
1874 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE }, /* test 0 */
1875 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
1876 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
1877 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
1878 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
1879 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
1880 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
1881 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, VK_ESCAPE, 0}, FALSE, FALSE },
1882 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', VK_ESCAPE, 0}, TRUE, FALSE },
1883 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
1884 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
1885 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
1886 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
1887 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
1888 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
1889 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
1890 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
1891 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
1893 { INPUT_MOUSE, {{1, 2}, {0}}, {0}, TRUE, TRUE }, /* test 18 */
1894 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
1895 { INPUT_MOUSE, {{1, 0}, {0}}, {0}, TRUE, TRUE },
1896 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
1897 { INPUT_MOUSE, {{1, 0}, {2, 2}, {0}}, {0}, TRUE, TRUE },
1898 { INPUT_MOUSE, {{2, 1}, {0}}, {0}, FALSE, FALSE },
1899 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
1900 { INPUT_MOUSE, {{3, 0}, {0}}, {0}, FALSE, FALSE },
1901 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
1902 { INPUT_MOUSE, {{3, 1}, {0}}, {0}, TRUE, TRUE },
1903 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
1904 { -1 }
1907 static void send_key(WORD wVk)
1909 TEST_INPUT i[2];
1910 memset(i, 0, sizeof(i));
1911 i[0].type = i[1].type = INPUT_KEYBOARD;
1912 i[0].u.ki.wVk = i[1].u.ki.wVk = wVk;
1913 i[1].u.ki.dwFlags = KEYEVENTF_KEYUP;
1914 pSendInput(2, (INPUT *) i, sizeof(INPUT));
1917 static BOOL click_menu(HANDLE hWnd, struct menu_item_pair_s *mi)
1919 HMENU hMenu = hMenus[mi->uMenu];
1920 TEST_INPUT i[3];
1921 MSG msg;
1922 RECT r;
1923 int screen_w = GetSystemMetrics(SM_CXSCREEN);
1924 int screen_h = GetSystemMetrics(SM_CYSCREEN);
1925 BOOL ret = GetMenuItemRect(mi->uMenu > 2 ? NULL : hWnd, hMenu, mi->uItem, &r);
1926 if(!ret) return FALSE;
1928 memset(i, 0, sizeof(i));
1929 i[0].type = i[1].type = i[2].type = INPUT_MOUSE;
1930 i[0].u.mi.dx = i[1].u.mi.dx = i[2].u.mi.dx
1931 = ((r.left + 5) * 65535) / screen_w;
1932 i[0].u.mi.dy = i[1].u.mi.dy = i[2].u.mi.dy
1933 = ((r.top + 5) * 65535) / screen_h;
1934 i[0].u.mi.dwFlags = i[1].u.mi.dwFlags = i[2].u.mi.dwFlags
1935 = MOUSEEVENTF_ABSOLUTE;
1936 i[0].u.mi.dwFlags |= MOUSEEVENTF_MOVE;
1937 i[1].u.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
1938 i[2].u.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
1939 ret = pSendInput(3, (INPUT *) i, sizeof(INPUT));
1941 /* hack to prevent mouse message buildup in Wine */
1942 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
1943 return ret;
1946 static DWORD WINAPI test_menu_input_thread(LPVOID lpParameter)
1948 int i, j;
1949 HANDLE hWnd = lpParameter;
1951 Sleep(500);
1952 /* mixed keyboard/mouse test */
1953 for (i = 0; menu_tests[i].type != -1; i++)
1955 int ret = TRUE, elapsed = 0;
1957 got_input = i && menu_tests[i-1].bMenuVisible;
1959 if (menu_tests[i].type == INPUT_KEYBOARD)
1960 for (j = 0; menu_tests[i].wVk[j] != 0; j++)
1961 send_key(menu_tests[i].wVk[j]);
1962 else
1963 for (j = 0; menu_tests[i].menu_item_pairs[j].uMenu != 0; j++)
1964 if (!(ret = click_menu(hWnd, &menu_tests[i].menu_item_pairs[j]))) break;
1966 if (!ret)
1968 skip( "test %u: failed to send input\n", i );
1969 PostMessage( hWnd, WM_CANCELMODE, 0, 0 );
1970 return 0;
1972 while (menu_tests[i].bMenuVisible != bMenuVisible)
1974 if (elapsed > 200)
1975 break;
1976 elapsed += 20;
1977 Sleep(20);
1980 if (!got_input)
1982 skip( "test %u: didn't receive input\n", i );
1983 PostMessage( hWnd, WM_CANCELMODE, 0, 0 );
1984 return 0;
1987 if (menu_tests[i]._todo_wine)
1989 todo_wine {
1990 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
1993 else
1994 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
1996 return 0;
1999 static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam,
2000 LPARAM lParam)
2002 switch (msg) {
2003 case WM_ENTERMENULOOP:
2004 bMenuVisible = TRUE;
2005 break;
2006 case WM_EXITMENULOOP:
2007 bMenuVisible = FALSE;
2008 break;
2009 case WM_KEYDOWN:
2010 case WM_SYSKEYDOWN:
2011 case WM_MOUSEMOVE:
2012 case WM_LBUTTONDOWN:
2013 case WM_LBUTTONUP:
2014 case WM_NCMOUSEMOVE:
2015 case WM_NCLBUTTONDOWN:
2016 case WM_NCLBUTTONUP:
2017 got_input = TRUE;
2018 /* fall through */
2019 default:
2020 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2022 return 0;
2025 static void test_menu_input(void) {
2026 MSG msg;
2027 WNDCLASSA wclass;
2028 HINSTANCE hInstance = GetModuleHandleA( NULL );
2029 HANDLE hThread, hWnd;
2030 DWORD tid;
2032 wclass.lpszClassName = "MenuTestClass";
2033 wclass.style = CS_HREDRAW | CS_VREDRAW;
2034 wclass.lpfnWndProc = WndProc;
2035 wclass.hInstance = hInstance;
2036 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
2037 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
2038 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2039 wclass.lpszMenuName = 0;
2040 wclass.cbClsExtra = 0;
2041 wclass.cbWndExtra = 0;
2042 assert (RegisterClassA( &wclass ));
2043 assert (hWnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
2044 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2045 400, 200, NULL, NULL, hInstance, NULL) );
2047 /* fixed menus */
2048 hMenus[3] = CreatePopupMenu();
2049 AppendMenu(hMenus[3], MF_STRING, 0, "&Enabled");
2050 AppendMenu(hMenus[3], MF_STRING|MF_DISABLED, 0, "&Disabled");
2052 hMenus[2] = CreatePopupMenu();
2053 AppendMenu(hMenus[2], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[3], "&Popup");
2054 AppendMenu(hMenus[2], MF_STRING, 0, "&Enabled");
2055 AppendMenu(hMenus[2], MF_STRING|MF_DISABLED, 0, "&Disabled");
2057 hMenus[1] = CreateMenu();
2058 AppendMenu(hMenus[1], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[2], "&Menu");
2059 AppendMenu(hMenus[1], MF_STRING, 0, "&Enabled");
2060 AppendMenu(hMenus[1], MF_STRING|MF_DISABLED, 0, "&Disabled");
2062 SetMenu(hWnd, hMenus[1]);
2063 ShowWindow(hWnd, SW_SHOW);
2064 UpdateWindow(hWnd);
2066 hThread = CreateThread(NULL, 0, test_menu_input_thread, hWnd, 0, &tid);
2067 while(1)
2069 if (WAIT_TIMEOUT != WaitForSingleObject(hThread, 50))
2070 break;
2071 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2073 DestroyWindow(hWnd);
2076 static void test_menu_flags( void )
2078 HMENU hMenu, hPopupMenu;
2080 hMenu = CreateMenu();
2081 hPopupMenu = CreatePopupMenu();
2083 AppendMenu(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2085 AppendMenu(hPopupMenu, MF_STRING | MF_HILITE | MF_DEFAULT, 101, "Item 1");
2086 InsertMenu(hPopupMenu, 1, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 102, "Item 2");
2087 AppendMenu(hPopupMenu, MF_STRING, 103, "Item 3");
2088 ModifyMenu(hPopupMenu, 2, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 103, "Item 3");
2090 ok(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_HILITE,
2091 "AppendMenu should accept MF_HILITE\n");
2092 ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2093 "InsertMenu should accept MF_HILITE\n");
2094 ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2095 "ModifyMenu should accept MF_HILITE\n");
2097 ok(!(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_DEFAULT),
2098 "AppendMenu must not accept MF_DEFAULT\n");
2099 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_DEFAULT),
2100 "InsertMenu must not accept MF_DEFAULT\n");
2101 ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_DEFAULT),
2102 "ModifyMenu must not accept MF_DEFAULT\n");
2104 DestroyMenu(hMenu);
2107 static void test_menu_hilitemenuitem( void )
2109 HMENU hMenu, hPopupMenu;
2110 WNDCLASSA wclass;
2111 HWND hWnd;
2113 wclass.lpszClassName = "HiliteMenuTestClass";
2114 wclass.style = CS_HREDRAW | CS_VREDRAW;
2115 wclass.lpfnWndProc = WndProc;
2116 wclass.hInstance = GetModuleHandleA( NULL );
2117 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
2118 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
2119 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2120 wclass.lpszMenuName = 0;
2121 wclass.cbClsExtra = 0;
2122 wclass.cbWndExtra = 0;
2123 assert (RegisterClassA( &wclass ));
2124 assert (hWnd = CreateWindowA( wclass.lpszClassName, "HiliteMenuTest",
2125 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2126 400, 200, NULL, NULL, wclass.hInstance, NULL) );
2128 hMenu = CreateMenu();
2129 hPopupMenu = CreatePopupMenu();
2131 AppendMenu(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2133 AppendMenu(hPopupMenu, MF_STRING, 101, "Item 1");
2134 AppendMenu(hPopupMenu, MF_STRING, 102, "Item 2");
2135 AppendMenu(hPopupMenu, MF_STRING, 103, "Item 3");
2137 SetMenu(hWnd, hMenu);
2139 /* test invalid arguments */
2141 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2142 "HiliteMenuItem: Item 2 is hilited\n");
2144 SetLastError(0xdeadbeef);
2145 todo_wine
2147 ok(!HiliteMenuItem(NULL, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2148 "HiliteMenuItem: call should have failed.\n");
2150 ok(GetLastError() == 0xdeadbeef || /* 9x */
2151 GetLastError() == ERROR_INVALID_WINDOW_HANDLE /* NT */,
2152 "HiliteMenuItem: expected error ERROR_INVALID_WINDOW_HANDLE, got: %d\n", GetLastError());
2154 SetLastError(0xdeadbeef);
2155 ok(!HiliteMenuItem(hWnd, NULL, 1, MF_HILITE | MF_BYPOSITION),
2156 "HiliteMenuItem: call should have failed.\n");
2157 ok(GetLastError() == 0xdeadbeef || /* 9x */
2158 GetLastError() == ERROR_INVALID_MENU_HANDLE /* NT */,
2159 "HiliteMenuItem: expected error ERROR_INVALID_MENU_HANDLE, got: %d\n", GetLastError());
2161 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2162 "HiliteMenuItem: Item 2 is hilited\n");
2164 /* either MF_HILITE or MF_UNHILITE *and* MF_BYCOMMAND or MF_BYPOSITION need to be set */
2166 SetLastError(0xdeadbeef);
2167 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_BYPOSITION),
2168 "HiliteMenuItem: call should have succeeded.\n");
2169 ok(GetLastError() == 0xdeadbeef,
2170 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2172 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2173 "HiliteMenuItem: Item 2 is hilited\n");
2175 SetLastError(0xdeadbeef);
2176 todo_wine
2178 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE),
2179 "HiliteMenuItem: call should have succeeded.\n");
2181 ok(GetLastError() == 0xdeadbeef,
2182 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2184 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2185 "HiliteMenuItem: Item 2 is hilited\n");
2187 /* hilite a menu item (by position) */
2189 SetLastError(0xdeadbeef);
2190 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2191 "HiliteMenuItem: call should not have failed.\n");
2192 ok(GetLastError() == 0xdeadbeef,
2193 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2195 todo_wine
2197 ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2198 "HiliteMenuItem: Item 2 is not hilited\n");
2201 /* unhilite a menu item (by position) */
2203 SetLastError(0xdeadbeef);
2204 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_UNHILITE | MF_BYPOSITION),
2205 "HiliteMenuItem: call should not have failed.\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 command) */
2214 SetLastError(0xdeadbeef);
2215 ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_HILITE | MF_BYCOMMAND),
2216 "HiliteMenuItem: call should not have failed.\n");
2217 ok(GetLastError() == 0xdeadbeef,
2218 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2220 todo_wine
2222 ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2223 "HiliteMenuItem: Item 3 is not hilited\n");
2226 /* unhilite a menu item (by command) */
2228 SetLastError(0xdeadbeef);
2229 ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_UNHILITE | MF_BYCOMMAND),
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, 2, MF_BYPOSITION) & MF_HILITE),
2235 "HiliteMenuItem: Item 3 is hilited\n");
2237 DestroyWindow(hWnd);
2240 static void check_menu_items(HMENU hmenu, UINT checked_cmd, UINT checked_type,
2241 UINT checked_state)
2243 INT i, count;
2245 count = GetMenuItemCount(hmenu);
2246 ok (count != -1, "GetMenuItemCount returned -1\n");
2248 for (i = 0; i < count; i++)
2250 BOOL ret;
2251 MENUITEMINFO mii;
2253 memset(&mii, 0, sizeof(mii));
2254 mii.cbSize = sizeof(mii);
2255 mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU;
2256 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2257 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2258 #if 0
2259 trace("item #%u: fType %04x, fState %04x, wID %u, hSubMenu %p\n",
2260 i, mii.fType, mii.fState, mii.wID, mii.hSubMenu);
2261 #endif
2262 if (mii.hSubMenu)
2264 ok(mii.wID == (UINT_PTR)mii.hSubMenu, "id %u: wID should be equal to hSubMenu\n", checked_cmd);
2265 check_menu_items(mii.hSubMenu, checked_cmd, checked_type, checked_state);
2267 else
2269 if (mii.wID == checked_cmd)
2271 ok(mii.fType == checked_type, "id %u: expected fType %04x, got %04x\n", checked_cmd, checked_type, mii.fType);
2272 ok(mii.fState == checked_state, "id %u: expected fState %04x, got %04x\n", checked_cmd, checked_state, mii.fState);
2273 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2275 else
2277 ok(mii.fType != MFT_RADIOCHECK, "id %u: not expected fType MFT_RADIOCHECK on cmd %u\n", checked_cmd, mii.wID);
2279 if (mii.fType == MFT_SEPARATOR)
2281 ok(mii.fState == MFS_GRAYED, "id %u: expected fState MFS_GRAYED, got %04x\n", checked_cmd, mii.fState);
2282 ok(mii.wID == 0, "id %u: expected wID 0, got %u\n", checked_cmd, mii.wID);
2284 else
2286 ok(mii.fState == 0, "id %u: expected fState 0, got %04x\n", checked_cmd, mii.fState);
2287 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2294 static void clear_ftype_and_state(HMENU hmenu, UINT id, UINT flags)
2296 BOOL ret;
2297 MENUITEMINFO mii;
2299 memset(&mii, 0, sizeof(mii));
2300 mii.cbSize = sizeof(mii);
2301 mii.fMask = MIIM_FTYPE | MIIM_STATE;
2302 ret = SetMenuItemInfo(hmenu, id, (flags & MF_BYPOSITION) != 0, &mii);
2303 ok(ret, "SetMenuItemInfo(%u) failed\n", id);
2306 static void test_CheckMenuRadioItem(void)
2308 BOOL ret;
2309 HMENU hmenu;
2311 hmenu = LoadMenu(GetModuleHandle(0), MAKEINTRESOURCE(1));
2312 assert(hmenu != 0);
2314 check_menu_items(hmenu, -1, 0, 0);
2316 ret = CheckMenuRadioItem(hmenu, 100, 100, 100, MF_BYCOMMAND);
2317 ok(ret, "CheckMenuRadioItem failed\n");
2318 check_menu_items(hmenu, 100, MFT_RADIOCHECK, MFS_CHECKED);
2320 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2321 ret = CheckMenuRadioItem(hmenu, 100, 100, -1, MF_BYCOMMAND);
2322 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2323 check_menu_items(hmenu, 100, MFT_RADIOCHECK, 0);
2325 /* clear check */
2326 clear_ftype_and_state(hmenu, 100, MF_BYCOMMAND);
2327 check_menu_items(hmenu, -1, 0, 0);
2329 /* first and checked items are on different menus */
2330 ret = CheckMenuRadioItem(hmenu, 0, 300, 202, MF_BYCOMMAND);
2331 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2332 check_menu_items(hmenu, -1, 0, 0);
2334 ret = CheckMenuRadioItem(hmenu, 200, 300, 202, MF_BYCOMMAND);
2335 ok(ret, "CheckMenuRadioItem failed\n");
2336 check_menu_items(hmenu, 202, MFT_RADIOCHECK, MFS_CHECKED);
2338 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2339 ret = CheckMenuRadioItem(hmenu, 202, 202, -1, MF_BYCOMMAND);
2340 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2341 check_menu_items(hmenu, 202, MFT_RADIOCHECK, 0);
2343 /* clear check */
2344 clear_ftype_and_state(hmenu, 202, MF_BYCOMMAND);
2345 check_menu_items(hmenu, -1, 0, 0);
2347 /* just for fun, try to check separator */
2348 ret = CheckMenuRadioItem(hmenu, 0, 300, 0, MF_BYCOMMAND);
2349 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2350 check_menu_items(hmenu, -1, 0, 0);
2353 static void test_menu_resource_layout(void)
2355 static const struct
2357 MENUITEMTEMPLATEHEADER mith;
2358 WORD data[14];
2359 } menu_template =
2361 { 0, 0 }, /* versionNumber, offset */
2363 /* mtOption, mtID, mtString[] '\0' terminated */
2364 MF_STRING, 1, 'F', 0,
2365 MF_STRING, 2, 0,
2366 MF_SEPARATOR, 3, 0,
2367 /* MF_SEPARATOR, 4, 'S', 0, FIXME: Wine ignores 'S' */
2368 MF_STRING|MF_GRAYED|MF_END, 5, 'E', 0
2371 static const struct
2373 UINT type, state, id;
2374 const char *str;
2375 } menu_data[] =
2377 { MF_STRING, MF_ENABLED, 1, "F" },
2378 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 2, "" },
2379 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 3, "" },
2380 /*{ MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 4, "S" }, FIXME: Wine ignores 'S'*/
2381 { MF_STRING, MF_GRAYED, 5, "E" },
2382 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 6, "" },
2383 { MF_STRING, MF_ENABLED, 7, "" },
2384 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 8, "" }
2386 HMENU hmenu;
2387 INT count, i;
2388 BOOL ret;
2390 hmenu = LoadMenuIndirect(&menu_template);
2391 ok(hmenu != 0, "LoadMenuIndirect error %u\n", GetLastError());
2393 ret = AppendMenu(hmenu, MF_STRING, 6, NULL);
2394 ok(ret, "AppendMenu failed\n");
2395 ret = AppendMenu(hmenu, MF_STRING, 7, "\0");
2396 ok(ret, "AppendMenu failed\n");
2397 ret = AppendMenu(hmenu, MF_SEPARATOR, 8, "separator");
2398 ok(ret, "AppendMenu failed\n");
2400 count = GetMenuItemCount(hmenu);
2401 ok(count == sizeof(menu_data)/sizeof(menu_data[0]),
2402 "expected %u menu items, got %u\n",
2403 (UINT)(sizeof(menu_data)/sizeof(menu_data[0])), count);
2405 for (i = 0; i < count; i++)
2407 char buf[20];
2408 MENUITEMINFO mii;
2410 memset(&mii, 0, sizeof(mii));
2411 mii.cbSize = sizeof(mii);
2412 mii.dwTypeData = buf;
2413 mii.cch = sizeof(buf);
2414 mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_STRING;
2415 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2416 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2417 #if 0
2418 trace("item #%u: fType %04x, fState %04x, wID %u, dwTypeData %s\n",
2419 i, mii.fType, mii.fState, mii.wID, (LPCSTR)mii.dwTypeData);
2420 #endif
2421 ok(mii.fType == menu_data[i].type,
2422 "%u: expected fType %04x, got %04x\n", i, menu_data[i].type, mii.fType);
2423 ok(mii.fState == menu_data[i].state,
2424 "%u: expected fState %04x, got %04x\n", i, menu_data[i].state, mii.fState);
2425 ok(mii.wID == menu_data[i].id,
2426 "%u: expected wID %04x, got %04x\n", i, menu_data[i].id, mii.wID);
2427 ok(mii.cch == strlen(menu_data[i].str),
2428 "%u: expected cch %u, got %u\n", i, (UINT)strlen(menu_data[i].str), mii.cch);
2429 ok(!strcmp(mii.dwTypeData, menu_data[i].str),
2430 "%u: expected dwTypeData %s, got %s\n", i, menu_data[i].str, (LPCSTR)mii.dwTypeData);
2433 DestroyMenu(hmenu);
2436 struct menu_data
2438 UINT type, id;
2439 const char *str;
2442 static HMENU create_menu_from_data(const struct menu_data *item, INT item_count)
2444 HMENU hmenu;
2445 INT i;
2446 BOOL ret;
2448 hmenu = CreateMenu();
2449 assert(hmenu != 0);
2451 for (i = 0; i < item_count; i++)
2453 SetLastError(0xdeadbeef);
2454 ret = AppendMenu(hmenu, item[i].type, item[i].id, item[i].str);
2455 ok(ret, "%d: AppendMenu(%04x, %04x, %p) error %u\n",
2456 i, item[i].type, item[i].id, item[i].str, GetLastError());
2458 return hmenu;
2461 /* use InsertMenuItem: does not set the MFT_BITMAP flag,
2462 * and does not accept non-magic bitmaps with invalid
2463 * bitmap handles */
2464 static HMENU create_menuitem_from_data(const struct menu_data *item, INT item_count)
2466 HMENU hmenu;
2467 INT i;
2468 BOOL ret;
2469 MENUITEMINFO mii = { sizeof( MENUITEMINFO)};
2471 hmenu = CreateMenu();
2472 assert(hmenu != 0);
2474 for (i = 0; i < item_count; i++)
2476 SetLastError(0xdeadbeef);
2478 mii.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STATE;
2479 mii.fType = 0;
2480 if( item[i].type & MFT_BITMAP)
2482 mii.fMask |= MIIM_BITMAP;
2483 mii.hbmpItem = (HBITMAP)item[i].str;
2485 else if( item[i].type & MFT_SEPARATOR)
2486 mii.fType = MFT_SEPARATOR;
2487 else
2489 mii.fMask |= MIIM_STRING;
2490 mii.dwTypeData = (LPSTR)item[i].str;
2491 mii.cch = strlen( item[i].str);
2493 mii.fState = 0;
2494 if( item[i].type & MF_HELP) mii.fType |= MF_HELP;
2495 mii.wID = item[i].id;
2496 ret = InsertMenuItem( hmenu, -1, TRUE, &mii);
2497 ok(ret, "%d: InsertMenuItem(%04x, %04x, %p) error %u\n",
2498 i, item[i].type, item[i].id, item[i].str, GetLastError());
2500 return hmenu;
2503 static void compare_menu_data(HMENU hmenu, const struct menu_data *item, INT item_count)
2505 INT count, i;
2506 BOOL ret;
2508 count = GetMenuItemCount(hmenu);
2509 ok(count == item_count, "expected %d, got %d menu items\n", count, item_count);
2511 for (i = 0; i < count; i++)
2513 char buf[20];
2514 MENUITEMINFO mii;
2516 memset(&mii, 0, sizeof(mii));
2517 mii.cbSize = sizeof(mii);
2518 mii.dwTypeData = buf;
2519 mii.cch = sizeof(buf);
2520 mii.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_BITMAP;
2521 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2522 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2523 #if 0
2524 trace("item #%u: fType %04x, fState %04x, wID %04x, hbmp %p\n",
2525 i, mii.fType, mii.fState, mii.wID, mii.hbmpItem);
2526 #endif
2527 ok(mii.fType == item[i].type,
2528 "%u: expected fType %04x, got %04x\n", i, item[i].type, mii.fType);
2529 ok(mii.wID == item[i].id,
2530 "%u: expected wID %04x, got %04x\n", i, item[i].id, mii.wID);
2531 if (mii.hbmpItem || !item[i].str)
2532 /* For some reason Windows sets high word to not 0 for
2533 * not "magic" ids.
2535 ok(LOWORD(mii.hbmpItem) == LOWORD(item[i].str),
2536 "%u: expected hbmpItem %p, got %p\n", i, item[i].str, mii.hbmpItem);
2537 else
2539 ok(mii.cch == strlen(item[i].str),
2540 "%u: expected cch %u, got %u\n", i, (UINT)strlen(item[i].str), mii.cch);
2541 ok(!strcmp(mii.dwTypeData, item[i].str),
2542 "%u: expected dwTypeData %s, got %s\n", i, item[i].str, (LPCSTR)mii.dwTypeData);
2547 static void test_InsertMenu(void)
2549 HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
2550 /* Note: XP treats only bitmap handles 1 - 6 as "magic" ones
2551 * regardless of their id.
2553 static const struct menu_data in1[] =
2555 { MF_STRING, 1, "File" },
2556 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) },
2557 { MF_STRING|MF_HELP, 2, "Help" }
2559 static const struct menu_data out1[] =
2561 { MF_STRING, 1, "File" },
2562 { MF_STRING|MF_HELP, 2, "Help" },
2563 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) }
2565 static const struct menu_data out1a[] =
2567 { MF_STRING, 1, "File" },
2568 { MF_STRING|MF_HELP, 2, "Help" },
2569 { MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) }
2571 const struct menu_data in2[] =
2573 { MF_STRING, 1, "File" },
2574 { MF_BITMAP|MF_HELP, SC_CLOSE, (char*)hbm },
2575 { MF_STRING|MF_HELP, 2, "Help" }
2577 const struct menu_data out2[] =
2579 { MF_STRING, 1, "File" },
2580 { MF_BITMAP|MF_HELP, SC_CLOSE, (char*)hbm },
2581 { MF_STRING|MF_HELP, 2, "Help" }
2583 const struct menu_data out2a[] =
2585 { MF_STRING, 1, "File" },
2586 { MF_HELP, SC_CLOSE, (char*)hbm },
2587 { MF_STRING|MF_HELP, 2, "Help" }
2589 static const struct menu_data in3[] =
2591 { MF_STRING, 1, "File" },
2592 { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) },
2593 { MF_STRING|MF_HELP, 2, "Help" }
2595 static const struct menu_data out3[] =
2597 { MF_STRING, 1, "File" },
2598 { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(0) },
2599 { MF_STRING|MF_HELP, 2, "Help" },
2601 static const struct menu_data in4[] =
2603 { MF_STRING, 1, "File" },
2604 { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCE(1) },
2605 { MF_STRING|MF_HELP, 2, "Help" }
2607 static const struct menu_data out4[] =
2609 { MF_STRING, 1, "File" },
2610 { MF_STRING|MF_HELP, 2, "Help" },
2611 { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCE(1) }
2613 static const struct menu_data out4a[] =
2615 { MF_STRING, 1, "File" },
2616 { MF_STRING|MF_HELP, 2, "Help" },
2617 { MF_HELP, 1, MAKEINTRESOURCE(1) }
2619 HMENU hmenu;
2621 #define create_menu(a) create_menu_from_data((a), sizeof(a)/sizeof((a)[0]))
2622 #define create_menuitem(a) create_menuitem_from_data((a), sizeof(a)/sizeof((a)[0]))
2623 #define compare_menu(h, a) compare_menu_data((h), (a), sizeof(a)/sizeof((a)[0]))
2625 hmenu = create_menu(in1);
2626 compare_menu(hmenu, out1);
2627 DestroyMenu(hmenu);
2629 hmenu = create_menu(in2);
2630 compare_menu(hmenu, out2);
2631 DestroyMenu(hmenu);
2633 hmenu = create_menu(in3);
2634 compare_menu(hmenu, out3);
2635 DestroyMenu(hmenu);
2637 hmenu = create_menu(in4);
2638 compare_menu(hmenu, out4);
2639 DestroyMenu(hmenu);
2641 /* now using InsertMenuItemInfo */
2642 hmenu = create_menuitem(in1);
2643 compare_menu(hmenu, out1a);
2644 DestroyMenu(hmenu);
2646 hmenu = create_menuitem(in2);
2647 compare_menu(hmenu, out2a);
2648 DestroyMenu(hmenu);
2650 hmenu = create_menuitem(in3);
2651 compare_menu(hmenu, out3);
2652 DestroyMenu(hmenu);
2654 hmenu = create_menuitem(in4);
2655 compare_menu(hmenu, out4a);
2656 DestroyMenu(hmenu);
2658 #undef create_menu
2659 #undef create_menuitem
2660 #undef compare_menu
2663 static void test_menu_getmenuinfo(void)
2665 HMENU hmenu;
2666 MENUINFO mi = {0};
2667 BOOL ret;
2668 DWORD gle;
2670 /* create a menu */
2671 hmenu = CreateMenu();
2672 assert( hmenu);
2673 /* test some parameter errors */
2674 SetLastError(0xdeadbeef);
2675 ret = pGetMenuInfo( hmenu, NULL);
2676 gle= GetLastError();
2677 ok( !ret, "GetMenuInfo() should have failed\n");
2678 ok( gle == ERROR_INVALID_PARAMETER ||
2679 broken(gle == 0xdeadbeef), /* Win98, WinME */
2680 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2681 SetLastError(0xdeadbeef);
2682 mi.cbSize = 0;
2683 ret = pGetMenuInfo( hmenu, &mi);
2684 gle= GetLastError();
2685 ok( !ret, "GetMenuInfo() should have failed\n");
2686 ok( gle == ERROR_INVALID_PARAMETER ||
2687 broken(gle == 0xdeadbeef), /* Win98, WinME */
2688 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2689 SetLastError(0xdeadbeef);
2690 mi.cbSize = sizeof( MENUINFO);
2691 ret = pGetMenuInfo( hmenu, &mi);
2692 gle= GetLastError();
2693 ok( ret, "GetMenuInfo() should have succeeded\n");
2694 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2695 SetLastError(0xdeadbeef);
2696 mi.cbSize = 0;
2697 ret = pGetMenuInfo( NULL, &mi);
2698 gle= GetLastError();
2699 ok( !ret, "GetMenuInfo() should have failed\n");
2700 ok( gle == ERROR_INVALID_PARAMETER ||
2701 broken(gle == 0xdeadbeef), /* Win98, WinME */
2702 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2703 /* clean up */
2704 DestroyMenu( hmenu);
2705 return;
2708 static void test_menu_setmenuinfo(void)
2710 HMENU hmenu, hsubmenu;
2711 MENUINFO mi = {0};
2712 MENUITEMINFOA mii = {sizeof( MENUITEMINFOA)};
2713 BOOL ret;
2714 DWORD gle;
2716 /* create a menu with a submenu */
2717 hmenu = CreateMenu();
2718 hsubmenu = CreateMenu();
2719 assert( hmenu && hsubmenu);
2720 mii.fMask = MIIM_SUBMENU;
2721 mii.hSubMenu = hsubmenu;
2722 ret = InsertMenuItem( hmenu, 0, FALSE, &mii);
2723 ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
2724 /* test some parameter errors */
2725 SetLastError(0xdeadbeef);
2726 ret = pSetMenuInfo( hmenu, NULL);
2727 gle= GetLastError();
2728 ok( !ret, "SetMenuInfo() should have failed\n");
2729 ok( gle == ERROR_INVALID_PARAMETER ||
2730 broken(gle == 0xdeadbeef), /* Win98, WinME */
2731 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2732 SetLastError(0xdeadbeef);
2733 mi.cbSize = 0;
2734 ret = pSetMenuInfo( hmenu, &mi);
2735 gle= GetLastError();
2736 ok( !ret, "SetMenuInfo() should have failed\n");
2737 ok( gle == ERROR_INVALID_PARAMETER ||
2738 broken(gle == 0xdeadbeef), /* Win98, WinME */
2739 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2740 SetLastError(0xdeadbeef);
2741 mi.cbSize = sizeof( MENUINFO);
2742 ret = pSetMenuInfo( hmenu, &mi);
2743 gle= GetLastError();
2744 ok( ret, "SetMenuInfo() should have succeeded\n");
2745 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2746 SetLastError(0xdeadbeef);
2747 mi.cbSize = 0;
2748 ret = pSetMenuInfo( NULL, &mi);
2749 gle= GetLastError();
2750 ok( !ret, "SetMenuInfo() should have failed\n");
2751 ok( gle == ERROR_INVALID_PARAMETER ||
2752 broken(gle == 0xdeadbeef), /* Win98, WinME */
2753 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2754 /* functional tests */
2755 /* menu and submenu should have the CHECKORBMP style bit cleared */
2756 SetLastError(0xdeadbeef);
2757 mi.cbSize = sizeof( MENUINFO);
2758 mi.fMask = MIM_STYLE;
2759 ret = pGetMenuInfo( hmenu, &mi);
2760 gle= GetLastError();
2761 ok( ret, "GetMenuInfo() should have succeeded\n");
2762 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2763 ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2764 SetLastError(0xdeadbeef);
2765 mi.cbSize = sizeof( MENUINFO);
2766 mi.fMask = MIM_STYLE;
2767 ret = pGetMenuInfo( hsubmenu, &mi);
2768 gle= GetLastError();
2769 ok( ret, "GetMenuInfo() should have succeeded\n");
2770 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2771 ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2772 /* SetMenuInfo() */
2773 SetLastError(0xdeadbeef);
2774 mi.cbSize = sizeof( MENUINFO);
2775 mi.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS;
2776 mi.dwStyle = MNS_CHECKORBMP;
2777 ret = pSetMenuInfo( hmenu, &mi);
2778 gle= GetLastError();
2779 ok( ret, "SetMenuInfo() should have succeeded\n");
2780 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2781 /* Now both menus should have the MNS_CHECKORBMP style bit set */
2782 SetLastError(0xdeadbeef);
2783 mi.cbSize = sizeof( MENUINFO);
2784 mi.fMask = MIM_STYLE;
2785 ret = pGetMenuInfo( hmenu, &mi);
2786 gle= GetLastError();
2787 ok( ret, "GetMenuInfo() should have succeeded\n");
2788 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2789 ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2790 SetLastError(0xdeadbeef);
2791 mi.cbSize = sizeof( MENUINFO);
2792 mi.fMask = MIM_STYLE;
2793 ret = pGetMenuInfo( hsubmenu, &mi);
2794 gle= GetLastError();
2795 ok( ret, "GetMenuInfo() should have succeeded\n");
2796 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2797 ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2798 /* now repeat that without the APPLYTOSUBMENUS flag and another style bit */
2799 SetLastError(0xdeadbeef);
2800 mi.cbSize = sizeof( MENUINFO);
2801 mi.fMask = MIM_STYLE ;
2802 mi.dwStyle = MNS_NOCHECK;
2803 ret = pSetMenuInfo( hmenu, &mi);
2804 gle= GetLastError();
2805 ok( ret, "SetMenuInfo() should have succeeded\n");
2806 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2807 /* Now only the top menu should have the MNS_NOCHECK style bit set */
2808 SetLastError(0xdeadbeef);
2809 mi.cbSize = sizeof( MENUINFO);
2810 mi.fMask = MIM_STYLE;
2811 ret = pGetMenuInfo( hmenu, &mi);
2812 gle= GetLastError();
2813 ok( ret, "GetMenuInfo() should have succeeded\n");
2814 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2815 ok( mi.dwStyle & MNS_NOCHECK, "menustyle was expected to have the MNS_NOCHECK flag\n");
2816 SetLastError(0xdeadbeef);
2817 mi.cbSize = sizeof( MENUINFO);
2818 mi.fMask = MIM_STYLE;
2819 ret = pGetMenuInfo( hsubmenu, &mi);
2820 gle= GetLastError();
2821 ok( ret, "GetMenuInfo() should have succeeded\n");
2822 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2823 ok( !(mi.dwStyle & MNS_NOCHECK), "menustyle was not expected to have the MNS_NOCHECK flag\n");
2824 /* clean up */
2825 DestroyMenu( hsubmenu);
2826 DestroyMenu( hmenu);
2827 return;
2830 /* little func to easy switch either TrackPopupMenu() or TrackPopupMenuEx() */
2831 static DWORD MyTrackPopupMenu( int ex, HMENU hmenu, UINT flags, INT x, INT y, HWND hwnd, LPTPMPARAMS ptpm)
2833 return ex
2834 ? TrackPopupMenuEx( hmenu, flags, x, y, hwnd, ptpm)
2835 : TrackPopupMenu( hmenu, flags, x, y, 0, hwnd, NULL);
2838 /* some TrackPopupMenu and TrackPopupMenuEx tests */
2839 /* the LastError values differ between NO_ERROR and invalid handle */
2840 /* between all windows versions tested. The first value is that valid on XP */
2841 /* Vista was the only that made returned different error values */
2842 /* between the TrackPopupMenu and TrackPopupMenuEx functions */
2843 static void test_menu_trackpopupmenu(void)
2845 BOOL ret;
2846 HMENU hmenu;
2847 DWORD gle;
2848 int Ex;
2849 HWND hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
2850 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
2851 NULL, NULL, NULL, NULL);
2852 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
2853 if (!hwnd) return;
2854 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
2855 for( Ex = 0; Ex < 2; Ex++)
2857 hmenu = CreatePopupMenu();
2858 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
2859 if (!hmenu)
2861 DestroyWindow(hwnd);
2862 return;
2864 /* display the menu */
2865 /* start with an invalid menu handle */
2866 gle = 0xdeadbeef;
2867 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2868 ret = MyTrackPopupMenu( Ex, NULL, 0x100, 100,100, hwnd, NULL);
2869 gle = GetLastError();
2870 ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
2871 ok( gle == ERROR_INVALID_MENU_HANDLE
2872 || broken (gle == 0xdeadbeef) /* win95 */
2873 || broken (gle == NO_ERROR) /* win98/ME */
2874 ,"TrackPopupMenu%s error got %u expected %u\n",
2875 Ex ? "Ex" : "", gle, ERROR_INVALID_MENU_HANDLE);
2876 ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
2877 "got unexpected message(s)%s%s%s\n",
2878 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2879 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2880 gflag_initmenu ? "WM_INITMENU": "");
2881 /* another one but not NULL */
2882 gle = 0xdeadbeef;
2883 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2884 ret = MyTrackPopupMenu( Ex, (HMENU)hwnd, 0x100, 100,100, hwnd, NULL);
2885 gle = GetLastError();
2886 ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
2887 ok( gle == ERROR_INVALID_MENU_HANDLE
2888 || broken (gle == 0xdeadbeef) /* win95 */
2889 || broken (gle == NO_ERROR) /* win98/ME */
2890 ,"TrackPopupMenu%s error got %u expected %u\n",
2891 Ex ? "Ex" : "", gle, ERROR_INVALID_MENU_HANDLE);
2892 ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
2893 "got unexpected message(s)%s%s%s\n",
2894 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2895 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2896 gflag_initmenu ? "WM_INITMENU": "");
2897 /* now a somewhat successful call */
2898 gle = 0xdeadbeef;
2899 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2900 ret = MyTrackPopupMenu( Ex, hmenu, 0x100, 100,100, hwnd, NULL);
2901 gle = GetLastError();
2902 ok( ret == 0, "TrackPopupMenu%s returned %d expected zero\n", Ex ? "Ex" : "", ret);
2903 ok( gle == NO_ERROR
2904 || gle == ERROR_INVALID_MENU_HANDLE /* NT4, win2k */
2905 || broken (gle == 0xdeadbeef) /* win95 */
2906 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
2907 Ex ? "Ex" : "", gle, NO_ERROR, ERROR_INVALID_MENU_HANDLE);
2908 ok( gflag_initmenupopup && gflag_entermenuloop && gflag_initmenu,
2909 "missed expected message(s)%s%s%s\n",
2910 !gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2911 !gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2912 !gflag_initmenu ? "WM_INITMENU": "");
2913 /* and another */
2914 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest");
2915 ok( ret, "AppendMenA has failed!\n");
2916 gle = 0xdeadbeef;
2917 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2918 ret = MyTrackPopupMenu( Ex, hmenu, 0x100, 100,100, hwnd, NULL);
2919 gle = GetLastError();
2920 ok( ret == 0, "TrackPopupMenu%s returned %d expected zero\n", Ex ? "Ex" : "", ret);
2921 ok( gle == NO_ERROR
2922 || gle == ERROR_INVALID_MENU_HANDLE /* NT4, win2k and Vista in the TrackPopupMenuEx case */
2923 || broken (gle == 0xdeadbeef) /* win95 */
2924 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
2925 Ex ? "Ex" : "", gle, NO_ERROR, ERROR_INVALID_MENU_HANDLE);
2926 ok( gflag_initmenupopup && gflag_entermenuloop && gflag_initmenu,
2927 "missed expected message(s)%s%s%s\n",
2928 !gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2929 !gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2930 !gflag_initmenu ? "WM_INITMENU": "");
2931 DestroyMenu(hmenu);
2933 /* clean up */
2934 DestroyWindow(hwnd);
2937 /* test handling of WM_CANCELMODE messages */
2938 static int g_got_enteridle;
2939 static HWND g_hwndtosend;
2940 static LRESULT WINAPI menu_cancelmode_wnd_proc(HWND hwnd, UINT msg,
2941 WPARAM wparam, LPARAM lparam)
2943 switch (msg)
2945 case WM_ENTERMENULOOP:
2946 g_got_enteridle = 0;
2947 return SendMessage( g_hwndtosend, WM_CANCELMODE, 0, 0);
2948 case WM_ENTERIDLE:
2950 if( g_got_enteridle++ == 0) {
2951 /* little hack to get another WM_ENTERIDLE message */
2952 PostMessage( hwnd, WM_MOUSEMOVE, 0, 0);
2953 return SendMessage( g_hwndtosend, WM_CANCELMODE, 0, 0);
2955 pEndMenu();
2956 return TRUE;
2959 return DefWindowProc( hwnd, msg, wparam, lparam);
2962 static void test_menu_cancelmode(void)
2964 DWORD ret;
2965 HWND hwnd, hwndchild;
2966 HMENU menu;
2967 if( !pEndMenu) { /* win95 */
2968 win_skip( "EndMenu is not available\n");
2969 return;
2971 hwnd = CreateWindowEx( 0, MAKEINTATOM(atomMenuCheckClass), NULL,
2972 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
2973 NULL, NULL, NULL, NULL);
2974 hwndchild = CreateWindowEx( 0, MAKEINTATOM(atomMenuCheckClass), NULL,
2975 WS_VISIBLE | WS_CHILD, 10, 10, 20, 20,
2976 hwnd, NULL, NULL, NULL);
2977 ok( hwnd != NULL && hwndchild != NULL,
2978 "CreateWindowEx failed with error %d\n", GetLastError());
2979 g_hwndtosend = hwnd;
2980 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_cancelmode_wnd_proc);
2981 SetWindowLongPtr( hwndchild, GWLP_WNDPROC, (LONG_PTR)menu_cancelmode_wnd_proc);
2982 menu = CreatePopupMenu();
2983 ok( menu != NULL, "CreatePopupMenu failed with error %d\n", GetLastError());
2984 ret = AppendMenuA( menu, MF_STRING, 1, "winetest");
2985 ok( ret, "Functie failed lasterror is %u\n", GetLastError());
2986 /* seems to be needed only on wine :( */
2987 {MSG msg; while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);}
2988 /* test the effect of sending a WM_CANCELMODE message in the WM_INITMENULOOP
2989 * handler of the menu owner */
2990 /* test results is exctracted from variable g_got_enteridle. Possible values:
2991 * 0 : complete conformance. Sending WM_CANCELMODE cancels a menu initializing tracking
2992 * 1 : Sending WM_CANCELMODE cancels a menu that is in tracking state
2993 * 2 : Sending WM_CANCELMODE does not work
2995 /* menu owner is top level window */
2996 g_hwndtosend = hwnd;
2997 ret = TrackPopupMenu( menu, 0x100, 100,100, 0, hwnd, NULL);
2998 todo_wine {
2999 ok( g_got_enteridle == 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle);
3001 ok( g_got_enteridle < 2, "received %d WM_ENTERIDLE messages, should be less than 2\n", g_got_enteridle);
3002 /* menu owner is child window */
3003 g_hwndtosend = hwndchild;
3004 ret = TrackPopupMenu( menu, 0x100, 100,100, 0, hwndchild, NULL);
3005 todo_wine {
3006 ok(g_got_enteridle == 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle);
3008 ok(g_got_enteridle < 2, "received %d WM_ENTERIDLE messages, should be less than 2\n", g_got_enteridle);
3009 /* now send the WM_CANCELMODE messages to the WRONG window */
3010 /* those should fail ( to have any effect) */
3011 g_hwndtosend = hwnd;
3012 ret = TrackPopupMenu( menu, 0x100, 100,100, 0, hwndchild, NULL);
3013 ok( g_got_enteridle == 2, "received %d WM_ENTERIDLE messages, should be 2\n", g_got_enteridle);
3014 /* cleanup */
3015 DestroyMenu( menu);
3016 DestroyWindow( hwndchild);
3017 DestroyWindow( hwnd);
3020 /* show menu trees have a maximum depth */
3021 static void test_menu_maxdepth(void)
3023 #define NR_MENUS 100
3024 HMENU hmenus[ NR_MENUS];
3025 int i;
3026 DWORD ret;
3028 SetLastError(12345678);
3029 for( i = 0; i < NR_MENUS; i++) {
3030 hmenus[i] = CreatePopupMenu();
3031 if( !hmenus[i]) break;
3033 ok( i == NR_MENUS, "could not create more than %d menu's\n", i);
3034 for( i = 1; i < NR_MENUS; i++) {
3035 ret = AppendMenuA( hmenus[i], MF_POPUP, (UINT_PTR)hmenus[i-1],"test");
3036 if( !ret) break;
3038 trace("Maximum depth is %d\n", i);
3039 ok( GetLastError() == 12345678, "unexpected error %d\n", GetLastError());
3040 ok( i < NR_MENUS ||
3041 broken( i == NR_MENUS), /* win98, NT */
3042 "no ( or very large) limit on menu depth!\n");
3044 for( i = 0; i < NR_MENUS; i++)
3045 DestroyMenu( hmenus[i]);
3048 /* bug #12171 */
3049 static void test_menu_circref(void)
3051 HMENU menu1, menu2;
3052 DWORD ret;
3054 menu1 = CreatePopupMenu();
3055 menu2 = CreatePopupMenu();
3056 ok( menu1 && menu2, "error creating menus.\n");
3057 ret = AppendMenuA( menu1, MF_POPUP, (UINT_PTR)menu2, "winetest");
3058 ok( ret, "AppendMenu failed, error is %d\n", GetLastError());
3059 ret = AppendMenuA( menu1, MF_STRING | MF_HILITE, 123, "winetest");
3060 ok( ret, "AppendMenu failed, error is %d\n", GetLastError());
3061 /* app chooses an id that happens to clash with its own hmenu */
3062 ret = AppendMenuA( menu2, MF_STRING, (UINT_PTR)menu2, "winetest");
3063 ok( ret, "AppendMenu failed, error is %d\n", GetLastError());
3064 /* now attempt to change the string of the first item of menu1 */
3065 ret = ModifyMenuA( menu1, (UINT_PTR)menu2, MF_POPUP, (UINT_PTR)menu2, "menu 2");
3066 ok( !ret ||
3067 broken( ret), /* win98, NT */
3068 "ModifyMenu should have failed.\n");
3069 if( !ret) { /* will probably stack fault if the ModifyMenu succeeded */
3070 ret = GetMenuState( menu1, 123, 0);
3071 ok( ret == MF_HILITE, "GetMenuState returned %x\n",ret);
3073 DestroyMenu( menu2);
3074 DestroyMenu( menu1);
3077 /* test how the menu texts are aligned when the menu items have
3078 * different combinations of text and bitmaps (bug #13350) */
3079 static void test_menualign(void)
3081 BYTE bmfill[300];
3082 HMENU menu;
3083 HBITMAP hbm1, hbm2, hbm3;
3084 MENUITEMINFO mii = { sizeof(MENUITEMINFO)};
3085 DWORD ret;
3086 HWND hwnd;
3087 MENUINFO mi = { sizeof( MENUINFO)};
3089 if( !winetest_interactive) {
3090 skip( "interactive alignment tests.\n");
3091 return;
3093 hwnd = CreateWindowEx(0,
3094 "STATIC",
3095 "Menu text alignment Test\nPlease make a selection.",
3096 WS_OVERLAPPEDWINDOW,
3097 100, 100,
3098 300, 300,
3099 NULL, NULL, 0, NULL);
3100 ShowWindow( hwnd, SW_SHOW);
3101 /* create bitmaps */
3102 memset( bmfill, 0xcc, sizeof( bmfill));
3103 hbm1 = CreateBitmap( 10,10,1,1,bmfill);
3104 hbm2 = CreateBitmap( 20,20,1,1,bmfill);
3105 hbm3 = CreateBitmap( 50,6,1,1,bmfill);
3106 ok( hbm1 && hbm2 && hbm3, "Creating bitmaps failed\n");
3107 menu = CreatePopupMenu();
3108 ok( menu != NULL, "CreatePopupMenu() failed\n");
3109 if( pGetMenuInfo) {
3110 mi.fMask = MIM_STYLE;
3111 ret = pGetMenuInfo( menu, &mi);
3112 ok( menu != NULL, "GetMenuInfo() failed\n");
3113 ok( 0 == mi.dwStyle, "menuinfo style is %x\n", mi.dwStyle);
3115 /* test 1 */
3116 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3117 mii.wID = 1;
3118 mii.hbmpItem = hbm1;
3119 mii.dwTypeData = (LPSTR) " OK: menu texts are correctly left-aligned.";
3120 ret = InsertMenuItem( menu, -1, TRUE, &mii);
3121 ok( ret, "InsertMenuItem() failed\n");
3122 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID ;
3123 mii.wID = 2;
3124 mii.hbmpItem = hbm2;
3125 mii.dwTypeData = (LPSTR) " FAIL: menu texts are NOT left-aligned.";
3126 ret = InsertMenuItem( menu, -1, TRUE, &mii);
3127 ok( ret, "InsertMenuItem() failed\n");
3128 ret = TrackPopupMenu( menu, TPM_RETURNCMD, 110, 200, 0, hwnd, NULL);
3129 ok( ret != 2, "User indicated that menu text alignment test 1 failed %d\n", ret);
3130 /* test 2*/
3131 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3132 mii.wID = 3;
3133 mii.hbmpItem = hbm3;
3134 mii.dwTypeData = NULL;
3135 ret = InsertMenuItem( menu, 0, TRUE, &mii);
3136 ok( ret, "InsertMenuItem() failed\n");
3137 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3138 mii.wID = 1;
3139 mii.hbmpItem = hbm1;
3140 /* make the text a bit longer, to keep it readable */
3141 /* this bug is on winXP and reproduced on wine */
3142 mii.dwTypeData = (LPSTR) " OK: menu texts are to the right of the bitmaps........";
3143 ret = SetMenuItemInfo( menu, 1, TRUE, &mii);
3144 ok( ret, "SetMenuItemInfo() failed\n");
3145 mii.wID = 2;
3146 mii.hbmpItem = hbm2;
3147 mii.dwTypeData = (LPSTR) " FAIL: menu texts are below the first bitmap. ";
3148 ret = SetMenuItemInfo( menu, 2, TRUE, &mii);
3149 ok( ret, "SetMenuItemInfo() failed\n");
3150 ret = TrackPopupMenu( menu, TPM_RETURNCMD, 110, 200, 0, hwnd, NULL);
3151 ok( ret != 2, "User indicated that menu text alignment test 2 failed %d\n", ret);
3152 /* test 3 */
3153 mii.fMask = MIIM_TYPE | MIIM_ID;
3154 mii.wID = 3;
3155 mii.fType = MFT_BITMAP;
3156 mii.dwTypeData = (LPSTR) hbm3;
3157 ret = SetMenuItemInfo( menu, 0, TRUE, &mii);
3158 ok( ret, "SetMenuItemInfo() failed\n");
3159 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3160 mii.wID = 1;
3161 mii.hbmpItem = NULL;
3162 mii.dwTypeData = (LPSTR) " OK: menu texts are below the bitmap.";
3163 ret = SetMenuItemInfo( menu, 1, TRUE, &mii);
3164 ok( ret, "SetMenuItemInfo() failed\n");
3165 mii.wID = 2;
3166 mii.hbmpItem = NULL;
3167 mii.dwTypeData = (LPSTR) " FAIL: menu texts are NOT below the bitmap.";
3168 ret = SetMenuItemInfo( menu, 2, TRUE, &mii);
3169 ok( ret, "SetMenuItemInfo() failed\n");
3170 ret = TrackPopupMenu( menu, TPM_RETURNCMD, 110, 200, 0, hwnd, NULL);
3171 ok( ret != 2, "User indicated that menu text alignment test 3 failed %d\n", ret);
3172 /* cleanup */
3173 DeleteObject( hbm1);
3174 DeleteObject( hbm2);
3175 DeleteObject( hbm3);
3176 DestroyMenu( menu);
3177 DestroyWindow( hwnd);
3180 START_TEST(menu)
3182 init_function_pointers();
3184 /* Wine defines MENUITEMINFO for W2K and above. NT4 and below can't
3185 * handle that.
3187 if (correct_behavior())
3189 test_menu_add_string();
3190 test_menu_iteminfo();
3191 test_menu_search_bycommand();
3192 test_CheckMenuRadioItem();
3193 test_menu_resource_layout();
3194 test_InsertMenu();
3195 test_menualign();
3198 register_menu_check_class();
3200 test_menu_locked_by_window();
3201 test_subpopup_locked_by_menu();
3202 test_menu_ownerdraw();
3203 test_menu_bmp_and_string();
3204 /* test Get/SetMenuInfo if available */
3205 if( pGetMenuInfo && pSetMenuInfo) {
3206 test_menu_getmenuinfo();
3207 test_menu_setmenuinfo();
3208 } else
3209 win_skip("Get/SetMenuInfo are not available\n");
3210 if( !pSendInput)
3211 win_skip("SendInput is not available\n");
3212 else
3213 test_menu_input();
3214 test_menu_flags();
3216 test_menu_hilitemenuitem();
3217 test_menu_trackpopupmenu();
3218 test_menu_cancelmode();
3219 test_menu_maxdepth();
3220 test_menu_circref();