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