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