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