Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / user32 / tests / menu.c
blob07cf4374e3f8eb34147f35bbfea10bc7bd152345
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 BOOL (WINAPI *pGetMenuBarInfo)(HWND,LONG,LONG,PMENUBARINFO);
42 static UINT (WINAPI *pSendInput)(UINT, INPUT*, size_t);
43 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
44 static BOOL (WINAPI *pEndMenu) (void);
46 static void init_function_pointers(void)
48 HMODULE hdll = GetModuleHandleA("user32");
50 #define GET_PROC(func) \
51 p ## func = (void*)GetProcAddress(hdll, #func); \
52 if(!p ## func) \
53 trace("GetProcAddress(%s) failed\n", #func);
55 GET_PROC(GetMenuInfo)
56 GET_PROC(GetMenuBarInfo)
57 GET_PROC(SendInput)
58 GET_PROC(SetMenuInfo)
59 GET_PROC(EndMenu)
61 #undef GET_PROC
64 static BOOL correct_behavior(void)
66 HMENU hmenu;
67 MENUITEMINFO info;
68 BOOL rc;
70 hmenu = CreateMenu();
72 memset(&info, 0, sizeof(MENUITEMINFO));
73 info.cbSize= sizeof(MENUITEMINFO);
74 SetLastError(0xdeadbeef);
75 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info);
76 /* Win9x : 0xdeadbeef
77 * NT4 : ERROR_INVALID_PARAMETER
78 * >= W2K : ERROR_MENU_ITEM_NOT_FOUND
80 if (!rc && GetLastError() != ERROR_MENU_ITEM_NOT_FOUND)
82 win_skip("NT4 and below can't handle a bigger MENUITEMINFO struct\n");
83 DestroyMenu(hmenu);
84 return FALSE;
87 DestroyMenu(hmenu);
88 return TRUE;
91 static LRESULT WINAPI menu_check_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
93 switch (msg)
95 case WM_ENTERMENULOOP:
96 /* mark window as having entered menu loop */
97 SetWindowLongPtr(hwnd, GWLP_USERDATA, TRUE);
98 /* exit menu modal loop
99 * ( A SendMessage does not work on NT3.51 here ) */
100 return PostMessage(hwnd, WM_CANCELMODE, 0, 0);
102 return DefWindowProc(hwnd, msg, wparam, lparam);
105 /* The MSVC headers ignore our NONAMELESSUNION requests so we have to define
106 * our own type */
107 typedef struct
109 DWORD type;
110 union
112 MOUSEINPUT mi;
113 KEYBDINPUT ki;
114 HARDWAREINPUT hi;
115 } u;
116 } TEST_INPUT;
118 /* globals to communicate between test and wndproc */
120 static BOOL bMenuVisible;
121 static INT popmenu;
122 static BOOL got_input;
123 static HMENU hMenus[4];
125 #define MOD_SIZE 10
126 #define MOD_NRMENUS 8
128 /* menu texts with their sizes */
129 static struct {
130 LPCSTR text;
131 SIZE size; /* size of text up to any \t */
132 SIZE sc_size; /* size of the short-cut */
133 } MOD_txtsizes[] = {
134 { "Pinot &Noir" },
135 { "&Merlot\bF4" },
136 { "Shira&z\tAlt+S" },
137 { "" },
138 { NULL }
141 static unsigned int MOD_maxid;
142 static RECT MOD_rc[MOD_NRMENUS];
143 static int MOD_avec, MOD_hic;
144 static int MOD_odheight;
145 static SIZE MODsizes[MOD_NRMENUS]= { {MOD_SIZE, MOD_SIZE},{MOD_SIZE, MOD_SIZE},
146 {MOD_SIZE, MOD_SIZE},{MOD_SIZE, MOD_SIZE}};
147 static int MOD_GotDrawItemMsg = FALSE;
148 static int gflag_initmenupopup,
149 gflag_entermenuloop,
150 gflag_initmenu;
152 /* wndproc used by test_menu_ownerdraw() */
153 static LRESULT WINAPI menu_ownerdraw_wnd_proc(HWND hwnd, UINT msg,
154 WPARAM wparam, LPARAM lparam)
156 static HMENU hmenupopup;
157 switch (msg)
159 case WM_INITMENUPOPUP:
160 gflag_initmenupopup++;
161 hmenupopup = (HMENU) wparam;
162 break;
163 case WM_ENTERMENULOOP:
164 gflag_entermenuloop++;
165 break;
166 case WM_INITMENU:
167 gflag_initmenu++;
168 break;
169 case WM_MEASUREITEM:
171 MEASUREITEMSTRUCT* pmis = (MEASUREITEMSTRUCT*)lparam;
172 if( winetest_debug)
173 trace("WM_MEASUREITEM received data %lx size %dx%d\n",
174 pmis->itemData, pmis->itemWidth, pmis->itemHeight);
175 ok( !wparam, "wrong wparam %lx\n", wparam );
176 ok( pmis->CtlType == ODT_MENU, "wrong type %x\n", pmis->CtlType );
177 MOD_odheight = pmis->itemHeight;
178 pmis->itemWidth = MODsizes[pmis->itemData].cx;
179 pmis->itemHeight = MODsizes[pmis->itemData].cy;
180 return TRUE;
182 case WM_DRAWITEM:
184 DRAWITEMSTRUCT * pdis;
185 TEXTMETRIC tm;
186 HPEN oldpen;
187 char chrs[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
188 SIZE sz;
189 int i;
190 pdis = (DRAWITEMSTRUCT *) lparam;
191 if( winetest_debug) {
192 RECT rc;
193 GetMenuItemRect( hwnd, (HMENU)pdis->hwndItem, pdis->itemData ,&rc);
194 trace("WM_DRAWITEM received hwnd %p hmenu %p itemdata %ld item %d rc %d,%d-%d,%d itemrc: %d,%d-%d,%d\n",
195 hwnd, pdis->hwndItem, pdis->itemData, pdis->itemID,
196 pdis->rcItem.left, pdis->rcItem.top,
197 pdis->rcItem.right,pdis->rcItem.bottom,
198 rc.left,rc.top,rc.right,rc.bottom);
199 oldpen=SelectObject( pdis->hDC, GetStockObject(
200 pdis->itemState & ODS_SELECTED ? WHITE_PEN :BLACK_PEN));
201 Rectangle( pdis->hDC, pdis->rcItem.left,pdis->rcItem.top,
202 pdis->rcItem.right,pdis->rcItem.bottom );
203 SelectObject( pdis->hDC, oldpen);
205 ok( !wparam, "wrong wparam %lx\n", wparam );
206 ok( pdis->CtlType == ODT_MENU, "wrong type %x\n", pdis->CtlType );
207 /* calculate widths of some menu texts */
208 if( ! MOD_txtsizes[0].size.cx)
209 for(i = 0; MOD_txtsizes[i].text; i++) {
210 char buf[100], *p;
211 RECT rc={0,0,0,0};
212 strcpy( buf, MOD_txtsizes[i].text);
213 if( ( p = strchr( buf, '\t'))) {
214 *p = '\0';
215 DrawText( pdis->hDC, p + 1, -1, &rc,
216 DT_SINGLELINE|DT_CALCRECT);
217 MOD_txtsizes[i].sc_size.cx= rc.right - rc.left;
218 MOD_txtsizes[i].sc_size.cy= rc.bottom - rc.top;
220 DrawText( pdis->hDC, buf, -1, &rc,
221 DT_SINGLELINE|DT_CALCRECT);
222 MOD_txtsizes[i].size.cx= rc.right - rc.left;
223 MOD_txtsizes[i].size.cy= rc.bottom - rc.top;
226 if( pdis->itemData > MOD_maxid) return TRUE;
227 /* store the rectangle */
228 MOD_rc[pdis->itemData] = pdis->rcItem;
229 /* calculate average character width */
230 GetTextExtentPoint( pdis->hDC, chrs, 52, &sz );
231 MOD_avec = (sz.cx + 26)/52;
232 GetTextMetrics( pdis->hDC, &tm);
233 MOD_hic = tm.tmHeight;
234 MOD_GotDrawItemMsg = TRUE;
235 return TRUE;
237 case WM_ENTERIDLE:
239 ok( lparam || broken(!lparam), /* win9x, nt4 */
240 "Menu window handle is NULL!\n");
241 if( lparam) {
242 HMENU hmenu = (HMENU)SendMessageA( (HWND)lparam, MN_GETHMENU, 0, 0);
243 ok( hmenupopup == hmenu, "MN_GETHMENU returns %p expected %p\n",
244 hmenu, hmenupopup);
246 PostMessage(hwnd, WM_CANCELMODE, 0, 0);
247 return TRUE;
251 return DefWindowProc(hwnd, msg, wparam, lparam);
254 static void register_menu_check_class(void)
256 WNDCLASS wc =
259 menu_check_wnd_proc,
262 GetModuleHandle(NULL),
263 NULL,
264 LoadCursor(NULL, IDC_ARROW),
265 (HBRUSH)(COLOR_BTNFACE+1),
266 NULL,
267 TEXT("WineMenuCheck"),
270 atomMenuCheckClass = RegisterClass(&wc);
273 static void test_getmenubarinfo(void)
275 BOOL ret;
276 HMENU hmenu;
277 MENUBARINFO mbi;
278 RECT rcw, rci;
279 HWND hwnd;
280 INT err;
282 if (!pGetMenuBarInfo) {
283 win_skip("GetMenuBarInfo is not available\n");
284 return;
287 mbi.cbSize = sizeof(MENUBARINFO);
289 hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
290 WS_SYSMENU | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
291 NULL, NULL, NULL, NULL);
292 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
294 /* no menu: getmenubarinfo should fail */
295 SetLastError(0xdeadbeef);
296 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
297 err = GetLastError();
298 ok(ret == FALSE, "GetMenuBarInfo should not have been successful\n");
299 ok(err == 0xdeadbeef, "err = %d\n", err);
301 /* create menubar, no items yet */
302 hmenu = CreateMenu();
303 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
305 ret = SetMenu(hwnd, hmenu);
306 ok(ret, "SetMenu failed with error %d\n", GetLastError());
308 SetLastError(0xdeadbeef);
309 ret = pGetMenuBarInfo(NULL, OBJID_CLIENT, 0, &mbi);
310 err = GetLastError();
311 ok(!ret, "GetMenuBarInfo succeeded\n");
312 ok(err == ERROR_INVALID_WINDOW_HANDLE, "err = %d\n", err);
314 SetLastError(0xdeadbeef);
315 ret = pGetMenuBarInfo(hwnd, OBJID_CLIENT, 0, &mbi);
316 err = GetLastError();
317 ok(!ret, "GetMenuBarInfo succeeded\n");
318 ok(err==ERROR_INVALID_MENU_HANDLE || broken(err==0xdeadbeef) /* NT, W2K, XP */, "err = %d\n", err);
320 SetLastError(0xdeadbeef);
321 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, -1, &mbi);
322 err = GetLastError();
323 ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
324 ok(err == 0xdeadbeef, "err = %d\n", err);
326 mbi.cbSize = 1000;
327 SetLastError(0xdeadbeef);
328 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
329 err = GetLastError();
330 ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
331 ok(err == ERROR_INVALID_PARAMETER, "err = %d\n", err);
332 mbi.cbSize = sizeof(MENUBARINFO);
334 SetLastError(0xdeadbeef);
335 ret = pGetMenuBarInfo(hwnd, 123, 0, &mbi);
336 err = GetLastError();
337 ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
338 ok(err == 0xdeadbeef, "err = %d\n", err);
340 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
341 ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
343 ok(mbi.rcBar.left == 0 && mbi.rcBar.top == 0 &&
344 mbi.rcBar.bottom == 0 && mbi.rcBar.right == 0,
345 "rcBar: Expected 0,0-0,0, got: %d,%d-%d,%d\n",
346 mbi.rcBar.left, mbi.rcBar.top, mbi.rcBar.right, mbi.rcBar.bottom);
347 ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n",
348 mbi.hMenu, hmenu);
349 ok(mbi.fBarFocused == 0, "fBarFocused: Got %d instead of 0.\n", mbi.fBarFocused);
350 ok(mbi.fFocused == 0, "fFocused: Got %d instead of 0.\n", mbi.fFocused);
352 /* add some items */
353 ret = AppendMenu(hmenu, MF_STRING , 100, "item 1");
354 ok(ret, "AppendMenu failed.\n");
355 ret = AppendMenu(hmenu, MF_STRING , 101, "item 2");
356 ok(ret, "AppendMenu failed.\n");
357 ret = SetMenu(hwnd, hmenu);
358 ok(ret, "SetMenu failed with error %d\n", GetLastError());
360 SetLastError(0xdeadbeef);
361 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 200, &mbi);
362 err = GetLastError();
363 ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
364 ok(err == 0xdeadbeef, "err = %d\n", err);
366 /* get info for the whole menu */
367 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
368 ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
370 /* calculate menu rectangle, from window rectangle and the position of the first item */
371 ret = GetWindowRect(hwnd, &rcw);
372 ok(ret, "GetWindowRect failed.\n");
373 ret = GetMenuItemRect(hwnd, hmenu, 0, &rci);
374 ok(ret, "GetMenuItemRect failed.\n");
375 todo_wine ok(mbi.rcBar.left == rci.left && mbi.rcBar.top == rci.top &&
376 mbi.rcBar.bottom == rci.bottom && mbi.rcBar.right == rcw.right - rci.left + rcw.left,
377 "rcBar: Got %d,%d-%d,%d instead of %d,%d-%d,%d\n",
378 mbi.rcBar.left, mbi.rcBar.top, mbi.rcBar.right, mbi.rcBar.bottom,
379 rci.left, rci.top, rcw.right - rci.left + rcw.left, rci.bottom);
380 ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n", mbi.hMenu, hmenu);
381 ok(mbi.fBarFocused == 0, "fBarFocused: got %d instead of 0\n", mbi.fBarFocused);
382 ok(mbi.fFocused == 0, "fFocused: got %d instead of 0\n", mbi.fFocused);
384 /* get info for item nr.2 */
385 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 2, &mbi);
386 ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
387 ret = GetMenuItemRect(hwnd, hmenu, 1, &rci);
388 ok(ret, "GetMenuItemRect failed.\n");
389 ok(mbi.rcBar.left == rci.left && mbi.rcBar.top == rci.top &&
390 mbi.rcBar.bottom == rci.bottom && mbi.rcBar.right == rci.right,
391 "rcBar: Got %d,%d-%d,%d instead of %d,%d-%d,%d\n",
392 mbi.rcBar.left, mbi.rcBar.top, mbi.rcBar.right, mbi.rcBar.bottom,
393 rci.left, rci.top, rci.right, rci.bottom);
394 ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n", mbi.hMenu, hmenu);
395 ok(mbi.fBarFocused == 0, "fBarFocused: got %d instead of 0\n", mbi.fBarFocused);
396 ok(mbi.fFocused == 0, "fFocused: got %d instead of 0\n", mbi.fFocused);
398 DestroyWindow(hwnd);
401 /* demonstrates that windows locks the menu object so that it is still valid
402 * even after a client calls DestroyMenu on it */
403 static void test_menu_locked_by_window(void)
405 BOOL ret;
406 HMENU hmenu;
407 HWND hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
408 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
409 NULL, NULL, NULL, NULL);
410 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
411 hmenu = CreateMenu();
412 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
413 ret = InsertMenu(hmenu, 0, MF_STRING, 0, TEXT("&Test"));
414 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
415 ret = SetMenu(hwnd, hmenu);
416 ok(ret, "SetMenu failed with error %d\n", GetLastError());
417 ret = DestroyMenu(hmenu);
418 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
420 ret = DrawMenuBar(hwnd);
421 todo_wine {
422 ok(ret, "DrawMenuBar failed with error %d\n", GetLastError());
424 ret = IsMenu(GetMenu(hwnd));
425 ok(!ret || broken(ret) /* nt4 */, "Menu handle should have been destroyed\n");
427 SendMessage(hwnd, WM_SYSCOMMAND, SC_KEYMENU, 0);
428 /* did we process the WM_INITMENU message? */
429 ret = GetWindowLongPtr(hwnd, GWLP_USERDATA);
430 todo_wine {
431 ok(ret, "WM_INITMENU should have been sent\n");
434 DestroyWindow(hwnd);
437 /* demonstrates that subpopup's are locked
438 * even after a client calls DestroyMenu on it */
439 static LRESULT WINAPI subpopuplocked_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
441 HWND hwndmenu;
442 switch (msg)
444 case WM_ENTERIDLE:
445 hwndmenu = GetCapture();
446 if( hwndmenu) {
447 PostMessage( hwndmenu, WM_KEYDOWN, VK_DOWN, 0);
448 PostMessage( hwndmenu, WM_KEYDOWN, VK_RIGHT, 0);
449 PostMessage( hwndmenu, WM_KEYDOWN, VK_RETURN, 0);
452 return DefWindowProc(hwnd, msg, wparam, lparam);
455 static void test_subpopup_locked_by_menu(void)
457 DWORD gle;
458 BOOL ret;
459 HMENU hmenu, hsubmenu;
460 MENUINFO mi = { sizeof( MENUINFO)};
461 MENUITEMINFO mii = { sizeof( MENUITEMINFO)};
462 HWND hwnd;
463 const int itemid = 0x1234567;
464 if( !pGetMenuInfo)
466 win_skip("GetMenuInfo is not available\n");
467 return;
469 /* create window, popupmenu with one subpopup */
470 hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
471 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
472 NULL, NULL, NULL, NULL);
473 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
474 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR) subpopuplocked_wnd_proc);
475 hmenu = CreatePopupMenu();
476 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
477 hsubmenu = CreatePopupMenu();
478 ok(hsubmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
479 ret = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hsubmenu,
480 TEXT("PopUpLockTest"));
481 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
482 ret = InsertMenu(hsubmenu, 0, MF_BYPOSITION | MF_STRING, itemid, TEXT("PopUpMenu"));
483 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
484 /* first some tests that all this functions properly */
485 mii.fMask = MIIM_SUBMENU;
486 ret = GetMenuItemInfo( hmenu, 0, TRUE, &mii);
487 ok( ret, "GetMenuItemInfo failed error %d\n", GetLastError());
488 ok( mii.hSubMenu == hsubmenu, "submenu is %p\n", mii.hSubMenu);
489 mi.fMask |= MIM_STYLE;
490 ret = pGetMenuInfo( hsubmenu, &mi);
491 ok( ret , "GetMenuInfo returned 0 with error %d\n", GetLastError());
492 ret = IsMenu( hsubmenu);
493 ok( ret , "Menu handle is not valid\n");
494 SetLastError( 0xdeadbeef);
495 ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
496 if( ret == (itemid & 0xffff)) {
497 win_skip("not on 16 bit menu subsystem\n");
498 DestroyMenu( hsubmenu);
499 } else {
500 gle = GetLastError();
501 ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, gle);
502 ok( gle == 0 ||
503 broken( gle == 0xdeadbeef), /* win2k0 */
504 "Last error is %d\n", gle);
505 /* then destroy the sub-popup */
506 ret = DestroyMenu( hsubmenu);
507 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
508 /* and repeat the tests */
509 mii.fMask = MIIM_SUBMENU;
510 ret = GetMenuItemInfo( hmenu, 0, TRUE, &mii);
511 ok( ret, "GetMenuItemInfo failed error %d\n", GetLastError());
512 /* GetMenuInfo fails now */
513 ok( mii.hSubMenu == hsubmenu, "submenu is %p\n", mii.hSubMenu);
514 mi.fMask |= MIM_STYLE;
515 ret = pGetMenuInfo( hsubmenu, &mi);
516 ok( !ret , "GetMenuInfo should have failed\n");
517 /* IsMenu says it is not */
518 ret = IsMenu( hsubmenu);
519 ok( !ret , "Menu handle should be invalid\n");
520 /* but TrackPopupMenu still works! */
521 SetLastError( 0xdeadbeef);
522 ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
523 gle = GetLastError();
524 todo_wine {
525 ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, gle);
527 ok( gle == 0 ||
528 broken(gle == 0xdeadbeef) || /* wow64 */
529 broken(gle == ERROR_INVALID_PARAMETER), /* win2k0 */
530 "Last error is %d\n", gle);
532 /* clean up */
533 DestroyMenu( hmenu);
534 DestroyWindow(hwnd);
537 static void test_menu_ownerdraw(void)
539 int i,j,k;
540 BOOL ret;
541 HMENU hmenu;
542 MENUITEMINFO mii;
543 LONG leftcol;
544 HWND hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
545 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
546 NULL, NULL, NULL, NULL);
547 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
548 if( !hwnd) return;
549 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
550 hmenu = CreatePopupMenu();
551 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
552 if( !hmenu) { DestroyWindow(hwnd);return;}
553 k=0;
554 for( j=0;j<2;j++) /* create columns */
555 for(i=0;i<2;i++) { /* create rows */
556 ret = AppendMenu( hmenu, MF_OWNERDRAW |
557 (i==0 ? MF_MENUBREAK : 0), k, MAKEINTRESOURCE(k));
558 k++;
559 ok( ret, "AppendMenu failed for %d\n", k-1);
561 MOD_maxid = k-1;
562 assert( k <= sizeof(MOD_rc)/sizeof(RECT));
563 /* display the menu */
564 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
566 /* columns have a 4 pixel gap between them */
567 ok( MOD_rc[0].right + 4 == MOD_rc[2].left,
568 "item rectangles are not separated by 4 pixels space\n");
569 /* height should be what the MEASUREITEM message has returned */
570 ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
571 "menu item has wrong height: %d should be %d\n",
572 MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
573 /* no gaps between the rows */
574 ok( MOD_rc[0].bottom - MOD_rc[1].top == 0,
575 "There should not be a space between the rows, gap is %d\n",
576 MOD_rc[0].bottom - MOD_rc[1].top);
577 /* test the correct value of the item height that was sent
578 * by the WM_MEASUREITEM message */
579 ok( MOD_odheight == HIWORD( GetDialogBaseUnits()) || /* WinNT,2k,XP */
580 MOD_odheight == MOD_hic, /* Win95,98,ME */
581 "Wrong height field in MEASUREITEMSTRUCT, expected %d or %d actual %d\n",
582 HIWORD( GetDialogBaseUnits()), MOD_hic, MOD_odheight);
583 /* test what MF_MENUBREAK did at the first position. Also show
584 * that an MF_SEPARATOR is ignored in the height calculation. */
585 leftcol= MOD_rc[0].left;
586 ModifyMenu( hmenu, 0, MF_BYCOMMAND| MF_OWNERDRAW| MF_SEPARATOR, 0, 0);
587 /* display the menu */
588 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
589 /* left should be 4 pixels less now */
590 ok( leftcol == MOD_rc[0].left + 4,
591 "columns should be 4 pixels to the left (actual %d).\n",
592 leftcol - MOD_rc[0].left);
593 /* test width */
594 ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
595 "width of owner drawn menu item is wrong. Got %d expected %d\n",
596 MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
597 /* and height */
598 ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
599 "Height is incorrect. Got %d expected %d\n",
600 MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
602 /* test owner-drawn callback bitmap */
603 ModifyMenu( hmenu, 1, MF_BYPOSITION | MFT_BITMAP, 1, (LPCSTR)HBMMENU_CALLBACK );
604 mii.cbSize = sizeof(mii);
605 mii.fMask = MIIM_BITMAP | MIIM_FTYPE | MIIM_ID;
606 if (GetMenuItemInfoA( hmenu, 1, TRUE, &mii ))
608 ok( mii.fType == MFT_BITMAP, "wrong type %x\n", mii.fType );
609 ok( mii.wID == 1, "wrong id %x\n", mii.wID );
610 ok( mii.hbmpItem == HBMMENU_CALLBACK, "wrong data %p\n", mii.hbmpItem );
612 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
614 /* test width/height of an ownerdraw menu bar as well */
615 ret = DestroyMenu(hmenu);
616 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
617 hmenu = CreateMenu();
618 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
619 if( !hmenu) { DestroyWindow(hwnd);return;}
620 MOD_maxid=1;
621 for(i=0;i<2;i++) {
622 ret = AppendMenu( hmenu, MF_OWNERDRAW , i, 0);
623 ok( ret, "AppendMenu failed for %d\n", i);
625 ret = SetMenu( hwnd, hmenu);
626 UpdateWindow( hwnd); /* hack for wine to draw the window + menu */
627 ok(ret, "SetMenu failed with error %d\n", GetLastError());
628 /* test width */
629 ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
630 "width of owner drawn menu item is wrong. Got %d expected %d\n",
631 MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
632 /* test hight */
633 ok( MOD_rc[0].bottom - MOD_rc[0].top == GetSystemMetrics( SM_CYMENU) - 1,
634 "Height of owner drawn menu item is wrong. Got %d expected %d\n",
635 MOD_rc[0].bottom - MOD_rc[0].top, GetSystemMetrics( SM_CYMENU) - 1);
637 /* clean up */
638 ret = DestroyMenu(hmenu);
639 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
640 DestroyWindow(hwnd);
643 /* helper for test_menu_bmp_and_string() */
644 static void test_mbs_help( int ispop, int hassub, int mnuopt,
645 HWND hwnd, int arrowwidth, int count, HBITMAP hbmp,
646 SIZE bmpsize, LPCSTR text, SIZE size, SIZE sc_size)
648 BOOL ret;
649 HMENU hmenu, submenu;
650 MENUITEMINFO mii={ sizeof( MENUITEMINFO )};
651 MENUINFO mi;
652 RECT rc;
653 CHAR text_copy[16];
654 int hastab, expect;
655 int failed = 0;
657 MOD_GotDrawItemMsg = FALSE;
658 mii.fMask = MIIM_FTYPE | MIIM_DATA | MIIM_STATE;
659 mii.fType = 0;
660 /* check the menu item unless MNS_CHECKORBMP is set */
661 mii.fState = (mnuopt != 2 ? MFS_CHECKED : MFS_UNCHECKED);
662 mii.dwItemData =0;
663 MODsizes[0] = bmpsize;
664 hastab = 0;
665 if( text ) {
666 char *p;
667 mii.fMask |= MIIM_STRING;
668 strcpy(text_copy, text);
669 mii.dwTypeData = text_copy; /* structure member declared non-const */
670 if( ( p = strchr( text, '\t'))) {
671 hastab = *(p + 1) ? 2 : 1;
674 /* tabs don't make sense in menubars */
675 if(hastab && !ispop) return;
676 if( hbmp) {
677 mii.fMask |= MIIM_BITMAP;
678 mii.hbmpItem = hbmp;
680 submenu = CreateMenu();
681 ok( submenu != 0, "CreateMenu failed with error %d\n", GetLastError());
682 if( ispop)
683 hmenu = CreatePopupMenu();
684 else
685 hmenu = CreateMenu();
686 ok( hmenu != 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
687 if( hassub) {
688 mii.fMask |= MIIM_SUBMENU;
689 mii.hSubMenu = submenu;
691 if( mnuopt) {
692 mi.cbSize = sizeof(mi);
693 mi.fMask = MIM_STYLE;
694 pGetMenuInfo( hmenu, &mi);
695 if( mnuopt) mi.dwStyle |= mnuopt == 1 ? MNS_NOCHECK : MNS_CHECKORBMP;
696 ret = pSetMenuInfo( hmenu, &mi);
697 ok( ret, "SetMenuInfo failed with error %d\n", GetLastError());
699 ret = InsertMenuItem( hmenu, 0, FALSE, &mii);
700 ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
701 failed = !ret;
702 if( winetest_debug) {
703 HDC hdc=GetDC(hwnd);
704 RECT rc = {100, 50, 400, 70};
705 char buf[100];
707 sprintf( buf,"%d text \"%s\" mnuopt %d", count, text ? text: "(nil)", mnuopt);
708 FillRect( hdc, &rc, (HBRUSH) COLOR_WINDOW);
709 TextOut( hdc, 10, 50, buf, strlen( buf));
710 ReleaseDC( hwnd, hdc);
712 if(ispop)
713 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
714 else {
715 ret = SetMenu( hwnd, hmenu);
716 ok(ret, "SetMenu failed with error %d\n", GetLastError());
717 DrawMenuBar( hwnd);
719 ret = GetMenuItemRect( hwnd, hmenu, 0, &rc);
720 ok(ret, "GetMenuItemRect failed with error %d\n", GetLastError());
722 if (0) /* comment out menu size checks, behavior is different in almost every Windows version */
723 /* the tests should however succeed on win2000, XP and Wine (at least up to 1.1.15) */
724 /* with a variety of dpis and desktop font sizes */
726 /* check menu width */
727 if( ispop)
728 expect = ( text || hbmp ?
729 4 + (mnuopt != 1 ? GetSystemMetrics(SM_CXMENUCHECK) : 0)
730 : 0) +
731 arrowwidth + MOD_avec + (hbmp ?
732 ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ? bmpsize.cx + 2 : GetSystemMetrics( SM_CXMENUSIZE) + 2)
733 : 0) +
734 (text && hastab ? /* TAB space */
735 MOD_avec + ( hastab==2 ? sc_size.cx : 0) : 0) +
736 (text ? 2 + (text[0] ? size.cx :0): 0) ;
737 else
738 expect = !(text || hbmp) ? 0 :
739 ( hbmp ? (text ? 2:0) + bmpsize.cx : 0 ) +
740 (text ? 2 * MOD_avec + (text[0] ? size.cx :0): 0) ;
741 ok( rc.right - rc.left == expect,
742 "menu width wrong, got %d expected %d\n", rc.right - rc.left, expect);
743 failed = failed || !(rc.right - rc.left == expect);
744 /* check menu height */
745 if( ispop)
746 expect = max( ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 : 0),
747 max( (text ? max( 2 + size.cy, MOD_hic + 4) : 0),
748 (hbmp ?
749 ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ?
750 bmpsize.cy + 2
751 : GetSystemMetrics( SM_CYMENUSIZE) + 2)
752 : 0)));
753 else
754 expect = ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 :
755 max( GetSystemMetrics( SM_CYMENU) - 1, (hbmp ? bmpsize.cy : 0)));
756 ok( rc.bottom - rc.top == expect,
757 "menu height wrong, got %d expected %d (%d)\n",
758 rc.bottom - rc.top, expect, GetSystemMetrics( SM_CYMENU));
759 failed = failed || !(rc.bottom - rc.top == expect);
760 if( hbmp == HBMMENU_CALLBACK && MOD_GotDrawItemMsg) {
761 /* check the position of the bitmap */
762 /* horizontal */
763 if (!ispop)
764 expect = 3;
765 else if (mnuopt == 0)
766 expect = 4 + GetSystemMetrics(SM_CXMENUCHECK);
767 else if (mnuopt == 1)
768 expect = 4;
769 else /* mnuopt == 2 */
770 expect = 2;
771 ok( expect == MOD_rc[0].left,
772 "bitmap left is %d expected %d\n", MOD_rc[0].left, expect);
773 failed = failed || !(expect == MOD_rc[0].left);
774 /* vertical */
775 expect = (rc.bottom - rc.top - MOD_rc[0].bottom + MOD_rc[0].top) / 2;
776 ok( expect == MOD_rc[0].top,
777 "bitmap top is %d expected %d\n", MOD_rc[0].top, expect);
778 failed = failed || !(expect == MOD_rc[0].top);
781 /* if there was a failure, report details */
782 if( failed) {
783 trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
784 count, (ispop? "POPUP": "MENUBAR"),text ? text: "(nil)", hbmp, bmpsize.cx, bmpsize.cy,
785 size.cx, size.cy, sc_size.cx, mnuopt, hastab);
786 trace(" check %d,%d arrow %d avechar %d\n",
787 GetSystemMetrics(SM_CXMENUCHECK ),
788 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
789 if( hbmp == HBMMENU_CALLBACK)
790 trace( " rc %d,%d-%d,%d bmp.rc %d,%d-%d,%d\n",
791 rc.left, rc.top, rc.top, rc.bottom, MOD_rc[0].left,
792 MOD_rc[0].top,MOD_rc[0].right, MOD_rc[0].bottom);
794 /* clean up */
795 ret = DestroyMenu(submenu);
796 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
797 ret = DestroyMenu(hmenu);
798 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
802 static void test_menu_bmp_and_string(void)
804 BYTE bmfill[300];
805 HBITMAP hbm_arrow;
806 BITMAP bm;
807 INT arrowwidth;
808 HWND hwnd;
809 HMENU hsysmenu;
810 MENUINFO mi= {sizeof(MENUINFO)};
811 MENUITEMINFOA mii= {sizeof(MENUITEMINFOA)};
812 int count, szidx, txtidx, bmpidx, hassub, mnuopt, ispop;
813 BOOL got;
815 if( !pGetMenuInfo)
817 win_skip("GetMenuInfo is not available\n");
818 return;
821 memset( bmfill, 0xcc, sizeof( bmfill));
822 hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL, WS_SYSMENU |
823 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
824 NULL, NULL, NULL, NULL);
825 hbm_arrow=LoadBitmap( 0, (CHAR*)OBM_MNARROW);
826 GetObject( hbm_arrow, sizeof(bm), &bm);
827 arrowwidth = bm.bmWidth;
828 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
829 if( !hwnd) return;
830 /* test system menu */
831 hsysmenu = GetSystemMenu( hwnd, FALSE);
832 ok( hsysmenu != NULL, "GetSystemMenu failed with error %d\n", GetLastError());
833 mi.fMask = MIM_STYLE;
834 mi.dwStyle = 0;
835 got = pGetMenuInfo( hsysmenu, &mi);
836 ok( got, "GetMenuInfo failed gle=%d\n", GetLastError());
837 ok( MNS_CHECKORBMP == mi.dwStyle, "System Menu Style is %08x, without the bit %08x\n",
838 mi.dwStyle, MNS_CHECKORBMP);
839 mii.fMask = MIIM_BITMAP;
840 mii.hbmpItem = NULL;
841 got = GetMenuItemInfoA( hsysmenu, SC_CLOSE, FALSE, &mii);
842 ok( got, "GetMenuItemInfoA failed gle=%d\n", GetLastError());
843 ok( HBMMENU_POPUP_CLOSE == mii.hbmpItem, "Item info did not get the right hbitmap: got %p expected %p\n",
844 mii.hbmpItem, HBMMENU_POPUP_CLOSE);
846 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
848 if( winetest_debug)
849 trace(" check %d,%d arrow %d avechar %d\n",
850 GetSystemMetrics(SM_CXMENUCHECK ),
851 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
852 count = 0;
853 MOD_maxid = 0;
854 for( ispop=1; ispop >= 0; ispop--){
855 static SIZE bmsizes[]= {
856 {10,10},{38,38},{1,30},{55,5}};
857 for( szidx=0; szidx < sizeof( bmsizes) / sizeof( SIZE); szidx++) {
858 HBITMAP hbm = CreateBitmap( bmsizes[szidx].cx, bmsizes[szidx].cy,1,1,bmfill);
859 HBITMAP bitmaps[] = { HBMMENU_CALLBACK, hbm, HBMMENU_POPUP_CLOSE, NULL };
860 ok( hbm != 0, "CreateBitmap failed err %d\n", GetLastError());
861 for( txtidx = 0; txtidx < sizeof(MOD_txtsizes)/sizeof(MOD_txtsizes[0]); txtidx++) {
862 for( hassub = 0; hassub < 2 ; hassub++) { /* add submenu item */
863 for( mnuopt = 0; mnuopt < 3 ; mnuopt++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
864 for( bmpidx = 0; bmpidx <sizeof(bitmaps)/sizeof(HBITMAP); bmpidx++) {
865 /* no need to test NULL bitmaps of several sizes */
866 if( !bitmaps[bmpidx] && szidx > 0) continue;
867 /* the HBMMENU_POPUP not to test for menu bars */
868 if( !ispop &&
869 bitmaps[bmpidx] >= HBMMENU_POPUP_CLOSE &&
870 bitmaps[bmpidx] <= HBMMENU_POPUP_MINIMIZE) continue;
871 if( !ispop && hassub) continue;
872 test_mbs_help( ispop, hassub, mnuopt,
873 hwnd, arrowwidth, ++count,
874 bitmaps[bmpidx],
875 bmsizes[szidx],
876 MOD_txtsizes[txtidx].text,
877 MOD_txtsizes[txtidx].size,
878 MOD_txtsizes[txtidx].sc_size);
883 DeleteObject( hbm);
886 /* clean up */
887 DestroyWindow(hwnd);
890 static void test_menu_add_string( void )
892 HMENU hmenu;
893 MENUITEMINFO info;
894 BOOL rc;
895 int ret;
897 char string[0x80];
898 char string2[0x80];
900 char strback[0x80];
901 WCHAR strbackW[0x80];
902 static CHAR blah[] = "blah";
903 static const WCHAR expectedString[] = {'D','u','m','m','y',' ','s','t','r','i','n','g', 0};
905 hmenu = CreateMenu();
907 memset( &info, 0, sizeof info );
908 info.cbSize = sizeof info;
909 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_ID;
910 info.dwTypeData = blah;
911 info.cch = 6;
912 info.dwItemData = 0;
913 info.wID = 1;
914 info.fState = 0;
915 InsertMenuItem(hmenu, 0, TRUE, &info );
917 memset( &info, 0, sizeof info );
918 info.cbSize = sizeof info;
919 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_DATA | MIIM_ID;
920 info.dwTypeData = string;
921 info.cch = sizeof string;
922 string[0] = 0;
923 GetMenuItemInfo( hmenu, 0, TRUE, &info );
925 ok( !strcmp( string, "blah" ), "menu item name differed\n");
927 /* Test combination of ownerdraw and strings with GetMenuItemString(A/W) */
928 strcpy(string, "Dummy string");
929 memset(&info, 0x00, sizeof(info));
930 info.cbSize= sizeof(MENUITEMINFO);
931 info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
932 info.fType= MFT_OWNERDRAW;
933 info.dwTypeData= string;
934 rc = InsertMenuItem( hmenu, 0, TRUE, &info );
935 ok (rc, "InsertMenuItem failed\n");
937 strcpy(string,"Garbage");
938 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
939 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
941 SetLastError(0xdeadbeef);
942 ret = GetMenuStringW( hmenu, 0, strbackW, 99, MF_BYPOSITION );
943 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
944 win_skip("GetMenuStringW is not implemented\n");
945 else
947 ok (ret, "GetMenuStringW on ownerdraw entry failed\n");
948 ok (!lstrcmpW( strbackW, expectedString ), "Menu text from Unicode version incorrect\n");
951 /* Just change ftype to string and see what text is stored */
952 memset(&info, 0x00, sizeof(info));
953 info.cbSize= sizeof(MENUITEMINFO);
954 info.fMask= MIIM_FTYPE; /* Set string type */
955 info.fType= MFT_STRING;
956 info.dwTypeData= (char *)0xdeadbeef;
957 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
958 ok (rc, "SetMenuItemInfo failed\n");
960 /* Did we keep the old dwTypeData? */
961 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
962 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
964 /* Ensure change to bitmap type fails */
965 memset(&info, 0x00, sizeof(info));
966 info.cbSize= sizeof(MENUITEMINFO);
967 info.fMask= MIIM_FTYPE; /* Set as bitmap type */
968 info.fType= MFT_BITMAP;
969 info.dwTypeData= (char *)0xdeadbee2;
970 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
971 ok (!rc, "SetMenuItemInfo unexpectedly worked\n");
973 /* Just change ftype back and ensure data hasn't been freed */
974 info.fType= MFT_OWNERDRAW; /* Set as ownerdraw type */
975 info.dwTypeData= (char *)0xdeadbee3;
976 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
977 ok (rc, "SetMenuItemInfo failed\n");
979 /* Did we keep the old dwTypeData? */
980 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
981 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
983 /* Just change string value (not type) */
984 memset(&info, 0x00, sizeof(info));
985 info.cbSize= sizeof(MENUITEMINFO);
986 info.fMask= MIIM_STRING; /* Set typeData */
987 strcpy(string2, "string2");
988 info.dwTypeData= string2;
989 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
990 ok (rc, "SetMenuItemInfo failed\n");
992 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
993 ok (!strcmp( strback, "string2" ), "Menu text from Ansi version incorrect\n");
995 /* crashes with wine 0.9.5 */
996 memset(&info, 0x00, sizeof(info));
997 info.cbSize= sizeof(MENUITEMINFO);
998 info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
999 info.fType= MFT_OWNERDRAW;
1000 rc = InsertMenuItem( hmenu, 0, TRUE, &info );
1001 ok (rc, "InsertMenuItem failed\n");
1002 ok (!GetMenuString( hmenu, 0, NULL, 0, MF_BYPOSITION),
1003 "GetMenuString on ownerdraw entry succeeded.\n");
1004 SetLastError(0xdeadbeef);
1005 ret = GetMenuStringW( hmenu, 0, NULL, 0, MF_BYPOSITION);
1006 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1007 win_skip("GetMenuStringW is not implemented\n");
1008 else
1009 ok (!ret, "GetMenuStringW on ownerdraw entry succeeded.\n");
1011 DestroyMenu( hmenu );
1014 /* define building blocks for the menu item info tests */
1015 static int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
1017 if (n <= 0) return 0;
1018 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
1019 return *str1 - *str2;
1022 static WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
1024 WCHAR *p = dst;
1025 while ((*p++ = *src++));
1026 return dst;
1029 static void insert_menu_item( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state, UINT id,
1030 HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
1031 void *type_data, UINT len, HBITMAP item, BOOL expect )
1033 MENUITEMINFOA info;
1034 BOOL ret;
1036 /* magic bitmap handle to test smaller cbSize */
1037 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
1038 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
1039 else
1040 info.cbSize = sizeof(info);
1041 info.fMask = mask;
1042 info.fType = type;
1043 info.fState = state;
1044 info.wID = id;
1045 info.hSubMenu = submenu;
1046 info.hbmpChecked = checked;
1047 info.hbmpUnchecked = unchecked;
1048 info.dwItemData = data;
1049 info.dwTypeData = type_data;
1050 info.cch = len;
1051 info.hbmpItem = item;
1052 SetLastError( 0xdeadbeef );
1053 if (ansi) ret = InsertMenuItemA( hmenu, 0, TRUE, &info );
1054 else ret = InsertMenuItemW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
1055 if (!expect) ok_(__FILE__, line)( !ret, "InsertMenuItem should have failed.\n" );
1056 else ok_(__FILE__, line)( ret, "InsertMenuItem failed, err %u\n", GetLastError());
1059 static void check_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
1060 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked,
1061 ULONG_PTR data, void *type_data, UINT in_len, UINT out_len,
1062 HBITMAP item, LPCSTR expname, BOOL expect, BOOL expstring )
1064 MENUITEMINFOA info;
1065 BOOL ret;
1066 WCHAR buffer[80];
1068 SetLastError( 0xdeadbeef );
1069 memset( &info, 0xcc, sizeof(info) );
1070 info.cbSize = sizeof(info);
1071 info.fMask = mask;
1072 info.dwTypeData = type_data;
1073 info.cch = in_len;
1075 ret = ansi ? GetMenuItemInfoA( hmenu, 0, TRUE, &info ) :
1076 GetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW *)&info );
1077 if (!expect)
1079 ok_(__FILE__, line)( !ret, "GetMenuItemInfo should have failed.\n" );
1080 return;
1082 ok_(__FILE__, line)( ret, "GetMenuItemInfo failed, err %u\n", GetLastError());
1083 if (mask & MIIM_TYPE)
1084 ok_(__FILE__, line)( info.fType == type || info.fType == LOWORD(type),
1085 "wrong type %x/%x\n", info.fType, type );
1086 if (mask & MIIM_STATE)
1087 ok_(__FILE__, line)( info.fState == state || info.fState == LOWORD(state),
1088 "wrong state %x/%x\n", info.fState, state );
1089 if (mask & MIIM_ID)
1090 ok_(__FILE__, line)( info.wID == id || info.wID == LOWORD(id),
1091 "wrong id %x/%x\n", info.wID, id );
1092 if (mask & MIIM_SUBMENU)
1093 ok_(__FILE__, line)( info.hSubMenu == submenu || (ULONG_PTR)info.hSubMenu == LOWORD(submenu),
1094 "wrong submenu %p/%p\n", info.hSubMenu, submenu );
1095 if (mask & MIIM_CHECKMARKS)
1097 ok_(__FILE__, line)( info.hbmpChecked == checked || (ULONG_PTR)info.hbmpChecked == LOWORD(checked),
1098 "wrong bmpchecked %p/%p\n", info.hbmpChecked, checked );
1099 ok_(__FILE__, line)( info.hbmpUnchecked == unchecked || (ULONG_PTR)info.hbmpUnchecked == LOWORD(unchecked),
1100 "wrong bmpunchecked %p/%p\n", info.hbmpUnchecked, unchecked );
1102 if (mask & MIIM_DATA)
1103 ok_(__FILE__, line)( info.dwItemData == data || info.dwItemData == LOWORD(data),
1104 "wrong item data %lx/%lx\n", info.dwItemData, data );
1105 if (mask & MIIM_BITMAP)
1106 ok_(__FILE__, line)( info.hbmpItem == item || (ULONG_PTR)info.hbmpItem == LOWORD(item),
1107 "wrong bmpitem %p/%p\n", info.hbmpItem, item );
1108 ok_(__FILE__, line)( info.dwTypeData == type_data || (ULONG_PTR)info.dwTypeData == LOWORD(type_data),
1109 "wrong type data %p/%p\n", info.dwTypeData, type_data );
1110 ok_(__FILE__, line)( info.cch == out_len ||
1111 broken(! ansi && info.cch == 2 * out_len) /* East-Asian */,
1112 "wrong len %x/%x\n", info.cch, out_len );
1113 if (expname)
1115 if(ansi)
1116 ok_(__FILE__, line)( !strncmp( expname, info.dwTypeData, out_len ),
1117 "menu item name differed from '%s' '%s'\n", expname, info.dwTypeData );
1118 else
1119 ok_(__FILE__, line)( !strncmpW( (WCHAR *)expname, (WCHAR *)info.dwTypeData, out_len ),
1120 "menu item name wrong\n" );
1122 SetLastError( 0xdeadbeef );
1123 ret = ansi ? GetMenuStringA( hmenu, 0, (char *)buffer, 80, MF_BYPOSITION ) :
1124 GetMenuStringW( hmenu, 0, buffer, 80, MF_BYPOSITION );
1125 if (expstring)
1126 ok_(__FILE__, line)( ret, "GetMenuString failed, err %u\n", GetLastError());
1127 else
1128 ok_(__FILE__, line)( !ret, "GetMenuString should have failed\n" );
1132 static void modify_menu( int line, HMENU hmenu, BOOL ansi, UINT flags, UINT_PTR id, void *data )
1134 BOOL ret;
1136 SetLastError( 0xdeadbeef );
1137 if (ansi) ret = ModifyMenuA( hmenu, 0, flags, id, data );
1138 else ret = ModifyMenuW( hmenu, 0, flags, id, data );
1139 ok_(__FILE__,line)( ret, "ModifyMenuA failed, err %u\n", GetLastError());
1142 static void set_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
1143 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
1144 void *type_data, UINT len, HBITMAP item )
1147 MENUITEMINFOA info;
1148 BOOL ret;
1150 /* magic bitmap handle to test smaller cbSize */
1151 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
1152 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
1153 else
1154 info.cbSize = sizeof(info);
1155 info.fMask = mask;
1156 info.fType = type;
1157 info.fState = state;
1158 info.wID = id;
1159 info.hSubMenu = submenu;
1160 info.hbmpChecked = checked;
1161 info.hbmpUnchecked = unchecked;
1162 info.dwItemData = data;
1163 info.dwTypeData = type_data;
1164 info.cch = len;
1165 info.hbmpItem = item;
1166 SetLastError( 0xdeadbeef );
1167 if (ansi) ret = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1168 else ret = SetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
1169 ok_(__FILE__, line)( ret, "SetMenuItemInfo failed, err %u\n", GetLastError());
1172 #define TMII_INSMI( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,eret1 )\
1173 hmenu = CreateMenu();\
1174 submenu = CreateMenu();\
1175 if(ansi)strcpy( string, init );\
1176 else strcpyW( string, init );\
1177 insert_menu_item( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, eret1 )
1179 /* GetMenuItemInfo + GetMenuString */
1180 #define TMII_GMII( c2,l2,\
1181 d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,\
1182 expname, eret2, eret3)\
1183 check_menu_item_info( __LINE__, hmenu, ansi, c2, d3, e3, f3, g3, h3, i3, j3, k3, l2, l3, m3, \
1184 expname, eret2, eret3 )
1186 #define TMII_DONE \
1187 RemoveMenu(hmenu, 0, TRUE );\
1188 DestroyMenu( hmenu );\
1189 DestroyMenu( submenu );
1191 /* modify menu */
1192 #define TMII_MODM( flags, id, data ) \
1193 modify_menu( __LINE__, hmenu, ansi, flags, id, data )
1195 /* SetMenuItemInfo */
1196 #define TMII_SMII( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1 ) \
1197 set_menu_item_info( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1 )
1200 #define OK 1
1201 #define ER 0
1204 static void test_menu_iteminfo( void )
1206 int ansi = TRUE;
1207 char txtA[]="wine";
1208 char initA[]="XYZ";
1209 char emptyA[]="";
1210 WCHAR txtW[]={'W','i','n','e',0};
1211 WCHAR initW[]={'X','Y','Z',0};
1212 WCHAR emptyW[]={0};
1213 void *txt, *init, *empty, *string;
1214 HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
1215 char stringA[0x80];
1216 HMENU hmenu, submenu;
1217 HBITMAP dummy_hbm = (HBITMAP)(ULONG_PTR)0xdeadbeef;
1219 do {
1220 if( ansi) {txt=txtA;init=initA;empty=emptyA;string=stringA;}
1221 else {txt=txtW;init=initW;empty=emptyW;string=stringA;}
1222 trace( "%s string %p hbm %p txt %p\n", ansi ? "ANSI tests: " : "Unicode tests:", string, hbm, txt);
1223 /* test all combinations of MFT_STRING, MFT_OWNERDRAW and MFT_BITMAP */
1224 /* (since MFT_STRING is zero, there are four of them) */
1225 TMII_INSMI( MIIM_TYPE, MFT_STRING, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1226 TMII_GMII ( MIIM_TYPE, 80,
1227 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1228 txt, OK, OK );
1229 TMII_DONE
1230 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1231 TMII_GMII ( MIIM_TYPE, 80,
1232 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1233 NULL, OK, ER );
1234 TMII_DONE
1235 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1236 TMII_GMII ( MIIM_TYPE, 80,
1237 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1238 NULL, OK, ER );
1239 TMII_DONE
1240 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1241 TMII_GMII ( MIIM_TYPE, 80,
1242 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1243 NULL, OK, ER );
1244 TMII_DONE
1245 /* not enough space for name*/
1246 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1247 TMII_GMII ( MIIM_TYPE, 0,
1248 MFT_STRING, 0, 0, 0, 0, 0, 0, NULL, 4, 0,
1249 NULL, OK, OK );
1250 TMII_DONE
1251 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1252 TMII_GMII ( MIIM_TYPE, 5,
1253 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1254 txt, OK, OK );
1255 TMII_DONE
1256 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1257 TMII_GMII ( MIIM_TYPE, 4,
1258 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 3, 0,
1259 txt, OK, OK );
1260 TMII_DONE
1261 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1262 TMII_GMII ( MIIM_TYPE, 0,
1263 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, 0,
1264 NULL, OK, ER );
1265 TMII_DONE
1266 /* cannot combine MIIM_TYPE with some other flags */
1267 TMII_INSMI( MIIM_TYPE|MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1268 TMII_DONE
1269 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1270 TMII_GMII ( MIIM_TYPE|MIIM_STRING, 80,
1271 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1272 NULL, ER, OK );
1273 TMII_DONE
1274 TMII_INSMI( MIIM_TYPE|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1275 TMII_DONE
1276 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1277 TMII_GMII ( MIIM_TYPE|MIIM_FTYPE, 80,
1278 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1279 NULL, ER, OK );
1280 TMII_DONE
1281 TMII_INSMI( MIIM_TYPE|MIIM_BITMAP, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, hbm, ER );
1282 TMII_DONE
1283 /* but succeeds with some others */
1284 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1285 TMII_GMII ( MIIM_TYPE|MIIM_SUBMENU, 80,
1286 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1287 txt, OK, OK );
1288 TMII_DONE
1289 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1290 TMII_GMII ( MIIM_TYPE|MIIM_STATE, 80,
1291 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1292 txt, OK, OK );
1293 TMII_DONE
1294 TMII_INSMI( MIIM_TYPE|MIIM_ID, MFT_STRING, -1, 888, 0, 0, 0, -1, txt, 6, 0, OK );
1295 TMII_GMII ( MIIM_TYPE|MIIM_ID, 80,
1296 MFT_STRING, 0, 888, 0, 0, 0, 0, string, 4, 0,
1297 txt, OK, OK );
1298 TMII_DONE
1299 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING, -1, -1, 0, 0, 0, 999, txt, 6, 0, OK );
1300 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1301 MFT_STRING, 0, 0, 0, 0, 0, 999, string, 4, 0,
1302 txt, OK, OK );
1303 TMII_DONE
1304 /* to be continued */
1305 /* set text with MIIM_TYPE and retrieve with MIIM_STRING */
1306 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1307 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1308 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1309 txt, OK, OK );
1310 TMII_DONE
1311 /* set text with MIIM_TYPE and retrieve with MIIM_STRING; MFT_OWNERDRAW causes an empty string */
1312 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1313 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1314 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1315 empty, OK, ER );
1316 TMII_DONE
1317 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1318 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1319 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1320 empty, OK, ER );
1321 TMII_DONE
1322 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1323 TMII_GMII ( MIIM_FTYPE, 80,
1324 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, 0,
1325 init, OK, ER );
1326 TMII_DONE
1327 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1328 TMII_GMII ( 0, 80,
1329 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1330 init, OK, OK );
1331 TMII_DONE
1332 /* contrary to MIIM_TYPE,you can set the text for an owner draw menu */
1333 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1334 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1335 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1336 txt, OK, OK );
1337 TMII_DONE
1338 /* same but retrieve with MIIM_TYPE */
1339 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1340 TMII_GMII ( MIIM_TYPE, 80,
1341 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1342 NULL, OK, OK );
1343 TMII_DONE
1344 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1345 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1346 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1347 empty, OK, ER );
1348 TMII_DONE
1349 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1350 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1351 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1352 empty, OK, ER );
1353 TMII_DONE
1355 /* How is that with bitmaps? */
1356 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1357 TMII_GMII ( MIIM_TYPE, 80,
1358 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1359 NULL, OK, ER );
1360 TMII_DONE
1361 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1362 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1363 0, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1364 init, OK, ER );
1365 TMII_DONE
1366 /* MIIM_BITMAP does not like MFT_BITMAP */
1367 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, hbm, ER );
1368 TMII_DONE
1369 /* no problem with OWNERDRAWN */
1370 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1371 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1372 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1373 init, OK, ER );
1374 TMII_DONE
1375 /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1376 TMII_INSMI( MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER );
1377 TMII_DONE
1379 /* menu with submenu */
1380 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1381 TMII_GMII ( MIIM_SUBMENU, 80,
1382 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1383 init, OK, ER );
1384 TMII_DONE
1385 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, empty, 0, 0, OK );
1386 TMII_GMII ( MIIM_SUBMENU, 80,
1387 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1388 init, OK, ER );
1389 TMII_DONE
1390 /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1391 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1392 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1393 MFT_STRING|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1394 empty, OK, ER );
1395 TMII_GMII ( MIIM_SUBMENU|MIIM_FTYPE, 80,
1396 MFT_SEPARATOR, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1397 empty, OK, ER );
1398 TMII_DONE
1399 /* menu with invalid submenu */
1400 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, (HMENU)999, 0, 0, -1, txt, 0, 0, ER );
1401 TMII_DONE
1402 /* Separator */
1403 TMII_INSMI( MIIM_TYPE, MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1404 TMII_GMII ( MIIM_TYPE, 80,
1405 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1406 NULL, OK, ER );
1407 TMII_DONE
1408 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1409 TMII_GMII ( MIIM_TYPE, 80,
1410 MFT_BITMAP|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1411 NULL, OK, ER );
1412 TMII_DONE
1413 /* SEPARATOR and STRING go well together */
1414 /* BITMAP and STRING go well together */
1415 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1416 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1417 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1418 txt, OK, OK );
1419 TMII_DONE
1420 /* BITMAP, SEPARATOR and STRING go well together */
1421 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1422 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1423 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1424 txt, OK, OK );
1425 TMII_DONE
1426 /* last two tests, but use MIIM_TYPE to retrieve info */
1427 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1428 TMII_GMII ( MIIM_TYPE, 80,
1429 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1430 NULL, OK, OK );
1431 TMII_DONE
1432 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1433 TMII_GMII ( MIIM_TYPE, 80,
1434 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1435 NULL, OK, OK );
1436 TMII_DONE
1437 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1438 TMII_GMII ( MIIM_TYPE, 80,
1439 MFT_SEPARATOR|MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1440 NULL, OK, OK );
1441 TMII_DONE
1442 /* same three with MFT_OWNERDRAW */
1443 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1444 TMII_GMII ( MIIM_TYPE, 80,
1445 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1446 NULL, OK, OK );
1447 TMII_DONE
1448 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1449 TMII_GMII ( MIIM_TYPE, 80,
1450 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1451 NULL, OK, OK );
1452 TMII_DONE
1453 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1454 TMII_GMII ( MIIM_TYPE, 80,
1455 MFT_SEPARATOR|MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1456 NULL, OK, OK );
1457 TMII_DONE
1459 TMII_INSMI( MIIM_STRING|MIIM_FTYPE|MIIM_ID, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1460 TMII_GMII ( MIIM_TYPE, 80,
1461 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1462 NULL, OK, OK );
1463 TMII_DONE
1464 /* test with modifymenu: string is preserved after setting OWNERDRAW */
1465 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1466 TMII_MODM( MFT_OWNERDRAW, -1, (void*)787 );
1467 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_DATA, 80,
1468 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 787, string, 4, 0,
1469 txt, OK, OK );
1470 TMII_DONE
1471 /* same with bitmap: now the text is cleared */
1472 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1473 TMII_MODM( MFT_BITMAP, 545, hbm );
1474 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1475 MFT_BITMAP, 0, 545, 0, 0, 0, 0, string, 0, hbm,
1476 empty, OK, ER );
1477 TMII_DONE
1478 /* start with bitmap: now setting text clears it (though he flag is raised) */
1479 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1480 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1481 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 0, hbm,
1482 empty, OK, ER );
1483 TMII_MODM( MFT_STRING, 545, txt );
1484 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1485 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 4, 0,
1486 txt, OK, OK );
1487 TMII_DONE
1488 /*repeat with text NULL */
1489 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1490 TMII_MODM( MFT_STRING, 545, NULL );
1491 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1492 MFT_SEPARATOR, 0, 545, 0, 0, 0, 0, string, 0, 0,
1493 empty, OK, ER );
1494 TMII_DONE
1495 /* repeat with text "" */
1496 TMII_INSMI( MIIM_BITMAP, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1497 TMII_MODM( MFT_STRING, 545, empty );
1498 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1499 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 0, 0,
1500 empty, OK, ER );
1501 TMII_DONE
1502 /* start with bitmap: set ownerdraw */
1503 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1504 TMII_MODM( MFT_OWNERDRAW, -1, (void *)232 );
1505 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_DATA, 80,
1506 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 232, string, 0, hbm,
1507 empty, OK, ER );
1508 TMII_DONE
1509 /* ask nothing */
1510 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1511 TMII_GMII ( 0, 80,
1512 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1513 init, OK, OK );
1514 TMII_DONE
1515 /* some tests with small cbSize: the hbmpItem is to be ignored */
1516 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1517 TMII_GMII ( MIIM_TYPE, 80,
1518 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1519 NULL, OK, ER );
1520 TMII_DONE
1521 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1522 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1523 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, NULL,
1524 init, OK, ER );
1525 TMII_DONE
1526 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1527 TMII_GMII ( MIIM_TYPE, 80,
1528 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, NULL,
1529 txt, OK, OK );
1530 TMII_DONE
1531 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1532 TMII_GMII ( MIIM_TYPE, 80,
1533 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1534 NULL, OK, OK );
1535 TMII_DONE
1536 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1537 TMII_GMII ( MIIM_TYPE, 80,
1538 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1539 NULL, OK, OK );
1540 TMII_DONE
1541 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1542 TMII_GMII ( MIIM_TYPE, 80,
1543 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1544 NULL, OK, OK );
1545 TMII_DONE
1546 /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus */
1547 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1548 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1549 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1550 NULL, OK, ER );
1551 TMII_DONE
1552 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1553 TMII_GMII ( MIIM_TYPE, 80,
1554 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1555 NULL, OK, ER );
1556 TMII_DONE
1557 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1558 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1559 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1560 NULL, OK, ER );
1561 TMII_DONE
1562 /* set a string menu to ownerdraw with MIIM_TYPE */
1563 TMII_INSMI( MIIM_TYPE, MFT_STRING, -2, -2, 0, 0, 0, -2, txt, -2, 0, OK );
1564 TMII_SMII ( MIIM_TYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1565 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1566 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1567 txt, OK, OK );
1568 TMII_DONE
1569 /* test with modifymenu add submenu */
1570 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1571 TMII_MODM( MF_POPUP, (UINT_PTR)submenu, txt );
1572 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_SUBMENU, 80,
1573 MFT_STRING, 0, 0, submenu, 0, 0, 0, string, 4, 0,
1574 txt, OK, OK );
1575 TMII_GMII ( MIIM_TYPE, 80,
1576 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1577 txt, OK, OK );
1578 TMII_DONE
1579 /* MFT_SEPARATOR bit is kept when the text is added */
1580 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1581 TMII_SMII( MIIM_STRING, 0, 0, 0, 0, 0, 0, 0, txt, 0, 0 );
1582 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1583 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, 0,
1584 txt, OK, OK );
1585 TMII_DONE
1586 /* MFT_SEPARATOR bit is kept when bitmap is added */
1587 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1588 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm );
1589 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1590 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1591 init, OK, ER );
1592 TMII_DONE
1593 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1594 Only the low word of the dwTypeData is used.
1595 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1596 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1597 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1598 TMII_GMII ( MIIM_TYPE, 80,
1599 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1600 NULL, OK, OK );
1601 TMII_DONE
1602 /* Type flags */
1603 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1604 TMII_GMII ( MIIM_TYPE, 80,
1605 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1606 NULL, OK, OK );
1607 TMII_DONE
1608 /* State flags */
1609 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1610 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1611 TMII_GMII ( MIIM_STATE, 80,
1612 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1613 NULL, OK, OK );
1614 TMII_DONE
1615 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1616 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1617 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1618 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1619 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1620 NULL, OK, OK );
1621 TMII_DONE
1622 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1623 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1624 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1625 TMII_GMII ( MIIM_FTYPE, 80,
1626 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1627 NULL, OK, OK );
1628 TMII_GMII ( MIIM_TYPE, 80,
1629 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1630 NULL, OK, OK );
1631 TMII_GMII ( MIIM_FTYPE, 80,
1632 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1633 NULL, OK, OK );
1634 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1635 TMII_GMII ( MIIM_TYPE, 80,
1636 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1637 NULL, OK, OK );
1638 TMII_DONE
1639 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1640 Only the low word of the dwTypeData is used.
1641 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1642 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1643 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1644 TMII_GMII ( MIIM_TYPE, 80,
1645 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1646 NULL, OK, OK );
1647 TMII_DONE
1648 /* Type flags */
1649 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1650 TMII_GMII ( MIIM_TYPE, 80,
1651 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1652 NULL, OK, OK );
1653 TMII_DONE
1654 /* State flags */
1655 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1656 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1657 TMII_GMII ( MIIM_STATE, 80,
1658 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1659 NULL, OK, OK );
1660 TMII_DONE
1661 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1662 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1663 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1664 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1665 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1666 NULL, OK, OK );
1667 TMII_DONE
1668 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1669 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1670 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1671 TMII_GMII ( MIIM_FTYPE, 80,
1672 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1673 NULL, OK, OK );
1674 TMII_GMII ( MIIM_TYPE, 80,
1675 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1676 NULL, OK, OK );
1677 TMII_GMII ( MIIM_FTYPE, 80,
1678 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1679 NULL, OK, OK );
1680 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1681 TMII_GMII ( MIIM_TYPE, 80,
1682 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1683 NULL, OK, OK );
1684 TMII_DONE
1685 } while( !(ansi = !ansi) );
1686 DeleteObject( hbm);
1690 The following tests try to confirm the algorithm used to return the menu items
1691 when there is a collision between a menu item and a popup menu
1693 static void test_menu_search_bycommand( void )
1695 HMENU hmenu, hmenuSub, hmenuSub2;
1696 MENUITEMINFO info;
1697 BOOL rc;
1698 UINT id;
1699 char strback[0x80];
1700 char strIn[0x80];
1701 static CHAR menuitem[] = "MenuItem",
1702 menuitem2[] = "MenuItem 2";
1704 /* Case 1: Menu containing a menu item */
1705 hmenu = CreateMenu();
1707 memset( &info, 0, sizeof info );
1708 info.cbSize = sizeof info;
1709 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1710 info.fType = MFT_STRING;
1711 strcpy(strIn, "Case 1 MenuItem");
1712 info.dwTypeData = strIn;
1713 info.wID = (UINT) 0x1234;
1715 rc = InsertMenuItem(hmenu, 0, TRUE, &info );
1716 ok (rc, "Inserting the menuitem failed\n");
1718 id = GetMenuItemID(hmenu, 0);
1719 ok (id == 0x1234, "Getting the menuitem id failed(gave %x)\n", id);
1721 /* Confirm the menuitem was given the id supplied (getting by position) */
1722 memset( &info, 0, sizeof info );
1723 strback[0] = 0x00;
1724 info.cbSize = sizeof(MENUITEMINFO);
1725 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1726 info.dwTypeData = strback;
1727 info.cch = sizeof(strback);
1729 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info); /* Get by position */
1730 ok (rc, "Getting the menu items info failed\n");
1731 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1732 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1734 /* Search by id - Should return the item */
1735 memset( &info, 0, sizeof info );
1736 strback[0] = 0x00;
1737 info.cbSize = sizeof(MENUITEMINFO);
1738 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1739 info.dwTypeData = strback;
1740 info.cch = sizeof(strback);
1741 rc = GetMenuItemInfo(hmenu, 0x1234, FALSE, &info); /* Get by ID */
1743 ok (rc, "Getting the menu items info failed\n");
1744 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1745 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1747 DestroyMenu( hmenu );
1749 /* Case 2: Menu containing a popup menu */
1750 hmenu = CreateMenu();
1751 hmenuSub = CreateMenu();
1753 strcpy(strIn, "Case 2 SubMenu");
1754 rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, strIn);
1755 ok (rc, "Inserting the popup menu into the main menu failed\n");
1757 id = GetMenuItemID(hmenu, 0);
1758 ok (id == -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id);
1760 /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
1761 memset( &info, 0, sizeof info );
1762 strback[0] = 0x00;
1763 info.cbSize = sizeof(MENUITEMINFO);
1764 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1765 info.dwTypeData = strback;
1766 info.cch = sizeof(strback);
1767 info.wID = 0xdeadbeef;
1769 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info); /* Get by position */
1770 ok (rc, "Getting the menu items info failed\n");
1771 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the menuitem\n");
1772 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1774 /* Search by id - returns the popup menu itself */
1775 memset( &info, 0, sizeof info );
1776 strback[0] = 0x00;
1777 info.cbSize = sizeof(MENUITEMINFO);
1778 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1779 info.dwTypeData = strback;
1780 info.cch = sizeof(strback);
1781 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1783 ok (rc, "Getting the menu items info failed\n");
1784 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1785 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1788 Now add an item after it with the same id
1790 memset( &info, 0, sizeof info );
1791 info.cbSize = sizeof info;
1792 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1793 info.fType = MFT_STRING;
1794 strcpy(strIn, "Case 2 MenuItem 1");
1795 info.dwTypeData = strIn;
1796 info.wID = (UINT_PTR) hmenuSub;
1797 rc = InsertMenuItem(hmenu, -1, TRUE, &info );
1798 ok (rc, "Inserting the menuitem failed\n");
1800 /* Search by id - returns the item which follows the popup menu */
1801 memset( &info, 0, sizeof info );
1802 strback[0] = 0x00;
1803 info.cbSize = sizeof(MENUITEMINFO);
1804 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1805 info.dwTypeData = strback;
1806 info.cch = sizeof(strback);
1807 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1809 ok (rc, "Getting the menu items info failed\n");
1810 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1811 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1814 Now add an item before the popup (with the same id)
1816 memset( &info, 0, sizeof info );
1817 info.cbSize = sizeof info;
1818 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1819 info.fType = MFT_STRING;
1820 strcpy(strIn, "Case 2 MenuItem 2");
1821 info.dwTypeData = strIn;
1822 info.wID = (UINT_PTR) hmenuSub;
1823 rc = InsertMenuItem(hmenu, 0, TRUE, &info );
1824 ok (rc, "Inserting the menuitem failed\n");
1826 /* Search by id - returns the item which precedes the popup menu */
1827 memset( &info, 0, sizeof info );
1828 strback[0] = 0x00;
1829 info.cbSize = sizeof(MENUITEMINFO);
1830 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1831 info.dwTypeData = strback;
1832 info.cch = sizeof(strback);
1833 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1835 ok (rc, "Getting the menu items info failed\n");
1836 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1837 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1839 DestroyMenu( hmenu );
1840 DestroyMenu( hmenuSub );
1843 Case 3: Menu containing a popup menu which in turn
1844 contains 2 items with the same id as the popup itself
1847 hmenu = CreateMenu();
1848 hmenuSub = CreateMenu();
1850 memset( &info, 0, sizeof info );
1851 info.cbSize = sizeof info;
1852 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1853 info.fType = MFT_STRING;
1854 info.dwTypeData = menuitem;
1855 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1857 rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1858 ok (rc, "Inserting the popup menu into the main menu failed\n");
1860 rc = InsertMenuItem(hmenuSub, 0, TRUE, &info );
1861 ok (rc, "Inserting the sub menu menuitem failed\n");
1863 memset( &info, 0, sizeof info );
1864 info.cbSize = sizeof info;
1865 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1866 info.fType = MFT_STRING;
1867 info.dwTypeData = menuitem2;
1868 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1870 rc = InsertMenuItem(hmenuSub, 1, TRUE, &info );
1871 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
1873 /* Prove that you can't query the id of a popup directly (By position) */
1874 id = GetMenuItemID(hmenu, 0);
1875 ok (id == -1, "Getting the sub menu id should have failed because its a popup (gave %x)\n", id);
1877 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1878 memset( &info, 0, sizeof info );
1879 strback[0] = 0x00;
1880 info.cbSize = sizeof(MENUITEMINFO);
1881 info.fMask = MIIM_STRING | MIIM_ID;
1882 info.dwTypeData = strback;
1883 info.cch = sizeof(strback);
1885 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
1886 ok (rc, "Getting the menus info failed\n");
1887 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
1888 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1889 DestroyMenu( hmenu );
1890 DestroyMenu( hmenuSub );
1893 Case 4: Menu containing 2 popup menus, the second
1894 contains 2 items with the same id as the first popup menu
1896 hmenu = CreateMenu();
1897 hmenuSub = CreateMenu();
1898 hmenuSub2 = CreateMenu();
1900 rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1901 ok (rc, "Inserting the popup menu into the main menu failed\n");
1903 rc = InsertMenu(hmenu, 1, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub2, "Submenu2");
1904 ok (rc, "Inserting the popup menu into the main menu failed\n");
1906 memset( &info, 0, sizeof info );
1907 info.cbSize = sizeof info;
1908 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1909 info.fType = MFT_STRING;
1910 info.dwTypeData = menuitem;
1911 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1913 rc = InsertMenuItem(hmenuSub2, 0, TRUE, &info );
1914 ok (rc, "Inserting the sub menu menuitem failed\n");
1916 memset( &info, 0, sizeof info );
1917 info.cbSize = sizeof info;
1918 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1919 info.fType = MFT_STRING;
1920 info.dwTypeData = menuitem2;
1921 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1923 rc = InsertMenuItem(hmenuSub2, 1, TRUE, &info );
1924 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
1926 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1927 memset( &info, 0, sizeof info );
1928 strback[0] = 0x00;
1929 info.cbSize = sizeof(MENUITEMINFO);
1930 info.fMask = MIIM_STRING | MIIM_ID;
1931 info.dwTypeData = strback;
1932 info.cch = sizeof(strback);
1934 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
1935 ok (rc, "Getting the menus info failed\n");
1936 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
1937 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1939 memset( &info, 0, sizeof info );
1940 strback[0] = 0x00;
1941 info.cbSize = sizeof(MENUITEMINFO);
1942 info.fMask = MIIM_STRING | MIIM_ID;
1943 info.dwTypeData = strback;
1944 info.cch = sizeof(strback);
1946 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub2, FALSE, &info);
1947 ok (rc, "Getting the menus info failed\n");
1948 ok (info.wID == (UINT_PTR)hmenuSub2, "IDs differ for popup menu\n");
1949 ok (!strcmp(info.dwTypeData, "Submenu2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1951 DestroyMenu( hmenu );
1952 DestroyMenu( hmenuSub );
1953 DestroyMenu( hmenuSub2 );
1957 Case 5: Menu containing a popup menu which in turn
1958 contains an item with a different id than the popup menu.
1959 This tests the fallback to a popup menu ID.
1962 hmenu = CreateMenu();
1963 hmenuSub = CreateMenu();
1965 rc = AppendMenu(hmenu, MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1966 ok (rc, "Appending the popup menu to the main menu failed\n");
1968 rc = AppendMenu(hmenuSub, MF_STRING, 102, "Item");
1969 ok (rc, "Appending the item to the popup menu failed\n");
1971 /* Set the ID for hmenuSub */
1972 info.cbSize = sizeof(info);
1973 info.fMask = MIIM_ID;
1974 info.wID = 101;
1976 rc = SetMenuItemInfo(hmenu, 0, TRUE, &info);
1977 ok(rc, "Setting the ID for the popup menu failed\n");
1979 /* Check if the ID has been set */
1980 info.wID = 0;
1981 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info);
1982 ok(rc, "Getting the ID for the popup menu failed\n");
1983 ok(info.wID == 101, "The ID for the popup menu has not been set\n");
1985 /* Prove getting the item info via ID returns the popup menu */
1986 memset( &info, 0, sizeof(info));
1987 strback[0] = 0x00;
1988 info.cbSize = sizeof(MENUITEMINFO);
1989 info.fMask = MIIM_STRING | MIIM_ID;
1990 info.dwTypeData = strback;
1991 info.cch = sizeof(strback);
1993 rc = GetMenuItemInfo(hmenu, 101, FALSE, &info);
1994 ok (rc, "Getting the menu info failed\n");
1995 ok (info.wID == 101, "IDs differ\n");
1996 ok (!strcmp(info.dwTypeData, "Submenu"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1998 /* Also look for the menu item */
1999 memset( &info, 0, sizeof(info));
2000 strback[0] = 0x00;
2001 info.cbSize = sizeof(MENUITEMINFO);
2002 info.fMask = MIIM_STRING | MIIM_ID;
2003 info.dwTypeData = strback;
2004 info.cch = sizeof(strback);
2006 rc = GetMenuItemInfo(hmenu, 102, FALSE, &info);
2007 ok (rc, "Getting the menu info failed\n");
2008 ok (info.wID == 102, "IDs differ\n");
2009 ok (!strcmp(info.dwTypeData, "Item"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2011 DestroyMenu(hmenu);
2012 DestroyMenu(hmenuSub);
2015 struct menu_item_pair_s {
2016 UINT uMenu; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
2017 * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
2018 * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
2019 UINT uItem;
2022 static struct menu_mouse_tests_s {
2023 DWORD type;
2024 struct menu_item_pair_s menu_item_pairs[5]; /* for mousing */
2025 WORD wVk[5]; /* keys */
2026 BOOL bMenuVisible;
2027 BOOL _todo_wine;
2028 } menu_tests[] = {
2029 /* for each test, send keys or clicks and check for menu visibility */
2030 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE }, /* test 0 */
2031 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
2032 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
2033 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2034 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
2035 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2036 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2037 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, VK_ESCAPE, 0}, FALSE, FALSE },
2038 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', VK_ESCAPE, 0}, TRUE, FALSE },
2039 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
2040 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2041 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2042 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2043 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2044 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
2045 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2046 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
2047 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2048 { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, TRUE, FALSE },
2049 { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, FALSE, FALSE },
2051 { INPUT_MOUSE, {{1, 2}, {0}}, {0}, TRUE, TRUE }, /* test 20 */
2052 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2053 { INPUT_MOUSE, {{1, 0}, {0}}, {0}, TRUE, TRUE },
2054 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2055 { INPUT_MOUSE, {{1, 0}, {2, 2}, {0}}, {0}, TRUE, TRUE },
2056 { INPUT_MOUSE, {{2, 1}, {0}}, {0}, FALSE, FALSE },
2057 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
2058 { INPUT_MOUSE, {{3, 0}, {0}}, {0}, FALSE, FALSE },
2059 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
2060 { INPUT_MOUSE, {{3, 1}, {0}}, {0}, TRUE, TRUE },
2061 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2062 { -1 }
2065 static void send_key(WORD wVk)
2067 TEST_INPUT i[2];
2068 memset(i, 0, sizeof(i));
2069 i[0].type = i[1].type = INPUT_KEYBOARD;
2070 i[0].u.ki.wVk = i[1].u.ki.wVk = wVk;
2071 i[1].u.ki.dwFlags = KEYEVENTF_KEYUP;
2072 pSendInput(2, (INPUT *) i, sizeof(INPUT));
2075 static BOOL click_menu(HANDLE hWnd, struct menu_item_pair_s *mi)
2077 HMENU hMenu = hMenus[mi->uMenu];
2078 TEST_INPUT i[3];
2079 MSG msg;
2080 RECT r;
2081 int screen_w = GetSystemMetrics(SM_CXSCREEN);
2082 int screen_h = GetSystemMetrics(SM_CYSCREEN);
2083 BOOL ret = GetMenuItemRect(mi->uMenu > 2 ? NULL : hWnd, hMenu, mi->uItem, &r);
2084 if(!ret) return FALSE;
2086 memset(i, 0, sizeof(i));
2087 i[0].type = i[1].type = i[2].type = INPUT_MOUSE;
2088 i[0].u.mi.dx = i[1].u.mi.dx = i[2].u.mi.dx
2089 = ((r.left + 5) * 65535) / screen_w;
2090 i[0].u.mi.dy = i[1].u.mi.dy = i[2].u.mi.dy
2091 = ((r.top + 5) * 65535) / screen_h;
2092 i[0].u.mi.dwFlags = i[1].u.mi.dwFlags = i[2].u.mi.dwFlags
2093 = MOUSEEVENTF_ABSOLUTE;
2094 i[0].u.mi.dwFlags |= MOUSEEVENTF_MOVE;
2095 i[1].u.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
2096 i[2].u.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
2097 ret = pSendInput(3, (INPUT *) i, sizeof(INPUT));
2099 /* hack to prevent mouse message buildup in Wine */
2100 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
2101 return ret;
2104 static DWORD WINAPI test_menu_input_thread(LPVOID lpParameter)
2106 int i, j;
2107 HANDLE hWnd = lpParameter;
2109 Sleep(500);
2110 /* mixed keyboard/mouse test */
2111 for (i = 0; menu_tests[i].type != -1; i++)
2113 int ret = TRUE, elapsed = 0;
2115 got_input = i && menu_tests[i-1].bMenuVisible;
2117 if (menu_tests[i].type == INPUT_KEYBOARD)
2118 for (j = 0; menu_tests[i].wVk[j] != 0; j++)
2119 send_key(menu_tests[i].wVk[j]);
2120 else
2121 for (j = 0; menu_tests[i].menu_item_pairs[j].uMenu != 0; j++)
2122 if (!(ret = click_menu(hWnd, &menu_tests[i].menu_item_pairs[j]))) break;
2124 if (!ret)
2126 skip( "test %u: failed to send input\n", i );
2127 PostMessage( hWnd, WM_CANCELMODE, 0, 0 );
2128 return 0;
2130 while (menu_tests[i].bMenuVisible != bMenuVisible)
2132 if (elapsed > 200)
2133 break;
2134 elapsed += 20;
2135 Sleep(20);
2138 if (!got_input)
2140 skip( "test %u: didn't receive input\n", i );
2141 PostMessage( hWnd, WM_CANCELMODE, 0, 0 );
2142 return 0;
2145 if (menu_tests[i]._todo_wine)
2147 todo_wine {
2148 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
2151 else
2152 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
2154 return 0;
2157 static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam,
2158 LPARAM lParam)
2160 switch (msg) {
2161 case WM_ENTERMENULOOP:
2162 bMenuVisible = TRUE;
2163 break;
2164 case WM_INITMENUPOPUP:
2165 case WM_UNINITMENUPOPUP:
2166 case WM_EXITMENULOOP:
2167 case WM_MENUSELECT:
2168 break;
2170 case WM_KEYDOWN:
2171 case WM_SYSKEYDOWN:
2172 case WM_MOUSEMOVE:
2173 case WM_LBUTTONDOWN:
2174 case WM_LBUTTONUP:
2175 case WM_NCMOUSEMOVE:
2176 case WM_NCLBUTTONDOWN:
2177 case WM_NCLBUTTONUP:
2178 got_input = TRUE;
2179 /* fall through */
2180 default:
2181 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2184 if(pGetMenuBarInfo)
2186 MENUBARINFO mbi;
2187 HMENU hmenu;
2188 UINT state;
2189 BOOL br;
2191 mbi.cbSize = sizeof(MENUBARINFO);
2193 /* get info for the menu */
2194 br = pGetMenuBarInfo(hWnd, OBJID_MENU, 0, &mbi);
2195 ok(br, "msg %x: GetMenuBarInfo failed\n", msg);
2196 hmenu = GetMenu(hWnd);
2197 ok(!mbi.hwndMenu, "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected NULL\n",
2198 msg, mbi.hwndMenu);
2199 ok(mbi.hMenu == hmenu, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2200 msg, mbi.hMenu, hmenu);
2201 ok(!bMenuVisible == !mbi.fBarFocused, "msg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2202 msg, mbi.fBarFocused != 0);
2203 ok(!bMenuVisible == !mbi.fFocused, "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n",
2204 msg, mbi.fFocused != 0);
2206 /* get info for the menu's first item */
2207 br = pGetMenuBarInfo(hWnd, OBJID_MENU, 1, &mbi);
2208 ok(br, "msg %x: GetMenuBarInfo failed\n", msg);
2209 state = GetMenuState(hmenu, 0, MF_BYPOSITION);
2210 if (pGetMenuInfo) /* Skip on NT */
2212 /* Native returns handle to destroyed window */
2213 if (msg==WM_UNINITMENUPOPUP && popmenu==1)
2214 todo_wine ok(!mbi.hwndMenu == !popmenu,
2215 "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected %sNULL\n",
2216 msg, mbi.hwndMenu, popmenu ? "not " : "");
2217 else
2218 ok(!mbi.hwndMenu == !popmenu,
2219 "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected %sNULL\n",
2220 msg, mbi.hwndMenu, popmenu ? "not " : "");
2222 ok(mbi.hMenu == hmenu, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2223 msg, mbi.hMenu, hmenu);
2224 ok(!bMenuVisible == !mbi.fBarFocused, "nsg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2225 msg, mbi.fBarFocused != 0);
2226 ok(!(bMenuVisible && (state & MF_HILITE)) == !mbi.fFocused,
2227 "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n", msg, mbi.fFocused != 0);
2230 if (msg == WM_EXITMENULOOP)
2231 bMenuVisible = FALSE;
2232 else if (msg == WM_INITMENUPOPUP)
2233 popmenu++;
2234 else if (msg == WM_UNINITMENUPOPUP)
2235 popmenu--;
2236 return 0;
2239 static void test_menu_input(void) {
2240 MSG msg;
2241 WNDCLASSA wclass;
2242 HINSTANCE hInstance = GetModuleHandleA( NULL );
2243 HANDLE hThread, hWnd;
2244 DWORD tid;
2245 ATOM aclass;
2247 if (!pSendInput)
2249 win_skip("SendInput is not available\n");
2250 return;
2253 wclass.lpszClassName = "MenuTestClass";
2254 wclass.style = CS_HREDRAW | CS_VREDRAW;
2255 wclass.lpfnWndProc = WndProc;
2256 wclass.hInstance = hInstance;
2257 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
2258 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
2259 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2260 wclass.lpszMenuName = 0;
2261 wclass.cbClsExtra = 0;
2262 wclass.cbWndExtra = 0;
2263 aclass = RegisterClassA( &wclass );
2264 ok (aclass, "MenuTest class not created\n");
2265 if (!aclass) return;
2266 hWnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
2267 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2268 400, 200, NULL, NULL, hInstance, NULL);
2269 ok (hWnd != NULL, "MenuTest window not created\n");
2270 if (!hWnd) return;
2271 /* fixed menus */
2272 hMenus[3] = CreatePopupMenu();
2273 AppendMenu(hMenus[3], MF_STRING, 0, "&Enabled");
2274 AppendMenu(hMenus[3], MF_STRING|MF_DISABLED, 0, "&Disabled");
2276 hMenus[2] = CreatePopupMenu();
2277 AppendMenu(hMenus[2], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[3], "&Popup");
2278 AppendMenu(hMenus[2], MF_STRING, 0, "&Enabled");
2279 AppendMenu(hMenus[2], MF_STRING|MF_DISABLED, 0, "&Disabled");
2281 hMenus[1] = CreateMenu();
2282 AppendMenu(hMenus[1], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[2], "&Menu");
2283 AppendMenu(hMenus[1], MF_STRING, 0, "&Enabled");
2284 AppendMenu(hMenus[1], MF_STRING|MF_DISABLED, 0, "&Disabled");
2286 SetMenu(hWnd, hMenus[1]);
2287 ShowWindow(hWnd, SW_SHOW);
2288 UpdateWindow(hWnd);
2290 hThread = CreateThread(NULL, 0, test_menu_input_thread, hWnd, 0, &tid);
2291 while(1)
2293 if (WAIT_TIMEOUT != WaitForSingleObject(hThread, 50))
2294 break;
2295 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2297 DestroyWindow(hWnd);
2300 static void test_menu_flags( void )
2302 HMENU hMenu, hPopupMenu;
2304 hMenu = CreateMenu();
2305 hPopupMenu = CreatePopupMenu();
2307 AppendMenu(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2309 AppendMenu(hPopupMenu, MF_STRING | MF_HILITE | MF_DEFAULT, 101, "Item 1");
2310 InsertMenu(hPopupMenu, 1, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 102, "Item 2");
2311 AppendMenu(hPopupMenu, MF_STRING, 103, "Item 3");
2312 ModifyMenu(hPopupMenu, 2, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 103, "Item 3");
2314 ok(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_HILITE,
2315 "AppendMenu should accept MF_HILITE\n");
2316 ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2317 "InsertMenu should accept MF_HILITE\n");
2318 ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2319 "ModifyMenu should accept MF_HILITE\n");
2321 ok(!(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_DEFAULT),
2322 "AppendMenu must not accept MF_DEFAULT\n");
2323 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_DEFAULT),
2324 "InsertMenu must not accept MF_DEFAULT\n");
2325 ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_DEFAULT),
2326 "ModifyMenu must not accept MF_DEFAULT\n");
2328 DestroyMenu(hMenu);
2331 static void test_menu_hilitemenuitem( void )
2333 HMENU hMenu, hPopupMenu;
2334 WNDCLASSA wclass;
2335 HWND hWnd;
2336 ATOM aclass;
2338 wclass.lpszClassName = "HiliteMenuTestClass";
2339 wclass.style = CS_HREDRAW | CS_VREDRAW;
2340 wclass.lpfnWndProc = WndProc;
2341 wclass.hInstance = GetModuleHandleA( NULL );
2342 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
2343 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
2344 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2345 wclass.lpszMenuName = 0;
2346 wclass.cbClsExtra = 0;
2347 wclass.cbWndExtra = 0;
2348 aclass = RegisterClassA( &wclass );
2349 ok (aclass, "HiliteMenuTest class could not be created\n");
2350 if (!aclass) return;
2351 hWnd = CreateWindowA( wclass.lpszClassName, "HiliteMenuTest",
2352 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2353 400, 200, NULL, NULL, wclass.hInstance, NULL);
2354 ok (hWnd != NULL, "HiliteMenuTest window could not be created\n");
2355 if (!hWnd) return;
2357 hMenu = CreateMenu();
2358 hPopupMenu = CreatePopupMenu();
2360 AppendMenu(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2362 AppendMenu(hPopupMenu, MF_STRING, 101, "Item 1");
2363 AppendMenu(hPopupMenu, MF_STRING, 102, "Item 2");
2364 AppendMenu(hPopupMenu, MF_STRING, 103, "Item 3");
2366 SetMenu(hWnd, hMenu);
2368 /* test invalid arguments */
2370 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2371 "HiliteMenuItem: Item 2 is hilited\n");
2373 SetLastError(0xdeadbeef);
2374 todo_wine
2376 ok(!HiliteMenuItem(NULL, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2377 "HiliteMenuItem: call should have failed.\n");
2379 ok(GetLastError() == 0xdeadbeef || /* 9x */
2380 GetLastError() == ERROR_INVALID_WINDOW_HANDLE /* NT */,
2381 "HiliteMenuItem: expected error ERROR_INVALID_WINDOW_HANDLE, got: %d\n", GetLastError());
2383 SetLastError(0xdeadbeef);
2384 ok(!HiliteMenuItem(hWnd, NULL, 1, MF_HILITE | MF_BYPOSITION),
2385 "HiliteMenuItem: call should have failed.\n");
2386 ok(GetLastError() == 0xdeadbeef || /* 9x */
2387 GetLastError() == ERROR_INVALID_MENU_HANDLE /* NT */,
2388 "HiliteMenuItem: expected error ERROR_INVALID_MENU_HANDLE, got: %d\n", GetLastError());
2390 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2391 "HiliteMenuItem: Item 2 is hilited\n");
2393 /* either MF_HILITE or MF_UNHILITE *and* MF_BYCOMMAND or MF_BYPOSITION need to be set */
2395 SetLastError(0xdeadbeef);
2396 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_BYPOSITION),
2397 "HiliteMenuItem: call should have succeeded.\n");
2398 ok(GetLastError() == 0xdeadbeef,
2399 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2401 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2402 "HiliteMenuItem: Item 2 is hilited\n");
2404 SetLastError(0xdeadbeef);
2405 todo_wine
2407 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE),
2408 "HiliteMenuItem: call should have succeeded.\n");
2410 ok(GetLastError() == 0xdeadbeef,
2411 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2413 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2414 "HiliteMenuItem: Item 2 is hilited\n");
2416 /* hilite a menu item (by position) */
2418 SetLastError(0xdeadbeef);
2419 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2420 "HiliteMenuItem: call should not have failed.\n");
2421 ok(GetLastError() == 0xdeadbeef,
2422 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2424 todo_wine
2426 ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2427 "HiliteMenuItem: Item 2 is not hilited\n");
2430 /* unhilite a menu item (by position) */
2432 SetLastError(0xdeadbeef);
2433 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_UNHILITE | MF_BYPOSITION),
2434 "HiliteMenuItem: call should not have failed.\n");
2435 ok(GetLastError() == 0xdeadbeef,
2436 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2438 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2439 "HiliteMenuItem: Item 2 is hilited\n");
2441 /* hilite a menu item (by command) */
2443 SetLastError(0xdeadbeef);
2444 ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_HILITE | MF_BYCOMMAND),
2445 "HiliteMenuItem: call should not have failed.\n");
2446 ok(GetLastError() == 0xdeadbeef,
2447 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2449 todo_wine
2451 ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2452 "HiliteMenuItem: Item 3 is not hilited\n");
2455 /* unhilite a menu item (by command) */
2457 SetLastError(0xdeadbeef);
2458 ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_UNHILITE | MF_BYCOMMAND),
2459 "HiliteMenuItem: call should not have failed.\n");
2460 ok(GetLastError() == 0xdeadbeef,
2461 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2463 ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE),
2464 "HiliteMenuItem: Item 3 is hilited\n");
2466 DestroyWindow(hWnd);
2469 static void check_menu_items(HMENU hmenu, UINT checked_cmd, UINT checked_type,
2470 UINT checked_state)
2472 INT i, count;
2474 count = GetMenuItemCount(hmenu);
2475 ok (count != -1, "GetMenuItemCount returned -1\n");
2477 for (i = 0; i < count; i++)
2479 BOOL ret;
2480 MENUITEMINFO mii;
2482 memset(&mii, 0, sizeof(mii));
2483 mii.cbSize = sizeof(mii);
2484 mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU;
2485 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2486 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2487 #if 0
2488 trace("item #%u: fType %04x, fState %04x, wID %u, hSubMenu %p\n",
2489 i, mii.fType, mii.fState, mii.wID, mii.hSubMenu);
2490 #endif
2491 if (mii.hSubMenu)
2493 ok(mii.wID == (UINT_PTR)mii.hSubMenu, "id %u: wID should be equal to hSubMenu\n", checked_cmd);
2494 check_menu_items(mii.hSubMenu, checked_cmd, checked_type, checked_state);
2496 else
2498 if (mii.wID == checked_cmd)
2500 ok(mii.fType == checked_type, "id %u: expected fType %04x, got %04x\n", checked_cmd, checked_type, mii.fType);
2501 ok(mii.fState == checked_state, "id %u: expected fState %04x, got %04x\n", checked_cmd, checked_state, mii.fState);
2502 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2504 else
2506 ok(mii.fType != MFT_RADIOCHECK, "id %u: not expected fType MFT_RADIOCHECK on cmd %u\n", checked_cmd, mii.wID);
2508 if (mii.fType == MFT_SEPARATOR)
2510 ok(mii.fState == MFS_GRAYED, "id %u: expected fState MFS_GRAYED, got %04x\n", checked_cmd, mii.fState);
2511 ok(mii.wID == 0, "id %u: expected wID 0, got %u\n", checked_cmd, mii.wID);
2513 else
2515 ok(mii.fState == 0, "id %u: expected fState 0, got %04x\n", checked_cmd, mii.fState);
2516 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2523 static void clear_ftype_and_state(HMENU hmenu, UINT id, UINT flags)
2525 BOOL ret;
2526 MENUITEMINFO mii;
2528 memset(&mii, 0, sizeof(mii));
2529 mii.cbSize = sizeof(mii);
2530 mii.fMask = MIIM_FTYPE | MIIM_STATE;
2531 ret = SetMenuItemInfo(hmenu, id, (flags & MF_BYPOSITION) != 0, &mii);
2532 ok(ret, "SetMenuItemInfo(%u) failed\n", id);
2535 static void test_CheckMenuRadioItem(void)
2537 BOOL ret;
2538 HMENU hmenu;
2540 hmenu = LoadMenu(GetModuleHandle(0), MAKEINTRESOURCE(1));
2541 assert(hmenu != 0);
2543 check_menu_items(hmenu, -1, 0, 0);
2545 ret = CheckMenuRadioItem(hmenu, 100, 100, 100, MF_BYCOMMAND);
2546 ok(ret, "CheckMenuRadioItem failed\n");
2547 check_menu_items(hmenu, 100, MFT_RADIOCHECK, MFS_CHECKED);
2549 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2550 ret = CheckMenuRadioItem(hmenu, 100, 100, -1, MF_BYCOMMAND);
2551 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2552 check_menu_items(hmenu, 100, MFT_RADIOCHECK, 0);
2554 /* clear check */
2555 clear_ftype_and_state(hmenu, 100, MF_BYCOMMAND);
2556 check_menu_items(hmenu, -1, 0, 0);
2558 /* first and checked items are on different menus */
2559 ret = CheckMenuRadioItem(hmenu, 0, 300, 202, MF_BYCOMMAND);
2560 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2561 check_menu_items(hmenu, -1, 0, 0);
2563 ret = CheckMenuRadioItem(hmenu, 200, 300, 202, MF_BYCOMMAND);
2564 ok(ret, "CheckMenuRadioItem failed\n");
2565 check_menu_items(hmenu, 202, MFT_RADIOCHECK, MFS_CHECKED);
2567 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2568 ret = CheckMenuRadioItem(hmenu, 202, 202, -1, MF_BYCOMMAND);
2569 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2570 check_menu_items(hmenu, 202, MFT_RADIOCHECK, 0);
2572 /* clear check */
2573 clear_ftype_and_state(hmenu, 202, MF_BYCOMMAND);
2574 check_menu_items(hmenu, -1, 0, 0);
2576 /* just for fun, try to check separator */
2577 ret = CheckMenuRadioItem(hmenu, 0, 300, 0, MF_BYCOMMAND);
2578 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2579 check_menu_items(hmenu, -1, 0, 0);
2582 static void test_menu_resource_layout(void)
2584 static const struct
2586 MENUITEMTEMPLATEHEADER mith;
2587 WORD data[14];
2588 } menu_template =
2590 { 0, 0 }, /* versionNumber, offset */
2592 /* mtOption, mtID, mtString[] '\0' terminated */
2593 MF_STRING, 1, 'F', 0,
2594 MF_STRING, 2, 0,
2595 MF_SEPARATOR, 3, 0,
2596 /* MF_SEPARATOR, 4, 'S', 0, FIXME: Wine ignores 'S' */
2597 MF_STRING|MF_GRAYED|MF_END, 5, 'E', 0
2600 static const struct
2602 UINT type, state, id;
2603 const char *str;
2604 } menu_data[] =
2606 { MF_STRING, MF_ENABLED, 1, "F" },
2607 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 2, "" },
2608 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 3, "" },
2609 /*{ MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 4, "S" }, FIXME: Wine ignores 'S'*/
2610 { MF_STRING, MF_GRAYED, 5, "E" },
2611 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 6, "" },
2612 { MF_STRING, MF_ENABLED, 7, "" },
2613 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 8, "" }
2615 HMENU hmenu;
2616 INT count, i;
2617 BOOL ret;
2619 hmenu = LoadMenuIndirect(&menu_template);
2620 ok(hmenu != 0, "LoadMenuIndirect error %u\n", GetLastError());
2622 ret = AppendMenu(hmenu, MF_STRING, 6, NULL);
2623 ok(ret, "AppendMenu failed\n");
2624 ret = AppendMenu(hmenu, MF_STRING, 7, "\0");
2625 ok(ret, "AppendMenu failed\n");
2626 ret = AppendMenu(hmenu, MF_SEPARATOR, 8, "separator");
2627 ok(ret, "AppendMenu failed\n");
2629 count = GetMenuItemCount(hmenu);
2630 ok(count == sizeof(menu_data)/sizeof(menu_data[0]),
2631 "expected %u menu items, got %u\n",
2632 (UINT)(sizeof(menu_data)/sizeof(menu_data[0])), count);
2634 for (i = 0; i < count; i++)
2636 char buf[20];
2637 MENUITEMINFO mii;
2639 memset(&mii, 0, sizeof(mii));
2640 mii.cbSize = sizeof(mii);
2641 mii.dwTypeData = buf;
2642 mii.cch = sizeof(buf);
2643 mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_STRING;
2644 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2645 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2646 #if 0
2647 trace("item #%u: fType %04x, fState %04x, wID %u, dwTypeData %s\n",
2648 i, mii.fType, mii.fState, mii.wID, (LPCSTR)mii.dwTypeData);
2649 #endif
2650 ok(mii.fType == menu_data[i].type,
2651 "%u: expected fType %04x, got %04x\n", i, menu_data[i].type, mii.fType);
2652 ok(mii.fState == menu_data[i].state,
2653 "%u: expected fState %04x, got %04x\n", i, menu_data[i].state, mii.fState);
2654 ok(mii.wID == menu_data[i].id,
2655 "%u: expected wID %04x, got %04x\n", i, menu_data[i].id, mii.wID);
2656 ok(mii.cch == strlen(menu_data[i].str),
2657 "%u: expected cch %u, got %u\n", i, (UINT)strlen(menu_data[i].str), mii.cch);
2658 ok(!strcmp(mii.dwTypeData, menu_data[i].str),
2659 "%u: expected dwTypeData %s, got %s\n", i, menu_data[i].str, (LPCSTR)mii.dwTypeData);
2662 DestroyMenu(hmenu);
2665 struct menu_data
2667 UINT type, id;
2668 const char *str;
2671 static HMENU create_menu_from_data(const struct menu_data *item, INT item_count)
2673 HMENU hmenu;
2674 INT i;
2675 BOOL ret;
2677 hmenu = CreateMenu();
2678 assert(hmenu != 0);
2680 for (i = 0; i < item_count; i++)
2682 SetLastError(0xdeadbeef);
2683 ret = AppendMenu(hmenu, item[i].type, item[i].id, item[i].str);
2684 ok(ret, "%d: AppendMenu(%04x, %04x, %p) error %u\n",
2685 i, item[i].type, item[i].id, item[i].str, GetLastError());
2687 return hmenu;
2690 /* use InsertMenuItem: does not set the MFT_BITMAP flag,
2691 * and does not accept non-magic bitmaps with invalid
2692 * bitmap handles */
2693 static HMENU create_menuitem_from_data(const struct menu_data *item, INT item_count)
2695 HMENU hmenu;
2696 INT i;
2697 BOOL ret;
2698 MENUITEMINFO mii = { sizeof( MENUITEMINFO)};
2700 hmenu = CreateMenu();
2701 assert(hmenu != 0);
2703 for (i = 0; i < item_count; i++)
2705 SetLastError(0xdeadbeef);
2707 mii.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STATE;
2708 mii.fType = 0;
2709 if( item[i].type & MFT_BITMAP)
2711 mii.fMask |= MIIM_BITMAP;
2712 mii.hbmpItem = (HBITMAP)item[i].str;
2714 else if( item[i].type & MFT_SEPARATOR)
2715 mii.fType = MFT_SEPARATOR;
2716 else
2718 mii.fMask |= MIIM_STRING;
2719 mii.dwTypeData = (LPSTR)item[i].str;
2720 mii.cch = strlen( item[i].str);
2722 mii.fState = 0;
2723 if( item[i].type & MF_HELP) mii.fType |= MF_HELP;
2724 mii.wID = item[i].id;
2725 ret = InsertMenuItem( hmenu, -1, TRUE, &mii);
2726 ok(ret, "%d: InsertMenuItem(%04x, %04x, %p) error %u\n",
2727 i, item[i].type, item[i].id, item[i].str, GetLastError());
2729 return hmenu;
2732 static void compare_menu_data(HMENU hmenu, const struct menu_data *item, INT item_count)
2734 INT count, i;
2735 BOOL ret;
2737 count = GetMenuItemCount(hmenu);
2738 ok(count == item_count, "expected %d, got %d menu items\n", count, item_count);
2740 for (i = 0; i < count; i++)
2742 char buf[20];
2743 MENUITEMINFO mii;
2745 memset(&mii, 0, sizeof(mii));
2746 mii.cbSize = sizeof(mii);
2747 mii.dwTypeData = buf;
2748 mii.cch = sizeof(buf);
2749 mii.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_BITMAP;
2750 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2751 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2752 #if 0
2753 trace("item #%u: fType %04x, fState %04x, wID %04x, hbmp %p\n",
2754 i, mii.fType, mii.fState, mii.wID, mii.hbmpItem);
2755 #endif
2756 ok(mii.fType == item[i].type,
2757 "%u: expected fType %04x, got %04x\n", i, item[i].type, mii.fType);
2758 ok(mii.wID == item[i].id,
2759 "%u: expected wID %04x, got %04x\n", i, item[i].id, mii.wID);
2760 if (mii.hbmpItem || !item[i].str)
2761 /* For some reason Windows sets high word to not 0 for
2762 * not "magic" ids.
2764 ok(LOWORD(mii.hbmpItem) == LOWORD(item[i].str),
2765 "%u: expected hbmpItem %p, got %p\n", i, item[i].str, mii.hbmpItem);
2766 else
2768 ok(mii.cch == strlen(item[i].str),
2769 "%u: expected cch %u, got %u\n", i, (UINT)strlen(item[i].str), mii.cch);
2770 ok(!strcmp(mii.dwTypeData, item[i].str),
2771 "%u: expected dwTypeData %s, got %s\n", i, item[i].str, (LPCSTR)mii.dwTypeData);
2776 static void test_InsertMenu(void)
2778 HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
2779 /* Note: XP treats only bitmap handles 1 - 6 as "magic" ones
2780 * regardless of their id.
2782 static const struct menu_data in1[] =
2784 { MF_STRING, 1, "File" },
2785 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) },
2786 { MF_STRING|MF_HELP, 2, "Help" }
2788 static const struct menu_data out1[] =
2790 { MF_STRING, 1, "File" },
2791 { MF_STRING|MF_HELP, 2, "Help" },
2792 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) }
2794 static const struct menu_data out1a[] =
2796 { MF_STRING, 1, "File" },
2797 { MF_STRING|MF_HELP, 2, "Help" },
2798 { MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) }
2800 const struct menu_data in2[] =
2802 { MF_STRING, 1, "File" },
2803 { MF_BITMAP|MF_HELP, SC_CLOSE, (char*)hbm },
2804 { MF_STRING|MF_HELP, 2, "Help" }
2806 const struct menu_data out2[] =
2808 { MF_STRING, 1, "File" },
2809 { MF_BITMAP|MF_HELP, SC_CLOSE, (char*)hbm },
2810 { MF_STRING|MF_HELP, 2, "Help" }
2812 const struct menu_data out2a[] =
2814 { MF_STRING, 1, "File" },
2815 { MF_HELP, SC_CLOSE, (char*)hbm },
2816 { MF_STRING|MF_HELP, 2, "Help" }
2818 static const struct menu_data in3[] =
2820 { MF_STRING, 1, "File" },
2821 { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) },
2822 { MF_STRING|MF_HELP, 2, "Help" }
2824 static const struct menu_data out3[] =
2826 { MF_STRING, 1, "File" },
2827 { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(0) },
2828 { MF_STRING|MF_HELP, 2, "Help" },
2830 static const struct menu_data in4[] =
2832 { MF_STRING, 1, "File" },
2833 { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCE(1) },
2834 { MF_STRING|MF_HELP, 2, "Help" }
2836 static const struct menu_data out4[] =
2838 { MF_STRING, 1, "File" },
2839 { MF_STRING|MF_HELP, 2, "Help" },
2840 { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCE(1) }
2842 static const struct menu_data out4a[] =
2844 { MF_STRING, 1, "File" },
2845 { MF_STRING|MF_HELP, 2, "Help" },
2846 { MF_HELP, 1, MAKEINTRESOURCE(1) }
2848 HMENU hmenu;
2850 #define create_menu(a) create_menu_from_data((a), sizeof(a)/sizeof((a)[0]))
2851 #define create_menuitem(a) create_menuitem_from_data((a), sizeof(a)/sizeof((a)[0]))
2852 #define compare_menu(h, a) compare_menu_data((h), (a), sizeof(a)/sizeof((a)[0]))
2854 hmenu = create_menu(in1);
2855 compare_menu(hmenu, out1);
2856 DestroyMenu(hmenu);
2858 hmenu = create_menu(in2);
2859 compare_menu(hmenu, out2);
2860 DestroyMenu(hmenu);
2862 hmenu = create_menu(in3);
2863 compare_menu(hmenu, out3);
2864 DestroyMenu(hmenu);
2866 hmenu = create_menu(in4);
2867 compare_menu(hmenu, out4);
2868 DestroyMenu(hmenu);
2870 /* now using InsertMenuItemInfo */
2871 hmenu = create_menuitem(in1);
2872 compare_menu(hmenu, out1a);
2873 DestroyMenu(hmenu);
2875 hmenu = create_menuitem(in2);
2876 compare_menu(hmenu, out2a);
2877 DestroyMenu(hmenu);
2879 hmenu = create_menuitem(in3);
2880 compare_menu(hmenu, out3);
2881 DestroyMenu(hmenu);
2883 hmenu = create_menuitem(in4);
2884 compare_menu(hmenu, out4a);
2885 DestroyMenu(hmenu);
2887 #undef create_menu
2888 #undef create_menuitem
2889 #undef compare_menu
2892 static void test_menu_getmenuinfo(void)
2894 HMENU hmenu;
2895 MENUINFO mi = {0};
2896 BOOL ret;
2897 DWORD gle;
2899 if (!pGetMenuInfo)
2901 win_skip("GetMenuInfo is not available\n");
2902 return;
2905 /* create a menu */
2906 hmenu = CreateMenu();
2907 assert( hmenu);
2908 /* test some parameter errors */
2909 SetLastError(0xdeadbeef);
2910 ret = pGetMenuInfo( hmenu, NULL);
2911 gle= GetLastError();
2912 ok( !ret, "GetMenuInfo() should have failed\n");
2913 ok( gle == ERROR_INVALID_PARAMETER ||
2914 broken(gle == 0xdeadbeef), /* Win98, WinME */
2915 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2916 SetLastError(0xdeadbeef);
2917 mi.cbSize = 0;
2918 ret = pGetMenuInfo( hmenu, &mi);
2919 gle= GetLastError();
2920 ok( !ret, "GetMenuInfo() should have failed\n");
2921 ok( gle == ERROR_INVALID_PARAMETER ||
2922 broken(gle == 0xdeadbeef), /* Win98, WinME */
2923 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2924 SetLastError(0xdeadbeef);
2925 mi.cbSize = sizeof( MENUINFO);
2926 ret = pGetMenuInfo( hmenu, &mi);
2927 gle= GetLastError();
2928 ok( ret, "GetMenuInfo() should have succeeded\n");
2929 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2930 SetLastError(0xdeadbeef);
2931 mi.cbSize = 0;
2932 ret = pGetMenuInfo( NULL, &mi);
2933 gle= GetLastError();
2934 ok( !ret, "GetMenuInfo() should have failed\n");
2935 ok( gle == ERROR_INVALID_PARAMETER ||
2936 broken(gle == 0xdeadbeef), /* Win98, WinME */
2937 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2938 /* clean up */
2939 DestroyMenu( hmenu);
2940 return;
2943 static void test_menu_setmenuinfo(void)
2945 HMENU hmenu, hsubmenu;
2946 MENUINFO mi = {0};
2947 MENUITEMINFOA mii = {sizeof( MENUITEMINFOA)};
2948 BOOL ret;
2949 DWORD gle;
2951 if (!pGetMenuInfo || !pSetMenuInfo)
2953 win_skip("Get/SetMenuInfo are not available\n");
2954 return;
2957 /* create a menu with a submenu */
2958 hmenu = CreateMenu();
2959 hsubmenu = CreateMenu();
2960 assert( hmenu && hsubmenu);
2961 mii.fMask = MIIM_SUBMENU;
2962 mii.hSubMenu = hsubmenu;
2963 ret = InsertMenuItem( hmenu, 0, FALSE, &mii);
2964 ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
2965 /* test some parameter errors */
2966 SetLastError(0xdeadbeef);
2967 ret = pSetMenuInfo( hmenu, NULL);
2968 gle= GetLastError();
2969 ok( !ret, "SetMenuInfo() should have failed\n");
2970 ok( gle == ERROR_INVALID_PARAMETER ||
2971 broken(gle == 0xdeadbeef), /* Win98, WinME */
2972 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2973 SetLastError(0xdeadbeef);
2974 mi.cbSize = 0;
2975 ret = pSetMenuInfo( hmenu, &mi);
2976 gle= GetLastError();
2977 ok( !ret, "SetMenuInfo() should have failed\n");
2978 ok( gle == ERROR_INVALID_PARAMETER ||
2979 broken(gle == 0xdeadbeef), /* Win98, WinME */
2980 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2981 SetLastError(0xdeadbeef);
2982 mi.cbSize = sizeof( MENUINFO);
2983 ret = pSetMenuInfo( hmenu, &mi);
2984 gle= GetLastError();
2985 ok( ret, "SetMenuInfo() should have succeeded\n");
2986 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2987 SetLastError(0xdeadbeef);
2988 mi.cbSize = 0;
2989 ret = pSetMenuInfo( NULL, &mi);
2990 gle= GetLastError();
2991 ok( !ret, "SetMenuInfo() should have failed\n");
2992 ok( gle == ERROR_INVALID_PARAMETER ||
2993 broken(gle == 0xdeadbeef), /* Win98, WinME */
2994 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2995 /* functional tests */
2996 /* menu and submenu should have the CHECKORBMP style bit cleared */
2997 SetLastError(0xdeadbeef);
2998 mi.cbSize = sizeof( MENUINFO);
2999 mi.fMask = MIM_STYLE;
3000 ret = pGetMenuInfo( hmenu, &mi);
3001 gle= GetLastError();
3002 ok( ret, "GetMenuInfo() should have succeeded\n");
3003 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3004 ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
3005 SetLastError(0xdeadbeef);
3006 mi.cbSize = sizeof( MENUINFO);
3007 mi.fMask = MIM_STYLE;
3008 ret = pGetMenuInfo( hsubmenu, &mi);
3009 gle= GetLastError();
3010 ok( ret, "GetMenuInfo() should have succeeded\n");
3011 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3012 ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
3013 /* SetMenuInfo() */
3014 SetLastError(0xdeadbeef);
3015 mi.cbSize = sizeof( MENUINFO);
3016 mi.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS;
3017 mi.dwStyle = MNS_CHECKORBMP;
3018 ret = pSetMenuInfo( hmenu, &mi);
3019 gle= GetLastError();
3020 ok( ret, "SetMenuInfo() should have succeeded\n");
3021 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
3022 /* Now both menus should have the MNS_CHECKORBMP style bit set */
3023 SetLastError(0xdeadbeef);
3024 mi.cbSize = sizeof( MENUINFO);
3025 mi.fMask = MIM_STYLE;
3026 ret = pGetMenuInfo( hmenu, &mi);
3027 gle= GetLastError();
3028 ok( ret, "GetMenuInfo() should have succeeded\n");
3029 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3030 ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
3031 SetLastError(0xdeadbeef);
3032 mi.cbSize = sizeof( MENUINFO);
3033 mi.fMask = MIM_STYLE;
3034 ret = pGetMenuInfo( hsubmenu, &mi);
3035 gle= GetLastError();
3036 ok( ret, "GetMenuInfo() should have succeeded\n");
3037 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3038 ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
3039 /* now repeat that without the APPLYTOSUBMENUS flag and another style bit */
3040 SetLastError(0xdeadbeef);
3041 mi.cbSize = sizeof( MENUINFO);
3042 mi.fMask = MIM_STYLE ;
3043 mi.dwStyle = MNS_NOCHECK;
3044 ret = pSetMenuInfo( hmenu, &mi);
3045 gle= GetLastError();
3046 ok( ret, "SetMenuInfo() should have succeeded\n");
3047 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
3048 /* Now only the top menu should have the MNS_NOCHECK style bit set */
3049 SetLastError(0xdeadbeef);
3050 mi.cbSize = sizeof( MENUINFO);
3051 mi.fMask = MIM_STYLE;
3052 ret = pGetMenuInfo( hmenu, &mi);
3053 gle= GetLastError();
3054 ok( ret, "GetMenuInfo() should have succeeded\n");
3055 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3056 ok( mi.dwStyle & MNS_NOCHECK, "menustyle was expected to have the MNS_NOCHECK flag\n");
3057 SetLastError(0xdeadbeef);
3058 mi.cbSize = sizeof( MENUINFO);
3059 mi.fMask = MIM_STYLE;
3060 ret = pGetMenuInfo( hsubmenu, &mi);
3061 gle= GetLastError();
3062 ok( ret, "GetMenuInfo() should have succeeded\n");
3063 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3064 ok( !(mi.dwStyle & MNS_NOCHECK), "menustyle was not expected to have the MNS_NOCHECK flag\n");
3065 /* clean up */
3066 DestroyMenu( hsubmenu);
3067 DestroyMenu( hmenu);
3068 return;
3071 /* little func to easy switch either TrackPopupMenu() or TrackPopupMenuEx() */
3072 static DWORD MyTrackPopupMenu( int ex, HMENU hmenu, UINT flags, INT x, INT y, HWND hwnd, LPTPMPARAMS ptpm)
3074 return ex
3075 ? TrackPopupMenuEx( hmenu, flags, x, y, hwnd, ptpm)
3076 : TrackPopupMenu( hmenu, flags, x, y, 0, hwnd, NULL);
3079 /* some TrackPopupMenu and TrackPopupMenuEx tests */
3080 /* the LastError values differ between NO_ERROR and invalid handle */
3081 /* between all windows versions tested. The first value is that valid on XP */
3082 /* Vista was the only that made returned different error values */
3083 /* between the TrackPopupMenu and TrackPopupMenuEx functions */
3084 static void test_menu_trackpopupmenu(void)
3086 BOOL ret;
3087 HMENU hmenu;
3088 DWORD gle;
3089 int Ex;
3090 HWND hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
3091 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
3092 NULL, NULL, NULL, NULL);
3093 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
3094 if (!hwnd) return;
3095 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
3096 for( Ex = 0; Ex < 2; Ex++)
3098 hmenu = CreatePopupMenu();
3099 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
3100 if (!hmenu)
3102 DestroyWindow(hwnd);
3103 return;
3105 /* display the menu */
3106 /* start with an invalid menu handle */
3107 SetLastError(0xdeadbeef);
3109 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
3110 ret = MyTrackPopupMenu( Ex, NULL, TPM_RETURNCMD, 100,100, hwnd, NULL);
3111 gle = GetLastError();
3112 ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
3113 ok( gle == ERROR_INVALID_MENU_HANDLE
3114 || broken (gle == 0xdeadbeef) /* win95 */
3115 || broken (gle == NO_ERROR) /* win98/ME */
3116 ,"TrackPopupMenu%s error got %u expected %u\n",
3117 Ex ? "Ex" : "", gle, ERROR_INVALID_MENU_HANDLE);
3118 ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
3119 "got unexpected message(s)%s%s%s\n",
3120 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
3121 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
3122 gflag_initmenu ? "WM_INITMENU": "");
3123 /* another one but not NULL */
3124 SetLastError(0xdeadbeef);
3125 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
3126 ret = MyTrackPopupMenu( Ex, (HMENU)hwnd, TPM_RETURNCMD, 100,100, hwnd, NULL);
3127 gle = GetLastError();
3128 ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
3129 ok( gle == ERROR_INVALID_MENU_HANDLE
3130 || broken (gle == 0xdeadbeef) /* win95 */
3131 || broken (gle == NO_ERROR) /* win98/ME */
3132 ,"TrackPopupMenu%s error got %u expected %u\n",
3133 Ex ? "Ex" : "", gle, ERROR_INVALID_MENU_HANDLE);
3134 ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
3135 "got unexpected message(s)%s%s%s\n",
3136 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
3137 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
3138 gflag_initmenu ? "WM_INITMENU": "");
3140 /* invalid window */
3141 SetLastError(0xdeadbeef);
3142 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
3143 ret = MyTrackPopupMenu( Ex, hmenu, TPM_RETURNCMD, 100,100, 0, NULL);
3144 gle = GetLastError();
3145 ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
3146 ok( gle == ERROR_INVALID_WINDOW_HANDLE, "TrackPopupMenu%s error got %u\n", Ex ? "Ex" : "", gle );
3147 ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
3148 "got unexpected message(s)%s%s%s\n",
3149 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
3150 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
3151 gflag_initmenu ? "WM_INITMENU": "");
3153 /* now a somewhat successful call */
3154 SetLastError(0xdeadbeef);
3155 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
3156 ret = MyTrackPopupMenu( Ex, hmenu, TPM_RETURNCMD, 100,100, hwnd, NULL);
3157 gle = GetLastError();
3158 ok( ret == 0, "TrackPopupMenu%s returned %d expected zero\n", Ex ? "Ex" : "", ret);
3159 ok( gle == NO_ERROR
3160 || gle == ERROR_INVALID_MENU_HANDLE /* NT4, win2k */
3161 || broken (gle == 0xdeadbeef) /* win95 */
3162 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
3163 Ex ? "Ex" : "", gle, NO_ERROR, ERROR_INVALID_MENU_HANDLE);
3164 ok( gflag_initmenupopup && gflag_entermenuloop && gflag_initmenu,
3165 "missed expected message(s)%s%s%s\n",
3166 !gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
3167 !gflag_entermenuloop ? "WM_INITMENULOOP ": "",
3168 !gflag_initmenu ? "WM_INITMENU": "");
3169 /* and another */
3170 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest");
3171 ok( ret, "AppendMenA has failed!\n");
3172 SetLastError(0xdeadbeef);
3173 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
3174 ret = MyTrackPopupMenu( Ex, hmenu, TPM_RETURNCMD, 100,100, hwnd, NULL);
3175 gle = GetLastError();
3176 ok( ret == 0, "TrackPopupMenu%s returned %d expected zero\n", Ex ? "Ex" : "", ret);
3177 ok( gle == NO_ERROR
3178 || gle == ERROR_INVALID_MENU_HANDLE /* NT4, win2k and Vista in the TrackPopupMenuEx case */
3179 || broken (gle == 0xdeadbeef) /* win95 */
3180 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
3181 Ex ? "Ex" : "", gle, NO_ERROR, ERROR_INVALID_MENU_HANDLE);
3182 ok( gflag_initmenupopup && gflag_entermenuloop && gflag_initmenu,
3183 "missed expected message(s)%s%s%s\n",
3184 !gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
3185 !gflag_entermenuloop ? "WM_INITMENULOOP ": "",
3186 !gflag_initmenu ? "WM_INITMENU": "");
3187 DestroyMenu(hmenu);
3189 /* clean up */
3190 DestroyWindow(hwnd);
3193 static HMENU g_hmenu;
3195 static LRESULT WINAPI menu_track_again_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3197 switch (msg)
3199 case WM_ENTERMENULOOP:
3201 BOOL ret;
3203 /* try a recursive call */
3204 SetLastError(0xdeadbeef);
3205 ret = TrackPopupMenu(g_hmenu, 0, 100, 100, 0, hwnd, NULL);
3206 ok(ret == FALSE, "got %d\n", ret);
3207 ok(GetLastError() == ERROR_POPUP_ALREADY_ACTIVE ||
3208 broken(GetLastError() == 0xdeadbeef) /* W9x */, "got %d\n", GetLastError());
3210 /* exit menu modal loop
3211 * ( A SendMessage does not work on NT3.51 here ) */
3212 return PostMessage(hwnd, WM_CANCELMODE, 0, 0);
3215 return DefWindowProc(hwnd, msg, wparam, lparam);
3218 static void test_menu_trackagain(void)
3220 HWND hwnd;
3221 BOOL ret;
3223 hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
3224 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
3225 NULL, NULL, NULL, NULL);
3226 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
3227 if (!hwnd) return;
3228 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_track_again_wnd_proc);
3230 g_hmenu = CreatePopupMenu();
3231 ok(g_hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
3233 ret = TrackPopupMenu( g_hmenu, 0, 100, 100, 0, hwnd, NULL);
3234 todo_wine ok(ret == FALSE, "got %d\n", ret);
3236 DestroyMenu(g_hmenu);
3237 DestroyWindow(hwnd);
3240 /* test handling of WM_CANCELMODE messages */
3241 static int g_got_enteridle;
3242 static HWND g_hwndtosend;
3243 static LRESULT WINAPI menu_cancelmode_wnd_proc(HWND hwnd, UINT msg,
3244 WPARAM wparam, LPARAM lparam)
3246 switch (msg)
3248 case WM_ENTERMENULOOP:
3249 g_got_enteridle = 0;
3250 return SendMessage( g_hwndtosend, WM_CANCELMODE, 0, 0);
3251 case WM_ENTERIDLE:
3253 if( g_got_enteridle++ == 0) {
3254 /* little hack to get another WM_ENTERIDLE message */
3255 PostMessage( hwnd, WM_MOUSEMOVE, 0, 0);
3256 return SendMessage( g_hwndtosend, WM_CANCELMODE, 0, 0);
3258 pEndMenu();
3259 return TRUE;
3262 return DefWindowProc( hwnd, msg, wparam, lparam);
3265 static void test_menu_cancelmode(void)
3267 DWORD ret;
3268 HWND hwnd, hwndchild;
3269 HMENU menu;
3270 if( !pEndMenu) { /* win95 */
3271 win_skip( "EndMenu is not available\n");
3272 return;
3274 hwnd = CreateWindowEx( 0, MAKEINTATOM(atomMenuCheckClass), NULL,
3275 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
3276 NULL, NULL, NULL, NULL);
3277 hwndchild = CreateWindowEx( 0, MAKEINTATOM(atomMenuCheckClass), NULL,
3278 WS_VISIBLE | WS_CHILD, 10, 10, 20, 20,
3279 hwnd, NULL, NULL, NULL);
3280 ok( hwnd != NULL && hwndchild != NULL,
3281 "CreateWindowEx failed with error %d\n", GetLastError());
3282 g_hwndtosend = hwnd;
3283 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_cancelmode_wnd_proc);
3284 SetWindowLongPtr( hwndchild, GWLP_WNDPROC, (LONG_PTR)menu_cancelmode_wnd_proc);
3285 menu = CreatePopupMenu();
3286 ok( menu != NULL, "CreatePopupMenu failed with error %d\n", GetLastError());
3287 ret = AppendMenuA( menu, MF_STRING, 1, "winetest");
3288 ok( ret, "Functie failed lasterror is %u\n", GetLastError());
3289 /* seems to be needed only on wine :( */
3290 {MSG msg; while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);}
3291 /* test the effect of sending a WM_CANCELMODE message in the WM_INITMENULOOP
3292 * handler of the menu owner */
3293 /* test results is extracted from variable g_got_enteridle. Possible values:
3294 * 0 : complete conformance. Sending WM_CANCELMODE cancels a menu initializing tracking
3295 * 1 : Sending WM_CANCELMODE cancels a menu that is in tracking state
3296 * 2 : Sending WM_CANCELMODE does not work
3298 /* menu owner is top level window */
3299 g_hwndtosend = hwnd;
3300 TrackPopupMenu( menu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
3301 todo_wine {
3302 ok( g_got_enteridle == 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle);
3304 ok( g_got_enteridle < 2, "received %d WM_ENTERIDLE messages, should be less than 2\n", g_got_enteridle);
3305 /* menu owner is child window */
3306 g_hwndtosend = hwndchild;
3307 TrackPopupMenu( menu, TPM_RETURNCMD, 100,100, 0, hwndchild, NULL);
3308 todo_wine {
3309 ok(g_got_enteridle == 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle);
3311 ok(g_got_enteridle < 2, "received %d WM_ENTERIDLE messages, should be less than 2\n", g_got_enteridle);
3312 /* now send the WM_CANCELMODE messages to the WRONG window */
3313 /* those should fail ( to have any effect) */
3314 g_hwndtosend = hwnd;
3315 TrackPopupMenu( menu, TPM_RETURNCMD, 100,100, 0, hwndchild, NULL);
3316 ok( g_got_enteridle == 2, "received %d WM_ENTERIDLE messages, should be 2\n", g_got_enteridle);
3317 /* cleanup */
3318 DestroyMenu( menu);
3319 DestroyWindow( hwndchild);
3320 DestroyWindow( hwnd);
3323 /* show menu trees have a maximum depth */
3324 static void test_menu_maxdepth(void)
3326 #define NR_MENUS 100
3327 HMENU hmenus[ NR_MENUS];
3328 int i;
3329 DWORD ret;
3331 SetLastError(12345678);
3332 for( i = 0; i < NR_MENUS; i++) {
3333 hmenus[i] = CreatePopupMenu();
3334 if( !hmenus[i]) break;
3336 ok( i == NR_MENUS, "could not create more than %d menu's\n", i);
3337 for( i = 1; i < NR_MENUS; i++) {
3338 ret = AppendMenuA( hmenus[i], MF_POPUP, (UINT_PTR)hmenus[i-1],"test");
3339 if( !ret) break;
3341 trace("Maximum depth is %d\n", i);
3342 ok( GetLastError() == 12345678, "unexpected error %d\n", GetLastError());
3343 ok( i < NR_MENUS ||
3344 broken( i == NR_MENUS), /* win98, NT */
3345 "no ( or very large) limit on menu depth!\n");
3347 for( i = 0; i < NR_MENUS; i++)
3348 DestroyMenu( hmenus[i]);
3351 /* bug #12171 */
3352 static void test_menu_circref(void)
3354 HMENU menu1, menu2;
3355 DWORD ret;
3357 menu1 = CreatePopupMenu();
3358 menu2 = CreatePopupMenu();
3359 ok( menu1 && menu2, "error creating menus.\n");
3360 ret = AppendMenuA( menu1, MF_POPUP, (UINT_PTR)menu2, "winetest");
3361 ok( ret, "AppendMenu failed, error is %d\n", GetLastError());
3362 ret = AppendMenuA( menu1, MF_STRING | MF_HILITE, 123, "winetest");
3363 ok( ret, "AppendMenu failed, error is %d\n", GetLastError());
3364 /* app chooses an id that happens to clash with its own hmenu */
3365 ret = AppendMenuA( menu2, MF_STRING, (UINT_PTR)menu2, "winetest");
3366 ok( ret, "AppendMenu failed, error is %d\n", GetLastError());
3367 /* now attempt to change the string of the first item of menu1 */
3368 ret = ModifyMenuA( menu1, (UINT_PTR)menu2, MF_POPUP, (UINT_PTR)menu2, "menu 2");
3369 ok( !ret ||
3370 broken( ret), /* win98, NT */
3371 "ModifyMenu should have failed.\n");
3372 if( !ret) { /* will probably stack fault if the ModifyMenu succeeded */
3373 ret = GetMenuState( menu1, 123, 0);
3374 ok( ret == MF_HILITE, "GetMenuState returned %x\n",ret);
3376 DestroyMenu( menu2);
3377 DestroyMenu( menu1);
3380 /* test how the menu texts are aligned when the menu items have
3381 * different combinations of text and bitmaps (bug #13350) */
3382 static void test_menualign(void)
3384 BYTE bmfill[300];
3385 HMENU menu;
3386 HBITMAP hbm1, hbm2, hbm3;
3387 MENUITEMINFO mii = { sizeof(MENUITEMINFO)};
3388 DWORD ret;
3389 HWND hwnd;
3390 MENUINFO mi = { sizeof( MENUINFO)};
3392 if( !winetest_interactive) {
3393 skip( "interactive alignment tests.\n");
3394 return;
3396 hwnd = CreateWindowEx(0,
3397 "STATIC",
3398 "Menu text alignment Test\nPlease make a selection.",
3399 WS_OVERLAPPEDWINDOW,
3400 100, 100,
3401 300, 300,
3402 NULL, NULL, 0, NULL);
3403 ShowWindow( hwnd, SW_SHOW);
3404 /* create bitmaps */
3405 memset( bmfill, 0xcc, sizeof( bmfill));
3406 hbm1 = CreateBitmap( 10,10,1,1,bmfill);
3407 hbm2 = CreateBitmap( 20,20,1,1,bmfill);
3408 hbm3 = CreateBitmap( 50,6,1,1,bmfill);
3409 ok( hbm1 && hbm2 && hbm3, "Creating bitmaps failed\n");
3410 menu = CreatePopupMenu();
3411 ok( menu != NULL, "CreatePopupMenu() failed\n");
3412 if( pGetMenuInfo) {
3413 mi.fMask = MIM_STYLE;
3414 ret = pGetMenuInfo( menu, &mi);
3415 ok( ret, "GetMenuInfo failed: %d\n", GetLastError());
3416 ok( menu != NULL, "GetMenuInfo() failed\n");
3417 ok( 0 == mi.dwStyle, "menuinfo style is %x\n", mi.dwStyle);
3419 /* test 1 */
3420 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3421 mii.wID = 1;
3422 mii.hbmpItem = hbm1;
3423 mii.dwTypeData = (LPSTR) " OK: menu texts are correctly left-aligned.";
3424 ret = InsertMenuItem( menu, -1, TRUE, &mii);
3425 ok( ret, "InsertMenuItem() failed\n");
3426 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID ;
3427 mii.wID = 2;
3428 mii.hbmpItem = hbm2;
3429 mii.dwTypeData = (LPSTR) " FAIL: menu texts are NOT left-aligned.";
3430 ret = InsertMenuItem( menu, -1, TRUE, &mii);
3431 ok( ret, "InsertMenuItem() failed\n");
3432 ret = TrackPopupMenu( menu, TPM_RETURNCMD, 110, 200, 0, hwnd, NULL);
3433 ok( ret != 2, "User indicated that menu text alignment test 1 failed %d\n", ret);
3434 /* test 2*/
3435 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3436 mii.wID = 3;
3437 mii.hbmpItem = hbm3;
3438 mii.dwTypeData = NULL;
3439 ret = InsertMenuItem( menu, 0, TRUE, &mii);
3440 ok( ret, "InsertMenuItem() failed\n");
3441 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3442 mii.wID = 1;
3443 mii.hbmpItem = hbm1;
3444 /* make the text a bit longer, to keep it readable */
3445 /* this bug is on winXP and reproduced on wine */
3446 mii.dwTypeData = (LPSTR) " OK: menu texts are to the right of the bitmaps........";
3447 ret = SetMenuItemInfo( menu, 1, TRUE, &mii);
3448 ok( ret, "SetMenuItemInfo() failed\n");
3449 mii.wID = 2;
3450 mii.hbmpItem = hbm2;
3451 mii.dwTypeData = (LPSTR) " FAIL: menu texts are below the first bitmap. ";
3452 ret = SetMenuItemInfo( menu, 2, TRUE, &mii);
3453 ok( ret, "SetMenuItemInfo() failed\n");
3454 ret = TrackPopupMenu( menu, TPM_RETURNCMD, 110, 200, 0, hwnd, NULL);
3455 ok( ret != 2, "User indicated that menu text alignment test 2 failed %d\n", ret);
3456 /* test 3 */
3457 mii.fMask = MIIM_TYPE | MIIM_ID;
3458 mii.wID = 3;
3459 mii.fType = MFT_BITMAP;
3460 mii.dwTypeData = (LPSTR) hbm3;
3461 ret = SetMenuItemInfo( menu, 0, TRUE, &mii);
3462 ok( ret, "SetMenuItemInfo() failed\n");
3463 mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3464 mii.wID = 1;
3465 mii.hbmpItem = NULL;
3466 mii.dwTypeData = (LPSTR) " OK: menu texts are below the bitmap.";
3467 ret = SetMenuItemInfo( menu, 1, TRUE, &mii);
3468 ok( ret, "SetMenuItemInfo() failed\n");
3469 mii.wID = 2;
3470 mii.hbmpItem = NULL;
3471 mii.dwTypeData = (LPSTR) " FAIL: menu texts are NOT below the bitmap.";
3472 ret = SetMenuItemInfo( menu, 2, TRUE, &mii);
3473 ok( ret, "SetMenuItemInfo() failed\n");
3474 ret = TrackPopupMenu( menu, TPM_RETURNCMD, 110, 200, 0, hwnd, NULL);
3475 ok( ret != 2, "User indicated that menu text alignment test 3 failed %d\n", ret);
3476 /* cleanup */
3477 DeleteObject( hbm1);
3478 DeleteObject( hbm2);
3479 DeleteObject( hbm3);
3480 DestroyMenu( menu);
3481 DestroyWindow( hwnd);
3484 START_TEST(menu)
3486 init_function_pointers();
3488 /* Wine defines MENUITEMINFO for W2K and above. NT4 and below can't
3489 * handle that.
3491 if (correct_behavior())
3493 test_menu_add_string();
3494 test_menu_iteminfo();
3495 test_menu_search_bycommand();
3496 test_CheckMenuRadioItem();
3497 test_menu_resource_layout();
3498 test_InsertMenu();
3499 test_menualign();
3502 register_menu_check_class();
3504 test_menu_locked_by_window();
3505 test_subpopup_locked_by_menu();
3506 test_menu_ownerdraw();
3507 test_getmenubarinfo();
3508 test_menu_bmp_and_string();
3509 test_menu_getmenuinfo();
3510 test_menu_setmenuinfo();
3511 test_menu_input();
3512 test_menu_flags();
3514 test_menu_hilitemenuitem();
3515 test_menu_trackpopupmenu();
3516 test_menu_trackagain();
3517 test_menu_cancelmode();
3518 test_menu_maxdepth();
3519 test_menu_circref();