ntdll/tests: Add a FILE_APPEND_DATA test.
[wine.git] / dlls / user32 / tests / menu.c
blobdeecbe8dd032850c9f399cf61682aacf2f9aa6b0
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, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
361 if( ret == (itemid & 0xffff)) {
362 win_skip("not on 16 bit menu subsystem\n");
363 DestroyMenu( hsubmenu);
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, TPM_RETURNCMD, 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 == 0xdeadbeef) || /* wow64 */
394 broken(gle == ERROR_INVALID_PARAMETER), /* win2k0 */
395 "Last error is %d\n", gle);
397 /* clean up */
398 DestroyMenu( hmenu);
399 DestroyWindow(hwnd);
402 static void test_menu_ownerdraw(void)
404 int i,j,k;
405 BOOL ret;
406 HMENU hmenu;
407 LONG leftcol;
408 HWND hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
409 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
410 NULL, NULL, NULL, NULL);
411 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
412 if( !hwnd) return;
413 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
414 hmenu = CreatePopupMenu();
415 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
416 if( !hmenu) { DestroyWindow(hwnd);return;}
417 k=0;
418 for( j=0;j<2;j++) /* create columns */
419 for(i=0;i<2;i++) { /* create rows */
420 ret = AppendMenu( hmenu, MF_OWNERDRAW |
421 (i==0 ? MF_MENUBREAK : 0), k, MAKEINTRESOURCE(k));
422 k++;
423 ok( ret, "AppendMenu failed for %d\n", k-1);
425 MOD_maxid = k-1;
426 assert( k <= sizeof(MOD_rc)/sizeof(RECT));
427 /* display the menu */
428 ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
430 /* columns have a 4 pixel gap between them */
431 ok( MOD_rc[0].right + 4 == MOD_rc[2].left,
432 "item rectangles are not separated by 4 pixels space\n");
433 /* height should be what the MEASUREITEM message has returned */
434 ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
435 "menu item has wrong height: %d should be %d\n",
436 MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
437 /* no gaps between the rows */
438 ok( MOD_rc[0].bottom - MOD_rc[1].top == 0,
439 "There should not be a space between the rows, gap is %d\n",
440 MOD_rc[0].bottom - MOD_rc[1].top);
441 /* test the correct value of the item height that was sent
442 * by the WM_MEASUREITEM message */
443 ok( MOD_odheight == HIWORD( GetDialogBaseUnits()) || /* WinNT,2k,XP */
444 MOD_odheight == MOD_hic, /* Win95,98,ME */
445 "Wrong height field in MEASUREITEMSTRUCT, expected %d or %d actual %d\n",
446 HIWORD( GetDialogBaseUnits()), MOD_hic, MOD_odheight);
447 /* test what MF_MENUBREAK did at the first position. Also show
448 * that an MF_SEPARATOR is ignored in the height calculation. */
449 leftcol= MOD_rc[0].left;
450 ModifyMenu( hmenu, 0, MF_BYCOMMAND| MF_OWNERDRAW| MF_SEPARATOR, 0, 0);
451 /* display the menu */
452 ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
453 /* left should be 4 pixels less now */
454 ok( leftcol == MOD_rc[0].left + 4,
455 "columns should be 4 pixels to the left (actual %d).\n",
456 leftcol - MOD_rc[0].left);
457 /* test width */
458 ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
459 "width of owner drawn menu item is wrong. Got %d expected %d\n",
460 MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
461 /* and height */
462 ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
463 "Height is incorrect. Got %d expected %d\n",
464 MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
466 /* test width/height of an ownerdraw menu bar as well */
467 ret = DestroyMenu(hmenu);
468 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
469 hmenu = CreateMenu();
470 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
471 if( !hmenu) { DestroyWindow(hwnd);return;}
472 MOD_maxid=1;
473 for(i=0;i<2;i++) {
474 ret = AppendMenu( hmenu, MF_OWNERDRAW , i, 0);
475 ok( ret, "AppendMenu failed for %d\n", i);
477 ret = SetMenu( hwnd, hmenu);
478 UpdateWindow( hwnd); /* hack for wine to draw the window + menu */
479 ok(ret, "SetMenu failed with error %d\n", GetLastError());
480 /* test width */
481 ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
482 "width of owner drawn menu item is wrong. Got %d expected %d\n",
483 MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
484 /* test hight */
485 ok( MOD_rc[0].bottom - MOD_rc[0].top == GetSystemMetrics( SM_CYMENU) - 1,
486 "Height of owner drawn menu item is wrong. Got %d expected %d\n",
487 MOD_rc[0].bottom - MOD_rc[0].top, GetSystemMetrics( SM_CYMENU) - 1);
489 /* clean up */
490 ret = DestroyMenu(hmenu);
491 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
492 DestroyWindow(hwnd);
495 /* helper for test_menu_bmp_and_string() */
496 static void test_mbs_help( int ispop, int hassub, int mnuopt,
497 HWND hwnd, int arrowwidth, int count, HBITMAP hbmp,
498 SIZE bmpsize, LPCSTR text, SIZE size, SIZE sc_size)
500 BOOL ret;
501 HMENU hmenu, submenu;
502 MENUITEMINFO mii={ sizeof( MENUITEMINFO )};
503 MENUINFO mi;
504 RECT rc;
505 CHAR text_copy[16];
506 int hastab, expect;
507 int failed = 0;
509 MOD_GotDrawItemMsg = FALSE;
510 mii.fMask = MIIM_FTYPE | MIIM_DATA | MIIM_STATE;
511 mii.fType = 0;
512 /* check the menu item unless MNS_CHECKORBMP is set */
513 mii.fState = (mnuopt != 2 ? MFS_CHECKED : MFS_UNCHECKED);
514 mii.dwItemData =0;
515 MODsizes[0] = bmpsize;
516 hastab = 0;
517 if( text ) {
518 char *p;
519 mii.fMask |= MIIM_STRING;
520 strcpy(text_copy, text);
521 mii.dwTypeData = text_copy; /* structure member declared non-const */
522 if( ( p = strchr( text, '\t'))) {
523 hastab = *(p + 1) ? 2 : 1;
526 /* tabs don't make sense in menubars */
527 if(hastab && !ispop) return;
528 if( hbmp) {
529 mii.fMask |= MIIM_BITMAP;
530 mii.hbmpItem = hbmp;
532 submenu = CreateMenu();
533 ok( submenu != 0, "CreateMenu failed with error %d\n", GetLastError());
534 if( ispop)
535 hmenu = CreatePopupMenu();
536 else
537 hmenu = CreateMenu();
538 ok( hmenu != 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
539 if( hassub) {
540 mii.fMask |= MIIM_SUBMENU;
541 mii.hSubMenu = submenu;
543 if( mnuopt) {
544 mi.cbSize = sizeof(mi);
545 mi.fMask = MIM_STYLE;
546 pGetMenuInfo( hmenu, &mi);
547 if( mnuopt) mi.dwStyle |= mnuopt == 1 ? MNS_NOCHECK : MNS_CHECKORBMP;
548 ret = pSetMenuInfo( hmenu, &mi);
549 ok( ret, "SetMenuInfo failed with error %d\n", GetLastError());
551 ret = InsertMenuItem( hmenu, 0, FALSE, &mii);
552 ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
553 failed = !ret;
554 if( winetest_debug) {
555 HDC hdc=GetDC(hwnd);
556 RECT rc = {100, 50, 400, 70};
557 char buf[100];
559 sprintf( buf,"%d text \"%s\" mnuopt %d", count, text ? text: "(nil)", mnuopt);
560 FillRect( hdc, &rc, (HBRUSH) COLOR_WINDOW);
561 TextOut( hdc, 10, 50, buf, strlen( buf));
562 ReleaseDC( hwnd, hdc);
564 if(ispop)
565 ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
566 else {
567 ret = SetMenu( hwnd, hmenu);
568 ok(ret, "SetMenu failed with error %d\n", GetLastError());
569 DrawMenuBar( hwnd);
571 ret = GetMenuItemRect( hwnd, hmenu, 0, &rc);
572 if (0) /* comment out menu size checks, behavior is different in almost every Windows version */
573 /* the tests should however succeed on win2000, XP and Wine (at least up to 1.1.15) */
574 /* with a variety of dpis and desktop font sizes */
576 /* check menu width */
577 if( ispop)
578 expect = ( text || hbmp ?
579 4 + (mnuopt != 1 ? GetSystemMetrics(SM_CXMENUCHECK) : 0)
580 : 0) +
581 arrowwidth + MOD_avec + (hbmp ?
582 ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ? bmpsize.cx + 2 : GetSystemMetrics( SM_CXMENUSIZE) + 2)
583 : 0) +
584 (text && hastab ? /* TAB space */
585 MOD_avec + ( hastab==2 ? sc_size.cx : 0) : 0) +
586 (text ? 2 + (text[0] ? size.cx :0): 0) ;
587 else
588 expect = !(text || hbmp) ? 0 :
589 ( hbmp ? (text ? 2:0) + bmpsize.cx : 0 ) +
590 (text ? 2 * MOD_avec + (text[0] ? size.cx :0): 0) ;
591 ok( rc.right - rc.left == expect,
592 "menu width wrong, got %d expected %d\n", rc.right - rc.left, expect);
593 failed = failed || !(rc.right - rc.left == expect);
594 /* check menu height */
595 if( ispop)
596 expect = max( ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 : 0),
597 max( (text ? max( 2 + size.cy, MOD_hic + 4) : 0),
598 (hbmp ?
599 ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ?
600 bmpsize.cy + 2
601 : GetSystemMetrics( SM_CYMENUSIZE) + 2)
602 : 0)));
603 else
604 expect = ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 :
605 max( GetSystemMetrics( SM_CYMENU) - 1, (hbmp ? bmpsize.cy : 0)));
606 ok( rc.bottom - rc.top == expect,
607 "menu height wrong, got %d expected %d (%d)\n",
608 rc.bottom - rc.top, expect, GetSystemMetrics( SM_CYMENU));
609 failed = failed || !(rc.bottom - rc.top == expect);
610 if( hbmp == HBMMENU_CALLBACK && MOD_GotDrawItemMsg) {
611 /* check the position of the bitmap */
612 /* horizontal */
613 if (!ispop)
614 expect = 3;
615 else if (mnuopt == 0)
616 expect = 4 + GetSystemMetrics(SM_CXMENUCHECK);
617 else if (mnuopt == 1)
618 expect = 4;
619 else /* mnuopt == 2 */
620 expect = 2;
621 ok( expect == MOD_rc[0].left,
622 "bitmap left is %d expected %d\n", MOD_rc[0].left, expect);
623 failed = failed || !(expect == MOD_rc[0].left);
624 /* vertical */
625 expect = (rc.bottom - rc.top - MOD_rc[0].bottom + MOD_rc[0].top) / 2;
626 ok( expect == MOD_rc[0].top,
627 "bitmap top is %d expected %d\n", MOD_rc[0].top, expect);
628 failed = failed || !(expect == MOD_rc[0].top);
631 /* if there was a failure, report details */
632 if( failed) {
633 trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
634 count, (ispop? "POPUP": "MENUBAR"),text ? text: "(nil)", hbmp, bmpsize.cx, bmpsize.cy,
635 size.cx, size.cy, sc_size.cx, mnuopt, hastab);
636 trace(" check %d,%d arrow %d avechar %d\n",
637 GetSystemMetrics(SM_CXMENUCHECK ),
638 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
639 if( hbmp == HBMMENU_CALLBACK)
640 trace( " rc %d,%d-%d,%d bmp.rc %d,%d-%d,%d\n",
641 rc.left, rc.top, rc.top, rc.bottom, MOD_rc[0].left,
642 MOD_rc[0].top,MOD_rc[0].right, MOD_rc[0].bottom);
644 /* clean up */
645 ret = DestroyMenu(submenu);
646 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
647 ret = DestroyMenu(hmenu);
648 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
652 static void test_menu_bmp_and_string(void)
654 BYTE bmfill[300];
655 HBITMAP hbm_arrow;
656 BITMAP bm;
657 INT arrowwidth;
658 HWND hwnd;
659 HMENU hsysmenu;
660 MENUINFO mi= {sizeof(MENUINFO)};
661 MENUITEMINFOA mii= {sizeof(MENUITEMINFOA)};
662 int count, szidx, txtidx, bmpidx, hassub, mnuopt, ispop;
664 if( !pGetMenuInfo)
666 win_skip("GetMenuInfo is not available\n");
667 return;
670 memset( bmfill, 0xcc, sizeof( bmfill));
671 hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL, WS_SYSMENU |
672 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
673 NULL, NULL, NULL, NULL);
674 hbm_arrow=LoadBitmap( 0, (CHAR*)OBM_MNARROW);
675 GetObject( hbm_arrow, sizeof(bm), &bm);
676 arrowwidth = bm.bmWidth;
677 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
678 if( !hwnd) return;
679 /* test system menu */
680 hsysmenu = GetSystemMenu( hwnd, FALSE);
681 ok( hsysmenu != NULL, "GetSystemMenu failed with error %d\n", GetLastError());
682 mi.fMask = MIM_STYLE;
683 mi.dwStyle = 0;
684 ok( pGetMenuInfo( hsysmenu, &mi), "GetMenuInfo failed gle=%d\n", GetLastError());
685 ok( MNS_CHECKORBMP == mi.dwStyle, "System Menu Style is %08x, without the bit %08x\n",
686 mi.dwStyle, MNS_CHECKORBMP);
687 mii.fMask = MIIM_BITMAP;
688 mii.hbmpItem = NULL;
689 ok( GetMenuItemInfoA( hsysmenu, SC_CLOSE, FALSE, &mii), "GetMenuItemInfoA failed gle=%d\n", GetLastError());
690 ok( HBMMENU_POPUP_CLOSE == mii.hbmpItem, "Item info did not get the right hbitmap: got %p expected %p\n",
691 mii.hbmpItem, HBMMENU_POPUP_CLOSE);
693 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
695 if( winetest_debug)
696 trace(" check %d,%d arrow %d avechar %d\n",
697 GetSystemMetrics(SM_CXMENUCHECK ),
698 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
699 count = 0;
700 MOD_maxid = 0;
701 for( ispop=1; ispop >= 0; ispop--){
702 static SIZE bmsizes[]= {
703 {10,10},{38,38},{1,30},{55,5}};
704 for( szidx=0; szidx < sizeof( bmsizes) / sizeof( SIZE); szidx++) {
705 HBITMAP hbm = CreateBitmap( bmsizes[szidx].cx, bmsizes[szidx].cy,1,1,bmfill);
706 HBITMAP bitmaps[] = { HBMMENU_CALLBACK, hbm, HBMMENU_POPUP_CLOSE, NULL };
707 ok( hbm != 0, "CreateBitmap failed err %d\n", GetLastError());
708 for( txtidx = 0; txtidx < sizeof(MOD_txtsizes)/sizeof(MOD_txtsizes[0]); txtidx++) {
709 for( hassub = 0; hassub < 2 ; hassub++) { /* add submenu item */
710 for( mnuopt = 0; mnuopt < 3 ; mnuopt++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
711 for( bmpidx = 0; bmpidx <sizeof(bitmaps)/sizeof(HBITMAP); bmpidx++) {
712 /* no need to test NULL bitmaps of several sizes */
713 if( !bitmaps[bmpidx] && szidx > 0) continue;
714 /* the HBMMENU_POPUP not to test for menu bars */
715 if( !ispop &&
716 bitmaps[bmpidx] >= HBMMENU_POPUP_CLOSE &&
717 bitmaps[bmpidx] <= HBMMENU_POPUP_MINIMIZE) continue;
718 if( !ispop && hassub) continue;
719 test_mbs_help( ispop, hassub, mnuopt,
720 hwnd, arrowwidth, ++count,
721 bitmaps[bmpidx],
722 bmsizes[szidx],
723 MOD_txtsizes[txtidx].text,
724 MOD_txtsizes[txtidx].size,
725 MOD_txtsizes[txtidx].sc_size);
730 DeleteObject( hbm);
733 /* clean up */
734 DestroyWindow(hwnd);
737 static void test_menu_add_string( void )
739 HMENU hmenu;
740 MENUITEMINFO info;
741 BOOL rc;
742 int ret;
744 char string[0x80];
745 char string2[0x80];
747 char strback[0x80];
748 WCHAR strbackW[0x80];
749 static CHAR blah[] = "blah";
750 static const WCHAR expectedString[] = {'D','u','m','m','y',' ','s','t','r','i','n','g', 0};
752 hmenu = CreateMenu();
754 memset( &info, 0, sizeof info );
755 info.cbSize = sizeof info;
756 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_ID;
757 info.dwTypeData = blah;
758 info.cch = 6;
759 info.dwItemData = 0;
760 info.wID = 1;
761 info.fState = 0;
762 InsertMenuItem(hmenu, 0, TRUE, &info );
764 memset( &info, 0, sizeof info );
765 info.cbSize = sizeof info;
766 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_DATA | MIIM_ID;
767 info.dwTypeData = string;
768 info.cch = sizeof string;
769 string[0] = 0;
770 GetMenuItemInfo( hmenu, 0, TRUE, &info );
772 ok( !strcmp( string, "blah" ), "menu item name differed\n");
774 /* Test combination of ownerdraw and strings with GetMenuItemString(A/W) */
775 strcpy(string, "Dummy string");
776 memset(&info, 0x00, sizeof(info));
777 info.cbSize= sizeof(MENUITEMINFO);
778 info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
779 info.fType= MFT_OWNERDRAW;
780 info.dwTypeData= string;
781 rc = InsertMenuItem( hmenu, 0, TRUE, &info );
782 ok (rc, "InsertMenuItem failed\n");
784 strcpy(string,"Garbage");
785 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
786 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
788 SetLastError(0xdeadbeef);
789 ret = GetMenuStringW( hmenu, 0, strbackW, 99, MF_BYPOSITION );
790 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
791 win_skip("GetMenuStringW is not implemented\n");
792 else
794 ok (ret, "GetMenuStringW on ownerdraw entry failed\n");
795 ok (!lstrcmpW( strbackW, expectedString ), "Menu text from Unicode version incorrect\n");
798 /* Just change ftype to string and see what text is stored */
799 memset(&info, 0x00, sizeof(info));
800 info.cbSize= sizeof(MENUITEMINFO);
801 info.fMask= MIIM_FTYPE; /* Set string type */
802 info.fType= MFT_STRING;
803 info.dwTypeData= (char *)0xdeadbeef;
804 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
805 ok (rc, "SetMenuItemInfo failed\n");
807 /* Did we keep the old dwTypeData? */
808 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
809 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
811 /* Ensure change to bitmap type fails */
812 memset(&info, 0x00, sizeof(info));
813 info.cbSize= sizeof(MENUITEMINFO);
814 info.fMask= MIIM_FTYPE; /* Set as bitmap type */
815 info.fType= MFT_BITMAP;
816 info.dwTypeData= (char *)0xdeadbee2;
817 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
818 ok (!rc, "SetMenuItemInfo unexpectedly worked\n");
820 /* Just change ftype back and ensure data hasn't been freed */
821 info.fType= MFT_OWNERDRAW; /* Set as ownerdraw type */
822 info.dwTypeData= (char *)0xdeadbee3;
823 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
824 ok (rc, "SetMenuItemInfo failed\n");
826 /* Did we keep the old dwTypeData? */
827 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
828 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
830 /* Just change string value (not type) */
831 memset(&info, 0x00, sizeof(info));
832 info.cbSize= sizeof(MENUITEMINFO);
833 info.fMask= MIIM_STRING; /* Set typeData */
834 strcpy(string2, "string2");
835 info.dwTypeData= string2;
836 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
837 ok (rc, "SetMenuItemInfo failed\n");
839 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
840 ok (!strcmp( strback, "string2" ), "Menu text from Ansi version incorrect\n");
842 /* crashes with wine 0.9.5 */
843 memset(&info, 0x00, sizeof(info));
844 info.cbSize= sizeof(MENUITEMINFO);
845 info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
846 info.fType= MFT_OWNERDRAW;
847 rc = InsertMenuItem( hmenu, 0, TRUE, &info );
848 ok (rc, "InsertMenuItem failed\n");
849 ok (!GetMenuString( hmenu, 0, NULL, 0, MF_BYPOSITION),
850 "GetMenuString on ownerdraw entry succeeded.\n");
851 SetLastError(0xdeadbeef);
852 ret = GetMenuStringW( hmenu, 0, NULL, 0, MF_BYPOSITION);
853 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
854 win_skip("GetMenuStringW is not implemented\n");
855 else
856 ok (!ret, "GetMenuStringW on ownerdraw entry succeeded.\n");
858 DestroyMenu( hmenu );
861 /* define building blocks for the menu item info tests */
862 static int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
864 if (n <= 0) return 0;
865 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
866 return *str1 - *str2;
869 static WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
871 WCHAR *p = dst;
872 while ((*p++ = *src++));
873 return dst;
876 static void insert_menu_item( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state, UINT id,
877 HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
878 void *type_data, UINT len, HBITMAP item, BOOL expect )
880 MENUITEMINFOA info;
881 BOOL ret;
883 /* magic bitmap handle to test smaller cbSize */
884 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
885 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
886 else
887 info.cbSize = sizeof(info);
888 info.fMask = mask;
889 info.fType = type;
890 info.fState = state;
891 info.wID = id;
892 info.hSubMenu = submenu;
893 info.hbmpChecked = checked;
894 info.hbmpUnchecked = unchecked;
895 info.dwItemData = data;
896 info.dwTypeData = type_data;
897 info.cch = len;
898 info.hbmpItem = item;
899 SetLastError( 0xdeadbeef );
900 if (ansi) ret = InsertMenuItemA( hmenu, 0, TRUE, &info );
901 else ret = InsertMenuItemW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
902 if (!expect) ok_(__FILE__, line)( !ret, "InsertMenuItem should have failed.\n" );
903 else ok_(__FILE__, line)( ret, "InsertMenuItem failed, err %u\n", GetLastError());
906 static void check_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
907 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked,
908 ULONG_PTR data, void *type_data, UINT in_len, UINT out_len,
909 HBITMAP item, LPCSTR expname, BOOL expect, BOOL expstring )
911 MENUITEMINFOA info;
912 BOOL ret;
913 WCHAR buffer[80];
915 SetLastError( 0xdeadbeef );
916 memset( &info, 0xcc, sizeof(info) );
917 info.cbSize = sizeof(info);
918 info.fMask = mask;
919 info.dwTypeData = type_data;
920 info.cch = in_len;
922 ret = ansi ? GetMenuItemInfoA( hmenu, 0, TRUE, &info ) :
923 GetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW *)&info );
924 if (!expect)
926 ok_(__FILE__, line)( !ret, "GetMenuItemInfo should have failed.\n" );
927 return;
929 ok_(__FILE__, line)( ret, "GetMenuItemInfo failed, err %u\n", GetLastError());
930 if (mask & MIIM_TYPE)
931 ok_(__FILE__, line)( info.fType == type || info.fType == LOWORD(type),
932 "wrong type %x/%x\n", info.fType, type );
933 if (mask & MIIM_STATE)
934 ok_(__FILE__, line)( info.fState == state || info.fState == LOWORD(state),
935 "wrong state %x/%x\n", info.fState, state );
936 if (mask & MIIM_ID)
937 ok_(__FILE__, line)( info.wID == id || info.wID == LOWORD(id),
938 "wrong id %x/%x\n", info.wID, id );
939 if (mask & MIIM_SUBMENU)
940 ok_(__FILE__, line)( info.hSubMenu == submenu || (ULONG_PTR)info.hSubMenu == LOWORD(submenu),
941 "wrong submenu %p/%p\n", info.hSubMenu, submenu );
942 if (mask & MIIM_CHECKMARKS)
944 ok_(__FILE__, line)( info.hbmpChecked == checked || (ULONG_PTR)info.hbmpChecked == LOWORD(checked),
945 "wrong bmpchecked %p/%p\n", info.hbmpChecked, checked );
946 ok_(__FILE__, line)( info.hbmpUnchecked == unchecked || (ULONG_PTR)info.hbmpUnchecked == LOWORD(unchecked),
947 "wrong bmpunchecked %p/%p\n", info.hbmpUnchecked, unchecked );
949 if (mask & MIIM_DATA)
950 ok_(__FILE__, line)( info.dwItemData == data || info.dwItemData == LOWORD(data),
951 "wrong item data %lx/%lx\n", info.dwItemData, data );
952 if (mask & MIIM_BITMAP)
953 ok_(__FILE__, line)( info.hbmpItem == item || (ULONG_PTR)info.hbmpItem == LOWORD(item),
954 "wrong bmpitem %p/%p\n", info.hbmpItem, item );
955 ok_(__FILE__, line)( info.dwTypeData == type_data || (ULONG_PTR)info.dwTypeData == LOWORD(type_data),
956 "wrong type data %p/%p\n", info.dwTypeData, type_data );
957 ok_(__FILE__, line)( info.cch == out_len, "wrong len %x/%x\n", info.cch, out_len );
958 if (expname)
960 if(ansi)
961 ok_(__FILE__, line)( !strncmp( expname, info.dwTypeData, out_len ),
962 "menu item name differed from '%s' '%s'\n", expname, info.dwTypeData );
963 else
964 ok_(__FILE__, line)( !strncmpW( (WCHAR *)expname, (WCHAR *)info.dwTypeData, out_len ),
965 "menu item name wrong\n" );
967 SetLastError( 0xdeadbeef );
968 ret = ansi ? GetMenuStringA( hmenu, 0, (char *)buffer, 80, MF_BYPOSITION ) :
969 GetMenuStringW( hmenu, 0, buffer, 80, MF_BYPOSITION );
970 if (expstring)
971 ok_(__FILE__, line)( ret, "GetMenuString failed, err %u\n", GetLastError());
972 else
973 ok_(__FILE__, line)( !ret, "GetMenuString should have failed\n" );
977 static void modify_menu( int line, HMENU hmenu, BOOL ansi, UINT flags, UINT_PTR id, void *data )
979 BOOL ret;
981 SetLastError( 0xdeadbeef );
982 if (ansi) ret = ModifyMenuA( hmenu, 0, flags, id, data );
983 else ret = ModifyMenuW( hmenu, 0, flags, id, data );
984 ok_(__FILE__,line)( ret, "ModifyMenuA failed, err %u\n", GetLastError());
987 static void set_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
988 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
989 void *type_data, UINT len, HBITMAP item )
992 MENUITEMINFOA info;
993 BOOL ret;
995 /* magic bitmap handle to test smaller cbSize */
996 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
997 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
998 else
999 info.cbSize = sizeof(info);
1000 info.fMask = mask;
1001 info.fType = type;
1002 info.fState = state;
1003 info.wID = id;
1004 info.hSubMenu = submenu;
1005 info.hbmpChecked = checked;
1006 info.hbmpUnchecked = unchecked;
1007 info.dwItemData = data;
1008 info.dwTypeData = type_data;
1009 info.cch = len;
1010 info.hbmpItem = item;
1011 SetLastError( 0xdeadbeef );
1012 if (ansi) ret = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1013 else ret = SetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
1014 ok_(__FILE__, line)( ret, "SetMenuItemInfo failed, err %u\n", GetLastError());
1017 #define TMII_INSMI( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,eret1 )\
1018 hmenu = CreateMenu();\
1019 submenu = CreateMenu();\
1020 if(ansi)strcpy( string, init );\
1021 else strcpyW( string, init );\
1022 insert_menu_item( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, eret1 )
1024 /* GetMenuItemInfo + GetMenuString */
1025 #define TMII_GMII( c2,l2,\
1026 d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,\
1027 expname, eret2, eret3)\
1028 check_menu_item_info( __LINE__, hmenu, ansi, c2, d3, e3, f3, g3, h3, i3, j3, k3, l2, l3, m3, \
1029 expname, eret2, eret3 )
1031 #define TMII_DONE \
1032 RemoveMenu(hmenu, 0, TRUE );\
1033 DestroyMenu( hmenu );\
1034 DestroyMenu( submenu );
1036 /* modify menu */
1037 #define TMII_MODM( flags, id, data ) \
1038 modify_menu( __LINE__, hmenu, ansi, flags, id, data )
1040 /* SetMenuItemInfo */
1041 #define TMII_SMII( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1 ) \
1042 set_menu_item_info( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1 )
1045 #define OK 1
1046 #define ER 0
1049 static void test_menu_iteminfo( void )
1051 int ansi = TRUE;
1052 char txtA[]="wine";
1053 char initA[]="XYZ";
1054 char emptyA[]="";
1055 WCHAR txtW[]={'W','i','n','e',0};
1056 WCHAR initW[]={'X','Y','Z',0};
1057 WCHAR emptyW[]={0};
1058 void *txt, *init, *empty, *string;
1059 HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
1060 char stringA[0x80];
1061 HMENU hmenu, submenu=CreateMenu();
1062 HBITMAP dummy_hbm = (HBITMAP)(ULONG_PTR)0xdeadbeef;
1064 do {
1065 if( ansi) {txt=txtA;init=initA;empty=emptyA;string=stringA;}
1066 else {txt=txtW;init=initW;empty=emptyW;string=stringA;}
1067 trace( "%s string %p hbm %p txt %p\n", ansi ? "ANSI tests: " : "Unicode tests:", string, hbm, txt);
1068 /* test all combinations of MFT_STRING, MFT_OWNERDRAW and MFT_BITMAP */
1069 /* (since MFT_STRING is zero, there are four of them) */
1070 TMII_INSMI( MIIM_TYPE, MFT_STRING, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1071 TMII_GMII ( MIIM_TYPE, 80,
1072 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1073 txt, OK, OK );
1074 TMII_DONE
1075 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1076 TMII_GMII ( MIIM_TYPE, 80,
1077 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1078 NULL, OK, ER );
1079 TMII_DONE
1080 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1081 TMII_GMII ( MIIM_TYPE, 80,
1082 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1083 NULL, OK, ER );
1084 TMII_DONE
1085 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1086 TMII_GMII ( MIIM_TYPE, 80,
1087 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1088 NULL, OK, ER );
1089 TMII_DONE
1090 /* not enough space for name*/
1091 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1092 TMII_GMII ( MIIM_TYPE, 0,
1093 MFT_STRING, 0, 0, 0, 0, 0, 0, NULL, 4, 0,
1094 NULL, OK, OK );
1095 TMII_DONE
1096 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1097 TMII_GMII ( MIIM_TYPE, 5,
1098 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1099 txt, OK, OK );
1100 TMII_DONE
1101 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1102 TMII_GMII ( MIIM_TYPE, 4,
1103 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 3, 0,
1104 txt, OK, OK );
1105 TMII_DONE
1106 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1107 TMII_GMII ( MIIM_TYPE, 0,
1108 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, 0,
1109 NULL, OK, ER );
1110 TMII_DONE
1111 /* cannot combine MIIM_TYPE with some other flags */
1112 TMII_INSMI( MIIM_TYPE|MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1113 TMII_DONE
1114 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1115 TMII_GMII ( MIIM_TYPE|MIIM_STRING, 80,
1116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1117 NULL, ER, OK );
1118 TMII_DONE
1119 TMII_INSMI( MIIM_TYPE|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1120 TMII_DONE
1121 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1122 TMII_GMII ( MIIM_TYPE|MIIM_FTYPE, 80,
1123 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1124 NULL, ER, OK );
1125 TMII_DONE
1126 TMII_INSMI( MIIM_TYPE|MIIM_BITMAP, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, hbm, ER );
1127 TMII_DONE
1128 /* but succeeds with some others */
1129 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1130 TMII_GMII ( MIIM_TYPE|MIIM_SUBMENU, 80,
1131 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1132 txt, OK, OK );
1133 TMII_DONE
1134 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1135 TMII_GMII ( MIIM_TYPE|MIIM_STATE, 80,
1136 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1137 txt, OK, OK );
1138 TMII_DONE
1139 TMII_INSMI( MIIM_TYPE|MIIM_ID, MFT_STRING, -1, 888, 0, 0, 0, -1, txt, 6, 0, OK );
1140 TMII_GMII ( MIIM_TYPE|MIIM_ID, 80,
1141 MFT_STRING, 0, 888, 0, 0, 0, 0, string, 4, 0,
1142 txt, OK, OK );
1143 TMII_DONE
1144 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING, -1, -1, 0, 0, 0, 999, txt, 6, 0, OK );
1145 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1146 MFT_STRING, 0, 0, 0, 0, 0, 999, string, 4, 0,
1147 txt, OK, OK );
1148 TMII_DONE
1149 /* to be continued */
1150 /* set text with MIIM_TYPE and retrieve with MIIM_STRING */
1151 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1152 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1153 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1154 txt, OK, OK );
1155 TMII_DONE
1156 /* set text with MIIM_TYPE and retrieve with MIIM_STRING; MFT_OWNERDRAW causes an empty string */
1157 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1158 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1159 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1160 empty, OK, ER );
1161 TMII_DONE
1162 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1163 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1164 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1165 empty, OK, ER );
1166 TMII_DONE
1167 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1168 TMII_GMII ( MIIM_FTYPE, 80,
1169 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, 0,
1170 init, OK, ER );
1171 TMII_DONE
1172 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1173 TMII_GMII ( 0, 80,
1174 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1175 init, OK, OK );
1176 TMII_DONE
1177 /* contrary to MIIM_TYPE,you can set the text for an owner draw menu */
1178 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1179 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1180 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1181 txt, OK, OK );
1182 TMII_DONE
1183 /* same but retrieve with MIIM_TYPE */
1184 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1185 TMII_GMII ( MIIM_TYPE, 80,
1186 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1187 NULL, OK, OK );
1188 TMII_DONE
1189 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1190 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1191 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1192 empty, OK, ER );
1193 TMII_DONE
1194 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1195 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1196 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1197 empty, OK, ER );
1198 TMII_DONE
1200 /* How is that with bitmaps? */
1201 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1202 TMII_GMII ( MIIM_TYPE, 80,
1203 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1204 NULL, OK, ER );
1205 TMII_DONE
1206 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1207 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1208 0, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1209 init, OK, ER );
1210 TMII_DONE
1211 /* MIIM_BITMAP does not like MFT_BITMAP */
1212 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, hbm, ER );
1213 TMII_DONE
1214 /* no problem with OWNERDRAWN */
1215 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1216 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1217 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1218 init, OK, ER );
1219 TMII_DONE
1220 /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1221 TMII_INSMI( MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER );
1222 TMII_DONE
1224 /* menu with submenu */
1225 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1226 TMII_GMII ( MIIM_SUBMENU, 80,
1227 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1228 init, OK, ER );
1229 TMII_DONE
1230 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, empty, 0, 0, OK );
1231 TMII_GMII ( MIIM_SUBMENU, 80,
1232 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1233 init, OK, ER );
1234 TMII_DONE
1235 /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1236 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1237 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1238 MFT_STRING|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1239 empty, OK, ER );
1240 TMII_GMII ( MIIM_SUBMENU|MIIM_FTYPE, 80,
1241 MFT_SEPARATOR, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1242 empty, OK, ER );
1243 TMII_DONE
1244 /* menu with invalid submenu */
1245 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, (HMENU)999, 0, 0, -1, txt, 0, 0, ER );
1246 TMII_DONE
1247 /* Separator */
1248 TMII_INSMI( MIIM_TYPE, MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1249 TMII_GMII ( MIIM_TYPE, 80,
1250 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1251 NULL, OK, ER );
1252 TMII_DONE
1253 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1254 TMII_GMII ( MIIM_TYPE, 80,
1255 MFT_BITMAP|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1256 NULL, OK, ER );
1257 TMII_DONE
1258 /* SEPARATOR and STRING go well together */
1259 /* BITMAP and STRING go well together */
1260 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1261 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1262 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1263 txt, OK, OK );
1264 TMII_DONE
1265 /* BITMAP, SEPARATOR and STRING go well together */
1266 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1267 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1268 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1269 txt, OK, OK );
1270 TMII_DONE
1271 /* last two tests, but use MIIM_TYPE to retrieve info */
1272 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1273 TMII_GMII ( MIIM_TYPE, 80,
1274 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1275 NULL, OK, OK );
1276 TMII_DONE
1277 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1278 TMII_GMII ( MIIM_TYPE, 80,
1279 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1280 NULL, OK, OK );
1281 TMII_DONE
1282 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1283 TMII_GMII ( MIIM_TYPE, 80,
1284 MFT_SEPARATOR|MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1285 NULL, OK, OK );
1286 TMII_DONE
1287 /* same three with MFT_OWNERDRAW */
1288 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1289 TMII_GMII ( MIIM_TYPE, 80,
1290 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1291 NULL, OK, OK );
1292 TMII_DONE
1293 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1294 TMII_GMII ( MIIM_TYPE, 80,
1295 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1296 NULL, OK, OK );
1297 TMII_DONE
1298 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1299 TMII_GMII ( MIIM_TYPE, 80,
1300 MFT_SEPARATOR|MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1301 NULL, OK, OK );
1302 TMII_DONE
1304 TMII_INSMI( MIIM_STRING|MIIM_FTYPE|MIIM_ID, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1305 TMII_GMII ( MIIM_TYPE, 80,
1306 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1307 NULL, OK, OK );
1308 TMII_DONE
1309 /* test with modifymenu: string is preserved after setting OWNERDRAW */
1310 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1311 TMII_MODM( MFT_OWNERDRAW, -1, (void*)787 );
1312 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_DATA, 80,
1313 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 787, string, 4, 0,
1314 txt, OK, OK );
1315 TMII_DONE
1316 /* same with bitmap: now the text is cleared */
1317 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1318 TMII_MODM( MFT_BITMAP, 545, hbm );
1319 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1320 MFT_BITMAP, 0, 545, 0, 0, 0, 0, string, 0, hbm,
1321 empty, OK, ER );
1322 TMII_DONE
1323 /* start with bitmap: now setting text clears it (though he flag is raised) */
1324 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1325 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1326 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 0, hbm,
1327 empty, OK, ER );
1328 TMII_MODM( MFT_STRING, 545, txt );
1329 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1330 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 4, 0,
1331 txt, OK, OK );
1332 TMII_DONE
1333 /*repeat with text NULL */
1334 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1335 TMII_MODM( MFT_STRING, 545, NULL );
1336 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1337 MFT_SEPARATOR, 0, 545, 0, 0, 0, 0, string, 0, 0,
1338 empty, OK, ER );
1339 TMII_DONE
1340 /* repeat with text "" */
1341 TMII_INSMI( MIIM_BITMAP, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1342 TMII_MODM( MFT_STRING, 545, empty );
1343 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1344 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 0, 0,
1345 empty, OK, ER );
1346 TMII_DONE
1347 /* start with bitmap: set ownerdraw */
1348 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1349 TMII_MODM( MFT_OWNERDRAW, -1, (void *)232 );
1350 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_DATA, 80,
1351 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 232, string, 0, hbm,
1352 empty, OK, ER );
1353 TMII_DONE
1354 /* ask nothing */
1355 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1356 TMII_GMII ( 0, 80,
1357 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1358 init, OK, OK );
1359 TMII_DONE
1360 /* some tests with small cbSize: the hbmpItem is to be ignored */
1361 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1362 TMII_GMII ( MIIM_TYPE, 80,
1363 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1364 NULL, OK, ER );
1365 TMII_DONE
1366 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1367 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1368 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, NULL,
1369 init, OK, ER );
1370 TMII_DONE
1371 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1372 TMII_GMII ( MIIM_TYPE, 80,
1373 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, NULL,
1374 txt, OK, OK );
1375 TMII_DONE
1376 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1377 TMII_GMII ( MIIM_TYPE, 80,
1378 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1379 NULL, OK, OK );
1380 TMII_DONE
1381 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1382 TMII_GMII ( MIIM_TYPE, 80,
1383 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1384 NULL, OK, OK );
1385 TMII_DONE
1386 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1387 TMII_GMII ( MIIM_TYPE, 80,
1388 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1389 NULL, OK, OK );
1390 TMII_DONE
1391 /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus */
1392 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1393 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1394 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1395 NULL, OK, ER );
1396 TMII_DONE
1397 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1398 TMII_GMII ( MIIM_TYPE, 80,
1399 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1400 NULL, OK, ER );
1401 TMII_DONE
1402 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1403 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1404 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1405 NULL, OK, ER );
1406 TMII_DONE
1407 /* set a string menu to ownerdraw with MIIM_TYPE */
1408 TMII_INSMI( MIIM_TYPE, MFT_STRING, -2, -2, 0, 0, 0, -2, txt, -2, 0, OK );
1409 TMII_SMII ( MIIM_TYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1410 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1411 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1412 txt, OK, OK );
1413 TMII_DONE
1414 /* test with modifymenu add submenu */
1415 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1416 TMII_MODM( MF_POPUP, (UINT_PTR)submenu, txt );
1417 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_SUBMENU, 80,
1418 MFT_STRING, 0, 0, submenu, 0, 0, 0, string, 4, 0,
1419 txt, OK, OK );
1420 TMII_GMII ( MIIM_TYPE, 80,
1421 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1422 txt, OK, OK );
1423 TMII_DONE
1424 /* MFT_SEPARATOR bit is kept when the text is added */
1425 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1426 TMII_SMII( MIIM_STRING, 0, 0, 0, 0, 0, 0, 0, txt, 0, 0 );
1427 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1428 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, 0,
1429 txt, OK, OK );
1430 TMII_DONE
1431 /* MFT_SEPARATOR bit is kept when bitmap is added */
1432 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1433 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm );
1434 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1435 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1436 init, OK, ER );
1437 TMII_DONE
1438 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1439 Only the low word of the dwTypeData is used.
1440 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1441 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1442 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1443 TMII_GMII ( MIIM_TYPE, 80,
1444 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1445 NULL, OK, OK );
1446 TMII_DONE
1447 /* Type flags */
1448 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1449 TMII_GMII ( MIIM_TYPE, 80,
1450 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1451 NULL, OK, OK );
1452 TMII_DONE
1453 /* State flags */
1454 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1455 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1456 TMII_GMII ( MIIM_STATE, 80,
1457 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1458 NULL, OK, OK );
1459 TMII_DONE
1460 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1461 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1462 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1463 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1464 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1465 NULL, OK, OK );
1466 TMII_DONE
1467 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1468 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1469 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1470 TMII_GMII ( MIIM_FTYPE, 80,
1471 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1472 NULL, OK, OK );
1473 TMII_GMII ( MIIM_TYPE, 80,
1474 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1475 NULL, OK, OK );
1476 TMII_GMII ( MIIM_FTYPE, 80,
1477 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1478 NULL, OK, OK );
1479 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1480 TMII_GMII ( MIIM_TYPE, 80,
1481 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1482 NULL, OK, OK );
1483 TMII_DONE
1484 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1485 Only the low word of the dwTypeData is used.
1486 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1487 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1488 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1489 TMII_GMII ( MIIM_TYPE, 80,
1490 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1491 NULL, OK, OK );
1492 TMII_DONE
1493 /* Type flags */
1494 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1495 TMII_GMII ( MIIM_TYPE, 80,
1496 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1497 NULL, OK, OK );
1498 TMII_DONE
1499 /* State flags */
1500 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1501 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1502 TMII_GMII ( MIIM_STATE, 80,
1503 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1504 NULL, OK, OK );
1505 TMII_DONE
1506 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1507 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1508 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1509 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1510 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1511 NULL, OK, OK );
1512 TMII_DONE
1513 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1514 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1515 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1516 TMII_GMII ( MIIM_FTYPE, 80,
1517 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1518 NULL, OK, OK );
1519 TMII_GMII ( MIIM_TYPE, 80,
1520 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1521 NULL, OK, OK );
1522 TMII_GMII ( MIIM_FTYPE, 80,
1523 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1524 NULL, OK, OK );
1525 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1526 TMII_GMII ( MIIM_TYPE, 80,
1527 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1528 NULL, OK, OK );
1529 TMII_DONE
1530 } while( !(ansi = !ansi) );
1531 DeleteObject( hbm);
1535 The following tests try to confirm the algorithm used to return the menu items
1536 when there is a collision between a menu item and a popup menu
1538 static void test_menu_search_bycommand( void )
1540 HMENU hmenu, hmenuSub, hmenuSub2;
1541 MENUITEMINFO info;
1542 BOOL rc;
1543 UINT id;
1544 char strback[0x80];
1545 char strIn[0x80];
1546 static CHAR menuitem[] = "MenuItem",
1547 menuitem2[] = "MenuItem 2";
1549 /* Case 1: Menu containing a menu item */
1550 hmenu = CreateMenu();
1552 memset( &info, 0, sizeof info );
1553 info.cbSize = sizeof info;
1554 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1555 info.fType = MFT_STRING;
1556 strcpy(strIn, "Case 1 MenuItem");
1557 info.dwTypeData = strIn;
1558 info.wID = (UINT) 0x1234;
1560 rc = InsertMenuItem(hmenu, 0, TRUE, &info );
1561 ok (rc, "Inserting the menuitem failed\n");
1563 id = GetMenuItemID(hmenu, 0);
1564 ok (id == 0x1234, "Getting the menuitem id failed(gave %x)\n", id);
1566 /* Confirm the menuitem was given the id supplied (getting by position) */
1567 memset( &info, 0, sizeof info );
1568 strback[0] = 0x00;
1569 info.cbSize = sizeof(MENUITEMINFO);
1570 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1571 info.dwTypeData = strback;
1572 info.cch = sizeof(strback);
1574 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info); /* Get by position */
1575 ok (rc, "Getting the menu items info failed\n");
1576 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1577 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1579 /* Search by id - Should return the item */
1580 memset( &info, 0, sizeof info );
1581 strback[0] = 0x00;
1582 info.cbSize = sizeof(MENUITEMINFO);
1583 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1584 info.dwTypeData = strback;
1585 info.cch = sizeof(strback);
1586 rc = GetMenuItemInfo(hmenu, 0x1234, FALSE, &info); /* Get by ID */
1588 ok (rc, "Getting the menu items info failed\n");
1589 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1590 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1592 DestroyMenu( hmenu );
1594 /* Case 2: Menu containing a popup menu */
1595 hmenu = CreateMenu();
1596 hmenuSub = CreateMenu();
1598 strcpy(strIn, "Case 2 SubMenu");
1599 rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, strIn);
1600 ok (rc, "Inserting the popup menu into the main menu failed\n");
1602 id = GetMenuItemID(hmenu, 0);
1603 ok (id == -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id);
1605 /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
1606 memset( &info, 0, sizeof info );
1607 strback[0] = 0x00;
1608 info.cbSize = sizeof(MENUITEMINFO);
1609 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1610 info.dwTypeData = strback;
1611 info.cch = sizeof(strback);
1612 info.wID = 0xdeadbeef;
1614 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info); /* Get by position */
1615 ok (rc, "Getting the menu items info failed\n");
1616 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the menuitem\n");
1617 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1619 /* Search by id - returns the popup menu itself */
1620 memset( &info, 0, sizeof info );
1621 strback[0] = 0x00;
1622 info.cbSize = sizeof(MENUITEMINFO);
1623 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1624 info.dwTypeData = strback;
1625 info.cch = sizeof(strback);
1626 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1628 ok (rc, "Getting the menu items info failed\n");
1629 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1630 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1633 Now add an item after it with the same id
1635 memset( &info, 0, sizeof info );
1636 info.cbSize = sizeof info;
1637 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1638 info.fType = MFT_STRING;
1639 strcpy(strIn, "Case 2 MenuItem 1");
1640 info.dwTypeData = strIn;
1641 info.wID = (UINT_PTR) hmenuSub;
1642 rc = InsertMenuItem(hmenu, -1, TRUE, &info );
1643 ok (rc, "Inserting the menuitem failed\n");
1645 /* Search by id - returns the item which follows the popup menu */
1646 memset( &info, 0, sizeof info );
1647 strback[0] = 0x00;
1648 info.cbSize = sizeof(MENUITEMINFO);
1649 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1650 info.dwTypeData = strback;
1651 info.cch = sizeof(strback);
1652 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1654 ok (rc, "Getting the menu items info failed\n");
1655 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1656 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1659 Now add an item before the popup (with the same id)
1661 memset( &info, 0, sizeof info );
1662 info.cbSize = sizeof info;
1663 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1664 info.fType = MFT_STRING;
1665 strcpy(strIn, "Case 2 MenuItem 2");
1666 info.dwTypeData = strIn;
1667 info.wID = (UINT_PTR) hmenuSub;
1668 rc = InsertMenuItem(hmenu, 0, TRUE, &info );
1669 ok (rc, "Inserting the menuitem failed\n");
1671 /* Search by id - returns the item which precedes the popup menu */
1672 memset( &info, 0, sizeof info );
1673 strback[0] = 0x00;
1674 info.cbSize = sizeof(MENUITEMINFO);
1675 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1676 info.dwTypeData = strback;
1677 info.cch = sizeof(strback);
1678 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1680 ok (rc, "Getting the menu items info failed\n");
1681 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1682 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1684 DestroyMenu( hmenu );
1685 DestroyMenu( hmenuSub );
1688 Case 3: Menu containing a popup menu which in turn
1689 contains 2 items with the same id as the popup itself
1692 hmenu = CreateMenu();
1693 hmenuSub = CreateMenu();
1695 memset( &info, 0, sizeof info );
1696 info.cbSize = sizeof info;
1697 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1698 info.fType = MFT_STRING;
1699 info.dwTypeData = menuitem;
1700 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1702 rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1703 ok (rc, "Inserting the popup menu into the main menu failed\n");
1705 rc = InsertMenuItem(hmenuSub, 0, TRUE, &info );
1706 ok (rc, "Inserting the sub menu menuitem failed\n");
1708 memset( &info, 0, sizeof info );
1709 info.cbSize = sizeof info;
1710 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1711 info.fType = MFT_STRING;
1712 info.dwTypeData = menuitem2;
1713 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1715 rc = InsertMenuItem(hmenuSub, 1, TRUE, &info );
1716 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
1718 /* Prove that you can't query the id of a popup directly (By position) */
1719 id = GetMenuItemID(hmenu, 0);
1720 ok (id == -1, "Getting the sub menu id should have failed because its a popup (gave %x)\n", id);
1722 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1723 memset( &info, 0, sizeof info );
1724 strback[0] = 0x00;
1725 info.cbSize = sizeof(MENUITEMINFO);
1726 info.fMask = MIIM_STRING | MIIM_ID;
1727 info.dwTypeData = strback;
1728 info.cch = sizeof(strback);
1730 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
1731 ok (rc, "Getting the menus info failed\n");
1732 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
1733 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1734 DestroyMenu( hmenu );
1735 DestroyMenu( hmenuSub );
1738 Case 4: Menu containing 2 popup menus, the second
1739 contains 2 items with the same id as the first popup menu
1741 hmenu = CreateMenu();
1742 hmenuSub = CreateMenu();
1743 hmenuSub2 = CreateMenu();
1745 rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1746 ok (rc, "Inserting the popup menu into the main menu failed\n");
1748 rc = InsertMenu(hmenu, 1, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub2, "Submenu2");
1749 ok (rc, "Inserting the popup menu into the main menu failed\n");
1751 memset( &info, 0, sizeof info );
1752 info.cbSize = sizeof info;
1753 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1754 info.fType = MFT_STRING;
1755 info.dwTypeData = menuitem;
1756 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1758 rc = InsertMenuItem(hmenuSub2, 0, TRUE, &info );
1759 ok (rc, "Inserting the sub menu menuitem failed\n");
1761 memset( &info, 0, sizeof info );
1762 info.cbSize = sizeof info;
1763 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1764 info.fType = MFT_STRING;
1765 info.dwTypeData = menuitem2;
1766 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1768 rc = InsertMenuItem(hmenuSub2, 1, TRUE, &info );
1769 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
1771 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1772 memset( &info, 0, sizeof info );
1773 strback[0] = 0x00;
1774 info.cbSize = sizeof(MENUITEMINFO);
1775 info.fMask = MIIM_STRING | MIIM_ID;
1776 info.dwTypeData = strback;
1777 info.cch = sizeof(strback);
1779 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
1780 ok (rc, "Getting the menus info failed\n");
1781 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
1782 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1784 memset( &info, 0, sizeof info );
1785 strback[0] = 0x00;
1786 info.cbSize = sizeof(MENUITEMINFO);
1787 info.fMask = MIIM_STRING | MIIM_ID;
1788 info.dwTypeData = strback;
1789 info.cch = sizeof(strback);
1791 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub2, FALSE, &info);
1792 ok (rc, "Getting the menus info failed\n");
1793 ok (info.wID == (UINT_PTR)hmenuSub2, "IDs differ for popup menu\n");
1794 ok (!strcmp(info.dwTypeData, "Submenu2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1796 DestroyMenu( hmenu );
1797 DestroyMenu( hmenuSub );
1798 DestroyMenu( hmenuSub2 );
1802 Case 5: Menu containing a popup menu which in turn
1803 contains an item with a different id than the popup menu.
1804 This tests the fallback to a popup menu ID.
1807 hmenu = CreateMenu();
1808 hmenuSub = CreateMenu();
1810 rc = AppendMenu(hmenu, MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1811 ok (rc, "Appending the popup menu to the main menu failed\n");
1813 rc = AppendMenu(hmenuSub, MF_STRING, 102, "Item");
1814 ok (rc, "Appending the item to the popup menu failed\n");
1816 /* Set the ID for hmenuSub */
1817 info.cbSize = sizeof(info);
1818 info.fMask = MIIM_ID;
1819 info.wID = 101;
1821 rc = SetMenuItemInfo(hmenu, 0, TRUE, &info);
1822 ok(rc, "Setting the ID for the popup menu failed\n");
1824 /* Check if the ID has been set */
1825 info.wID = 0;
1826 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info);
1827 ok(rc, "Getting the ID for the popup menu failed\n");
1828 ok(info.wID == 101, "The ID for the popup menu has not been set\n");
1830 /* Prove getting the item info via ID returns the popup menu */
1831 memset( &info, 0, sizeof(info));
1832 strback[0] = 0x00;
1833 info.cbSize = sizeof(MENUITEMINFO);
1834 info.fMask = MIIM_STRING | MIIM_ID;
1835 info.dwTypeData = strback;
1836 info.cch = sizeof(strback);
1838 rc = GetMenuItemInfo(hmenu, 101, FALSE, &info);
1839 ok (rc, "Getting the menu info failed\n");
1840 ok (info.wID == 101, "IDs differ\n");
1841 ok (!strcmp(info.dwTypeData, "Submenu"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1843 /* Also look for the menu item */
1844 memset( &info, 0, sizeof(info));
1845 strback[0] = 0x00;
1846 info.cbSize = sizeof(MENUITEMINFO);
1847 info.fMask = MIIM_STRING | MIIM_ID;
1848 info.dwTypeData = strback;
1849 info.cch = sizeof(strback);
1851 rc = GetMenuItemInfo(hmenu, 102, FALSE, &info);
1852 ok (rc, "Getting the menu info failed\n");
1853 ok (info.wID == 102, "IDs differ\n");
1854 ok (!strcmp(info.dwTypeData, "Item"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1856 DestroyMenu(hmenu);
1857 DestroyMenu(hmenuSub);
1860 struct menu_item_pair_s {
1861 UINT uMenu; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
1862 * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
1863 * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
1864 UINT uItem;
1867 static struct menu_mouse_tests_s {
1868 DWORD type;
1869 struct menu_item_pair_s menu_item_pairs[5]; /* for mousing */
1870 WORD wVk[5]; /* keys */
1871 BOOL bMenuVisible;
1872 BOOL _todo_wine;
1873 } menu_tests[] = {
1874 /* for each test, send keys or clicks and check for menu visibility */
1875 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE }, /* test 0 */
1876 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
1877 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
1878 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
1879 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
1880 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
1881 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
1882 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, VK_ESCAPE, 0}, FALSE, FALSE },
1883 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', VK_ESCAPE, 0}, TRUE, FALSE },
1884 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
1885 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
1886 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
1887 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
1888 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
1889 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
1890 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
1891 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
1892 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
1893 { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, TRUE, FALSE },
1894 { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, FALSE, FALSE },
1896 { INPUT_MOUSE, {{1, 2}, {0}}, {0}, TRUE, TRUE }, /* test 20 */
1897 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
1898 { INPUT_MOUSE, {{1, 0}, {0}}, {0}, TRUE, TRUE },
1899 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
1900 { INPUT_MOUSE, {{1, 0}, {2, 2}, {0}}, {0}, TRUE, TRUE },
1901 { INPUT_MOUSE, {{2, 1}, {0}}, {0}, FALSE, FALSE },
1902 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
1903 { INPUT_MOUSE, {{3, 0}, {0}}, {0}, FALSE, FALSE },
1904 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
1905 { INPUT_MOUSE, {{3, 1}, {0}}, {0}, TRUE, TRUE },
1906 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
1907 { -1 }
1910 static void send_key(WORD wVk)
1912 TEST_INPUT i[2];
1913 memset(i, 0, sizeof(i));
1914 i[0].type = i[1].type = INPUT_KEYBOARD;
1915 i[0].u.ki.wVk = i[1].u.ki.wVk = wVk;
1916 i[1].u.ki.dwFlags = KEYEVENTF_KEYUP;
1917 pSendInput(2, (INPUT *) i, sizeof(INPUT));
1920 static BOOL click_menu(HANDLE hWnd, struct menu_item_pair_s *mi)
1922 HMENU hMenu = hMenus[mi->uMenu];
1923 TEST_INPUT i[3];
1924 MSG msg;
1925 RECT r;
1926 int screen_w = GetSystemMetrics(SM_CXSCREEN);
1927 int screen_h = GetSystemMetrics(SM_CYSCREEN);
1928 BOOL ret = GetMenuItemRect(mi->uMenu > 2 ? NULL : hWnd, hMenu, mi->uItem, &r);
1929 if(!ret) return FALSE;
1931 memset(i, 0, sizeof(i));
1932 i[0].type = i[1].type = i[2].type = INPUT_MOUSE;
1933 i[0].u.mi.dx = i[1].u.mi.dx = i[2].u.mi.dx
1934 = ((r.left + 5) * 65535) / screen_w;
1935 i[0].u.mi.dy = i[1].u.mi.dy = i[2].u.mi.dy
1936 = ((r.top + 5) * 65535) / screen_h;
1937 i[0].u.mi.dwFlags = i[1].u.mi.dwFlags = i[2].u.mi.dwFlags
1938 = MOUSEEVENTF_ABSOLUTE;
1939 i[0].u.mi.dwFlags |= MOUSEEVENTF_MOVE;
1940 i[1].u.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
1941 i[2].u.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
1942 ret = pSendInput(3, (INPUT *) i, sizeof(INPUT));
1944 /* hack to prevent mouse message buildup in Wine */
1945 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
1946 return ret;
1949 static DWORD WINAPI test_menu_input_thread(LPVOID lpParameter)
1951 int i, j;
1952 HANDLE hWnd = lpParameter;
1954 Sleep(500);
1955 /* mixed keyboard/mouse test */
1956 for (i = 0; menu_tests[i].type != -1; i++)
1958 int ret = TRUE, elapsed = 0;
1960 got_input = i && menu_tests[i-1].bMenuVisible;
1962 if (menu_tests[i].type == INPUT_KEYBOARD)
1963 for (j = 0; menu_tests[i].wVk[j] != 0; j++)
1964 send_key(menu_tests[i].wVk[j]);
1965 else
1966 for (j = 0; menu_tests[i].menu_item_pairs[j].uMenu != 0; j++)
1967 if (!(ret = click_menu(hWnd, &menu_tests[i].menu_item_pairs[j]))) break;
1969 if (!ret)
1971 skip( "test %u: failed to send input\n", i );
1972 PostMessage( hWnd, WM_CANCELMODE, 0, 0 );
1973 return 0;
1975 while (menu_tests[i].bMenuVisible != bMenuVisible)
1977 if (elapsed > 200)
1978 break;
1979 elapsed += 20;
1980 Sleep(20);
1983 if (!got_input)
1985 skip( "test %u: didn't receive input\n", i );
1986 PostMessage( hWnd, WM_CANCELMODE, 0, 0 );
1987 return 0;
1990 if (menu_tests[i]._todo_wine)
1992 todo_wine {
1993 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
1996 else
1997 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
1999 return 0;
2002 static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam,
2003 LPARAM lParam)
2005 switch (msg) {
2006 case WM_ENTERMENULOOP:
2007 bMenuVisible = TRUE;
2008 break;
2009 case WM_EXITMENULOOP:
2010 bMenuVisible = FALSE;
2011 break;
2012 case WM_KEYDOWN:
2013 case WM_SYSKEYDOWN:
2014 case WM_MOUSEMOVE:
2015 case WM_LBUTTONDOWN:
2016 case WM_LBUTTONUP:
2017 case WM_NCMOUSEMOVE:
2018 case WM_NCLBUTTONDOWN:
2019 case WM_NCLBUTTONUP:
2020 got_input = TRUE;
2021 /* fall through */
2022 default:
2023 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2025 return 0;
2028 static void test_menu_input(void) {
2029 MSG msg;
2030 WNDCLASSA wclass;
2031 HINSTANCE hInstance = GetModuleHandleA( NULL );
2032 HANDLE hThread, hWnd;
2033 DWORD tid;
2035 if (!pSendInput)
2037 win_skip("SendInput is not available\n");
2038 return;
2041 wclass.lpszClassName = "MenuTestClass";
2042 wclass.style = CS_HREDRAW | CS_VREDRAW;
2043 wclass.lpfnWndProc = WndProc;
2044 wclass.hInstance = hInstance;
2045 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
2046 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
2047 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2048 wclass.lpszMenuName = 0;
2049 wclass.cbClsExtra = 0;
2050 wclass.cbWndExtra = 0;
2051 assert (RegisterClassA( &wclass ));
2052 assert (hWnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
2053 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2054 400, 200, NULL, NULL, hInstance, NULL) );
2056 /* fixed menus */
2057 hMenus[3] = CreatePopupMenu();
2058 AppendMenu(hMenus[3], MF_STRING, 0, "&Enabled");
2059 AppendMenu(hMenus[3], MF_STRING|MF_DISABLED, 0, "&Disabled");
2061 hMenus[2] = CreatePopupMenu();
2062 AppendMenu(hMenus[2], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[3], "&Popup");
2063 AppendMenu(hMenus[2], MF_STRING, 0, "&Enabled");
2064 AppendMenu(hMenus[2], MF_STRING|MF_DISABLED, 0, "&Disabled");
2066 hMenus[1] = CreateMenu();
2067 AppendMenu(hMenus[1], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[2], "&Menu");
2068 AppendMenu(hMenus[1], MF_STRING, 0, "&Enabled");
2069 AppendMenu(hMenus[1], MF_STRING|MF_DISABLED, 0, "&Disabled");
2071 SetMenu(hWnd, hMenus[1]);
2072 ShowWindow(hWnd, SW_SHOW);
2073 UpdateWindow(hWnd);
2075 hThread = CreateThread(NULL, 0, test_menu_input_thread, hWnd, 0, &tid);
2076 while(1)
2078 if (WAIT_TIMEOUT != WaitForSingleObject(hThread, 50))
2079 break;
2080 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2082 DestroyWindow(hWnd);
2085 static void test_menu_flags( void )
2087 HMENU hMenu, hPopupMenu;
2089 hMenu = CreateMenu();
2090 hPopupMenu = CreatePopupMenu();
2092 AppendMenu(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2094 AppendMenu(hPopupMenu, MF_STRING | MF_HILITE | MF_DEFAULT, 101, "Item 1");
2095 InsertMenu(hPopupMenu, 1, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 102, "Item 2");
2096 AppendMenu(hPopupMenu, MF_STRING, 103, "Item 3");
2097 ModifyMenu(hPopupMenu, 2, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 103, "Item 3");
2099 ok(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_HILITE,
2100 "AppendMenu should accept MF_HILITE\n");
2101 ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2102 "InsertMenu should accept MF_HILITE\n");
2103 ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2104 "ModifyMenu should accept MF_HILITE\n");
2106 ok(!(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_DEFAULT),
2107 "AppendMenu must not accept MF_DEFAULT\n");
2108 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_DEFAULT),
2109 "InsertMenu must not accept MF_DEFAULT\n");
2110 ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_DEFAULT),
2111 "ModifyMenu must not accept MF_DEFAULT\n");
2113 DestroyMenu(hMenu);
2116 static void test_menu_hilitemenuitem( void )
2118 HMENU hMenu, hPopupMenu;
2119 WNDCLASSA wclass;
2120 HWND hWnd;
2122 wclass.lpszClassName = "HiliteMenuTestClass";
2123 wclass.style = CS_HREDRAW | CS_VREDRAW;
2124 wclass.lpfnWndProc = WndProc;
2125 wclass.hInstance = GetModuleHandleA( NULL );
2126 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
2127 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
2128 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2129 wclass.lpszMenuName = 0;
2130 wclass.cbClsExtra = 0;
2131 wclass.cbWndExtra = 0;
2132 assert (RegisterClassA( &wclass ));
2133 assert (hWnd = CreateWindowA( wclass.lpszClassName, "HiliteMenuTest",
2134 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2135 400, 200, NULL, NULL, wclass.hInstance, NULL) );
2137 hMenu = CreateMenu();
2138 hPopupMenu = CreatePopupMenu();
2140 AppendMenu(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2142 AppendMenu(hPopupMenu, MF_STRING, 101, "Item 1");
2143 AppendMenu(hPopupMenu, MF_STRING, 102, "Item 2");
2144 AppendMenu(hPopupMenu, MF_STRING, 103, "Item 3");
2146 SetMenu(hWnd, hMenu);
2148 /* test invalid arguments */
2150 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2151 "HiliteMenuItem: Item 2 is hilited\n");
2153 SetLastError(0xdeadbeef);
2154 todo_wine
2156 ok(!HiliteMenuItem(NULL, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2157 "HiliteMenuItem: call should have failed.\n");
2159 ok(GetLastError() == 0xdeadbeef || /* 9x */
2160 GetLastError() == ERROR_INVALID_WINDOW_HANDLE /* NT */,
2161 "HiliteMenuItem: expected error ERROR_INVALID_WINDOW_HANDLE, got: %d\n", GetLastError());
2163 SetLastError(0xdeadbeef);
2164 ok(!HiliteMenuItem(hWnd, NULL, 1, MF_HILITE | MF_BYPOSITION),
2165 "HiliteMenuItem: call should have failed.\n");
2166 ok(GetLastError() == 0xdeadbeef || /* 9x */
2167 GetLastError() == ERROR_INVALID_MENU_HANDLE /* NT */,
2168 "HiliteMenuItem: expected error ERROR_INVALID_MENU_HANDLE, got: %d\n", GetLastError());
2170 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2171 "HiliteMenuItem: Item 2 is hilited\n");
2173 /* either MF_HILITE or MF_UNHILITE *and* MF_BYCOMMAND or MF_BYPOSITION need to be set */
2175 SetLastError(0xdeadbeef);
2176 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_BYPOSITION),
2177 "HiliteMenuItem: call should have succeeded.\n");
2178 ok(GetLastError() == 0xdeadbeef,
2179 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2181 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2182 "HiliteMenuItem: Item 2 is hilited\n");
2184 SetLastError(0xdeadbeef);
2185 todo_wine
2187 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE),
2188 "HiliteMenuItem: call should have succeeded.\n");
2190 ok(GetLastError() == 0xdeadbeef,
2191 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2193 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2194 "HiliteMenuItem: Item 2 is hilited\n");
2196 /* hilite a menu item (by position) */
2198 SetLastError(0xdeadbeef);
2199 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2200 "HiliteMenuItem: call should not have failed.\n");
2201 ok(GetLastError() == 0xdeadbeef,
2202 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2204 todo_wine
2206 ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2207 "HiliteMenuItem: Item 2 is not hilited\n");
2210 /* unhilite a menu item (by position) */
2212 SetLastError(0xdeadbeef);
2213 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_UNHILITE | MF_BYPOSITION),
2214 "HiliteMenuItem: call should not have failed.\n");
2215 ok(GetLastError() == 0xdeadbeef,
2216 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2218 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2219 "HiliteMenuItem: Item 2 is hilited\n");
2221 /* hilite a menu item (by command) */
2223 SetLastError(0xdeadbeef);
2224 ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_HILITE | MF_BYCOMMAND),
2225 "HiliteMenuItem: call should not have failed.\n");
2226 ok(GetLastError() == 0xdeadbeef,
2227 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2229 todo_wine
2231 ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2232 "HiliteMenuItem: Item 3 is not hilited\n");
2235 /* unhilite a menu item (by command) */
2237 SetLastError(0xdeadbeef);
2238 ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_UNHILITE | MF_BYCOMMAND),
2239 "HiliteMenuItem: call should not have failed.\n");
2240 ok(GetLastError() == 0xdeadbeef,
2241 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2243 ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE),
2244 "HiliteMenuItem: Item 3 is hilited\n");
2246 DestroyWindow(hWnd);
2249 static void check_menu_items(HMENU hmenu, UINT checked_cmd, UINT checked_type,
2250 UINT checked_state)
2252 INT i, count;
2254 count = GetMenuItemCount(hmenu);
2255 ok (count != -1, "GetMenuItemCount returned -1\n");
2257 for (i = 0; i < count; i++)
2259 BOOL ret;
2260 MENUITEMINFO mii;
2262 memset(&mii, 0, sizeof(mii));
2263 mii.cbSize = sizeof(mii);
2264 mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU;
2265 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2266 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2267 #if 0
2268 trace("item #%u: fType %04x, fState %04x, wID %u, hSubMenu %p\n",
2269 i, mii.fType, mii.fState, mii.wID, mii.hSubMenu);
2270 #endif
2271 if (mii.hSubMenu)
2273 ok(mii.wID == (UINT_PTR)mii.hSubMenu, "id %u: wID should be equal to hSubMenu\n", checked_cmd);
2274 check_menu_items(mii.hSubMenu, checked_cmd, checked_type, checked_state);
2276 else
2278 if (mii.wID == checked_cmd)
2280 ok(mii.fType == checked_type, "id %u: expected fType %04x, got %04x\n", checked_cmd, checked_type, mii.fType);
2281 ok(mii.fState == checked_state, "id %u: expected fState %04x, got %04x\n", checked_cmd, checked_state, mii.fState);
2282 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2284 else
2286 ok(mii.fType != MFT_RADIOCHECK, "id %u: not expected fType MFT_RADIOCHECK on cmd %u\n", checked_cmd, mii.wID);
2288 if (mii.fType == MFT_SEPARATOR)
2290 ok(mii.fState == MFS_GRAYED, "id %u: expected fState MFS_GRAYED, got %04x\n", checked_cmd, mii.fState);
2291 ok(mii.wID == 0, "id %u: expected wID 0, got %u\n", checked_cmd, mii.wID);
2293 else
2295 ok(mii.fState == 0, "id %u: expected fState 0, got %04x\n", checked_cmd, mii.fState);
2296 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2303 static void clear_ftype_and_state(HMENU hmenu, UINT id, UINT flags)
2305 BOOL ret;
2306 MENUITEMINFO mii;
2308 memset(&mii, 0, sizeof(mii));
2309 mii.cbSize = sizeof(mii);
2310 mii.fMask = MIIM_FTYPE | MIIM_STATE;
2311 ret = SetMenuItemInfo(hmenu, id, (flags & MF_BYPOSITION) != 0, &mii);
2312 ok(ret, "SetMenuItemInfo(%u) failed\n", id);
2315 static void test_CheckMenuRadioItem(void)
2317 BOOL ret;
2318 HMENU hmenu;
2320 hmenu = LoadMenu(GetModuleHandle(0), MAKEINTRESOURCE(1));
2321 assert(hmenu != 0);
2323 check_menu_items(hmenu, -1, 0, 0);
2325 ret = CheckMenuRadioItem(hmenu, 100, 100, 100, MF_BYCOMMAND);
2326 ok(ret, "CheckMenuRadioItem failed\n");
2327 check_menu_items(hmenu, 100, MFT_RADIOCHECK, MFS_CHECKED);
2329 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2330 ret = CheckMenuRadioItem(hmenu, 100, 100, -1, MF_BYCOMMAND);
2331 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2332 check_menu_items(hmenu, 100, MFT_RADIOCHECK, 0);
2334 /* clear check */
2335 clear_ftype_and_state(hmenu, 100, MF_BYCOMMAND);
2336 check_menu_items(hmenu, -1, 0, 0);
2338 /* first and checked items are on different menus */
2339 ret = CheckMenuRadioItem(hmenu, 0, 300, 202, MF_BYCOMMAND);
2340 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2341 check_menu_items(hmenu, -1, 0, 0);
2343 ret = CheckMenuRadioItem(hmenu, 200, 300, 202, MF_BYCOMMAND);
2344 ok(ret, "CheckMenuRadioItem failed\n");
2345 check_menu_items(hmenu, 202, MFT_RADIOCHECK, MFS_CHECKED);
2347 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2348 ret = CheckMenuRadioItem(hmenu, 202, 202, -1, MF_BYCOMMAND);
2349 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2350 check_menu_items(hmenu, 202, MFT_RADIOCHECK, 0);
2352 /* clear check */
2353 clear_ftype_and_state(hmenu, 202, MF_BYCOMMAND);
2354 check_menu_items(hmenu, -1, 0, 0);
2356 /* just for fun, try to check separator */
2357 ret = CheckMenuRadioItem(hmenu, 0, 300, 0, MF_BYCOMMAND);
2358 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2359 check_menu_items(hmenu, -1, 0, 0);
2362 static void test_menu_resource_layout(void)
2364 static const struct
2366 MENUITEMTEMPLATEHEADER mith;
2367 WORD data[14];
2368 } menu_template =
2370 { 0, 0 }, /* versionNumber, offset */
2372 /* mtOption, mtID, mtString[] '\0' terminated */
2373 MF_STRING, 1, 'F', 0,
2374 MF_STRING, 2, 0,
2375 MF_SEPARATOR, 3, 0,
2376 /* MF_SEPARATOR, 4, 'S', 0, FIXME: Wine ignores 'S' */
2377 MF_STRING|MF_GRAYED|MF_END, 5, 'E', 0
2380 static const struct
2382 UINT type, state, id;
2383 const char *str;
2384 } menu_data[] =
2386 { MF_STRING, MF_ENABLED, 1, "F" },
2387 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 2, "" },
2388 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 3, "" },
2389 /*{ MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 4, "S" }, FIXME: Wine ignores 'S'*/
2390 { MF_STRING, MF_GRAYED, 5, "E" },
2391 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 6, "" },
2392 { MF_STRING, MF_ENABLED, 7, "" },
2393 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 8, "" }
2395 HMENU hmenu;
2396 INT count, i;
2397 BOOL ret;
2399 hmenu = LoadMenuIndirect(&menu_template);
2400 ok(hmenu != 0, "LoadMenuIndirect error %u\n", GetLastError());
2402 ret = AppendMenu(hmenu, MF_STRING, 6, NULL);
2403 ok(ret, "AppendMenu failed\n");
2404 ret = AppendMenu(hmenu, MF_STRING, 7, "\0");
2405 ok(ret, "AppendMenu failed\n");
2406 ret = AppendMenu(hmenu, MF_SEPARATOR, 8, "separator");
2407 ok(ret, "AppendMenu failed\n");
2409 count = GetMenuItemCount(hmenu);
2410 ok(count == sizeof(menu_data)/sizeof(menu_data[0]),
2411 "expected %u menu items, got %u\n",
2412 (UINT)(sizeof(menu_data)/sizeof(menu_data[0])), count);
2414 for (i = 0; i < count; i++)
2416 char buf[20];
2417 MENUITEMINFO mii;
2419 memset(&mii, 0, sizeof(mii));
2420 mii.cbSize = sizeof(mii);
2421 mii.dwTypeData = buf;
2422 mii.cch = sizeof(buf);
2423 mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_STRING;
2424 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2425 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2426 #if 0
2427 trace("item #%u: fType %04x, fState %04x, wID %u, dwTypeData %s\n",
2428 i, mii.fType, mii.fState, mii.wID, (LPCSTR)mii.dwTypeData);
2429 #endif
2430 ok(mii.fType == menu_data[i].type,
2431 "%u: expected fType %04x, got %04x\n", i, menu_data[i].type, mii.fType);
2432 ok(mii.fState == menu_data[i].state,
2433 "%u: expected fState %04x, got %04x\n", i, menu_data[i].state, mii.fState);
2434 ok(mii.wID == menu_data[i].id,
2435 "%u: expected wID %04x, got %04x\n", i, menu_data[i].id, mii.wID);
2436 ok(mii.cch == strlen(menu_data[i].str),
2437 "%u: expected cch %u, got %u\n", i, (UINT)strlen(menu_data[i].str), mii.cch);
2438 ok(!strcmp(mii.dwTypeData, menu_data[i].str),
2439 "%u: expected dwTypeData %s, got %s\n", i, menu_data[i].str, (LPCSTR)mii.dwTypeData);
2442 DestroyMenu(hmenu);
2445 struct menu_data
2447 UINT type, id;
2448 const char *str;
2451 static HMENU create_menu_from_data(const struct menu_data *item, INT item_count)
2453 HMENU hmenu;
2454 INT i;
2455 BOOL ret;
2457 hmenu = CreateMenu();
2458 assert(hmenu != 0);
2460 for (i = 0; i < item_count; i++)
2462 SetLastError(0xdeadbeef);
2463 ret = AppendMenu(hmenu, item[i].type, item[i].id, item[i].str);
2464 ok(ret, "%d: AppendMenu(%04x, %04x, %p) error %u\n",
2465 i, item[i].type, item[i].id, item[i].str, GetLastError());
2467 return hmenu;
2470 /* use InsertMenuItem: does not set the MFT_BITMAP flag,
2471 * and does not accept non-magic bitmaps with invalid
2472 * bitmap handles */
2473 static HMENU create_menuitem_from_data(const struct menu_data *item, INT item_count)
2475 HMENU hmenu;
2476 INT i;
2477 BOOL ret;
2478 MENUITEMINFO mii = { sizeof( MENUITEMINFO)};
2480 hmenu = CreateMenu();
2481 assert(hmenu != 0);
2483 for (i = 0; i < item_count; i++)
2485 SetLastError(0xdeadbeef);
2487 mii.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STATE;
2488 mii.fType = 0;
2489 if( item[i].type & MFT_BITMAP)
2491 mii.fMask |= MIIM_BITMAP;
2492 mii.hbmpItem = (HBITMAP)item[i].str;
2494 else if( item[i].type & MFT_SEPARATOR)
2495 mii.fType = MFT_SEPARATOR;
2496 else
2498 mii.fMask |= MIIM_STRING;
2499 mii.dwTypeData = (LPSTR)item[i].str;
2500 mii.cch = strlen( item[i].str);
2502 mii.fState = 0;
2503 if( item[i].type & MF_HELP) mii.fType |= MF_HELP;
2504 mii.wID = item[i].id;
2505 ret = InsertMenuItem( hmenu, -1, TRUE, &mii);
2506 ok(ret, "%d: InsertMenuItem(%04x, %04x, %p) error %u\n",
2507 i, item[i].type, item[i].id, item[i].str, GetLastError());
2509 return hmenu;
2512 static void compare_menu_data(HMENU hmenu, const struct menu_data *item, INT item_count)
2514 INT count, i;
2515 BOOL ret;
2517 count = GetMenuItemCount(hmenu);
2518 ok(count == item_count, "expected %d, got %d menu items\n", count, item_count);
2520 for (i = 0; i < count; i++)
2522 char buf[20];
2523 MENUITEMINFO mii;
2525 memset(&mii, 0, sizeof(mii));
2526 mii.cbSize = sizeof(mii);
2527 mii.dwTypeData = buf;
2528 mii.cch = sizeof(buf);
2529 mii.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_BITMAP;
2530 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2531 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2532 #if 0
2533 trace("item #%u: fType %04x, fState %04x, wID %04x, hbmp %p\n",
2534 i, mii.fType, mii.fState, mii.wID, mii.hbmpItem);
2535 #endif
2536 ok(mii.fType == item[i].type,
2537 "%u: expected fType %04x, got %04x\n", i, item[i].type, mii.fType);
2538 ok(mii.wID == item[i].id,
2539 "%u: expected wID %04x, got %04x\n", i, item[i].id, mii.wID);
2540 if (mii.hbmpItem || !item[i].str)
2541 /* For some reason Windows sets high word to not 0 for
2542 * not "magic" ids.
2544 ok(LOWORD(mii.hbmpItem) == LOWORD(item[i].str),
2545 "%u: expected hbmpItem %p, got %p\n", i, item[i].str, mii.hbmpItem);
2546 else
2548 ok(mii.cch == strlen(item[i].str),
2549 "%u: expected cch %u, got %u\n", i, (UINT)strlen(item[i].str), mii.cch);
2550 ok(!strcmp(mii.dwTypeData, item[i].str),
2551 "%u: expected dwTypeData %s, got %s\n", i, item[i].str, (LPCSTR)mii.dwTypeData);
2556 static void test_InsertMenu(void)
2558 HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
2559 /* Note: XP treats only bitmap handles 1 - 6 as "magic" ones
2560 * regardless of their id.
2562 static const struct menu_data in1[] =
2564 { MF_STRING, 1, "File" },
2565 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) },
2566 { MF_STRING|MF_HELP, 2, "Help" }
2568 static const struct menu_data out1[] =
2570 { MF_STRING, 1, "File" },
2571 { MF_STRING|MF_HELP, 2, "Help" },
2572 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) }
2574 static const struct menu_data out1a[] =
2576 { MF_STRING, 1, "File" },
2577 { MF_STRING|MF_HELP, 2, "Help" },
2578 { MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) }
2580 const struct menu_data in2[] =
2582 { MF_STRING, 1, "File" },
2583 { MF_BITMAP|MF_HELP, SC_CLOSE, (char*)hbm },
2584 { MF_STRING|MF_HELP, 2, "Help" }
2586 const struct menu_data out2[] =
2588 { MF_STRING, 1, "File" },
2589 { MF_BITMAP|MF_HELP, SC_CLOSE, (char*)hbm },
2590 { MF_STRING|MF_HELP, 2, "Help" }
2592 const struct menu_data out2a[] =
2594 { MF_STRING, 1, "File" },
2595 { MF_HELP, SC_CLOSE, (char*)hbm },
2596 { MF_STRING|MF_HELP, 2, "Help" }
2598 static const struct menu_data in3[] =
2600 { MF_STRING, 1, "File" },
2601 { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) },
2602 { MF_STRING|MF_HELP, 2, "Help" }
2604 static const struct menu_data out3[] =
2606 { MF_STRING, 1, "File" },
2607 { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(0) },
2608 { MF_STRING|MF_HELP, 2, "Help" },
2610 static const struct menu_data in4[] =
2612 { MF_STRING, 1, "File" },
2613 { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCE(1) },
2614 { MF_STRING|MF_HELP, 2, "Help" }
2616 static const struct menu_data out4[] =
2618 { MF_STRING, 1, "File" },
2619 { MF_STRING|MF_HELP, 2, "Help" },
2620 { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCE(1) }
2622 static const struct menu_data out4a[] =
2624 { MF_STRING, 1, "File" },
2625 { MF_STRING|MF_HELP, 2, "Help" },
2626 { MF_HELP, 1, MAKEINTRESOURCE(1) }
2628 HMENU hmenu;
2630 #define create_menu(a) create_menu_from_data((a), sizeof(a)/sizeof((a)[0]))
2631 #define create_menuitem(a) create_menuitem_from_data((a), sizeof(a)/sizeof((a)[0]))
2632 #define compare_menu(h, a) compare_menu_data((h), (a), sizeof(a)/sizeof((a)[0]))
2634 hmenu = create_menu(in1);
2635 compare_menu(hmenu, out1);
2636 DestroyMenu(hmenu);
2638 hmenu = create_menu(in2);
2639 compare_menu(hmenu, out2);
2640 DestroyMenu(hmenu);
2642 hmenu = create_menu(in3);
2643 compare_menu(hmenu, out3);
2644 DestroyMenu(hmenu);
2646 hmenu = create_menu(in4);
2647 compare_menu(hmenu, out4);
2648 DestroyMenu(hmenu);
2650 /* now using InsertMenuItemInfo */
2651 hmenu = create_menuitem(in1);
2652 compare_menu(hmenu, out1a);
2653 DestroyMenu(hmenu);
2655 hmenu = create_menuitem(in2);
2656 compare_menu(hmenu, out2a);
2657 DestroyMenu(hmenu);
2659 hmenu = create_menuitem(in3);
2660 compare_menu(hmenu, out3);
2661 DestroyMenu(hmenu);
2663 hmenu = create_menuitem(in4);
2664 compare_menu(hmenu, out4a);
2665 DestroyMenu(hmenu);
2667 #undef create_menu
2668 #undef create_menuitem
2669 #undef compare_menu
2672 static void test_menu_getmenuinfo(void)
2674 HMENU hmenu;
2675 MENUINFO mi = {0};
2676 BOOL ret;
2677 DWORD gle;
2679 if (!pGetMenuInfo)
2681 win_skip("GetMenuInfo is not available\n");
2682 return;
2685 /* create a menu */
2686 hmenu = CreateMenu();
2687 assert( hmenu);
2688 /* test some parameter errors */
2689 SetLastError(0xdeadbeef);
2690 ret = pGetMenuInfo( hmenu, NULL);
2691 gle= GetLastError();
2692 ok( !ret, "GetMenuInfo() should have failed\n");
2693 ok( gle == ERROR_INVALID_PARAMETER ||
2694 broken(gle == 0xdeadbeef), /* Win98, WinME */
2695 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2696 SetLastError(0xdeadbeef);
2697 mi.cbSize = 0;
2698 ret = pGetMenuInfo( hmenu, &mi);
2699 gle= GetLastError();
2700 ok( !ret, "GetMenuInfo() should have failed\n");
2701 ok( gle == ERROR_INVALID_PARAMETER ||
2702 broken(gle == 0xdeadbeef), /* Win98, WinME */
2703 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2704 SetLastError(0xdeadbeef);
2705 mi.cbSize = sizeof( MENUINFO);
2706 ret = pGetMenuInfo( hmenu, &mi);
2707 gle= GetLastError();
2708 ok( ret, "GetMenuInfo() should have succeeded\n");
2709 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2710 SetLastError(0xdeadbeef);
2711 mi.cbSize = 0;
2712 ret = pGetMenuInfo( NULL, &mi);
2713 gle= GetLastError();
2714 ok( !ret, "GetMenuInfo() should have failed\n");
2715 ok( gle == ERROR_INVALID_PARAMETER ||
2716 broken(gle == 0xdeadbeef), /* Win98, WinME */
2717 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2718 /* clean up */
2719 DestroyMenu( hmenu);
2720 return;
2723 static void test_menu_setmenuinfo(void)
2725 HMENU hmenu, hsubmenu;
2726 MENUINFO mi = {0};
2727 MENUITEMINFOA mii = {sizeof( MENUITEMINFOA)};
2728 BOOL ret;
2729 DWORD gle;
2731 if (!pGetMenuInfo || !pSetMenuInfo)
2733 win_skip("Get/SetMenuInfo are not available\n");
2734 return;
2737 /* create a menu with a submenu */
2738 hmenu = CreateMenu();
2739 hsubmenu = CreateMenu();
2740 assert( hmenu && hsubmenu);
2741 mii.fMask = MIIM_SUBMENU;
2742 mii.hSubMenu = hsubmenu;
2743 ret = InsertMenuItem( hmenu, 0, FALSE, &mii);
2744 ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
2745 /* test some parameter errors */
2746 SetLastError(0xdeadbeef);
2747 ret = pSetMenuInfo( hmenu, NULL);
2748 gle= GetLastError();
2749 ok( !ret, "SetMenuInfo() should have failed\n");
2750 ok( gle == ERROR_INVALID_PARAMETER ||
2751 broken(gle == 0xdeadbeef), /* Win98, WinME */
2752 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2753 SetLastError(0xdeadbeef);
2754 mi.cbSize = 0;
2755 ret = pSetMenuInfo( hmenu, &mi);
2756 gle= GetLastError();
2757 ok( !ret, "SetMenuInfo() should have failed\n");
2758 ok( gle == ERROR_INVALID_PARAMETER ||
2759 broken(gle == 0xdeadbeef), /* Win98, WinME */
2760 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2761 SetLastError(0xdeadbeef);
2762 mi.cbSize = sizeof( MENUINFO);
2763 ret = pSetMenuInfo( hmenu, &mi);
2764 gle= GetLastError();
2765 ok( ret, "SetMenuInfo() should have succeeded\n");
2766 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2767 SetLastError(0xdeadbeef);
2768 mi.cbSize = 0;
2769 ret = pSetMenuInfo( NULL, &mi);
2770 gle= GetLastError();
2771 ok( !ret, "SetMenuInfo() should have failed\n");
2772 ok( gle == ERROR_INVALID_PARAMETER ||
2773 broken(gle == 0xdeadbeef), /* Win98, WinME */
2774 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2775 /* functional tests */
2776 /* menu and submenu should have the CHECKORBMP style bit cleared */
2777 SetLastError(0xdeadbeef);
2778 mi.cbSize = sizeof( MENUINFO);
2779 mi.fMask = MIM_STYLE;
2780 ret = pGetMenuInfo( hmenu, &mi);
2781 gle= GetLastError();
2782 ok( ret, "GetMenuInfo() should have succeeded\n");
2783 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2784 ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2785 SetLastError(0xdeadbeef);
2786 mi.cbSize = sizeof( MENUINFO);
2787 mi.fMask = MIM_STYLE;
2788 ret = pGetMenuInfo( hsubmenu, &mi);
2789 gle= GetLastError();
2790 ok( ret, "GetMenuInfo() should have succeeded\n");
2791 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2792 ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2793 /* SetMenuInfo() */
2794 SetLastError(0xdeadbeef);
2795 mi.cbSize = sizeof( MENUINFO);
2796 mi.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS;
2797 mi.dwStyle = MNS_CHECKORBMP;
2798 ret = pSetMenuInfo( hmenu, &mi);
2799 gle= GetLastError();
2800 ok( ret, "SetMenuInfo() should have succeeded\n");
2801 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2802 /* Now both menus should have the MNS_CHECKORBMP style bit set */
2803 SetLastError(0xdeadbeef);
2804 mi.cbSize = sizeof( MENUINFO);
2805 mi.fMask = MIM_STYLE;
2806 ret = pGetMenuInfo( hmenu, &mi);
2807 gle= GetLastError();
2808 ok( ret, "GetMenuInfo() should have succeeded\n");
2809 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2810 ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2811 SetLastError(0xdeadbeef);
2812 mi.cbSize = sizeof( MENUINFO);
2813 mi.fMask = MIM_STYLE;
2814 ret = pGetMenuInfo( hsubmenu, &mi);
2815 gle= GetLastError();
2816 ok( ret, "GetMenuInfo() should have succeeded\n");
2817 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2818 ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2819 /* now repeat that without the APPLYTOSUBMENUS flag and another style bit */
2820 SetLastError(0xdeadbeef);
2821 mi.cbSize = sizeof( MENUINFO);
2822 mi.fMask = MIM_STYLE ;
2823 mi.dwStyle = MNS_NOCHECK;
2824 ret = pSetMenuInfo( hmenu, &mi);
2825 gle= GetLastError();
2826 ok( ret, "SetMenuInfo() should have succeeded\n");
2827 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2828 /* Now only the top menu should have the MNS_NOCHECK style bit set */
2829 SetLastError(0xdeadbeef);
2830 mi.cbSize = sizeof( MENUINFO);
2831 mi.fMask = MIM_STYLE;
2832 ret = pGetMenuInfo( hmenu, &mi);
2833 gle= GetLastError();
2834 ok( ret, "GetMenuInfo() should have succeeded\n");
2835 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2836 ok( mi.dwStyle & MNS_NOCHECK, "menustyle was expected to have the MNS_NOCHECK flag\n");
2837 SetLastError(0xdeadbeef);
2838 mi.cbSize = sizeof( MENUINFO);
2839 mi.fMask = MIM_STYLE;
2840 ret = pGetMenuInfo( hsubmenu, &mi);
2841 gle= GetLastError();
2842 ok( ret, "GetMenuInfo() should have succeeded\n");
2843 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2844 ok( !(mi.dwStyle & MNS_NOCHECK), "menustyle was not expected to have the MNS_NOCHECK flag\n");
2845 /* clean up */
2846 DestroyMenu( hsubmenu);
2847 DestroyMenu( hmenu);
2848 return;
2851 /* little func to easy switch either TrackPopupMenu() or TrackPopupMenuEx() */
2852 static DWORD MyTrackPopupMenu( int ex, HMENU hmenu, UINT flags, INT x, INT y, HWND hwnd, LPTPMPARAMS ptpm)
2854 return ex
2855 ? TrackPopupMenuEx( hmenu, flags, x, y, hwnd, ptpm)
2856 : TrackPopupMenu( hmenu, flags, x, y, 0, hwnd, NULL);
2859 /* some TrackPopupMenu and TrackPopupMenuEx tests */
2860 /* the LastError values differ between NO_ERROR and invalid handle */
2861 /* between all windows versions tested. The first value is that valid on XP */
2862 /* Vista was the only that made returned different error values */
2863 /* between the TrackPopupMenu and TrackPopupMenuEx functions */
2864 static void test_menu_trackpopupmenu(void)
2866 BOOL ret;
2867 HMENU hmenu;
2868 DWORD gle;
2869 int Ex;
2870 HWND hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
2871 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
2872 NULL, NULL, NULL, NULL);
2873 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
2874 if (!hwnd) return;
2875 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
2876 for( Ex = 0; Ex < 2; Ex++)
2878 hmenu = CreatePopupMenu();
2879 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
2880 if (!hmenu)
2882 DestroyWindow(hwnd);
2883 return;
2885 /* display the menu */
2886 /* start with an invalid menu handle */
2887 gle = 0xdeadbeef;
2888 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2889 ret = MyTrackPopupMenu( Ex, NULL, TPM_RETURNCMD, 100,100, hwnd, NULL);
2890 gle = GetLastError();
2891 ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
2892 ok( gle == ERROR_INVALID_MENU_HANDLE
2893 || broken (gle == 0xdeadbeef) /* win95 */
2894 || broken (gle == NO_ERROR) /* win98/ME */
2895 ,"TrackPopupMenu%s error got %u expected %u\n",
2896 Ex ? "Ex" : "", gle, ERROR_INVALID_MENU_HANDLE);
2897 ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
2898 "got unexpected message(s)%s%s%s\n",
2899 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2900 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2901 gflag_initmenu ? "WM_INITMENU": "");
2902 /* another one but not NULL */
2903 gle = 0xdeadbeef;
2904 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2905 ret = MyTrackPopupMenu( Ex, (HMENU)hwnd, TPM_RETURNCMD, 100,100, hwnd, NULL);
2906 gle = GetLastError();
2907 ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
2908 ok( gle == ERROR_INVALID_MENU_HANDLE
2909 || broken (gle == 0xdeadbeef) /* win95 */
2910 || broken (gle == NO_ERROR) /* win98/ME */
2911 ,"TrackPopupMenu%s error got %u expected %u\n",
2912 Ex ? "Ex" : "", gle, ERROR_INVALID_MENU_HANDLE);
2913 ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
2914 "got unexpected message(s)%s%s%s\n",
2915 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2916 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2917 gflag_initmenu ? "WM_INITMENU": "");
2918 /* now a somewhat successful call */
2919 gle = 0xdeadbeef;
2920 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2921 ret = MyTrackPopupMenu( Ex, hmenu, TPM_RETURNCMD, 100,100, hwnd, NULL);
2922 gle = GetLastError();
2923 ok( ret == 0, "TrackPopupMenu%s returned %d expected zero\n", Ex ? "Ex" : "", ret);
2924 ok( gle == NO_ERROR
2925 || gle == ERROR_INVALID_MENU_HANDLE /* NT4, win2k */
2926 || broken (gle == 0xdeadbeef) /* win95 */
2927 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
2928 Ex ? "Ex" : "", gle, NO_ERROR, ERROR_INVALID_MENU_HANDLE);
2929 ok( gflag_initmenupopup && gflag_entermenuloop && gflag_initmenu,
2930 "missed expected message(s)%s%s%s\n",
2931 !gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2932 !gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2933 !gflag_initmenu ? "WM_INITMENU": "");
2934 /* and another */
2935 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest");
2936 ok( ret, "AppendMenA has failed!\n");
2937 gle = 0xdeadbeef;
2938 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2939 ret = MyTrackPopupMenu( Ex, hmenu, TPM_RETURNCMD, 100,100, hwnd, NULL);
2940 gle = GetLastError();
2941 ok( ret == 0, "TrackPopupMenu%s returned %d expected zero\n", Ex ? "Ex" : "", ret);
2942 ok( gle == NO_ERROR
2943 || gle == ERROR_INVALID_MENU_HANDLE /* NT4, win2k and Vista in the TrackPopupMenuEx case */
2944 || broken (gle == 0xdeadbeef) /* win95 */
2945 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
2946 Ex ? "Ex" : "", gle, NO_ERROR, ERROR_INVALID_MENU_HANDLE);
2947 ok( gflag_initmenupopup && gflag_entermenuloop && gflag_initmenu,
2948 "missed expected message(s)%s%s%s\n",
2949 !gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2950 !gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2951 !gflag_initmenu ? "WM_INITMENU": "");
2952 DestroyMenu(hmenu);
2954 /* clean up */
2955 DestroyWindow(hwnd);
2958 static HMENU g_hmenu;
2960 static LRESULT WINAPI menu_track_again_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2962 switch (msg)
2964 case WM_ENTERMENULOOP:
2966 BOOL ret;
2968 /* try a recursive call */
2969 SetLastError(0xdeadbeef);
2970 ret = TrackPopupMenu(g_hmenu, 0, 100, 100, 0, hwnd, NULL);
2971 ok(ret == FALSE, "got %d\n", ret);
2972 ok(GetLastError() == ERROR_POPUP_ALREADY_ACTIVE ||
2973 broken(GetLastError() == 0xdeadbeef) /* W9x */, "got %d\n", GetLastError());
2975 /* exit menu modal loop
2976 * ( A SendMessage does not work on NT3.51 here ) */
2977 return PostMessage(hwnd, WM_CANCELMODE, 0, 0);
2980 return DefWindowProc(hwnd, msg, wparam, lparam);
2983 static void test_menu_trackagain(void)
2985 HWND hwnd;
2986 BOOL ret;
2988 hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
2989 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
2990 NULL, NULL, NULL, NULL);
2991 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
2992 if (!hwnd) return;
2993 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_track_again_wnd_proc);
2995 g_hmenu = CreatePopupMenu();
2996 ok(g_hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
2998 ret = TrackPopupMenu( g_hmenu, 0, 100, 100, 0, hwnd, NULL);
2999 todo_wine ok(ret == FALSE, "got %d\n", ret);
3001 DestroyMenu(g_hmenu);
3002 DestroyWindow(hwnd);
3005 /* test handling of WM_CANCELMODE messages */
3006 static int g_got_enteridle;
3007 static HWND g_hwndtosend;
3008 static LRESULT WINAPI menu_cancelmode_wnd_proc(HWND hwnd, UINT msg,
3009 WPARAM wparam, LPARAM lparam)
3011 switch (msg)
3013 case WM_ENTERMENULOOP:
3014 g_got_enteridle = 0;
3015 return SendMessage( g_hwndtosend, WM_CANCELMODE, 0, 0);
3016 case WM_ENTERIDLE:
3018 if( g_got_enteridle++ == 0) {
3019 /* little hack to get another WM_ENTERIDLE message */
3020 PostMessage( hwnd, WM_MOUSEMOVE, 0, 0);
3021 return SendMessage( g_hwndtosend, WM_CANCELMODE, 0, 0);
3023 pEndMenu();
3024 return TRUE;
3027 return DefWindowProc( hwnd, msg, wparam, lparam);
3030 static void test_menu_cancelmode(void)
3032 DWORD ret;
3033 HWND hwnd, hwndchild;
3034 HMENU menu;
3035 if( !pEndMenu) { /* win95 */
3036 win_skip( "EndMenu is not available\n");
3037 return;
3039 hwnd = CreateWindowEx( 0, MAKEINTATOM(atomMenuCheckClass), NULL,
3040 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
3041 NULL, NULL, NULL, NULL);
3042 hwndchild = CreateWindowEx( 0, MAKEINTATOM(atomMenuCheckClass), NULL,
3043 WS_VISIBLE | WS_CHILD, 10, 10, 20, 20,
3044 hwnd, NULL, NULL, NULL);
3045 ok( hwnd != NULL && hwndchild != NULL,
3046 "CreateWindowEx failed with error %d\n", GetLastError());
3047 g_hwndtosend = hwnd;
3048 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_cancelmode_wnd_proc);
3049 SetWindowLongPtr( hwndchild, GWLP_WNDPROC, (LONG_PTR)menu_cancelmode_wnd_proc);
3050 menu = CreatePopupMenu();
3051 ok( menu != NULL, "CreatePopupMenu failed with error %d\n", GetLastError());
3052 ret = AppendMenuA( menu, MF_STRING, 1, "winetest");
3053 ok( ret, "Functie failed lasterror is %u\n", GetLastError());
3054 /* seems to be needed only on wine :( */
3055 {MSG msg; while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);}
3056 /* test the effect of sending a WM_CANCELMODE message in the WM_INITMENULOOP
3057 * handler of the menu owner */
3058 /* test results is exctracted from variable g_got_enteridle. Possible values:
3059 * 0 : complete conformance. Sending WM_CANCELMODE cancels a menu initializing tracking
3060 * 1 : Sending WM_CANCELMODE cancels a menu that is in tracking state
3061 * 2 : Sending WM_CANCELMODE does not work
3063 /* menu owner is top level window */
3064 g_hwndtosend = hwnd;
3065 ret = TrackPopupMenu( menu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
3066 todo_wine {
3067 ok( g_got_enteridle == 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle);
3069 ok( g_got_enteridle < 2, "received %d WM_ENTERIDLE messages, should be less than 2\n", g_got_enteridle);
3070 /* menu owner is child window */
3071 g_hwndtosend = hwndchild;
3072 ret = TrackPopupMenu( menu, TPM_RETURNCMD, 100,100, 0, hwndchild, NULL);
3073 todo_wine {
3074 ok(g_got_enteridle == 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle);
3076 ok(g_got_enteridle < 2, "received %d WM_ENTERIDLE messages, should be less than 2\n", g_got_enteridle);
3077 /* now send the WM_CANCELMODE messages to the WRONG window */
3078 /* those should fail ( to have any effect) */
3079 g_hwndtosend = hwnd;
3080 ret = TrackPopupMenu( menu, TPM_RETURNCMD, 100,100, 0, hwndchild, NULL);
3081 ok( g_got_enteridle == 2, "received %d WM_ENTERIDLE messages, should be 2\n", g_got_enteridle);
3082 /* cleanup */
3083 DestroyMenu( menu);
3084 DestroyWindow( hwndchild);
3085 DestroyWindow( hwnd);
3088 /* show menu trees have a maximum depth */
3089 static void test_menu_maxdepth(void)
3091 #define NR_MENUS 100
3092 HMENU hmenus[ NR_MENUS];
3093 int i;
3094 DWORD ret;
3096 SetLastError(12345678);
3097 for( i = 0; i < NR_MENUS; i++) {
3098 hmenus[i] = CreatePopupMenu();
3099 if( !hmenus[i]) break;
3101 ok( i == NR_MENUS, "could not create more than %d menu's\n", i);
3102 for( i = 1; i < NR_MENUS; i++) {
3103 ret = AppendMenuA( hmenus[i], MF_POPUP, (UINT_PTR)hmenus[i-1],"test");
3104 if( !ret) break;
3106 trace("Maximum depth is %d\n", i);
3107 ok( GetLastError() == 12345678, "unexpected error %d\n", GetLastError());
3108 ok( i < NR_MENUS ||
3109 broken( i == NR_MENUS), /* win98, NT */
3110 "no ( or very large) limit on menu depth!\n");
3112 for( i = 0; i < NR_MENUS; i++)
3113 DestroyMenu( hmenus[i]);
3116 /* bug #12171 */
3117 static void test_menu_circref(void)
3119 HMENU menu1, menu2;
3120 DWORD ret;
3122 menu1 = CreatePopupMenu();
3123 menu2 = CreatePopupMenu();
3124 ok( menu1 && menu2, "error creating menus.\n");
3125 ret = AppendMenuA( menu1, MF_POPUP, (UINT_PTR)menu2, "winetest");
3126 ok( ret, "AppendMenu failed, error is %d\n", GetLastError());
3127 ret = AppendMenuA( menu1, MF_STRING | MF_HILITE, 123, "winetest");
3128 ok( ret, "AppendMenu failed, error is %d\n", GetLastError());
3129 /* app chooses an id that happens to clash with its own hmenu */
3130 ret = AppendMenuA( menu2, MF_STRING, (UINT_PTR)menu2, "winetest");
3131 ok( ret, "AppendMenu failed, error is %d\n", GetLastError());
3132 /* now attempt to change the string of the first item of menu1 */
3133 ret = ModifyMenuA( menu1, (UINT_PTR)menu2, MF_POPUP, (UINT_PTR)menu2, "menu 2");
3134 ok( !ret ||
3135 broken( ret), /* win98, NT */
3136 "ModifyMenu should have failed.\n");
3137 if( !ret) { /* will probably stack fault if the ModifyMenu succeeded */
3138 ret = GetMenuState( menu1, 123, 0);
3139 ok( ret == MF_HILITE, "GetMenuState returned %x\n",ret);
3141 DestroyMenu( menu2);
3142 DestroyMenu( menu1);
3145 /* test how the menu texts are aligned when the menu items have
3146 * different combinations of text and bitmaps (bug #13350) */
3147 static void test_menualign(void)
3149 BYTE bmfill[300];
3150 HMENU menu;
3151 HBITMAP hbm1, hbm2, hbm3;
3152 MENUITEMINFO mii = { sizeof(MENUITEMINFO)};
3153 DWORD ret;
3154 HWND hwnd;
3155 MENUINFO mi = { sizeof( MENUINFO)};
3157 if( !winetest_interactive) {
3158 skip( "interactive alignment tests.\n");
3159 return;
3161 hwnd = CreateWindowEx(0,
3162 "STATIC",
3163 "Menu text alignment Test\nPlease make a selection.",
3164 WS_OVERLAPPEDWINDOW,
3165 100, 100,
3166 300, 300,
3167 NULL, NULL, 0, NULL);
3168 ShowWindow( hwnd, SW_SHOW);
3169 /* create bitmaps */
3170 memset( bmfill, 0xcc, sizeof( bmfill));
3171 hbm1 = CreateBitmap( 10,10,1,1,bmfill);
3172 hbm2 = CreateBitmap( 20,20,1,1,bmfill);
3173 hbm3 = CreateBitmap( 50,6,1,1,bmfill);
3174 ok( hbm1 && hbm2 && hbm3, "Creating bitmaps failed\n");
3175 menu = CreatePopupMenu();
3176 ok( menu != NULL, "CreatePopupMenu() failed\n");
3177 if( pGetMenuInfo) {
3178 mi.fMask = MIM_STYLE;
3179 ret = pGetMenuInfo( menu, &mi);
3180 ok( menu != NULL, "GetMenuInfo() failed\n");
3181 ok( 0 == mi.dwStyle, "menuinfo style is %x\n", mi.dwStyle);
3183 /* test 1 */
3184 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3185 mii.wID = 1;
3186 mii.hbmpItem = hbm1;
3187 mii.dwTypeData = (LPSTR) " OK: menu texts are correctly left-aligned.";
3188 ret = InsertMenuItem( menu, -1, TRUE, &mii);
3189 ok( ret, "InsertMenuItem() failed\n");
3190 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID ;
3191 mii.wID = 2;
3192 mii.hbmpItem = hbm2;
3193 mii.dwTypeData = (LPSTR) " FAIL: menu texts are NOT left-aligned.";
3194 ret = InsertMenuItem( menu, -1, TRUE, &mii);
3195 ok( ret, "InsertMenuItem() failed\n");
3196 ret = TrackPopupMenu( menu, TPM_RETURNCMD, 110, 200, 0, hwnd, NULL);
3197 ok( ret != 2, "User indicated that menu text alignment test 1 failed %d\n", ret);
3198 /* test 2*/
3199 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3200 mii.wID = 3;
3201 mii.hbmpItem = hbm3;
3202 mii.dwTypeData = NULL;
3203 ret = InsertMenuItem( menu, 0, TRUE, &mii);
3204 ok( ret, "InsertMenuItem() failed\n");
3205 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3206 mii.wID = 1;
3207 mii.hbmpItem = hbm1;
3208 /* make the text a bit longer, to keep it readable */
3209 /* this bug is on winXP and reproduced on wine */
3210 mii.dwTypeData = (LPSTR) " OK: menu texts are to the right of the bitmaps........";
3211 ret = SetMenuItemInfo( menu, 1, TRUE, &mii);
3212 ok( ret, "SetMenuItemInfo() failed\n");
3213 mii.wID = 2;
3214 mii.hbmpItem = hbm2;
3215 mii.dwTypeData = (LPSTR) " FAIL: menu texts are below the first bitmap. ";
3216 ret = SetMenuItemInfo( menu, 2, TRUE, &mii);
3217 ok( ret, "SetMenuItemInfo() failed\n");
3218 ret = TrackPopupMenu( menu, TPM_RETURNCMD, 110, 200, 0, hwnd, NULL);
3219 ok( ret != 2, "User indicated that menu text alignment test 2 failed %d\n", ret);
3220 /* test 3 */
3221 mii.fMask = MIIM_TYPE | MIIM_ID;
3222 mii.wID = 3;
3223 mii.fType = MFT_BITMAP;
3224 mii.dwTypeData = (LPSTR) hbm3;
3225 ret = SetMenuItemInfo( menu, 0, TRUE, &mii);
3226 ok( ret, "SetMenuItemInfo() failed\n");
3227 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3228 mii.wID = 1;
3229 mii.hbmpItem = NULL;
3230 mii.dwTypeData = (LPSTR) " OK: menu texts are below the bitmap.";
3231 ret = SetMenuItemInfo( menu, 1, TRUE, &mii);
3232 ok( ret, "SetMenuItemInfo() failed\n");
3233 mii.wID = 2;
3234 mii.hbmpItem = NULL;
3235 mii.dwTypeData = (LPSTR) " FAIL: menu texts are NOT below the bitmap.";
3236 ret = SetMenuItemInfo( menu, 2, TRUE, &mii);
3237 ok( ret, "SetMenuItemInfo() failed\n");
3238 ret = TrackPopupMenu( menu, TPM_RETURNCMD, 110, 200, 0, hwnd, NULL);
3239 ok( ret != 2, "User indicated that menu text alignment test 3 failed %d\n", ret);
3240 /* cleanup */
3241 DeleteObject( hbm1);
3242 DeleteObject( hbm2);
3243 DeleteObject( hbm3);
3244 DestroyMenu( menu);
3245 DestroyWindow( hwnd);
3248 START_TEST(menu)
3250 init_function_pointers();
3252 /* Wine defines MENUITEMINFO for W2K and above. NT4 and below can't
3253 * handle that.
3255 if (correct_behavior())
3257 test_menu_add_string();
3258 test_menu_iteminfo();
3259 test_menu_search_bycommand();
3260 test_CheckMenuRadioItem();
3261 test_menu_resource_layout();
3262 test_InsertMenu();
3263 test_menualign();
3266 register_menu_check_class();
3268 test_menu_locked_by_window();
3269 test_subpopup_locked_by_menu();
3270 test_menu_ownerdraw();
3271 test_menu_bmp_and_string();
3272 test_menu_getmenuinfo();
3273 test_menu_setmenuinfo();
3274 test_menu_input();
3275 test_menu_flags();
3277 test_menu_hilitemenuitem();
3278 test_menu_trackpopupmenu();
3279 test_menu_trackagain();
3280 test_menu_cancelmode();
3281 test_menu_maxdepth();
3282 test_menu_circref();