[USER32_WINETEST]
[reactos.git] / rostests / winetests / user32 / menu.c
1 /*
2 * Unit tests for menus
3 *
4 * Copyright 2005 Robert Shearman
5 * Copyright 2007 Dmitry Timoshkov
6 *
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.
11 *
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.
16 *
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
20 */
21
22 //#define _WIN32_WINNT 0x0501
23
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <assert.h>
28
29 #define OEMRESOURCE /* For OBM_MNARROW */
30
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35
36 #include "wine/test.h"
37
38 static ATOM atomMenuCheckClass;
39
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);
45
46 static void init_function_pointers(void)
47 {
48 HMODULE hdll = GetModuleHandleA("user32");
49
50 #define GET_PROC(func) \
51 p ## func = (void*)GetProcAddress(hdll, #func); \
52 if(!p ## func) \
53 trace("GetProcAddress(%s) failed\n", #func);
54
55 GET_PROC(GetMenuInfo)
56 GET_PROC(GetMenuBarInfo)
57 GET_PROC(SendInput)
58 GET_PROC(SetMenuInfo)
59 GET_PROC(EndMenu)
60
61 #undef GET_PROC
62 }
63
64 static BOOL correct_behavior(void)
65 {
66 HMENU hmenu;
67 MENUITEMINFOA info;
68 BOOL rc;
69
70 hmenu = CreateMenu();
71
72 memset(&info, 0, sizeof(MENUITEMINFOA));
73 info.cbSize= sizeof(MENUITEMINFOA);
74 SetLastError(0xdeadbeef);
75 rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info);
76 /* Win9x : 0xdeadbeef
77 * NT4 : ERROR_INVALID_PARAMETER
78 * >= W2K : ERROR_MENU_ITEM_NOT_FOUND
79 */
80 if (!rc && GetLastError() != ERROR_MENU_ITEM_NOT_FOUND)
81 {
82 win_skip("NT4 and below can't handle a bigger MENUITEMINFO struct\n");
83 DestroyMenu(hmenu);
84 return FALSE;
85 }
86
87 DestroyMenu(hmenu);
88 return TRUE;
89 }
90
91 static LRESULT WINAPI menu_check_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
92 {
93 switch (msg)
94 {
95 case WM_ENTERMENULOOP:
96 /* mark window as having entered menu loop */
97 SetWindowLongPtrA(hwnd, GWLP_USERDATA, TRUE);
98 /* exit menu modal loop
99 * ( A SendMessage does not work on NT3.51 here ) */
100 return PostMessageA(hwnd, WM_CANCELMODE, 0, 0);
101 }
102 return DefWindowProcA(hwnd, msg, wparam, lparam);
103 }
104
105 /* The MSVC headers ignore our NONAMELESSUNION requests so we have to define
106 * our own type */
107 typedef struct
108 {
109 DWORD type;
110 union
111 {
112 MOUSEINPUT mi;
113 KEYBDINPUT ki;
114 HARDWAREINPUT hi;
115 } u;
116 } TEST_INPUT;
117
118 /* globals to communicate between test and wndproc */
119
120 static BOOL bMenuVisible;
121 static INT popmenu;
122 static BOOL got_input;
123 static HMENU hMenus[4];
124
125 #define MOD_SIZE 10
126 #define MOD_NRMENUS 8
127
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 }
139 };
140
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 BOOL MOD_GotDrawItemMsg = FALSE;
148 static int gflag_initmenupopup,
149 gflag_entermenuloop,
150 gflag_initmenu,
151 gflag_enteridle;
152 static WPARAM selectitem_wp;
153 static LPARAM selectitem_lp;
154
155 /* wndproc used by test_menu_ownerdraw() */
156 static LRESULT WINAPI menu_ownerdraw_wnd_proc(HWND hwnd, UINT msg,
157 WPARAM wparam, LPARAM lparam)
158 {
159 static HMENU hmenupopup;
160 switch (msg)
161 {
162 case WM_INITMENUPOPUP:
163 gflag_initmenupopup++;
164 hmenupopup = (HMENU) wparam;
165 break;
166 case WM_ENTERMENULOOP:
167 gflag_entermenuloop++;
168 break;
169 case WM_INITMENU:
170 gflag_initmenu++;
171 break;
172 case WM_MEASUREITEM:
173 {
174 MEASUREITEMSTRUCT* pmis = (MEASUREITEMSTRUCT*)lparam;
175 if (winetest_debug > 1)
176 trace("WM_MEASUREITEM received data %lx size %dx%d\n",
177 pmis->itemData, pmis->itemWidth, pmis->itemHeight);
178 ok( !wparam, "wrong wparam %lx\n", wparam );
179 ok( pmis->CtlType == ODT_MENU, "wrong type %x\n", pmis->CtlType );
180 MOD_odheight = pmis->itemHeight;
181 pmis->itemWidth = MODsizes[pmis->itemData].cx;
182 pmis->itemHeight = MODsizes[pmis->itemData].cy;
183 return TRUE;
184 }
185 case WM_DRAWITEM:
186 {
187 DRAWITEMSTRUCT * pdis;
188 TEXTMETRICA tm;
189 HPEN oldpen;
190 char chrs[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
191 SIZE sz;
192 int i;
193 pdis = (DRAWITEMSTRUCT *) lparam;
194 if (winetest_debug > 1) {
195 RECT rc;
196 GetMenuItemRect( hwnd, (HMENU)pdis->hwndItem, pdis->itemData ,&rc);
197 trace("WM_DRAWITEM received hwnd %p hmenu %p itemdata %ld item %d rc %d,%d-%d,%d itemrc: %d,%d-%d,%d\n",
198 hwnd, pdis->hwndItem, pdis->itemData, pdis->itemID,
199 pdis->rcItem.left, pdis->rcItem.top,
200 pdis->rcItem.right,pdis->rcItem.bottom,
201 rc.left,rc.top,rc.right,rc.bottom);
202 oldpen=SelectObject( pdis->hDC, GetStockObject(
203 pdis->itemState & ODS_SELECTED ? WHITE_PEN :BLACK_PEN));
204 Rectangle( pdis->hDC, pdis->rcItem.left,pdis->rcItem.top,
205 pdis->rcItem.right,pdis->rcItem.bottom );
206 SelectObject( pdis->hDC, oldpen);
207 }
208 ok( !wparam, "wrong wparam %lx\n", wparam );
209 ok( pdis->CtlType == ODT_MENU, "wrong type %x\n", pdis->CtlType );
210 /* calculate widths of some menu texts */
211 if( ! MOD_txtsizes[0].size.cx)
212 for(i = 0; MOD_txtsizes[i].text; i++) {
213 char buf[100], *p;
214 RECT rc={0,0,0,0};
215 strcpy( buf, MOD_txtsizes[i].text);
216 if( ( p = strchr( buf, '\t'))) {
217 *p = '\0';
218 DrawTextA( pdis->hDC, p + 1, -1, &rc,
219 DT_SINGLELINE|DT_CALCRECT);
220 MOD_txtsizes[i].sc_size.cx= rc.right - rc.left;
221 MOD_txtsizes[i].sc_size.cy= rc.bottom - rc.top;
222 }
223 DrawTextA( pdis->hDC, buf, -1, &rc,
224 DT_SINGLELINE|DT_CALCRECT);
225 MOD_txtsizes[i].size.cx= rc.right - rc.left;
226 MOD_txtsizes[i].size.cy= rc.bottom - rc.top;
227 }
228
229 if( pdis->itemData > MOD_maxid) return TRUE;
230 /* store the rectangle */
231 MOD_rc[pdis->itemData] = pdis->rcItem;
232 /* calculate average character width */
233 GetTextExtentPointA( pdis->hDC, chrs, 52, &sz );
234 MOD_avec = (sz.cx + 26)/52;
235 GetTextMetricsA( pdis->hDC, &tm);
236 MOD_hic = tm.tmHeight;
237 MOD_GotDrawItemMsg = TRUE;
238 return TRUE;
239 }
240 case WM_ENTERIDLE:
241 {
242 gflag_enteridle++;
243 ok( lparam || broken(!lparam), /* win9x, nt4 */
244 "Menu window handle is NULL!\n");
245 if( lparam) {
246 HMENU hmenu = (HMENU)SendMessageA( (HWND)lparam, MN_GETHMENU, 0, 0);
247 ok( hmenupopup == hmenu, "MN_GETHMENU returns %p expected %p\n",
248 hmenu, hmenupopup);
249 }
250 PostMessageA(hwnd, WM_CANCELMODE, 0, 0);
251 return TRUE;
252 }
253 case WM_MENUSELECT:
254 selectitem_wp = wparam;
255 selectitem_lp = lparam;
256 break;
257 }
258 return DefWindowProcA(hwnd, msg, wparam, lparam);
259 }
260
261 static void register_menu_check_class(void)
262 {
263 WNDCLASSA wc =
264 {
265 0,
266 menu_check_wnd_proc,
267 0,
268 0,
269 GetModuleHandleA(NULL),
270 NULL,
271 LoadCursorA(NULL, (LPCSTR)IDC_ARROW),
272 (HBRUSH)(COLOR_BTNFACE+1),
273 NULL,
274 "WineMenuCheck",
275 };
276
277 atomMenuCheckClass = RegisterClassA(&wc);
278 }
279
280 static void test_getmenubarinfo(void)
281 {
282 BOOL ret;
283 HMENU hmenu;
284 MENUBARINFO mbi;
285 RECT rcw, rci;
286 HWND hwnd;
287 INT err;
288
289 if (!pGetMenuBarInfo) {
290 win_skip("GetMenuBarInfo is not available\n");
291 return;
292 }
293
294 mbi.cbSize = sizeof(MENUBARINFO);
295
296 hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
297 WS_SYSMENU | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
298 NULL, NULL, NULL, NULL);
299 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
300
301 /* no menu: getmenubarinfo should fail */
302 SetLastError(0xdeadbeef);
303 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
304 err = GetLastError();
305 ok(ret == FALSE, "GetMenuBarInfo should not have been successful\n");
306 ok(err == 0xdeadbeef, "err = %d\n", err);
307
308 /* create menubar, no items yet */
309 hmenu = CreateMenu();
310 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
311
312 ret = SetMenu(hwnd, hmenu);
313 ok(ret, "SetMenu failed with error %d\n", GetLastError());
314
315 SetLastError(0xdeadbeef);
316 ret = pGetMenuBarInfo(NULL, OBJID_CLIENT, 0, &mbi);
317 err = GetLastError();
318 ok(!ret, "GetMenuBarInfo succeeded\n");
319 ok(err == ERROR_INVALID_WINDOW_HANDLE, "err = %d\n", err);
320
321 SetLastError(0xdeadbeef);
322 ret = pGetMenuBarInfo(hwnd, OBJID_CLIENT, 0, &mbi);
323 err = GetLastError();
324 ok(!ret, "GetMenuBarInfo succeeded\n");
325 ok(err==ERROR_INVALID_MENU_HANDLE || broken(err==0xdeadbeef) /* NT, W2K, XP */, "err = %d\n", err);
326
327 SetLastError(0xdeadbeef);
328 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, -1, &mbi);
329 err = GetLastError();
330 ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
331 ok(err == 0xdeadbeef, "err = %d\n", err);
332
333 mbi.cbSize = 1000;
334 SetLastError(0xdeadbeef);
335 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
336 err = GetLastError();
337 ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
338 ok(err == ERROR_INVALID_PARAMETER, "err = %d\n", err);
339 mbi.cbSize = sizeof(MENUBARINFO);
340
341 SetLastError(0xdeadbeef);
342 ret = pGetMenuBarInfo(hwnd, 123, 0, &mbi);
343 err = GetLastError();
344 ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
345 ok(err == 0xdeadbeef, "err = %d\n", err);
346
347 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
348 ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
349
350 ok(mbi.rcBar.left == 0 && mbi.rcBar.top == 0 &&
351 mbi.rcBar.bottom == 0 && mbi.rcBar.right == 0,
352 "rcBar: Expected 0,0-0,0, got: %d,%d-%d,%d\n",
353 mbi.rcBar.left, mbi.rcBar.top, mbi.rcBar.right, mbi.rcBar.bottom);
354 ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n",
355 mbi.hMenu, hmenu);
356 ok(mbi.fBarFocused == 0, "fBarFocused: Got %d instead of 0.\n", mbi.fBarFocused);
357 ok(mbi.fFocused == 0, "fFocused: Got %d instead of 0.\n", mbi.fFocused);
358
359 /* add some items */
360 ret = AppendMenuA(hmenu, MF_STRING , 100, "item 1");
361 ok(ret, "AppendMenu failed.\n");
362 ret = AppendMenuA(hmenu, MF_STRING , 101, "item 2");
363 ok(ret, "AppendMenu failed.\n");
364 ret = SetMenu(hwnd, hmenu);
365 ok(ret, "SetMenu failed with error %d\n", GetLastError());
366
367 SetLastError(0xdeadbeef);
368 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 200, &mbi);
369 err = GetLastError();
370 ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
371 ok(err == 0xdeadbeef, "err = %d\n", err);
372
373 /* get info for the whole menu */
374 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
375 ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
376
377 /* calculate menu rectangle, from window rectangle and the position of the first item */
378 ret = GetWindowRect(hwnd, &rcw);
379 ok(ret, "GetWindowRect failed.\n");
380 ret = GetMenuItemRect(hwnd, hmenu, 0, &rci);
381 ok(ret, "GetMenuItemRect failed.\n");
382 todo_wine ok(mbi.rcBar.left == rci.left && mbi.rcBar.top == rci.top &&
383 mbi.rcBar.bottom == rci.bottom && mbi.rcBar.right == rcw.right - rci.left + rcw.left,
384 "rcBar: Got %d,%d-%d,%d instead of %d,%d-%d,%d\n",
385 mbi.rcBar.left, mbi.rcBar.top, mbi.rcBar.right, mbi.rcBar.bottom,
386 rci.left, rci.top, rcw.right - rci.left + rcw.left, rci.bottom);
387 ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n", mbi.hMenu, hmenu);
388 ok(mbi.fBarFocused == 0, "fBarFocused: got %d instead of 0\n", mbi.fBarFocused);
389 ok(mbi.fFocused == 0, "fFocused: got %d instead of 0\n", mbi.fFocused);
390
391 /* get info for item nr.2 */
392 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 2, &mbi);
393 ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
394 ret = GetMenuItemRect(hwnd, hmenu, 1, &rci);
395 ok(ret, "GetMenuItemRect failed.\n");
396 ok(mbi.rcBar.left == rci.left && mbi.rcBar.top == rci.top &&
397 mbi.rcBar.bottom == rci.bottom && mbi.rcBar.right == rci.right,
398 "rcBar: Got %d,%d-%d,%d instead of %d,%d-%d,%d\n",
399 mbi.rcBar.left, mbi.rcBar.top, mbi.rcBar.right, mbi.rcBar.bottom,
400 rci.left, rci.top, rci.right, rci.bottom);
401 ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n", mbi.hMenu, hmenu);
402 ok(mbi.fBarFocused == 0, "fBarFocused: got %d instead of 0\n", mbi.fBarFocused);
403 ok(mbi.fFocused == 0, "fFocused: got %d instead of 0\n", mbi.fFocused);
404
405 DestroyWindow(hwnd);
406 }
407
408 /* demonstrates that windows locks the menu object so that it is still valid
409 * even after a client calls DestroyMenu on it */
410 static void test_menu_locked_by_window(void)
411 {
412 BOOL ret;
413 HMENU hmenu;
414 HWND hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
415 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
416 NULL, NULL, NULL, NULL);
417 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
418 hmenu = CreateMenu();
419 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
420 ret = InsertMenuA(hmenu, 0, MF_STRING, 0, "&Test");
421 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
422 ret = SetMenu(hwnd, hmenu);
423 ok(ret, "SetMenu failed with error %d\n", GetLastError());
424 ret = DestroyMenu(hmenu);
425 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
426
427 ret = DrawMenuBar(hwnd);
428 ok(ret, "DrawMenuBar failed with error %d\n", GetLastError());
429 ret = IsMenu(GetMenu(hwnd));
430 ok(!ret || broken(ret) /* nt4 */, "Menu handle should have been destroyed\n");
431
432 SendMessageA(hwnd, WM_SYSCOMMAND, SC_KEYMENU, 0);
433 /* did we process the WM_INITMENU message? */
434 ret = GetWindowLongPtrA(hwnd, GWLP_USERDATA);
435 todo_wine {
436 ok(ret, "WM_INITMENU should have been sent\n");
437 }
438
439 DestroyWindow(hwnd);
440 }
441
442 /* demonstrates that subpopup's are locked
443 * even after a client calls DestroyMenu on it */
444 static LRESULT WINAPI subpopuplocked_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
445 {
446 HWND hwndmenu;
447 switch (msg)
448 {
449 case WM_ENTERIDLE:
450 hwndmenu = GetCapture();
451 if( hwndmenu) {
452 PostMessageA( hwndmenu, WM_KEYDOWN, VK_DOWN, 0);
453 PostMessageA( hwndmenu, WM_KEYDOWN, VK_RIGHT, 0);
454 PostMessageA( hwndmenu, WM_KEYDOWN, VK_RETURN, 0);
455 }
456 }
457 return DefWindowProcA(hwnd, msg, wparam, lparam);
458 }
459
460 static void test_subpopup_locked_by_menu(void)
461 {
462 DWORD gle;
463 BOOL ret;
464 HMENU hmenu, hsubmenu;
465 MENUINFO mi = { sizeof( MENUINFO)};
466 MENUITEMINFOA mii = { sizeof( MENUITEMINFOA)};
467 HWND hwnd;
468 const int itemid = 0x1234567;
469 if( !pGetMenuInfo)
470 {
471 win_skip("GetMenuInfo is not available\n");
472 return;
473 }
474 /* create window, popupmenu with one subpopup */
475 hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
476 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
477 NULL, NULL, NULL, NULL);
478 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
479 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR) subpopuplocked_wnd_proc);
480 hmenu = CreatePopupMenu();
481 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
482 hsubmenu = CreatePopupMenu();
483 ok(hsubmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
484 ret = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hsubmenu,
485 "PopUpLockTest");
486 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
487 ret = InsertMenuA(hsubmenu, 0, MF_BYPOSITION | MF_STRING, itemid, "PopUpMenu");
488 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
489 /* first some tests that all this functions properly */
490 mii.fMask = MIIM_SUBMENU;
491 ret = GetMenuItemInfoA( hmenu, 0, TRUE, &mii);
492 ok( ret, "GetMenuItemInfo failed error %d\n", GetLastError());
493 ok( mii.hSubMenu == hsubmenu, "submenu is %p\n", mii.hSubMenu);
494 mi.fMask |= MIM_STYLE;
495 ret = pGetMenuInfo( hsubmenu, &mi);
496 ok( ret , "GetMenuInfo returned 0 with error %d\n", GetLastError());
497 ret = IsMenu( hsubmenu);
498 ok( ret , "Menu handle is not valid\n");
499 SetLastError( 0xdeadbeef);
500 ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
501 if( ret == (itemid & 0xffff)) {
502 win_skip("not on 16 bit menu subsystem\n");
503 DestroyMenu( hsubmenu);
504 } else {
505 gle = GetLastError();
506 ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, gle);
507 ok( gle == 0 ||
508 broken( gle == 0xdeadbeef), /* win2k0 */
509 "Last error is %d\n", gle);
510 /* then destroy the sub-popup */
511 ret = DestroyMenu( hsubmenu);
512 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
513 /* and repeat the tests */
514 mii.fMask = MIIM_SUBMENU;
515 ret = GetMenuItemInfoA( hmenu, 0, TRUE, &mii);
516 ok( ret, "GetMenuItemInfo failed error %d\n", GetLastError());
517 /* GetMenuInfo fails now */
518 ok( mii.hSubMenu == hsubmenu, "submenu is %p\n", mii.hSubMenu);
519 mi.fMask |= MIM_STYLE;
520 ret = pGetMenuInfo( hsubmenu, &mi);
521 ok( !ret , "GetMenuInfo should have failed\n");
522 /* IsMenu says it is not */
523 ret = IsMenu( hsubmenu);
524 ok( !ret , "Menu handle should be invalid\n");
525 /* but TrackPopupMenu still works! */
526 SetLastError( 0xdeadbeef);
527 ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
528 gle = GetLastError();
529 todo_wine {
530 ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, gle);
531 }
532 ok( gle == 0 ||
533 broken(gle == 0xdeadbeef) || /* wow64 */
534 broken(gle == ERROR_INVALID_PARAMETER), /* win2k0 */
535 "Last error is %d\n", gle);
536 }
537 /* clean up */
538 DestroyMenu( hmenu);
539 DestroyWindow(hwnd);
540 }
541
542 static void test_menu_ownerdraw(void)
543 {
544 int i,j,k;
545 BOOL ret;
546 HMENU hmenu;
547 MENUITEMINFOA mii;
548 LONG leftcol;
549 HWND hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
550 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
551 NULL, NULL, NULL, NULL);
552 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
553 if( !hwnd) return;
554 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
555 hmenu = CreatePopupMenu();
556 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
557 if( !hmenu) { DestroyWindow(hwnd);return;}
558 k=0;
559 for( j=0;j<2;j++) /* create columns */
560 for(i=0;i<2;i++) { /* create rows */
561 ret = AppendMenuA( hmenu, MF_OWNERDRAW |
562 (i==0 ? MF_MENUBREAK : 0), k, (LPCSTR)MAKEINTRESOURCE(k));
563 k++;
564 ok( ret, "AppendMenu failed for %d\n", k-1);
565 }
566 MOD_maxid = k-1;
567 assert( k <= sizeof(MOD_rc)/sizeof(RECT));
568 /* display the menu */
569 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
570
571 /* columns have a 4 pixel gap between them */
572 ok( MOD_rc[0].right + 4 == MOD_rc[2].left,
573 "item rectangles are not separated by 4 pixels space\n");
574 /* height should be what the MEASUREITEM message has returned */
575 ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
576 "menu item has wrong height: %d should be %d\n",
577 MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
578 /* no gaps between the rows */
579 ok( MOD_rc[0].bottom - MOD_rc[1].top == 0,
580 "There should not be a space between the rows, gap is %d\n",
581 MOD_rc[0].bottom - MOD_rc[1].top);
582 /* test the correct value of the item height that was sent
583 * by the WM_MEASUREITEM message */
584 ok( MOD_odheight == HIWORD( GetDialogBaseUnits()) || /* WinNT,2k,XP */
585 MOD_odheight == MOD_hic, /* Win95,98,ME */
586 "Wrong height field in MEASUREITEMSTRUCT, expected %d or %d actual %d\n",
587 HIWORD( GetDialogBaseUnits()), MOD_hic, MOD_odheight);
588 /* test what MF_MENUBREAK did at the first position. Also show
589 * that an MF_SEPARATOR is ignored in the height calculation. */
590 leftcol= MOD_rc[0].left;
591 ModifyMenuA( hmenu, 0, MF_BYCOMMAND| MF_OWNERDRAW| MF_SEPARATOR, 0, 0);
592 /* display the menu */
593 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
594 /* left should be 4 pixels less now */
595 ok( leftcol == MOD_rc[0].left + 4,
596 "columns should be 4 pixels to the left (actual %d).\n",
597 leftcol - MOD_rc[0].left);
598 /* test width */
599 ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
600 "width of owner drawn menu item is wrong. Got %d expected %d\n",
601 MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
602 /* and height */
603 ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
604 "Height is incorrect. Got %d expected %d\n",
605 MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
606
607 /* test owner-drawn callback bitmap */
608 ModifyMenuA( hmenu, 1, MF_BYPOSITION | MFT_BITMAP, 1, (LPCSTR)HBMMENU_CALLBACK );
609 mii.cbSize = sizeof(mii);
610 mii.fMask = MIIM_BITMAP | MIIM_FTYPE | MIIM_ID;
611 if (GetMenuItemInfoA( hmenu, 1, TRUE, &mii ))
612 {
613 ok( mii.fType == MFT_BITMAP, "wrong type %x\n", mii.fType );
614 ok( mii.wID == 1, "wrong id %x\n", mii.wID );
615 ok( mii.hbmpItem == HBMMENU_CALLBACK, "wrong data %p\n", mii.hbmpItem );
616 }
617 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
618
619 /* test width/height of an ownerdraw menu bar as well */
620 ret = DestroyMenu(hmenu);
621 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
622 hmenu = CreateMenu();
623 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
624 if( !hmenu) { DestroyWindow(hwnd);return;}
625 MOD_maxid=1;
626 for(i=0;i<2;i++) {
627 ret = AppendMenuA( hmenu, MF_OWNERDRAW, i, 0 );
628 ok( ret, "AppendMenu failed for %d\n", i);
629 }
630 ret = SetMenu( hwnd, hmenu);
631 UpdateWindow( hwnd); /* hack for wine to draw the window + menu */
632 ok(ret, "SetMenu failed with error %d\n", GetLastError());
633 /* test width */
634 ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
635 "width of owner drawn menu item is wrong. Got %d expected %d\n",
636 MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
637 /* test hight */
638 ok( MOD_rc[0].bottom - MOD_rc[0].top == GetSystemMetrics( SM_CYMENU) - 1,
639 "Height of owner drawn menu item is wrong. Got %d expected %d\n",
640 MOD_rc[0].bottom - MOD_rc[0].top, GetSystemMetrics( SM_CYMENU) - 1);
641
642 /* clean up */
643 ret = DestroyMenu(hmenu);
644 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
645 DestroyWindow(hwnd);
646 }
647
648 /* helper for test_menu_bmp_and_string() */
649 static void test_mbs_help( int ispop, int hassub, int mnuopt,
650 HWND hwnd, int arrowwidth, int count, HBITMAP hbmp,
651 SIZE bmpsize, LPCSTR text, SIZE size, SIZE sc_size)
652 {
653 BOOL ret;
654 HMENU hmenu, submenu;
655 MENUITEMINFOA mii={ sizeof( MENUITEMINFOA )};
656 MENUINFO mi;
657 RECT rc;
658 CHAR text_copy[16];
659 int hastab, expect;
660 BOOL failed = FALSE;
661
662 MOD_GotDrawItemMsg = FALSE;
663 mii.fMask = MIIM_FTYPE | MIIM_DATA | MIIM_STATE;
664 mii.fType = 0;
665 /* check the menu item unless MNS_CHECKORBMP is set */
666 mii.fState = (mnuopt != 2 ? MFS_CHECKED : MFS_UNCHECKED);
667 mii.dwItemData =0;
668 MODsizes[0] = bmpsize;
669 hastab = 0;
670 if( text ) {
671 char *p;
672 mii.fMask |= MIIM_STRING;
673 strcpy(text_copy, text);
674 mii.dwTypeData = text_copy; /* structure member declared non-const */
675 if( ( p = strchr( text, '\t'))) {
676 hastab = *(p + 1) ? 2 : 1;
677 }
678 }
679 /* tabs don't make sense in menubars */
680 if(hastab && !ispop) return;
681 if( hbmp) {
682 mii.fMask |= MIIM_BITMAP;
683 mii.hbmpItem = hbmp;
684 }
685 submenu = CreateMenu();
686 ok( submenu != 0, "CreateMenu failed with error %d\n", GetLastError());
687 if( ispop)
688 hmenu = CreatePopupMenu();
689 else
690 hmenu = CreateMenu();
691 ok( hmenu != 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
692 if( hassub) {
693 mii.fMask |= MIIM_SUBMENU;
694 mii.hSubMenu = submenu;
695 }
696 if( mnuopt) {
697 mi.cbSize = sizeof(mi);
698 mi.fMask = MIM_STYLE;
699 pGetMenuInfo( hmenu, &mi);
700 if( mnuopt) mi.dwStyle |= mnuopt == 1 ? MNS_NOCHECK : MNS_CHECKORBMP;
701 ret = pSetMenuInfo( hmenu, &mi);
702 ok( ret, "SetMenuInfo failed with error %d\n", GetLastError());
703 }
704 ret = InsertMenuItemA( hmenu, 0, FALSE, &mii);
705 ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
706 failed = !ret;
707 if( winetest_debug) {
708 HDC hdc=GetDC(hwnd);
709 RECT rc = {100, 50, 400, 70};
710 char buf[100];
711
712 sprintf( buf,"%d text \"%s\" mnuopt %d", count, text ? text: "(nil)", mnuopt);
713 FillRect( hdc, &rc, (HBRUSH) COLOR_WINDOW);
714 TextOutA( hdc, 10, 50, buf, strlen( buf));
715 ReleaseDC( hwnd, hdc);
716 }
717 if(ispop)
718 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
719 else {
720 ret = SetMenu( hwnd, hmenu);
721 ok(ret, "SetMenu failed with error %d\n", GetLastError());
722 DrawMenuBar( hwnd);
723 }
724 ret = GetMenuItemRect( hwnd, hmenu, 0, &rc);
725 ok(ret, "GetMenuItemRect failed with error %d\n", GetLastError());
726
727 if (0) /* comment out menu size checks, behavior is different in almost every Windows version */
728 /* the tests should however succeed on win2000, XP and Wine (at least up to 1.1.15) */
729 /* with a variety of dpis and desktop font sizes */
730 {
731 /* check menu width */
732 if( ispop)
733 expect = ( text || hbmp ?
734 4 + (mnuopt != 1 ? GetSystemMetrics(SM_CXMENUCHECK) : 0)
735 : 0) +
736 arrowwidth + MOD_avec + (hbmp ?
737 ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ? bmpsize.cx + 2 : GetSystemMetrics( SM_CXMENUSIZE) + 2)
738 : 0) +
739 (text && hastab ? /* TAB space */
740 MOD_avec + ( hastab==2 ? sc_size.cx : 0) : 0) +
741 (text ? 2 + (text[0] ? size.cx :0): 0) ;
742 else
743 expect = !(text || hbmp) ? 0 :
744 ( hbmp ? (text ? 2:0) + bmpsize.cx : 0 ) +
745 (text ? 2 * MOD_avec + (text[0] ? size.cx :0): 0) ;
746 ok( rc.right - rc.left == expect,
747 "menu width wrong, got %d expected %d\n", rc.right - rc.left, expect);
748 failed = failed || !(rc.right - rc.left == expect);
749 /* check menu height */
750 if( ispop)
751 expect = max( ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 : 0),
752 max( (text ? max( 2 + size.cy, MOD_hic + 4) : 0),
753 (hbmp ?
754 ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ?
755 bmpsize.cy + 2
756 : GetSystemMetrics( SM_CYMENUSIZE) + 2)
757 : 0)));
758 else
759 expect = ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 :
760 max( GetSystemMetrics( SM_CYMENU) - 1, (hbmp ? bmpsize.cy : 0)));
761 ok( rc.bottom - rc.top == expect,
762 "menu height wrong, got %d expected %d (%d)\n",
763 rc.bottom - rc.top, expect, GetSystemMetrics( SM_CYMENU));
764 failed = failed || !(rc.bottom - rc.top == expect);
765 if( hbmp == HBMMENU_CALLBACK && MOD_GotDrawItemMsg) {
766 /* check the position of the bitmap */
767 /* horizontal */
768 if (!ispop)
769 expect = 3;
770 else if (mnuopt == 0)
771 expect = 4 + GetSystemMetrics(SM_CXMENUCHECK);
772 else if (mnuopt == 1)
773 expect = 4;
774 else /* mnuopt == 2 */
775 expect = 2;
776 ok( expect == MOD_rc[0].left,
777 "bitmap left is %d expected %d\n", MOD_rc[0].left, expect);
778 failed = failed || !(expect == MOD_rc[0].left);
779 /* vertical */
780 expect = (rc.bottom - rc.top - MOD_rc[0].bottom + MOD_rc[0].top) / 2;
781 ok( expect == MOD_rc[0].top,
782 "bitmap top is %d expected %d\n", MOD_rc[0].top, expect);
783 failed = failed || !(expect == MOD_rc[0].top);
784 }
785 }
786 /* if there was a failure, report details */
787 if( failed) {
788 trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
789 count, (ispop? "POPUP": "MENUBAR"),text ? text: "(nil)", hbmp, bmpsize.cx, bmpsize.cy,
790 size.cx, size.cy, sc_size.cx, mnuopt, hastab);
791 trace(" check %d,%d arrow %d avechar %d\n",
792 GetSystemMetrics(SM_CXMENUCHECK ),
793 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
794 if( hbmp == HBMMENU_CALLBACK)
795 trace( " rc %d,%d-%d,%d bmp.rc %d,%d-%d,%d\n",
796 rc.left, rc.top, rc.top, rc.bottom, MOD_rc[0].left,
797 MOD_rc[0].top,MOD_rc[0].right, MOD_rc[0].bottom);
798 }
799 /* clean up */
800 ret = DestroyMenu(submenu);
801 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
802 ret = DestroyMenu(hmenu);
803 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
804 }
805
806
807 static void test_menu_bmp_and_string(void)
808 {
809 BYTE bmfill[300];
810 HBITMAP hbm_arrow;
811 BITMAP bm;
812 INT arrowwidth;
813 HWND hwnd;
814 HMENU hsysmenu;
815 MENUINFO mi= {sizeof(MENUINFO)};
816 MENUITEMINFOA mii= {sizeof(MENUITEMINFOA)};
817 int count, szidx, txtidx, bmpidx, hassub, mnuopt, ispop;
818 BOOL got;
819
820 if( !pGetMenuInfo)
821 {
822 win_skip("GetMenuInfo is not available\n");
823 return;
824 }
825
826 memset( bmfill, 0xcc, sizeof( bmfill));
827 hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL, WS_SYSMENU |
828 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
829 NULL, NULL, NULL, NULL);
830 hbm_arrow = LoadBitmapA( 0, (LPCSTR)OBM_MNARROW);
831 GetObjectA( hbm_arrow, sizeof(bm), &bm);
832 arrowwidth = bm.bmWidth;
833 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
834 if( !hwnd) return;
835 /* test system menu */
836 hsysmenu = GetSystemMenu( hwnd, FALSE);
837 ok( hsysmenu != NULL, "GetSystemMenu failed with error %d\n", GetLastError());
838 mi.fMask = MIM_STYLE;
839 mi.dwStyle = 0;
840 got = pGetMenuInfo( hsysmenu, &mi);
841 ok( got, "GetMenuInfo failed gle=%d\n", GetLastError());
842 ok( MNS_CHECKORBMP == mi.dwStyle, "System Menu Style is %08x, without the bit %08x\n",
843 mi.dwStyle, MNS_CHECKORBMP);
844 mii.fMask = MIIM_BITMAP;
845 mii.hbmpItem = NULL;
846 got = GetMenuItemInfoA( hsysmenu, SC_CLOSE, FALSE, &mii);
847 ok( got, "GetMenuItemInfoA failed gle=%d\n", GetLastError());
848 ok( HBMMENU_POPUP_CLOSE == mii.hbmpItem, "Item info did not get the right hbitmap: got %p expected %p\n",
849 mii.hbmpItem, HBMMENU_POPUP_CLOSE);
850
851 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
852
853 if( winetest_debug)
854 trace(" check %d,%d arrow %d avechar %d\n",
855 GetSystemMetrics(SM_CXMENUCHECK ),
856 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
857 count = 0;
858 MOD_maxid = 0;
859 for( ispop=1; ispop >= 0; ispop--){
860 static SIZE bmsizes[]= {
861 {10,10},{38,38},{1,30},{55,5}};
862 for( szidx=0; szidx < sizeof( bmsizes) / sizeof( SIZE); szidx++) {
863 HBITMAP hbm = CreateBitmap( bmsizes[szidx].cx, bmsizes[szidx].cy,1,1,bmfill);
864 HBITMAP bitmaps[] = { HBMMENU_CALLBACK, hbm, HBMMENU_POPUP_CLOSE, NULL };
865 ok( hbm != 0, "CreateBitmap failed err %d\n", GetLastError());
866 for( txtidx = 0; txtidx < sizeof(MOD_txtsizes)/sizeof(MOD_txtsizes[0]); txtidx++) {
867 for( hassub = 0; hassub < 2 ; hassub++) { /* add submenu item */
868 for( mnuopt = 0; mnuopt < 3 ; mnuopt++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
869 for( bmpidx = 0; bmpidx <sizeof(bitmaps)/sizeof(HBITMAP); bmpidx++) {
870 /* no need to test NULL bitmaps of several sizes */
871 if( !bitmaps[bmpidx] && szidx > 0) continue;
872 /* the HBMMENU_POPUP not to test for menu bars */
873 if( !ispop &&
874 bitmaps[bmpidx] >= HBMMENU_POPUP_CLOSE &&
875 bitmaps[bmpidx] <= HBMMENU_POPUP_MINIMIZE) continue;
876 if( !ispop && hassub) continue;
877 test_mbs_help( ispop, hassub, mnuopt,
878 hwnd, arrowwidth, ++count,
879 bitmaps[bmpidx],
880 bmsizes[szidx],
881 MOD_txtsizes[txtidx].text,
882 MOD_txtsizes[txtidx].size,
883 MOD_txtsizes[txtidx].sc_size);
884 }
885 }
886 }
887 }
888 DeleteObject( hbm);
889 }
890 }
891 /* clean up */
892 DestroyWindow(hwnd);
893 }
894
895 static void test_menu_add_string( void )
896 {
897 HMENU hmenu;
898 MENUITEMINFOA info;
899 BOOL rc;
900 int ret;
901
902 char string[0x80];
903 char string2[0x80];
904
905 char strback[0x80];
906 WCHAR strbackW[0x80];
907 static CHAR blah[] = "blah";
908 static const WCHAR expectedString[] = {'D','u','m','m','y',' ','s','t','r','i','n','g', 0};
909
910 hmenu = CreateMenu();
911
912 memset( &info, 0, sizeof info );
913 info.cbSize = sizeof info;
914 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_ID;
915 info.dwTypeData = blah;
916 info.cch = 6;
917 info.dwItemData = 0;
918 info.wID = 1;
919 info.fState = 0;
920 InsertMenuItemA(hmenu, 0, TRUE, &info );
921
922 memset( &info, 0, sizeof info );
923 info.cbSize = sizeof info;
924 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_DATA | MIIM_ID;
925 info.dwTypeData = string;
926 info.cch = sizeof string;
927 string[0] = 0;
928 GetMenuItemInfoA( hmenu, 0, TRUE, &info );
929
930 ok( !strcmp( string, "blah" ), "menu item name differed\n");
931
932 /* Test combination of ownerdraw and strings with GetMenuItemString(A/W) */
933 strcpy(string, "Dummy string");
934 memset(&info, 0x00, sizeof(info));
935 info.cbSize= sizeof(MENUITEMINFOA);
936 info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
937 info.fType= MFT_OWNERDRAW;
938 info.dwTypeData= string;
939 rc = InsertMenuItemA( hmenu, 0, TRUE, &info );
940 ok (rc, "InsertMenuItem failed\n");
941
942 strcpy(string,"Garbage");
943 ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
944 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
945
946 SetLastError(0xdeadbeef);
947 ret = GetMenuStringW( hmenu, 0, strbackW, 99, MF_BYPOSITION );
948 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
949 win_skip("GetMenuStringW is not implemented\n");
950 else
951 {
952 ok (ret, "GetMenuStringW on ownerdraw entry failed\n");
953 ok (!lstrcmpW( strbackW, expectedString ), "Menu text from Unicode version incorrect\n");
954 }
955
956 /* Just try some invalid parameter tests */
957 SetLastError(0xdeadbeef);
958 rc = SetMenuItemInfoA( hmenu, 0, TRUE, NULL );
959 ret = GetLastError();
960 ok (!rc, "SetMenuItemInfoA succeeded unexpectedly\n");
961 ok (ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
962
963 SetLastError(0xdeadbeef);
964 rc = SetMenuItemInfoA( hmenu, 0, FALSE, NULL );
965 ret = GetLastError();
966 ok (!rc, "SetMenuItemInfoA succeeded unexpectedly\n");
967 ok (ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
968
969 /* Just change ftype to string and see what text is stored */
970 memset(&info, 0x00, sizeof(info));
971 info.cbSize= sizeof(MENUITEMINFOA);
972 info.fMask= MIIM_FTYPE; /* Set string type */
973 info.fType= MFT_STRING;
974 info.dwTypeData= (char *)0xdeadbeef;
975 rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
976 ok (rc, "SetMenuItemInfo failed\n");
977
978 /* Did we keep the old dwTypeData? */
979 ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
980 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
981
982 /* Ensure change to bitmap type fails */
983 memset(&info, 0x00, sizeof(info));
984 info.cbSize= sizeof(MENUITEMINFOA);
985 info.fMask= MIIM_FTYPE; /* Set as bitmap type */
986 info.fType= MFT_BITMAP;
987 info.dwTypeData= (char *)0xdeadbee2;
988 rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
989 ok (!rc, "SetMenuItemInfo unexpectedly worked\n");
990
991 /* Just change ftype back and ensure data hasn't been freed */
992 info.fType= MFT_OWNERDRAW; /* Set as ownerdraw type */
993 info.dwTypeData= (char *)0xdeadbee3;
994 rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
995 ok (rc, "SetMenuItemInfo failed\n");
996
997 /* Did we keep the old dwTypeData? */
998 ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
999 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
1000
1001 /* Just change string value (not type) */
1002 memset(&info, 0x00, sizeof(info));
1003 info.cbSize= sizeof(MENUITEMINFOA);
1004 info.fMask= MIIM_STRING; /* Set typeData */
1005 strcpy(string2, "string2");
1006 info.dwTypeData= string2;
1007 rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1008 ok (rc, "SetMenuItemInfo failed\n");
1009
1010 ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1011 ok (!strcmp( strback, "string2" ), "Menu text from Ansi version incorrect\n");
1012
1013 /* crashes with wine 0.9.5 */
1014 memset(&info, 0x00, sizeof(info));
1015 info.cbSize= sizeof(MENUITEMINFOA);
1016 info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
1017 info.fType= MFT_OWNERDRAW;
1018 rc = InsertMenuItemA( hmenu, 0, TRUE, &info );
1019 ok (rc, "InsertMenuItem failed\n");
1020 ok (!GetMenuStringA( hmenu, 0, NULL, 0, MF_BYPOSITION),
1021 "GetMenuString on ownerdraw entry succeeded.\n");
1022 SetLastError(0xdeadbeef);
1023 ret = GetMenuStringW( hmenu, 0, NULL, 0, MF_BYPOSITION);
1024 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1025 win_skip("GetMenuStringW is not implemented\n");
1026 else
1027 ok (!ret, "GetMenuStringW on ownerdraw entry succeeded.\n");
1028
1029 DestroyMenu( hmenu );
1030 }
1031
1032 /* define building blocks for the menu item info tests */
1033 static int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
1034 {
1035 if (n <= 0) return 0;
1036 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
1037 return *str1 - *str2;
1038 }
1039
1040 static WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
1041 {
1042 WCHAR *p = dst;
1043 while ((*p++ = *src++));
1044 return dst;
1045 }
1046
1047 static void insert_menu_item( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state, UINT id,
1048 HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
1049 void *type_data, UINT len, HBITMAP item, BOOL expect )
1050 {
1051 MENUITEMINFOA info;
1052 BOOL ret;
1053
1054 /* magic bitmap handle to test smaller cbSize */
1055 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
1056 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
1057 else
1058 info.cbSize = sizeof(info);
1059 info.fMask = mask;
1060 info.fType = type;
1061 info.fState = state;
1062 info.wID = id;
1063 info.hSubMenu = submenu;
1064 info.hbmpChecked = checked;
1065 info.hbmpUnchecked = unchecked;
1066 info.dwItemData = data;
1067 info.dwTypeData = type_data;
1068 info.cch = len;
1069 info.hbmpItem = item;
1070 SetLastError( 0xdeadbeef );
1071 if (ansi) ret = InsertMenuItemA( hmenu, 0, TRUE, &info );
1072 else ret = InsertMenuItemW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
1073 if (!expect) ok_(__FILE__, line)( !ret, "InsertMenuItem should have failed.\n" );
1074 else ok_(__FILE__, line)( ret, "InsertMenuItem failed, err %u\n", GetLastError());
1075 }
1076
1077 static void check_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
1078 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked,
1079 ULONG_PTR data, void *type_data, UINT in_len, UINT out_len,
1080 HBITMAP item, LPCSTR expname, BOOL expect, BOOL expstring )
1081 {
1082 MENUITEMINFOA info;
1083 BOOL ret;
1084 WCHAR buffer[80];
1085
1086 SetLastError( 0xdeadbeef );
1087 memset( &info, 0xcc, sizeof(info) );
1088 info.cbSize = sizeof(info);
1089 info.fMask = mask;
1090 info.dwTypeData = type_data;
1091 info.cch = in_len;
1092
1093 ret = ansi ? GetMenuItemInfoA( hmenu, 0, TRUE, &info ) :
1094 GetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW *)&info );
1095 if (!expect)
1096 {
1097 ok_(__FILE__, line)( !ret, "GetMenuItemInfo should have failed.\n" );
1098 return;
1099 }
1100 ok_(__FILE__, line)( ret, "GetMenuItemInfo failed, err %u\n", GetLastError());
1101 if (mask & MIIM_TYPE)
1102 ok_(__FILE__, line)( info.fType == type || info.fType == LOWORD(type),
1103 "wrong type %x/%x\n", info.fType, type );
1104 if (mask & MIIM_STATE)
1105 ok_(__FILE__, line)( info.fState == state || info.fState == LOWORD(state),
1106 "wrong state %x/%x\n", info.fState, state );
1107 if (mask & MIIM_ID)
1108 ok_(__FILE__, line)( info.wID == id || info.wID == LOWORD(id),
1109 "wrong id %x/%x\n", info.wID, id );
1110 if (mask & MIIM_SUBMENU)
1111 ok_(__FILE__, line)( info.hSubMenu == submenu || (ULONG_PTR)info.hSubMenu == LOWORD(submenu),
1112 "wrong submenu %p/%p\n", info.hSubMenu, submenu );
1113 if (mask & MIIM_CHECKMARKS)
1114 {
1115 ok_(__FILE__, line)( info.hbmpChecked == checked || (ULONG_PTR)info.hbmpChecked == LOWORD(checked),
1116 "wrong bmpchecked %p/%p\n", info.hbmpChecked, checked );
1117 ok_(__FILE__, line)( info.hbmpUnchecked == unchecked || (ULONG_PTR)info.hbmpUnchecked == LOWORD(unchecked),
1118 "wrong bmpunchecked %p/%p\n", info.hbmpUnchecked, unchecked );
1119 }
1120 if (mask & MIIM_DATA)
1121 ok_(__FILE__, line)( info.dwItemData == data || info.dwItemData == LOWORD(data),
1122 "wrong item data %lx/%lx\n", info.dwItemData, data );
1123 if (mask & MIIM_BITMAP)
1124 ok_(__FILE__, line)( info.hbmpItem == item || (ULONG_PTR)info.hbmpItem == LOWORD(item),
1125 "wrong bmpitem %p/%p\n", info.hbmpItem, item );
1126 ok_(__FILE__, line)( info.dwTypeData == type_data || (ULONG_PTR)info.dwTypeData == LOWORD(type_data),
1127 "wrong type data %p/%p\n", info.dwTypeData, type_data );
1128 ok_(__FILE__, line)( info.cch == out_len ||
1129 broken(! ansi && info.cch == 2 * out_len) /* East-Asian */,
1130 "wrong len %x/%x\n", info.cch, out_len );
1131 if (expname)
1132 {
1133 if(ansi)
1134 ok_(__FILE__, line)( !strncmp( expname, info.dwTypeData, out_len ),
1135 "menu item name differed from '%s' '%s'\n", expname, info.dwTypeData );
1136 else
1137 ok_(__FILE__, line)( !strncmpW( (WCHAR *)expname, (WCHAR *)info.dwTypeData, out_len ),
1138 "menu item name wrong\n" );
1139
1140 SetLastError( 0xdeadbeef );
1141 ret = ansi ? GetMenuStringA( hmenu, 0, (char *)buffer, 80, MF_BYPOSITION ) :
1142 GetMenuStringW( hmenu, 0, buffer, 80, MF_BYPOSITION );
1143 if (expstring)
1144 ok_(__FILE__, line)( ret, "GetMenuString failed, err %u\n", GetLastError());
1145 else
1146 ok_(__FILE__, line)( !ret, "GetMenuString should have failed\n" );
1147 }
1148 }
1149
1150 static void modify_menu( int line, HMENU hmenu, BOOL ansi, UINT flags, UINT_PTR id, void *data )
1151 {
1152 BOOL ret;
1153
1154 SetLastError( 0xdeadbeef );
1155 if (ansi) ret = ModifyMenuA( hmenu, 0, flags, id, data );
1156 else ret = ModifyMenuW( hmenu, 0, flags, id, data );
1157 ok_(__FILE__,line)( ret, "ModifyMenuA failed, err %u\n", GetLastError());
1158 }
1159
1160 static void set_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
1161 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
1162 void *type_data, UINT len, HBITMAP item )
1163
1164 {
1165 MENUITEMINFOA info;
1166 BOOL ret;
1167
1168 /* magic bitmap handle to test smaller cbSize */
1169 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
1170 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
1171 else
1172 info.cbSize = sizeof(info);
1173 info.fMask = mask;
1174 info.fType = type;
1175 info.fState = state;
1176 info.wID = id;
1177 info.hSubMenu = submenu;
1178 info.hbmpChecked = checked;
1179 info.hbmpUnchecked = unchecked;
1180 info.dwItemData = data;
1181 info.dwTypeData = type_data;
1182 info.cch = len;
1183 info.hbmpItem = item;
1184 SetLastError( 0xdeadbeef );
1185 if (ansi) ret = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1186 else ret = SetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
1187 ok_(__FILE__, line)( ret, "SetMenuItemInfo failed, err %u\n", GetLastError());
1188 }
1189
1190 #define TMII_INSMI( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,eret1 )\
1191 hmenu = CreateMenu();\
1192 submenu = CreateMenu();\
1193 if(ansi)strcpy( string, init );\
1194 else strcpyW( string, init );\
1195 insert_menu_item( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, eret1 )
1196
1197 /* GetMenuItemInfo + GetMenuString */
1198 #define TMII_GMII( c2,l2,\
1199 d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,\
1200 expname, eret2, eret3)\
1201 check_menu_item_info( __LINE__, hmenu, ansi, c2, d3, e3, f3, g3, h3, i3, j3, k3, l2, l3, m3, \
1202 expname, eret2, eret3 )
1203
1204 #define TMII_DONE \
1205 RemoveMenu(hmenu, 0, TRUE );\
1206 DestroyMenu( hmenu );\
1207 DestroyMenu( submenu );
1208
1209 /* modify menu */
1210 #define TMII_MODM( flags, id, data ) \
1211 modify_menu( __LINE__, hmenu, ansi, flags, id, data )
1212
1213 /* SetMenuItemInfo */
1214 #define TMII_SMII( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1 ) \
1215 set_menu_item_info( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1 )
1216
1217
1218 #define OK 1
1219 #define ER 0
1220
1221
1222 static void test_menu_iteminfo( void )
1223 {
1224 BOOL ansi = TRUE;
1225 char txtA[]="wine";
1226 char initA[]="XYZ";
1227 char emptyA[]="";
1228 WCHAR txtW[]={'W','i','n','e',0};
1229 WCHAR initW[]={'X','Y','Z',0};
1230 WCHAR emptyW[]={0};
1231 void *txt, *init, *empty, *string;
1232 HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
1233 char stringA[0x80];
1234 HMENU hmenu, submenu;
1235 HBITMAP dummy_hbm = (HBITMAP)(ULONG_PTR)0xdeadbeef;
1236
1237 do {
1238 if( ansi) {txt=txtA;init=initA;empty=emptyA;string=stringA;}
1239 else {txt=txtW;init=initW;empty=emptyW;string=stringA;}
1240 trace( "%s string %p hbm %p txt %p\n", ansi ? "ANSI tests: " : "Unicode tests:", string, hbm, txt);
1241 /* test all combinations of MFT_STRING, MFT_OWNERDRAW and MFT_BITMAP */
1242 /* (since MFT_STRING is zero, there are four of them) */
1243 TMII_INSMI( MIIM_TYPE, MFT_STRING, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1244 TMII_GMII ( MIIM_TYPE, 80,
1245 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1246 txt, OK, OK );
1247 TMII_DONE
1248 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1249 TMII_GMII ( MIIM_TYPE, 80,
1250 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1251 NULL, OK, ER );
1252 TMII_DONE
1253 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1254 TMII_GMII ( MIIM_TYPE, 80,
1255 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1256 NULL, OK, ER );
1257 TMII_DONE
1258 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1259 TMII_GMII ( MIIM_TYPE, 80,
1260 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1261 NULL, OK, ER );
1262 TMII_DONE
1263 /* not enough space for name*/
1264 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1265 TMII_GMII ( MIIM_TYPE, 0,
1266 MFT_STRING, 0, 0, 0, 0, 0, 0, NULL, 4, 0,
1267 NULL, OK, OK );
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, 5,
1271 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1272 txt, OK, OK );
1273 TMII_DONE
1274 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1275 TMII_GMII ( MIIM_TYPE, 4,
1276 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 3, 0,
1277 txt, OK, OK );
1278 TMII_DONE
1279 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1280 TMII_GMII ( MIIM_TYPE, 0,
1281 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, 0,
1282 NULL, OK, ER );
1283 TMII_DONE
1284 /* cannot combine MIIM_TYPE with some other flags */
1285 TMII_INSMI( MIIM_TYPE|MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1286 TMII_DONE
1287 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1288 TMII_GMII ( MIIM_TYPE|MIIM_STRING, 80,
1289 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1290 NULL, ER, OK );
1291 TMII_DONE
1292 TMII_INSMI( MIIM_TYPE|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1293 TMII_DONE
1294 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1295 TMII_GMII ( MIIM_TYPE|MIIM_FTYPE, 80,
1296 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1297 NULL, ER, OK );
1298 TMII_DONE
1299 TMII_INSMI( MIIM_TYPE|MIIM_BITMAP, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, hbm, ER );
1300 TMII_DONE
1301 /* but succeeds with some others */
1302 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1303 TMII_GMII ( MIIM_TYPE|MIIM_SUBMENU, 80,
1304 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1305 txt, OK, OK );
1306 TMII_DONE
1307 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1308 TMII_GMII ( MIIM_TYPE|MIIM_STATE, 80,
1309 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1310 txt, OK, OK );
1311 TMII_DONE
1312 TMII_INSMI( MIIM_TYPE|MIIM_ID, MFT_STRING, -1, 888, 0, 0, 0, -1, txt, 6, 0, OK );
1313 TMII_GMII ( MIIM_TYPE|MIIM_ID, 80,
1314 MFT_STRING, 0, 888, 0, 0, 0, 0, string, 4, 0,
1315 txt, OK, OK );
1316 TMII_DONE
1317 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING, -1, -1, 0, 0, 0, 999, txt, 6, 0, OK );
1318 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1319 MFT_STRING, 0, 0, 0, 0, 0, 999, string, 4, 0,
1320 txt, OK, OK );
1321 TMII_DONE
1322 /* to be continued */
1323 /* set text with MIIM_TYPE and retrieve with MIIM_STRING */
1324 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1325 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1326 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1327 txt, OK, OK );
1328 TMII_DONE
1329 /* set text with MIIM_TYPE and retrieve with MIIM_STRING; MFT_OWNERDRAW causes an empty string */
1330 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1331 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1332 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1333 empty, OK, ER );
1334 TMII_DONE
1335 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1336 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1337 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1338 empty, OK, ER );
1339 TMII_DONE
1340 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1341 TMII_GMII ( MIIM_FTYPE, 80,
1342 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, 0,
1343 init, OK, ER );
1344 TMII_DONE
1345 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1346 TMII_GMII ( 0, 80,
1347 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1348 init, OK, OK );
1349 TMII_DONE
1350 /* contrary to MIIM_TYPE,you can set the text for an owner draw menu */
1351 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1352 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1353 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1354 txt, OK, OK );
1355 TMII_DONE
1356 /* same but retrieve with MIIM_TYPE */
1357 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1358 TMII_GMII ( MIIM_TYPE, 80,
1359 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1360 NULL, OK, OK );
1361 TMII_DONE
1362 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1363 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1364 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1365 empty, OK, ER );
1366 TMII_DONE
1367 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1368 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1369 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1370 empty, OK, ER );
1371 TMII_DONE
1372 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1373 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1374 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, 0,
1375 NULL, OK, ER );
1376 TMII_DONE
1377
1378 /* How is that with bitmaps? */
1379 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1380 TMII_GMII ( MIIM_TYPE, 80,
1381 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1382 NULL, OK, ER );
1383 TMII_DONE
1384 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1385 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1386 0, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1387 init, OK, ER );
1388 TMII_DONE
1389 /* MIIM_BITMAP does not like MFT_BITMAP */
1390 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, hbm, ER );
1391 TMII_DONE
1392 /* no problem with OWNERDRAWN */
1393 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1394 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1395 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1396 init, OK, ER );
1397 TMII_DONE
1398 /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1399 TMII_INSMI( MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER );
1400 TMII_DONE
1401
1402 /* menu with submenu */
1403 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1404 TMII_GMII ( MIIM_SUBMENU, 80,
1405 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1406 init, OK, ER );
1407 TMII_DONE
1408 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, empty, 0, 0, OK );
1409 TMII_GMII ( MIIM_SUBMENU, 80,
1410 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1411 init, OK, ER );
1412 TMII_DONE
1413 /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1414 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1415 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1416 MFT_STRING|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1417 empty, OK, ER );
1418 TMII_GMII ( MIIM_SUBMENU|MIIM_FTYPE, 80,
1419 MFT_SEPARATOR, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1420 empty, OK, ER );
1421 TMII_DONE
1422 /* menu with invalid submenu */
1423 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, (HMENU)999, 0, 0, -1, txt, 0, 0, ER );
1424 TMII_DONE
1425 /* Separator */
1426 TMII_INSMI( MIIM_TYPE, MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1427 TMII_GMII ( MIIM_TYPE, 80,
1428 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1429 NULL, OK, ER );
1430 TMII_DONE
1431 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1432 TMII_GMII ( MIIM_TYPE, 80,
1433 MFT_BITMAP|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1434 NULL, OK, ER );
1435 TMII_DONE
1436 /* SEPARATOR and STRING go well together */
1437 /* BITMAP and STRING go well together */
1438 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1439 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1440 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1441 txt, OK, OK );
1442 TMII_DONE
1443 /* BITMAP, SEPARATOR and STRING go well together */
1444 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1445 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1446 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1447 txt, OK, OK );
1448 TMII_DONE
1449 /* last two tests, but use MIIM_TYPE to retrieve info */
1450 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1451 TMII_GMII ( MIIM_TYPE, 80,
1452 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1453 NULL, OK, OK );
1454 TMII_DONE
1455 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1456 TMII_GMII ( MIIM_TYPE, 80,
1457 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1458 NULL, OK, OK );
1459 TMII_DONE
1460 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1461 TMII_GMII ( MIIM_TYPE, 80,
1462 MFT_SEPARATOR|MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1463 NULL, OK, OK );
1464 TMII_DONE
1465 /* same three with MFT_OWNERDRAW */
1466 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1467 TMII_GMII ( MIIM_TYPE, 80,
1468 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1469 NULL, OK, OK );
1470 TMII_DONE
1471 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1472 TMII_GMII ( MIIM_TYPE, 80,
1473 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1474 NULL, OK, OK );
1475 TMII_DONE
1476 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1477 TMII_GMII ( MIIM_TYPE, 80,
1478 MFT_SEPARATOR|MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1479 NULL, OK, OK );
1480 TMII_DONE
1481
1482 TMII_INSMI( MIIM_STRING|MIIM_FTYPE|MIIM_ID, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1483 TMII_GMII ( MIIM_TYPE, 80,
1484 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1485 NULL, OK, OK );
1486 TMII_DONE
1487 /* test with modifymenu: string is preserved after setting OWNERDRAW */
1488 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1489 TMII_MODM( MFT_OWNERDRAW, -1, (void*)787 );
1490 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_DATA, 80,
1491 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 787, string, 4, 0,
1492 txt, OK, OK );
1493 TMII_DONE
1494 /* same with bitmap: now the text is cleared */
1495 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1496 TMII_MODM( MFT_BITMAP, 545, hbm );
1497 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1498 MFT_BITMAP, 0, 545, 0, 0, 0, 0, string, 0, hbm,
1499 empty, OK, ER );
1500 TMII_DONE
1501 /* start with bitmap: now setting text clears it (though he flag is raised) */
1502 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1503 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1504 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 0, hbm,
1505 empty, OK, ER );
1506 TMII_MODM( MFT_STRING, 545, txt );
1507 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1508 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 4, 0,
1509 txt, OK, OK );
1510 TMII_DONE
1511 /*repeat with text NULL */
1512 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1513 TMII_MODM( MFT_STRING, 545, NULL );
1514 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1515 MFT_SEPARATOR, 0, 545, 0, 0, 0, 0, string, 0, 0,
1516 empty, OK, ER );
1517 TMII_DONE
1518 /* repeat with text "" */
1519 TMII_INSMI( MIIM_BITMAP, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1520 TMII_MODM( MFT_STRING, 545, empty );
1521 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1522 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 0, 0,
1523 empty, OK, ER );
1524 TMII_DONE
1525 /* start with bitmap: set ownerdraw */
1526 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1527 TMII_MODM( MFT_OWNERDRAW, -1, (void *)232 );
1528 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_DATA, 80,
1529 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 232, string, 0, hbm,
1530 empty, OK, ER );
1531 TMII_DONE
1532 /* ask nothing */
1533 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1534 TMII_GMII ( 0, 80,
1535 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1536 init, OK, OK );
1537 TMII_DONE
1538 /* some tests with small cbSize: the hbmpItem is to be ignored */
1539 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1540 TMII_GMII ( MIIM_TYPE, 80,
1541 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1542 NULL, OK, ER );
1543 TMII_DONE
1544 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1545 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1546 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, NULL,
1547 init, OK, ER );
1548 TMII_DONE
1549 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1550 TMII_GMII ( MIIM_TYPE, 80,
1551 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, NULL,
1552 txt, OK, OK );
1553 TMII_DONE
1554 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1555 TMII_GMII ( MIIM_TYPE, 80,
1556 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1557 NULL, OK, OK );
1558 TMII_DONE
1559 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1560 TMII_GMII ( MIIM_TYPE, 80,
1561 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1562 NULL, OK, OK );
1563 TMII_DONE
1564 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1565 TMII_GMII ( MIIM_TYPE, 80,
1566 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1567 NULL, OK, OK );
1568 TMII_DONE
1569 /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus */
1570 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1571 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1572 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1573 NULL, OK, ER );
1574 TMII_DONE
1575 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1576 TMII_GMII ( MIIM_TYPE, 80,
1577 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1578 NULL, OK, ER );
1579 TMII_DONE
1580 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1581 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1582 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1583 NULL, OK, ER );
1584 TMII_DONE
1585 /* set a string menu to ownerdraw with MIIM_TYPE */
1586 TMII_INSMI( MIIM_TYPE, MFT_STRING, -2, -2, 0, 0, 0, -2, txt, -2, 0, OK );
1587 TMII_SMII ( MIIM_TYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1588 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1589 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1590 txt, OK, OK );
1591 TMII_DONE
1592 /* test with modifymenu add submenu */
1593 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1594 TMII_MODM( MF_POPUP, (UINT_PTR)submenu, txt );
1595 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_SUBMENU, 80,
1596 MFT_STRING, 0, 0, submenu, 0, 0, 0, string, 4, 0,
1597 txt, OK, OK );
1598 TMII_GMII ( MIIM_TYPE, 80,
1599 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1600 txt, OK, OK );
1601 TMII_DONE
1602 /* MFT_SEPARATOR bit is kept when the text is added */
1603 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1604 TMII_SMII( MIIM_STRING, 0, 0, 0, 0, 0, 0, 0, txt, 0, 0 );
1605 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1606 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, 0,
1607 txt, OK, OK );
1608 TMII_DONE
1609 /* MFT_SEPARATOR bit is kept when bitmap is added */
1610 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1611 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm );
1612 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1613 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1614 init, OK, ER );
1615 TMII_DONE
1616 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1617 Only the low word of the dwTypeData is used.
1618 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1619 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1620 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1621 TMII_GMII ( MIIM_TYPE, 80,
1622 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1623 NULL, OK, OK );
1624 TMII_DONE
1625 /* Type flags */
1626 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1627 TMII_GMII ( MIIM_TYPE, 80,
1628 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1629 NULL, OK, OK );
1630 TMII_DONE
1631 /* State flags */
1632 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1633 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1634 TMII_GMII ( MIIM_STATE, 80,
1635 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1636 NULL, OK, OK );
1637 TMII_DONE
1638 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1639 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1640 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1641 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1642 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1643 NULL, OK, OK );
1644 TMII_DONE
1645 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1646 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1647 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1648 TMII_GMII ( MIIM_FTYPE, 80,
1649 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1650 NULL, OK, OK );
1651 TMII_GMII ( MIIM_TYPE, 80,
1652 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1653 NULL, OK, OK );
1654 TMII_GMII ( MIIM_FTYPE, 80,
1655 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1656 NULL, OK, OK );
1657 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1658 TMII_GMII ( MIIM_TYPE, 80,
1659 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1660 NULL, OK, OK );
1661 TMII_DONE
1662 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1663 Only the low word of the dwTypeData is used.
1664 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1665 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1666 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1667 TMII_GMII ( MIIM_TYPE, 80,
1668 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1669 NULL, OK, OK );
1670 TMII_DONE
1671 /* Type flags */
1672 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1673 TMII_GMII ( MIIM_TYPE, 80,
1674 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1675 NULL, OK, OK );
1676 TMII_DONE
1677 /* State flags */
1678 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1679 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1680 TMII_GMII ( MIIM_STATE, 80,
1681 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1682 NULL, OK, OK );
1683 TMII_DONE
1684 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1685 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1686 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1687 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1688 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1689 NULL, OK, OK );
1690 TMII_DONE
1691 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1692 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1693 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1694 TMII_GMII ( MIIM_FTYPE, 80,
1695 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1696 NULL, OK, OK );
1697 TMII_GMII ( MIIM_TYPE, 80,
1698 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1699 NULL, OK, OK );
1700 TMII_GMII ( MIIM_FTYPE, 80,
1701 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1702 NULL, OK, OK );
1703 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1704 TMII_GMII ( MIIM_TYPE, 80,
1705 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1706 NULL, OK, OK );
1707 TMII_DONE
1708 } while( !(ansi = !ansi) );
1709 DeleteObject( hbm);
1710 }
1711
1712 /*
1713 The following tests try to confirm the algorithm used to return the menu items
1714 when there is a collision between a menu item and a popup menu
1715 */
1716 static void test_menu_search_bycommand( void )
1717 {
1718 HMENU hmenu, hmenuSub, hmenuSub2;
1719 MENUITEMINFOA info;
1720 BOOL rc;
1721 UINT id;
1722 char strback[0x80];
1723 char strIn[0x80];
1724 static CHAR menuitem[] = "MenuItem",
1725 menuitem2[] = "MenuItem 2";
1726
1727 /* Case 1: Menu containing a menu item */
1728 hmenu = CreateMenu();
1729
1730 memset( &info, 0, sizeof info );
1731 info.cbSize = sizeof info;
1732 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1733 info.fType = MFT_STRING;
1734 strcpy(strIn, "Case 1 MenuItem");
1735 info.dwTypeData = strIn;
1736 info.wID = (UINT) 0x1234;
1737
1738 rc = InsertMenuItemA(hmenu, 0, TRUE, &info );
1739 ok (rc, "Inserting the menuitem failed\n");
1740
1741 id = GetMenuItemID(hmenu, 0);
1742 ok (id == 0x1234, "Getting the menuitem id failed(gave %x)\n", id);
1743
1744 /* Confirm the menuitem was given the id supplied (getting by position) */
1745 memset( &info, 0, sizeof info );
1746 strback[0] = 0x00;
1747 info.cbSize = sizeof(MENUITEMINFOA);
1748 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1749 info.dwTypeData = strback;
1750 info.cch = sizeof(strback);
1751
1752 rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info); /* Get by position */
1753 ok (rc, "Getting the menu items info failed\n");
1754 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1755 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1756
1757 /* Search by id - Should return the item */
1758 memset( &info, 0, sizeof info );
1759 strback[0] = 0x00;
1760 info.cbSize = sizeof(MENUITEMINFOA);
1761 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1762 info.dwTypeData = strback;
1763 info.cch = sizeof(strback);
1764 rc = GetMenuItemInfoA(hmenu, 0x1234, FALSE, &info); /* Get by ID */
1765
1766 ok (rc, "Getting the menu items info failed\n");
1767 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1768 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1769
1770 DestroyMenu( hmenu );
1771
1772 /* Case 2: Menu containing a popup menu */
1773 hmenu = CreateMenu();
1774 hmenuSub = CreateMenu();
1775
1776 strcpy(strIn, "Case 2 SubMenu");
1777 rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, strIn);
1778 ok (rc, "Inserting the popup menu into the main menu failed\n");
1779
1780 id = GetMenuItemID(hmenu, 0);
1781 ok (id == -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id);
1782
1783 /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
1784 memset( &info, 0, sizeof info );
1785 strback[0] = 0x00;
1786 info.cbSize = sizeof(MENUITEMINFOA);
1787 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1788 info.dwTypeData = strback;
1789 info.cch = sizeof(strback);
1790 info.wID = 0xdeadbeef;
1791
1792 rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info); /* Get by position */
1793 ok (rc, "Getting the menu items info failed\n");
1794 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the menuitem\n");
1795 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1796
1797 /* Search by id - returns the popup menu itself */
1798 memset( &info, 0, sizeof info );
1799 strback[0] = 0x00;
1800 info.cbSize = sizeof(MENUITEMINFOA);
1801 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1802 info.dwTypeData = strback;
1803 info.cch = sizeof(strback);
1804 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1805
1806 ok (rc, "Getting the menu items info failed\n");
1807 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1808 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1809
1810 /*
1811 Now add an item after it with the same id
1812 */
1813 memset( &info, 0, sizeof info );
1814 info.cbSize = sizeof info;
1815 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1816 info.fType = MFT_STRING;
1817 strcpy(strIn, "Case 2 MenuItem 1");
1818 info.dwTypeData = strIn;
1819 info.wID = (UINT_PTR) hmenuSub;
1820 rc = InsertMenuItemA(hmenu, -1, TRUE, &info );
1821 ok (rc, "Inserting the menuitem failed\n");
1822
1823 /* Search by id - returns the item which follows the popup menu */
1824 memset( &info, 0, sizeof info );
1825 strback[0] = 0x00;
1826 info.cbSize = sizeof(MENUITEMINFOA);
1827 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1828 info.dwTypeData = strback;
1829 info.cch = sizeof(strback);
1830 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1831
1832 ok (rc, "Getting the menu items info failed\n");
1833 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1834 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1835
1836 /*
1837 Now add an item before the popup (with the same id)
1838 */
1839 memset( &info, 0, sizeof info );
1840 info.cbSize = sizeof info;
1841 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1842 info.fType = MFT_STRING;
1843 strcpy(strIn, "Case 2 MenuItem 2");
1844 info.dwTypeData = strIn;
1845 info.wID = (UINT_PTR) hmenuSub;
1846 rc = InsertMenuItemA(hmenu, 0, TRUE, &info );
1847 ok (rc, "Inserting the menuitem failed\n");
1848
1849 /* Search by id - returns the item which precedes the popup menu */
1850 memset( &info, 0, sizeof info );
1851 strback[0] = 0x00;
1852 info.cbSize = sizeof(MENUITEMINFOA);
1853 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1854 info.dwTypeData = strback;
1855 info.cch = sizeof(strback);
1856 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1857
1858 ok (rc, "Getting the menu items info failed\n");
1859 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1860 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1861
1862 DestroyMenu( hmenu );
1863 DestroyMenu( hmenuSub );
1864
1865 /*
1866 Case 3: Menu containing a popup menu which in turn
1867 contains 2 items with the same id as the popup itself
1868 */
1869
1870 hmenu = CreateMenu();
1871 hmenuSub = CreateMenu();
1872
1873 memset( &info, 0, sizeof info );
1874 info.cbSize = sizeof info;
1875 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1876 info.fType = MFT_STRING;
1877 info.dwTypeData = menuitem;
1878 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1879
1880 rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1881 ok (rc, "Inserting the popup menu into the main menu failed\n");
1882
1883 rc = InsertMenuItemA(hmenuSub, 0, TRUE, &info );
1884 ok (rc, "Inserting the sub menu menuitem failed\n");
1885
1886 memset( &info, 0, sizeof info );
1887 info.cbSize = sizeof info;
1888 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1889 info.fType = MFT_STRING;
1890 info.dwTypeData = menuitem2;
1891 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1892
1893 rc = InsertMenuItemA(hmenuSub, 1, TRUE, &info );
1894 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
1895
1896 /* Prove that you can't query the id of a popup directly (By position) */
1897 id = GetMenuItemID(hmenu, 0);
1898 ok (id == -1, "Getting the sub menu id should have failed because it's a popup (gave %x)\n", id);
1899
1900 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1901 memset( &info, 0, sizeof info );
1902 strback[0] = 0x00;
1903 info.cbSize = sizeof(MENUITEMINFOA);
1904 info.fMask = MIIM_STRING | MIIM_ID;
1905 info.dwTypeData = strback;
1906 info.cch = sizeof(strback);
1907
1908 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
1909 ok (rc, "Getting the menus info failed\n");
1910 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
1911 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1912 DestroyMenu( hmenu );
1913 DestroyMenu( hmenuSub );
1914
1915 /*
1916 Case 4: Menu containing 2 popup menus, the second
1917 contains 2 items with the same id as the first popup menu
1918 */
1919 hmenu = CreateMenu();
1920 hmenuSub = CreateMenu();
1921 hmenuSub2 = CreateMenu();
1922
1923 rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1924 ok (rc, "Inserting the popup menu into the main menu failed\n");
1925
1926 rc = InsertMenuA(hmenu, 1, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub2, "Submenu2");
1927 ok (rc, "Inserting the popup menu into the main menu failed\n");
1928
1929 memset( &info, 0, sizeof info );
1930 info.cbSize = sizeof info;
1931 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1932 info.fType = MFT_STRING;
1933 info.dwTypeData = menuitem;
1934 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1935
1936 rc = InsertMenuItemA(hmenuSub2, 0, TRUE, &info );
1937 ok (rc, "Inserting the sub menu menuitem failed\n");
1938
1939 memset( &info, 0, sizeof info );
1940 info.cbSize = sizeof info;
1941 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1942 info.fType = MFT_STRING;
1943 info.dwTypeData = menuitem2;
1944 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1945
1946 rc = InsertMenuItemA(hmenuSub2, 1, TRUE, &info );
1947 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
1948
1949 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1950 memset( &info, 0, sizeof info );
1951 strback[0] = 0x00;
1952 info.cbSize = sizeof(MENUITEMINFOA);
1953 info.fMask = MIIM_STRING | MIIM_ID;
1954 info.dwTypeData = strback;
1955 info.cch = sizeof(strback);
1956
1957 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
1958 ok (rc, "Getting the menus info failed\n");
1959 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
1960 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1961
1962 memset( &info, 0, sizeof info );
1963 strback[0] = 0x00;
1964 info.cbSize = sizeof(MENUITEMINFOA);
1965 info.fMask = MIIM_STRING | MIIM_ID;
1966 info.dwTypeData = strback;
1967 info.cch = sizeof(strback);
1968
1969 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub2, FALSE, &info);
1970 ok (rc, "Getting the menus info failed\n");
1971 ok (info.wID == (UINT_PTR)hmenuSub2, "IDs differ for popup menu\n");
1972 ok (!strcmp(info.dwTypeData, "Submenu2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1973
1974 DestroyMenu( hmenu );
1975 DestroyMenu( hmenuSub );
1976 DestroyMenu( hmenuSub2 );
1977
1978
1979 /*
1980 Case 5: Menu containing a popup menu which in turn
1981 contains an item with a different id than the popup menu.
1982 This tests the fallback to a popup menu ID.
1983 */
1984
1985 hmenu = CreateMenu();
1986 hmenuSub = CreateMenu();
1987
1988 rc = AppendMenuA(hmenu, MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1989 ok (rc, "Appending the popup menu to the main menu failed\n");
1990
1991 rc = AppendMenuA(hmenuSub, MF_STRING, 102, "Item");
1992 ok (rc, "Appending the item to the popup menu failed\n");
1993
1994 /* Set the ID for hmenuSub */
1995 info.cbSize = sizeof(info);
1996 info.fMask = MIIM_ID;
1997 info.wID = 101;
1998
1999 rc = SetMenuItemInfoA(hmenu, 0, TRUE, &info);
2000 ok(rc, "Setting the ID for the popup menu failed\n");
2001
2002 /* Check if the ID has been set */
2003 info.wID = 0;
2004 rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info);
2005 ok(rc, "Getting the ID for the popup menu failed\n");
2006 ok(info.wID == 101, "The ID for the popup menu has not been set\n");
2007
2008 /* Prove getting the item info via ID returns the popup menu */
2009 memset( &info, 0, sizeof(info));
2010 strback[0] = 0x00;
2011 info.cbSize = sizeof(MENUITEMINFOA);
2012 info.fMask = MIIM_STRING | MIIM_ID;
2013 info.dwTypeData = strback;
2014 info.cch = sizeof(strback);
2015
2016 rc = GetMenuItemInfoA(hmenu, 101, FALSE, &info);
2017 ok (rc, "Getting the menu info failed\n");
2018 ok (info.wID == 101, "IDs differ\n");
2019 ok (!strcmp(info.dwTypeData, "Submenu"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2020
2021 /* Also look for the menu item */
2022 memset( &info, 0, sizeof(info));
2023 strback[0] = 0x00;
2024 info.cbSize = sizeof(MENUITEMINFOA);
2025 info.fMask = MIIM_STRING | MIIM_ID;
2026 info.dwTypeData = strback;
2027 info.cch = sizeof(strback);
2028
2029 rc = GetMenuItemInfoA(hmenu, 102, FALSE, &info);
2030 ok (rc, "Getting the menu info failed\n");
2031 ok (info.wID == 102, "IDs differ\n");
2032 ok (!strcmp(info.dwTypeData, "Item"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2033
2034 DestroyMenu(hmenu);
2035 DestroyMenu(hmenuSub);
2036 }
2037
2038 struct menu_item_pair_s {
2039 UINT uMenu; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
2040 * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
2041 * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
2042 UINT uItem;
2043 };
2044
2045 static struct menu_mouse_tests_s {
2046 DWORD type;
2047 struct menu_item_pair_s menu_item_pairs[5]; /* for mousing */
2048 WORD wVk[5]; /* keys */
2049 BOOL bMenuVisible;
2050 BOOL _todo_wine;
2051 } menu_tests[] = {
2052 /* for each test, send keys or clicks and check for menu visibility */
2053 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE }, /* test 0 */
2054 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
2055 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
2056 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2057 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
2058 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2059 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2060 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, VK_ESCAPE, 0}, FALSE, FALSE },
2061 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', VK_ESCAPE, 0}, TRUE, FALSE },
2062 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
2063 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2064 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2065 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2066 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2067 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
2068 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2069 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
2070 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2071 { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, TRUE, FALSE },
2072 { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, FALSE, FALSE },
2073
2074 { INPUT_MOUSE, {{1, 2}, {0}}, {0}, TRUE, TRUE }, /* test 20 */
2075 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2076 { INPUT_MOUSE, {{1, 0}, {0}}, {0}, TRUE, TRUE },
2077 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2078 { INPUT_MOUSE, {{1, 0}, {2, 2}, {0}}, {0}, TRUE, TRUE },
2079 { INPUT_MOUSE, {{2, 1}, {0}}, {0}, FALSE, FALSE },
2080 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
2081 { INPUT_MOUSE, {{3, 0}, {0}}, {0}, FALSE, FALSE },
2082 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
2083 { INPUT_MOUSE, {{3, 1}, {0}}, {0}, TRUE, TRUE },
2084 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2085 { -1 }
2086 };
2087
2088 static void send_key(WORD wVk)
2089 {
2090 TEST_INPUT i[2];
2091 memset(i, 0, sizeof(i));
2092 i[0].type = i[1].type = INPUT_KEYBOARD;
2093 i[0].u.ki.wVk = i[1].u.ki.wVk = wVk;
2094 i[1].u.ki.dwFlags = KEYEVENTF_KEYUP;
2095 pSendInput(2, (INPUT *) i, sizeof(INPUT));
2096 }
2097
2098 static BOOL click_menu(HANDLE hWnd, struct menu_item_pair_s *mi)
2099 {
2100 HMENU hMenu = hMenus[mi->uMenu];
2101 TEST_INPUT i[3];
2102 MSG msg;
2103 RECT r;
2104 int screen_w = GetSystemMetrics(SM_CXSCREEN);
2105 int screen_h = GetSystemMetrics(SM_CYSCREEN);
2106 BOOL ret = GetMenuItemRect(mi->uMenu > 2 ? NULL : hWnd, hMenu, mi->uItem, &r);
2107 if(!ret) return FALSE;
2108
2109 memset(i, 0, sizeof(i));
2110 i[0].type = i[1].type = i[2].type = INPUT_MOUSE;
2111 i[0].u.mi.dx = i[1].u.mi.dx = i[2].u.mi.dx
2112 = ((r.left + 5) * 65535) / screen_w;
2113 i[0].u.mi.dy = i[1].u.mi.dy = i[2].u.mi.dy
2114 = ((r.top + 5) * 65535) / screen_h;
2115 i[0].u.mi.dwFlags = i[1].u.mi.dwFlags = i[2].u.mi.dwFlags
2116 = MOUSEEVENTF_ABSOLUTE;
2117 i[0].u.mi.dwFlags |= MOUSEEVENTF_MOVE;
2118 i[1].u.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
2119 i[2].u.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
2120 ret = pSendInput(3, (INPUT *) i, sizeof(INPUT));
2121
2122 /* hack to prevent mouse message buildup in Wine */
2123 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
2124 return ret;
2125 }
2126
2127 static DWORD WINAPI test_menu_input_thread(LPVOID lpParameter)
2128 {
2129 int i, j;
2130 HANDLE hWnd = lpParameter;
2131
2132 Sleep(500);
2133 /* mixed keyboard/mouse test */
2134 for (i = 0; menu_tests[i].type != -1; i++)
2135 {
2136 BOOL ret = TRUE;
2137 int elapsed = 0;
2138
2139 got_input = i && menu_tests[i-1].bMenuVisible;
2140
2141 if (menu_tests[i].type == INPUT_KEYBOARD)
2142 for (j = 0; menu_tests[i].wVk[j] != 0; j++)
2143 send_key(menu_tests[i].wVk[j]);
2144 else
2145 for (j = 0; menu_tests[i].menu_item_pairs[j].uMenu != 0; j++)
2146 if (!(ret = click_menu(hWnd, &menu_tests[i].menu_item_pairs[j]))) break;
2147
2148 if (!ret)
2149 {
2150 skip( "test %u: failed to send input\n", i );
2151 PostMessageA( hWnd, WM_CANCELMODE, 0, 0 );
2152 return 0;
2153 }
2154 while (menu_tests[i].bMenuVisible != bMenuVisible)
2155 {
2156 if (elapsed > 200)
2157 break;
2158 elapsed += 20;
2159 Sleep(20);
2160 }
2161
2162 if (!got_input)
2163 {
2164 skip( "test %u: didn't receive input\n", i );
2165 PostMessageA( hWnd, WM_CANCELMODE, 0, 0 );
2166 return 0;
2167 }
2168
2169 if (menu_tests[i]._todo_wine)
2170 {
2171 todo_wine {
2172 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
2173 }
2174 }
2175 else
2176 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
2177 }
2178 return 0;
2179 }
2180
2181 static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam,
2182 LPARAM lParam)
2183 {
2184 switch (msg) {
2185 case WM_ENTERMENULOOP:
2186 bMenuVisible = TRUE;
2187 break;
2188 case WM_INITMENUPOPUP:
2189 case WM_UNINITMENUPOPUP:
2190 case WM_EXITMENULOOP:
2191 case WM_MENUSELECT:
2192 break;
2193
2194 case WM_KEYDOWN:
2195 case WM_SYSKEYDOWN:
2196 case WM_MOUSEMOVE:
2197 case WM_LBUTTONDOWN:
2198 case WM_LBUTTONUP:
2199 case WM_NCMOUSEMOVE:
2200 case WM_NCLBUTTONDOWN:
2201 case WM_NCLBUTTONUP:
2202 got_input = TRUE;
2203 /* fall through */
2204 default:
2205 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2206 }
2207
2208 if(pGetMenuBarInfo)
2209 {
2210 MENUBARINFO mbi;
2211 HMENU hmenu;
2212 UINT state;
2213 BOOL br;
2214
2215 mbi.cbSize = sizeof(MENUBARINFO);
2216
2217 /* get info for the menu */
2218 br = pGetMenuBarInfo(hWnd, OBJID_MENU, 0, &mbi);
2219 ok(br, "msg %x: GetMenuBarInfo failed\n", msg);
2220 hmenu = GetMenu(hWnd);
2221 ok(!mbi.hwndMenu, "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected NULL\n",
2222 msg, mbi.hwndMenu);
2223 ok(mbi.hMenu == hmenu, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2224 msg, mbi.hMenu, hmenu);
2225 ok(!bMenuVisible == !mbi.fBarFocused, "msg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2226 msg, mbi.fBarFocused != 0);
2227 ok(!bMenuVisible == !mbi.fFocused, "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n",
2228 msg, mbi.fFocused != 0);
2229
2230 /* get info for the menu's first item */
2231 br = pGetMenuBarInfo(hWnd, OBJID_MENU, 1, &mbi);
2232 ok(br, "msg %x: GetMenuBarInfo failed\n", msg);
2233 state = GetMenuState(hmenu, 0, MF_BYPOSITION);
2234 if (pGetMenuInfo) /* Skip on NT */
2235 {
2236 /* Native returns handle to destroyed window */
2237 if (msg==WM_UNINITMENUPOPUP && popmenu==1)
2238 todo_wine ok(!mbi.hwndMenu == !popmenu,
2239 "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected %sNULL\n",
2240 msg, mbi.hwndMenu, popmenu ? "not " : "");
2241 else
2242 ok(!mbi.hwndMenu == !popmenu,
2243 "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected %sNULL\n",
2244 msg, mbi.hwndMenu, popmenu ? "not " : "");
2245 }
2246 ok(mbi.hMenu == hmenu, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2247 msg, mbi.hMenu, hmenu);
2248 ok(!bMenuVisible == !mbi.fBarFocused, "nsg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2249 msg, mbi.fBarFocused != 0);
2250 ok(!(bMenuVisible && (state & MF_HILITE)) == !mbi.fFocused,
2251 "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n", msg, mbi.fFocused != 0);
2252 }
2253
2254 if (msg == WM_EXITMENULOOP)
2255 bMenuVisible = FALSE;
2256 else if (msg == WM_INITMENUPOPUP)
2257 popmenu++;
2258 else if (msg == WM_UNINITMENUPOPUP)
2259 popmenu--;
2260 return 0;
2261 }
2262
2263 static void test_menu_input(void) {
2264 MSG msg;
2265 WNDCLASSA wclass;
2266 HINSTANCE hInstance = GetModuleHandleA( NULL );
2267 HANDLE hThread, hWnd;
2268 DWORD tid;
2269 ATOM aclass;
2270
2271 if (!pSendInput)
2272 {
2273 win_skip("SendInput is not available\n");
2274 return;
2275 }
2276
2277 wclass.lpszClassName = "MenuTestClass";
2278 wclass.style = CS_HREDRAW | CS_VREDRAW;
2279 wclass.lpfnWndProc = WndProc;
2280 wclass.hInstance = hInstance;
2281 wclass.hIcon = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
2282 wclass.hCursor = LoadCursorA( 0, (LPCSTR)IDC_ARROW );
2283 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2284 wclass.lpszMenuName = 0;
2285 wclass.cbClsExtra = 0;
2286 wclass.cbWndExtra = 0;
2287 aclass = RegisterClassA( &wclass );
2288 ok (aclass, "MenuTest class not created\n");
2289 if (!aclass) return;
2290 hWnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
2291 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2292 400, 200, NULL, NULL, hInstance, NULL);
2293 ok (hWnd != NULL, "MenuTest window not created\n");
2294 if (!hWnd) return;
2295 /* fixed menus */
2296 hMenus[3] = CreatePopupMenu();
2297 AppendMenuA(hMenus[3], MF_STRING, 0, "&Enabled");
2298 AppendMenuA(hMenus[3], MF_STRING|MF_DISABLED, 0, "&Disabled");
2299
2300 hMenus[2] = CreatePopupMenu();
2301 AppendMenuA(hMenus[2], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[3], "&Popup");
2302 AppendMenuA(hMenus[2], MF_STRING, 0, "&Enabled");
2303 AppendMenuA(hMenus[2], MF_STRING|MF_DISABLED, 0, "&Disabled");
2304
2305 hMenus[1] = CreateMenu();
2306 AppendMenuA(hMenus[1], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[2], "&Menu");
2307 AppendMenuA(hMenus[1], MF_STRING, 0, "&Enabled");
2308 AppendMenuA(hMenus[1], MF_STRING|MF_DISABLED, 0, "&Disabled");
2309
2310 SetMenu(hWnd, hMenus[1]);
2311 ShowWindow(hWnd, SW_SHOW);
2312 UpdateWindow(hWnd);
2313
2314 hThread = CreateThread(NULL, 0, test_menu_input_thread, hWnd, 0, &tid);
2315 while(1)
2316 {
2317 if (WAIT_TIMEOUT != WaitForSingleObject(hThread, 50))
2318 break;
2319 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2320 }
2321 DestroyWindow(hWnd);
2322 }
2323
2324 static void test_menu_flags( void )
2325 {
2326 HMENU hMenu, hPopupMenu;
2327
2328 hMenu = CreateMenu();
2329 hPopupMenu = CreatePopupMenu();
2330
2331 AppendMenuA(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2332
2333 AppendMenuA(hPopupMenu, MF_STRING | MF_HILITE | MF_DEFAULT, 101, "Item 1");
2334 InsertMenuA(hPopupMenu, 1, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 102, "Item 2");
2335 AppendMenuA(hPopupMenu, MF_STRING, 103, "Item 3");
2336 ModifyMenuA(hPopupMenu, 2, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 103, "Item 3");
2337
2338 ok(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_HILITE,
2339 "AppendMenu should accept MF_HILITE\n");
2340 ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2341 "InsertMenu should accept MF_HILITE\n");
2342 ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2343 "ModifyMenu should accept MF_HILITE\n");
2344
2345 ok(!(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_DEFAULT),
2346 "AppendMenu must not accept MF_DEFAULT\n");
2347 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_DEFAULT),
2348 "InsertMenu must not accept MF_DEFAULT\n");
2349 ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_DEFAULT),
2350 "ModifyMenu must not accept MF_DEFAULT\n");
2351
2352 DestroyMenu(hMenu);
2353 }
2354
2355 static void test_menu_hilitemenuitem( void )
2356 {
2357 HMENU hMenu, hPopupMenu;
2358 WNDCLASSA wclass;
2359 HWND hWnd;
2360 ATOM aclass;
2361
2362 wclass.lpszClassName = "HiliteMenuTestClass";
2363 wclass.style = CS_HREDRAW | CS_VREDRAW;
2364 wclass.lpfnWndProc = WndProc;
2365 wclass.hInstance = GetModuleHandleA( NULL );
2366 wclass.hIcon = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
2367 wclass.hCursor = LoadCursorA( 0, (LPCSTR)IDC_ARROW );
2368 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2369 wclass.lpszMenuName = 0;
2370 wclass.cbClsExtra = 0;
2371 wclass.cbWndExtra = 0;
2372 aclass = RegisterClassA( &wclass );
2373 ok (aclass, "HiliteMenuTest class could not be created\n");
2374 if (!aclass) return;
2375 hWnd = CreateWindowA( wclass.lpszClassName, "HiliteMenuTest",
2376 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2377 400, 200, NULL, NULL, wclass.hInstance, NULL);
2378 ok (hWnd != NULL, "HiliteMenuTest window could not be created\n");
2379 if (!hWnd) return;
2380
2381 hMenu = CreateMenu();
2382 hPopupMenu = CreatePopupMenu();
2383
2384 AppendMenuA(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2385
2386 AppendMenuA(hPopupMenu, MF_STRING, 101, "Item 1");
2387 AppendMenuA(hPopupMenu, MF_STRING, 102, "Item 2");
2388 AppendMenuA(hPopupMenu, MF_STRING, 103, "Item 3");
2389
2390 SetMenu(hWnd, hMenu);
2391
2392 /* test invalid arguments */
2393
2394 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2395 "HiliteMenuItem: Item 2 is hilited\n");
2396
2397 SetLastError(0xdeadbeef);
2398 todo_wine
2399 {
2400 ok(!HiliteMenuItem(NULL, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2401 "HiliteMenuItem: call should have failed.\n");
2402 }
2403 ok(GetLastError() == 0xdeadbeef || /* 9x */
2404 GetLastError() == ERROR_INVALID_WINDOW_HANDLE /* NT */,
2405 "HiliteMenuItem: expected error ERROR_INVALID_WINDOW_HANDLE, got: %d\n", GetLastError());
2406
2407 SetLastError(0xdeadbeef);
2408 ok(!HiliteMenuItem(hWnd, NULL, 1, MF_HILITE | MF_BYPOSITION),
2409 "HiliteMenuItem: call should have failed.\n");
2410 ok(GetLastError() == 0xdeadbeef || /* 9x */
2411 GetLastError() == ERROR_INVALID_MENU_HANDLE /* NT */,
2412 "HiliteMenuItem: expected error ERROR_INVALID_MENU_HANDLE, got: %d\n", GetLastError());
2413
2414 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2415 "HiliteMenuItem: Item 2 is hilited\n");
2416
2417 /* either MF_HILITE or MF_UNHILITE *and* MF_BYCOMMAND or MF_BYPOSITION need to be set */
2418
2419 SetLastError(0xdeadbeef);
2420 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_BYPOSITION),
2421 "HiliteMenuItem: call should have succeeded.\n");
2422 ok(GetLastError() == 0xdeadbeef,
2423 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2424
2425 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2426 "HiliteMenuItem: Item 2 is hilited\n");
2427
2428 SetLastError(0xdeadbeef);
2429 todo_wine
2430 {
2431 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE),
2432 "HiliteMenuItem: call should have succeeded.\n");
2433 }
2434 ok(GetLastError() == 0xdeadbeef,
2435 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2436
2437 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2438 "HiliteMenuItem: Item 2 is hilited\n");
2439
2440 /* hilite a menu item (by position) */
2441
2442 SetLastError(0xdeadbeef);
2443 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2444 "HiliteMenuItem: call should not have failed.\n");
2445 ok(GetLastError() == 0xdeadbeef,
2446 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2447
2448 todo_wine
2449 {
2450 ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2451 "HiliteMenuItem: Item 2 is not hilited\n");
2452 }
2453
2454 /* unhilite a menu item (by position) */
2455
2456 SetLastError(0xdeadbeef);
2457 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_UNHILITE | MF_BYPOSITION),
2458 "HiliteMenuItem: call should not have failed.\n");
2459 ok(GetLastError() == 0xdeadbeef,
2460 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2461
2462 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2463 "HiliteMenuItem: Item 2 is hilited\n");
2464
2465 /* hilite a menu item (by command) */
2466
2467 SetLastError(0xdeadbeef);
2468 ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_HILITE | MF_BYCOMMAND),
2469 "HiliteMenuItem: call should not have failed.\n");
2470 ok(GetLastError() == 0xdeadbeef,
2471 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2472
2473 todo_wine
2474 {
2475 ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2476 "HiliteMenuItem: Item 3 is not hilited\n");
2477 }
2478
2479 /* unhilite a menu item (by command) */
2480
2481 SetLastError(0xdeadbeef);
2482 ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_UNHILITE | MF_BYCOMMAND),
2483 "HiliteMenuItem: call should not have failed.\n");
2484 ok(GetLastError() == 0xdeadbeef,
2485 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2486
2487 ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE),
2488 "HiliteMenuItem: Item 3 is hilited\n");
2489
2490 DestroyWindow(hWnd);
2491 }
2492
2493 static void check_menu_items(HMENU hmenu, UINT checked_cmd, UINT checked_type,
2494 UINT checked_state)
2495 {
2496 INT i, count;
2497
2498 count = GetMenuItemCount(hmenu);
2499 ok (count != -1, "GetMenuItemCount returned -1\n");
2500
2501 for (i = 0; i < count; i++)
2502 {
2503 BOOL ret;
2504 MENUITEMINFOA mii;
2505
2506 memset(&mii, 0, sizeof(mii));
2507 mii.cbSize = sizeof(mii);
2508 mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU;
2509 ret = GetMenuItemInfoA(hmenu, i, TRUE, &mii);
2510 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2511 if (0)
2512 trace("item #%u: fType %04x, fState %04x, wID %u, hSubMenu %p\n",
2513 i, mii.fType, mii.fState, mii.wID, mii.hSubMenu);
2514
2515 if (mii.hSubMenu)
2516 {
2517 ok(mii.wID == (UINT_PTR)mii.hSubMenu, "id %u: wID should be equal to hSubMenu\n", checked_cmd);
2518 if (!GetMenuItemCount(mii.hSubMenu))
2519 {
2520 ok(mii.fType == checked_type, "id %u: expected fType %04x, got %04x\n", checked_cmd, checked_type, mii.fType);
2521 ok(mii.fState == checked_state, "id %u: expected fState %04x, got %04x\n", checked_cmd, checked_state, mii.fState);
2522 }
2523 check_menu_items(mii.hSubMenu, checked_cmd, checked_type, checked_state);
2524 }
2525 else
2526 {
2527 if (mii.wID == checked_cmd)
2528 {
2529 ok(mii.fType == checked_type, "id %u: expected fType %04x, got %04x\n", checked_cmd, checked_type, mii.fType);
2530 ok(mii.fState == checked_state, "id %u: expected fState %04x, got %04x\n", checked_cmd, checked_state, mii.fState);
2531 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2532 }
2533 else
2534 {
2535 ok(mii.fType != MFT_RADIOCHECK, "id %u: not expected fType MFT_RADIOCHECK on cmd %u\n", checked_cmd, mii.wID);
2536
2537 if (mii.fType == MFT_SEPARATOR)
2538 {
2539 ok(mii.fState == MFS_GRAYED, "id %u: expected fState MFS_GRAYED, got %04x\n", checked_cmd, mii.fState);
2540 ok(mii.wID == 0, "id %u: expected wID 0, got %u\n", checked_cmd, mii.wID);
2541 }
2542 else
2543 {
2544 ok(mii.fState == 0, "id %u: expected fState 0, got %04x\n", checked_cmd, mii.fState);
2545 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2546 }
2547 }
2548 }
2549 }
2550 }
2551
2552 static void clear_ftype_and_state(HMENU hmenu, UINT id, UINT flags)
2553 {
2554 BOOL ret;
2555 MENUITEMINFOA mii;
2556
2557 memset(&mii, 0, sizeof(mii));
2558 mii.cbSize = sizeof(mii);
2559 mii.fMask = MIIM_FTYPE | MIIM_STATE