4 * Copyright 2005 Robert Shearman
5 * Copyright 2007 Dmitry Timoshkov
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.
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.
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
22 #define _WIN32_WINNT 0x0501
29 #define OEMRESOURCE /* For OBM_MNARROW */
36 #include "wine/test.h"
38 static ATOM atomMenuCheckClass
;
40 static BOOL (WINAPI
*pGetMenuInfo
)(HMENU
,LPCMENUINFO
);
41 static BOOL (WINAPI
*pGetMenuBarInfo
)(HWND
,LONG
,LONG
,PMENUBARINFO
);
42 static UINT (WINAPI
*pSendInput
)(UINT
, INPUT
*, size_t);
43 static BOOL (WINAPI
*pSetMenuInfo
)(HMENU
,LPCMENUINFO
);
44 static BOOL (WINAPI
*pEndMenu
) (void);
46 static void init_function_pointers(void)
48 HMODULE hdll
= GetModuleHandleA("user32");
50 #define GET_PROC(func) \
51 p ## func = (void*)GetProcAddress(hdll, #func); \
53 trace("GetProcAddress(%s) failed\n", #func);
56 GET_PROC(GetMenuBarInfo
)
64 static BOOL
correct_behavior(void)
72 memset(&info
, 0, sizeof(MENUITEMINFOA
));
73 info
.cbSize
= sizeof(MENUITEMINFOA
);
74 SetLastError(0xdeadbeef);
75 rc
= GetMenuItemInfoA(hmenu
, 0, TRUE
, &info
);
77 * NT4 : ERROR_INVALID_PARAMETER
78 * >= W2K : ERROR_MENU_ITEM_NOT_FOUND
80 if (!rc
&& GetLastError() != ERROR_MENU_ITEM_NOT_FOUND
)
82 win_skip("NT4 and below can't handle a bigger MENUITEMINFO struct\n");
91 static LRESULT WINAPI
menu_check_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
95 case WM_ENTERMENULOOP
:
96 /* mark window as having entered menu loop */
97 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, TRUE
);
98 /* exit menu modal loop
99 * ( A SendMessage does not work on NT3.51 here ) */
100 return PostMessageA(hwnd
, WM_CANCELMODE
, 0, 0);
102 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
105 /* The MSVC headers ignore our NONAMELESSUNION requests so we have to define
118 /* globals to communicate between test and wndproc */
120 static BOOL bMenuVisible
;
122 static BOOL got_input
;
123 static HMENU hMenus
[4];
126 #define MOD_NRMENUS 8
128 /* menu texts with their sizes */
131 SIZE size
; /* size of text up to any \t */
132 SIZE sc_size
; /* size of the short-cut */
136 { "Shira&z\tAlt+S" },
141 static unsigned int MOD_maxid
;
142 static RECT MOD_rc
[MOD_NRMENUS
];
143 static int MOD_avec
, MOD_hic
;
144 static int MOD_odheight
;
145 static SIZE MODsizes
[MOD_NRMENUS
]= { {MOD_SIZE
, MOD_SIZE
},{MOD_SIZE
, MOD_SIZE
},
146 {MOD_SIZE
, MOD_SIZE
},{MOD_SIZE
, MOD_SIZE
}};
147 static BOOL MOD_GotDrawItemMsg
= FALSE
;
148 static int gflag_initmenupopup
,
152 static WPARAM selectitem_wp
;
153 static LPARAM selectitem_lp
;
155 /* wndproc used by test_menu_ownerdraw() */
156 static LRESULT WINAPI
menu_ownerdraw_wnd_proc(HWND hwnd
, UINT msg
,
157 WPARAM wparam
, LPARAM lparam
)
159 static HMENU hmenupopup
;
162 case WM_INITMENUPOPUP
:
163 gflag_initmenupopup
++;
164 hmenupopup
= (HMENU
) wparam
;
166 case WM_ENTERMENULOOP
:
167 gflag_entermenuloop
++;
174 MEASUREITEMSTRUCT
* pmis
= (MEASUREITEMSTRUCT
*)lparam
;
176 trace("WM_MEASUREITEM received data %lx size %dx%d\n",
177 pmis
->itemData
, pmis
->itemWidth
, pmis
->itemHeight
);
178 ok( !wparam
, "wrong wparam %lx\n", wparam
);
179 ok( pmis
->CtlType
== ODT_MENU
, "wrong type %x\n", pmis
->CtlType
);
180 MOD_odheight
= pmis
->itemHeight
;
181 pmis
->itemWidth
= MODsizes
[pmis
->itemData
].cx
;
182 pmis
->itemHeight
= MODsizes
[pmis
->itemData
].cy
;
187 DRAWITEMSTRUCT
* pdis
;
190 char chrs
[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
193 pdis
= (DRAWITEMSTRUCT
*) lparam
;
194 if( winetest_debug
) {
196 GetMenuItemRect( hwnd
, (HMENU
)pdis
->hwndItem
, pdis
->itemData
,&rc
);
197 trace("WM_DRAWITEM received hwnd %p hmenu %p itemdata %ld item %d rc %d,%d-%d,%d itemrc: %d,%d-%d,%d\n",
198 hwnd
, pdis
->hwndItem
, pdis
->itemData
, pdis
->itemID
,
199 pdis
->rcItem
.left
, pdis
->rcItem
.top
,
200 pdis
->rcItem
.right
,pdis
->rcItem
.bottom
,
201 rc
.left
,rc
.top
,rc
.right
,rc
.bottom
);
202 oldpen
=SelectObject( pdis
->hDC
, GetStockObject(
203 pdis
->itemState
& ODS_SELECTED
? WHITE_PEN
:BLACK_PEN
));
204 Rectangle( pdis
->hDC
, pdis
->rcItem
.left
,pdis
->rcItem
.top
,
205 pdis
->rcItem
.right
,pdis
->rcItem
.bottom
);
206 SelectObject( pdis
->hDC
, oldpen
);
208 ok( !wparam
, "wrong wparam %lx\n", wparam
);
209 ok( pdis
->CtlType
== ODT_MENU
, "wrong type %x\n", pdis
->CtlType
);
210 /* calculate widths of some menu texts */
211 if( ! MOD_txtsizes
[0].size
.cx
)
212 for(i
= 0; MOD_txtsizes
[i
].text
; i
++) {
215 strcpy( buf
, MOD_txtsizes
[i
].text
);
216 if( ( p
= strchr( buf
, '\t'))) {
218 DrawTextA( pdis
->hDC
, p
+ 1, -1, &rc
,
219 DT_SINGLELINE
|DT_CALCRECT
);
220 MOD_txtsizes
[i
].sc_size
.cx
= rc
.right
- rc
.left
;
221 MOD_txtsizes
[i
].sc_size
.cy
= rc
.bottom
- rc
.top
;
223 DrawTextA( pdis
->hDC
, buf
, -1, &rc
,
224 DT_SINGLELINE
|DT_CALCRECT
);
225 MOD_txtsizes
[i
].size
.cx
= rc
.right
- rc
.left
;
226 MOD_txtsizes
[i
].size
.cy
= rc
.bottom
- rc
.top
;
229 if( pdis
->itemData
> MOD_maxid
) return TRUE
;
230 /* store the rectangle */
231 MOD_rc
[pdis
->itemData
] = pdis
->rcItem
;
232 /* calculate average character width */
233 GetTextExtentPointA( pdis
->hDC
, chrs
, 52, &sz
);
234 MOD_avec
= (sz
.cx
+ 26)/52;
235 GetTextMetricsA( pdis
->hDC
, &tm
);
236 MOD_hic
= tm
.tmHeight
;
237 MOD_GotDrawItemMsg
= TRUE
;
243 ok( lparam
|| broken(!lparam
), /* win9x, nt4 */
244 "Menu window handle is NULL!\n");
246 HMENU hmenu
= (HMENU
)SendMessageA( (HWND
)lparam
, MN_GETHMENU
, 0, 0);
247 ok( hmenupopup
== hmenu
, "MN_GETHMENU returns %p expected %p\n",
250 PostMessageA(hwnd
, WM_CANCELMODE
, 0, 0);
254 selectitem_wp
= wparam
;
255 selectitem_lp
= lparam
;
258 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
261 static void register_menu_check_class(void)
269 GetModuleHandleA(NULL
),
271 LoadCursorA(NULL
, (LPCSTR
)IDC_ARROW
),
272 (HBRUSH
)(COLOR_BTNFACE
+1),
277 atomMenuCheckClass
= RegisterClassA(&wc
);
280 static void test_getmenubarinfo(void)
289 if (!pGetMenuBarInfo
) {
290 win_skip("GetMenuBarInfo is not available\n");
294 mbi
.cbSize
= sizeof(MENUBARINFO
);
296 hwnd
= CreateWindowExA(0, (LPCSTR
)MAKEINTATOM(atomMenuCheckClass
), NULL
,
297 WS_SYSMENU
| WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 100, 100,
298 NULL
, NULL
, NULL
, NULL
);
299 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
301 /* no menu: getmenubarinfo should fail */
302 SetLastError(0xdeadbeef);
303 ret
= pGetMenuBarInfo(hwnd
, OBJID_MENU
, 0, &mbi
);
304 err
= GetLastError();
305 ok(ret
== FALSE
, "GetMenuBarInfo should not have been successful\n");
306 ok(err
== 0xdeadbeef, "err = %d\n", err
);
308 /* create menubar, no items yet */
309 hmenu
= CreateMenu();
310 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
312 ret
= SetMenu(hwnd
, hmenu
);
313 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
315 SetLastError(0xdeadbeef);
316 ret
= pGetMenuBarInfo(NULL
, OBJID_CLIENT
, 0, &mbi
);
317 err
= GetLastError();
318 ok(!ret
, "GetMenuBarInfo succeeded\n");
319 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "err = %d\n", err
);
321 SetLastError(0xdeadbeef);
322 ret
= pGetMenuBarInfo(hwnd
, OBJID_CLIENT
, 0, &mbi
);
323 err
= GetLastError();
324 ok(!ret
, "GetMenuBarInfo succeeded\n");
325 ok(err
==ERROR_INVALID_MENU_HANDLE
|| broken(err
==0xdeadbeef) /* NT, W2K, XP */, "err = %d\n", err
);
327 SetLastError(0xdeadbeef);
328 ret
= pGetMenuBarInfo(hwnd
, OBJID_MENU
, -1, &mbi
);
329 err
= GetLastError();
330 ok(ret
== FALSE
, "GetMenuBarInfo should have failed\n");
331 ok(err
== 0xdeadbeef, "err = %d\n", err
);
334 SetLastError(0xdeadbeef);
335 ret
= pGetMenuBarInfo(hwnd
, OBJID_MENU
, 0, &mbi
);
336 err
= GetLastError();
337 ok(ret
== FALSE
, "GetMenuBarInfo should have failed\n");
338 ok(err
== ERROR_INVALID_PARAMETER
, "err = %d\n", err
);
339 mbi
.cbSize
= sizeof(MENUBARINFO
);
341 SetLastError(0xdeadbeef);
342 ret
= pGetMenuBarInfo(hwnd
, 123, 0, &mbi
);
343 err
= GetLastError();
344 ok(ret
== FALSE
, "GetMenuBarInfo should have failed\n");
345 ok(err
== 0xdeadbeef, "err = %d\n", err
);
347 ret
= pGetMenuBarInfo(hwnd
, OBJID_MENU
, 0, &mbi
);
348 ok(ret
, "GetMenuBarInfo failed with error %d\n", GetLastError());
350 ok(mbi
.rcBar
.left
== 0 && mbi
.rcBar
.top
== 0 &&
351 mbi
.rcBar
.bottom
== 0 && mbi
.rcBar
.right
== 0,
352 "rcBar: Expected 0,0-0,0, got: %d,%d-%d,%d\n",
353 mbi
.rcBar
.left
, mbi
.rcBar
.top
, mbi
.rcBar
.right
, mbi
.rcBar
.bottom
);
354 ok(mbi
.hMenu
== hmenu
, "hMenu: Got %p instead of %p\n",
356 ok(mbi
.fBarFocused
== 0, "fBarFocused: Got %d instead of 0.\n", mbi
.fBarFocused
);
357 ok(mbi
.fFocused
== 0, "fFocused: Got %d instead of 0.\n", mbi
.fFocused
);
360 ret
= AppendMenuA(hmenu
, MF_STRING
, 100, "item 1");
361 ok(ret
, "AppendMenu failed.\n");
362 ret
= AppendMenuA(hmenu
, MF_STRING
, 101, "item 2");
363 ok(ret
, "AppendMenu failed.\n");
364 ret
= SetMenu(hwnd
, hmenu
);
365 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
367 SetLastError(0xdeadbeef);
368 ret
= pGetMenuBarInfo(hwnd
, OBJID_MENU
, 200, &mbi
);
369 err
= GetLastError();
370 ok(ret
== FALSE
, "GetMenuBarInfo should have failed\n");
371 ok(err
== 0xdeadbeef, "err = %d\n", err
);
373 /* get info for the whole menu */
374 ret
= pGetMenuBarInfo(hwnd
, OBJID_MENU
, 0, &mbi
);
375 ok(ret
, "GetMenuBarInfo failed with error %d\n", GetLastError());
377 /* calculate menu rectangle, from window rectangle and the position of the first item */
378 ret
= GetWindowRect(hwnd
, &rcw
);
379 ok(ret
, "GetWindowRect failed.\n");
380 ret
= GetMenuItemRect(hwnd
, hmenu
, 0, &rci
);
381 ok(ret
, "GetMenuItemRect failed.\n");
382 todo_wine
ok(mbi
.rcBar
.left
== rci
.left
&& mbi
.rcBar
.top
== rci
.top
&&
383 mbi
.rcBar
.bottom
== rci
.bottom
&& mbi
.rcBar
.right
== rcw
.right
- rci
.left
+ rcw
.left
,
384 "rcBar: Got %d,%d-%d,%d instead of %d,%d-%d,%d\n",
385 mbi
.rcBar
.left
, mbi
.rcBar
.top
, mbi
.rcBar
.right
, mbi
.rcBar
.bottom
,
386 rci
.left
, rci
.top
, rcw
.right
- rci
.left
+ rcw
.left
, rci
.bottom
);
387 ok(mbi
.hMenu
== hmenu
, "hMenu: Got %p instead of %p\n", mbi
.hMenu
, hmenu
);
388 ok(mbi
.fBarFocused
== 0, "fBarFocused: got %d instead of 0\n", mbi
.fBarFocused
);
389 ok(mbi
.fFocused
== 0, "fFocused: got %d instead of 0\n", mbi
.fFocused
);
391 /* get info for item nr.2 */
392 ret
= pGetMenuBarInfo(hwnd
, OBJID_MENU
, 2, &mbi
);
393 ok(ret
, "GetMenuBarInfo failed with error %d\n", GetLastError());
394 ret
= GetMenuItemRect(hwnd
, hmenu
, 1, &rci
);
395 ok(ret
, "GetMenuItemRect failed.\n");
396 ok(mbi
.rcBar
.left
== rci
.left
&& mbi
.rcBar
.top
== rci
.top
&&
397 mbi
.rcBar
.bottom
== rci
.bottom
&& mbi
.rcBar
.right
== rci
.right
,
398 "rcBar: Got %d,%d-%d,%d instead of %d,%d-%d,%d\n",
399 mbi
.rcBar
.left
, mbi
.rcBar
.top
, mbi
.rcBar
.right
, mbi
.rcBar
.bottom
,
400 rci
.left
, rci
.top
, rci
.right
, rci
.bottom
);
401 ok(mbi
.hMenu
== hmenu
, "hMenu: Got %p instead of %p\n", mbi
.hMenu
, hmenu
);
402 ok(mbi
.fBarFocused
== 0, "fBarFocused: got %d instead of 0\n", mbi
.fBarFocused
);
403 ok(mbi
.fFocused
== 0, "fFocused: got %d instead of 0\n", mbi
.fFocused
);
408 /* demonstrates that windows locks the menu object so that it is still valid
409 * even after a client calls DestroyMenu on it */
410 static void test_menu_locked_by_window(void)
414 HWND hwnd
= CreateWindowExA(0, (LPCSTR
)MAKEINTATOM(atomMenuCheckClass
), NULL
,
415 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
416 NULL
, NULL
, NULL
, NULL
);
417 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
418 hmenu
= CreateMenu();
419 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
420 ret
= InsertMenuA(hmenu
, 0, MF_STRING
, 0, "&Test");
421 ok(ret
, "InsertMenu failed with error %d\n", GetLastError());
422 ret
= SetMenu(hwnd
, hmenu
);
423 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
424 ret
= DestroyMenu(hmenu
);
425 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
427 ret
= DrawMenuBar(hwnd
);
428 ok(ret
, "DrawMenuBar failed with error %d\n", GetLastError());
429 ret
= IsMenu(GetMenu(hwnd
));
430 ok(!ret
|| broken(ret
) /* nt4 */, "Menu handle should have been destroyed\n");
432 SendMessageA(hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, 0);
433 /* did we process the WM_INITMENU message? */
434 ret
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
436 ok(ret
, "WM_INITMENU should have been sent\n");
442 /* demonstrates that subpopup's are locked
443 * even after a client calls DestroyMenu on it */
444 static LRESULT WINAPI
subpopuplocked_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
450 hwndmenu
= GetCapture();
452 PostMessageA( hwndmenu
, WM_KEYDOWN
, VK_DOWN
, 0);
453 PostMessageA( hwndmenu
, WM_KEYDOWN
, VK_RIGHT
, 0);
454 PostMessageA( hwndmenu
, WM_KEYDOWN
, VK_RETURN
, 0);
457 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
460 static void test_subpopup_locked_by_menu(void)
464 HMENU hmenu
, hsubmenu
;
465 MENUINFO mi
= { sizeof( MENUINFO
)};
466 MENUITEMINFOA mii
= { sizeof( MENUITEMINFOA
)};
468 const int itemid
= 0x1234567;
471 win_skip("GetMenuInfo is not available\n");
474 /* create window, popupmenu with one subpopup */
475 hwnd
= CreateWindowExA(0, (LPCSTR
)MAKEINTATOM(atomMenuCheckClass
), NULL
,
476 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
477 NULL
, NULL
, NULL
, NULL
);
478 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
479 SetWindowLongPtrA( hwnd
, GWLP_WNDPROC
, (LONG_PTR
) subpopuplocked_wnd_proc
);
480 hmenu
= CreatePopupMenu();
481 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
482 hsubmenu
= CreatePopupMenu();
483 ok(hsubmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
484 ret
= InsertMenuA(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hsubmenu
,
486 ok(ret
, "InsertMenu failed with error %d\n", GetLastError());
487 ret
= InsertMenuA(hsubmenu
, 0, MF_BYPOSITION
| MF_STRING
, itemid
, "PopUpMenu");
488 ok(ret
, "InsertMenu failed with error %d\n", GetLastError());
489 /* first some tests that all this functions properly */
490 mii
.fMask
= MIIM_SUBMENU
;
491 ret
= GetMenuItemInfoA( hmenu
, 0, TRUE
, &mii
);
492 ok( ret
, "GetMenuItemInfo failed error %d\n", GetLastError());
493 ok( mii
.hSubMenu
== hsubmenu
, "submenu is %p\n", mii
.hSubMenu
);
494 mi
.fMask
|= MIM_STYLE
;
495 ret
= pGetMenuInfo( hsubmenu
, &mi
);
496 ok( ret
, "GetMenuInfo returned 0 with error %d\n", GetLastError());
497 ret
= IsMenu( hsubmenu
);
498 ok( ret
, "Menu handle is not valid\n");
499 SetLastError( 0xdeadbeef);
500 ret
= TrackPopupMenu( hmenu
, TPM_RETURNCMD
, 100,100, 0, hwnd
, NULL
);
501 if( ret
== (itemid
& 0xffff)) {
502 win_skip("not on 16 bit menu subsystem\n");
503 DestroyMenu( hsubmenu
);
505 gle
= GetLastError();
506 ok( ret
== itemid
, "TrackPopupMenu returned %d error is %d\n", ret
, gle
);
508 broken( gle
== 0xdeadbeef), /* win2k0 */
509 "Last error is %d\n", gle
);
510 /* then destroy the sub-popup */
511 ret
= DestroyMenu( hsubmenu
);
512 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
513 /* and repeat the tests */
514 mii
.fMask
= MIIM_SUBMENU
;
515 ret
= GetMenuItemInfoA( hmenu
, 0, TRUE
, &mii
);
516 ok( ret
, "GetMenuItemInfo failed error %d\n", GetLastError());
517 /* GetMenuInfo fails now */
518 ok( mii
.hSubMenu
== hsubmenu
, "submenu is %p\n", mii
.hSubMenu
);
519 mi
.fMask
|= MIM_STYLE
;
520 ret
= pGetMenuInfo( hsubmenu
, &mi
);
521 ok( !ret
, "GetMenuInfo should have failed\n");
522 /* IsMenu says it is not */
523 ret
= IsMenu( hsubmenu
);
524 ok( !ret
, "Menu handle should be invalid\n");
525 /* but TrackPopupMenu still works! */
526 SetLastError( 0xdeadbeef);
527 ret
= TrackPopupMenu( hmenu
, TPM_RETURNCMD
, 100,100, 0, hwnd
, NULL
);
528 gle
= GetLastError();
530 ok( ret
== itemid
, "TrackPopupMenu returned %d error is %d\n", ret
, gle
);
533 broken(gle
== 0xdeadbeef) || /* wow64 */
534 broken(gle
== ERROR_INVALID_PARAMETER
), /* win2k0 */
535 "Last error is %d\n", gle
);
542 static void test_menu_ownerdraw(void)
549 HWND hwnd
= CreateWindowExA(0, (LPCSTR
)MAKEINTATOM(atomMenuCheckClass
), NULL
,
550 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
551 NULL
, NULL
, NULL
, NULL
);
552 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
554 SetWindowLongPtrA( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_ownerdraw_wnd_proc
);
555 hmenu
= CreatePopupMenu();
556 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
557 if( !hmenu
) { DestroyWindow(hwnd
);return;}
559 for( j
=0;j
<2;j
++) /* create columns */
560 for(i
=0;i
<2;i
++) { /* create rows */
561 ret
= AppendMenuA( hmenu
, MF_OWNERDRAW
|
562 (i
==0 ? MF_MENUBREAK
: 0), k
, (LPCSTR
)MAKEINTRESOURCE(k
));
564 ok( ret
, "AppendMenu failed for %d\n", k
-1);
567 assert( k
<= sizeof(MOD_rc
)/sizeof(RECT
));
568 /* display the menu */
569 TrackPopupMenu( hmenu
, TPM_RETURNCMD
, 100,100, 0, hwnd
, NULL
);
571 /* columns have a 4 pixel gap between them */
572 ok( MOD_rc
[0].right
+ 4 == MOD_rc
[2].left
,
573 "item rectangles are not separated by 4 pixels space\n");
574 /* height should be what the MEASUREITEM message has returned */
575 ok( MOD_rc
[0].bottom
- MOD_rc
[0].top
== MOD_SIZE
,
576 "menu item has wrong height: %d should be %d\n",
577 MOD_rc
[0].bottom
- MOD_rc
[0].top
, MOD_SIZE
);
578 /* no gaps between the rows */
579 ok( MOD_rc
[0].bottom
- MOD_rc
[1].top
== 0,
580 "There should not be a space between the rows, gap is %d\n",
581 MOD_rc
[0].bottom
- MOD_rc
[1].top
);
582 /* test the correct value of the item height that was sent
583 * by the WM_MEASUREITEM message */
584 ok( MOD_odheight
== HIWORD( GetDialogBaseUnits()) || /* WinNT,2k,XP */
585 MOD_odheight
== MOD_hic
, /* Win95,98,ME */
586 "Wrong height field in MEASUREITEMSTRUCT, expected %d or %d actual %d\n",
587 HIWORD( GetDialogBaseUnits()), MOD_hic
, MOD_odheight
);
588 /* test what MF_MENUBREAK did at the first position. Also show
589 * that an MF_SEPARATOR is ignored in the height calculation. */
590 leftcol
= MOD_rc
[0].left
;
591 ModifyMenuA( hmenu
, 0, MF_BYCOMMAND
| MF_OWNERDRAW
| MF_SEPARATOR
, 0, 0);
592 /* display the menu */
593 TrackPopupMenu( hmenu
, TPM_RETURNCMD
, 100,100, 0, hwnd
, NULL
);
594 /* left should be 4 pixels less now */
595 ok( leftcol
== MOD_rc
[0].left
+ 4,
596 "columns should be 4 pixels to the left (actual %d).\n",
597 leftcol
- MOD_rc
[0].left
);
599 ok( MOD_rc
[0].right
- MOD_rc
[0].left
== 2 * MOD_avec
+ MOD_SIZE
,
600 "width of owner drawn menu item is wrong. Got %d expected %d\n",
601 MOD_rc
[0].right
- MOD_rc
[0].left
, 2*MOD_avec
+ MOD_SIZE
);
603 ok( MOD_rc
[0].bottom
- MOD_rc
[0].top
== MOD_SIZE
,
604 "Height is incorrect. Got %d expected %d\n",
605 MOD_rc
[0].bottom
- MOD_rc
[0].top
, MOD_SIZE
);
607 /* test owner-drawn callback bitmap */
608 ModifyMenuA( hmenu
, 1, MF_BYPOSITION
| MFT_BITMAP
, 1, (LPCSTR
)HBMMENU_CALLBACK
);
609 mii
.cbSize
= sizeof(mii
);
610 mii
.fMask
= MIIM_BITMAP
| MIIM_FTYPE
| MIIM_ID
;
611 if (GetMenuItemInfoA( hmenu
, 1, TRUE
, &mii
))
613 ok( mii
.fType
== MFT_BITMAP
, "wrong type %x\n", mii
.fType
);
614 ok( mii
.wID
== 1, "wrong id %x\n", mii
.wID
);
615 ok( mii
.hbmpItem
== HBMMENU_CALLBACK
, "wrong data %p\n", mii
.hbmpItem
);
617 TrackPopupMenu( hmenu
, TPM_RETURNCMD
, 100,100, 0, hwnd
, NULL
);
619 /* test width/height of an ownerdraw menu bar as well */
620 ret
= DestroyMenu(hmenu
);
621 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
622 hmenu
= CreateMenu();
623 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
624 if( !hmenu
) { DestroyWindow(hwnd
);return;}
627 ret
= AppendMenuA( hmenu
, MF_OWNERDRAW
, i
, 0 );
628 ok( ret
, "AppendMenu failed for %d\n", i
);
630 ret
= SetMenu( hwnd
, hmenu
);
631 UpdateWindow( hwnd
); /* hack for wine to draw the window + menu */
632 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
634 ok( MOD_rc
[0].right
- MOD_rc
[0].left
== 2 * MOD_avec
+ MOD_SIZE
,
635 "width of owner drawn menu item is wrong. Got %d expected %d\n",
636 MOD_rc
[0].right
- MOD_rc
[0].left
, 2*MOD_avec
+ MOD_SIZE
);
638 ok( MOD_rc
[0].bottom
- MOD_rc
[0].top
== GetSystemMetrics( SM_CYMENU
) - 1,
639 "Height of owner drawn menu item is wrong. Got %d expected %d\n",
640 MOD_rc
[0].bottom
- MOD_rc
[0].top
, GetSystemMetrics( SM_CYMENU
) - 1);
643 ret
= DestroyMenu(hmenu
);
644 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
648 /* helper for test_menu_bmp_and_string() */
649 static void test_mbs_help( int ispop
, int hassub
, int mnuopt
,
650 HWND hwnd
, int arrowwidth
, int count
, HBITMAP hbmp
,
651 SIZE bmpsize
, LPCSTR text
, SIZE size
, SIZE sc_size
)
654 HMENU hmenu
, submenu
;
655 MENUITEMINFOA mii
={ sizeof( MENUITEMINFOA
)};
662 MOD_GotDrawItemMsg
= FALSE
;
663 mii
.fMask
= MIIM_FTYPE
| MIIM_DATA
| MIIM_STATE
;
665 /* check the menu item unless MNS_CHECKORBMP is set */
666 mii
.fState
= (mnuopt
!= 2 ? MFS_CHECKED
: MFS_UNCHECKED
);
668 MODsizes
[0] = bmpsize
;
672 mii
.fMask
|= MIIM_STRING
;
673 strcpy(text_copy
, text
);
674 mii
.dwTypeData
= text_copy
; /* structure member declared non-const */
675 if( ( p
= strchr( text
, '\t'))) {
676 hastab
= *(p
+ 1) ? 2 : 1;
679 /* tabs don't make sense in menubars */
680 if(hastab
&& !ispop
) return;
682 mii
.fMask
|= MIIM_BITMAP
;
685 submenu
= CreateMenu();
686 ok( submenu
!= 0, "CreateMenu failed with error %d\n", GetLastError());
688 hmenu
= CreatePopupMenu();
690 hmenu
= CreateMenu();
691 ok( hmenu
!= 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
693 mii
.fMask
|= MIIM_SUBMENU
;
694 mii
.hSubMenu
= submenu
;
697 mi
.cbSize
= sizeof(mi
);
698 mi
.fMask
= MIM_STYLE
;
699 pGetMenuInfo( hmenu
, &mi
);
700 if( mnuopt
) mi
.dwStyle
|= mnuopt
== 1 ? MNS_NOCHECK
: MNS_CHECKORBMP
;
701 ret
= pSetMenuInfo( hmenu
, &mi
);
702 ok( ret
, "SetMenuInfo failed with error %d\n", GetLastError());
704 ret
= InsertMenuItemA( hmenu
, 0, FALSE
, &mii
);
705 ok( ret
, "InsertMenuItem failed with error %d\n", GetLastError());
707 if( winetest_debug
) {
709 RECT rc
= {100, 50, 400, 70};
712 sprintf( buf
,"%d text \"%s\" mnuopt %d", count
, text
? text
: "(nil)", mnuopt
);
713 FillRect( hdc
, &rc
, (HBRUSH
) COLOR_WINDOW
);
714 TextOutA( hdc
, 10, 50, buf
, strlen( buf
));
715 ReleaseDC( hwnd
, hdc
);
718 TrackPopupMenu( hmenu
, TPM_RETURNCMD
, 100,100, 0, hwnd
, NULL
);
720 ret
= SetMenu( hwnd
, hmenu
);
721 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
724 ret
= GetMenuItemRect( hwnd
, hmenu
, 0, &rc
);
725 ok(ret
, "GetMenuItemRect failed with error %d\n", GetLastError());
727 if (0) /* comment out menu size checks, behavior is different in almost every Windows version */
728 /* the tests should however succeed on win2000, XP and Wine (at least up to 1.1.15) */
729 /* with a variety of dpis and desktop font sizes */
731 /* check menu width */
733 expect
= ( text
|| hbmp
?
734 4 + (mnuopt
!= 1 ? GetSystemMetrics(SM_CXMENUCHECK
) : 0)
736 arrowwidth
+ MOD_avec
+ (hbmp
?
737 ((INT_PTR
)hbmp
<0||(INT_PTR
)hbmp
>12 ? bmpsize
.cx
+ 2 : GetSystemMetrics( SM_CXMENUSIZE
) + 2)
739 (text
&& hastab
? /* TAB space */
740 MOD_avec
+ ( hastab
==2 ? sc_size
.cx
: 0) : 0) +
741 (text
? 2 + (text
[0] ? size
.cx
:0): 0) ;
743 expect
= !(text
|| hbmp
) ? 0 :
744 ( hbmp
? (text
? 2:0) + bmpsize
.cx
: 0 ) +
745 (text
? 2 * MOD_avec
+ (text
[0] ? size
.cx
:0): 0) ;
746 ok( rc
.right
- rc
.left
== expect
,
747 "menu width wrong, got %d expected %d\n", rc
.right
- rc
.left
, expect
);
748 failed
= failed
|| !(rc
.right
- rc
.left
== expect
);
749 /* check menu height */
751 expect
= max( ( !(text
|| hbmp
) ? GetSystemMetrics( SM_CYMENUSIZE
)/2 : 0),
752 max( (text
? max( 2 + size
.cy
, MOD_hic
+ 4) : 0),
754 ((INT_PTR
)hbmp
<0||(INT_PTR
)hbmp
>12 ?
756 : GetSystemMetrics( SM_CYMENUSIZE
) + 2)
759 expect
= ( !(text
|| hbmp
) ? GetSystemMetrics( SM_CYMENUSIZE
)/2 :
760 max( GetSystemMetrics( SM_CYMENU
) - 1, (hbmp
? bmpsize
.cy
: 0)));
761 ok( rc
.bottom
- rc
.top
== expect
,
762 "menu height wrong, got %d expected %d (%d)\n",
763 rc
.bottom
- rc
.top
, expect
, GetSystemMetrics( SM_CYMENU
));
764 failed
= failed
|| !(rc
.bottom
- rc
.top
== expect
);
765 if( hbmp
== HBMMENU_CALLBACK
&& MOD_GotDrawItemMsg
) {
766 /* check the position of the bitmap */
770 else if (mnuopt
== 0)
771 expect
= 4 + GetSystemMetrics(SM_CXMENUCHECK
);
772 else if (mnuopt
== 1)
774 else /* mnuopt == 2 */
776 ok( expect
== MOD_rc
[0].left
,
777 "bitmap left is %d expected %d\n", MOD_rc
[0].left
, expect
);
778 failed
= failed
|| !(expect
== MOD_rc
[0].left
);
780 expect
= (rc
.bottom
- rc
.top
- MOD_rc
[0].bottom
+ MOD_rc
[0].top
) / 2;
781 ok( expect
== MOD_rc
[0].top
,
782 "bitmap top is %d expected %d\n", MOD_rc
[0].top
, expect
);
783 failed
= failed
|| !(expect
== MOD_rc
[0].top
);
786 /* if there was a failure, report details */
788 trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
789 count
, (ispop
? "POPUP": "MENUBAR"),text
? text
: "(nil)", hbmp
, bmpsize
.cx
, bmpsize
.cy
,
790 size
.cx
, size
.cy
, sc_size
.cx
, mnuopt
, hastab
);
791 trace(" check %d,%d arrow %d avechar %d\n",
792 GetSystemMetrics(SM_CXMENUCHECK
),
793 GetSystemMetrics(SM_CYMENUCHECK
),arrowwidth
, MOD_avec
);
794 if( hbmp
== HBMMENU_CALLBACK
)
795 trace( " rc %d,%d-%d,%d bmp.rc %d,%d-%d,%d\n",
796 rc
.left
, rc
.top
, rc
.top
, rc
.bottom
, MOD_rc
[0].left
,
797 MOD_rc
[0].top
,MOD_rc
[0].right
, MOD_rc
[0].bottom
);
800 ret
= DestroyMenu(submenu
);
801 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
802 ret
= DestroyMenu(hmenu
);
803 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
807 static void test_menu_bmp_and_string(void)
815 MENUINFO mi
= {sizeof(MENUINFO
)};
816 MENUITEMINFOA mii
= {sizeof(MENUITEMINFOA
)};
817 int count
, szidx
, txtidx
, bmpidx
, hassub
, mnuopt
, ispop
;
822 win_skip("GetMenuInfo is not available\n");
826 memset( bmfill
, 0xcc, sizeof( bmfill
));
827 hwnd
= CreateWindowExA(0, (LPCSTR
)MAKEINTATOM(atomMenuCheckClass
), NULL
, WS_SYSMENU
|
828 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
829 NULL
, NULL
, NULL
, NULL
);
830 hbm_arrow
= LoadBitmapA( 0, (LPCSTR
)OBM_MNARROW
);
831 GetObjectA( hbm_arrow
, sizeof(bm
), &bm
);
832 arrowwidth
= bm
.bmWidth
;
833 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
835 /* test system menu */
836 hsysmenu
= GetSystemMenu( hwnd
, FALSE
);
837 ok( hsysmenu
!= NULL
, "GetSystemMenu failed with error %d\n", GetLastError());
838 mi
.fMask
= MIM_STYLE
;
840 got
= pGetMenuInfo( hsysmenu
, &mi
);
841 ok( got
, "GetMenuInfo failed gle=%d\n", GetLastError());
842 ok( MNS_CHECKORBMP
== mi
.dwStyle
, "System Menu Style is %08x, without the bit %08x\n",
843 mi
.dwStyle
, MNS_CHECKORBMP
);
844 mii
.fMask
= MIIM_BITMAP
;
846 got
= GetMenuItemInfoA( hsysmenu
, SC_CLOSE
, FALSE
, &mii
);
847 ok( got
, "GetMenuItemInfoA failed gle=%d\n", GetLastError());
848 ok( HBMMENU_POPUP_CLOSE
== mii
.hbmpItem
, "Item info did not get the right hbitmap: got %p expected %p\n",
849 mii
.hbmpItem
, HBMMENU_POPUP_CLOSE
);
851 SetWindowLongPtrA( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_ownerdraw_wnd_proc
);
854 trace(" check %d,%d arrow %d avechar %d\n",
855 GetSystemMetrics(SM_CXMENUCHECK
),
856 GetSystemMetrics(SM_CYMENUCHECK
),arrowwidth
, MOD_avec
);
859 for( ispop
=1; ispop
>= 0; ispop
--){
860 static SIZE bmsizes
[]= {
861 {10,10},{38,38},{1,30},{55,5}};
862 for( szidx
=0; szidx
< sizeof( bmsizes
) / sizeof( SIZE
); szidx
++) {
863 HBITMAP hbm
= CreateBitmap( bmsizes
[szidx
].cx
, bmsizes
[szidx
].cy
,1,1,bmfill
);
864 HBITMAP bitmaps
[] = { HBMMENU_CALLBACK
, hbm
, HBMMENU_POPUP_CLOSE
, NULL
};
865 ok( hbm
!= 0, "CreateBitmap failed err %d\n", GetLastError());
866 for( txtidx
= 0; txtidx
< sizeof(MOD_txtsizes
)/sizeof(MOD_txtsizes
[0]); txtidx
++) {
867 for( hassub
= 0; hassub
< 2 ; hassub
++) { /* add submenu item */
868 for( mnuopt
= 0; mnuopt
< 3 ; mnuopt
++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
869 for( bmpidx
= 0; bmpidx
<sizeof(bitmaps
)/sizeof(HBITMAP
); bmpidx
++) {
870 /* no need to test NULL bitmaps of several sizes */
871 if( !bitmaps
[bmpidx
] && szidx
> 0) continue;
872 /* the HBMMENU_POPUP not to test for menu bars */
874 bitmaps
[bmpidx
] >= HBMMENU_POPUP_CLOSE
&&
875 bitmaps
[bmpidx
] <= HBMMENU_POPUP_MINIMIZE
) continue;
876 if( !ispop
&& hassub
) continue;
877 test_mbs_help( ispop
, hassub
, mnuopt
,
878 hwnd
, arrowwidth
, ++count
,
881 MOD_txtsizes
[txtidx
].text
,
882 MOD_txtsizes
[txtidx
].size
,
883 MOD_txtsizes
[txtidx
].sc_size
);
895 static void test_menu_add_string( void )
906 WCHAR strbackW
[0x80];
907 static CHAR blah
[] = "blah";
908 static const WCHAR expectedString
[] = {'D','u','m','m','y',' ','s','t','r','i','n','g', 0};
910 hmenu
= CreateMenu();
912 memset( &info
, 0, sizeof info
);
913 info
.cbSize
= sizeof info
;
914 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_ID
;
915 info
.dwTypeData
= blah
;
920 InsertMenuItemA(hmenu
, 0, TRUE
, &info
);
922 memset( &info
, 0, sizeof info
);
923 info
.cbSize
= sizeof info
;
924 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_DATA
| MIIM_ID
;
925 info
.dwTypeData
= string
;
926 info
.cch
= sizeof string
;
928 GetMenuItemInfoA( hmenu
, 0, TRUE
, &info
);
930 ok( !strcmp( string
, "blah" ), "menu item name differed\n");
932 /* Test combination of ownerdraw and strings with GetMenuItemString(A/W) */
933 strcpy(string
, "Dummy string");
934 memset(&info
, 0x00, sizeof(info
));
935 info
.cbSize
= sizeof(MENUITEMINFOA
);
936 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
; /* Set OwnerDraw + typeData */
937 info
.fType
= MFT_OWNERDRAW
;
938 info
.dwTypeData
= string
;
939 rc
= InsertMenuItemA( hmenu
, 0, TRUE
, &info
);
940 ok (rc
, "InsertMenuItem failed\n");
942 strcpy(string
,"Garbage");
943 ok (GetMenuStringA( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
944 ok (!strcmp( strback
, "Dummy string" ), "Menu text from Ansi version incorrect\n");
946 SetLastError(0xdeadbeef);
947 ret
= GetMenuStringW( hmenu
, 0, strbackW
, 99, MF_BYPOSITION
);
948 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
949 win_skip("GetMenuStringW is not implemented\n");
952 ok (ret
, "GetMenuStringW on ownerdraw entry failed\n");
953 ok (!lstrcmpW( strbackW
, expectedString
), "Menu text from Unicode version incorrect\n");
956 /* Just try some invalid parameter tests */
957 SetLastError(0xdeadbeef);
958 rc
= SetMenuItemInfoA( hmenu
, 0, TRUE
, NULL
);
959 ret
= GetLastError();
960 ok (!rc
, "SetMenuItemInfoA succeeded unexpectedly\n");
961 ok (ret
== ERROR_INVALID_PARAMETER
, "Expected 87, got %d\n", ret
);
963 SetLastError(0xdeadbeef);
964 rc
= SetMenuItemInfoA( hmenu
, 0, FALSE
, NULL
);
965 ret
= GetLastError();
966 ok (!rc
, "SetMenuItemInfoA succeeded unexpectedly\n");
967 ok (ret
== ERROR_INVALID_PARAMETER
, "Expected 87, got %d\n", ret
);
969 /* Just change ftype to string and see what text is stored */
970 memset(&info
, 0x00, sizeof(info
));
971 info
.cbSize
= sizeof(MENUITEMINFOA
);
972 info
.fMask
= MIIM_FTYPE
; /* Set string type */
973 info
.fType
= MFT_STRING
;
974 info
.dwTypeData
= (char *)0xdeadbeef;
975 rc
= SetMenuItemInfoA( hmenu
, 0, TRUE
, &info
);
976 ok (rc
, "SetMenuItemInfo failed\n");
978 /* Did we keep the old dwTypeData? */
979 ok (GetMenuStringA( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
980 ok (!strcmp( strback
, "Dummy string" ), "Menu text from Ansi version incorrect\n");
982 /* Ensure change to bitmap type fails */
983 memset(&info
, 0x00, sizeof(info
));
984 info
.cbSize
= sizeof(MENUITEMINFOA
);
985 info
.fMask
= MIIM_FTYPE
; /* Set as bitmap type */
986 info
.fType
= MFT_BITMAP
;
987 info
.dwTypeData
= (char *)0xdeadbee2;
988 rc
= SetMenuItemInfoA( hmenu
, 0, TRUE
, &info
);
989 ok (!rc
, "SetMenuItemInfo unexpectedly worked\n");
991 /* Just change ftype back and ensure data hasn't been freed */
992 info
.fType
= MFT_OWNERDRAW
; /* Set as ownerdraw type */
993 info
.dwTypeData
= (char *)0xdeadbee3;
994 rc
= SetMenuItemInfoA( hmenu
, 0, TRUE
, &info
);
995 ok (rc
, "SetMenuItemInfo failed\n");
997 /* Did we keep the old dwTypeData? */
998 ok (GetMenuStringA( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
999 ok (!strcmp( strback
, "Dummy string" ), "Menu text from Ansi version incorrect\n");
1001 /* Just change string value (not type) */
1002 memset(&info
, 0x00, sizeof(info
));
1003 info
.cbSize
= sizeof(MENUITEMINFOA
);
1004 info
.fMask
= MIIM_STRING
; /* Set typeData */
1005 strcpy(string2
, "string2");
1006 info
.dwTypeData
= string2
;
1007 rc
= SetMenuItemInfoA( hmenu
, 0, TRUE
, &info
);
1008 ok (rc
, "SetMenuItemInfo failed\n");
1010 ok (GetMenuStringA( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
1011 ok (!strcmp( strback
, "string2" ), "Menu text from Ansi version incorrect\n");
1013 /* crashes with wine 0.9.5 */
1014 memset(&info
, 0x00, sizeof(info
));
1015 info
.cbSize
= sizeof(MENUITEMINFOA
);
1016 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
; /* Set OwnerDraw + typeData */
1017 info
.fType
= MFT_OWNERDRAW
;
1018 rc
= InsertMenuItemA( hmenu
, 0, TRUE
, &info
);
1019 ok (rc
, "InsertMenuItem failed\n");
1020 ok (!GetMenuStringA( hmenu
, 0, NULL
, 0, MF_BYPOSITION
),
1021 "GetMenuString on ownerdraw entry succeeded.\n");
1022 SetLastError(0xdeadbeef);
1023 ret
= GetMenuStringW( hmenu
, 0, NULL
, 0, MF_BYPOSITION
);
1024 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1025 win_skip("GetMenuStringW is not implemented\n");
1027 ok (!ret
, "GetMenuStringW on ownerdraw entry succeeded.\n");
1029 DestroyMenu( hmenu
);
1032 /* define building blocks for the menu item info tests */
1033 static int strncmpW( const WCHAR
*str1
, const WCHAR
*str2
, int n
)
1035 if (n
<= 0) return 0;
1036 while ((--n
> 0) && *str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
1037 return *str1
- *str2
;
1040 static WCHAR
*strcpyW( WCHAR
*dst
, const WCHAR
*src
)
1043 while ((*p
++ = *src
++));
1047 static void insert_menu_item( int line
, HMENU hmenu
, BOOL ansi
, UINT mask
, UINT type
, UINT state
, UINT id
,
1048 HMENU submenu
, HBITMAP checked
, HBITMAP unchecked
, ULONG_PTR data
,
1049 void *type_data
, UINT len
, HBITMAP item
, BOOL expect
)
1054 /* magic bitmap handle to test smaller cbSize */
1055 if (item
== (HBITMAP
)(ULONG_PTR
)0xdeadbeef)
1056 info
.cbSize
= FIELD_OFFSET(MENUITEMINFOA
,hbmpItem
);
1058 info
.cbSize
= sizeof(info
);
1061 info
.fState
= state
;
1063 info
.hSubMenu
= submenu
;
1064 info
.hbmpChecked
= checked
;
1065 info
.hbmpUnchecked
= unchecked
;
1066 info
.dwItemData
= data
;
1067 info
.dwTypeData
= type_data
;
1069 info
.hbmpItem
= item
;
1070 SetLastError( 0xdeadbeef );
1071 if (ansi
) ret
= InsertMenuItemA( hmenu
, 0, TRUE
, &info
);
1072 else ret
= InsertMenuItemW( hmenu
, 0, TRUE
, (MENUITEMINFOW
*)&info
);
1073 if (!expect
) ok_(__FILE__
, line
)( !ret
, "InsertMenuItem should have failed.\n" );
1074 else ok_(__FILE__
, line
)( ret
, "InsertMenuItem failed, err %u\n", GetLastError());
1077 static void check_menu_item_info( int line
, HMENU hmenu
, BOOL ansi
, UINT mask
, UINT type
, UINT state
,
1078 UINT id
, HMENU submenu
, HBITMAP checked
, HBITMAP unchecked
,
1079 ULONG_PTR data
, void *type_data
, UINT in_len
, UINT out_len
,
1080 HBITMAP item
, LPCSTR expname
, BOOL expect
, BOOL expstring
)
1086 SetLastError( 0xdeadbeef );
1087 memset( &info
, 0xcc, sizeof(info
) );
1088 info
.cbSize
= sizeof(info
);
1090 info
.dwTypeData
= type_data
;
1093 ret
= ansi
? GetMenuItemInfoA( hmenu
, 0, TRUE
, &info
) :
1094 GetMenuItemInfoW( hmenu
, 0, TRUE
, (MENUITEMINFOW
*)&info
);
1097 ok_(__FILE__
, line
)( !ret
, "GetMenuItemInfo should have failed.\n" );
1100 ok_(__FILE__
, line
)( ret
, "GetMenuItemInfo failed, err %u\n", GetLastError());
1101 if (mask
& MIIM_TYPE
)
1102 ok_(__FILE__
, line
)( info
.fType
== type
|| info
.fType
== LOWORD(type
),
1103 "wrong type %x/%x\n", info
.fType
, type
);
1104 if (mask
& MIIM_STATE
)
1105 ok_(__FILE__
, line
)( info
.fState
== state
|| info
.fState
== LOWORD(state
),
1106 "wrong state %x/%x\n", info
.fState
, state
);
1108 ok_(__FILE__
, line
)( info
.wID
== id
|| info
.wID
== LOWORD(id
),
1109 "wrong id %x/%x\n", info
.wID
, id
);
1110 if (mask
& MIIM_SUBMENU
)
1111 ok_(__FILE__
, line
)( info
.hSubMenu
== submenu
|| (ULONG_PTR
)info
.hSubMenu
== LOWORD(submenu
),
1112 "wrong submenu %p/%p\n", info
.hSubMenu
, submenu
);
1113 if (mask
& MIIM_CHECKMARKS
)
1115 ok_(__FILE__
, line
)( info
.hbmpChecked
== checked
|| (ULONG_PTR
)info
.hbmpChecked
== LOWORD(checked
),
1116 "wrong bmpchecked %p/%p\n", info
.hbmpChecked
, checked
);
1117 ok_(__FILE__
, line
)( info
.hbmpUnchecked
== unchecked
|| (ULONG_PTR
)info
.hbmpUnchecked
== LOWORD(unchecked
),
1118 "wrong bmpunchecked %p/%p\n", info
.hbmpUnchecked
, unchecked
);
1120 if (mask
& MIIM_DATA
)
1121 ok_(__FILE__
, line
)( info
.dwItemData
== data
|| info
.dwItemData
== LOWORD(data
),
1122 "wrong item data %lx/%lx\n", info
.dwItemData
, data
);
1123 if (mask
& MIIM_BITMAP
)
1124 ok_(__FILE__
, line
)( info
.hbmpItem
== item
|| (ULONG_PTR
)info
.hbmpItem
== LOWORD(item
),
1125 "wrong bmpitem %p/%p\n", info
.hbmpItem
, item
);
1126 ok_(__FILE__
, line
)( info
.dwTypeData
== type_data
|| (ULONG_PTR
)info
.dwTypeData
== LOWORD(type_data
),
1127 "wrong type data %p/%p\n", info
.dwTypeData
, type_data
);
1128 ok_(__FILE__
, line
)( info
.cch
== out_len
||
1129 broken(! ansi
&& info
.cch
== 2 * out_len
) /* East-Asian */,
1130 "wrong len %x/%x\n", info
.cch
, out_len
);
1134 ok_(__FILE__
, line
)( !strncmp( expname
, info
.dwTypeData
, out_len
),
1135 "menu item name differed from '%s' '%s'\n", expname
, info
.dwTypeData
);
1137 ok_(__FILE__
, line
)( !strncmpW( (WCHAR
*)expname
, (WCHAR
*)info
.dwTypeData
, out_len
),
1138 "menu item name wrong\n" );
1140 SetLastError( 0xdeadbeef );
1141 ret
= ansi
? GetMenuStringA( hmenu
, 0, (char *)buffer
, 80, MF_BYPOSITION
) :
1142 GetMenuStringW( hmenu
, 0, buffer
, 80, MF_BYPOSITION
);
1144 ok_(__FILE__
, line
)( ret
, "GetMenuString failed, err %u\n", GetLastError());
1146 ok_(__FILE__
, line
)( !ret
, "GetMenuString should have failed\n" );
1150 static void modify_menu( int line
, HMENU hmenu
, BOOL ansi
, UINT flags
, UINT_PTR id
, void *data
)
1154 SetLastError( 0xdeadbeef );
1155 if (ansi
) ret
= ModifyMenuA( hmenu
, 0, flags
, id
, data
);
1156 else ret
= ModifyMenuW( hmenu
, 0, flags
, id
, data
);
1157 ok_(__FILE__
,line
)( ret
, "ModifyMenuA failed, err %u\n", GetLastError());
1160 static void set_menu_item_info( int line
, HMENU hmenu
, BOOL ansi
, UINT mask
, UINT type
, UINT state
,
1161 UINT id
, HMENU submenu
, HBITMAP checked
, HBITMAP unchecked
, ULONG_PTR data
,
1162 void *type_data
, UINT len
, HBITMAP item
)
1168 /* magic bitmap handle to test smaller cbSize */
1169 if (item
== (HBITMAP
)(ULONG_PTR
)0xdeadbeef)
1170 info
.cbSize
= FIELD_OFFSET(MENUITEMINFOA
,hbmpItem
);
1172 info
.cbSize
= sizeof(info
);
1175 info
.fState
= state
;
1177 info
.hSubMenu
= submenu
;
1178 info
.hbmpChecked
= checked
;
1179 info
.hbmpUnchecked
= unchecked
;
1180 info
.dwItemData
= data
;
1181 info
.dwTypeData
= type_data
;
1183 info
.hbmpItem
= item
;
1184 SetLastError( 0xdeadbeef );
1185 if (ansi
) ret
= SetMenuItemInfoA( hmenu
, 0, TRUE
, &info
);
1186 else ret
= SetMenuItemInfoW( hmenu
, 0, TRUE
, (MENUITEMINFOW
*)&info
);
1187 ok_(__FILE__
, line
)( ret
, "SetMenuItemInfo failed, err %u\n", GetLastError());
1190 #define TMII_INSMI( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,eret1 )\
1191 hmenu = CreateMenu();\
1192 submenu = CreateMenu();\
1193 if(ansi)strcpy( string, init );\
1194 else strcpyW( string, init );\
1195 insert_menu_item( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, eret1 )
1197 /* GetMenuItemInfo + GetMenuString */
1198 #define TMII_GMII( c2,l2,\
1199 d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,\
1200 expname, eret2, eret3)\
1201 check_menu_item_info( __LINE__, hmenu, ansi, c2, d3, e3, f3, g3, h3, i3, j3, k3, l2, l3, m3, \
1202 expname, eret2, eret3 )
1205 RemoveMenu(hmenu, 0, TRUE );\
1206 DestroyMenu( hmenu );\
1207 DestroyMenu( submenu );
1210 #define TMII_MODM( flags, id, data ) \
1211 modify_menu( __LINE__, hmenu, ansi, flags, id, data )
1213 /* SetMenuItemInfo */
1214 #define TMII_SMII( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1 ) \
1215 set_menu_item_info( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1 )
1222 static void test_menu_iteminfo( void )
1228 WCHAR txtW
[]={'W','i','n','e',0};
1229 WCHAR initW
[]={'X','Y','Z',0};
1231 void *txt
, *init
, *empty
, *string
;
1232 HBITMAP hbm
= CreateBitmap(1,1,1,1,NULL
);
1234 HMENU hmenu
, submenu
;
1235 HBITMAP dummy_hbm
= (HBITMAP
)(ULONG_PTR
)0xdeadbeef;
1238 if( ansi
) {txt
=txtA
;init
=initA
;empty
=emptyA
;string
=stringA
;}
1239 else {txt
=txtW
;init
=initW
;empty
=emptyW
;string
=stringA
;}
1240 trace( "%s string %p hbm %p txt %p\n", ansi
? "ANSI tests: " : "Unicode tests:", string
, hbm
, txt
);
1241 /* test all combinations of MFT_STRING, MFT_OWNERDRAW and MFT_BITMAP */
1242 /* (since MFT_STRING is zero, there are four of them) */
1243 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, 0, 0, 0, 0, 0, 0, txt
, 0, 0, OK
);
1244 TMII_GMII ( MIIM_TYPE
, 80,
1245 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1248 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1249 TMII_GMII ( MIIM_TYPE
, 80,
1250 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1253 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, 6, 0, OK
);
1254 TMII_GMII ( MIIM_TYPE
, 80,
1255 MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1258 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, hbm
, 6, 0, OK
);
1259 TMII_GMII ( MIIM_TYPE
, 80,
1260 MFT_BITMAP
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1263 /* not enough space for name*/
1264 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1265 TMII_GMII ( MIIM_TYPE
, 0,
1266 MFT_STRING
, 0, 0, 0, 0, 0, 0, NULL
, 4, 0,
1269 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1270 TMII_GMII ( MIIM_TYPE
, 5,
1271 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1274 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1275 TMII_GMII ( MIIM_TYPE
, 4,
1276 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 3, 0,
1279 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1280 TMII_GMII ( MIIM_TYPE
, 0,
1281 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 0, 0,
1284 /* cannot combine MIIM_TYPE with some other flags */
1285 TMII_INSMI( MIIM_TYPE
|MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, ER
);
1287 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1288 TMII_GMII ( MIIM_TYPE
|MIIM_STRING
, 80,
1289 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1292 TMII_INSMI( MIIM_TYPE
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, ER
);
1294 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1295 TMII_GMII ( MIIM_TYPE
|MIIM_FTYPE
, 80,
1296 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1299 TMII_INSMI( MIIM_TYPE
|MIIM_BITMAP
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, 6, hbm
, ER
);
1301 /* but succeeds with some others */
1302 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1303 TMII_GMII ( MIIM_TYPE
|MIIM_SUBMENU
, 80,
1304 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1307 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1308 TMII_GMII ( MIIM_TYPE
|MIIM_STATE
, 80,
1309 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1312 TMII_INSMI( MIIM_TYPE
|MIIM_ID
, MFT_STRING
, -1, 888, 0, 0, 0, -1, txt
, 6, 0, OK
);
1313 TMII_GMII ( MIIM_TYPE
|MIIM_ID
, 80,
1314 MFT_STRING
, 0, 888, 0, 0, 0, 0, string
, 4, 0,
1317 TMII_INSMI( MIIM_TYPE
|MIIM_DATA
, MFT_STRING
, -1, -1, 0, 0, 0, 999, txt
, 6, 0, OK
);
1318 TMII_GMII ( MIIM_TYPE
|MIIM_DATA
, 80,
1319 MFT_STRING
, 0, 0, 0, 0, 0, 999, string
, 4, 0,
1322 /* to be continued */
1323 /* set text with MIIM_TYPE and retrieve with MIIM_STRING */
1324 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1325 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1326 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1329 /* set text with MIIM_TYPE and retrieve with MIIM_STRING; MFT_OWNERDRAW causes an empty string */
1330 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1331 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1332 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1335 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1336 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1337 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1340 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1341 TMII_GMII ( MIIM_FTYPE
, 80,
1342 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 80, 0,
1345 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1347 0, 0, 0, 0, 0, 0, 0, string
, 80, 0,
1350 /* contrary to MIIM_TYPE,you can set the text for an owner draw menu */
1351 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1352 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1353 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1356 /* same but retrieve with MIIM_TYPE */
1357 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1358 TMII_GMII ( MIIM_TYPE
, 80,
1359 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1362 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1363 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1364 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1367 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1368 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1369 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1373 /* How is that with bitmaps? */
1374 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1375 TMII_GMII ( MIIM_TYPE
, 80,
1376 MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1379 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1380 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1381 0, 0, 0, 0, 0, 0, 0, string
, 80, hbm
,
1384 /* MIIM_BITMAP does not like MFT_BITMAP */
1385 TMII_INSMI( MIIM_BITMAP
|MIIM_FTYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, ER
);
1387 /* no problem with OWNERDRAWN */
1388 TMII_INSMI( MIIM_BITMAP
|MIIM_FTYPE
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1389 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1390 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 80, hbm
,
1393 /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1394 TMII_INSMI( MIIM_FTYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER
);
1397 /* menu with submenu */
1398 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, submenu
, 0, 0, -1, txt
, 0, 0, OK
);
1399 TMII_GMII ( MIIM_SUBMENU
, 80,
1400 0, 0, 0, submenu
, 0, 0, 0, string
, 80, 0,
1403 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, submenu
, 0, 0, -1, empty
, 0, 0, OK
);
1404 TMII_GMII ( MIIM_SUBMENU
, 80,
1405 0, 0, 0, submenu
, 0, 0, 0, string
, 80, 0,
1408 /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1409 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, submenu
, 0, 0, -1, txt
, 0, 0, OK
);
1410 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1411 MFT_STRING
|MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1413 TMII_GMII ( MIIM_SUBMENU
|MIIM_FTYPE
, 80,
1414 MFT_SEPARATOR
, 0, 0, submenu
, 0, 0, 0, string
, 80, 0,
1417 /* menu with invalid submenu */
1418 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, (HMENU
)999, 0, 0, -1, txt
, 0, 0, ER
);
1421 TMII_INSMI( MIIM_TYPE
, MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, txt
, 0, 0, OK
);
1422 TMII_GMII ( MIIM_TYPE
, 80,
1423 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1426 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
|MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, hbm
, 6, 0, OK
);
1427 TMII_GMII ( MIIM_TYPE
, 80,
1428 MFT_BITMAP
|MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1431 /* SEPARATOR and STRING go well together */
1432 /* BITMAP and STRING go well together */
1433 TMII_INSMI( MIIM_STRING
|MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1434 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, 80,
1435 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, hbm
,
1438 /* BITMAP, SEPARATOR and STRING go well together */
1439 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1440 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, 80,
1441 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 4, hbm
,
1444 /* last two tests, but use MIIM_TYPE to retrieve info */
1445 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1446 TMII_GMII ( MIIM_TYPE
, 80,
1447 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1450 TMII_INSMI( MIIM_STRING
|MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1451 TMII_GMII ( MIIM_TYPE
, 80,
1452 MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1455 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1456 TMII_GMII ( MIIM_TYPE
, 80,
1457 MFT_SEPARATOR
|MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1460 /* same three with MFT_OWNERDRAW */
1461 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
, MFT_SEPARATOR
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1462 TMII_GMII ( MIIM_TYPE
, 80,
1463 MFT_SEPARATOR
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1466 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1467 TMII_GMII ( MIIM_TYPE
, 80,
1468 MFT_BITMAP
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1471 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1472 TMII_GMII ( MIIM_TYPE
, 80,
1473 MFT_SEPARATOR
|MFT_BITMAP
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1477 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
|MIIM_ID
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1478 TMII_GMII ( MIIM_TYPE
, 80,
1479 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1482 /* test with modifymenu: string is preserved after setting OWNERDRAW */
1483 TMII_INSMI( MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1484 TMII_MODM( MFT_OWNERDRAW
, -1, (void*)787 );
1485 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_DATA
, 80,
1486 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 787, string
, 4, 0,
1489 /* same with bitmap: now the text is cleared */
1490 TMII_INSMI( MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1491 TMII_MODM( MFT_BITMAP
, 545, hbm
);
1492 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1493 MFT_BITMAP
, 0, 545, 0, 0, 0, 0, string
, 0, hbm
,
1496 /* start with bitmap: now setting text clears it (though he flag is raised) */
1497 TMII_INSMI( MIIM_BITMAP
, MFT_STRING
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1498 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1499 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 0, hbm
,
1501 TMII_MODM( MFT_STRING
, 545, txt
);
1502 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1503 MFT_STRING
, 0, 545, 0, 0, 0, 0, string
, 4, 0,
1506 /*repeat with text NULL */
1507 TMII_INSMI( MIIM_BITMAP
, MFT_STRING
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1508 TMII_MODM( MFT_STRING
, 545, NULL
);
1509 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1510 MFT_SEPARATOR
, 0, 545, 0, 0, 0, 0, string
, 0, 0,
1513 /* repeat with text "" */
1514 TMII_INSMI( MIIM_BITMAP
, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1515 TMII_MODM( MFT_STRING
, 545, empty
);
1516 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1517 MFT_STRING
, 0, 545, 0, 0, 0, 0, string
, 0, 0,
1520 /* start with bitmap: set ownerdraw */
1521 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1522 TMII_MODM( MFT_OWNERDRAW
, -1, (void *)232 );
1523 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_DATA
, 80,
1524 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 232, string
, 0, hbm
,
1528 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1530 0, 0, 0, 0, 0, 0, 0, string
, 80, 0,
1533 /* some tests with small cbSize: the hbmpItem is to be ignored */
1534 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm
, OK
);
1535 TMII_GMII ( MIIM_TYPE
, 80,
1536 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, NULL
, 0, NULL
,
1539 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm
, OK
);
1540 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1541 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 80, NULL
,
1544 TMII_INSMI( MIIM_STRING
|MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1545 TMII_GMII ( MIIM_TYPE
, 80,
1546 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, NULL
,
1549 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1550 TMII_GMII ( MIIM_TYPE
, 80,
1551 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1554 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1555 TMII_GMII ( MIIM_TYPE
, 80,
1556 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1559 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1560 TMII_GMII ( MIIM_TYPE
, 80,
1561 MFT_SEPARATOR
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1564 /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus */
1565 TMII_INSMI( MIIM_TYPE
|MIIM_DATA
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, 343, txt
, 0, 0, OK
);
1566 TMII_GMII ( MIIM_TYPE
|MIIM_DATA
, 80,
1567 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1570 TMII_INSMI( MIIM_TYPE
|MIIM_DATA
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, 343, txt
, 0, 0, OK
);
1571 TMII_GMII ( MIIM_TYPE
, 80,
1572 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1575 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, 343, txt
, 0, 0, OK
);
1576 TMII_GMII ( MIIM_TYPE
|MIIM_DATA
, 80,
1577 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1580 /* set a string menu to ownerdraw with MIIM_TYPE */
1581 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -2, -2, 0, 0, 0, -2, txt
, -2, 0, OK
);
1582 TMII_SMII ( MIIM_TYPE
, MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1583 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1584 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1587 /* test with modifymenu add submenu */
1588 TMII_INSMI( MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1589 TMII_MODM( MF_POPUP
, (UINT_PTR
)submenu
, txt
);
1590 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_SUBMENU
, 80,
1591 MFT_STRING
, 0, 0, submenu
, 0, 0, 0, string
, 4, 0,
1593 TMII_GMII ( MIIM_TYPE
, 80,
1594 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1597 /* MFT_SEPARATOR bit is kept when the text is added */
1598 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1599 TMII_SMII( MIIM_STRING
, 0, 0, 0, 0, 0, 0, 0, txt
, 0, 0 );
1600 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1601 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1604 /* MFT_SEPARATOR bit is kept when bitmap is added */
1605 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1606 TMII_SMII( MIIM_BITMAP
, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm
);
1607 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1608 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 80, hbm
,
1611 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1612 Only the low word of the dwTypeData is used.
1613 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1614 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_RIGHTJUSTIFY
, -1, -1, 0, 0, 0, -1,
1615 (HMENU
)MAKELONG(HBMMENU_MBAR_CLOSE
, 0x1234), -1, 0, OK
);
1616 TMII_GMII ( MIIM_TYPE
, 80,
1617 MFT_BITMAP
| MFT_RIGHTJUSTIFY
, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE
, 0, HBMMENU_MBAR_CLOSE
,
1621 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1622 TMII_GMII ( MIIM_TYPE
, 80,
1623 MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1627 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1628 TMII_SMII( MIIM_STATE
, -1, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 0, 0 );
1629 TMII_GMII ( MIIM_STATE
, 80,
1630 0, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 80, 0,
1633 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1634 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1635 TMII_SMII( MIIM_CHECKMARKS
, MFT_RADIOCHECK
, 0, 0, 0, hbm
, hbm
, 0, 0, 0, 0 );
1636 TMII_GMII ( MIIM_CHECKMARKS
| MIIM_TYPE
, 80,
1637 MFT_BITMAP
, 0, 0, 0, hbm
, hbm
, 0, hbm
, 0, hbm
,
1640 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1641 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1642 TMII_SMII( MIIM_FTYPE
, MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, (HBITMAP
)0x1234, 0, 0 );
1643 TMII_GMII ( MIIM_FTYPE
, 80,
1644 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1646 TMII_GMII ( MIIM_TYPE
, 80,
1647 MFT_BITMAP
| MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1649 TMII_GMII ( MIIM_FTYPE
, 80,
1650 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1652 TMII_SMII( MIIM_BITMAP
, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
);
1653 TMII_GMII ( MIIM_TYPE
, 80,
1654 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 0, NULL
,
1657 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1658 Only the low word of the dwTypeData is used.
1659 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1660 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_RIGHTJUSTIFY
, -1, -1, 0, 0, 0, -1,
1661 (HMENU
)MAKELONG(HBMMENU_MBAR_CLOSE
, 0x1234), -1, 0, OK
);
1662 TMII_GMII ( MIIM_TYPE
, 80,
1663 MFT_BITMAP
| MFT_RIGHTJUSTIFY
, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE
, 0, HBMMENU_MBAR_CLOSE
,
1667 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1668 TMII_GMII ( MIIM_TYPE
, 80,
1669 MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1673 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1674 TMII_SMII( MIIM_STATE
, -1, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 0, 0 );
1675 TMII_GMII ( MIIM_STATE
, 80,
1676 0, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 80, 0,
1679 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1680 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1681 TMII_SMII( MIIM_CHECKMARKS
, MFT_RADIOCHECK
, 0, 0, 0, hbm
, hbm
, 0, 0, 0, 0 );
1682 TMII_GMII ( MIIM_CHECKMARKS
| MIIM_TYPE
, 80,
1683 MFT_BITMAP
, 0, 0, 0, hbm
, hbm
, 0, hbm
, 0, hbm
,
1686 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1687 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1688 TMII_SMII( MIIM_FTYPE
, MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, (HBITMAP
)0x1234, 0, 0 );
1689 TMII_GMII ( MIIM_FTYPE
, 80,
1690 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1692 TMII_GMII ( MIIM_TYPE
, 80,
1693 MFT_BITMAP
| MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1695 TMII_GMII ( MIIM_FTYPE
, 80,
1696 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1698 TMII_SMII( MIIM_BITMAP
, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
);
1699 TMII_GMII ( MIIM_TYPE
, 80,
1700 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 0, NULL
,
1703 } while( !(ansi
= !ansi
) );
1708 The following tests try to confirm the algorithm used to return the menu items
1709 when there is a collision between a menu item and a popup menu
1711 static void test_menu_search_bycommand( void )
1713 HMENU hmenu
, hmenuSub
, hmenuSub2
;
1719 static CHAR menuitem
[] = "MenuItem",
1720 menuitem2
[] = "MenuItem 2";
1722 /* Case 1: Menu containing a menu item */
1723 hmenu
= CreateMenu();
1725 memset( &info
, 0, sizeof info
);
1726 info
.cbSize
= sizeof info
;
1727 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1728 info
.fType
= MFT_STRING
;
1729 strcpy(strIn
, "Case 1 MenuItem");
1730 info
.dwTypeData
= strIn
;
1731 info
.wID
= (UINT
) 0x1234;
1733 rc
= InsertMenuItemA(hmenu
, 0, TRUE
, &info
);
1734 ok (rc
, "Inserting the menuitem failed\n");
1736 id
= GetMenuItemID(hmenu
, 0);
1737 ok (id
== 0x1234, "Getting the menuitem id failed(gave %x)\n", id
);
1739 /* Confirm the menuitem was given the id supplied (getting by position) */
1740 memset( &info
, 0, sizeof info
);
1742 info
.cbSize
= sizeof(MENUITEMINFOA
);
1743 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1744 info
.dwTypeData
= strback
;
1745 info
.cch
= sizeof(strback
);
1747 rc
= GetMenuItemInfoA(hmenu
, 0, TRUE
, &info
); /* Get by position */
1748 ok (rc
, "Getting the menu items info failed\n");
1749 ok (info
.wID
== 0x1234, "IDs differ for the menuitem\n");
1750 ok (!strcmp(info
.dwTypeData
, "Case 1 MenuItem"), "Returned item has wrong label\n");
1752 /* Search by id - Should return the item */
1753 memset( &info
, 0, sizeof info
);
1755 info
.cbSize
= sizeof(MENUITEMINFOA
);
1756 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1757 info
.dwTypeData
= strback
;
1758 info
.cch
= sizeof(strback
);
1759 rc
= GetMenuItemInfoA(hmenu
, 0x1234, FALSE
, &info
); /* Get by ID */
1761 ok (rc
, "Getting the menu items info failed\n");
1762 ok (info
.wID
== 0x1234, "IDs differ for the menuitem\n");
1763 ok (!strcmp(info
.dwTypeData
, "Case 1 MenuItem"), "Returned item has wrong label\n");
1765 DestroyMenu( hmenu
);
1767 /* Case 2: Menu containing a popup menu */
1768 hmenu
= CreateMenu();
1769 hmenuSub
= CreateMenu();
1771 strcpy(strIn
, "Case 2 SubMenu");
1772 rc
= InsertMenuA(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, strIn
);
1773 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1775 id
= GetMenuItemID(hmenu
, 0);
1776 ok (id
== -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id
);
1778 /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
1779 memset( &info
, 0, sizeof info
);
1781 info
.cbSize
= sizeof(MENUITEMINFOA
);
1782 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1783 info
.dwTypeData
= strback
;
1784 info
.cch
= sizeof(strback
);
1785 info
.wID
= 0xdeadbeef;
1787 rc
= GetMenuItemInfoA(hmenu
, 0, TRUE
, &info
); /* Get by position */
1788 ok (rc
, "Getting the menu items info failed\n");
1789 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the menuitem\n");
1790 ok (!strcmp(info
.dwTypeData
, "Case 2 SubMenu"), "Returned item has wrong label\n");
1792 /* Search by id - returns the popup menu itself */
1793 memset( &info
, 0, sizeof info
);
1795 info
.cbSize
= sizeof(MENUITEMINFOA
);
1796 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1797 info
.dwTypeData
= strback
;
1798 info
.cch
= sizeof(strback
);
1799 rc
= GetMenuItemInfoA(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
); /* Get by ID */
1801 ok (rc
, "Getting the menu items info failed\n");
1802 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the popup menu\n");
1803 ok (!strcmp(info
.dwTypeData
, "Case 2 SubMenu"), "Returned item has wrong label\n");
1806 Now add an item after it with the same id
1808 memset( &info
, 0, sizeof info
);
1809 info
.cbSize
= sizeof info
;
1810 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1811 info
.fType
= MFT_STRING
;
1812 strcpy(strIn
, "Case 2 MenuItem 1");
1813 info
.dwTypeData
= strIn
;
1814 info
.wID
= (UINT_PTR
) hmenuSub
;
1815 rc
= InsertMenuItemA(hmenu
, -1, TRUE
, &info
);
1816 ok (rc
, "Inserting the menuitem failed\n");
1818 /* Search by id - returns the item which follows the popup menu */
1819 memset( &info
, 0, sizeof info
);
1821 info
.cbSize
= sizeof(MENUITEMINFOA
);
1822 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1823 info
.dwTypeData
= strback
;
1824 info
.cch
= sizeof(strback
);
1825 rc
= GetMenuItemInfoA(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
); /* Get by ID */
1827 ok (rc
, "Getting the menu items info failed\n");
1828 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the popup menu\n");
1829 ok (!strcmp(info
.dwTypeData
, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1832 Now add an item before the popup (with the same id)
1834 memset( &info
, 0, sizeof info
);
1835 info
.cbSize
= sizeof info
;
1836 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1837 info
.fType
= MFT_STRING
;
1838 strcpy(strIn
, "Case 2 MenuItem 2");
1839 info
.dwTypeData
= strIn
;
1840 info
.wID
= (UINT_PTR
) hmenuSub
;
1841 rc
= InsertMenuItemA(hmenu
, 0, TRUE
, &info
);
1842 ok (rc
, "Inserting the menuitem failed\n");
1844 /* Search by id - returns the item which precedes the popup menu */
1845 memset( &info
, 0, sizeof info
);
1847 info
.cbSize
= sizeof(MENUITEMINFOA
);
1848 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1849 info
.dwTypeData
= strback
;
1850 info
.cch
= sizeof(strback
);
1851 rc
= GetMenuItemInfoA(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
); /* Get by ID */
1853 ok (rc
, "Getting the menu items info failed\n");
1854 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the popup menu\n");
1855 ok (!strcmp(info
.dwTypeData
, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1857 DestroyMenu( hmenu
);
1858 DestroyMenu( hmenuSub
);
1861 Case 3: Menu containing a popup menu which in turn
1862 contains 2 items with the same id as the popup itself
1865 hmenu
= CreateMenu();
1866 hmenuSub
= CreateMenu();
1868 memset( &info
, 0, sizeof info
);
1869 info
.cbSize
= sizeof info
;
1870 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1871 info
.fType
= MFT_STRING
;
1872 info
.dwTypeData
= menuitem
;
1873 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1875 rc
= InsertMenuA(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, "Submenu");
1876 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1878 rc
= InsertMenuItemA(hmenuSub
, 0, TRUE
, &info
);
1879 ok (rc
, "Inserting the sub menu menuitem failed\n");
1881 memset( &info
, 0, sizeof info
);
1882 info
.cbSize
= sizeof info
;
1883 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1884 info
.fType
= MFT_STRING
;
1885 info
.dwTypeData
= menuitem2
;
1886 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1888 rc
= InsertMenuItemA(hmenuSub
, 1, TRUE
, &info
);
1889 ok (rc
, "Inserting the sub menu menuitem 2 failed\n");
1891 /* Prove that you can't query the id of a popup directly (By position) */
1892 id
= GetMenuItemID(hmenu
, 0);
1893 ok (id
== -1, "Getting the sub menu id should have failed because it's a popup (gave %x)\n", id
);
1895 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1896 memset( &info
, 0, sizeof info
);
1898 info
.cbSize
= sizeof(MENUITEMINFOA
);
1899 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1900 info
.dwTypeData
= strback
;
1901 info
.cch
= sizeof(strback
);
1903 rc
= GetMenuItemInfoA(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
);
1904 ok (rc
, "Getting the menus info failed\n");
1905 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for popup menu\n");
1906 ok (!strcmp(info
.dwTypeData
, "MenuItem"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1907 DestroyMenu( hmenu
);
1908 DestroyMenu( hmenuSub
);
1911 Case 4: Menu containing 2 popup menus, the second
1912 contains 2 items with the same id as the first popup menu
1914 hmenu
= CreateMenu();
1915 hmenuSub
= CreateMenu();
1916 hmenuSub2
= CreateMenu();
1918 rc
= InsertMenuA(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, "Submenu");
1919 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1921 rc
= InsertMenuA(hmenu
, 1, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub2
, "Submenu2");
1922 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1924 memset( &info
, 0, sizeof info
);
1925 info
.cbSize
= sizeof info
;
1926 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1927 info
.fType
= MFT_STRING
;
1928 info
.dwTypeData
= menuitem
;
1929 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1931 rc
= InsertMenuItemA(hmenuSub2
, 0, TRUE
, &info
);
1932 ok (rc
, "Inserting the sub menu menuitem failed\n");
1934 memset( &info
, 0, sizeof info
);
1935 info
.cbSize
= sizeof info
;
1936 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1937 info
.fType
= MFT_STRING
;
1938 info
.dwTypeData
= menuitem2
;
1939 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1941 rc
= InsertMenuItemA(hmenuSub2
, 1, TRUE
, &info
);
1942 ok (rc
, "Inserting the sub menu menuitem 2 failed\n");
1944 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1945 memset( &info
, 0, sizeof info
);
1947 info
.cbSize
= sizeof(MENUITEMINFOA
);
1948 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1949 info
.dwTypeData
= strback
;
1950 info
.cch
= sizeof(strback
);
1952 rc
= GetMenuItemInfoA(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
);
1953 ok (rc
, "Getting the menus info failed\n");
1954 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for popup menu\n");
1955 ok (!strcmp(info
.dwTypeData
, "MenuItem"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1957 memset( &info
, 0, sizeof info
);
1959 info
.cbSize
= sizeof(MENUITEMINFOA
);
1960 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1961 info
.dwTypeData
= strback
;
1962 info
.cch
= sizeof(strback
);
1964 rc
= GetMenuItemInfoA(hmenu
, (UINT_PTR
)hmenuSub2
, FALSE
, &info
);
1965 ok (rc
, "Getting the menus info failed\n");
1966 ok (info
.wID
== (UINT_PTR
)hmenuSub2
, "IDs differ for popup menu\n");
1967 ok (!strcmp(info
.dwTypeData
, "Submenu2"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1969 DestroyMenu( hmenu
);
1970 DestroyMenu( hmenuSub
);
1971 DestroyMenu( hmenuSub2
);
1975 Case 5: Menu containing a popup menu which in turn
1976 contains an item with a different id than the popup menu.
1977 This tests the fallback to a popup menu ID.
1980 hmenu
= CreateMenu();
1981 hmenuSub
= CreateMenu();
1983 rc
= AppendMenuA(hmenu
, MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, "Submenu");
1984 ok (rc
, "Appending the popup menu to the main menu failed\n");
1986 rc
= AppendMenuA(hmenuSub
, MF_STRING
, 102, "Item");
1987 ok (rc
, "Appending the item to the popup menu failed\n");
1989 /* Set the ID for hmenuSub */
1990 info
.cbSize
= sizeof(info
);
1991 info
.fMask
= MIIM_ID
;
1994 rc
= SetMenuItemInfoA(hmenu
, 0, TRUE
, &info
);
1995 ok(rc
, "Setting the ID for the popup menu failed\n");
1997 /* Check if the ID has been set */
1999 rc
= GetMenuItemInfoA(hmenu
, 0, TRUE
, &info
);
2000 ok(rc
, "Getting the ID for the popup menu failed\n");
2001 ok(info
.wID
== 101, "The ID for the popup menu has not been set\n");
2003 /* Prove getting the item info via ID returns the popup menu */
2004 memset( &info
, 0, sizeof(info
));
2006 info
.cbSize
= sizeof(MENUITEMINFOA
);
2007 info
.fMask
= MIIM_STRING
| MIIM_ID
;
2008 info
.dwTypeData
= strback
;
2009 info
.cch
= sizeof(strback
);
2011 rc
= GetMenuItemInfoA(hmenu
, 101, FALSE
, &info
);
2012 ok (rc
, "Getting the menu info failed\n");
2013 ok (info
.wID
== 101, "IDs differ\n");
2014 ok (!strcmp(info
.dwTypeData
, "Submenu"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
2016 /* Also look for the menu item */
2017 memset( &info
, 0, sizeof(info
));
2019 info
.cbSize
= sizeof(MENUITEMINFOA
);
2020 info
.fMask
= MIIM_STRING
| MIIM_ID
;
2021 info
.dwTypeData
= strback
;
2022 info
.cch
= sizeof(strback
);
2024 rc
= GetMenuItemInfoA(hmenu
, 102, FALSE
, &info
);
2025 ok (rc
, "Getting the menu info failed\n");
2026 ok (info
.wID
== 102, "IDs differ\n");
2027 ok (!strcmp(info
.dwTypeData
, "Item"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
2030 DestroyMenu(hmenuSub
);
2033 struct menu_item_pair_s
{
2034 UINT uMenu
; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
2035 * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
2036 * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
2040 static struct menu_mouse_tests_s
{
2042 struct menu_item_pair_s menu_item_pairs
[5]; /* for mousing */
2043 WORD wVk
[5]; /* keys */
2047 /* for each test, send keys or clicks and check for menu visibility */
2048 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 0}, TRUE
, FALSE
}, /* test 0 */
2049 { INPUT_KEYBOARD
, {{0}}, {VK_ESCAPE
, 0}, FALSE
, FALSE
},
2050 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 0}, TRUE
, FALSE
},
2051 { INPUT_KEYBOARD
, {{0}}, {'D', 0}, FALSE
, FALSE
},
2052 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 0}, TRUE
, FALSE
},
2053 { INPUT_KEYBOARD
, {{0}}, {'E', 0}, FALSE
, FALSE
},
2054 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 0}, TRUE
, FALSE
},
2055 { INPUT_KEYBOARD
, {{0}}, {VK_ESCAPE
, VK_ESCAPE
, 0}, FALSE
, FALSE
},
2056 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', VK_ESCAPE
, 0}, TRUE
, FALSE
},
2057 { INPUT_KEYBOARD
, {{0}}, {VK_ESCAPE
, 0}, FALSE
, FALSE
},
2058 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 0}, TRUE
, FALSE
},
2059 { INPUT_KEYBOARD
, {{0}}, {'D', 0}, FALSE
, FALSE
},
2060 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 0}, TRUE
, FALSE
},
2061 { INPUT_KEYBOARD
, {{0}}, {'E', 0}, FALSE
, FALSE
},
2062 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 'P', 0}, TRUE
, FALSE
},
2063 { INPUT_KEYBOARD
, {{0}}, {'D', 0}, FALSE
, FALSE
},
2064 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 'P', 0}, TRUE
, FALSE
},
2065 { INPUT_KEYBOARD
, {{0}}, {'E', 0}, FALSE
, FALSE
},
2066 { INPUT_KEYBOARD
, {{0}}, {VK_F10
, 0}, TRUE
, FALSE
},
2067 { INPUT_KEYBOARD
, {{0}}, {VK_F10
, 0}, FALSE
, FALSE
},
2069 { INPUT_MOUSE
, {{1, 2}, {0}}, {0}, TRUE
, TRUE
}, /* test 20 */
2070 { INPUT_MOUSE
, {{1, 1}, {0}}, {0}, FALSE
, FALSE
},
2071 { INPUT_MOUSE
, {{1, 0}, {0}}, {0}, TRUE
, TRUE
},
2072 { INPUT_MOUSE
, {{1, 1}, {0}}, {0}, FALSE
, FALSE
},
2073 { INPUT_MOUSE
, {{1, 0}, {2, 2}, {0}}, {0}, TRUE
, TRUE
},
2074 { INPUT_MOUSE
, {{2, 1}, {0}}, {0}, FALSE
, FALSE
},
2075 { INPUT_MOUSE
, {{1, 0}, {2, 0}, {0}}, {0}, TRUE
, TRUE
},
2076 { INPUT_MOUSE
, {{3, 0}, {0}}, {0}, FALSE
, FALSE
},
2077 { INPUT_MOUSE
, {{1, 0}, {2, 0}, {0}}, {0}, TRUE
, TRUE
},
2078 { INPUT_MOUSE
, {{3, 1}, {0}}, {0}, TRUE
, TRUE
},
2079 { INPUT_MOUSE
, {{1, 1}, {0}}, {0}, FALSE
, FALSE
},
2083 static void send_key(WORD wVk
)
2086 memset(i
, 0, sizeof(i
));
2087 i
[0].type
= i
[1].type
= INPUT_KEYBOARD
;
2088 i
[0].u
.ki
.wVk
= i
[1].u
.ki
.wVk
= wVk
;
2089 i
[1].u
.ki
.dwFlags
= KEYEVENTF_KEYUP
;
2090 pSendInput(2, (INPUT
*) i
, sizeof(INPUT
));
2093 static BOOL
click_menu(HANDLE hWnd
, struct menu_item_pair_s
*mi
)
2095 HMENU hMenu
= hMenus
[mi
->uMenu
];
2099 int screen_w
= GetSystemMetrics(SM_CXSCREEN
);
2100 int screen_h
= GetSystemMetrics(SM_CYSCREEN
);
2101 BOOL ret
= GetMenuItemRect(mi
->uMenu
> 2 ? NULL
: hWnd
, hMenu
, mi
->uItem
, &r
);
2102 if(!ret
) return FALSE
;
2104 memset(i
, 0, sizeof(i
));
2105 i
[0].type
= i
[1].type
= i
[2].type
= INPUT_MOUSE
;
2106 i
[0].u
.mi
.dx
= i
[1].u
.mi
.dx
= i
[2].u
.mi
.dx
2107 = ((r
.left
+ 5) * 65535) / screen_w
;
2108 i
[0].u
.mi
.dy
= i
[1].u
.mi
.dy
= i
[2].u
.mi
.dy
2109 = ((r
.top
+ 5) * 65535) / screen_h
;
2110 i
[0].u
.mi
.dwFlags
= i
[1].u
.mi
.dwFlags
= i
[2].u
.mi
.dwFlags
2111 = MOUSEEVENTF_ABSOLUTE
;
2112 i
[0].u
.mi
.dwFlags
|= MOUSEEVENTF_MOVE
;
2113 i
[1].u
.mi
.dwFlags
|= MOUSEEVENTF_LEFTDOWN
;
2114 i
[2].u
.mi
.dwFlags
|= MOUSEEVENTF_LEFTUP
;
2115 ret
= pSendInput(3, (INPUT
*) i
, sizeof(INPUT
));
2117 /* hack to prevent mouse message buildup in Wine */
2118 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
2122 static DWORD WINAPI
test_menu_input_thread(LPVOID lpParameter
)
2125 HANDLE hWnd
= lpParameter
;
2128 /* mixed keyboard/mouse test */
2129 for (i
= 0; menu_tests
[i
].type
!= -1; i
++)
2134 got_input
= i
&& menu_tests
[i
-1].bMenuVisible
;
2136 if (menu_tests
[i
].type
== INPUT_KEYBOARD
)
2137 for (j
= 0; menu_tests
[i
].wVk
[j
] != 0; j
++)
2138 send_key(menu_tests
[i
].wVk
[j
]);
2140 for (j
= 0; menu_tests
[i
].menu_item_pairs
[j
].uMenu
!= 0; j
++)
2141 if (!(ret
= click_menu(hWnd
, &menu_tests
[i
].menu_item_pairs
[j
]))) break;
2145 skip( "test %u: failed to send input\n", i
);
2146 PostMessageA( hWnd
, WM_CANCELMODE
, 0, 0 );
2149 while (menu_tests
[i
].bMenuVisible
!= bMenuVisible
)
2159 skip( "test %u: didn't receive input\n", i
);
2160 PostMessageA( hWnd
, WM_CANCELMODE
, 0, 0 );
2164 if (menu_tests
[i
]._todo_wine
)
2167 ok(menu_tests
[i
].bMenuVisible
== bMenuVisible
, "test %d\n", i
);
2171 ok(menu_tests
[i
].bMenuVisible
== bMenuVisible
, "test %d\n", i
);
2176 static LRESULT CALLBACK
WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
,
2180 case WM_ENTERMENULOOP
:
2181 bMenuVisible
= TRUE
;
2183 case WM_INITMENUPOPUP
:
2184 case WM_UNINITMENUPOPUP
:
2185 case WM_EXITMENULOOP
:
2192 case WM_LBUTTONDOWN
:
2194 case WM_NCMOUSEMOVE
:
2195 case WM_NCLBUTTONDOWN
:
2196 case WM_NCLBUTTONUP
:
2200 return( DefWindowProcA( hWnd
, msg
, wParam
, lParam
) );
2210 mbi
.cbSize
= sizeof(MENUBARINFO
);
2212 /* get info for the menu */
2213 br
= pGetMenuBarInfo(hWnd
, OBJID_MENU
, 0, &mbi
);
2214 ok(br
, "msg %x: GetMenuBarInfo failed\n", msg
);
2215 hmenu
= GetMenu(hWnd
);
2216 ok(!mbi
.hwndMenu
, "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected NULL\n",
2218 ok(mbi
.hMenu
== hmenu
, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2219 msg
, mbi
.hMenu
, hmenu
);
2220 ok(!bMenuVisible
== !mbi
.fBarFocused
, "msg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2221 msg
, mbi
.fBarFocused
!= 0);
2222 ok(!bMenuVisible
== !mbi
.fFocused
, "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n",
2223 msg
, mbi
.fFocused
!= 0);
2225 /* get info for the menu's first item */
2226 br
= pGetMenuBarInfo(hWnd
, OBJID_MENU
, 1, &mbi
);
2227 ok(br
, "msg %x: GetMenuBarInfo failed\n", msg
);
2228 state
= GetMenuState(hmenu
, 0, MF_BYPOSITION
);
2229 if (pGetMenuInfo
) /* Skip on NT */
2231 /* Native returns handle to destroyed window */
2232 if (msg
==WM_UNINITMENUPOPUP
&& popmenu
==1)
2233 todo_wine
ok(!mbi
.hwndMenu
== !popmenu
,
2234 "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected %sNULL\n",
2235 msg
, mbi
.hwndMenu
, popmenu
? "not " : "");
2237 ok(!mbi
.hwndMenu
== !popmenu
,
2238 "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected %sNULL\n",
2239 msg
, mbi
.hwndMenu
, popmenu
? "not " : "");
2241 ok(mbi
.hMenu
== hmenu
, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2242 msg
, mbi
.hMenu
, hmenu
);
2243 ok(!bMenuVisible
== !mbi
.fBarFocused
, "nsg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2244 msg
, mbi
.fBarFocused
!= 0);
2245 ok(!(bMenuVisible
&& (state
& MF_HILITE
)) == !mbi
.fFocused
,
2246 "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n", msg
, mbi
.fFocused
!= 0);
2249 if (msg
== WM_EXITMENULOOP
)
2250 bMenuVisible
= FALSE
;
2251 else if (msg
== WM_INITMENUPOPUP
)
2253 else if (msg
== WM_UNINITMENUPOPUP
)
2258 static void test_menu_input(void) {
2261 HINSTANCE hInstance
= GetModuleHandleA( NULL
);
2262 HANDLE hThread
, hWnd
;
2268 win_skip("SendInput is not available\n");
2272 wclass
.lpszClassName
= "MenuTestClass";
2273 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
2274 wclass
.lpfnWndProc
= WndProc
;
2275 wclass
.hInstance
= hInstance
;
2276 wclass
.hIcon
= LoadIconA( 0, (LPCSTR
)IDI_APPLICATION
);
2277 wclass
.hCursor
= LoadCursorA( 0, (LPCSTR
)IDC_ARROW
);
2278 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
2279 wclass
.lpszMenuName
= 0;
2280 wclass
.cbClsExtra
= 0;
2281 wclass
.cbWndExtra
= 0;
2282 aclass
= RegisterClassA( &wclass
);
2283 ok (aclass
, "MenuTest class not created\n");
2284 if (!aclass
) return;
2285 hWnd
= CreateWindowA( wclass
.lpszClassName
, "MenuTest",
2286 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0,
2287 400, 200, NULL
, NULL
, hInstance
, NULL
);
2288 ok (hWnd
!= NULL
, "MenuTest window not created\n");
2291 hMenus
[3] = CreatePopupMenu();
2292 AppendMenuA(hMenus
[3], MF_STRING
, 0, "&Enabled");
2293 AppendMenuA(hMenus
[3], MF_STRING
|MF_DISABLED
, 0, "&Disabled");
2295 hMenus
[2] = CreatePopupMenu();
2296 AppendMenuA(hMenus
[2], MF_STRING
|MF_POPUP
, (UINT_PTR
) hMenus
[3], "&Popup");
2297 AppendMenuA(hMenus
[2], MF_STRING
, 0, "&Enabled");
2298 AppendMenuA(hMenus
[2], MF_STRING
|MF_DISABLED
, 0, "&Disabled");
2300 hMenus
[1] = CreateMenu();
2301 AppendMenuA(hMenus
[1], MF_STRING
|MF_POPUP
, (UINT_PTR
) hMenus
[2], "&Menu");
2302 AppendMenuA(hMenus
[1], MF_STRING
, 0, "&Enabled");
2303 AppendMenuA(hMenus
[1], MF_STRING
|MF_DISABLED
, 0, "&Disabled");
2305 SetMenu(hWnd
, hMenus
[1]);
2306 ShowWindow(hWnd
, SW_SHOW
);
2309 hThread
= CreateThread(NULL
, 0, test_menu_input_thread
, hWnd
, 0, &tid
);
2312 if (WAIT_TIMEOUT
!= WaitForSingleObject(hThread
, 50))
2314 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2316 DestroyWindow(hWnd
);
2319 static void test_menu_flags( void )
2321 HMENU hMenu
, hPopupMenu
;
2323 hMenu
= CreateMenu();
2324 hPopupMenu
= CreatePopupMenu();
2326 AppendMenuA(hMenu
, MF_POPUP
| MF_STRING
, (UINT_PTR
)hPopupMenu
, "Popup");
2328 AppendMenuA(hPopupMenu
, MF_STRING
| MF_HILITE
| MF_DEFAULT
, 101, "Item 1");
2329 InsertMenuA(hPopupMenu
, 1, MF_BYPOSITION
| MF_STRING
| MF_HILITE
| MF_DEFAULT
, 102, "Item 2");
2330 AppendMenuA(hPopupMenu
, MF_STRING
, 103, "Item 3");
2331 ModifyMenuA(hPopupMenu
, 2, MF_BYPOSITION
| MF_STRING
| MF_HILITE
| MF_DEFAULT
, 103, "Item 3");
2333 ok(GetMenuState(hPopupMenu
, 0, MF_BYPOSITION
) & MF_HILITE
,
2334 "AppendMenu should accept MF_HILITE\n");
2335 ok(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
,
2336 "InsertMenu should accept MF_HILITE\n");
2337 ok(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_HILITE
,
2338 "ModifyMenu should accept MF_HILITE\n");
2340 ok(!(GetMenuState(hPopupMenu
, 0, MF_BYPOSITION
) & MF_DEFAULT
),
2341 "AppendMenu must not accept MF_DEFAULT\n");
2342 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_DEFAULT
),
2343 "InsertMenu must not accept MF_DEFAULT\n");
2344 ok(!(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_DEFAULT
),
2345 "ModifyMenu must not accept MF_DEFAULT\n");
2350 static void test_menu_hilitemenuitem( void )
2352 HMENU hMenu
, hPopupMenu
;
2357 wclass
.lpszClassName
= "HiliteMenuTestClass";
2358 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
2359 wclass
.lpfnWndProc
= WndProc
;
2360 wclass
.hInstance
= GetModuleHandleA( NULL
);
2361 wclass
.hIcon
= LoadIconA( 0, (LPCSTR
)IDI_APPLICATION
);
2362 wclass
.hCursor
= LoadCursorA( 0, (LPCSTR
)IDC_ARROW
);
2363 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
2364 wclass
.lpszMenuName
= 0;
2365 wclass
.cbClsExtra
= 0;
2366 wclass
.cbWndExtra
= 0;
2367 aclass
= RegisterClassA( &wclass
);
2368 ok (aclass
, "HiliteMenuTest class could not be created\n");
2369 if (!aclass
) return;
2370 hWnd
= CreateWindowA( wclass
.lpszClassName
, "HiliteMenuTest",
2371 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0,
2372 400, 200, NULL
, NULL
, wclass
.hInstance
, NULL
);
2373 ok (hWnd
!= NULL
, "HiliteMenuTest window could not be created\n");
2376 hMenu
= CreateMenu();
2377 hPopupMenu
= CreatePopupMenu();
2379 AppendMenuA(hMenu
, MF_POPUP
| MF_STRING
, (UINT_PTR
)hPopupMenu
, "Popup");
2381 AppendMenuA(hPopupMenu
, MF_STRING
, 101, "Item 1");
2382 AppendMenuA(hPopupMenu
, MF_STRING
, 102, "Item 2");
2383 AppendMenuA(hPopupMenu
, MF_STRING
, 103, "Item 3");
2385 SetMenu(hWnd
, hMenu
);
2387 /* test invalid arguments */
2389 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2390 "HiliteMenuItem: Item 2 is hilited\n");
2392 SetLastError(0xdeadbeef);
2395 ok(!HiliteMenuItem(NULL
, hPopupMenu
, 1, MF_HILITE
| MF_BYPOSITION
),
2396 "HiliteMenuItem: call should have failed.\n");
2398 ok(GetLastError() == 0xdeadbeef || /* 9x */
2399 GetLastError() == ERROR_INVALID_WINDOW_HANDLE
/* NT */,
2400 "HiliteMenuItem: expected error ERROR_INVALID_WINDOW_HANDLE, got: %d\n", GetLastError());
2402 SetLastError(0xdeadbeef);
2403 ok(!HiliteMenuItem(hWnd
, NULL
, 1, MF_HILITE
| MF_BYPOSITION
),
2404 "HiliteMenuItem: call should have failed.\n");
2405 ok(GetLastError() == 0xdeadbeef || /* 9x */
2406 GetLastError() == ERROR_INVALID_MENU_HANDLE
/* NT */,
2407 "HiliteMenuItem: expected error ERROR_INVALID_MENU_HANDLE, got: %d\n", GetLastError());
2409 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2410 "HiliteMenuItem: Item 2 is hilited\n");
2412 /* either MF_HILITE or MF_UNHILITE *and* MF_BYCOMMAND or MF_BYPOSITION need to be set */
2414 SetLastError(0xdeadbeef);
2415 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_BYPOSITION
),
2416 "HiliteMenuItem: call should have succeeded.\n");
2417 ok(GetLastError() == 0xdeadbeef,
2418 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2420 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2421 "HiliteMenuItem: Item 2 is hilited\n");
2423 SetLastError(0xdeadbeef);
2426 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_HILITE
),
2427 "HiliteMenuItem: call should have succeeded.\n");
2429 ok(GetLastError() == 0xdeadbeef,
2430 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2432 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2433 "HiliteMenuItem: Item 2 is hilited\n");
2435 /* hilite a menu item (by position) */
2437 SetLastError(0xdeadbeef);
2438 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_HILITE
| MF_BYPOSITION
),
2439 "HiliteMenuItem: call should not have failed.\n");
2440 ok(GetLastError() == 0xdeadbeef,
2441 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2445 ok(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
,
2446 "HiliteMenuItem: Item 2 is not hilited\n");
2449 /* unhilite a menu item (by position) */
2451 SetLastError(0xdeadbeef);
2452 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_UNHILITE
| MF_BYPOSITION
),
2453 "HiliteMenuItem: call should not have failed.\n");
2454 ok(GetLastError() == 0xdeadbeef,
2455 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2457 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2458 "HiliteMenuItem: Item 2 is hilited\n");
2460 /* hilite a menu item (by command) */
2462 SetLastError(0xdeadbeef);
2463 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 103, MF_HILITE
| MF_BYCOMMAND
),
2464 "HiliteMenuItem: call should not have failed.\n");
2465 ok(GetLastError() == 0xdeadbeef,
2466 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2470 ok(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_HILITE
,
2471 "HiliteMenuItem: Item 3 is not hilited\n");
2474 /* unhilite a menu item (by command) */
2476 SetLastError(0xdeadbeef);
2477 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 103, MF_UNHILITE
| MF_BYCOMMAND
),
2478 "HiliteMenuItem: call should not have failed.\n");
2479 ok(GetLastError() == 0xdeadbeef,
2480 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2482 ok(!(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_HILITE
),
2483 "HiliteMenuItem: Item 3 is hilited\n");
2485 DestroyWindow(hWnd
);
2488 static void check_menu_items(HMENU hmenu
, UINT checked_cmd
, UINT checked_type
,
2493 count
= GetMenuItemCount(hmenu
);
2494 ok (count
!= -1, "GetMenuItemCount returned -1\n");
2496 for (i
= 0; i
< count
; i
++)
2501 memset(&mii
, 0, sizeof(mii
));
2502 mii
.cbSize
= sizeof(mii
);
2503 mii
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_ID
| MIIM_SUBMENU
;
2504 ret
= GetMenuItemInfoA(hmenu
, i
, TRUE
, &mii
);
2505 ok(ret
, "GetMenuItemInfo(%u) failed\n", i
);
2507 trace("item #%u: fType %04x, fState %04x, wID %u, hSubMenu %p\n",
2508 i
, mii
.fType
, mii
.fState
, mii
.wID
, mii
.hSubMenu
);
2512 ok(mii
.wID
== (UINT_PTR
)mii
.hSubMenu
, "id %u: wID should be equal to hSubMenu\n", checked_cmd
);
2513 check_menu_items(mii
.hSubMenu
, checked_cmd
, checked_type
, checked_state
);
2517 if (mii
.wID
== checked_cmd
)
2519 ok(mii
.fType
== checked_type
, "id %u: expected fType %04x, got %04x\n", checked_cmd
, checked_type
, mii
.fType
);
2520 ok(mii
.fState
== checked_state
, "id %u: expected fState %04x, got %04x\n", checked_cmd
, checked_state
, mii
.fState
);
2521 ok(mii
.wID
!= 0, "id %u: not expected wID 0\n", checked_cmd
);
2525 ok(mii
.fType
!= MFT_RADIOCHECK
, "id %u: not expected fType MFT_RADIOCHECK on cmd %u\n", checked_cmd
, mii
.wID
);
2527 if (mii
.fType
== MFT_SEPARATOR
)
2529 ok(mii
.fState
== MFS_GRAYED
, "id %u: expected fState MFS_GRAYED, got %04x\n", checked_cmd
, mii
.fState
);
2530 ok(mii
.wID
== 0, "id %u: expected wID 0, got %u\n", checked_cmd
, mii
.wID
);
2534 ok(mii
.fState
== 0, "id %u: expected fState 0, got %04x\n", checked_cmd
, mii
.fState
);
2535 ok(mii
.wID
!= 0, "id %u: not expected wID 0\n", checked_cmd
);
2542 static void clear_ftype_and_state(HMENU hmenu
, UINT id
, UINT flags
)
2547 memset(&mii
, 0, sizeof(mii
));
2548 mii
.cbSize
= sizeof(mii
);
2549 mii
.fMask
= MIIM_FTYPE
| MIIM_STATE
;
2550 ret
= SetMenuItemInfoA(hmenu
, id
, (flags
& MF_BYPOSITION
) != 0, &mii
);
2551 ok(ret
, "SetMenuItemInfo(%u) failed\n", id
);
2554 static void test_CheckMenuRadioItem(void)
2559 hmenu
= LoadMenuA(GetModuleHandleA(NULL
), MAKEINTRESOURCEA(1));
2562 check_menu_items(hmenu
, -1, 0, 0);
2564 ret
= CheckMenuRadioItem(hmenu
, 100, 100, 100, MF_BYCOMMAND
);
2565 ok(ret
, "CheckMenuRadioItem failed\n");
2566 check_menu_items(hmenu
, 100, MFT_RADIOCHECK
, MFS_CHECKED
);
2568 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2569 ret
= CheckMenuRadioItem(hmenu
, 100, 100, -1, MF_BYCOMMAND
);
2570 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2571 check_menu_items(hmenu
, 100, MFT_RADIOCHECK
, 0);
2574 clear_ftype_and_state(hmenu
, 100, MF_BYCOMMAND
);
2575 check_menu_items(hmenu
, -1, 0, 0);
2577 /* first and checked items are on different menus */
2578 ret
= CheckMenuRadioItem(hmenu
, 0, 300, 202, MF_BYCOMMAND
);
2579 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2580 check_menu_items(hmenu
, -1, 0, 0);
2582 ret
= CheckMenuRadioItem(hmenu
, 200, 300, 202, MF_BYCOMMAND
);
2583 ok(ret
, "CheckMenuRadioItem failed\n");
2584 check_menu_items(hmenu
, 202, MFT_RADIOCHECK
, MFS_CHECKED
);
2586 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2587 ret
= CheckMenuRadioItem(hmenu
, 202, 202, -1, MF_BYCOMMAND
);
2588 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2589 check_menu_items(hmenu
, 202, MFT_RADIOCHECK
, 0);
2592 clear_ftype_and_state(hmenu
, 202, MF_BYCOMMAND
);
2593 check_menu_items(hmenu
, -1, 0, 0);
2595 /* just for fun, try to check separator */
2596 ret
= CheckMenuRadioItem(hmenu
, 0, 300, 0, MF_BYCOMMAND
);
2597 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2598 check_menu_items(hmenu
, -1, 0, 0);
2601 static void test_menu_resource_layout(void)
2605 MENUITEMTEMPLATEHEADER mith
;
2609 { 0, 0 }, /* versionNumber, offset */
2611 /* mtOption, mtID, mtString[] '\0' terminated */
2612 MF_STRING
, 1, 'F', 0,
2615 /* MF_SEPARATOR, 4, 'S', 0, FIXME: Wine ignores 'S' */
2616 MF_STRING
|MF_GRAYED
|MF_END
, 5, 'E', 0
2621 UINT type
, state
, id
;
2625 { MF_STRING
, MF_ENABLED
, 1, "F" },
2626 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 2, "" },
2627 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 3, "" },
2628 /*{ MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 4, "S" }, FIXME: Wine ignores 'S'*/
2629 { MF_STRING
, MF_GRAYED
, 5, "E" },
2630 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 6, "" },
2631 { MF_STRING
, MF_ENABLED
, 7, "" },
2632 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 8, "" }
2638 hmenu
= LoadMenuIndirectA(&menu_template
);
2639 ok(hmenu
!= 0, "LoadMenuIndirect error %u\n", GetLastError());
2641 ret
= AppendMenuA(hmenu
, MF_STRING
, 6, NULL
);
2642 ok(ret
, "AppendMenu failed\n");
2643 ret
= AppendMenuA(hmenu
, MF_STRING
, 7, "\0");
2644 ok(ret
, "AppendMenu failed\n");
2645 ret
= AppendMenuA(hmenu
, MF_SEPARATOR
, 8, "separator");
2646 ok(ret
, "AppendMenu failed\n");
2648 count
= GetMenuItemCount(hmenu
);
2649 ok(count
== sizeof(menu_data
)/sizeof(menu_data
[0]),
2650 "expected %u menu items, got %u\n",
2651 (UINT
)(sizeof(menu_data
)/sizeof(menu_data
[0])), count
);
2653 for (i
= 0; i
< count
; i
++)
2658 memset(&mii
, 0, sizeof(mii
));
2659 mii
.cbSize
= sizeof(mii
);
2660 mii
.dwTypeData
= buf
;
2661 mii
.cch
= sizeof(buf
);
2662 mii
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_ID
| MIIM_STRING
;
2663 ret
= GetMenuItemInfoA(hmenu
, i
, TRUE
, &mii
);
2664 ok(ret
, "GetMenuItemInfo(%u) failed\n", i
);
2666 trace("item #%u: fType %04x, fState %04x, wID %u, dwTypeData %s\n",
2667 i
, mii
.fType
, mii
.fState
, mii
.wID
, (LPCSTR
)mii
.dwTypeData
);
2669 ok(mii
.fType
== menu_data
[i
].type
,
2670 "%u: expected fType %04x, got %04x\n", i
, menu_data
[i
].type
, mii
.fType
);
2671 ok(mii
.fState
== menu_data
[i
].state
,
2672 "%u: expected fState %04x, got %04x\n", i
, menu_data
[i
].state
, mii
.fState
);
2673 ok(mii
.wID
== menu_data
[i
].id
,
2674 "%u: expected wID %04x, got %04x\n", i
, menu_data
[i
].id
, mii
.wID
);
2675 ok(mii
.cch
== strlen(menu_data
[i
].str
),
2676 "%u: expected cch %u, got %u\n", i
, (UINT
)strlen(menu_data
[i
].str
), mii
.cch
);
2677 ok(!strcmp(mii
.dwTypeData
, menu_data
[i
].str
),
2678 "%u: expected dwTypeData %s, got %s\n", i
, menu_data
[i
].str
, (LPCSTR
)mii
.dwTypeData
);
2690 static HMENU
create_menu_from_data(const struct menu_data
*item
, INT item_count
)
2696 hmenu
= CreateMenu();
2699 for (i
= 0; i
< item_count
; i
++)
2701 SetLastError(0xdeadbeef);
2702 ret
= AppendMenuA(hmenu
, item
[i
].type
, item
[i
].id
, item
[i
].str
);
2703 ok(ret
, "%d: AppendMenu(%04x, %04x, %p) error %u\n",
2704 i
, item
[i
].type
, item
[i
].id
, item
[i
].str
, GetLastError());
2709 /* use InsertMenuItem: does not set the MFT_BITMAP flag,
2710 * and does not accept non-magic bitmaps with invalid
2712 static HMENU
create_menuitem_from_data(const struct menu_data
*item
, INT item_count
)
2717 MENUITEMINFOA mii
= { sizeof( MENUITEMINFOA
) };
2719 hmenu
= CreateMenu();
2722 for (i
= 0; i
< item_count
; i
++)
2724 SetLastError(0xdeadbeef);
2726 mii
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STATE
;
2728 if( item
[i
].type
& MFT_BITMAP
)
2730 mii
.fMask
|= MIIM_BITMAP
;
2731 mii
.hbmpItem
= (HBITMAP
)item
[i
].str
;
2733 else if( item
[i
].type
& MFT_SEPARATOR
)
2734 mii
.fType
= MFT_SEPARATOR
;
2737 mii
.fMask
|= MIIM_STRING
;
2738 mii
.dwTypeData
= (LPSTR
)item
[i
].str
;
2739 mii
.cch
= strlen( item
[i
].str
);
2742 if( item
[i
].type
& MF_HELP
) mii
.fType
|= MF_HELP
;
2743 mii
.wID
= item
[i
].id
;
2744 ret
= InsertMenuItemA( hmenu
, -1, TRUE
, &mii
);
2745 ok(ret
, "%d: InsertMenuItem(%04x, %04x, %p) error %u\n",
2746 i
, item
[i
].type
, item
[i
].id
, item
[i
].str
, GetLastError());
2751 static void compare_menu_data(HMENU hmenu
, const struct menu_data
*item
, INT item_count
)
2756 count
= GetMenuItemCount(hmenu
);
2757 ok(count
== item_count
, "expected %d, got %d menu items\n", count
, item_count
);
2759 for (i
= 0; i
< count
; i
++)
2764 memset(&mii
, 0, sizeof(mii
));
2765 mii
.cbSize
= sizeof(mii
);
2766 mii
.dwTypeData
= buf
;
2767 mii
.cch
= sizeof(buf
);
2768 mii
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
| MIIM_BITMAP
;
2769 ret
= GetMenuItemInfoA(hmenu
, i
, TRUE
, &mii
);
2770 ok(ret
, "GetMenuItemInfo(%u) failed\n", i
);
2772 trace("item #%u: fType %04x, fState %04x, wID %04x, hbmp %p\n",
2773 i
, mii
.fType
, mii
.fState
, mii
.wID
, mii
.hbmpItem
);
2775 ok(mii
.fType
== item
[i
].type
,
2776 "%u: expected fType %04x, got %04x\n", i
, item
[i
].type
, mii
.fType
);
2777 ok(mii
.wID
== item
[i
].id
,
2778 "%u: expected wID %04x, got %04x\n", i
, item
[i
].id
, mii
.wID
);
2779 if (mii
.hbmpItem
|| !item
[i
].str
)
2780 /* For some reason Windows sets high word to not 0 for
2783 ok(LOWORD(mii
.hbmpItem
) == LOWORD(item
[i
].str
),
2784 "%u: expected hbmpItem %p, got %p\n", i
, item
[i
].str
, mii
.hbmpItem
);
2787 ok(mii
.cch
== strlen(item
[i
].str
),
2788 "%u: expected cch %u, got %u\n", i
, (UINT
)strlen(item
[i
].str
), mii
.cch
);
2789 ok(!strcmp(mii
.dwTypeData
, item
[i
].str
),
2790 "%u: expected dwTypeData %s, got %s\n", i
, item
[i
].str
, (LPCSTR
)mii
.dwTypeData
);
2795 static void test_InsertMenu(void)
2797 HBITMAP hbm
= CreateBitmap(1,1,1,1,NULL
);
2798 /* Note: XP treats only bitmap handles 1 - 6 as "magic" ones
2799 * regardless of their id.
2801 static const struct menu_data in1
[] =
2803 { MF_STRING
, 1, "File" },
2804 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCEA(1) },
2805 { MF_STRING
|MF_HELP
, 2, "Help" }
2807 static const struct menu_data out1
[] =
2809 { MF_STRING
, 1, "File" },
2810 { MF_STRING
|MF_HELP
, 2, "Help" },
2811 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCEA(1) }
2813 static const struct menu_data out1a
[] =
2815 { MF_STRING
, 1, "File" },
2816 { MF_STRING
|MF_HELP
, 2, "Help" },
2817 { MF_HELP
, SC_CLOSE
, MAKEINTRESOURCEA(1) }
2819 const struct menu_data in2
[] =
2821 { MF_STRING
, 1, "File" },
2822 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, (char*)hbm
},
2823 { MF_STRING
|MF_HELP
, 2, "Help" }
2825 const struct menu_data out2
[] =
2827 { MF_STRING
, 1, "File" },
2828 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, (char*)hbm
},
2829 { MF_STRING
|MF_HELP
, 2, "Help" }
2831 const struct menu_data out2a
[] =
2833 { MF_STRING
, 1, "File" },
2834 { MF_HELP
, SC_CLOSE
, (char*)hbm
},
2835 { MF_STRING
|MF_HELP
, 2, "Help" }
2837 static const struct menu_data in3
[] =
2839 { MF_STRING
, 1, "File" },
2840 { MF_SEPARATOR
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCEA(1) },
2841 { MF_STRING
|MF_HELP
, 2, "Help" }
2843 static const struct menu_data out3
[] =
2845 { MF_STRING
, 1, "File" },
2846 { MF_SEPARATOR
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCEA(0) },
2847 { MF_STRING
|MF_HELP
, 2, "Help" },
2849 static const struct menu_data in4
[] =
2851 { MF_STRING
, 1, "File" },
2852 { MF_BITMAP
|MF_HELP
, 1, MAKEINTRESOURCEA(1) },
2853 { MF_STRING
|MF_HELP
, 2, "Help" }
2855 static const struct menu_data out4
[] =
2857 { MF_STRING
, 1, "File" },
2858 { MF_STRING
|MF_HELP
, 2, "Help" },
2859 { MF_BITMAP
|MF_HELP
, 1, MAKEINTRESOURCEA(1) }
2861 static const struct menu_data out4a
[] =
2863 { MF_STRING
, 1, "File" },
2864 { MF_STRING
|MF_HELP
, 2, "Help" },
2865 { MF_HELP
, 1, MAKEINTRESOURCEA(1) }
2869 #define create_menu(a) create_menu_from_data((a), sizeof(a)/sizeof((a)[0]))
2870 #define create_menuitem(a) create_menuitem_from_data((a), sizeof(a)/sizeof((a)[0]))
2871 #define compare_menu(h, a) compare_menu_data((h), (a), sizeof(a)/sizeof((a)[0]))
2873 hmenu
= create_menu(in1
);
2874 compare_menu(hmenu
, out1
);
2877 hmenu
= create_menu(in2
);
2878 compare_menu(hmenu
, out2
);
2881 hmenu
= create_menu(in3
);
2882 compare_menu(hmenu
, out3
);
2885 hmenu
= create_menu(in4
);
2886 compare_menu(hmenu
, out4
);
2889 /* now using InsertMenuItemInfo */
2890 hmenu
= create_menuitem(in1
);
2891 compare_menu(hmenu
, out1a
);
2894 hmenu
= create_menuitem(in2
);
2895 compare_menu(hmenu
, out2a
);
2898 hmenu
= create_menuitem(in3
);
2899 compare_menu(hmenu
, out3
);
2902 hmenu
= create_menuitem(in4
);
2903 compare_menu(hmenu
, out4a
);
2907 #undef create_menuitem
2911 static void test_menu_getmenuinfo(void)
2920 win_skip("GetMenuInfo is not available\n");
2925 hmenu
= CreateMenu();
2927 /* test some parameter errors */
2928 SetLastError(0xdeadbeef);
2929 ret
= pGetMenuInfo( hmenu
, NULL
);
2930 gle
= GetLastError();
2931 ok( !ret
, "GetMenuInfo() should have failed\n");
2932 ok( gle
== ERROR_INVALID_PARAMETER
||
2933 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2934 "GetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2935 SetLastError(0xdeadbeef);
2937 ret
= pGetMenuInfo( hmenu
, &mi
);
2938 gle
= GetLastError();
2939 ok( !ret
, "GetMenuInfo() should have failed\n");
2940 ok( gle
== ERROR_INVALID_PARAMETER
||
2941 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2942 "GetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2943 SetLastError(0xdeadbeef);
2944 mi
.cbSize
= sizeof( MENUINFO
);
2945 ret
= pGetMenuInfo( hmenu
, &mi
);
2946 gle
= GetLastError();
2947 ok( ret
, "GetMenuInfo() should have succeeded\n");
2948 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2949 SetLastError(0xdeadbeef);
2951 ret
= pGetMenuInfo( NULL
, &mi
);
2952 gle
= GetLastError();
2953 ok( !ret
, "GetMenuInfo() should have failed\n");
2954 ok( gle
== ERROR_INVALID_PARAMETER
||
2955 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2956 "GetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2958 DestroyMenu( hmenu
);
2962 static void test_menu_setmenuinfo(void)
2964 HMENU hmenu
, hsubmenu
;
2966 MENUITEMINFOA mii
= { sizeof(MENUITEMINFOA
) };
2970 if (!pGetMenuInfo
|| !pSetMenuInfo
)
2972 win_skip("Get/SetMenuInfo are not available\n");
2976 /* create a menu with a submenu */
2977 hmenu
= CreateMenu();
2978 hsubmenu
= CreateMenu();
2979 assert( hmenu
&& hsubmenu
);
2980 mii
.fMask
= MIIM_SUBMENU
;
2981 mii
.hSubMenu
= hsubmenu
;
2982 ret
= InsertMenuItemA( hmenu
, 0, FALSE
, &mii
);
2983 ok( ret
, "InsertMenuItem failed with error %d\n", GetLastError());
2984 /* test some parameter errors */
2985 SetLastError(0xdeadbeef);
2986 ret
= pSetMenuInfo( hmenu
, NULL
);
2987 gle
= GetLastError();
2988 ok( !ret
, "SetMenuInfo() should have failed\n");
2989 ok( gle
== ERROR_INVALID_PARAMETER
||
2990 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2991 "SetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2992 SetLastError(0xdeadbeef);
2994 ret
= pSetMenuInfo( hmenu
, &mi
);
2995 gle
= GetLastError();
2996 ok( !ret
, "SetMenuInfo() should have failed\n");
2997 ok( gle
== ERROR_INVALID_PARAMETER
||
2998 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2999 "SetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
3000 SetLastError(0xdeadbeef);
3001 mi
.cbSize
= sizeof( MENUINFO
);
3002 ret
= pSetMenuInfo( hmenu
, &mi
);
3003 gle
= GetLastError();
3004 ok( ret
, "SetMenuInfo() should have succeeded\n");
3005 ok( gle
== 0xdeadbeef, "SetMenuInfo() error got %u\n", gle
);
3006 SetLastError(0xdeadbeef);
3008 ret
= pSetMenuInfo( NULL
, &mi
);
3009 gle
= GetLastError();
3010 ok( !ret
, "SetMenuInfo() should have failed\n");
3011 ok( gle
== ERROR_INVALID_PARAMETER
||
3012 broken(gle
== 0xdeadbeef), /* Win98, WinME */
3013 "SetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
3014 /* functional tests */
3015 /* menu and submenu should have the CHECKORBMP style bit cleared */
3016 SetLastError(0xdeadbeef);
3017 mi
.cbSize
= sizeof( MENUINFO
);
3018 mi
.fMask
= MIM_STYLE
;
3019 ret
= pGetMenuInfo( hmenu
, &mi
);
3020 gle
= GetLastError();
3021 ok( ret
, "GetMenuInfo() should have succeeded\n");
3022 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
3023 ok( !(mi
.dwStyle
& MNS_CHECKORBMP
), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
3024 SetLastError(0xdeadbeef);
3025 mi
.cbSize
= sizeof( MENUINFO
);
3026 mi
.fMask
= MIM_STYLE
;
3027 ret
= pGetMenuInfo( hsubmenu
, &mi
);
3028 gle
= GetLastError();
3029 ok( ret
, "GetMenuInfo() should have succeeded\n");
3030 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
3031 ok( !(mi
.dwStyle
& MNS_CHECKORBMP
), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
3033 SetLastError(0xdeadbeef);
3034 mi
.cbSize
= sizeof( MENUINFO
);
3035 mi
.fMask
= MIM_STYLE
| MIM_APPLYTOSUBMENUS
;
3036 mi
.dwStyle
= MNS_CHECKORBMP
;
3037 ret
= pSetMenuInfo( hmenu
, &mi
);
3038 gle
= GetLastError();
3039 ok( ret
, "SetMenuInfo() should have succeeded\n");
3040 ok( gle
== 0xdeadbeef, "SetMenuInfo() error got %u\n", gle
);
3041 /* Now both menus should have the MNS_CHECKORBMP style bit set */
3042 SetLastError(0xdeadbeef);
3043 mi
.cbSize
= sizeof( MENUINFO
);
3044 mi
.fMask
= MIM_STYLE
;
3045 ret
= pGetMenuInfo( hmenu
, &mi
);
3046 gle
= GetLastError();
3047 ok( ret
, "GetMenuInfo() should have succeeded\n");
3048 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
3049 ok( mi
.dwStyle
& MNS_CHECKORBMP
, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
3050 SetLastError(0xdeadbeef);
3051 mi
.cbSize
= sizeof( MENUINFO
);
3052 mi
.fMask
= MIM_STYLE
;
3053 ret
= pGetMenuInfo( hsubmenu
, &mi
);
3054 gle
= GetLastError();
3055 ok( ret
, "GetMenuInfo() should have succeeded\n");
3056 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
3057 ok( mi
.dwStyle
& MNS_CHECKORBMP
, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
3058 /* now repeat that without the APPLYTOSUBMENUS flag and another style bit */
3059 SetLastError(0xdeadbeef);
3060 mi
.cbSize
= sizeof( MENUINFO
);
3061 mi
.fMask
= MIM_STYLE
;
3062 mi
.dwStyle
= MNS_NOCHECK
;
3063 ret
= pSetMenuInfo( hmenu
, &mi
);
3064 gle
= GetLastError();
3065 ok( ret
, "SetMenuInfo() should have succeeded\n");
3066 ok( gle
== 0xdeadbeef, "SetMenuInfo() error got %u\n", gle
);
3067 /* Now only the top menu should have the MNS_NOCHECK style bit set */
3068 SetLastError(0xdeadbeef);
3069 mi
.cbSize
= sizeof( MENUINFO
);
3070 mi
.fMask
= MIM_STYLE
;
3071 ret
= pGetMenuInfo( hmenu
, &mi
);
3072 gle
= GetLastError();
3073 ok( ret
, "GetMenuInfo() should have succeeded\n");
3074 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
3075 ok( mi
.dwStyle
& MNS_NOCHECK
, "menustyle was expected to have the MNS_NOCHECK flag\n");
3076 SetLastError(0xdeadbeef);
3077 mi
.cbSize
= sizeof( MENUINFO
);
3078 mi
.fMask
= MIM_STYLE
;
3079 ret
= pGetMenuInfo( hsubmenu
, &mi
);
3080 gle
= GetLastError();
3081 ok( ret
, "GetMenuInfo() should have succeeded\n");
3082 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
3083 ok( !(mi
.dwStyle
& MNS_NOCHECK
), "menustyle was not expected to have the MNS_NOCHECK flag\n");
3085 DestroyMenu( hsubmenu
);
3086 DestroyMenu( hmenu
);
3090 /* little func to easy switch either TrackPopupMenu() or TrackPopupMenuEx() */
3091 static DWORD
MyTrackPopupMenu( int ex
, HMENU hmenu
, UINT flags
, INT x
, INT y
, HWND hwnd
, LPTPMPARAMS ptpm
)
3094 ? TrackPopupMenuEx( hmenu
, flags
, x
, y
, hwnd
, ptpm
)
3095 : TrackPopupMenu( hmenu
, flags
, x
, y
, 0, hwnd
, NULL
);
3098 /* some TrackPopupMenu and TrackPopupMenuEx tests */
3099 /* the LastError values differ between NO_ERROR and invalid handle */
3100 /* between all windows versions tested. The first value is that valid on XP */
3101 /* Vista was the only that made returned different error values */
3102 /* between the TrackPopupMenu and TrackPopupMenuEx functions */
3103 static void test_menu_trackpopupmenu(void)
3109 HWND hwnd
= CreateWindowExA(0, (LPCSTR
)MAKEINTATOM(atomMenuCheckClass
), NULL
,
3110 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
3111 NULL
, NULL
, NULL
, NULL
);
3112 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
3114 SetWindowLongPtrA( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_ownerdraw_wnd_proc
);
3115 for( Ex
= 0; Ex
< 2; Ex
++)
3117 hmenu
= CreatePopupMenu();
3118 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
3121 DestroyWindow(hwnd
);
3124 /* display the menu */
3125 /* start with an invalid menu handle */
3126 SetLastError(0xdeadbeef);
3128 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= 0;
3129 ret
= MyTrackPopupMenu( Ex
, NULL
, TPM_RETURNCMD
, 100,100, hwnd
, NULL
);
3130 gle
= GetLastError();
3131 ok( !ret
, "TrackPopupMenu%s should have failed\n", Ex
? "Ex" : "");
3132 ok( gle
== ERROR_INVALID_MENU_HANDLE
3133 || broken (gle
== 0xdeadbeef) /* win95 */
3134 || broken (gle
== NO_ERROR
) /* win98/ME */
3135 ,"TrackPopupMenu%s error got %u expected %u\n",
3136 Ex
? "Ex" : "", gle
, ERROR_INVALID_MENU_HANDLE
);
3137 ok( !(gflag_initmenupopup
|| gflag_entermenuloop
|| gflag_initmenu
),
3138 "got unexpected message(s)%s%s%s\n",
3139 gflag_initmenupopup
? " WM_INITMENUPOPUP ": " ",
3140 gflag_entermenuloop
? "WM_INITMENULOOP ": "",
3141 gflag_initmenu
? "WM_INITMENU": "");
3142 /* another one but not NULL */
3143 SetLastError(0xdeadbeef);
3144 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= 0;
3145 ret
= MyTrackPopupMenu( Ex
, (HMENU
)hwnd
, TPM_RETURNCMD
, 100,100, hwnd
, NULL
);
3146 gle
= GetLastError();
3147 ok( !ret
, "TrackPopupMenu%s should have failed\n", Ex
? "Ex" : "");
3148 ok( gle
== ERROR_INVALID_MENU_HANDLE
3149 || broken (gle
== 0xdeadbeef) /* win95 */
3150 || broken (gle
== NO_ERROR
) /* win98/ME */
3151 ,"TrackPopupMenu%s error got %u expected %u\n",
3152 Ex
? "Ex" : "", gle
, ERROR_INVALID_MENU_HANDLE
);
3153 ok( !(gflag_initmenupopup
|| gflag_entermenuloop
|| gflag_initmenu
),
3154 "got unexpected message(s)%s%s%s\n",
3155 gflag_initmenupopup
? " WM_INITMENUPOPUP ": " ",
3156 gflag_entermenuloop
? "WM_INITMENULOOP ": "",
3157 gflag_initmenu
? "WM_INITMENU": "");
3159 /* invalid window */
3160 SetLastError(0xdeadbeef);
3161 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= 0;
3162 ret
= MyTrackPopupMenu( Ex
, hmenu
, TPM_RETURNCMD
, 100,100, 0, NULL
);
3163 gle
= GetLastError();
3164 ok( !ret
, "TrackPopupMenu%s should have failed\n", Ex
? "Ex" : "");
3165 ok( gle
== ERROR_INVALID_WINDOW_HANDLE
, "TrackPopupMenu%s error got %u\n", Ex
? "Ex" : "", gle
);
3166 ok( !(gflag_initmenupopup
|| gflag_entermenuloop
|| gflag_initmenu
),
3167 "got unexpected message(s)%s%s%s\n",
3168 gflag_initmenupopup
? " WM_INITMENUPOPUP ": " ",
3169 gflag_entermenuloop
? "WM_INITMENULOOP ": "",
3170 gflag_initmenu
? "WM_INITMENU": "");
3172 /* now a somewhat successful call */
3173 SetLastError(0xdeadbeef);
3174 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= 0;
3175 ret
= MyTrackPopupMenu( Ex
, hmenu
, TPM_RETURNCMD
, 100,100, hwnd
, NULL
);
3176 gle
= GetLastError();
3177 ok( ret
== 0, "TrackPopupMenu%s returned %d expected zero\n", Ex
? "Ex" : "", ret
);
3179 || gle
== ERROR_INVALID_MENU_HANDLE
/* NT4, win2k */
3180 || broken (gle
== 0xdeadbeef) /* win95 */
3181 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
3182 Ex
? "Ex" : "", gle
, NO_ERROR
, ERROR_INVALID_MENU_HANDLE
);
3183 ok( gflag_initmenupopup
&& gflag_entermenuloop
&& gflag_initmenu
,
3184 "missed expected message(s)%s%s%s\n",
3185 !gflag_initmenupopup
? " WM_INITMENUPOPUP ": " ",
3186 !gflag_entermenuloop
? "WM_INITMENULOOP ": "",
3187 !gflag_initmenu
? "WM_INITMENU": "");
3189 ret
= AppendMenuA( hmenu
, MF_STRING
, 1, "winetest");
3190 ok( ret
, "AppendMenA has failed!\n");
3191 SetLastError(0xdeadbeef);
3192 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= 0;
3193 ret
= MyTrackPopupMenu( Ex
, hmenu
, TPM_RETURNCMD
, 100,100, hwnd
, NULL
);
3194 gle
= GetLastError();
3195 ok( ret
== 0, "TrackPopupMenu%s returned %d expected zero\n", Ex
? "Ex" : "", ret
);
3197 || gle
== ERROR_INVALID_MENU_HANDLE
/* NT4, win2k and Vista in the TrackPopupMenuEx case */
3198 || broken (gle
== 0xdeadbeef) /* win95 */
3199 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
3200 Ex
? "Ex" : "", gle
, NO_ERROR
, ERROR_INVALID_MENU_HANDLE
);
3201 ok( gflag_initmenupopup
&& gflag_entermenuloop
&& gflag_initmenu
,
3202 "missed expected message(s)%s%s%s\n",
3203 !gflag_initmenupopup
? " WM_INITMENUPOPUP ": " ",
3204 !gflag_entermenuloop
? "WM_INITMENULOOP ": "",
3205 !gflag_initmenu
? "WM_INITMENU": "");
3209 DestroyWindow(hwnd
);
3212 static HMENU g_hmenu
;
3214 static LRESULT WINAPI
menu_track_again_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3218 case WM_ENTERMENULOOP
:
3222 /* try a recursive call */
3223 SetLastError(0xdeadbeef);
3224 ret
= TrackPopupMenu(g_hmenu
, 0, 100, 100, 0, hwnd
, NULL
);
3225 ok(ret
== FALSE
, "got %d\n", ret
);
3226 ok(GetLastError() == ERROR_POPUP_ALREADY_ACTIVE
||
3227 broken(GetLastError() == 0xdeadbeef) /* W9x */, "got %d\n", GetLastError());
3229 /* exit menu modal loop
3230 * ( A SendMessage does not work on NT3.51 here ) */
3231 return PostMessageA(hwnd
, WM_CANCELMODE
, 0, 0);
3234 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
3237 static void test_menu_trackagain(void)
3242 hwnd
= CreateWindowExA(0, (LPCSTR
)MAKEINTATOM(atomMenuCheckClass
), NULL
,
3243 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
3244 NULL
, NULL
, NULL
, NULL
);
3245 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
3247 SetWindowLongPtrA( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_track_again_wnd_proc
);
3249 g_hmenu
= CreatePopupMenu();
3250 ok(g_hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
3252 ret
= AppendMenuA(g_hmenu
, MF_STRING
, 100, "item 1");
3253 ok(ret
, "AppendMenu failed.\n");
3254 ret
= AppendMenuA(g_hmenu
, MF_STRING
, 101, "item 2");
3255 ok(ret
, "AppendMenu failed.\n");
3257 ret
= TrackPopupMenu( g_hmenu
, 0, 100, 100, 0, hwnd
, NULL
);
3258 ok(ret
== TRUE
, "got %d\n", ret
);
3260 DestroyMenu(g_hmenu
);
3261 DestroyWindow(hwnd
);
3264 /* test handling of WM_CANCELMODE messages */
3265 static int g_got_enteridle
;
3266 static HWND g_hwndtosend
;
3267 static LRESULT WINAPI
menu_cancelmode_wnd_proc(HWND hwnd
, UINT msg
,
3268 WPARAM wparam
, LPARAM lparam
)
3272 case WM_ENTERMENULOOP
:
3273 g_got_enteridle
= 0;
3274 return SendMessageA( g_hwndtosend
, WM_CANCELMODE
, 0, 0);
3277 if( g_got_enteridle
++ == 0) {
3278 /* little hack to get another WM_ENTERIDLE message */
3279 PostMessageA( hwnd
, WM_MOUSEMOVE
, 0, 0);
3280 return SendMessageA( g_hwndtosend
, WM_CANCELMODE
, 0, 0);
3286 return DefWindowProcA( hwnd
, msg
, wparam
, lparam
);
3289 static void test_menu_cancelmode(void)
3292 HWND hwnd
, hwndchild
;
3293 HMENU menu
, menubar
;
3295 if( !pEndMenu
) { /* win95 */
3296 win_skip( "EndMenu is not available\n");
3299 hwnd
= CreateWindowExA( 0, (LPCSTR
)MAKEINTATOM(atomMenuCheckClass
), NULL
,
3300 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
3301 NULL
, NULL
, NULL
, NULL
);
3302 hwndchild
= CreateWindowExA( 0, (LPCSTR
)MAKEINTATOM(atomMenuCheckClass
), NULL
,
3303 WS_VISIBLE
| WS_CHILD
, 10, 10, 20, 20,
3304 hwnd
, NULL
, NULL
, NULL
);
3305 ok( hwnd
!= NULL
&& hwndchild
!= NULL
,
3306 "CreateWindowEx failed with error %d\n", GetLastError());
3307 g_hwndtosend
= hwnd
;
3308 SetWindowLongPtrA( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_cancelmode_wnd_proc
);
3309 SetWindowLongPtrA( hwndchild
, GWLP_WNDPROC
, (LONG_PTR
)menu_cancelmode_wnd_proc
);
3310 menu
= CreatePopupMenu();
3311 ok( menu
!= NULL
, "CreatePopupMenu failed with error %d\n", GetLastError());
3312 ret
= AppendMenuA( menu
, MF_STRING
, 1, "winetest");
3313 ok( ret
, "Functie failed lasterror is %u\n", GetLastError());
3314 /* seems to be needed only on wine :( */
3315 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
3316 DispatchMessageA(&msg
);
3317 /* test the effect of sending a WM_CANCELMODE message in the WM_INITMENULOOP
3318 * handler of the menu owner */
3319 /* test results is extracted from variable g_got_enteridle. Possible values:
3320 * 0 : complete conformance. Sending WM_CANCELMODE cancels a menu initializing tracking
3321 * 1 : Sending WM_CANCELMODE cancels a menu that is in tracking state
3322 * 2 : Sending WM_CANCELMODE does not work
3324 /* menu owner is top level window */
3325 g_hwndtosend
= hwnd
;
3326 TrackPopupMenu( menu
, TPM_RETURNCMD
, 100,100, 0, hwnd
, NULL
);
3327 ok( g_got_enteridle
== 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle
);
3328 /* menu owner is child window */
3329 g_hwndtosend
= hwndchild
;
3330 TrackPopupMenu( menu
, TPM_RETURNCMD
, 100,100, 0, hwndchild
, NULL
);
3331 ok(g_got_enteridle
== 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle
);
3332 /* now send the WM_CANCELMODE messages to the WRONG window */
3333 /* those should fail ( to have any effect) */
3334 g_hwndtosend
= hwnd
;
3335 TrackPopupMenu( menu
, TPM_RETURNCMD
, 100,100, 0, hwndchild
, NULL
);
3336 ok( g_got_enteridle
== 2, "received %d WM_ENTERIDLE messages, should be 2\n", g_got_enteridle
);
3338 /* test canceling tracking in a window's menu bar */
3339 menubar
= CreateMenu();
3340 ok( menubar
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
3341 ret
= AppendMenuA( menubar
, MF_POPUP
|MF_STRING
, (UINT_PTR
)menu
, "winetest");
3342 ok( ret
, "AppendMenuA failed lasterror is %u\n", GetLastError());
3343 ret
= SetMenu( hwnd
, menubar
);
3344 ok( ret
, "SetMenu failed lasterror is %u\n", GetLastError());
3345 /* initiate tracking */
3346 g_hwndtosend
= hwnd
;
3347 ret
= SendMessageA( hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, 0 );
3348 ok( ret
== 0, "Sending WM_SYSCOMMAND/SC_KEYMENU failed lasterror is %u\n", GetLastError());
3349 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
3350 DispatchMessageA(&msg
);
3351 ok(g_got_enteridle
== 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle
);
3354 DestroyMenu( menubar
);
3356 DestroyWindow( hwndchild
);
3357 DestroyWindow( hwnd
);
3360 /* show menu trees have a maximum depth */
3361 static void test_menu_maxdepth(void)
3363 #define NR_MENUS 100
3364 HMENU hmenus
[ NR_MENUS
];
3368 SetLastError(12345678);
3369 for( i
= 0; i
< NR_MENUS
; i
++) {
3370 hmenus
[i
] = CreatePopupMenu();
3371 if( !hmenus
[i
]) break;
3373 ok( i
== NR_MENUS
, "could not create more than %d menu's\n", i
);
3374 for( i
= 1; i
< NR_MENUS
; i
++) {
3375 ret
= AppendMenuA( hmenus
[i
], MF_POPUP
, (UINT_PTR
)hmenus
[i
-1],"test");
3378 trace("Maximum depth is %d\n", i
);
3379 ok( GetLastError() == 12345678, "unexpected error %d\n", GetLastError());
3381 broken( i
== NR_MENUS
), /* win98, NT */
3382 "no ( or very large) limit on menu depth!\n");
3384 for( i
= 0; i
< NR_MENUS
; i
++)
3385 DestroyMenu( hmenus
[i
]);
3389 static void test_menu_circref(void)
3394 menu1
= CreatePopupMenu();
3395 menu2
= CreatePopupMenu();
3396 ok( menu1
&& menu2
, "error creating menus.\n");
3397 ret
= AppendMenuA( menu1
, MF_POPUP
, (UINT_PTR
)menu2
, "winetest");
3398 ok( ret
, "AppendMenu failed, error is %d\n", GetLastError());
3399 ret
= AppendMenuA( menu1
, MF_STRING
| MF_HILITE
, 123, "winetest");
3400 ok( ret
, "AppendMenu failed, error is %d\n", GetLastError());
3401 /* app chooses an id that happens to clash with its own hmenu */
3402 ret
= AppendMenuA( menu2
, MF_STRING
, (UINT_PTR
)menu2
, "winetest");
3403 ok( ret
, "AppendMenu failed, error is %d\n", GetLastError());
3404 /* now attempt to change the string of the first item of menu1 */
3405 ret
= ModifyMenuA( menu1
, (UINT_PTR
)menu2
, MF_POPUP
, (UINT_PTR
)menu2
, "menu 2");
3407 broken( ret
), /* win98, NT */
3408 "ModifyMenu should have failed.\n");
3409 if( !ret
) { /* will probably stack fault if the ModifyMenu succeeded */
3410 ret
= GetMenuState( menu1
, 123, 0);
3411 ok( ret
== MF_HILITE
, "GetMenuState returned %x\n",ret
);
3413 DestroyMenu( menu2
);
3414 DestroyMenu( menu1
);
3417 /* test how the menu texts are aligned when the menu items have
3418 * different combinations of text and bitmaps (bug #13350) */
3419 static void test_menualign(void)
3423 HBITMAP hbm1
, hbm2
, hbm3
;
3424 MENUITEMINFOA mii
= { sizeof(MENUITEMINFOA
) };
3427 MENUINFO mi
= { sizeof( MENUINFO
)};
3429 if( !winetest_interactive
) {
3430 skip( "interactive alignment tests.\n");
3433 hwnd
= CreateWindowExA(0,
3435 "Menu text alignment Test\nPlease make a selection.",
3436 WS_OVERLAPPEDWINDOW
,
3439 NULL
, NULL
, 0, NULL
);
3440 ShowWindow( hwnd
, SW_SHOW
);
3441 /* create bitmaps */
3442 memset( bmfill
, 0xcc, sizeof( bmfill
));
3443 hbm1
= CreateBitmap( 10,10,1,1,bmfill
);
3444 hbm2
= CreateBitmap( 20,20,1,1,bmfill
);
3445 hbm3
= CreateBitmap( 50,6,1,1,bmfill
);
3446 ok( hbm1
&& hbm2
&& hbm3
, "Creating bitmaps failed\n");
3447 menu
= CreatePopupMenu();
3448 ok( menu
!= NULL
, "CreatePopupMenu() failed\n");
3450 mi
.fMask
= MIM_STYLE
;
3451 ret
= pGetMenuInfo( menu
, &mi
);
3452 ok( ret
, "GetMenuInfo failed: %d\n", GetLastError());
3453 ok( menu
!= NULL
, "GetMenuInfo() failed\n");
3454 ok( 0 == mi
.dwStyle
, "menuinfo style is %x\n", mi
.dwStyle
);
3457 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3459 mii
.hbmpItem
= hbm1
;
3460 mii
.dwTypeData
= (LPSTR
) " OK: menu texts are correctly left-aligned.";
3461 ret
= InsertMenuItemA( menu
, -1, TRUE
, &mii
);
3462 ok( ret
, "InsertMenuItem() failed\n");
3463 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3465 mii
.hbmpItem
= hbm2
;
3466 mii
.dwTypeData
= (LPSTR
) " FAIL: menu texts are NOT left-aligned.";
3467 ret
= InsertMenuItemA( menu
, -1, TRUE
, &mii
);
3468 ok( ret
, "InsertMenuItem() failed\n");
3469 ret
= TrackPopupMenu( menu
, TPM_RETURNCMD
, 110, 200, 0, hwnd
, NULL
);
3470 ok( ret
!= 2, "User indicated that menu text alignment test 1 failed %d\n", ret
);
3472 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3474 mii
.hbmpItem
= hbm3
;
3475 mii
.dwTypeData
= NULL
;
3476 ret
= InsertMenuItemA( menu
, 0, TRUE
, &mii
);
3477 ok( ret
, "InsertMenuItem() failed\n");
3478 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3480 mii
.hbmpItem
= hbm1
;
3481 /* make the text a bit longer, to keep it readable */
3482 /* this bug is on winXP and reproduced on wine */
3483 mii
.dwTypeData
= (LPSTR
) " OK: menu texts are to the right of the bitmaps........";
3484 ret
= SetMenuItemInfoA( menu
, 1, TRUE
, &mii
);
3485 ok( ret
, "SetMenuItemInfo() failed\n");
3487 mii
.hbmpItem
= hbm2
;
3488 mii
.dwTypeData
= (LPSTR
) " FAIL: menu texts are below the first bitmap. ";
3489 ret
= SetMenuItemInfoA( menu
, 2, TRUE
, &mii
);
3490 ok( ret
, "SetMenuItemInfo() failed\n");
3491 ret
= TrackPopupMenu( menu
, TPM_RETURNCMD
, 110, 200, 0, hwnd
, NULL
);
3492 ok( ret
!= 2, "User indicated that menu text alignment test 2 failed %d\n", ret
);
3494 mii
.fMask
= MIIM_TYPE
| MIIM_ID
;
3496 mii
.fType
= MFT_BITMAP
;
3497 mii
.dwTypeData
= (LPSTR
) hbm3
;
3498 ret
= SetMenuItemInfoA( menu
, 0, TRUE
, &mii
);
3499 ok( ret
, "SetMenuItemInfo() failed\n");
3500 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3502 mii
.hbmpItem
= NULL
;
3503 mii
.dwTypeData
= (LPSTR
) " OK: menu texts are below the bitmap.";
3504 ret
= SetMenuItemInfoA( menu
, 1, TRUE
, &mii
);
3505 ok( ret
, "SetMenuItemInfo() failed\n");
3507 mii
.hbmpItem
= NULL
;
3508 mii
.dwTypeData
= (LPSTR
) " FAIL: menu texts are NOT below the bitmap.";
3509 ret
= SetMenuItemInfoA( menu
, 2, TRUE
, &mii
);
3510 ok( ret
, "SetMenuItemInfo() failed\n");
3511 ret
= TrackPopupMenu( menu
, TPM_RETURNCMD
, 110, 200, 0, hwnd
, NULL
);
3512 ok( ret
!= 2, "User indicated that menu text alignment test 3 failed %d\n", ret
);
3514 DeleteObject( hbm1
);
3515 DeleteObject( hbm2
);
3516 DeleteObject( hbm3
);
3518 DestroyWindow( hwnd
);
3521 static LRESULT WINAPI
menu_fill_in_init(HWND hwnd
, UINT msg
,
3522 WPARAM wparam
, LPARAM lparam
)
3528 case WM_INITMENUPOPUP
:
3529 gflag_initmenupopup
++;
3530 hmenupopup
= (HMENU
) wparam
;
3531 ret
= AppendMenuA(hmenupopup
, MF_STRING
, 100, "item 1");
3532 ok(ret
, "AppendMenu failed.\n");
3533 ret
= AppendMenuA(hmenupopup
, MF_STRING
, 101, "item 2");
3534 ok(ret
, "AppendMenu failed.\n");
3536 case WM_ENTERMENULOOP
:
3537 gflag_entermenuloop
++;
3544 PostMessageA(hwnd
, WM_CANCELMODE
, 0, 0);
3547 selectitem_wp
= wparam
;
3548 selectitem_lp
= lparam
;
3551 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
3554 static void test_emptypopup(void)
3559 HWND hwnd
= CreateWindowExA(0, (LPCSTR
)MAKEINTATOM(atomMenuCheckClass
), NULL
,
3560 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
3561 NULL
, NULL
, NULL
, NULL
);
3562 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
3563 SetWindowLongPtrA( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_ownerdraw_wnd_proc
);
3565 hmenu
= CreatePopupMenu();
3566 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
3568 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= gflag_enteridle
= 0;
3569 selectitem_wp
= 0xdeadbeef;
3570 selectitem_lp
= 0xdeadbeef;
3572 ret
= TrackPopupMenu( hmenu
, TPM_RETURNCMD
, 100,100, 0, hwnd
, NULL
);
3573 ok(ret
== 0, "got %i\n", ret
);
3575 ok(gflag_initmenupopup
== 1, "got %i\n", gflag_initmenupopup
);
3576 ok(gflag_entermenuloop
== 1, "got %i\n", gflag_entermenuloop
);
3577 ok(gflag_initmenu
== 1, "got %i\n", gflag_initmenu
);
3578 todo_wine
ok(gflag_enteridle
== 0, "got %i\n", gflag_initmenu
);
3580 todo_wine
ok(selectitem_wp
== 0xdeadbeef, "got %lx\n", selectitem_wp
);
3581 todo_wine
ok(selectitem_lp
== 0xdeadbeef, "got %lx\n", selectitem_lp
);
3583 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= gflag_enteridle
= 0;
3584 selectitem_wp
= 0xdeadbeef;
3585 selectitem_lp
= 0xdeadbeef;
3587 ret
= TrackPopupMenu( hmenu
, 0, 100,100, 0, hwnd
, NULL
);
3588 todo_wine
ok(ret
== 0, "got %i\n", ret
);
3590 ok(gflag_initmenupopup
== 1, "got %i\n", gflag_initmenupopup
);
3591 ok(gflag_entermenuloop
== 1, "got %i\n", gflag_entermenuloop
);
3592 ok(gflag_initmenu
== 1, "got %i\n", gflag_initmenu
);
3593 todo_wine
ok(gflag_enteridle
== 0, "got %i\n", gflag_initmenu
);
3595 todo_wine
ok(selectitem_wp
== 0xdeadbeef, "got %lx\n", selectitem_wp
);
3596 todo_wine
ok(selectitem_lp
== 0xdeadbeef, "got %lx\n", selectitem_lp
);
3598 SetWindowLongPtrA( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_fill_in_init
);
3600 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= gflag_enteridle
= 0;
3601 selectitem_wp
= 0xdeadbeef;
3602 selectitem_lp
= 0xdeadbeef;
3604 ret
= TrackPopupMenu( hmenu
, 0, 100,100, 0, hwnd
, NULL
);
3605 ok(ret
== 1, "got %i\n", ret
);
3607 ok(gflag_initmenupopup
== 1, "got %i\n", gflag_initmenupopup
);
3608 ok(gflag_entermenuloop
== 1, "got %i\n", gflag_entermenuloop
);
3609 ok(gflag_initmenu
== 1, "got %i\n", gflag_initmenu
);
3610 ok(gflag_enteridle
== 1, "got %i\n", gflag_initmenu
);
3612 ok(selectitem_wp
== 0xffff0000, "got %lx\n", selectitem_wp
);
3613 ok(selectitem_lp
== 0, "got %lx\n", selectitem_lp
);
3615 DestroyWindow(hwnd
);
3617 ret
= DestroyMenu(hmenu
);
3618 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
3623 init_function_pointers();
3625 /* Wine defines MENUITEMINFO for W2K and above. NT4 and below can't
3628 if (correct_behavior())
3630 test_menu_add_string();
3631 test_menu_iteminfo();
3632 test_menu_search_bycommand();
3633 test_CheckMenuRadioItem();
3634 test_menu_resource_layout();
3639 register_menu_check_class();
3641 test_menu_locked_by_window();
3642 test_subpopup_locked_by_menu();
3643 test_menu_ownerdraw();
3644 test_getmenubarinfo();
3645 test_menu_bmp_and_string();
3646 test_menu_getmenuinfo();
3647 test_menu_setmenuinfo();
3651 test_menu_hilitemenuitem();
3652 test_menu_trackpopupmenu();
3653 test_menu_trackagain();
3654 test_menu_cancelmode();
3655 test_menu_maxdepth();
3656 test_menu_circref();