23922053b089fb9c30afdd1d3c50ba55e8f39e78
[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)
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) {
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
1373 /* How is that with bitmaps? */
1374 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1375 TMII_GMII ( MIIM_TYPE, 80,
1376 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1377 NULL, OK, ER );
1378 TMII_DONE
1379 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1380 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1381 0, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1382 init, OK, ER );
1383 TMII_DONE
1384 /* MIIM_BITMAP does not like MFT_BITMAP */
1385 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, hbm, ER );
1386 TMII_DONE
1387 /* no problem with OWNERDRAWN */
1388 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1389 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1390 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1391 init, OK, ER );
1392 TMII_DONE
1393 /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1394 TMII_INSMI( MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER );
1395 TMII_DONE
1396
1397 /* menu with submenu */
1398 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1399 TMII_GMII ( MIIM_SUBMENU, 80,
1400 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1401 init, OK, ER );
1402 TMII_DONE
1403 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, empty, 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 /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1409 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1410 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1411 MFT_STRING|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1412 empty, OK, ER );
1413 TMII_GMII ( MIIM_SUBMENU|MIIM_FTYPE, 80,
1414 MFT_SEPARATOR, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1415 empty, OK, ER );
1416 TMII_DONE
1417 /* menu with invalid submenu */
1418 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, (HMENU)999, 0, 0, -1, txt, 0, 0, ER );
1419 TMII_DONE
1420 /* Separator */
1421 TMII_INSMI( MIIM_TYPE, MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1422 TMII_GMII ( MIIM_TYPE, 80,
1423 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1424 NULL, OK, ER );
1425 TMII_DONE
1426 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1427 TMII_GMII ( MIIM_TYPE, 80,
1428 MFT_BITMAP|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1429 NULL, OK, ER );
1430 TMII_DONE
1431 /* SEPARATOR and STRING go well together */
1432 /* BITMAP and STRING go well together */
1433 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1434 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1435 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1436 txt, OK, OK );
1437 TMII_DONE
1438 /* BITMAP, SEPARATOR and STRING go well together */
1439 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1440 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1441 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1442 txt, OK, OK );
1443 TMII_DONE
1444 /* last two tests, but use MIIM_TYPE to retrieve info */
1445 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1446 TMII_GMII ( MIIM_TYPE, 80,
1447 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1448 NULL, OK, OK );
1449 TMII_DONE
1450 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1451 TMII_GMII ( MIIM_TYPE, 80,
1452 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1453 NULL, OK, OK );
1454 TMII_DONE
1455 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1456 TMII_GMII ( MIIM_TYPE, 80,
1457 MFT_SEPARATOR|MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1458 NULL, OK, OK );
1459 TMII_DONE
1460 /* same three with MFT_OWNERDRAW */
1461 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1462 TMII_GMII ( MIIM_TYPE, 80,
1463 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1464 NULL, OK, OK );
1465 TMII_DONE
1466 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1467 TMII_GMII ( MIIM_TYPE, 80,
1468 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1469 NULL, OK, OK );
1470 TMII_DONE
1471 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1472 TMII_GMII ( MIIM_TYPE, 80,
1473 MFT_SEPARATOR|MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1474 NULL, OK, OK );
1475 TMII_DONE
1476
1477 TMII_INSMI( MIIM_STRING|MIIM_FTYPE|MIIM_ID, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1478 TMII_GMII ( MIIM_TYPE, 80,
1479 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1480 NULL, OK, OK );
1481 TMII_DONE
1482 /* test with modifymenu: string is preserved after setting OWNERDRAW */
1483 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1484 TMII_MODM( MFT_OWNERDRAW, -1, (void*)787 );
1485 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_DATA, 80,
1486 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 787, string, 4, 0,
1487 txt, OK, OK );
1488 TMII_DONE
1489 /* same with bitmap: now the text is cleared */
1490 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1491 TMII_MODM( MFT_BITMAP, 545, hbm );
1492 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1493 MFT_BITMAP, 0, 545, 0, 0, 0, 0, string, 0, hbm,
1494 empty, OK, ER );
1495 TMII_DONE
1496 /* start with bitmap: now setting text clears it (though he flag is raised) */
1497 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1498 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1499 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 0, hbm,
1500 empty, OK, ER );
1501 TMII_MODM( MFT_STRING, 545, txt );
1502 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1503 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 4, 0,
1504 txt, OK, OK );
1505 TMII_DONE
1506 /*repeat with text NULL */
1507 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1508 TMII_MODM( MFT_STRING, 545, NULL );
1509 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1510 MFT_SEPARATOR, 0, 545, 0, 0, 0, 0, string, 0, 0,
1511 empty, OK, ER );
1512 TMII_DONE
1513 /* repeat with text "" */
1514 TMII_INSMI( MIIM_BITMAP, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1515 TMII_MODM( MFT_STRING, 545, empty );
1516 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1517 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 0, 0,
1518 empty, OK, ER );
1519 TMII_DONE
1520 /* start with bitmap: set ownerdraw */
1521 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1522 TMII_MODM( MFT_OWNERDRAW, -1, (void *)232 );
1523 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_DATA, 80,
1524 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 232, string, 0, hbm,
1525 empty, OK, ER );
1526 TMII_DONE
1527 /* ask nothing */
1528 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1529 TMII_GMII ( 0, 80,
1530 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1531 init, OK, OK );
1532 TMII_DONE
1533 /* some tests with small cbSize: the hbmpItem is to be ignored */
1534 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1535 TMII_GMII ( MIIM_TYPE, 80,
1536 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1537 NULL, OK, ER );
1538 TMII_DONE
1539 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1540 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1541 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, NULL,
1542 init, OK, ER );
1543 TMII_DONE
1544 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1545 TMII_GMII ( MIIM_TYPE, 80,
1546 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, NULL,
1547 txt, OK, OK );
1548 TMII_DONE
1549 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1550 TMII_GMII ( MIIM_TYPE, 80,
1551 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1552 NULL, OK, OK );
1553 TMII_DONE
1554 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1555 TMII_GMII ( MIIM_TYPE, 80,
1556 MFT_OWNERDRAW, 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_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1560 TMII_GMII ( MIIM_TYPE, 80,
1561 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1562 NULL, OK, OK );
1563 TMII_DONE
1564 /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus */
1565 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1566 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1567 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1568 NULL, OK, ER );
1569 TMII_DONE
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, 80,
1572 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1573 NULL, OK, ER );
1574 TMII_DONE
1575 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1576 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1577 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1578 NULL, OK, ER );
1579 TMII_DONE
1580 /* set a string menu to ownerdraw with MIIM_TYPE */
1581 TMII_INSMI( MIIM_TYPE, MFT_STRING, -2, -2, 0, 0, 0, -2, txt, -2, 0, OK );
1582 TMII_SMII ( MIIM_TYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1583 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1584 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1585 txt, OK, OK );
1586 TMII_DONE
1587 /* test with modifymenu add submenu */
1588 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1589 TMII_MODM( MF_POPUP, (UINT_PTR)submenu, txt );
1590 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_SUBMENU, 80,
1591 MFT_STRING, 0, 0, submenu, 0, 0, 0, string, 4, 0,
1592 txt, OK, OK );
1593 TMII_GMII ( MIIM_TYPE, 80,
1594 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1595 txt, OK, OK );
1596 TMII_DONE
1597 /* MFT_SEPARATOR bit is kept when the text is added */
1598 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1599 TMII_SMII( MIIM_STRING, 0, 0, 0, 0, 0, 0, 0, txt, 0, 0 );
1600 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1601 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, 0,
1602 txt, OK, OK );
1603 TMII_DONE
1604 /* MFT_SEPARATOR bit is kept when bitmap is added */
1605 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1606 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm );
1607 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1608 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1609 init, OK, ER );
1610 TMII_DONE
1611 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1612 Only the low word of the dwTypeData is used.
1613 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1614 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1615 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1616 TMII_GMII ( MIIM_TYPE, 80,
1617 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1618 NULL, OK, OK );
1619 TMII_DONE
1620 /* Type flags */
1621 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1622 TMII_GMII ( MIIM_TYPE, 80,
1623 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1624 NULL, OK, OK );
1625 TMII_DONE
1626 /* State flags */
1627 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1628 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1629 TMII_GMII ( MIIM_STATE, 80,
1630 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1631 NULL, OK, OK );
1632 TMII_DONE
1633 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1634 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1635 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1636 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1637 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1638 NULL, OK, OK );
1639 TMII_DONE
1640 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1641 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1642 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1643 TMII_GMII ( MIIM_FTYPE, 80,
1644 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1645 NULL, OK, OK );
1646 TMII_GMII ( MIIM_TYPE, 80,
1647 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1648 NULL, OK, OK );
1649 TMII_GMII ( MIIM_FTYPE, 80,
1650 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1651 NULL, OK, OK );
1652 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1653 TMII_GMII ( MIIM_TYPE, 80,
1654 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1655 NULL, OK, OK );
1656 TMII_DONE
1657 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1658 Only the low word of the dwTypeData is used.
1659 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1660 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1661 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1662 TMII_GMII ( MIIM_TYPE, 80,
1663 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1664 NULL, OK, OK );
1665 TMII_DONE
1666 /* Type flags */
1667 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1668 TMII_GMII ( MIIM_TYPE, 80,
1669 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1670 NULL, OK, OK );
1671 TMII_DONE
1672 /* State flags */
1673 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1674 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1675 TMII_GMII ( MIIM_STATE, 80,
1676 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1677 NULL, OK, OK );
1678 TMII_DONE
1679 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1680 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1681 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1682 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1683 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1684 NULL, OK, OK );
1685 TMII_DONE
1686 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1687 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1688 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1689 TMII_GMII ( MIIM_FTYPE, 80,
1690 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1691 NULL, OK, OK );
1692 TMII_GMII ( MIIM_TYPE, 80,
1693 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1694 NULL, OK, OK );
1695 TMII_GMII ( MIIM_FTYPE, 80,
1696 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1697 NULL, OK, OK );
1698 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1699 TMII_GMII ( MIIM_TYPE, 80,
1700 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1701 NULL, OK, OK );
1702 TMII_DONE
1703 } while( !(ansi = !ansi) );
1704 DeleteObject( hbm);
1705 }
1706
1707 /*
1708 The following tests try to confirm the algorithm used to return the menu items
1709 when there is a collision between a menu item and a popup menu
1710 */
1711 static void test_menu_search_bycommand( void )
1712 {
1713 HMENU hmenu, hmenuSub, hmenuSub2;
1714 MENUITEMINFOA info;
1715 BOOL rc;
1716 UINT id;
1717 char strback[0x80];
1718 char strIn[0x80];
1719 static CHAR menuitem[] = "MenuItem",
1720 menuitem2[] = "MenuItem 2";
1721
1722 /* Case 1: Menu containing a menu item */
1723 hmenu = CreateMenu();
1724
1725 memset( &info, 0, sizeof info );
1726 info.cbSize = sizeof info;
1727 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1728 info.fType = MFT_STRING;
1729 strcpy(strIn, "Case 1 MenuItem");
1730 info.dwTypeData = strIn;
1731 info.wID = (UINT) 0x1234;
1732
1733 rc = InsertMenuItemA(hmenu, 0, TRUE, &info );
1734 ok (rc, "Inserting the menuitem failed\n");
1735
1736 id = GetMenuItemID(hmenu, 0);
1737 ok (id == 0x1234, "Getting the menuitem id failed(gave %x)\n", id);
1738
1739 /* Confirm the menuitem was given the id supplied (getting by position) */
1740 memset( &info, 0, sizeof info );
1741 strback[0] = 0x00;
1742 info.cbSize = sizeof(MENUITEMINFOA);
1743 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1744 info.dwTypeData = strback;
1745 info.cch = sizeof(strback);
1746
1747 rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info); /* Get by position */
1748 ok (rc, "Getting the menu items info failed\n");
1749 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1750 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1751
1752 /* Search by id - Should return the item */
1753 memset( &info, 0, sizeof info );
1754 strback[0] = 0x00;
1755 info.cbSize = sizeof(MENUITEMINFOA);
1756 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1757 info.dwTypeData = strback;
1758 info.cch = sizeof(strback);
1759 rc = GetMenuItemInfoA(hmenu, 0x1234, FALSE, &info); /* Get by ID */
1760
1761 ok (rc, "Getting the menu items info failed\n");
1762 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1763 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1764
1765 DestroyMenu( hmenu );
1766
1767 /* Case 2: Menu containing a popup menu */
1768 hmenu = CreateMenu();
1769 hmenuSub = CreateMenu();
1770
1771 strcpy(strIn, "Case 2 SubMenu");
1772 rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, strIn);
1773 ok (rc, "Inserting the popup menu into the main menu failed\n");
1774
1775 id = GetMenuItemID(hmenu, 0);
1776 ok (id == -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id);
1777
1778 /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
1779 memset( &info, 0, sizeof info );
1780 strback[0] = 0x00;
1781 info.cbSize = sizeof(MENUITEMINFOA);
1782 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1783 info.dwTypeData = strback;
1784 info.cch = sizeof(strback);
1785 info.wID = 0xdeadbeef;
1786
1787 rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info); /* Get by position */
1788 ok (rc, "Getting the menu items info failed\n");
1789 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the menuitem\n");
1790 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1791
1792 /* Search by id - returns the popup menu itself */
1793 memset( &info, 0, sizeof info );
1794 strback[0] = 0x00;
1795 info.cbSize = sizeof(MENUITEMINFOA);
1796 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1797 info.dwTypeData = strback;
1798 info.cch = sizeof(strback);
1799 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1800
1801 ok (rc, "Getting the menu items info failed\n");
1802 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1803 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1804
1805 /*
1806 Now add an item after it with the same id
1807 */
1808 memset( &info, 0, sizeof info );
1809 info.cbSize = sizeof info;
1810 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1811 info.fType = MFT_STRING;
1812 strcpy(strIn, "Case 2 MenuItem 1");
1813 info.dwTypeData = strIn;
1814 info.wID = (UINT_PTR) hmenuSub;
1815 rc = InsertMenuItemA(hmenu, -1, TRUE, &info );
1816 ok (rc, "Inserting the menuitem failed\n");
1817
1818 /* Search by id - returns the item which follows the popup menu */
1819 memset( &info, 0, sizeof info );
1820 strback[0] = 0x00;
1821 info.cbSize = sizeof(MENUITEMINFOA);
1822 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1823 info.dwTypeData = strback;
1824 info.cch = sizeof(strback);
1825 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1826
1827 ok (rc, "Getting the menu items info failed\n");
1828 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1829 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1830
1831 /*
1832 Now add an item before the popup (with the same id)
1833 */
1834 memset( &info, 0, sizeof info );
1835 info.cbSize = sizeof info;
1836 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1837 info.fType = MFT_STRING;
1838 strcpy(strIn, "Case 2 MenuItem 2");
1839 info.dwTypeData = strIn;
1840 info.wID = (UINT_PTR) hmenuSub;
1841 rc = InsertMenuItemA(hmenu, 0, TRUE, &info );
1842 ok (rc, "Inserting the menuitem failed\n");
1843
1844 /* Search by id - returns the item which precedes the popup menu */
1845 memset( &info, 0, sizeof info );
1846 strback[0] = 0x00;
1847 info.cbSize = sizeof(MENUITEMINFOA);
1848 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1849 info.dwTypeData = strback;
1850 info.cch = sizeof(strback);
1851 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1852
1853 ok (rc, "Getting the menu items info failed\n");
1854 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1855 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1856
1857 DestroyMenu( hmenu );
1858 DestroyMenu( hmenuSub );
1859
1860 /*
1861 Case 3: Menu containing a popup menu which in turn
1862 contains 2 items with the same id as the popup itself
1863 */
1864
1865 hmenu = CreateMenu();
1866 hmenuSub = CreateMenu();
1867
1868 memset( &info, 0, sizeof info );
1869 info.cbSize = sizeof info;
1870 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1871 info.fType = MFT_STRING;
1872 info.dwTypeData = menuitem;
1873 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1874
1875 rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1876 ok (rc, "Inserting the popup menu into the main menu failed\n");
1877
1878 rc = InsertMenuItemA(hmenuSub, 0, TRUE, &info );
1879 ok (rc, "Inserting the sub menu menuitem failed\n");
1880
1881 memset( &info, 0, sizeof info );
1882 info.cbSize = sizeof info;
1883 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1884 info.fType = MFT_STRING;
1885 info.dwTypeData = menuitem2;
1886 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1887
1888 rc = InsertMenuItemA(hmenuSub, 1, TRUE, &info );
1889 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
1890
1891 /* Prove that you can't query the id of a popup directly (By position) */
1892 id = GetMenuItemID(hmenu, 0);
1893 ok (id == -1, "Getting the sub menu id should have failed because it's a popup (gave %x)\n", id);
1894
1895 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1896 memset( &info, 0, sizeof info );
1897 strback[0] = 0x00;
1898 info.cbSize = sizeof(MENUITEMINFOA);
1899 info.fMask = MIIM_STRING | MIIM_ID;
1900 info.dwTypeData = strback;
1901 info.cch = sizeof(strback);
1902
1903 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
1904 ok (rc, "Getting the menus info failed\n");
1905 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
1906 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1907 DestroyMenu( hmenu );
1908 DestroyMenu( hmenuSub );
1909
1910 /*
1911 Case 4: Menu containing 2 popup menus, the second
1912 contains 2 items with the same id as the first popup menu
1913 */
1914 hmenu = CreateMenu();
1915 hmenuSub = CreateMenu();
1916 hmenuSub2 = CreateMenu();
1917
1918 rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1919 ok (rc, "Inserting the popup menu into the main menu failed\n");
1920
1921 rc = InsertMenuA(hmenu, 1, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub2, "Submenu2");
1922 ok (rc, "Inserting the popup menu into the main menu failed\n");
1923
1924 memset( &info, 0, sizeof info );
1925 info.cbSize = sizeof info;
1926 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1927 info.fType = MFT_STRING;
1928 info.dwTypeData = menuitem;
1929 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1930
1931 rc = InsertMenuItemA(hmenuSub2, 0, TRUE, &info );
1932 ok (rc, "Inserting the sub menu menuitem failed\n");
1933
1934 memset( &info, 0, sizeof info );
1935 info.cbSize = sizeof info;
1936 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1937 info.fType = MFT_STRING;
1938 info.dwTypeData = menuitem2;
1939 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1940
1941 rc = InsertMenuItemA(hmenuSub2, 1, TRUE, &info );
1942 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
1943
1944 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1945 memset( &info, 0, sizeof info );
1946 strback[0] = 0x00;
1947 info.cbSize = sizeof(MENUITEMINFOA);
1948 info.fMask = MIIM_STRING | MIIM_ID;
1949 info.dwTypeData = strback;
1950 info.cch = sizeof(strback);
1951
1952 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
1953 ok (rc, "Getting the menus info failed\n");
1954 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
1955 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1956
1957 memset( &info, 0, sizeof info );
1958 strback[0] = 0x00;
1959 info.cbSize = sizeof(MENUITEMINFOA);
1960 info.fMask = MIIM_STRING | MIIM_ID;
1961 info.dwTypeData = strback;
1962 info.cch = sizeof(strback);
1963
1964 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub2, FALSE, &info);
1965 ok (rc, "Getting the menus info failed\n");
1966 ok (info.wID == (UINT_PTR)hmenuSub2, "IDs differ for popup menu\n");
1967 ok (!strcmp(info.dwTypeData, "Submenu2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1968
1969 DestroyMenu( hmenu );
1970 DestroyMenu( hmenuSub );
1971 DestroyMenu( hmenuSub2 );
1972
1973
1974 /*
1975 Case 5: Menu containing a popup menu which in turn
1976 contains an item with a different id than the popup menu.
1977 This tests the fallback to a popup menu ID.
1978 */
1979
1980 hmenu = CreateMenu();
1981 hmenuSub = CreateMenu();
1982
1983 rc = AppendMenuA(hmenu, MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1984 ok (rc, "Appending the popup menu to the main menu failed\n");
1985
1986 rc = AppendMenuA(hmenuSub, MF_STRING, 102, "Item");
1987 ok (rc, "Appending the item to the popup menu failed\n");
1988
1989 /* Set the ID for hmenuSub */
1990 info.cbSize = sizeof(info);
1991 info.fMask = MIIM_ID;
1992 info.wID = 101;
1993
1994 rc = SetMenuItemInfoA(hmenu, 0, TRUE, &info);
1995 ok(rc, "Setting the ID for the popup menu failed\n");
1996
1997 /* Check if the ID has been set */
1998 info.wID = 0;
1999 rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info);
2000 ok(rc, "Getting the ID for the popup menu failed\n");
2001 ok(info.wID == 101, "The ID for the popup menu has not been set\n");
2002
2003 /* Prove getting the item info via ID returns the popup menu */
2004 memset( &info, 0, sizeof(info));
2005 strback[0] = 0x00;
2006 info.cbSize = sizeof(MENUITEMINFOA);
2007 info.fMask = MIIM_STRING | MIIM_ID;
2008 info.dwTypeData = strback;
2009 info.cch = sizeof(strback);
2010
2011 rc = GetMenuItemInfoA(hmenu, 101, FALSE, &info);
2012 ok (rc, "Getting the menu info failed\n");
2013 ok (info.wID == 101, "IDs differ\n");
2014 ok (!strcmp(info.dwTypeData, "Submenu"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2015
2016 /* Also look for the menu item */
2017 memset( &info, 0, sizeof(info));
2018 strback[0] = 0x00;
2019 info.cbSize = sizeof(MENUITEMINFOA);
2020 info.fMask = MIIM_STRING | MIIM_ID;
2021 info.dwTypeData = strback;
2022 info.cch = sizeof(strback);
2023
2024 rc = GetMenuItemInfoA(hmenu, 102, FALSE, &info);
2025 ok (rc, "Getting the menu info failed\n");
2026 ok (info.wID == 102, "IDs differ\n");
2027 ok (!strcmp(info.dwTypeData, "Item"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2028
2029 DestroyMenu(hmenu);
2030 DestroyMenu(hmenuSub);
2031 }
2032
2033 struct menu_item_pair_s {
2034 UINT uMenu; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
2035 * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
2036 * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
2037 UINT uItem;
2038 };
2039
2040 static struct menu_mouse_tests_s {
2041 DWORD type;
2042 struct menu_item_pair_s menu_item_pairs[5]; /* for mousing */
2043 WORD wVk[5]; /* keys */
2044 BOOL bMenuVisible;
2045 BOOL _todo_wine;
2046 } menu_tests[] = {
2047 /* for each test, send keys or clicks and check for menu visibility */
2048 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE }, /* test 0 */
2049 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
2050 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
2051 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2052 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
2053 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2054 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2055 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, VK_ESCAPE, 0}, FALSE, FALSE },
2056 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', VK_ESCAPE, 0}, TRUE, FALSE },
2057 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
2058 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2059 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2060 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2061 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2062 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
2063 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2064 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
2065 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2066 { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, TRUE, FALSE },
2067 { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, FALSE, FALSE },
2068
2069 { INPUT_MOUSE, {{1, 2}, {0}}, {0}, TRUE, TRUE }, /* test 20 */
2070 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2071 { INPUT_MOUSE, {{1, 0}, {0}}, {0}, TRUE, TRUE },
2072 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2073 { INPUT_MOUSE, {{1, 0}, {2, 2}, {0}}, {0}, TRUE, TRUE },
2074 { INPUT_MOUSE, {{2, 1}, {0}}, {0}, FALSE, FALSE },
2075 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
2076 { INPUT_MOUSE, {{3, 0}, {0}}, {0}, FALSE, FALSE },
2077 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
2078 { INPUT_MOUSE, {{3, 1}, {0}}, {0}, TRUE, TRUE },
2079 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2080 { -1 }
2081 };
2082
2083 static void send_key(WORD wVk)
2084 {
2085 TEST_INPUT i[2];
2086 memset(i, 0, sizeof(i));
2087 i[0].type = i[1].type = INPUT_KEYBOARD;
2088 i[0].u.ki.wVk = i[1].u.ki.wVk = wVk;
2089 i[1].u.ki.dwFlags = KEYEVENTF_KEYUP;
2090 pSendInput(2, (INPUT *) i, sizeof(INPUT));
2091 }
2092
2093 static BOOL click_menu(HANDLE hWnd, struct menu_item_pair_s *mi)
2094 {
2095 HMENU hMenu = hMenus[mi->uMenu];
2096 TEST_INPUT i[3];
2097 MSG msg;
2098 RECT r;
2099 int screen_w = GetSystemMetrics(SM_CXSCREEN);
2100 int screen_h = GetSystemMetrics(SM_CYSCREEN);
2101 BOOL ret = GetMenuItemRect(mi->uMenu > 2 ? NULL : hWnd, hMenu, mi->uItem, &r);
2102 if(!ret) return FALSE;
2103
2104 memset(i, 0, sizeof(i));
2105 i[0].type = i[1].type = i[2].type = INPUT_MOUSE;
2106 i[0].u.mi.dx = i[1].u.mi.dx = i[2].u.mi.dx
2107 = ((r.left + 5) * 65535) / screen_w;
2108 i[0].u.mi.dy = i[1].u.mi.dy = i[2].u.mi.dy
2109 = ((r.top + 5) * 65535) / screen_h;
2110 i[0].u.mi.dwFlags = i[1].u.mi.dwFlags = i[2].u.mi.dwFlags
2111 = MOUSEEVENTF_ABSOLUTE;
2112 i[0].u.mi.dwFlags |= MOUSEEVENTF_MOVE;
2113 i[1].u.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
2114 i[2].u.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
2115 ret = pSendInput(3, (INPUT *) i, sizeof(INPUT));
2116
2117 /* hack to prevent mouse message buildup in Wine */
2118 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
2119 return ret;
2120 }
2121
2122 static DWORD WINAPI test_menu_input_thread(LPVOID lpParameter)
2123 {
2124 int i, j;
2125 HANDLE hWnd = lpParameter;
2126
2127 Sleep(500);
2128 /* mixed keyboard/mouse test */
2129 for (i = 0; menu_tests[i].type != -1; i++)
2130 {
2131 BOOL ret = TRUE;
2132 int elapsed = 0;
2133
2134 got_input = i && menu_tests[i-1].bMenuVisible;
2135
2136 if (menu_tests[i].type == INPUT_KEYBOARD)
2137 for (j = 0; menu_tests[i].wVk[j] != 0; j++)
2138 send_key(menu_tests[i].wVk[j]);
2139 else
2140 for (j = 0; menu_tests[i].menu_item_pairs[j].uMenu != 0; j++)
2141 if (!(ret = click_menu(hWnd, &menu_tests[i].menu_item_pairs[j]))) break;
2142
2143 if (!ret)
2144 {
2145 skip( "test %u: failed to send input\n", i );
2146 PostMessageA( hWnd, WM_CANCELMODE, 0, 0 );
2147 return 0;
2148 }
2149 while (menu_tests[i].bMenuVisible != bMenuVisible)
2150 {
2151 if (elapsed > 200)
2152 break;
2153 elapsed += 20;
2154 Sleep(20);
2155 }
2156
2157 if (!got_input)
2158 {
2159 skip( "test %u: didn't receive input\n", i );
2160 PostMessageA( hWnd, WM_CANCELMODE, 0, 0 );
2161 return 0;
2162 }
2163
2164 if (menu_tests[i]._todo_wine)
2165 {
2166 todo_wine {
2167 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
2168 }
2169 }
2170 else
2171 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
2172 }
2173 return 0;
2174 }
2175
2176 static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam,
2177 LPARAM lParam)
2178 {
2179 switch (msg) {
2180 case WM_ENTERMENULOOP:
2181 bMenuVisible = TRUE;
2182 break;
2183 case WM_INITMENUPOPUP:
2184 case WM_UNINITMENUPOPUP:
2185 case WM_EXITMENULOOP:
2186 case WM_MENUSELECT:
2187 break;
2188
2189 case WM_KEYDOWN:
2190 case WM_SYSKEYDOWN:
2191 case WM_MOUSEMOVE:
2192 case WM_LBUTTONDOWN:
2193 case WM_LBUTTONUP:
2194 case WM_NCMOUSEMOVE:
2195 case WM_NCLBUTTONDOWN:
2196 case WM_NCLBUTTONUP:
2197 got_input = TRUE;
2198 /* fall through */
2199 default:
2200 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2201 }
2202
2203 if(pGetMenuBarInfo)
2204 {
2205 MENUBARINFO mbi;
2206 HMENU hmenu;
2207 UINT state;
2208 BOOL br;
2209
2210 mbi.cbSize = sizeof(MENUBARINFO);
2211
2212 /* get info for the menu */
2213 br = pGetMenuBarInfo(hWnd, OBJID_MENU, 0, &mbi);
2214 ok(br, "msg %x: GetMenuBarInfo failed\n", msg);
2215 hmenu = GetMenu(hWnd);
2216 ok(!mbi.hwndMenu, "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected NULL\n",
2217 msg, mbi.hwndMenu);
2218 ok(mbi.hMenu == hmenu, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2219 msg, mbi.hMenu, hmenu);
2220 ok(!bMenuVisible == !mbi.fBarFocused, "msg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2221 msg, mbi.fBarFocused != 0);
2222 ok(!bMenuVisible == !mbi.fFocused, "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n",
2223 msg, mbi.fFocused != 0);
2224
2225 /* get info for the menu's first item */
2226 br = pGetMenuBarInfo(hWnd, OBJID_MENU, 1, &mbi);
2227 ok(br, "msg %x: GetMenuBarInfo failed\n", msg);
2228 state = GetMenuState(hmenu, 0, MF_BYPOSITION);
2229 if (pGetMenuInfo) /* Skip on NT */
2230 {
2231 /* Native returns handle to destroyed window */
2232 if (msg==WM_UNINITMENUPOPUP && popmenu==1)
2233 todo_wine ok(!mbi.hwndMenu == !popmenu,
2234 "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected %sNULL\n",
2235 msg, mbi.hwndMenu, popmenu ? "not " : "");
2236 else
2237 ok(!mbi.hwndMenu == !popmenu,
2238 "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected %sNULL\n",
2239 msg, mbi.hwndMenu, popmenu ? "not " : "");
2240 }
2241 ok(mbi.hMenu == hmenu, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2242 msg, mbi.hMenu, hmenu);
2243 ok(!bMenuVisible == !mbi.fBarFocused, "nsg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2244 msg, mbi.fBarFocused != 0);
2245 ok(!(bMenuVisible && (state & MF_HILITE)) == !mbi.fFocused,
2246 "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n", msg, mbi.fFocused != 0);
2247 }
2248
2249 if (msg == WM_EXITMENULOOP)
2250 bMenuVisible = FALSE;
2251 else if (msg == WM_INITMENUPOPUP)
2252 popmenu++;
2253 else if (msg == WM_UNINITMENUPOPUP)
2254 popmenu--;
2255 return 0;
2256 }
2257
2258 static void test_menu_input(void) {
2259 MSG msg;
2260 WNDCLASSA wclass;
2261 HINSTANCE hInstance = GetModuleHandleA( NULL );
2262 HANDLE hThread, hWnd;
2263 DWORD tid;
2264 ATOM aclass;
2265
2266 if (!pSendInput)
2267 {
2268 win_skip("SendInput is not available\n");
2269 return;
2270 }
2271
2272 wclass.lpszClassName = "MenuTestClass";
2273 wclass.style = CS_HREDRAW | CS_VREDRAW;
2274 wclass.lpfnWndProc = WndProc;
2275 wclass.hInstance = hInstance;
2276 wclass.hIcon = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
2277 wclass.hCursor = LoadCursorA( 0, (LPCSTR)IDC_ARROW );
2278 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2279 wclass.lpszMenuName = 0;
2280 wclass.cbClsExtra = 0;
2281 wclass.cbWndExtra = 0;
2282 aclass = RegisterClassA( &wclass );
2283 ok (aclass, "MenuTest class not created\n");
2284 if (!aclass) return;
2285 hWnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
2286 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2287 400, 200, NULL, NULL, hInstance, NULL);
2288 ok (hWnd != NULL, "MenuTest window not created\n");
2289 if (!hWnd) return;
2290 /* fixed menus */
2291 hMenus[3] = CreatePopupMenu();
2292 AppendMenuA(hMenus[3], MF_STRING, 0, "&Enabled");
2293 AppendMenuA(hMenus[3], MF_STRING|MF_DISABLED, 0, "&Disabled");
2294
2295 hMenus[2] = CreatePopupMenu();
2296 AppendMenuA(hMenus[2], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[3], "&Popup");
2297 AppendMenuA(hMenus[2], MF_STRING, 0, "&Enabled");
2298 AppendMenuA(hMenus[2], MF_STRING|MF_DISABLED, 0, "&Disabled");
2299
2300 hMenus[1] = CreateMenu();
2301 AppendMenuA(hMenus[1], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[2], "&Menu");
2302 AppendMenuA(hMenus[1], MF_STRING, 0, "&Enabled");
2303 AppendMenuA(hMenus[1], MF_STRING|MF_DISABLED, 0, "&Disabled");
2304
2305 SetMenu(hWnd, hMenus[1]);
2306 ShowWindow(hWnd, SW_SHOW);
2307 UpdateWindow(hWnd);
2308
2309 hThread = CreateThread(NULL, 0, test_menu_input_thread, hWnd, 0, &tid);
2310 while(1)
2311 {
2312 if (WAIT_TIMEOUT != WaitForSingleObject(hThread, 50))
2313 break;
2314 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2315 }
2316 DestroyWindow(hWnd);
2317 }
2318
2319 static void test_menu_flags( void )
2320 {
2321 HMENU hMenu, hPopupMenu;
2322
2323 hMenu = CreateMenu();
2324 hPopupMenu = CreatePopupMenu();
2325
2326 AppendMenuA(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2327
2328 AppendMenuA(hPopupMenu, MF_STRING | MF_HILITE | MF_DEFAULT, 101, "Item 1");
2329 InsertMenuA(hPopupMenu, 1, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 102, "Item 2");
2330 AppendMenuA(hPopupMenu, MF_STRING, 103, "Item 3");
2331 ModifyMenuA(hPopupMenu, 2, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 103, "Item 3");
2332
2333 ok(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_HILITE,
2334 "AppendMenu should accept MF_HILITE\n");
2335 ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2336 "InsertMenu should accept MF_HILITE\n");
2337 ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2338 "ModifyMenu should accept MF_HILITE\n");
2339
2340 ok(!(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_DEFAULT),
2341 "AppendMenu must not accept MF_DEFAULT\n");
2342 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_DEFAULT),
2343 "InsertMenu must not accept MF_DEFAULT\n");
2344 ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_DEFAULT),
2345 "ModifyMenu must not accept MF_DEFAULT\n");
2346
2347 DestroyMenu(hMenu);
2348 }
2349
2350 static void test_menu_hilitemenuitem( void )
2351 {
2352 HMENU hMenu, hPopupMenu;
2353 WNDCLASSA wclass;
2354 HWND hWnd;
2355 ATOM aclass;
2356
2357 wclass.lpszClassName = "HiliteMenuTestClass";
2358 wclass.style = CS_HREDRAW | CS_VREDRAW;
2359 wclass.lpfnWndProc = WndProc;
2360 wclass.hInstance = GetModuleHandleA( NULL );
2361 wclass.hIcon = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
2362 wclass.hCursor = LoadCursorA( 0, (LPCSTR)IDC_ARROW );
2363 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2364 wclass.lpszMenuName = 0;
2365 wclass.cbClsExtra = 0;
2366 wclass.cbWndExtra = 0;
2367 aclass = RegisterClassA( &wclass );
2368 ok (aclass, "HiliteMenuTest class could not be created\n");
2369 if (!aclass) return;
2370 hWnd = CreateWindowA( wclass.lpszClassName, "HiliteMenuTest",
2371 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2372 400, 200, NULL, NULL, wclass.hInstance, NULL);
2373 ok (hWnd != NULL, "HiliteMenuTest window could not be created\n");
2374 if (!hWnd) return;
2375
2376 hMenu = CreateMenu();
2377 hPopupMenu = CreatePopupMenu();
2378
2379 AppendMenuA(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2380
2381 AppendMenuA(hPopupMenu, MF_STRING, 101, "Item 1");
2382 AppendMenuA(hPopupMenu, MF_STRING, 102, "Item 2");
2383 AppendMenuA(hPopupMenu, MF_STRING, 103, "Item 3");
2384
2385 SetMenu(hWnd, hMenu);
2386
2387 /* test invalid arguments */
2388
2389 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2390 "HiliteMenuItem: Item 2 is hilited\n");
2391
2392 SetLastError(0xdeadbeef);
2393 todo_wine
2394 {
2395 ok(!HiliteMenuItem(NULL, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2396 "HiliteMenuItem: call should have failed.\n");
2397 }
2398 ok(GetLastError() == 0xdeadbeef || /* 9x */
2399 GetLastError() == ERROR_INVALID_WINDOW_HANDLE /* NT */,
2400 "HiliteMenuItem: expected error ERROR_INVALID_WINDOW_HANDLE, got: %d\n", GetLastError());
2401
2402 SetLastError(0xdeadbeef);
2403 ok(!HiliteMenuItem(hWnd, NULL, 1, MF_HILITE | MF_BYPOSITION),
2404 "HiliteMenuItem: call should have failed.\n");
2405 ok(GetLastError() == 0xdeadbeef || /* 9x */
2406 GetLastError() == ERROR_INVALID_MENU_HANDLE /* NT */,
2407 "HiliteMenuItem: expected error ERROR_INVALID_MENU_HANDLE, got: %d\n", GetLastError());
2408
2409 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2410 "HiliteMenuItem: Item 2 is hilited\n");
2411
2412 /* either MF_HILITE or MF_UNHILITE *and* MF_BYCOMMAND or MF_BYPOSITION need to be set */
2413
2414 SetLastError(0xdeadbeef);
2415 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_BYPOSITION),
2416 "HiliteMenuItem: call should have succeeded.\n");
2417 ok(GetLastError() == 0xdeadbeef,
2418 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2419
2420 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2421 "HiliteMenuItem: Item 2 is hilited\n");
2422
2423 SetLastError(0xdeadbeef);
2424 todo_wine
2425 {
2426 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE),
2427 "HiliteMenuItem: call should have succeeded.\n");
2428 }
2429 ok(GetLastError() == 0xdeadbeef,
2430 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2431
2432 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2433 "HiliteMenuItem: Item 2 is hilited\n");
2434
2435 /* hilite a menu item (by position) */
2436
2437 SetLastError(0xdeadbeef);
2438 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2439 "HiliteMenuItem: call should not have failed.\n");
2440 ok(GetLastError() == 0xdeadbeef,
2441 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2442
2443 todo_wine
2444 {
2445 ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2446 "HiliteMenuItem: Item 2 is not hilited\n");
2447 }
2448
2449 /* unhilite a menu item (by position) */
2450
2451 SetLastError(0xdeadbeef);
2452 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_UNHILITE | MF_BYPOSITION),
2453 "HiliteMenuItem: call should not have failed.\n");
2454 ok(GetLastError() == 0xdeadbeef,
2455 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2456
2457 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2458 "HiliteMenuItem: Item 2 is hilited\n");
2459
2460 /* hilite a menu item (by command) */
2461
2462 SetLastError(0xdeadbeef);
2463 ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_HILITE | MF_BYCOMMAND),
2464 "HiliteMenuItem: call should not have failed.\n");
2465 ok(GetLastError() == 0xdeadbeef,
2466 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2467
2468 todo_wine
2469 {
2470 ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2471 "HiliteMenuItem: Item 3 is not hilited\n");
2472 }
2473
2474 /* unhilite a menu item (by command) */
2475
2476 SetLastError(0xdeadbeef);
2477 ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_UNHILITE | MF_BYCOMMAND),
2478 "HiliteMenuItem: call should not have failed.\n");
2479 ok(GetLastError() == 0xdeadbeef,
2480 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2481
2482 ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE),
2483 "HiliteMenuItem: Item 3 is hilited\n");
2484
2485 DestroyWindow(hWnd);
2486 }
2487
2488 static void check_menu_items(HMENU hmenu, UINT checked_cmd, UINT checked_type,
2489 UINT checked_state)
2490 {
2491 INT i, count;
2492
2493 count = GetMenuItemCount(hmenu);
2494 ok (count != -1, "GetMenuItemCount returned -1\n");
2495
2496 for (i = 0; i < count; i++)
2497 {
2498 BOOL ret;
2499 MENUITEMINFOA mii;
2500
2501 memset(&mii, 0, sizeof(mii));
2502 mii.cbSize = sizeof(mii);
2503 mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU;
2504 ret = GetMenuItemInfoA(hmenu, i, TRUE, &mii);
2505 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2506 if (0)
2507 trace("item #%u: fType %04x, fState %04x, wID %u, hSubMenu %p\n",
2508 i, mii.fType, mii.fState, mii.wID, mii.hSubMenu);
2509
2510 if (mii.hSubMenu)
2511 {
2512 ok(mii.wID == (UINT_PTR)mii.hSubMenu, "id %u: wID should be equal to hSubMenu\n", checked_cmd);
2513 check_menu_items(mii.hSubMenu, checked_cmd, checked_type, checked_state);
2514 }
2515 else
2516 {
2517 if (mii.wID == checked_cmd)
2518 {
2519 ok(mii.fType == checked_type, "id %u: expected fType %04x, got %04x\n", checked_cmd, checked_type, mii.fType);
2520 ok(mii.fState == checked_state, "id %u: expected fState %04x, got %04x\n", checked_cmd, checked_state, mii.fState);
2521 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2522 }
2523 else
2524 {
2525 ok(mii.fType != MFT_RADIOCHECK, "id %u: not expected fType MFT_RADIOCHECK on cmd %u\n", checked_cmd, mii.wID);
2526
2527 if (mii.fType == MFT_SEPARATOR)
2528 {
2529 ok(mii.fState == MFS_GRAYED, "id %u: expected fState MFS_GRAYED, got %04x\n", checked_cmd, mii.fState);
2530 ok(mii.wID == 0, "id %u: expected wID 0, got %u\n", checked_cmd, mii.wID);
2531 }
2532 else
2533 {
2534 ok(mii.fState == 0, "id %u: expected fState 0, got %04x\n", checked_cmd, mii.fState);
2535 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2536 }
2537 }
2538 }
2539 }
2540 }
2541
2542 static void clear_ftype_and_state(HMENU hmenu, UINT id, UINT flags)
2543 {
2544 BOOL ret;
2545 MENUITEMINFOA mii;
2546
2547 memset(&mii, 0, sizeof(mii));
2548 mii.cbSize = sizeof(mii);
2549 mii.fMask = MIIM_FTYPE | MIIM_STATE;
2550 ret = SetMenuItemInfoA(hmenu, id, (flags & MF_BYPOSITION) != 0, &mii);
2551 ok(ret, "SetMenuItemInfo(%u) failed\n", id);
2552 }
2553
2554 static void test_CheckMenuRadioItem(void)
2555 {
2556 BOOL ret;
2557 HMENU hmenu;
2558
2559 hmenu = LoadMenuA(GetModuleHandleA(NULL), MAKEINTRESOURCEA(1));
2560 assert(hmenu != 0);
2561
2562 check_menu_items(hmenu, -1, 0, 0);
2563
2564 ret = CheckMenuRadioItem(hmenu, 100, 100, 100, MF_BYCOMMAND);
2565 ok(ret, "CheckMenuRadioItem failed\n");
2566 check_menu_items(hmenu, 100, MFT_RADIOCHECK, MFS_CHECKED);
2567
2568 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2569 ret = CheckMenuRadioItem(hmenu, 100, 100, -1, MF_BYCOMMAND);
2570 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2571 check_menu_items(hmenu, 100, MFT_RADIOCHECK, 0);
2572
2573 /* clear check */
2574 clear_ftype_and_state(hmenu, 100, MF_BYCOMMAND);
2575 check_menu_items(hmenu, -1, 0, 0);
2576
2577 /* first and checked items are on different menus */
2578 ret = CheckMenuRadioItem(hmenu, 0, 300, 202, MF_BYCOMMAND);
2579 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2580 check_menu_items(hmenu, -1, 0, 0);
2581
2582 ret = CheckMenuRadioItem(hmenu, 200, 300, 202, MF_BYCOMMAND);
2583 ok(ret, "CheckMenuRadioItem failed\n");
2584 check_menu_items(hmenu, 202, MFT_RADIOCHECK, MFS_CHECKED);
2585
2586 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2587 ret = CheckMenuRadioItem(hmenu, 202, 202, -1, MF_BYCOMMAND);
2588 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2589 check_menu_items(hmenu, 202, MFT_RADIOCHECK, 0);
2590
2591 /* clear check */
2592 clear_ftype_and_state(hmenu, 202, MF_BYCOMMAND);
2593 check_menu_items(hmenu, -1, 0, 0);
2594
2595 /* just for fun, try to check separator */
2596 ret = CheckMenuRadioItem(hmenu, 0, 300, 0, MF_BYCOMMAND);
2597 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2598 check_menu_items(hmenu, -1, 0, 0);
2599 }
2600
2601 static void test_menu_resource_layout(void)
2602 {
2603 static const struct
2604 {
2605 MENUITEMTEMPLATEHEADER mith;
2606 WORD data[14];
2607 } menu_template =
2608 {
2609 { 0, 0 }, /* versionNumber, offset */
2610 {
2611 /* mtOption, mtID, mtString[] '\0' terminated */
2612 MF_STRING, 1, 'F', 0,
2613 MF_STRING, 2, 0,
2614 MF_SEPARATOR, 3, 0,
2615 /* MF_SEPARATOR, 4, 'S', 0, FIXME: Wine ignores 'S' */
2616 MF_STRING|MF_GRAYED|MF_END, 5, 'E', 0
2617 }
2618 };
2619 static const struct
2620 {
2621 UINT type, state, id;
2622 const char *str;
2623 } menu_data[] =
2624 {
2625 { MF_STRING, MF_ENABLED, 1, "F" },
2626 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 2, "" },
2627 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 3, "" },
2628 /*{ MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 4, "S" }, FIXME: Wine ignores 'S'*/
2629 { MF_STRING, MF_GRAYED, 5, "E" },
2630 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 6, "" },
2631 { MF_STRING, MF_ENABLED, 7, "" },
2632 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 8, "" }
2633 };
2634 HMENU hmenu;
2635 INT count, i;
2636 BOOL ret;
2637
2638 hmenu = LoadMenuIndirectA(&menu_template);
2639 ok(hmenu != 0, "LoadMenuIndirect error %u\n", GetLastError());
2640
2641 ret = AppendMenuA(hmenu, MF_STRING, 6, NULL);
2642 ok(ret, "AppendMenu failed\n");
2643 ret = AppendMenuA(hmenu, MF_STRING, 7, "\0");
2644 ok(ret, "AppendMenu failed\n");
2645 ret = AppendMenuA(hmenu, MF_SEPARATOR, 8, "separator");
2646 ok(ret, "AppendMenu failed\n");
2647
2648 count = GetMenuItemCount(hmenu);
2649 ok(count == sizeof(menu_data)/sizeof(menu_data[0]),
2650 "expected %u menu items, got %u\n",
2651 (UINT)(sizeof(menu_data)/sizeof(menu_data[0])), count);
2652
2653 for (i = 0; i < count; i++)
2654 {
2655 char buf[20];
2656 MENUITEMINFOA mii;
2657
2658 memset(&mii, 0, sizeof(mii));
2659 mii.cbSize = sizeof(mii);
2660 mii.dwTypeData = buf;
2661 mii.cch = sizeof(buf);
2662 mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_STRING;
2663 ret = GetMenuItemInfoA(hmenu, i, TRUE, &mii);
2664 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2665 if (0)
2666 trace("item #%u: fType %04x, fState %04x, wID %u, dwTypeData %s\n",
2667 i, mii.fType, mii.fState, mii.wID, (LPCSTR)mii.dwTypeData);
2668
2669 ok(mii.fType == menu_data[i].type,
2670 "%u: expected fType %04x, got %04x\n", i, menu_data[i].type, mii.fType);
2671 ok(mii.fState == menu_data[i].state,
2672 "%u: expected fState %04x, got %04x\n", i, menu_data[i].state, mii.fState);
2673 ok(mii.wID == menu_data[i].id,
2674 "%u: expected wID %04x, got %04x\n", i, menu_data[i].id, mii.wID);
2675 ok(mii.cch == strlen(menu_data[i].str),
2676 "%u: expected cch %u, got %u\n", i, (UINT)strlen(menu_data[i].str), mii.cch);
2677 ok(!strcmp(mii.dwTypeData, menu_data[i].str),
2678 "%u: expected dwTypeData %s, got %s\n", i, menu_data[i].str, (LPCSTR)mii.dwTypeData);
2679 }
2680
2681 DestroyMenu(hmenu);
2682 }
2683
2684 struct menu_data
2685 {
2686 UINT type, id;
2687 const char *str;
2688 };
2689
2690 static HMENU create_menu_from_data(const struct menu_data *item, INT item_count)
2691 {
2692 HMENU hmenu;
2693 INT i;
2694 BOOL ret;
2695
2696 hmenu = CreateMenu();
2697 assert(hmenu != 0);
2698
2699 for (i = 0; i < item_count; i++)
2700 {
2701 SetLastError(0xdeadbeef);
2702 ret = AppendMenuA(hmenu, item[i].type, item[i].id, item[i].str);
2703 ok(ret, "%d: AppendMenu(%04x, %04x, %p) error %u\n",
2704 i, item[i].type, item[i].id, item[i].str, GetLastError());
2705 }
2706 return hmenu;
2707 }
2708
2709 /* use InsertMenuItem: does not set the MFT_BITMAP flag,
2710 * and does not accept non-magic bitmaps with invalid
2711 * bitmap handles */
2712 static HMENU create_menuitem_from_data(const struct menu_data *item, INT item_count)
2713 {
2714 HMENU hmenu;
2715 INT i;
2716 BOOL ret;
2717 MENUITEMINFOA mii = { sizeof( MENUITEMINFOA) };
2718
2719 hmenu = CreateMenu();
2720 assert(hmenu != 0);
2721
2722 for (i = 0; i < item_count; i++)
2723 {
2724 SetLastError(0xdeadbeef);
2725
2726 mii.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STATE;
2727 mii.fType = 0;
2728 if( item[i].type & MFT_BITMAP)
2729 {
2730 mii.fMask |= MIIM_BITMAP;
2731 mii.hbmpItem = (HBITMAP)item[i].str;
2732 }
2733 else if( item[i].type & MFT_SEPARATOR)
2734 mii.fType = MFT_SEPARATOR;
2735 else
2736 {
2737 mii.fMask |= MIIM_STRING;
2738 mii.dwTypeData = (LPSTR)item[i].str;
2739 mii.cch = strlen( item[i].str);
2740 }
2741 mii.fState = 0;
2742 if( item[i].type & MF_HELP) mii.fType |= MF_HELP;
2743 mii.wID = item[i].id;
2744 ret = InsertMenuItemA( hmenu, -1, TRUE, &mii);
2745 ok(ret, "%d: InsertMenuItem(%04x, %04x, %p) error %u\n",
2746 i, item[i].type, item[i].id, item[i].str, GetLastError());
2747 }
2748 return hmenu;
2749 }
2750
2751 static void compare_menu_data(HMENU hmenu, const struct menu_data *item, INT item_count)
2752 {
2753 INT count, i;
2754 BOOL ret;
2755
2756 count = GetMenuItemCount(hmenu);
2757 ok(count == item_count, "expected %d, got %d menu items\n", count, item_count);
2758
2759 for (i = 0; i < count; i++)
2760 {
2761 char buf[20];
2762 MENUITEMINFOA mii;
2763
2764 memset(&mii, 0, sizeof(mii));
2765 mii.cbSize = sizeof(mii);
2766 mii.dwTypeData = buf;
2767 mii.cch = sizeof(buf);
2768 mii.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_BITMAP;
2769 ret = GetMenuItemInfoA(hmenu, i, TRUE, &mii);
2770 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2771 if (0)
2772 trace("item #%u: fType %04x, fState %04x, wID %04x, hbmp %p\n",
2773 i, mii.fType, mii.fState, mii.wID, mii.hbmpItem);
2774
2775 ok(mii.fType == item[i].type,
2776 "%u: expected fType %04x, got %04x\n", i, item[i].type, mii.fType);
2777 ok(mii.wID == item[i].id,
2778 "%u: expected wID %04x, got %04x\n", i, item[i].id, mii.wID);
2779 if (mii.hbmpItem || !item[i].str)
2780 /* For some reason Windows sets high word to not 0 for
2781 * not "magic" ids.
2782 */
2783 ok(LOWORD(mii.hbmpItem) == LOWORD(item[i].str),
2784 "%u: expected hbmpItem %p, got %p\n", i, item[i].str, mii.hbmpItem);
2785 else
2786 {
2787 ok(mii.cch == strlen(item[i].str),
2788 "%u: expected cch %u, got %u\n", i, (UINT)strlen(item[i].str), mii.cch);
2789 ok(!strcmp(mii.dwTypeData, item[i].str),
2790 "%u: expected dwTypeData %s, got %s\n", i, item[i].str, (LPCSTR)mii.dwTypeData);
2791 }
2792 }
2793 }
2794
2795 static void test_InsertMenu(void)
2796 {
2797 HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
2798 /* Note: XP treats only bitmap handles 1 - 6 as "magic" ones
2799 * regardless of their id.
2800 */
2801 static const struct menu_data in1[] =
2802 {
2803 { MF_STRING, 1, "File" },
2804 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCEA(1) },
2805 { MF_STRING|MF_HELP, 2, "Help" }
2806 };
2807 static const struct menu_data out1[] =
2808 {
2809 { MF_STRING, 1, "File" },
2810 { MF_STRING|MF_HELP, 2, "Help" },
2811 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCEA(1) }
2812 };
2813 static const struct menu_data out1a[] =
2814 {
2815 { MF_STRING, 1, "File" },
2816 { MF_STRING|MF_HELP, 2, "Help" },
2817 { MF_HELP, SC_CLOSE, MAKEINTRESOURCEA(1) }
2818 };
2819 const struct menu_data in2[] =
2820 {
2821 { MF_STRING, 1, "File" },
2822 { MF_BITMAP|MF_HELP, SC_CLOSE, (char*)hbm },
2823 { MF_STRING|MF_HELP, 2, "Help" }
2824 };
2825 const struct menu_data out2[] =
2826 {
2827 { MF_STRING, 1, "File" },
2828 { MF_BITMAP|MF_HELP, SC_CLOSE, (char*)hbm },
2829 { MF_STRING|MF_HELP, 2, "Help" }
2830 };
2831 const struct menu_data out2a[] =
2832 {
2833 { MF_STRING, 1, "File" },
2834 { MF_HELP, SC_CLOSE, (char*)hbm },
2835 { MF_STRING|MF_HELP, 2, "Help" }
2836 };
2837 static const struct menu_data in3[] =
2838 {
2839 { MF_STRING, 1, "File" },
2840 { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCEA(1) },
2841 { MF_STRING|MF_HELP, 2, "Help" }
2842 };
2843 static const struct menu_data out3[] =
2844 {
2845 { MF_STRING, 1, "File" },
2846 { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCEA(0) },
2847 { MF_STRING|MF_HELP, 2, "Help" },
2848 };
2849 static const struct menu_data in4[] =
2850 {
2851 { MF_STRING, 1, "File" },
2852 { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCEA(1) },
2853 { MF_STRING|MF_HELP, 2, "Help" }
2854 };
2855 static const struct menu_data out4[] =
2856 {
2857 { MF_STRING, 1, "File" },
2858 { MF_STRING|MF_HELP, 2, "Help" },
2859 { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCEA(1) }
2860 };
2861 static const struct menu_data out4a[] =
2862 {
2863 { MF_STRING, 1, "File" },
2864 { MF_STRING|MF_HELP, 2, "Help" },
2865 { MF_HELP, 1, MAKEINTRESOURCEA(1) }
2866 };
2867 HMENU hmenu;
2868
2869 #define create_menu(a) create_menu_from_data((a), sizeof(a)/sizeof((a)[0]))
2870 #define create_menuitem(a) create_menuitem_from_data((a), sizeof(a)/sizeof((a)[0]))
2871 #define compare_menu(h, a) compare_menu_data((h), (a), sizeof(a)/sizeof((a)[0]))
2872
2873 hmenu = create_menu(in1);
2874 compare_menu(hmenu, out1);
2875 DestroyMenu(hmenu);
2876
2877 hmenu = create_menu(in2);
2878 compare_menu(hmenu, out2);
2879 DestroyMenu(hmenu);
2880
2881 hmenu = create_menu(in3);
2882 compare_menu(hmenu, out3);
2883 DestroyMenu(hmenu);
2884
2885 hmenu = create_menu(in4);
2886 compare_menu(hmenu, out4);
2887 DestroyMenu(hmenu);
2888
2889 /* now using InsertMenuItemInfo */
2890 hmenu = create_menuitem(in1);
2891 compare_menu(hmenu, out1a);
2892 DestroyMenu(hmenu);
2893
2894 hmenu = create_menuitem(in2);
2895 compare_menu(hmenu, out2a);
2896 DestroyMenu(hmenu);
2897
2898 hmenu = create_menuitem(in3);
2899 compare_menu(hmenu, out3);
2900 DestroyMenu(hmenu);
2901
2902 hmenu = create_menuitem(in4);
2903 compare_menu(hmenu, out4a);
2904 DestroyMenu(hmenu);
2905
2906 #undef create_menu
2907 #undef create_menuitem
2908 #undef compare_menu
2909 }
2910
2911 static void test_menu_getmenuinfo(void)
2912 {
2913 HMENU hmenu;
2914 MENUINFO mi = {0};
2915 BOOL ret;
2916 DWORD gle;
2917
2918 if (!pGetMenuInfo)
2919 {
2920 win_skip("GetMenuInfo is not available