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(MENUITEMINFO
));
73 info
.cbSize
= sizeof(MENUITEMINFO
);
74 SetLastError(0xdeadbeef);
75 rc
= GetMenuItemInfo(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 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, TRUE
);
98 /* exit menu modal loop
99 * ( A SendMessage does not work on NT3.51 here ) */
100 return PostMessage(hwnd
, WM_CANCELMODE
, 0, 0);
102 return DefWindowProc(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 int MOD_GotDrawItemMsg
= FALSE
;
148 static int gflag_initmenupopup
,
152 /* wndproc used by test_menu_ownerdraw() */
153 static LRESULT WINAPI
menu_ownerdraw_wnd_proc(HWND hwnd
, UINT msg
,
154 WPARAM wparam
, LPARAM lparam
)
156 static HMENU hmenupopup
;
159 case WM_INITMENUPOPUP
:
160 gflag_initmenupopup
++;
161 hmenupopup
= (HMENU
) wparam
;
163 case WM_ENTERMENULOOP
:
164 gflag_entermenuloop
++;
171 MEASUREITEMSTRUCT
* pmis
= (MEASUREITEMSTRUCT
*)lparam
;
173 trace("WM_MEASUREITEM received data %lx size %dx%d\n",
174 pmis
->itemData
, pmis
->itemWidth
, pmis
->itemHeight
);
175 ok( !wparam
, "wrong wparam %lx\n", wparam
);
176 ok( pmis
->CtlType
== ODT_MENU
, "wrong type %x\n", pmis
->CtlType
);
177 MOD_odheight
= pmis
->itemHeight
;
178 pmis
->itemWidth
= MODsizes
[pmis
->itemData
].cx
;
179 pmis
->itemHeight
= MODsizes
[pmis
->itemData
].cy
;
184 DRAWITEMSTRUCT
* pdis
;
187 char chrs
[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
190 pdis
= (DRAWITEMSTRUCT
*) lparam
;
191 if( winetest_debug
) {
193 GetMenuItemRect( hwnd
, (HMENU
)pdis
->hwndItem
, pdis
->itemData
,&rc
);
194 trace("WM_DRAWITEM received hwnd %p hmenu %p itemdata %ld item %d rc %d,%d-%d,%d itemrc: %d,%d-%d,%d\n",
195 hwnd
, pdis
->hwndItem
, pdis
->itemData
, pdis
->itemID
,
196 pdis
->rcItem
.left
, pdis
->rcItem
.top
,
197 pdis
->rcItem
.right
,pdis
->rcItem
.bottom
,
198 rc
.left
,rc
.top
,rc
.right
,rc
.bottom
);
199 oldpen
=SelectObject( pdis
->hDC
, GetStockObject(
200 pdis
->itemState
& ODS_SELECTED
? WHITE_PEN
:BLACK_PEN
));
201 Rectangle( pdis
->hDC
, pdis
->rcItem
.left
,pdis
->rcItem
.top
,
202 pdis
->rcItem
.right
,pdis
->rcItem
.bottom
);
203 SelectObject( pdis
->hDC
, oldpen
);
205 ok( !wparam
, "wrong wparam %lx\n", wparam
);
206 ok( pdis
->CtlType
== ODT_MENU
, "wrong type %x\n", pdis
->CtlType
);
207 /* calculate widths of some menu texts */
208 if( ! MOD_txtsizes
[0].size
.cx
)
209 for(i
= 0; MOD_txtsizes
[i
].text
; i
++) {
212 strcpy( buf
, MOD_txtsizes
[i
].text
);
213 if( ( p
= strchr( buf
, '\t'))) {
215 DrawText( pdis
->hDC
, p
+ 1, -1, &rc
,
216 DT_SINGLELINE
|DT_CALCRECT
);
217 MOD_txtsizes
[i
].sc_size
.cx
= rc
.right
- rc
.left
;
218 MOD_txtsizes
[i
].sc_size
.cy
= rc
.bottom
- rc
.top
;
220 DrawText( pdis
->hDC
, buf
, -1, &rc
,
221 DT_SINGLELINE
|DT_CALCRECT
);
222 MOD_txtsizes
[i
].size
.cx
= rc
.right
- rc
.left
;
223 MOD_txtsizes
[i
].size
.cy
= rc
.bottom
- rc
.top
;
226 if( pdis
->itemData
> MOD_maxid
) return TRUE
;
227 /* store the rectangle */
228 MOD_rc
[pdis
->itemData
] = pdis
->rcItem
;
229 /* calculate average character width */
230 GetTextExtentPoint( pdis
->hDC
, chrs
, 52, &sz
);
231 MOD_avec
= (sz
.cx
+ 26)/52;
232 GetTextMetrics( pdis
->hDC
, &tm
);
233 MOD_hic
= tm
.tmHeight
;
234 MOD_GotDrawItemMsg
= TRUE
;
239 ok( lparam
|| broken(!lparam
), /* win9x, nt4 */
240 "Menu window handle is NULL!\n");
242 HMENU hmenu
= (HMENU
)SendMessageA( (HWND
)lparam
, MN_GETHMENU
, 0, 0);
243 ok( hmenupopup
== hmenu
, "MN_GETHMENU returns %p expected %p\n",
246 PostMessage(hwnd
, WM_CANCELMODE
, 0, 0);
251 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
254 static void register_menu_check_class(void)
262 GetModuleHandle(NULL
),
264 LoadCursor(NULL
, IDC_ARROW
),
265 (HBRUSH
)(COLOR_BTNFACE
+1),
267 TEXT("WineMenuCheck"),
270 atomMenuCheckClass
= RegisterClass(&wc
);
273 static void test_getmenubarinfo(void)
282 if (!pGetMenuBarInfo
) {
283 win_skip("GetMenuBarInfo is not available\n");
287 mbi
.cbSize
= sizeof(MENUBARINFO
);
289 hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
290 WS_SYSMENU
| WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 100, 100,
291 NULL
, NULL
, NULL
, NULL
);
292 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
294 /* no menu: getmenubarinfo should fail */
295 SetLastError(0xdeadbeef);
296 ret
= pGetMenuBarInfo(hwnd
, OBJID_MENU
, 0, &mbi
);
297 err
= GetLastError();
298 ok(ret
== FALSE
, "GetMenuBarInfo should not have been successful\n");
299 ok(err
== 0xdeadbeef, "err = %d\n", err
);
301 /* create menubar, no items yet */
302 hmenu
= CreateMenu();
303 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
305 ret
= SetMenu(hwnd
, hmenu
);
306 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
308 SetLastError(0xdeadbeef);
309 ret
= pGetMenuBarInfo(NULL
, OBJID_CLIENT
, 0, &mbi
);
310 err
= GetLastError();
311 ok(!ret
, "GetMenuBarInfo succeeded\n");
312 ok(err
== ERROR_INVALID_WINDOW_HANDLE
, "err = %d\n", err
);
314 SetLastError(0xdeadbeef);
315 ret
= pGetMenuBarInfo(hwnd
, OBJID_CLIENT
, 0, &mbi
);
316 err
= GetLastError();
317 ok(!ret
, "GetMenuBarInfo succeeded\n");
318 ok(err
==ERROR_INVALID_MENU_HANDLE
|| broken(err
==0xdeadbeef) /* NT, W2K, XP */, "err = %d\n", err
);
320 SetLastError(0xdeadbeef);
321 ret
= pGetMenuBarInfo(hwnd
, OBJID_MENU
, -1, &mbi
);
322 err
= GetLastError();
323 ok(ret
== FALSE
, "GetMenuBarInfo should have failed\n");
324 ok(err
== 0xdeadbeef, "err = %d\n", err
);
327 SetLastError(0xdeadbeef);
328 ret
= pGetMenuBarInfo(hwnd
, OBJID_MENU
, 0, &mbi
);
329 err
= GetLastError();
330 ok(ret
== FALSE
, "GetMenuBarInfo should have failed\n");
331 ok(err
== ERROR_INVALID_PARAMETER
, "err = %d\n", err
);
332 mbi
.cbSize
= sizeof(MENUBARINFO
);
334 SetLastError(0xdeadbeef);
335 ret
= pGetMenuBarInfo(hwnd
, 123, 0, &mbi
);
336 err
= GetLastError();
337 ok(ret
== FALSE
, "GetMenuBarInfo should have failed\n");
338 ok(err
== 0xdeadbeef, "err = %d\n", err
);
340 ret
= pGetMenuBarInfo(hwnd
, OBJID_MENU
, 0, &mbi
);
341 ok(ret
, "GetMenuBarInfo failed with error %d\n", GetLastError());
343 ok(mbi
.rcBar
.left
== 0 && mbi
.rcBar
.top
== 0 &&
344 mbi
.rcBar
.bottom
== 0 && mbi
.rcBar
.right
== 0,
345 "rcBar: Expected 0,0-0,0, got: %d,%d-%d,%d\n",
346 mbi
.rcBar
.left
, mbi
.rcBar
.top
, mbi
.rcBar
.right
, mbi
.rcBar
.bottom
);
347 ok(mbi
.hMenu
== hmenu
, "hMenu: Got %p instead of %p\n",
349 ok(mbi
.fBarFocused
== 0, "fBarFocused: Got %d instead of 0.\n", mbi
.fBarFocused
);
350 ok(mbi
.fFocused
== 0, "fFocused: Got %d instead of 0.\n", mbi
.fFocused
);
353 ret
= AppendMenu(hmenu
, MF_STRING
, 100, "item 1");
354 ok(ret
, "AppendMenu failed.\n");
355 ret
= AppendMenu(hmenu
, MF_STRING
, 101, "item 2");
356 ok(ret
, "AppendMenu failed.\n");
357 ret
= SetMenu(hwnd
, hmenu
);
358 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
360 SetLastError(0xdeadbeef);
361 ret
= pGetMenuBarInfo(hwnd
, OBJID_MENU
, 200, &mbi
);
362 err
= GetLastError();
363 ok(ret
== FALSE
, "GetMenuBarInfo should have failed\n");
364 ok(err
== 0xdeadbeef, "err = %d\n", err
);
366 /* get info for the whole menu */
367 ret
= pGetMenuBarInfo(hwnd
, OBJID_MENU
, 0, &mbi
);
368 ok(ret
, "GetMenuBarInfo failed with error %d\n", GetLastError());
370 /* calculate menu rectangle, from window rectangle and the position of the first item */
371 ret
= GetWindowRect(hwnd
, &rcw
);
372 ok(ret
, "GetWindowRect failed.\n");
373 ret
= GetMenuItemRect(hwnd
, hmenu
, 0, &rci
);
374 ok(ret
, "GetMenuItemRect failed.\n");
375 todo_wine
ok(mbi
.rcBar
.left
== rci
.left
&& mbi
.rcBar
.top
== rci
.top
&&
376 mbi
.rcBar
.bottom
== rci
.bottom
&& mbi
.rcBar
.right
== rcw
.right
- rci
.left
+ rcw
.left
,
377 "rcBar: Got %d,%d-%d,%d instead of %d,%d-%d,%d\n",
378 mbi
.rcBar
.left
, mbi
.rcBar
.top
, mbi
.rcBar
.right
, mbi
.rcBar
.bottom
,
379 rci
.left
, rci
.top
, rcw
.right
- rci
.left
+ rcw
.left
, rci
.bottom
);
380 ok(mbi
.hMenu
== hmenu
, "hMenu: Got %p instead of %p\n", mbi
.hMenu
, hmenu
);
381 ok(mbi
.fBarFocused
== 0, "fBarFocused: got %d instead of 0\n", mbi
.fBarFocused
);
382 ok(mbi
.fFocused
== 0, "fFocused: got %d instead of 0\n", mbi
.fFocused
);
384 /* get info for item nr.2 */
385 ret
= pGetMenuBarInfo(hwnd
, OBJID_MENU
, 2, &mbi
);
386 ok(ret
, "GetMenuBarInfo failed with error %d\n", GetLastError());
387 ret
= GetMenuItemRect(hwnd
, hmenu
, 1, &rci
);
388 ok(ret
, "GetMenuItemRect failed.\n");
389 ok(mbi
.rcBar
.left
== rci
.left
&& mbi
.rcBar
.top
== rci
.top
&&
390 mbi
.rcBar
.bottom
== rci
.bottom
&& mbi
.rcBar
.right
== rci
.right
,
391 "rcBar: Got %d,%d-%d,%d instead of %d,%d-%d,%d\n",
392 mbi
.rcBar
.left
, mbi
.rcBar
.top
, mbi
.rcBar
.right
, mbi
.rcBar
.bottom
,
393 rci
.left
, rci
.top
, rci
.right
, rci
.bottom
);
394 ok(mbi
.hMenu
== hmenu
, "hMenu: Got %p instead of %p\n", mbi
.hMenu
, hmenu
);
395 ok(mbi
.fBarFocused
== 0, "fBarFocused: got %d instead of 0\n", mbi
.fBarFocused
);
396 ok(mbi
.fFocused
== 0, "fFocused: got %d instead of 0\n", mbi
.fFocused
);
401 /* demonstrates that windows locks the menu object so that it is still valid
402 * even after a client calls DestroyMenu on it */
403 static void test_menu_locked_by_window(void)
407 HWND hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
408 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
409 NULL
, NULL
, NULL
, NULL
);
410 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
411 hmenu
= CreateMenu();
412 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
413 ret
= InsertMenu(hmenu
, 0, MF_STRING
, 0, TEXT("&Test"));
414 ok(ret
, "InsertMenu failed with error %d\n", GetLastError());
415 ret
= SetMenu(hwnd
, hmenu
);
416 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
417 ret
= DestroyMenu(hmenu
);
418 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
420 ret
= DrawMenuBar(hwnd
);
422 ok(ret
, "DrawMenuBar failed with error %d\n", GetLastError());
424 ret
= IsMenu(GetMenu(hwnd
));
425 ok(!ret
|| broken(ret
) /* nt4 */, "Menu handle should have been destroyed\n");
427 SendMessage(hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, 0);
428 /* did we process the WM_INITMENU message? */
429 ret
= GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
431 ok(ret
, "WM_INITMENU should have been sent\n");
437 /* demonstrates that subpopup's are locked
438 * even after a client calls DestroyMenu on it */
439 static LRESULT WINAPI
subpopuplocked_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
445 hwndmenu
= GetCapture();
447 PostMessage( hwndmenu
, WM_KEYDOWN
, VK_DOWN
, 0);
448 PostMessage( hwndmenu
, WM_KEYDOWN
, VK_RIGHT
, 0);
449 PostMessage( hwndmenu
, WM_KEYDOWN
, VK_RETURN
, 0);
452 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
455 static void test_subpopup_locked_by_menu(void)
459 HMENU hmenu
, hsubmenu
;
460 MENUINFO mi
= { sizeof( MENUINFO
)};
461 MENUITEMINFO mii
= { sizeof( MENUITEMINFO
)};
463 const int itemid
= 0x1234567;
466 win_skip("GetMenuInfo is not available\n");
469 /* create window, popupmenu with one subpopup */
470 hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
471 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
472 NULL
, NULL
, NULL
, NULL
);
473 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
474 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
) subpopuplocked_wnd_proc
);
475 hmenu
= CreatePopupMenu();
476 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
477 hsubmenu
= CreatePopupMenu();
478 ok(hsubmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
479 ret
= InsertMenu(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hsubmenu
,
480 TEXT("PopUpLockTest"));
481 ok(ret
, "InsertMenu failed with error %d\n", GetLastError());
482 ret
= InsertMenu(hsubmenu
, 0, MF_BYPOSITION
| MF_STRING
, itemid
, TEXT("PopUpMenu"));
483 ok(ret
, "InsertMenu failed with error %d\n", GetLastError());
484 /* first some tests that all this functions properly */
485 mii
.fMask
= MIIM_SUBMENU
;
486 ret
= GetMenuItemInfo( hmenu
, 0, TRUE
, &mii
);
487 ok( ret
, "GetMenuItemInfo failed error %d\n", GetLastError());
488 ok( mii
.hSubMenu
== hsubmenu
, "submenu is %p\n", mii
.hSubMenu
);
489 mi
.fMask
|= MIM_STYLE
;
490 ret
= pGetMenuInfo( hsubmenu
, &mi
);
491 ok( ret
, "GetMenuInfo returned 0 with error %d\n", GetLastError());
492 ret
= IsMenu( hsubmenu
);
493 ok( ret
, "Menu handle is not valid\n");
494 SetLastError( 0xdeadbeef);
495 ret
= TrackPopupMenu( hmenu
, TPM_RETURNCMD
, 100,100, 0, hwnd
, NULL
);
496 if( ret
== (itemid
& 0xffff)) {
497 win_skip("not on 16 bit menu subsystem\n");
498 DestroyMenu( hsubmenu
);
500 gle
= GetLastError();
501 ok( ret
== itemid
, "TrackPopupMenu returned %d error is %d\n", ret
, gle
);
503 broken( gle
== 0xdeadbeef), /* win2k0 */
504 "Last error is %d\n", gle
);
505 /* then destroy the sub-popup */
506 ret
= DestroyMenu( hsubmenu
);
507 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
508 /* and repeat the tests */
509 mii
.fMask
= MIIM_SUBMENU
;
510 ret
= GetMenuItemInfo( hmenu
, 0, TRUE
, &mii
);
511 ok( ret
, "GetMenuItemInfo failed error %d\n", GetLastError());
512 /* GetMenuInfo fails now */
513 ok( mii
.hSubMenu
== hsubmenu
, "submenu is %p\n", mii
.hSubMenu
);
514 mi
.fMask
|= MIM_STYLE
;
515 ret
= pGetMenuInfo( hsubmenu
, &mi
);
516 ok( !ret
, "GetMenuInfo should have failed\n");
517 /* IsMenu says it is not */
518 ret
= IsMenu( hsubmenu
);
519 ok( !ret
, "Menu handle should be invalid\n");
520 /* but TrackPopupMenu still works! */
521 SetLastError( 0xdeadbeef);
522 ret
= TrackPopupMenu( hmenu
, TPM_RETURNCMD
, 100,100, 0, hwnd
, NULL
);
523 gle
= GetLastError();
525 ok( ret
== itemid
, "TrackPopupMenu returned %d error is %d\n", ret
, gle
);
528 broken(gle
== 0xdeadbeef) || /* wow64 */
529 broken(gle
== ERROR_INVALID_PARAMETER
), /* win2k0 */
530 "Last error is %d\n", gle
);
537 static void test_menu_ownerdraw(void)
544 HWND hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
545 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
546 NULL
, NULL
, NULL
, NULL
);
547 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
549 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_ownerdraw_wnd_proc
);
550 hmenu
= CreatePopupMenu();
551 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
552 if( !hmenu
) { DestroyWindow(hwnd
);return;}
554 for( j
=0;j
<2;j
++) /* create columns */
555 for(i
=0;i
<2;i
++) { /* create rows */
556 ret
= AppendMenu( hmenu
, MF_OWNERDRAW
|
557 (i
==0 ? MF_MENUBREAK
: 0), k
, MAKEINTRESOURCE(k
));
559 ok( ret
, "AppendMenu failed for %d\n", k
-1);
562 assert( k
<= sizeof(MOD_rc
)/sizeof(RECT
));
563 /* display the menu */
564 TrackPopupMenu( hmenu
, TPM_RETURNCMD
, 100,100, 0, hwnd
, NULL
);
566 /* columns have a 4 pixel gap between them */
567 ok( MOD_rc
[0].right
+ 4 == MOD_rc
[2].left
,
568 "item rectangles are not separated by 4 pixels space\n");
569 /* height should be what the MEASUREITEM message has returned */
570 ok( MOD_rc
[0].bottom
- MOD_rc
[0].top
== MOD_SIZE
,
571 "menu item has wrong height: %d should be %d\n",
572 MOD_rc
[0].bottom
- MOD_rc
[0].top
, MOD_SIZE
);
573 /* no gaps between the rows */
574 ok( MOD_rc
[0].bottom
- MOD_rc
[1].top
== 0,
575 "There should not be a space between the rows, gap is %d\n",
576 MOD_rc
[0].bottom
- MOD_rc
[1].top
);
577 /* test the correct value of the item height that was sent
578 * by the WM_MEASUREITEM message */
579 ok( MOD_odheight
== HIWORD( GetDialogBaseUnits()) || /* WinNT,2k,XP */
580 MOD_odheight
== MOD_hic
, /* Win95,98,ME */
581 "Wrong height field in MEASUREITEMSTRUCT, expected %d or %d actual %d\n",
582 HIWORD( GetDialogBaseUnits()), MOD_hic
, MOD_odheight
);
583 /* test what MF_MENUBREAK did at the first position. Also show
584 * that an MF_SEPARATOR is ignored in the height calculation. */
585 leftcol
= MOD_rc
[0].left
;
586 ModifyMenu( hmenu
, 0, MF_BYCOMMAND
| MF_OWNERDRAW
| MF_SEPARATOR
, 0, 0);
587 /* display the menu */
588 TrackPopupMenu( hmenu
, TPM_RETURNCMD
, 100,100, 0, hwnd
, NULL
);
589 /* left should be 4 pixels less now */
590 ok( leftcol
== MOD_rc
[0].left
+ 4,
591 "columns should be 4 pixels to the left (actual %d).\n",
592 leftcol
- MOD_rc
[0].left
);
594 ok( MOD_rc
[0].right
- MOD_rc
[0].left
== 2 * MOD_avec
+ MOD_SIZE
,
595 "width of owner drawn menu item is wrong. Got %d expected %d\n",
596 MOD_rc
[0].right
- MOD_rc
[0].left
, 2*MOD_avec
+ MOD_SIZE
);
598 ok( MOD_rc
[0].bottom
- MOD_rc
[0].top
== MOD_SIZE
,
599 "Height is incorrect. Got %d expected %d\n",
600 MOD_rc
[0].bottom
- MOD_rc
[0].top
, MOD_SIZE
);
602 /* test owner-drawn callback bitmap */
603 ModifyMenu( hmenu
, 1, MF_BYPOSITION
| MFT_BITMAP
, 1, (LPCSTR
)HBMMENU_CALLBACK
);
604 mii
.cbSize
= sizeof(mii
);
605 mii
.fMask
= MIIM_BITMAP
| MIIM_FTYPE
| MIIM_ID
;
606 if (GetMenuItemInfoA( hmenu
, 1, TRUE
, &mii
))
608 ok( mii
.fType
== MFT_BITMAP
, "wrong type %x\n", mii
.fType
);
609 ok( mii
.wID
== 1, "wrong id %x\n", mii
.wID
);
610 ok( mii
.hbmpItem
== HBMMENU_CALLBACK
, "wrong data %p\n", mii
.hbmpItem
);
612 TrackPopupMenu( hmenu
, TPM_RETURNCMD
, 100,100, 0, hwnd
, NULL
);
614 /* test width/height of an ownerdraw menu bar as well */
615 ret
= DestroyMenu(hmenu
);
616 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
617 hmenu
= CreateMenu();
618 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
619 if( !hmenu
) { DestroyWindow(hwnd
);return;}
622 ret
= AppendMenu( hmenu
, MF_OWNERDRAW
, i
, 0);
623 ok( ret
, "AppendMenu failed for %d\n", i
);
625 ret
= SetMenu( hwnd
, hmenu
);
626 UpdateWindow( hwnd
); /* hack for wine to draw the window + menu */
627 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
629 ok( MOD_rc
[0].right
- MOD_rc
[0].left
== 2 * MOD_avec
+ MOD_SIZE
,
630 "width of owner drawn menu item is wrong. Got %d expected %d\n",
631 MOD_rc
[0].right
- MOD_rc
[0].left
, 2*MOD_avec
+ MOD_SIZE
);
633 ok( MOD_rc
[0].bottom
- MOD_rc
[0].top
== GetSystemMetrics( SM_CYMENU
) - 1,
634 "Height of owner drawn menu item is wrong. Got %d expected %d\n",
635 MOD_rc
[0].bottom
- MOD_rc
[0].top
, GetSystemMetrics( SM_CYMENU
) - 1);
638 ret
= DestroyMenu(hmenu
);
639 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
643 /* helper for test_menu_bmp_and_string() */
644 static void test_mbs_help( int ispop
, int hassub
, int mnuopt
,
645 HWND hwnd
, int arrowwidth
, int count
, HBITMAP hbmp
,
646 SIZE bmpsize
, LPCSTR text
, SIZE size
, SIZE sc_size
)
649 HMENU hmenu
, submenu
;
650 MENUITEMINFO mii
={ sizeof( MENUITEMINFO
)};
657 MOD_GotDrawItemMsg
= FALSE
;
658 mii
.fMask
= MIIM_FTYPE
| MIIM_DATA
| MIIM_STATE
;
660 /* check the menu item unless MNS_CHECKORBMP is set */
661 mii
.fState
= (mnuopt
!= 2 ? MFS_CHECKED
: MFS_UNCHECKED
);
663 MODsizes
[0] = bmpsize
;
667 mii
.fMask
|= MIIM_STRING
;
668 strcpy(text_copy
, text
);
669 mii
.dwTypeData
= text_copy
; /* structure member declared non-const */
670 if( ( p
= strchr( text
, '\t'))) {
671 hastab
= *(p
+ 1) ? 2 : 1;
674 /* tabs don't make sense in menubars */
675 if(hastab
&& !ispop
) return;
677 mii
.fMask
|= MIIM_BITMAP
;
680 submenu
= CreateMenu();
681 ok( submenu
!= 0, "CreateMenu failed with error %d\n", GetLastError());
683 hmenu
= CreatePopupMenu();
685 hmenu
= CreateMenu();
686 ok( hmenu
!= 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
688 mii
.fMask
|= MIIM_SUBMENU
;
689 mii
.hSubMenu
= submenu
;
692 mi
.cbSize
= sizeof(mi
);
693 mi
.fMask
= MIM_STYLE
;
694 pGetMenuInfo( hmenu
, &mi
);
695 if( mnuopt
) mi
.dwStyle
|= mnuopt
== 1 ? MNS_NOCHECK
: MNS_CHECKORBMP
;
696 ret
= pSetMenuInfo( hmenu
, &mi
);
697 ok( ret
, "SetMenuInfo failed with error %d\n", GetLastError());
699 ret
= InsertMenuItem( hmenu
, 0, FALSE
, &mii
);
700 ok( ret
, "InsertMenuItem failed with error %d\n", GetLastError());
702 if( winetest_debug
) {
704 RECT rc
= {100, 50, 400, 70};
707 sprintf( buf
,"%d text \"%s\" mnuopt %d", count
, text
? text
: "(nil)", mnuopt
);
708 FillRect( hdc
, &rc
, (HBRUSH
) COLOR_WINDOW
);
709 TextOut( hdc
, 10, 50, buf
, strlen( buf
));
710 ReleaseDC( hwnd
, hdc
);
713 TrackPopupMenu( hmenu
, TPM_RETURNCMD
, 100,100, 0, hwnd
, NULL
);
715 ret
= SetMenu( hwnd
, hmenu
);
716 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
719 ret
= GetMenuItemRect( hwnd
, hmenu
, 0, &rc
);
720 ok(ret
, "GetMenuItemRect failed with error %d\n", GetLastError());
722 if (0) /* comment out menu size checks, behavior is different in almost every Windows version */
723 /* the tests should however succeed on win2000, XP and Wine (at least up to 1.1.15) */
724 /* with a variety of dpis and desktop font sizes */
726 /* check menu width */
728 expect
= ( text
|| hbmp
?
729 4 + (mnuopt
!= 1 ? GetSystemMetrics(SM_CXMENUCHECK
) : 0)
731 arrowwidth
+ MOD_avec
+ (hbmp
?
732 ((INT_PTR
)hbmp
<0||(INT_PTR
)hbmp
>12 ? bmpsize
.cx
+ 2 : GetSystemMetrics( SM_CXMENUSIZE
) + 2)
734 (text
&& hastab
? /* TAB space */
735 MOD_avec
+ ( hastab
==2 ? sc_size
.cx
: 0) : 0) +
736 (text
? 2 + (text
[0] ? size
.cx
:0): 0) ;
738 expect
= !(text
|| hbmp
) ? 0 :
739 ( hbmp
? (text
? 2:0) + bmpsize
.cx
: 0 ) +
740 (text
? 2 * MOD_avec
+ (text
[0] ? size
.cx
:0): 0) ;
741 ok( rc
.right
- rc
.left
== expect
,
742 "menu width wrong, got %d expected %d\n", rc
.right
- rc
.left
, expect
);
743 failed
= failed
|| !(rc
.right
- rc
.left
== expect
);
744 /* check menu height */
746 expect
= max( ( !(text
|| hbmp
) ? GetSystemMetrics( SM_CYMENUSIZE
)/2 : 0),
747 max( (text
? max( 2 + size
.cy
, MOD_hic
+ 4) : 0),
749 ((INT_PTR
)hbmp
<0||(INT_PTR
)hbmp
>12 ?
751 : GetSystemMetrics( SM_CYMENUSIZE
) + 2)
754 expect
= ( !(text
|| hbmp
) ? GetSystemMetrics( SM_CYMENUSIZE
)/2 :
755 max( GetSystemMetrics( SM_CYMENU
) - 1, (hbmp
? bmpsize
.cy
: 0)));
756 ok( rc
.bottom
- rc
.top
== expect
,
757 "menu height wrong, got %d expected %d (%d)\n",
758 rc
.bottom
- rc
.top
, expect
, GetSystemMetrics( SM_CYMENU
));
759 failed
= failed
|| !(rc
.bottom
- rc
.top
== expect
);
760 if( hbmp
== HBMMENU_CALLBACK
&& MOD_GotDrawItemMsg
) {
761 /* check the position of the bitmap */
765 else if (mnuopt
== 0)
766 expect
= 4 + GetSystemMetrics(SM_CXMENUCHECK
);
767 else if (mnuopt
== 1)
769 else /* mnuopt == 2 */
771 ok( expect
== MOD_rc
[0].left
,
772 "bitmap left is %d expected %d\n", MOD_rc
[0].left
, expect
);
773 failed
= failed
|| !(expect
== MOD_rc
[0].left
);
775 expect
= (rc
.bottom
- rc
.top
- MOD_rc
[0].bottom
+ MOD_rc
[0].top
) / 2;
776 ok( expect
== MOD_rc
[0].top
,
777 "bitmap top is %d expected %d\n", MOD_rc
[0].top
, expect
);
778 failed
= failed
|| !(expect
== MOD_rc
[0].top
);
781 /* if there was a failure, report details */
783 trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
784 count
, (ispop
? "POPUP": "MENUBAR"),text
? text
: "(nil)", hbmp
, bmpsize
.cx
, bmpsize
.cy
,
785 size
.cx
, size
.cy
, sc_size
.cx
, mnuopt
, hastab
);
786 trace(" check %d,%d arrow %d avechar %d\n",
787 GetSystemMetrics(SM_CXMENUCHECK
),
788 GetSystemMetrics(SM_CYMENUCHECK
),arrowwidth
, MOD_avec
);
789 if( hbmp
== HBMMENU_CALLBACK
)
790 trace( " rc %d,%d-%d,%d bmp.rc %d,%d-%d,%d\n",
791 rc
.left
, rc
.top
, rc
.top
, rc
.bottom
, MOD_rc
[0].left
,
792 MOD_rc
[0].top
,MOD_rc
[0].right
, MOD_rc
[0].bottom
);
795 ret
= DestroyMenu(submenu
);
796 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
797 ret
= DestroyMenu(hmenu
);
798 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
802 static void test_menu_bmp_and_string(void)
810 MENUINFO mi
= {sizeof(MENUINFO
)};
811 MENUITEMINFOA mii
= {sizeof(MENUITEMINFOA
)};
812 int count
, szidx
, txtidx
, bmpidx
, hassub
, mnuopt
, ispop
;
817 win_skip("GetMenuInfo is not available\n");
821 memset( bmfill
, 0xcc, sizeof( bmfill
));
822 hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
, WS_SYSMENU
|
823 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
824 NULL
, NULL
, NULL
, NULL
);
825 hbm_arrow
=LoadBitmap( 0, (CHAR
*)OBM_MNARROW
);
826 GetObject( hbm_arrow
, sizeof(bm
), &bm
);
827 arrowwidth
= bm
.bmWidth
;
828 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
830 /* test system menu */
831 hsysmenu
= GetSystemMenu( hwnd
, FALSE
);
832 ok( hsysmenu
!= NULL
, "GetSystemMenu failed with error %d\n", GetLastError());
833 mi
.fMask
= MIM_STYLE
;
835 got
= pGetMenuInfo( hsysmenu
, &mi
);
836 ok( got
, "GetMenuInfo failed gle=%d\n", GetLastError());
837 ok( MNS_CHECKORBMP
== mi
.dwStyle
, "System Menu Style is %08x, without the bit %08x\n",
838 mi
.dwStyle
, MNS_CHECKORBMP
);
839 mii
.fMask
= MIIM_BITMAP
;
841 got
= GetMenuItemInfoA( hsysmenu
, SC_CLOSE
, FALSE
, &mii
);
842 ok( got
, "GetMenuItemInfoA failed gle=%d\n", GetLastError());
843 ok( HBMMENU_POPUP_CLOSE
== mii
.hbmpItem
, "Item info did not get the right hbitmap: got %p expected %p\n",
844 mii
.hbmpItem
, HBMMENU_POPUP_CLOSE
);
846 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_ownerdraw_wnd_proc
);
849 trace(" check %d,%d arrow %d avechar %d\n",
850 GetSystemMetrics(SM_CXMENUCHECK
),
851 GetSystemMetrics(SM_CYMENUCHECK
),arrowwidth
, MOD_avec
);
854 for( ispop
=1; ispop
>= 0; ispop
--){
855 static SIZE bmsizes
[]= {
856 {10,10},{38,38},{1,30},{55,5}};
857 for( szidx
=0; szidx
< sizeof( bmsizes
) / sizeof( SIZE
); szidx
++) {
858 HBITMAP hbm
= CreateBitmap( bmsizes
[szidx
].cx
, bmsizes
[szidx
].cy
,1,1,bmfill
);
859 HBITMAP bitmaps
[] = { HBMMENU_CALLBACK
, hbm
, HBMMENU_POPUP_CLOSE
, NULL
};
860 ok( hbm
!= 0, "CreateBitmap failed err %d\n", GetLastError());
861 for( txtidx
= 0; txtidx
< sizeof(MOD_txtsizes
)/sizeof(MOD_txtsizes
[0]); txtidx
++) {
862 for( hassub
= 0; hassub
< 2 ; hassub
++) { /* add submenu item */
863 for( mnuopt
= 0; mnuopt
< 3 ; mnuopt
++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
864 for( bmpidx
= 0; bmpidx
<sizeof(bitmaps
)/sizeof(HBITMAP
); bmpidx
++) {
865 /* no need to test NULL bitmaps of several sizes */
866 if( !bitmaps
[bmpidx
] && szidx
> 0) continue;
867 /* the HBMMENU_POPUP not to test for menu bars */
869 bitmaps
[bmpidx
] >= HBMMENU_POPUP_CLOSE
&&
870 bitmaps
[bmpidx
] <= HBMMENU_POPUP_MINIMIZE
) continue;
871 if( !ispop
&& hassub
) continue;
872 test_mbs_help( ispop
, hassub
, mnuopt
,
873 hwnd
, arrowwidth
, ++count
,
876 MOD_txtsizes
[txtidx
].text
,
877 MOD_txtsizes
[txtidx
].size
,
878 MOD_txtsizes
[txtidx
].sc_size
);
890 static void test_menu_add_string( void )
901 WCHAR strbackW
[0x80];
902 static CHAR blah
[] = "blah";
903 static const WCHAR expectedString
[] = {'D','u','m','m','y',' ','s','t','r','i','n','g', 0};
905 hmenu
= CreateMenu();
907 memset( &info
, 0, sizeof info
);
908 info
.cbSize
= sizeof info
;
909 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_ID
;
910 info
.dwTypeData
= blah
;
915 InsertMenuItem(hmenu
, 0, TRUE
, &info
);
917 memset( &info
, 0, sizeof info
);
918 info
.cbSize
= sizeof info
;
919 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_DATA
| MIIM_ID
;
920 info
.dwTypeData
= string
;
921 info
.cch
= sizeof string
;
923 GetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
925 ok( !strcmp( string
, "blah" ), "menu item name differed\n");
927 /* Test combination of ownerdraw and strings with GetMenuItemString(A/W) */
928 strcpy(string
, "Dummy string");
929 memset(&info
, 0x00, sizeof(info
));
930 info
.cbSize
= sizeof(MENUITEMINFO
);
931 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
; /* Set OwnerDraw + typeData */
932 info
.fType
= MFT_OWNERDRAW
;
933 info
.dwTypeData
= string
;
934 rc
= InsertMenuItem( hmenu
, 0, TRUE
, &info
);
935 ok (rc
, "InsertMenuItem failed\n");
937 strcpy(string
,"Garbage");
938 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
939 ok (!strcmp( strback
, "Dummy string" ), "Menu text from Ansi version incorrect\n");
941 SetLastError(0xdeadbeef);
942 ret
= GetMenuStringW( hmenu
, 0, strbackW
, 99, MF_BYPOSITION
);
943 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
944 win_skip("GetMenuStringW is not implemented\n");
947 ok (ret
, "GetMenuStringW on ownerdraw entry failed\n");
948 ok (!lstrcmpW( strbackW
, expectedString
), "Menu text from Unicode version incorrect\n");
951 /* Just change ftype to string and see what text is stored */
952 memset(&info
, 0x00, sizeof(info
));
953 info
.cbSize
= sizeof(MENUITEMINFO
);
954 info
.fMask
= MIIM_FTYPE
; /* Set string type */
955 info
.fType
= MFT_STRING
;
956 info
.dwTypeData
= (char *)0xdeadbeef;
957 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
958 ok (rc
, "SetMenuItemInfo failed\n");
960 /* Did we keep the old dwTypeData? */
961 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
962 ok (!strcmp( strback
, "Dummy string" ), "Menu text from Ansi version incorrect\n");
964 /* Ensure change to bitmap type fails */
965 memset(&info
, 0x00, sizeof(info
));
966 info
.cbSize
= sizeof(MENUITEMINFO
);
967 info
.fMask
= MIIM_FTYPE
; /* Set as bitmap type */
968 info
.fType
= MFT_BITMAP
;
969 info
.dwTypeData
= (char *)0xdeadbee2;
970 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
971 ok (!rc
, "SetMenuItemInfo unexpectedly worked\n");
973 /* Just change ftype back and ensure data hasn't been freed */
974 info
.fType
= MFT_OWNERDRAW
; /* Set as ownerdraw type */
975 info
.dwTypeData
= (char *)0xdeadbee3;
976 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
977 ok (rc
, "SetMenuItemInfo failed\n");
979 /* Did we keep the old dwTypeData? */
980 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
981 ok (!strcmp( strback
, "Dummy string" ), "Menu text from Ansi version incorrect\n");
983 /* Just change string value (not type) */
984 memset(&info
, 0x00, sizeof(info
));
985 info
.cbSize
= sizeof(MENUITEMINFO
);
986 info
.fMask
= MIIM_STRING
; /* Set typeData */
987 strcpy(string2
, "string2");
988 info
.dwTypeData
= string2
;
989 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
990 ok (rc
, "SetMenuItemInfo failed\n");
992 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
993 ok (!strcmp( strback
, "string2" ), "Menu text from Ansi version incorrect\n");
995 /* crashes with wine 0.9.5 */
996 memset(&info
, 0x00, sizeof(info
));
997 info
.cbSize
= sizeof(MENUITEMINFO
);
998 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
; /* Set OwnerDraw + typeData */
999 info
.fType
= MFT_OWNERDRAW
;
1000 rc
= InsertMenuItem( hmenu
, 0, TRUE
, &info
);
1001 ok (rc
, "InsertMenuItem failed\n");
1002 ok (!GetMenuString( hmenu
, 0, NULL
, 0, MF_BYPOSITION
),
1003 "GetMenuString on ownerdraw entry succeeded.\n");
1004 SetLastError(0xdeadbeef);
1005 ret
= GetMenuStringW( hmenu
, 0, NULL
, 0, MF_BYPOSITION
);
1006 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1007 win_skip("GetMenuStringW is not implemented\n");
1009 ok (!ret
, "GetMenuStringW on ownerdraw entry succeeded.\n");
1011 DestroyMenu( hmenu
);
1014 /* define building blocks for the menu item info tests */
1015 static int strncmpW( const WCHAR
*str1
, const WCHAR
*str2
, int n
)
1017 if (n
<= 0) return 0;
1018 while ((--n
> 0) && *str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
1019 return *str1
- *str2
;
1022 static WCHAR
*strcpyW( WCHAR
*dst
, const WCHAR
*src
)
1025 while ((*p
++ = *src
++));
1029 static void insert_menu_item( int line
, HMENU hmenu
, BOOL ansi
, UINT mask
, UINT type
, UINT state
, UINT id
,
1030 HMENU submenu
, HBITMAP checked
, HBITMAP unchecked
, ULONG_PTR data
,
1031 void *type_data
, UINT len
, HBITMAP item
, BOOL expect
)
1036 /* magic bitmap handle to test smaller cbSize */
1037 if (item
== (HBITMAP
)(ULONG_PTR
)0xdeadbeef)
1038 info
.cbSize
= FIELD_OFFSET(MENUITEMINFOA
,hbmpItem
);
1040 info
.cbSize
= sizeof(info
);
1043 info
.fState
= state
;
1045 info
.hSubMenu
= submenu
;
1046 info
.hbmpChecked
= checked
;
1047 info
.hbmpUnchecked
= unchecked
;
1048 info
.dwItemData
= data
;
1049 info
.dwTypeData
= type_data
;
1051 info
.hbmpItem
= item
;
1052 SetLastError( 0xdeadbeef );
1053 if (ansi
) ret
= InsertMenuItemA( hmenu
, 0, TRUE
, &info
);
1054 else ret
= InsertMenuItemW( hmenu
, 0, TRUE
, (MENUITEMINFOW
*)&info
);
1055 if (!expect
) ok_(__FILE__
, line
)( !ret
, "InsertMenuItem should have failed.\n" );
1056 else ok_(__FILE__
, line
)( ret
, "InsertMenuItem failed, err %u\n", GetLastError());
1059 static void check_menu_item_info( int line
, HMENU hmenu
, BOOL ansi
, UINT mask
, UINT type
, UINT state
,
1060 UINT id
, HMENU submenu
, HBITMAP checked
, HBITMAP unchecked
,
1061 ULONG_PTR data
, void *type_data
, UINT in_len
, UINT out_len
,
1062 HBITMAP item
, LPCSTR expname
, BOOL expect
, BOOL expstring
)
1068 SetLastError( 0xdeadbeef );
1069 memset( &info
, 0xcc, sizeof(info
) );
1070 info
.cbSize
= sizeof(info
);
1072 info
.dwTypeData
= type_data
;
1075 ret
= ansi
? GetMenuItemInfoA( hmenu
, 0, TRUE
, &info
) :
1076 GetMenuItemInfoW( hmenu
, 0, TRUE
, (MENUITEMINFOW
*)&info
);
1079 ok_(__FILE__
, line
)( !ret
, "GetMenuItemInfo should have failed.\n" );
1082 ok_(__FILE__
, line
)( ret
, "GetMenuItemInfo failed, err %u\n", GetLastError());
1083 if (mask
& MIIM_TYPE
)
1084 ok_(__FILE__
, line
)( info
.fType
== type
|| info
.fType
== LOWORD(type
),
1085 "wrong type %x/%x\n", info
.fType
, type
);
1086 if (mask
& MIIM_STATE
)
1087 ok_(__FILE__
, line
)( info
.fState
== state
|| info
.fState
== LOWORD(state
),
1088 "wrong state %x/%x\n", info
.fState
, state
);
1090 ok_(__FILE__
, line
)( info
.wID
== id
|| info
.wID
== LOWORD(id
),
1091 "wrong id %x/%x\n", info
.wID
, id
);
1092 if (mask
& MIIM_SUBMENU
)
1093 ok_(__FILE__
, line
)( info
.hSubMenu
== submenu
|| (ULONG_PTR
)info
.hSubMenu
== LOWORD(submenu
),
1094 "wrong submenu %p/%p\n", info
.hSubMenu
, submenu
);
1095 if (mask
& MIIM_CHECKMARKS
)
1097 ok_(__FILE__
, line
)( info
.hbmpChecked
== checked
|| (ULONG_PTR
)info
.hbmpChecked
== LOWORD(checked
),
1098 "wrong bmpchecked %p/%p\n", info
.hbmpChecked
, checked
);
1099 ok_(__FILE__
, line
)( info
.hbmpUnchecked
== unchecked
|| (ULONG_PTR
)info
.hbmpUnchecked
== LOWORD(unchecked
),
1100 "wrong bmpunchecked %p/%p\n", info
.hbmpUnchecked
, unchecked
);
1102 if (mask
& MIIM_DATA
)
1103 ok_(__FILE__
, line
)( info
.dwItemData
== data
|| info
.dwItemData
== LOWORD(data
),
1104 "wrong item data %lx/%lx\n", info
.dwItemData
, data
);
1105 if (mask
& MIIM_BITMAP
)
1106 ok_(__FILE__
, line
)( info
.hbmpItem
== item
|| (ULONG_PTR
)info
.hbmpItem
== LOWORD(item
),
1107 "wrong bmpitem %p/%p\n", info
.hbmpItem
, item
);
1108 ok_(__FILE__
, line
)( info
.dwTypeData
== type_data
|| (ULONG_PTR
)info
.dwTypeData
== LOWORD(type_data
),
1109 "wrong type data %p/%p\n", info
.dwTypeData
, type_data
);
1110 ok_(__FILE__
, line
)( info
.cch
== out_len
||
1111 broken(! ansi
&& info
.cch
== 2 * out_len
) /* East-Asian */,
1112 "wrong len %x/%x\n", info
.cch
, out_len
);
1116 ok_(__FILE__
, line
)( !strncmp( expname
, info
.dwTypeData
, out_len
),
1117 "menu item name differed from '%s' '%s'\n", expname
, info
.dwTypeData
);
1119 ok_(__FILE__
, line
)( !strncmpW( (WCHAR
*)expname
, (WCHAR
*)info
.dwTypeData
, out_len
),
1120 "menu item name wrong\n" );
1122 SetLastError( 0xdeadbeef );
1123 ret
= ansi
? GetMenuStringA( hmenu
, 0, (char *)buffer
, 80, MF_BYPOSITION
) :
1124 GetMenuStringW( hmenu
, 0, buffer
, 80, MF_BYPOSITION
);
1126 ok_(__FILE__
, line
)( ret
, "GetMenuString failed, err %u\n", GetLastError());
1128 ok_(__FILE__
, line
)( !ret
, "GetMenuString should have failed\n" );
1132 static void modify_menu( int line
, HMENU hmenu
, BOOL ansi
, UINT flags
, UINT_PTR id
, void *data
)
1136 SetLastError( 0xdeadbeef );
1137 if (ansi
) ret
= ModifyMenuA( hmenu
, 0, flags
, id
, data
);
1138 else ret
= ModifyMenuW( hmenu
, 0, flags
, id
, data
);
1139 ok_(__FILE__
,line
)( ret
, "ModifyMenuA failed, err %u\n", GetLastError());
1142 static void set_menu_item_info( int line
, HMENU hmenu
, BOOL ansi
, UINT mask
, UINT type
, UINT state
,
1143 UINT id
, HMENU submenu
, HBITMAP checked
, HBITMAP unchecked
, ULONG_PTR data
,
1144 void *type_data
, UINT len
, HBITMAP item
)
1150 /* magic bitmap handle to test smaller cbSize */
1151 if (item
== (HBITMAP
)(ULONG_PTR
)0xdeadbeef)
1152 info
.cbSize
= FIELD_OFFSET(MENUITEMINFOA
,hbmpItem
);
1154 info
.cbSize
= sizeof(info
);
1157 info
.fState
= state
;
1159 info
.hSubMenu
= submenu
;
1160 info
.hbmpChecked
= checked
;
1161 info
.hbmpUnchecked
= unchecked
;
1162 info
.dwItemData
= data
;
1163 info
.dwTypeData
= type_data
;
1165 info
.hbmpItem
= item
;
1166 SetLastError( 0xdeadbeef );
1167 if (ansi
) ret
= SetMenuItemInfoA( hmenu
, 0, TRUE
, &info
);
1168 else ret
= SetMenuItemInfoW( hmenu
, 0, TRUE
, (MENUITEMINFOW
*)&info
);
1169 ok_(__FILE__
, line
)( ret
, "SetMenuItemInfo failed, err %u\n", GetLastError());
1172 #define TMII_INSMI( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,eret1 )\
1173 hmenu = CreateMenu();\
1174 submenu = CreateMenu();\
1175 if(ansi)strcpy( string, init );\
1176 else strcpyW( string, init );\
1177 insert_menu_item( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, eret1 )
1179 /* GetMenuItemInfo + GetMenuString */
1180 #define TMII_GMII( c2,l2,\
1181 d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,\
1182 expname, eret2, eret3)\
1183 check_menu_item_info( __LINE__, hmenu, ansi, c2, d3, e3, f3, g3, h3, i3, j3, k3, l2, l3, m3, \
1184 expname, eret2, eret3 )
1187 RemoveMenu(hmenu, 0, TRUE );\
1188 DestroyMenu( hmenu );\
1189 DestroyMenu( submenu );
1192 #define TMII_MODM( flags, id, data ) \
1193 modify_menu( __LINE__, hmenu, ansi, flags, id, data )
1195 /* SetMenuItemInfo */
1196 #define TMII_SMII( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1 ) \
1197 set_menu_item_info( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1 )
1204 static void test_menu_iteminfo( void )
1210 WCHAR txtW
[]={'W','i','n','e',0};
1211 WCHAR initW
[]={'X','Y','Z',0};
1213 void *txt
, *init
, *empty
, *string
;
1214 HBITMAP hbm
= CreateBitmap(1,1,1,1,NULL
);
1216 HMENU hmenu
, submenu
;
1217 HBITMAP dummy_hbm
= (HBITMAP
)(ULONG_PTR
)0xdeadbeef;
1220 if( ansi
) {txt
=txtA
;init
=initA
;empty
=emptyA
;string
=stringA
;}
1221 else {txt
=txtW
;init
=initW
;empty
=emptyW
;string
=stringA
;}
1222 trace( "%s string %p hbm %p txt %p\n", ansi
? "ANSI tests: " : "Unicode tests:", string
, hbm
, txt
);
1223 /* test all combinations of MFT_STRING, MFT_OWNERDRAW and MFT_BITMAP */
1224 /* (since MFT_STRING is zero, there are four of them) */
1225 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, 0, 0, 0, 0, 0, 0, txt
, 0, 0, OK
);
1226 TMII_GMII ( MIIM_TYPE
, 80,
1227 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1230 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1231 TMII_GMII ( MIIM_TYPE
, 80,
1232 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1235 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, 6, 0, OK
);
1236 TMII_GMII ( MIIM_TYPE
, 80,
1237 MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1240 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, hbm
, 6, 0, OK
);
1241 TMII_GMII ( MIIM_TYPE
, 80,
1242 MFT_BITMAP
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1245 /* not enough space for name*/
1246 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1247 TMII_GMII ( MIIM_TYPE
, 0,
1248 MFT_STRING
, 0, 0, 0, 0, 0, 0, NULL
, 4, 0,
1251 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1252 TMII_GMII ( MIIM_TYPE
, 5,
1253 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1256 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1257 TMII_GMII ( MIIM_TYPE
, 4,
1258 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 3, 0,
1261 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1262 TMII_GMII ( MIIM_TYPE
, 0,
1263 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 0, 0,
1266 /* cannot combine MIIM_TYPE with some other flags */
1267 TMII_INSMI( MIIM_TYPE
|MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, ER
);
1269 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1270 TMII_GMII ( MIIM_TYPE
|MIIM_STRING
, 80,
1271 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1274 TMII_INSMI( MIIM_TYPE
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, ER
);
1276 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1277 TMII_GMII ( MIIM_TYPE
|MIIM_FTYPE
, 80,
1278 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1281 TMII_INSMI( MIIM_TYPE
|MIIM_BITMAP
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, 6, hbm
, ER
);
1283 /* but succeeds with some others */
1284 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1285 TMII_GMII ( MIIM_TYPE
|MIIM_SUBMENU
, 80,
1286 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1289 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1290 TMII_GMII ( MIIM_TYPE
|MIIM_STATE
, 80,
1291 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1294 TMII_INSMI( MIIM_TYPE
|MIIM_ID
, MFT_STRING
, -1, 888, 0, 0, 0, -1, txt
, 6, 0, OK
);
1295 TMII_GMII ( MIIM_TYPE
|MIIM_ID
, 80,
1296 MFT_STRING
, 0, 888, 0, 0, 0, 0, string
, 4, 0,
1299 TMII_INSMI( MIIM_TYPE
|MIIM_DATA
, MFT_STRING
, -1, -1, 0, 0, 0, 999, txt
, 6, 0, OK
);
1300 TMII_GMII ( MIIM_TYPE
|MIIM_DATA
, 80,
1301 MFT_STRING
, 0, 0, 0, 0, 0, 999, string
, 4, 0,
1304 /* to be continued */
1305 /* set text with MIIM_TYPE and retrieve with MIIM_STRING */
1306 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1307 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1308 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1311 /* set text with MIIM_TYPE and retrieve with MIIM_STRING; MFT_OWNERDRAW causes an empty string */
1312 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1313 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1314 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1317 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1318 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1319 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1322 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1323 TMII_GMII ( MIIM_FTYPE
, 80,
1324 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 80, 0,
1327 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1329 0, 0, 0, 0, 0, 0, 0, string
, 80, 0,
1332 /* contrary to MIIM_TYPE,you can set the text for an owner draw menu */
1333 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1334 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1335 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1338 /* same but retrieve with MIIM_TYPE */
1339 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1340 TMII_GMII ( MIIM_TYPE
, 80,
1341 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1344 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1345 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1346 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1349 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1350 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1351 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1355 /* How is that with bitmaps? */
1356 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1357 TMII_GMII ( MIIM_TYPE
, 80,
1358 MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1361 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1362 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1363 0, 0, 0, 0, 0, 0, 0, string
, 80, hbm
,
1366 /* MIIM_BITMAP does not like MFT_BITMAP */
1367 TMII_INSMI( MIIM_BITMAP
|MIIM_FTYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, ER
);
1369 /* no problem with OWNERDRAWN */
1370 TMII_INSMI( MIIM_BITMAP
|MIIM_FTYPE
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1371 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1372 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 80, hbm
,
1375 /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1376 TMII_INSMI( MIIM_FTYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER
);
1379 /* menu with submenu */
1380 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, submenu
, 0, 0, -1, txt
, 0, 0, OK
);
1381 TMII_GMII ( MIIM_SUBMENU
, 80,
1382 0, 0, 0, submenu
, 0, 0, 0, string
, 80, 0,
1385 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, submenu
, 0, 0, -1, empty
, 0, 0, OK
);
1386 TMII_GMII ( MIIM_SUBMENU
, 80,
1387 0, 0, 0, submenu
, 0, 0, 0, string
, 80, 0,
1390 /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1391 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, submenu
, 0, 0, -1, txt
, 0, 0, OK
);
1392 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1393 MFT_STRING
|MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1395 TMII_GMII ( MIIM_SUBMENU
|MIIM_FTYPE
, 80,
1396 MFT_SEPARATOR
, 0, 0, submenu
, 0, 0, 0, string
, 80, 0,
1399 /* menu with invalid submenu */
1400 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, (HMENU
)999, 0, 0, -1, txt
, 0, 0, ER
);
1403 TMII_INSMI( MIIM_TYPE
, MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, txt
, 0, 0, OK
);
1404 TMII_GMII ( MIIM_TYPE
, 80,
1405 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1408 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
|MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, hbm
, 6, 0, OK
);
1409 TMII_GMII ( MIIM_TYPE
, 80,
1410 MFT_BITMAP
|MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1413 /* SEPARATOR and STRING go well together */
1414 /* BITMAP and STRING go well together */
1415 TMII_INSMI( MIIM_STRING
|MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1416 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, 80,
1417 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, hbm
,
1420 /* BITMAP, SEPARATOR and STRING go well together */
1421 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1422 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, 80,
1423 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 4, hbm
,
1426 /* last two tests, but use MIIM_TYPE to retrieve info */
1427 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1428 TMII_GMII ( MIIM_TYPE
, 80,
1429 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1432 TMII_INSMI( MIIM_STRING
|MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1433 TMII_GMII ( MIIM_TYPE
, 80,
1434 MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1437 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1438 TMII_GMII ( MIIM_TYPE
, 80,
1439 MFT_SEPARATOR
|MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1442 /* same three with MFT_OWNERDRAW */
1443 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
, MFT_SEPARATOR
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1444 TMII_GMII ( MIIM_TYPE
, 80,
1445 MFT_SEPARATOR
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1448 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1449 TMII_GMII ( MIIM_TYPE
, 80,
1450 MFT_BITMAP
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1453 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1454 TMII_GMII ( MIIM_TYPE
, 80,
1455 MFT_SEPARATOR
|MFT_BITMAP
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1459 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
|MIIM_ID
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1460 TMII_GMII ( MIIM_TYPE
, 80,
1461 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1464 /* test with modifymenu: string is preserved after setting OWNERDRAW */
1465 TMII_INSMI( MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1466 TMII_MODM( MFT_OWNERDRAW
, -1, (void*)787 );
1467 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_DATA
, 80,
1468 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 787, string
, 4, 0,
1471 /* same with bitmap: now the text is cleared */
1472 TMII_INSMI( MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1473 TMII_MODM( MFT_BITMAP
, 545, hbm
);
1474 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1475 MFT_BITMAP
, 0, 545, 0, 0, 0, 0, string
, 0, hbm
,
1478 /* start with bitmap: now setting text clears it (though he flag is raised) */
1479 TMII_INSMI( MIIM_BITMAP
, MFT_STRING
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1480 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1481 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 0, hbm
,
1483 TMII_MODM( MFT_STRING
, 545, txt
);
1484 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1485 MFT_STRING
, 0, 545, 0, 0, 0, 0, string
, 4, 0,
1488 /*repeat with text NULL */
1489 TMII_INSMI( MIIM_BITMAP
, MFT_STRING
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1490 TMII_MODM( MFT_STRING
, 545, NULL
);
1491 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1492 MFT_SEPARATOR
, 0, 545, 0, 0, 0, 0, string
, 0, 0,
1495 /* repeat with text "" */
1496 TMII_INSMI( MIIM_BITMAP
, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1497 TMII_MODM( MFT_STRING
, 545, empty
);
1498 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1499 MFT_STRING
, 0, 545, 0, 0, 0, 0, string
, 0, 0,
1502 /* start with bitmap: set ownerdraw */
1503 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1504 TMII_MODM( MFT_OWNERDRAW
, -1, (void *)232 );
1505 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_DATA
, 80,
1506 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 232, string
, 0, hbm
,
1510 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1512 0, 0, 0, 0, 0, 0, 0, string
, 80, 0,
1515 /* some tests with small cbSize: the hbmpItem is to be ignored */
1516 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm
, OK
);
1517 TMII_GMII ( MIIM_TYPE
, 80,
1518 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, NULL
, 0, NULL
,
1521 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm
, OK
);
1522 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1523 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 80, NULL
,
1526 TMII_INSMI( MIIM_STRING
|MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1527 TMII_GMII ( MIIM_TYPE
, 80,
1528 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, NULL
,
1531 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1532 TMII_GMII ( MIIM_TYPE
, 80,
1533 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1536 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1537 TMII_GMII ( MIIM_TYPE
, 80,
1538 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1541 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1542 TMII_GMII ( MIIM_TYPE
, 80,
1543 MFT_SEPARATOR
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1546 /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus */
1547 TMII_INSMI( MIIM_TYPE
|MIIM_DATA
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, 343, txt
, 0, 0, OK
);
1548 TMII_GMII ( MIIM_TYPE
|MIIM_DATA
, 80,
1549 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1552 TMII_INSMI( MIIM_TYPE
|MIIM_DATA
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, 343, txt
, 0, 0, OK
);
1553 TMII_GMII ( MIIM_TYPE
, 80,
1554 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1557 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, 343, txt
, 0, 0, OK
);
1558 TMII_GMII ( MIIM_TYPE
|MIIM_DATA
, 80,
1559 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1562 /* set a string menu to ownerdraw with MIIM_TYPE */
1563 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -2, -2, 0, 0, 0, -2, txt
, -2, 0, OK
);
1564 TMII_SMII ( MIIM_TYPE
, MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1565 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1566 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1569 /* test with modifymenu add submenu */
1570 TMII_INSMI( MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1571 TMII_MODM( MF_POPUP
, (UINT_PTR
)submenu
, txt
);
1572 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_SUBMENU
, 80,
1573 MFT_STRING
, 0, 0, submenu
, 0, 0, 0, string
, 4, 0,
1575 TMII_GMII ( MIIM_TYPE
, 80,
1576 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1579 /* MFT_SEPARATOR bit is kept when the text is added */
1580 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1581 TMII_SMII( MIIM_STRING
, 0, 0, 0, 0, 0, 0, 0, txt
, 0, 0 );
1582 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1583 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1586 /* MFT_SEPARATOR bit is kept when bitmap is added */
1587 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1588 TMII_SMII( MIIM_BITMAP
, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm
);
1589 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1590 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 80, hbm
,
1593 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1594 Only the low word of the dwTypeData is used.
1595 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1596 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_RIGHTJUSTIFY
, -1, -1, 0, 0, 0, -1,
1597 (HMENU
)MAKELONG(HBMMENU_MBAR_CLOSE
, 0x1234), -1, 0, OK
);
1598 TMII_GMII ( MIIM_TYPE
, 80,
1599 MFT_BITMAP
| MFT_RIGHTJUSTIFY
, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE
, 0, HBMMENU_MBAR_CLOSE
,
1603 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1604 TMII_GMII ( MIIM_TYPE
, 80,
1605 MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1609 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1610 TMII_SMII( MIIM_STATE
, -1, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 0, 0 );
1611 TMII_GMII ( MIIM_STATE
, 80,
1612 0, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 80, 0,
1615 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1616 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1617 TMII_SMII( MIIM_CHECKMARKS
, MFT_RADIOCHECK
, 0, 0, 0, hbm
, hbm
, 0, 0, 0, 0 );
1618 TMII_GMII ( MIIM_CHECKMARKS
| MIIM_TYPE
, 80,
1619 MFT_BITMAP
, 0, 0, 0, hbm
, hbm
, 0, hbm
, 0, hbm
,
1622 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1623 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1624 TMII_SMII( MIIM_FTYPE
, MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, (HBITMAP
)0x1234, 0, 0 );
1625 TMII_GMII ( MIIM_FTYPE
, 80,
1626 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1628 TMII_GMII ( MIIM_TYPE
, 80,
1629 MFT_BITMAP
| MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1631 TMII_GMII ( MIIM_FTYPE
, 80,
1632 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1634 TMII_SMII( MIIM_BITMAP
, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
);
1635 TMII_GMII ( MIIM_TYPE
, 80,
1636 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 0, NULL
,
1639 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1640 Only the low word of the dwTypeData is used.
1641 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1642 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_RIGHTJUSTIFY
, -1, -1, 0, 0, 0, -1,
1643 (HMENU
)MAKELONG(HBMMENU_MBAR_CLOSE
, 0x1234), -1, 0, OK
);
1644 TMII_GMII ( MIIM_TYPE
, 80,
1645 MFT_BITMAP
| MFT_RIGHTJUSTIFY
, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE
, 0, HBMMENU_MBAR_CLOSE
,
1649 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1650 TMII_GMII ( MIIM_TYPE
, 80,
1651 MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1655 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1656 TMII_SMII( MIIM_STATE
, -1, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 0, 0 );
1657 TMII_GMII ( MIIM_STATE
, 80,
1658 0, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 80, 0,
1661 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1662 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1663 TMII_SMII( MIIM_CHECKMARKS
, MFT_RADIOCHECK
, 0, 0, 0, hbm
, hbm
, 0, 0, 0, 0 );
1664 TMII_GMII ( MIIM_CHECKMARKS
| MIIM_TYPE
, 80,
1665 MFT_BITMAP
, 0, 0, 0, hbm
, hbm
, 0, hbm
, 0, hbm
,
1668 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1669 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1670 TMII_SMII( MIIM_FTYPE
, MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, (HBITMAP
)0x1234, 0, 0 );
1671 TMII_GMII ( MIIM_FTYPE
, 80,
1672 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1674 TMII_GMII ( MIIM_TYPE
, 80,
1675 MFT_BITMAP
| MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1677 TMII_GMII ( MIIM_FTYPE
, 80,
1678 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1680 TMII_SMII( MIIM_BITMAP
, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
);
1681 TMII_GMII ( MIIM_TYPE
, 80,
1682 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 0, NULL
,
1685 } while( !(ansi
= !ansi
) );
1690 The following tests try to confirm the algorithm used to return the menu items
1691 when there is a collision between a menu item and a popup menu
1693 static void test_menu_search_bycommand( void )
1695 HMENU hmenu
, hmenuSub
, hmenuSub2
;
1701 static CHAR menuitem
[] = "MenuItem",
1702 menuitem2
[] = "MenuItem 2";
1704 /* Case 1: Menu containing a menu item */
1705 hmenu
= CreateMenu();
1707 memset( &info
, 0, sizeof info
);
1708 info
.cbSize
= sizeof info
;
1709 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1710 info
.fType
= MFT_STRING
;
1711 strcpy(strIn
, "Case 1 MenuItem");
1712 info
.dwTypeData
= strIn
;
1713 info
.wID
= (UINT
) 0x1234;
1715 rc
= InsertMenuItem(hmenu
, 0, TRUE
, &info
);
1716 ok (rc
, "Inserting the menuitem failed\n");
1718 id
= GetMenuItemID(hmenu
, 0);
1719 ok (id
== 0x1234, "Getting the menuitem id failed(gave %x)\n", id
);
1721 /* Confirm the menuitem was given the id supplied (getting by position) */
1722 memset( &info
, 0, sizeof info
);
1724 info
.cbSize
= sizeof(MENUITEMINFO
);
1725 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1726 info
.dwTypeData
= strback
;
1727 info
.cch
= sizeof(strback
);
1729 rc
= GetMenuItemInfo(hmenu
, 0, TRUE
, &info
); /* Get by position */
1730 ok (rc
, "Getting the menu items info failed\n");
1731 ok (info
.wID
== 0x1234, "IDs differ for the menuitem\n");
1732 ok (!strcmp(info
.dwTypeData
, "Case 1 MenuItem"), "Returned item has wrong label\n");
1734 /* Search by id - Should return the item */
1735 memset( &info
, 0, sizeof info
);
1737 info
.cbSize
= sizeof(MENUITEMINFO
);
1738 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1739 info
.dwTypeData
= strback
;
1740 info
.cch
= sizeof(strback
);
1741 rc
= GetMenuItemInfo(hmenu
, 0x1234, FALSE
, &info
); /* Get by ID */
1743 ok (rc
, "Getting the menu items info failed\n");
1744 ok (info
.wID
== 0x1234, "IDs differ for the menuitem\n");
1745 ok (!strcmp(info
.dwTypeData
, "Case 1 MenuItem"), "Returned item has wrong label\n");
1747 DestroyMenu( hmenu
);
1749 /* Case 2: Menu containing a popup menu */
1750 hmenu
= CreateMenu();
1751 hmenuSub
= CreateMenu();
1753 strcpy(strIn
, "Case 2 SubMenu");
1754 rc
= InsertMenu(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, strIn
);
1755 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1757 id
= GetMenuItemID(hmenu
, 0);
1758 ok (id
== -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id
);
1760 /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
1761 memset( &info
, 0, sizeof info
);
1763 info
.cbSize
= sizeof(MENUITEMINFO
);
1764 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1765 info
.dwTypeData
= strback
;
1766 info
.cch
= sizeof(strback
);
1767 info
.wID
= 0xdeadbeef;
1769 rc
= GetMenuItemInfo(hmenu
, 0, TRUE
, &info
); /* Get by position */
1770 ok (rc
, "Getting the menu items info failed\n");
1771 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the menuitem\n");
1772 ok (!strcmp(info
.dwTypeData
, "Case 2 SubMenu"), "Returned item has wrong label\n");
1774 /* Search by id - returns the popup menu itself */
1775 memset( &info
, 0, sizeof info
);
1777 info
.cbSize
= sizeof(MENUITEMINFO
);
1778 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1779 info
.dwTypeData
= strback
;
1780 info
.cch
= sizeof(strback
);
1781 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
); /* Get by ID */
1783 ok (rc
, "Getting the menu items info failed\n");
1784 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the popup menu\n");
1785 ok (!strcmp(info
.dwTypeData
, "Case 2 SubMenu"), "Returned item has wrong label\n");
1788 Now add an item after it with the same id
1790 memset( &info
, 0, sizeof info
);
1791 info
.cbSize
= sizeof info
;
1792 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1793 info
.fType
= MFT_STRING
;
1794 strcpy(strIn
, "Case 2 MenuItem 1");
1795 info
.dwTypeData
= strIn
;
1796 info
.wID
= (UINT_PTR
) hmenuSub
;
1797 rc
= InsertMenuItem(hmenu
, -1, TRUE
, &info
);
1798 ok (rc
, "Inserting the menuitem failed\n");
1800 /* Search by id - returns the item which follows the popup menu */
1801 memset( &info
, 0, sizeof info
);
1803 info
.cbSize
= sizeof(MENUITEMINFO
);
1804 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1805 info
.dwTypeData
= strback
;
1806 info
.cch
= sizeof(strback
);
1807 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
); /* Get by ID */
1809 ok (rc
, "Getting the menu items info failed\n");
1810 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the popup menu\n");
1811 ok (!strcmp(info
.dwTypeData
, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1814 Now add an item before the popup (with the same id)
1816 memset( &info
, 0, sizeof info
);
1817 info
.cbSize
= sizeof info
;
1818 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1819 info
.fType
= MFT_STRING
;
1820 strcpy(strIn
, "Case 2 MenuItem 2");
1821 info
.dwTypeData
= strIn
;
1822 info
.wID
= (UINT_PTR
) hmenuSub
;
1823 rc
= InsertMenuItem(hmenu
, 0, TRUE
, &info
);
1824 ok (rc
, "Inserting the menuitem failed\n");
1826 /* Search by id - returns the item which precedes the popup menu */
1827 memset( &info
, 0, sizeof info
);
1829 info
.cbSize
= sizeof(MENUITEMINFO
);
1830 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1831 info
.dwTypeData
= strback
;
1832 info
.cch
= sizeof(strback
);
1833 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
); /* Get by ID */
1835 ok (rc
, "Getting the menu items info failed\n");
1836 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the popup menu\n");
1837 ok (!strcmp(info
.dwTypeData
, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1839 DestroyMenu( hmenu
);
1840 DestroyMenu( hmenuSub
);
1843 Case 3: Menu containing a popup menu which in turn
1844 contains 2 items with the same id as the popup itself
1847 hmenu
= CreateMenu();
1848 hmenuSub
= CreateMenu();
1850 memset( &info
, 0, sizeof info
);
1851 info
.cbSize
= sizeof info
;
1852 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1853 info
.fType
= MFT_STRING
;
1854 info
.dwTypeData
= menuitem
;
1855 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1857 rc
= InsertMenu(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, "Submenu");
1858 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1860 rc
= InsertMenuItem(hmenuSub
, 0, TRUE
, &info
);
1861 ok (rc
, "Inserting the sub menu menuitem failed\n");
1863 memset( &info
, 0, sizeof info
);
1864 info
.cbSize
= sizeof info
;
1865 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1866 info
.fType
= MFT_STRING
;
1867 info
.dwTypeData
= menuitem2
;
1868 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1870 rc
= InsertMenuItem(hmenuSub
, 1, TRUE
, &info
);
1871 ok (rc
, "Inserting the sub menu menuitem 2 failed\n");
1873 /* Prove that you can't query the id of a popup directly (By position) */
1874 id
= GetMenuItemID(hmenu
, 0);
1875 ok (id
== -1, "Getting the sub menu id should have failed because its a popup (gave %x)\n", id
);
1877 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1878 memset( &info
, 0, sizeof info
);
1880 info
.cbSize
= sizeof(MENUITEMINFO
);
1881 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1882 info
.dwTypeData
= strback
;
1883 info
.cch
= sizeof(strback
);
1885 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
);
1886 ok (rc
, "Getting the menus info failed\n");
1887 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for popup menu\n");
1888 ok (!strcmp(info
.dwTypeData
, "MenuItem"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1889 DestroyMenu( hmenu
);
1890 DestroyMenu( hmenuSub
);
1893 Case 4: Menu containing 2 popup menus, the second
1894 contains 2 items with the same id as the first popup menu
1896 hmenu
= CreateMenu();
1897 hmenuSub
= CreateMenu();
1898 hmenuSub2
= CreateMenu();
1900 rc
= InsertMenu(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, "Submenu");
1901 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1903 rc
= InsertMenu(hmenu
, 1, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub2
, "Submenu2");
1904 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1906 memset( &info
, 0, sizeof info
);
1907 info
.cbSize
= sizeof info
;
1908 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1909 info
.fType
= MFT_STRING
;
1910 info
.dwTypeData
= menuitem
;
1911 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1913 rc
= InsertMenuItem(hmenuSub2
, 0, TRUE
, &info
);
1914 ok (rc
, "Inserting the sub menu menuitem failed\n");
1916 memset( &info
, 0, sizeof info
);
1917 info
.cbSize
= sizeof info
;
1918 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1919 info
.fType
= MFT_STRING
;
1920 info
.dwTypeData
= menuitem2
;
1921 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1923 rc
= InsertMenuItem(hmenuSub2
, 1, TRUE
, &info
);
1924 ok (rc
, "Inserting the sub menu menuitem 2 failed\n");
1926 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1927 memset( &info
, 0, sizeof info
);
1929 info
.cbSize
= sizeof(MENUITEMINFO
);
1930 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1931 info
.dwTypeData
= strback
;
1932 info
.cch
= sizeof(strback
);
1934 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
);
1935 ok (rc
, "Getting the menus info failed\n");
1936 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for popup menu\n");
1937 ok (!strcmp(info
.dwTypeData
, "MenuItem"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1939 memset( &info
, 0, sizeof info
);
1941 info
.cbSize
= sizeof(MENUITEMINFO
);
1942 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1943 info
.dwTypeData
= strback
;
1944 info
.cch
= sizeof(strback
);
1946 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub2
, FALSE
, &info
);
1947 ok (rc
, "Getting the menus info failed\n");
1948 ok (info
.wID
== (UINT_PTR
)hmenuSub2
, "IDs differ for popup menu\n");
1949 ok (!strcmp(info
.dwTypeData
, "Submenu2"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1951 DestroyMenu( hmenu
);
1952 DestroyMenu( hmenuSub
);
1953 DestroyMenu( hmenuSub2
);
1957 Case 5: Menu containing a popup menu which in turn
1958 contains an item with a different id than the popup menu.
1959 This tests the fallback to a popup menu ID.
1962 hmenu
= CreateMenu();
1963 hmenuSub
= CreateMenu();
1965 rc
= AppendMenu(hmenu
, MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, "Submenu");
1966 ok (rc
, "Appending the popup menu to the main menu failed\n");
1968 rc
= AppendMenu(hmenuSub
, MF_STRING
, 102, "Item");
1969 ok (rc
, "Appending the item to the popup menu failed\n");
1971 /* Set the ID for hmenuSub */
1972 info
.cbSize
= sizeof(info
);
1973 info
.fMask
= MIIM_ID
;
1976 rc
= SetMenuItemInfo(hmenu
, 0, TRUE
, &info
);
1977 ok(rc
, "Setting the ID for the popup menu failed\n");
1979 /* Check if the ID has been set */
1981 rc
= GetMenuItemInfo(hmenu
, 0, TRUE
, &info
);
1982 ok(rc
, "Getting the ID for the popup menu failed\n");
1983 ok(info
.wID
== 101, "The ID for the popup menu has not been set\n");
1985 /* Prove getting the item info via ID returns the popup menu */
1986 memset( &info
, 0, sizeof(info
));
1988 info
.cbSize
= sizeof(MENUITEMINFO
);
1989 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1990 info
.dwTypeData
= strback
;
1991 info
.cch
= sizeof(strback
);
1993 rc
= GetMenuItemInfo(hmenu
, 101, FALSE
, &info
);
1994 ok (rc
, "Getting the menu info failed\n");
1995 ok (info
.wID
== 101, "IDs differ\n");
1996 ok (!strcmp(info
.dwTypeData
, "Submenu"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1998 /* Also look for the menu item */
1999 memset( &info
, 0, sizeof(info
));
2001 info
.cbSize
= sizeof(MENUITEMINFO
);
2002 info
.fMask
= MIIM_STRING
| MIIM_ID
;
2003 info
.dwTypeData
= strback
;
2004 info
.cch
= sizeof(strback
);
2006 rc
= GetMenuItemInfo(hmenu
, 102, FALSE
, &info
);
2007 ok (rc
, "Getting the menu info failed\n");
2008 ok (info
.wID
== 102, "IDs differ\n");
2009 ok (!strcmp(info
.dwTypeData
, "Item"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
2012 DestroyMenu(hmenuSub
);
2015 struct menu_item_pair_s
{
2016 UINT uMenu
; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
2017 * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
2018 * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
2022 static struct menu_mouse_tests_s
{
2024 struct menu_item_pair_s menu_item_pairs
[5]; /* for mousing */
2025 WORD wVk
[5]; /* keys */
2029 /* for each test, send keys or clicks and check for menu visibility */
2030 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 0}, TRUE
, FALSE
}, /* test 0 */
2031 { INPUT_KEYBOARD
, {{0}}, {VK_ESCAPE
, 0}, FALSE
, FALSE
},
2032 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 0}, TRUE
, FALSE
},
2033 { INPUT_KEYBOARD
, {{0}}, {'D', 0}, FALSE
, FALSE
},
2034 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 0}, TRUE
, FALSE
},
2035 { INPUT_KEYBOARD
, {{0}}, {'E', 0}, FALSE
, FALSE
},
2036 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 0}, TRUE
, FALSE
},
2037 { INPUT_KEYBOARD
, {{0}}, {VK_ESCAPE
, VK_ESCAPE
, 0}, FALSE
, FALSE
},
2038 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', VK_ESCAPE
, 0}, TRUE
, FALSE
},
2039 { INPUT_KEYBOARD
, {{0}}, {VK_ESCAPE
, 0}, FALSE
, FALSE
},
2040 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 0}, TRUE
, FALSE
},
2041 { INPUT_KEYBOARD
, {{0}}, {'D', 0}, FALSE
, FALSE
},
2042 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 0}, TRUE
, FALSE
},
2043 { INPUT_KEYBOARD
, {{0}}, {'E', 0}, FALSE
, FALSE
},
2044 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 'P', 0}, TRUE
, FALSE
},
2045 { INPUT_KEYBOARD
, {{0}}, {'D', 0}, FALSE
, FALSE
},
2046 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 'P', 0}, TRUE
, FALSE
},
2047 { INPUT_KEYBOARD
, {{0}}, {'E', 0}, FALSE
, FALSE
},
2048 { INPUT_KEYBOARD
, {{0}}, {VK_F10
, 0}, TRUE
, FALSE
},
2049 { INPUT_KEYBOARD
, {{0}}, {VK_F10
, 0}, FALSE
, FALSE
},
2051 { INPUT_MOUSE
, {{1, 2}, {0}}, {0}, TRUE
, TRUE
}, /* test 20 */
2052 { INPUT_MOUSE
, {{1, 1}, {0}}, {0}, FALSE
, FALSE
},
2053 { INPUT_MOUSE
, {{1, 0}, {0}}, {0}, TRUE
, TRUE
},
2054 { INPUT_MOUSE
, {{1, 1}, {0}}, {0}, FALSE
, FALSE
},
2055 { INPUT_MOUSE
, {{1, 0}, {2, 2}, {0}}, {0}, TRUE
, TRUE
},
2056 { INPUT_MOUSE
, {{2, 1}, {0}}, {0}, FALSE
, FALSE
},
2057 { INPUT_MOUSE
, {{1, 0}, {2, 0}, {0}}, {0}, TRUE
, TRUE
},
2058 { INPUT_MOUSE
, {{3, 0}, {0}}, {0}, FALSE
, FALSE
},
2059 { INPUT_MOUSE
, {{1, 0}, {2, 0}, {0}}, {0}, TRUE
, TRUE
},
2060 { INPUT_MOUSE
, {{3, 1}, {0}}, {0}, TRUE
, TRUE
},
2061 { INPUT_MOUSE
, {{1, 1}, {0}}, {0}, FALSE
, FALSE
},
2065 static void send_key(WORD wVk
)
2068 memset(i
, 0, sizeof(i
));
2069 i
[0].type
= i
[1].type
= INPUT_KEYBOARD
;
2070 i
[0].u
.ki
.wVk
= i
[1].u
.ki
.wVk
= wVk
;
2071 i
[1].u
.ki
.dwFlags
= KEYEVENTF_KEYUP
;
2072 pSendInput(2, (INPUT
*) i
, sizeof(INPUT
));
2075 static BOOL
click_menu(HANDLE hWnd
, struct menu_item_pair_s
*mi
)
2077 HMENU hMenu
= hMenus
[mi
->uMenu
];
2081 int screen_w
= GetSystemMetrics(SM_CXSCREEN
);
2082 int screen_h
= GetSystemMetrics(SM_CYSCREEN
);
2083 BOOL ret
= GetMenuItemRect(mi
->uMenu
> 2 ? NULL
: hWnd
, hMenu
, mi
->uItem
, &r
);
2084 if(!ret
) return FALSE
;
2086 memset(i
, 0, sizeof(i
));
2087 i
[0].type
= i
[1].type
= i
[2].type
= INPUT_MOUSE
;
2088 i
[0].u
.mi
.dx
= i
[1].u
.mi
.dx
= i
[2].u
.mi
.dx
2089 = ((r
.left
+ 5) * 65535) / screen_w
;
2090 i
[0].u
.mi
.dy
= i
[1].u
.mi
.dy
= i
[2].u
.mi
.dy
2091 = ((r
.top
+ 5) * 65535) / screen_h
;
2092 i
[0].u
.mi
.dwFlags
= i
[1].u
.mi
.dwFlags
= i
[2].u
.mi
.dwFlags
2093 = MOUSEEVENTF_ABSOLUTE
;
2094 i
[0].u
.mi
.dwFlags
|= MOUSEEVENTF_MOVE
;
2095 i
[1].u
.mi
.dwFlags
|= MOUSEEVENTF_LEFTDOWN
;
2096 i
[2].u
.mi
.dwFlags
|= MOUSEEVENTF_LEFTUP
;
2097 ret
= pSendInput(3, (INPUT
*) i
, sizeof(INPUT
));
2099 /* hack to prevent mouse message buildup in Wine */
2100 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
2104 static DWORD WINAPI
test_menu_input_thread(LPVOID lpParameter
)
2107 HANDLE hWnd
= lpParameter
;
2110 /* mixed keyboard/mouse test */
2111 for (i
= 0; menu_tests
[i
].type
!= -1; i
++)
2113 int ret
= TRUE
, elapsed
= 0;
2115 got_input
= i
&& menu_tests
[i
-1].bMenuVisible
;
2117 if (menu_tests
[i
].type
== INPUT_KEYBOARD
)
2118 for (j
= 0; menu_tests
[i
].wVk
[j
] != 0; j
++)
2119 send_key(menu_tests
[i
].wVk
[j
]);
2121 for (j
= 0; menu_tests
[i
].menu_item_pairs
[j
].uMenu
!= 0; j
++)
2122 if (!(ret
= click_menu(hWnd
, &menu_tests
[i
].menu_item_pairs
[j
]))) break;
2126 skip( "test %u: failed to send input\n", i
);
2127 PostMessage( hWnd
, WM_CANCELMODE
, 0, 0 );
2130 while (menu_tests
[i
].bMenuVisible
!= bMenuVisible
)
2140 skip( "test %u: didn't receive input\n", i
);
2141 PostMessage( hWnd
, WM_CANCELMODE
, 0, 0 );
2145 if (menu_tests
[i
]._todo_wine
)
2148 ok(menu_tests
[i
].bMenuVisible
== bMenuVisible
, "test %d\n", i
);
2152 ok(menu_tests
[i
].bMenuVisible
== bMenuVisible
, "test %d\n", i
);
2157 static LRESULT CALLBACK
WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
,
2161 case WM_ENTERMENULOOP
:
2162 bMenuVisible
= TRUE
;
2164 case WM_INITMENUPOPUP
:
2165 case WM_UNINITMENUPOPUP
:
2166 case WM_EXITMENULOOP
:
2173 case WM_LBUTTONDOWN
:
2175 case WM_NCMOUSEMOVE
:
2176 case WM_NCLBUTTONDOWN
:
2177 case WM_NCLBUTTONUP
:
2181 return( DefWindowProcA( hWnd
, msg
, wParam
, lParam
) );
2191 mbi
.cbSize
= sizeof(MENUBARINFO
);
2193 /* get info for the menu */
2194 br
= pGetMenuBarInfo(hWnd
, OBJID_MENU
, 0, &mbi
);
2195 ok(br
, "msg %x: GetMenuBarInfo failed\n", msg
);
2196 hmenu
= GetMenu(hWnd
);
2197 ok(!mbi
.hwndMenu
, "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected NULL\n",
2199 ok(mbi
.hMenu
== hmenu
, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2200 msg
, mbi
.hMenu
, hmenu
);
2201 ok(!bMenuVisible
== !mbi
.fBarFocused
, "msg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2202 msg
, mbi
.fBarFocused
!= 0);
2203 ok(!bMenuVisible
== !mbi
.fFocused
, "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n",
2204 msg
, mbi
.fFocused
!= 0);
2206 /* get info for the menu's first item */
2207 br
= pGetMenuBarInfo(hWnd
, OBJID_MENU
, 1, &mbi
);
2208 ok(br
, "msg %x: GetMenuBarInfo failed\n", msg
);
2209 state
= GetMenuState(hmenu
, 0, MF_BYPOSITION
);
2210 if (pGetMenuInfo
) /* Skip on NT */
2212 /* Native returns handle to destroyed window */
2213 if (msg
==WM_UNINITMENUPOPUP
&& popmenu
==1)
2214 todo_wine
ok(!mbi
.hwndMenu
== !popmenu
,
2215 "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected %sNULL\n",
2216 msg
, mbi
.hwndMenu
, popmenu
? "not " : "");
2218 ok(!mbi
.hwndMenu
== !popmenu
,
2219 "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected %sNULL\n",
2220 msg
, mbi
.hwndMenu
, popmenu
? "not " : "");
2222 ok(mbi
.hMenu
== hmenu
, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2223 msg
, mbi
.hMenu
, hmenu
);
2224 ok(!bMenuVisible
== !mbi
.fBarFocused
, "nsg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2225 msg
, mbi
.fBarFocused
!= 0);
2226 ok(!(bMenuVisible
&& (state
& MF_HILITE
)) == !mbi
.fFocused
,
2227 "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n", msg
, mbi
.fFocused
!= 0);
2230 if (msg
== WM_EXITMENULOOP
)
2231 bMenuVisible
= FALSE
;
2232 else if (msg
== WM_INITMENUPOPUP
)
2234 else if (msg
== WM_UNINITMENUPOPUP
)
2239 static void test_menu_input(void) {
2242 HINSTANCE hInstance
= GetModuleHandleA( NULL
);
2243 HANDLE hThread
, hWnd
;
2249 win_skip("SendInput is not available\n");
2253 wclass
.lpszClassName
= "MenuTestClass";
2254 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
2255 wclass
.lpfnWndProc
= WndProc
;
2256 wclass
.hInstance
= hInstance
;
2257 wclass
.hIcon
= LoadIconA( 0, IDI_APPLICATION
);
2258 wclass
.hCursor
= LoadCursorA( NULL
, IDC_ARROW
);
2259 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
2260 wclass
.lpszMenuName
= 0;
2261 wclass
.cbClsExtra
= 0;
2262 wclass
.cbWndExtra
= 0;
2263 aclass
= RegisterClassA( &wclass
);
2264 ok (aclass
, "MenuTest class not created\n");
2265 if (!aclass
) return;
2266 hWnd
= CreateWindowA( wclass
.lpszClassName
, "MenuTest",
2267 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0,
2268 400, 200, NULL
, NULL
, hInstance
, NULL
);
2269 ok (hWnd
!= NULL
, "MenuTest window not created\n");
2272 hMenus
[3] = CreatePopupMenu();
2273 AppendMenu(hMenus
[3], MF_STRING
, 0, "&Enabled");
2274 AppendMenu(hMenus
[3], MF_STRING
|MF_DISABLED
, 0, "&Disabled");
2276 hMenus
[2] = CreatePopupMenu();
2277 AppendMenu(hMenus
[2], MF_STRING
|MF_POPUP
, (UINT_PTR
) hMenus
[3], "&Popup");
2278 AppendMenu(hMenus
[2], MF_STRING
, 0, "&Enabled");
2279 AppendMenu(hMenus
[2], MF_STRING
|MF_DISABLED
, 0, "&Disabled");
2281 hMenus
[1] = CreateMenu();
2282 AppendMenu(hMenus
[1], MF_STRING
|MF_POPUP
, (UINT_PTR
) hMenus
[2], "&Menu");
2283 AppendMenu(hMenus
[1], MF_STRING
, 0, "&Enabled");
2284 AppendMenu(hMenus
[1], MF_STRING
|MF_DISABLED
, 0, "&Disabled");
2286 SetMenu(hWnd
, hMenus
[1]);
2287 ShowWindow(hWnd
, SW_SHOW
);
2290 hThread
= CreateThread(NULL
, 0, test_menu_input_thread
, hWnd
, 0, &tid
);
2293 if (WAIT_TIMEOUT
!= WaitForSingleObject(hThread
, 50))
2295 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2297 DestroyWindow(hWnd
);
2300 static void test_menu_flags( void )
2302 HMENU hMenu
, hPopupMenu
;
2304 hMenu
= CreateMenu();
2305 hPopupMenu
= CreatePopupMenu();
2307 AppendMenu(hMenu
, MF_POPUP
| MF_STRING
, (UINT_PTR
)hPopupMenu
, "Popup");
2309 AppendMenu(hPopupMenu
, MF_STRING
| MF_HILITE
| MF_DEFAULT
, 101, "Item 1");
2310 InsertMenu(hPopupMenu
, 1, MF_BYPOSITION
| MF_STRING
| MF_HILITE
| MF_DEFAULT
, 102, "Item 2");
2311 AppendMenu(hPopupMenu
, MF_STRING
, 103, "Item 3");
2312 ModifyMenu(hPopupMenu
, 2, MF_BYPOSITION
| MF_STRING
| MF_HILITE
| MF_DEFAULT
, 103, "Item 3");
2314 ok(GetMenuState(hPopupMenu
, 0, MF_BYPOSITION
) & MF_HILITE
,
2315 "AppendMenu should accept MF_HILITE\n");
2316 ok(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
,
2317 "InsertMenu should accept MF_HILITE\n");
2318 ok(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_HILITE
,
2319 "ModifyMenu should accept MF_HILITE\n");
2321 ok(!(GetMenuState(hPopupMenu
, 0, MF_BYPOSITION
) & MF_DEFAULT
),
2322 "AppendMenu must not accept MF_DEFAULT\n");
2323 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_DEFAULT
),
2324 "InsertMenu must not accept MF_DEFAULT\n");
2325 ok(!(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_DEFAULT
),
2326 "ModifyMenu must not accept MF_DEFAULT\n");
2331 static void test_menu_hilitemenuitem( void )
2333 HMENU hMenu
, hPopupMenu
;
2338 wclass
.lpszClassName
= "HiliteMenuTestClass";
2339 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
2340 wclass
.lpfnWndProc
= WndProc
;
2341 wclass
.hInstance
= GetModuleHandleA( NULL
);
2342 wclass
.hIcon
= LoadIconA( 0, IDI_APPLICATION
);
2343 wclass
.hCursor
= LoadCursorA( NULL
, IDC_ARROW
);
2344 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
2345 wclass
.lpszMenuName
= 0;
2346 wclass
.cbClsExtra
= 0;
2347 wclass
.cbWndExtra
= 0;
2348 aclass
= RegisterClassA( &wclass
);
2349 ok (aclass
, "HiliteMenuTest class could not be created\n");
2350 if (!aclass
) return;
2351 hWnd
= CreateWindowA( wclass
.lpszClassName
, "HiliteMenuTest",
2352 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0,
2353 400, 200, NULL
, NULL
, wclass
.hInstance
, NULL
);
2354 ok (hWnd
!= NULL
, "HiliteMenuTest window could not be created\n");
2357 hMenu
= CreateMenu();
2358 hPopupMenu
= CreatePopupMenu();
2360 AppendMenu(hMenu
, MF_POPUP
| MF_STRING
, (UINT_PTR
)hPopupMenu
, "Popup");
2362 AppendMenu(hPopupMenu
, MF_STRING
, 101, "Item 1");
2363 AppendMenu(hPopupMenu
, MF_STRING
, 102, "Item 2");
2364 AppendMenu(hPopupMenu
, MF_STRING
, 103, "Item 3");
2366 SetMenu(hWnd
, hMenu
);
2368 /* test invalid arguments */
2370 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2371 "HiliteMenuItem: Item 2 is hilited\n");
2373 SetLastError(0xdeadbeef);
2376 ok(!HiliteMenuItem(NULL
, hPopupMenu
, 1, MF_HILITE
| MF_BYPOSITION
),
2377 "HiliteMenuItem: call should have failed.\n");
2379 ok(GetLastError() == 0xdeadbeef || /* 9x */
2380 GetLastError() == ERROR_INVALID_WINDOW_HANDLE
/* NT */,
2381 "HiliteMenuItem: expected error ERROR_INVALID_WINDOW_HANDLE, got: %d\n", GetLastError());
2383 SetLastError(0xdeadbeef);
2384 ok(!HiliteMenuItem(hWnd
, NULL
, 1, MF_HILITE
| MF_BYPOSITION
),
2385 "HiliteMenuItem: call should have failed.\n");
2386 ok(GetLastError() == 0xdeadbeef || /* 9x */
2387 GetLastError() == ERROR_INVALID_MENU_HANDLE
/* NT */,
2388 "HiliteMenuItem: expected error ERROR_INVALID_MENU_HANDLE, got: %d\n", GetLastError());
2390 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2391 "HiliteMenuItem: Item 2 is hilited\n");
2393 /* either MF_HILITE or MF_UNHILITE *and* MF_BYCOMMAND or MF_BYPOSITION need to be set */
2395 SetLastError(0xdeadbeef);
2396 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_BYPOSITION
),
2397 "HiliteMenuItem: call should have succeeded.\n");
2398 ok(GetLastError() == 0xdeadbeef,
2399 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2401 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2402 "HiliteMenuItem: Item 2 is hilited\n");
2404 SetLastError(0xdeadbeef);
2407 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_HILITE
),
2408 "HiliteMenuItem: call should have succeeded.\n");
2410 ok(GetLastError() == 0xdeadbeef,
2411 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2413 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2414 "HiliteMenuItem: Item 2 is hilited\n");
2416 /* hilite a menu item (by position) */
2418 SetLastError(0xdeadbeef);
2419 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_HILITE
| MF_BYPOSITION
),
2420 "HiliteMenuItem: call should not have failed.\n");
2421 ok(GetLastError() == 0xdeadbeef,
2422 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2426 ok(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
,
2427 "HiliteMenuItem: Item 2 is not hilited\n");
2430 /* unhilite a menu item (by position) */
2432 SetLastError(0xdeadbeef);
2433 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_UNHILITE
| MF_BYPOSITION
),
2434 "HiliteMenuItem: call should not have failed.\n");
2435 ok(GetLastError() == 0xdeadbeef,
2436 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2438 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2439 "HiliteMenuItem: Item 2 is hilited\n");
2441 /* hilite a menu item (by command) */
2443 SetLastError(0xdeadbeef);
2444 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 103, MF_HILITE
| MF_BYCOMMAND
),
2445 "HiliteMenuItem: call should not have failed.\n");
2446 ok(GetLastError() == 0xdeadbeef,
2447 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2451 ok(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_HILITE
,
2452 "HiliteMenuItem: Item 3 is not hilited\n");
2455 /* unhilite a menu item (by command) */
2457 SetLastError(0xdeadbeef);
2458 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 103, MF_UNHILITE
| MF_BYCOMMAND
),
2459 "HiliteMenuItem: call should not have failed.\n");
2460 ok(GetLastError() == 0xdeadbeef,
2461 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2463 ok(!(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_HILITE
),
2464 "HiliteMenuItem: Item 3 is hilited\n");
2466 DestroyWindow(hWnd
);
2469 static void check_menu_items(HMENU hmenu
, UINT checked_cmd
, UINT checked_type
,
2474 count
= GetMenuItemCount(hmenu
);
2475 ok (count
!= -1, "GetMenuItemCount returned -1\n");
2477 for (i
= 0; i
< count
; i
++)
2482 memset(&mii
, 0, sizeof(mii
));
2483 mii
.cbSize
= sizeof(mii
);
2484 mii
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_ID
| MIIM_SUBMENU
;
2485 ret
= GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
);
2486 ok(ret
, "GetMenuItemInfo(%u) failed\n", i
);
2488 trace("item #%u: fType %04x, fState %04x, wID %u, hSubMenu %p\n",
2489 i
, mii
.fType
, mii
.fState
, mii
.wID
, mii
.hSubMenu
);
2493 ok(mii
.wID
== (UINT_PTR
)mii
.hSubMenu
, "id %u: wID should be equal to hSubMenu\n", checked_cmd
);
2494 check_menu_items(mii
.hSubMenu
, checked_cmd
, checked_type
, checked_state
);
2498 if (mii
.wID
== checked_cmd
)
2500 ok(mii
.fType
== checked_type
, "id %u: expected fType %04x, got %04x\n", checked_cmd
, checked_type
, mii
.fType
);
2501 ok(mii
.fState
== checked_state
, "id %u: expected fState %04x, got %04x\n", checked_cmd
, checked_state
, mii
.fState
);
2502 ok(mii
.wID
!= 0, "id %u: not expected wID 0\n", checked_cmd
);
2506 ok(mii
.fType
!= MFT_RADIOCHECK
, "id %u: not expected fType MFT_RADIOCHECK on cmd %u\n", checked_cmd
, mii
.wID
);
2508 if (mii
.fType
== MFT_SEPARATOR
)
2510 ok(mii
.fState
== MFS_GRAYED
, "id %u: expected fState MFS_GRAYED, got %04x\n", checked_cmd
, mii
.fState
);
2511 ok(mii
.wID
== 0, "id %u: expected wID 0, got %u\n", checked_cmd
, mii
.wID
);
2515 ok(mii
.fState
== 0, "id %u: expected fState 0, got %04x\n", checked_cmd
, mii
.fState
);
2516 ok(mii
.wID
!= 0, "id %u: not expected wID 0\n", checked_cmd
);
2523 static void clear_ftype_and_state(HMENU hmenu
, UINT id
, UINT flags
)
2528 memset(&mii
, 0, sizeof(mii
));
2529 mii
.cbSize
= sizeof(mii
);
2530 mii
.fMask
= MIIM_FTYPE
| MIIM_STATE
;
2531 ret
= SetMenuItemInfo(hmenu
, id
, (flags
& MF_BYPOSITION
) != 0, &mii
);
2532 ok(ret
, "SetMenuItemInfo(%u) failed\n", id
);
2535 static void test_CheckMenuRadioItem(void)
2540 hmenu
= LoadMenu(GetModuleHandle(0), MAKEINTRESOURCE(1));
2543 check_menu_items(hmenu
, -1, 0, 0);
2545 ret
= CheckMenuRadioItem(hmenu
, 100, 100, 100, MF_BYCOMMAND
);
2546 ok(ret
, "CheckMenuRadioItem failed\n");
2547 check_menu_items(hmenu
, 100, MFT_RADIOCHECK
, MFS_CHECKED
);
2549 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2550 ret
= CheckMenuRadioItem(hmenu
, 100, 100, -1, MF_BYCOMMAND
);
2551 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2552 check_menu_items(hmenu
, 100, MFT_RADIOCHECK
, 0);
2555 clear_ftype_and_state(hmenu
, 100, MF_BYCOMMAND
);
2556 check_menu_items(hmenu
, -1, 0, 0);
2558 /* first and checked items are on different menus */
2559 ret
= CheckMenuRadioItem(hmenu
, 0, 300, 202, MF_BYCOMMAND
);
2560 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2561 check_menu_items(hmenu
, -1, 0, 0);
2563 ret
= CheckMenuRadioItem(hmenu
, 200, 300, 202, MF_BYCOMMAND
);
2564 ok(ret
, "CheckMenuRadioItem failed\n");
2565 check_menu_items(hmenu
, 202, MFT_RADIOCHECK
, MFS_CHECKED
);
2567 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2568 ret
= CheckMenuRadioItem(hmenu
, 202, 202, -1, MF_BYCOMMAND
);
2569 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2570 check_menu_items(hmenu
, 202, MFT_RADIOCHECK
, 0);
2573 clear_ftype_and_state(hmenu
, 202, MF_BYCOMMAND
);
2574 check_menu_items(hmenu
, -1, 0, 0);
2576 /* just for fun, try to check separator */
2577 ret
= CheckMenuRadioItem(hmenu
, 0, 300, 0, MF_BYCOMMAND
);
2578 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2579 check_menu_items(hmenu
, -1, 0, 0);
2582 static void test_menu_resource_layout(void)
2586 MENUITEMTEMPLATEHEADER mith
;
2590 { 0, 0 }, /* versionNumber, offset */
2592 /* mtOption, mtID, mtString[] '\0' terminated */
2593 MF_STRING
, 1, 'F', 0,
2596 /* MF_SEPARATOR, 4, 'S', 0, FIXME: Wine ignores 'S' */
2597 MF_STRING
|MF_GRAYED
|MF_END
, 5, 'E', 0
2602 UINT type
, state
, id
;
2606 { MF_STRING
, MF_ENABLED
, 1, "F" },
2607 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 2, "" },
2608 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 3, "" },
2609 /*{ MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 4, "S" }, FIXME: Wine ignores 'S'*/
2610 { MF_STRING
, MF_GRAYED
, 5, "E" },
2611 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 6, "" },
2612 { MF_STRING
, MF_ENABLED
, 7, "" },
2613 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 8, "" }
2619 hmenu
= LoadMenuIndirect(&menu_template
);
2620 ok(hmenu
!= 0, "LoadMenuIndirect error %u\n", GetLastError());
2622 ret
= AppendMenu(hmenu
, MF_STRING
, 6, NULL
);
2623 ok(ret
, "AppendMenu failed\n");
2624 ret
= AppendMenu(hmenu
, MF_STRING
, 7, "\0");
2625 ok(ret
, "AppendMenu failed\n");
2626 ret
= AppendMenu(hmenu
, MF_SEPARATOR
, 8, "separator");
2627 ok(ret
, "AppendMenu failed\n");
2629 count
= GetMenuItemCount(hmenu
);
2630 ok(count
== sizeof(menu_data
)/sizeof(menu_data
[0]),
2631 "expected %u menu items, got %u\n",
2632 (UINT
)(sizeof(menu_data
)/sizeof(menu_data
[0])), count
);
2634 for (i
= 0; i
< count
; i
++)
2639 memset(&mii
, 0, sizeof(mii
));
2640 mii
.cbSize
= sizeof(mii
);
2641 mii
.dwTypeData
= buf
;
2642 mii
.cch
= sizeof(buf
);
2643 mii
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_ID
| MIIM_STRING
;
2644 ret
= GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
);
2645 ok(ret
, "GetMenuItemInfo(%u) failed\n", i
);
2647 trace("item #%u: fType %04x, fState %04x, wID %u, dwTypeData %s\n",
2648 i
, mii
.fType
, mii
.fState
, mii
.wID
, (LPCSTR
)mii
.dwTypeData
);
2650 ok(mii
.fType
== menu_data
[i
].type
,
2651 "%u: expected fType %04x, got %04x\n", i
, menu_data
[i
].type
, mii
.fType
);
2652 ok(mii
.fState
== menu_data
[i
].state
,
2653 "%u: expected fState %04x, got %04x\n", i
, menu_data
[i
].state
, mii
.fState
);
2654 ok(mii
.wID
== menu_data
[i
].id
,
2655 "%u: expected wID %04x, got %04x\n", i
, menu_data
[i
].id
, mii
.wID
);
2656 ok(mii
.cch
== strlen(menu_data
[i
].str
),
2657 "%u: expected cch %u, got %u\n", i
, (UINT
)strlen(menu_data
[i
].str
), mii
.cch
);
2658 ok(!strcmp(mii
.dwTypeData
, menu_data
[i
].str
),
2659 "%u: expected dwTypeData %s, got %s\n", i
, menu_data
[i
].str
, (LPCSTR
)mii
.dwTypeData
);
2671 static HMENU
create_menu_from_data(const struct menu_data
*item
, INT item_count
)
2677 hmenu
= CreateMenu();
2680 for (i
= 0; i
< item_count
; i
++)
2682 SetLastError(0xdeadbeef);
2683 ret
= AppendMenu(hmenu
, item
[i
].type
, item
[i
].id
, item
[i
].str
);
2684 ok(ret
, "%d: AppendMenu(%04x, %04x, %p) error %u\n",
2685 i
, item
[i
].type
, item
[i
].id
, item
[i
].str
, GetLastError());
2690 /* use InsertMenuItem: does not set the MFT_BITMAP flag,
2691 * and does not accept non-magic bitmaps with invalid
2693 static HMENU
create_menuitem_from_data(const struct menu_data
*item
, INT item_count
)
2698 MENUITEMINFO mii
= { sizeof( MENUITEMINFO
)};
2700 hmenu
= CreateMenu();
2703 for (i
= 0; i
< item_count
; i
++)
2705 SetLastError(0xdeadbeef);
2707 mii
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STATE
;
2709 if( item
[i
].type
& MFT_BITMAP
)
2711 mii
.fMask
|= MIIM_BITMAP
;
2712 mii
.hbmpItem
= (HBITMAP
)item
[i
].str
;
2714 else if( item
[i
].type
& MFT_SEPARATOR
)
2715 mii
.fType
= MFT_SEPARATOR
;
2718 mii
.fMask
|= MIIM_STRING
;
2719 mii
.dwTypeData
= (LPSTR
)item
[i
].str
;
2720 mii
.cch
= strlen( item
[i
].str
);
2723 if( item
[i
].type
& MF_HELP
) mii
.fType
|= MF_HELP
;
2724 mii
.wID
= item
[i
].id
;
2725 ret
= InsertMenuItem( hmenu
, -1, TRUE
, &mii
);
2726 ok(ret
, "%d: InsertMenuItem(%04x, %04x, %p) error %u\n",
2727 i
, item
[i
].type
, item
[i
].id
, item
[i
].str
, GetLastError());
2732 static void compare_menu_data(HMENU hmenu
, const struct menu_data
*item
, INT item_count
)
2737 count
= GetMenuItemCount(hmenu
);
2738 ok(count
== item_count
, "expected %d, got %d menu items\n", count
, item_count
);
2740 for (i
= 0; i
< count
; i
++)
2745 memset(&mii
, 0, sizeof(mii
));
2746 mii
.cbSize
= sizeof(mii
);
2747 mii
.dwTypeData
= buf
;
2748 mii
.cch
= sizeof(buf
);
2749 mii
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
| MIIM_BITMAP
;
2750 ret
= GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
);
2751 ok(ret
, "GetMenuItemInfo(%u) failed\n", i
);
2753 trace("item #%u: fType %04x, fState %04x, wID %04x, hbmp %p\n",
2754 i
, mii
.fType
, mii
.fState
, mii
.wID
, mii
.hbmpItem
);
2756 ok(mii
.fType
== item
[i
].type
,
2757 "%u: expected fType %04x, got %04x\n", i
, item
[i
].type
, mii
.fType
);
2758 ok(mii
.wID
== item
[i
].id
,
2759 "%u: expected wID %04x, got %04x\n", i
, item
[i
].id
, mii
.wID
);
2760 if (mii
.hbmpItem
|| !item
[i
].str
)
2761 /* For some reason Windows sets high word to not 0 for
2764 ok(LOWORD(mii
.hbmpItem
) == LOWORD(item
[i
].str
),
2765 "%u: expected hbmpItem %p, got %p\n", i
, item
[i
].str
, mii
.hbmpItem
);
2768 ok(mii
.cch
== strlen(item
[i
].str
),
2769 "%u: expected cch %u, got %u\n", i
, (UINT
)strlen(item
[i
].str
), mii
.cch
);
2770 ok(!strcmp(mii
.dwTypeData
, item
[i
].str
),
2771 "%u: expected dwTypeData %s, got %s\n", i
, item
[i
].str
, (LPCSTR
)mii
.dwTypeData
);
2776 static void test_InsertMenu(void)
2778 HBITMAP hbm
= CreateBitmap(1,1,1,1,NULL
);
2779 /* Note: XP treats only bitmap handles 1 - 6 as "magic" ones
2780 * regardless of their id.
2782 static const struct menu_data in1
[] =
2784 { MF_STRING
, 1, "File" },
2785 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(1) },
2786 { MF_STRING
|MF_HELP
, 2, "Help" }
2788 static const struct menu_data out1
[] =
2790 { MF_STRING
, 1, "File" },
2791 { MF_STRING
|MF_HELP
, 2, "Help" },
2792 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(1) }
2794 static const struct menu_data out1a
[] =
2796 { MF_STRING
, 1, "File" },
2797 { MF_STRING
|MF_HELP
, 2, "Help" },
2798 { MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(1) }
2800 const struct menu_data in2
[] =
2802 { MF_STRING
, 1, "File" },
2803 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, (char*)hbm
},
2804 { MF_STRING
|MF_HELP
, 2, "Help" }
2806 const struct menu_data out2
[] =
2808 { MF_STRING
, 1, "File" },
2809 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, (char*)hbm
},
2810 { MF_STRING
|MF_HELP
, 2, "Help" }
2812 const struct menu_data out2a
[] =
2814 { MF_STRING
, 1, "File" },
2815 { MF_HELP
, SC_CLOSE
, (char*)hbm
},
2816 { MF_STRING
|MF_HELP
, 2, "Help" }
2818 static const struct menu_data in3
[] =
2820 { MF_STRING
, 1, "File" },
2821 { MF_SEPARATOR
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(1) },
2822 { MF_STRING
|MF_HELP
, 2, "Help" }
2824 static const struct menu_data out3
[] =
2826 { MF_STRING
, 1, "File" },
2827 { MF_SEPARATOR
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(0) },
2828 { MF_STRING
|MF_HELP
, 2, "Help" },
2830 static const struct menu_data in4
[] =
2832 { MF_STRING
, 1, "File" },
2833 { MF_BITMAP
|MF_HELP
, 1, MAKEINTRESOURCE(1) },
2834 { MF_STRING
|MF_HELP
, 2, "Help" }
2836 static const struct menu_data out4
[] =
2838 { MF_STRING
, 1, "File" },
2839 { MF_STRING
|MF_HELP
, 2, "Help" },
2840 { MF_BITMAP
|MF_HELP
, 1, MAKEINTRESOURCE(1) }
2842 static const struct menu_data out4a
[] =
2844 { MF_STRING
, 1, "File" },
2845 { MF_STRING
|MF_HELP
, 2, "Help" },
2846 { MF_HELP
, 1, MAKEINTRESOURCE(1) }
2850 #define create_menu(a) create_menu_from_data((a), sizeof(a)/sizeof((a)[0]))
2851 #define create_menuitem(a) create_menuitem_from_data((a), sizeof(a)/sizeof((a)[0]))
2852 #define compare_menu(h, a) compare_menu_data((h), (a), sizeof(a)/sizeof((a)[0]))
2854 hmenu
= create_menu(in1
);
2855 compare_menu(hmenu
, out1
);
2858 hmenu
= create_menu(in2
);
2859 compare_menu(hmenu
, out2
);
2862 hmenu
= create_menu(in3
);
2863 compare_menu(hmenu
, out3
);
2866 hmenu
= create_menu(in4
);
2867 compare_menu(hmenu
, out4
);
2870 /* now using InsertMenuItemInfo */
2871 hmenu
= create_menuitem(in1
);
2872 compare_menu(hmenu
, out1a
);
2875 hmenu
= create_menuitem(in2
);
2876 compare_menu(hmenu
, out2a
);
2879 hmenu
= create_menuitem(in3
);
2880 compare_menu(hmenu
, out3
);
2883 hmenu
= create_menuitem(in4
);
2884 compare_menu(hmenu
, out4a
);
2888 #undef create_menuitem
2892 static void test_menu_getmenuinfo(void)
2901 win_skip("GetMenuInfo is not available\n");
2906 hmenu
= CreateMenu();
2908 /* test some parameter errors */
2909 SetLastError(0xdeadbeef);
2910 ret
= pGetMenuInfo( hmenu
, NULL
);
2911 gle
= GetLastError();
2912 ok( !ret
, "GetMenuInfo() should have failed\n");
2913 ok( gle
== ERROR_INVALID_PARAMETER
||
2914 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2915 "GetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2916 SetLastError(0xdeadbeef);
2918 ret
= pGetMenuInfo( hmenu
, &mi
);
2919 gle
= GetLastError();
2920 ok( !ret
, "GetMenuInfo() should have failed\n");
2921 ok( gle
== ERROR_INVALID_PARAMETER
||
2922 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2923 "GetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2924 SetLastError(0xdeadbeef);
2925 mi
.cbSize
= sizeof( MENUINFO
);
2926 ret
= pGetMenuInfo( hmenu
, &mi
);
2927 gle
= GetLastError();
2928 ok( ret
, "GetMenuInfo() should have succeeded\n");
2929 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2930 SetLastError(0xdeadbeef);
2932 ret
= pGetMenuInfo( NULL
, &mi
);
2933 gle
= GetLastError();
2934 ok( !ret
, "GetMenuInfo() should have failed\n");
2935 ok( gle
== ERROR_INVALID_PARAMETER
||
2936 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2937 "GetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2939 DestroyMenu( hmenu
);
2943 static void test_menu_setmenuinfo(void)
2945 HMENU hmenu
, hsubmenu
;
2947 MENUITEMINFOA mii
= {sizeof( MENUITEMINFOA
)};
2951 if (!pGetMenuInfo
|| !pSetMenuInfo
)
2953 win_skip("Get/SetMenuInfo are not available\n");
2957 /* create a menu with a submenu */
2958 hmenu
= CreateMenu();
2959 hsubmenu
= CreateMenu();
2960 assert( hmenu
&& hsubmenu
);
2961 mii
.fMask
= MIIM_SUBMENU
;
2962 mii
.hSubMenu
= hsubmenu
;
2963 ret
= InsertMenuItem( hmenu
, 0, FALSE
, &mii
);
2964 ok( ret
, "InsertMenuItem failed with error %d\n", GetLastError());
2965 /* test some parameter errors */
2966 SetLastError(0xdeadbeef);
2967 ret
= pSetMenuInfo( hmenu
, NULL
);
2968 gle
= GetLastError();
2969 ok( !ret
, "SetMenuInfo() should have failed\n");
2970 ok( gle
== ERROR_INVALID_PARAMETER
||
2971 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2972 "SetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2973 SetLastError(0xdeadbeef);
2975 ret
= pSetMenuInfo( hmenu
, &mi
);
2976 gle
= GetLastError();
2977 ok( !ret
, "SetMenuInfo() should have failed\n");
2978 ok( gle
== ERROR_INVALID_PARAMETER
||
2979 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2980 "SetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2981 SetLastError(0xdeadbeef);
2982 mi
.cbSize
= sizeof( MENUINFO
);
2983 ret
= pSetMenuInfo( hmenu
, &mi
);
2984 gle
= GetLastError();
2985 ok( ret
, "SetMenuInfo() should have succeeded\n");
2986 ok( gle
== 0xdeadbeef, "SetMenuInfo() error got %u\n", gle
);
2987 SetLastError(0xdeadbeef);
2989 ret
= pSetMenuInfo( NULL
, &mi
);
2990 gle
= GetLastError();
2991 ok( !ret
, "SetMenuInfo() should have failed\n");
2992 ok( gle
== ERROR_INVALID_PARAMETER
||
2993 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2994 "SetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2995 /* functional tests */
2996 /* menu and submenu should have the CHECKORBMP style bit cleared */
2997 SetLastError(0xdeadbeef);
2998 mi
.cbSize
= sizeof( MENUINFO
);
2999 mi
.fMask
= MIM_STYLE
;
3000 ret
= pGetMenuInfo( hmenu
, &mi
);
3001 gle
= GetLastError();
3002 ok( ret
, "GetMenuInfo() should have succeeded\n");
3003 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
3004 ok( !(mi
.dwStyle
& MNS_CHECKORBMP
), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
3005 SetLastError(0xdeadbeef);
3006 mi
.cbSize
= sizeof( MENUINFO
);
3007 mi
.fMask
= MIM_STYLE
;
3008 ret
= pGetMenuInfo( hsubmenu
, &mi
);
3009 gle
= GetLastError();
3010 ok( ret
, "GetMenuInfo() should have succeeded\n");
3011 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
3012 ok( !(mi
.dwStyle
& MNS_CHECKORBMP
), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
3014 SetLastError(0xdeadbeef);
3015 mi
.cbSize
= sizeof( MENUINFO
);
3016 mi
.fMask
= MIM_STYLE
| MIM_APPLYTOSUBMENUS
;
3017 mi
.dwStyle
= MNS_CHECKORBMP
;
3018 ret
= pSetMenuInfo( hmenu
, &mi
);
3019 gle
= GetLastError();
3020 ok( ret
, "SetMenuInfo() should have succeeded\n");
3021 ok( gle
== 0xdeadbeef, "SetMenuInfo() error got %u\n", gle
);
3022 /* Now both menus should have the MNS_CHECKORBMP style bit set */
3023 SetLastError(0xdeadbeef);
3024 mi
.cbSize
= sizeof( MENUINFO
);
3025 mi
.fMask
= MIM_STYLE
;
3026 ret
= pGetMenuInfo( hmenu
, &mi
);
3027 gle
= GetLastError();
3028 ok( ret
, "GetMenuInfo() should have succeeded\n");
3029 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
3030 ok( mi
.dwStyle
& MNS_CHECKORBMP
, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
3031 SetLastError(0xdeadbeef);
3032 mi
.cbSize
= sizeof( MENUINFO
);
3033 mi
.fMask
= MIM_STYLE
;
3034 ret
= pGetMenuInfo( hsubmenu
, &mi
);
3035 gle
= GetLastError();
3036 ok( ret
, "GetMenuInfo() should have succeeded\n");
3037 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
3038 ok( mi
.dwStyle
& MNS_CHECKORBMP
, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
3039 /* now repeat that without the APPLYTOSUBMENUS flag and another style bit */
3040 SetLastError(0xdeadbeef);
3041 mi
.cbSize
= sizeof( MENUINFO
);
3042 mi
.fMask
= MIM_STYLE
;
3043 mi
.dwStyle
= MNS_NOCHECK
;
3044 ret
= pSetMenuInfo( hmenu
, &mi
);
3045 gle
= GetLastError();
3046 ok( ret
, "SetMenuInfo() should have succeeded\n");
3047 ok( gle
== 0xdeadbeef, "SetMenuInfo() error got %u\n", gle
);
3048 /* Now only the top menu should have the MNS_NOCHECK style bit set */
3049 SetLastError(0xdeadbeef);
3050 mi
.cbSize
= sizeof( MENUINFO
);
3051 mi
.fMask
= MIM_STYLE
;
3052 ret
= pGetMenuInfo( hmenu
, &mi
);
3053 gle
= GetLastError();
3054 ok( ret
, "GetMenuInfo() should have succeeded\n");
3055 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
3056 ok( mi
.dwStyle
& MNS_NOCHECK
, "menustyle was expected to have the MNS_NOCHECK flag\n");
3057 SetLastError(0xdeadbeef);
3058 mi
.cbSize
= sizeof( MENUINFO
);
3059 mi
.fMask
= MIM_STYLE
;
3060 ret
= pGetMenuInfo( hsubmenu
, &mi
);
3061 gle
= GetLastError();
3062 ok( ret
, "GetMenuInfo() should have succeeded\n");
3063 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
3064 ok( !(mi
.dwStyle
& MNS_NOCHECK
), "menustyle was not expected to have the MNS_NOCHECK flag\n");
3066 DestroyMenu( hsubmenu
);
3067 DestroyMenu( hmenu
);
3071 /* little func to easy switch either TrackPopupMenu() or TrackPopupMenuEx() */
3072 static DWORD
MyTrackPopupMenu( int ex
, HMENU hmenu
, UINT flags
, INT x
, INT y
, HWND hwnd
, LPTPMPARAMS ptpm
)
3075 ? TrackPopupMenuEx( hmenu
, flags
, x
, y
, hwnd
, ptpm
)
3076 : TrackPopupMenu( hmenu
, flags
, x
, y
, 0, hwnd
, NULL
);
3079 /* some TrackPopupMenu and TrackPopupMenuEx tests */
3080 /* the LastError values differ between NO_ERROR and invalid handle */
3081 /* between all windows versions tested. The first value is that valid on XP */
3082 /* Vista was the only that made returned different error values */
3083 /* between the TrackPopupMenu and TrackPopupMenuEx functions */
3084 static void test_menu_trackpopupmenu(void)
3090 HWND hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
3091 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
3092 NULL
, NULL
, NULL
, NULL
);
3093 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
3095 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_ownerdraw_wnd_proc
);
3096 for( Ex
= 0; Ex
< 2; Ex
++)
3098 hmenu
= CreatePopupMenu();
3099 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
3102 DestroyWindow(hwnd
);
3105 /* display the menu */
3106 /* start with an invalid menu handle */
3107 SetLastError(0xdeadbeef);
3109 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= 0;
3110 ret
= MyTrackPopupMenu( Ex
, NULL
, TPM_RETURNCMD
, 100,100, hwnd
, NULL
);
3111 gle
= GetLastError();
3112 ok( !ret
, "TrackPopupMenu%s should have failed\n", Ex
? "Ex" : "");
3113 ok( gle
== ERROR_INVALID_MENU_HANDLE
3114 || broken (gle
== 0xdeadbeef) /* win95 */
3115 || broken (gle
== NO_ERROR
) /* win98/ME */
3116 ,"TrackPopupMenu%s error got %u expected %u\n",
3117 Ex
? "Ex" : "", gle
, ERROR_INVALID_MENU_HANDLE
);
3118 ok( !(gflag_initmenupopup
|| gflag_entermenuloop
|| gflag_initmenu
),
3119 "got unexpected message(s)%s%s%s\n",
3120 gflag_initmenupopup
? " WM_INITMENUPOPUP ": " ",
3121 gflag_entermenuloop
? "WM_INITMENULOOP ": "",
3122 gflag_initmenu
? "WM_INITMENU": "");
3123 /* another one but not NULL */
3124 SetLastError(0xdeadbeef);
3125 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= 0;
3126 ret
= MyTrackPopupMenu( Ex
, (HMENU
)hwnd
, TPM_RETURNCMD
, 100,100, hwnd
, NULL
);
3127 gle
= GetLastError();
3128 ok( !ret
, "TrackPopupMenu%s should have failed\n", Ex
? "Ex" : "");
3129 ok( gle
== ERROR_INVALID_MENU_HANDLE
3130 || broken (gle
== 0xdeadbeef) /* win95 */
3131 || broken (gle
== NO_ERROR
) /* win98/ME */
3132 ,"TrackPopupMenu%s error got %u expected %u\n",
3133 Ex
? "Ex" : "", gle
, ERROR_INVALID_MENU_HANDLE
);
3134 ok( !(gflag_initmenupopup
|| gflag_entermenuloop
|| gflag_initmenu
),
3135 "got unexpected message(s)%s%s%s\n",
3136 gflag_initmenupopup
? " WM_INITMENUPOPUP ": " ",
3137 gflag_entermenuloop
? "WM_INITMENULOOP ": "",
3138 gflag_initmenu
? "WM_INITMENU": "");
3140 /* invalid window */
3141 SetLastError(0xdeadbeef);
3142 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= 0;
3143 ret
= MyTrackPopupMenu( Ex
, hmenu
, TPM_RETURNCMD
, 100,100, 0, NULL
);
3144 gle
= GetLastError();
3145 ok( !ret
, "TrackPopupMenu%s should have failed\n", Ex
? "Ex" : "");
3146 ok( gle
== ERROR_INVALID_WINDOW_HANDLE
, "TrackPopupMenu%s error got %u\n", Ex
? "Ex" : "", gle
);
3147 ok( !(gflag_initmenupopup
|| gflag_entermenuloop
|| gflag_initmenu
),
3148 "got unexpected message(s)%s%s%s\n",
3149 gflag_initmenupopup
? " WM_INITMENUPOPUP ": " ",
3150 gflag_entermenuloop
? "WM_INITMENULOOP ": "",
3151 gflag_initmenu
? "WM_INITMENU": "");
3153 /* now a somewhat successful call */
3154 SetLastError(0xdeadbeef);
3155 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= 0;
3156 ret
= MyTrackPopupMenu( Ex
, hmenu
, TPM_RETURNCMD
, 100,100, hwnd
, NULL
);
3157 gle
= GetLastError();
3158 ok( ret
== 0, "TrackPopupMenu%s returned %d expected zero\n", Ex
? "Ex" : "", ret
);
3160 || gle
== ERROR_INVALID_MENU_HANDLE
/* NT4, win2k */
3161 || broken (gle
== 0xdeadbeef) /* win95 */
3162 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
3163 Ex
? "Ex" : "", gle
, NO_ERROR
, ERROR_INVALID_MENU_HANDLE
);
3164 ok( gflag_initmenupopup
&& gflag_entermenuloop
&& gflag_initmenu
,
3165 "missed expected message(s)%s%s%s\n",
3166 !gflag_initmenupopup
? " WM_INITMENUPOPUP ": " ",
3167 !gflag_entermenuloop
? "WM_INITMENULOOP ": "",
3168 !gflag_initmenu
? "WM_INITMENU": "");
3170 ret
= AppendMenuA( hmenu
, MF_STRING
, 1, "winetest");
3171 ok( ret
, "AppendMenA has failed!\n");
3172 SetLastError(0xdeadbeef);
3173 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= 0;
3174 ret
= MyTrackPopupMenu( Ex
, hmenu
, TPM_RETURNCMD
, 100,100, hwnd
, NULL
);
3175 gle
= GetLastError();
3176 ok( ret
== 0, "TrackPopupMenu%s returned %d expected zero\n", Ex
? "Ex" : "", ret
);
3178 || gle
== ERROR_INVALID_MENU_HANDLE
/* NT4, win2k and Vista in the TrackPopupMenuEx case */
3179 || broken (gle
== 0xdeadbeef) /* win95 */
3180 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
3181 Ex
? "Ex" : "", gle
, NO_ERROR
, ERROR_INVALID_MENU_HANDLE
);
3182 ok( gflag_initmenupopup
&& gflag_entermenuloop
&& gflag_initmenu
,
3183 "missed expected message(s)%s%s%s\n",
3184 !gflag_initmenupopup
? " WM_INITMENUPOPUP ": " ",
3185 !gflag_entermenuloop
? "WM_INITMENULOOP ": "",
3186 !gflag_initmenu
? "WM_INITMENU": "");
3190 DestroyWindow(hwnd
);
3193 static HMENU g_hmenu
;
3195 static LRESULT WINAPI
menu_track_again_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3199 case WM_ENTERMENULOOP
:
3203 /* try a recursive call */
3204 SetLastError(0xdeadbeef);
3205 ret
= TrackPopupMenu(g_hmenu
, 0, 100, 100, 0, hwnd
, NULL
);
3206 ok(ret
== FALSE
, "got %d\n", ret
);
3207 ok(GetLastError() == ERROR_POPUP_ALREADY_ACTIVE
||
3208 broken(GetLastError() == 0xdeadbeef) /* W9x */, "got %d\n", GetLastError());
3210 /* exit menu modal loop
3211 * ( A SendMessage does not work on NT3.51 here ) */
3212 return PostMessage(hwnd
, WM_CANCELMODE
, 0, 0);
3215 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3218 static void test_menu_trackagain(void)
3223 hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
3224 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
3225 NULL
, NULL
, NULL
, NULL
);
3226 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
3228 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_track_again_wnd_proc
);
3230 g_hmenu
= CreatePopupMenu();
3231 ok(g_hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
3233 ret
= TrackPopupMenu( g_hmenu
, 0, 100, 100, 0, hwnd
, NULL
);
3234 todo_wine
ok(ret
== FALSE
, "got %d\n", ret
);
3236 DestroyMenu(g_hmenu
);
3237 DestroyWindow(hwnd
);
3240 /* test handling of WM_CANCELMODE messages */
3241 static int g_got_enteridle
;
3242 static HWND g_hwndtosend
;
3243 static LRESULT WINAPI
menu_cancelmode_wnd_proc(HWND hwnd
, UINT msg
,
3244 WPARAM wparam
, LPARAM lparam
)
3248 case WM_ENTERMENULOOP
:
3249 g_got_enteridle
= 0;
3250 return SendMessage( g_hwndtosend
, WM_CANCELMODE
, 0, 0);
3253 if( g_got_enteridle
++ == 0) {
3254 /* little hack to get another WM_ENTERIDLE message */
3255 PostMessage( hwnd
, WM_MOUSEMOVE
, 0, 0);
3256 return SendMessage( g_hwndtosend
, WM_CANCELMODE
, 0, 0);
3262 return DefWindowProc( hwnd
, msg
, wparam
, lparam
);
3265 static void test_menu_cancelmode(void)
3268 HWND hwnd
, hwndchild
;
3269 HMENU menu
, menubar
;
3271 if( !pEndMenu
) { /* win95 */
3272 win_skip( "EndMenu is not available\n");
3275 hwnd
= CreateWindowEx( 0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
3276 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
3277 NULL
, NULL
, NULL
, NULL
);
3278 hwndchild
= CreateWindowEx( 0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
3279 WS_VISIBLE
| WS_CHILD
, 10, 10, 20, 20,
3280 hwnd
, NULL
, NULL
, NULL
);
3281 ok( hwnd
!= NULL
&& hwndchild
!= NULL
,
3282 "CreateWindowEx failed with error %d\n", GetLastError());
3283 g_hwndtosend
= hwnd
;
3284 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_cancelmode_wnd_proc
);
3285 SetWindowLongPtr( hwndchild
, GWLP_WNDPROC
, (LONG_PTR
)menu_cancelmode_wnd_proc
);
3286 menu
= CreatePopupMenu();
3287 ok( menu
!= NULL
, "CreatePopupMenu failed with error %d\n", GetLastError());
3288 ret
= AppendMenuA( menu
, MF_STRING
, 1, "winetest");
3289 ok( ret
, "Functie failed lasterror is %u\n", GetLastError());
3290 /* seems to be needed only on wine :( */
3291 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
3292 DispatchMessage(&msg
);
3293 /* test the effect of sending a WM_CANCELMODE message in the WM_INITMENULOOP
3294 * handler of the menu owner */
3295 /* test results is extracted from variable g_got_enteridle. Possible values:
3296 * 0 : complete conformance. Sending WM_CANCELMODE cancels a menu initializing tracking
3297 * 1 : Sending WM_CANCELMODE cancels a menu that is in tracking state
3298 * 2 : Sending WM_CANCELMODE does not work
3300 /* menu owner is top level window */
3301 g_hwndtosend
= hwnd
;
3302 TrackPopupMenu( menu
, TPM_RETURNCMD
, 100,100, 0, hwnd
, NULL
);
3304 ok( g_got_enteridle
== 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle
);
3306 ok( g_got_enteridle
< 2, "received %d WM_ENTERIDLE messages, should be less than 2\n", g_got_enteridle
);
3307 /* menu owner is child window */
3308 g_hwndtosend
= hwndchild
;
3309 TrackPopupMenu( menu
, TPM_RETURNCMD
, 100,100, 0, hwndchild
, NULL
);
3311 ok(g_got_enteridle
== 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle
);
3313 ok(g_got_enteridle
< 2, "received %d WM_ENTERIDLE messages, should be less than 2\n", g_got_enteridle
);
3314 /* now send the WM_CANCELMODE messages to the WRONG window */
3315 /* those should fail ( to have any effect) */
3316 g_hwndtosend
= hwnd
;
3317 TrackPopupMenu( menu
, TPM_RETURNCMD
, 100,100, 0, hwndchild
, NULL
);
3318 ok( g_got_enteridle
== 2, "received %d WM_ENTERIDLE messages, should be 2\n", g_got_enteridle
);
3320 /* test canceling tracking in a window's menu bar */
3321 menubar
= CreateMenu();
3322 ok( menubar
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
3323 ret
= AppendMenuA( menubar
, MF_POPUP
|MF_STRING
, (UINT_PTR
)menu
, "winetest");
3324 ok( ret
, "AppendMenuA failed lasterror is %u\n", GetLastError());
3325 ret
= SetMenu( hwnd
, menubar
);
3326 ok( ret
, "SetMenu failed lasterror is %u\n", GetLastError());
3327 /* initiate tracking */
3328 g_hwndtosend
= hwnd
;
3329 ret
= SendMessage( hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, 0 );
3330 ok( ret
== 0, "Sending WM_SYSCOMMAND/SC_KEYMENU failed lasterror is %u\n", GetLastError());
3331 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
3332 DispatchMessage(&msg
);
3334 ok(g_got_enteridle
== 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle
);
3336 ok(g_got_enteridle
< 2, "received %d WM_ENTERIDLE messages, should be less than 2\n", g_got_enteridle
);
3339 DestroyMenu( menubar
);
3341 DestroyWindow( hwndchild
);
3342 DestroyWindow( hwnd
);
3345 /* show menu trees have a maximum depth */
3346 static void test_menu_maxdepth(void)
3348 #define NR_MENUS 100
3349 HMENU hmenus
[ NR_MENUS
];
3353 SetLastError(12345678);
3354 for( i
= 0; i
< NR_MENUS
; i
++) {
3355 hmenus
[i
] = CreatePopupMenu();
3356 if( !hmenus
[i
]) break;
3358 ok( i
== NR_MENUS
, "could not create more than %d menu's\n", i
);
3359 for( i
= 1; i
< NR_MENUS
; i
++) {
3360 ret
= AppendMenuA( hmenus
[i
], MF_POPUP
, (UINT_PTR
)hmenus
[i
-1],"test");
3363 trace("Maximum depth is %d\n", i
);
3364 ok( GetLastError() == 12345678, "unexpected error %d\n", GetLastError());
3366 broken( i
== NR_MENUS
), /* win98, NT */
3367 "no ( or very large) limit on menu depth!\n");
3369 for( i
= 0; i
< NR_MENUS
; i
++)
3370 DestroyMenu( hmenus
[i
]);
3374 static void test_menu_circref(void)
3379 menu1
= CreatePopupMenu();
3380 menu2
= CreatePopupMenu();
3381 ok( menu1
&& menu2
, "error creating menus.\n");
3382 ret
= AppendMenuA( menu1
, MF_POPUP
, (UINT_PTR
)menu2
, "winetest");
3383 ok( ret
, "AppendMenu failed, error is %d\n", GetLastError());
3384 ret
= AppendMenuA( menu1
, MF_STRING
| MF_HILITE
, 123, "winetest");
3385 ok( ret
, "AppendMenu failed, error is %d\n", GetLastError());
3386 /* app chooses an id that happens to clash with its own hmenu */
3387 ret
= AppendMenuA( menu2
, MF_STRING
, (UINT_PTR
)menu2
, "winetest");
3388 ok( ret
, "AppendMenu failed, error is %d\n", GetLastError());
3389 /* now attempt to change the string of the first item of menu1 */
3390 ret
= ModifyMenuA( menu1
, (UINT_PTR
)menu2
, MF_POPUP
, (UINT_PTR
)menu2
, "menu 2");
3392 broken( ret
), /* win98, NT */
3393 "ModifyMenu should have failed.\n");
3394 if( !ret
) { /* will probably stack fault if the ModifyMenu succeeded */
3395 ret
= GetMenuState( menu1
, 123, 0);
3396 ok( ret
== MF_HILITE
, "GetMenuState returned %x\n",ret
);
3398 DestroyMenu( menu2
);
3399 DestroyMenu( menu1
);
3402 /* test how the menu texts are aligned when the menu items have
3403 * different combinations of text and bitmaps (bug #13350) */
3404 static void test_menualign(void)
3408 HBITMAP hbm1
, hbm2
, hbm3
;
3409 MENUITEMINFO mii
= { sizeof(MENUITEMINFO
)};
3412 MENUINFO mi
= { sizeof( MENUINFO
)};
3414 if( !winetest_interactive
) {
3415 skip( "interactive alignment tests.\n");
3418 hwnd
= CreateWindowEx(0,
3420 "Menu text alignment Test\nPlease make a selection.",
3421 WS_OVERLAPPEDWINDOW
,
3424 NULL
, NULL
, 0, NULL
);
3425 ShowWindow( hwnd
, SW_SHOW
);
3426 /* create bitmaps */
3427 memset( bmfill
, 0xcc, sizeof( bmfill
));
3428 hbm1
= CreateBitmap( 10,10,1,1,bmfill
);
3429 hbm2
= CreateBitmap( 20,20,1,1,bmfill
);
3430 hbm3
= CreateBitmap( 50,6,1,1,bmfill
);
3431 ok( hbm1
&& hbm2
&& hbm3
, "Creating bitmaps failed\n");
3432 menu
= CreatePopupMenu();
3433 ok( menu
!= NULL
, "CreatePopupMenu() failed\n");
3435 mi
.fMask
= MIM_STYLE
;
3436 ret
= pGetMenuInfo( menu
, &mi
);
3437 ok( ret
, "GetMenuInfo failed: %d\n", GetLastError());
3438 ok( menu
!= NULL
, "GetMenuInfo() failed\n");
3439 ok( 0 == mi
.dwStyle
, "menuinfo style is %x\n", mi
.dwStyle
);
3442 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3444 mii
.hbmpItem
= hbm1
;
3445 mii
.dwTypeData
= (LPSTR
) " OK: menu texts are correctly left-aligned.";
3446 ret
= InsertMenuItem( menu
, -1, TRUE
, &mii
);
3447 ok( ret
, "InsertMenuItem() failed\n");
3448 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3450 mii
.hbmpItem
= hbm2
;
3451 mii
.dwTypeData
= (LPSTR
) " FAIL: menu texts are NOT left-aligned.";
3452 ret
= InsertMenuItem( menu
, -1, TRUE
, &mii
);
3453 ok( ret
, "InsertMenuItem() failed\n");
3454 ret
= TrackPopupMenu( menu
, TPM_RETURNCMD
, 110, 200, 0, hwnd
, NULL
);
3455 ok( ret
!= 2, "User indicated that menu text alignment test 1 failed %d\n", ret
);
3457 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3459 mii
.hbmpItem
= hbm3
;
3460 mii
.dwTypeData
= NULL
;
3461 ret
= InsertMenuItem( menu
, 0, TRUE
, &mii
);
3462 ok( ret
, "InsertMenuItem() failed\n");
3463 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3465 mii
.hbmpItem
= hbm1
;
3466 /* make the text a bit longer, to keep it readable */
3467 /* this bug is on winXP and reproduced on wine */
3468 mii
.dwTypeData
= (LPSTR
) " OK: menu texts are to the right of the bitmaps........";
3469 ret
= SetMenuItemInfo( menu
, 1, TRUE
, &mii
);
3470 ok( ret
, "SetMenuItemInfo() failed\n");
3472 mii
.hbmpItem
= hbm2
;
3473 mii
.dwTypeData
= (LPSTR
) " FAIL: menu texts are below the first bitmap. ";
3474 ret
= SetMenuItemInfo( menu
, 2, TRUE
, &mii
);
3475 ok( ret
, "SetMenuItemInfo() failed\n");
3476 ret
= TrackPopupMenu( menu
, TPM_RETURNCMD
, 110, 200, 0, hwnd
, NULL
);
3477 ok( ret
!= 2, "User indicated that menu text alignment test 2 failed %d\n", ret
);
3479 mii
.fMask
= MIIM_TYPE
| MIIM_ID
;
3481 mii
.fType
= MFT_BITMAP
;
3482 mii
.dwTypeData
= (LPSTR
) hbm3
;
3483 ret
= SetMenuItemInfo( menu
, 0, TRUE
, &mii
);
3484 ok( ret
, "SetMenuItemInfo() failed\n");
3485 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3487 mii
.hbmpItem
= NULL
;
3488 mii
.dwTypeData
= (LPSTR
) " OK: menu texts are below the bitmap.";
3489 ret
= SetMenuItemInfo( menu
, 1, TRUE
, &mii
);
3490 ok( ret
, "SetMenuItemInfo() failed\n");
3492 mii
.hbmpItem
= NULL
;
3493 mii
.dwTypeData
= (LPSTR
) " FAIL: menu texts are NOT below the bitmap.";
3494 ret
= SetMenuItemInfo( menu
, 2, TRUE
, &mii
);
3495 ok( ret
, "SetMenuItemInfo() failed\n");
3496 ret
= TrackPopupMenu( menu
, TPM_RETURNCMD
, 110, 200, 0, hwnd
, NULL
);
3497 ok( ret
!= 2, "User indicated that menu text alignment test 3 failed %d\n", ret
);
3499 DeleteObject( hbm1
);
3500 DeleteObject( hbm2
);
3501 DeleteObject( hbm3
);
3503 DestroyWindow( hwnd
);
3508 init_function_pointers();
3510 /* Wine defines MENUITEMINFO for W2K and above. NT4 and below can't
3513 if (correct_behavior())
3515 test_menu_add_string();
3516 test_menu_iteminfo();
3517 test_menu_search_bycommand();
3518 test_CheckMenuRadioItem();
3519 test_menu_resource_layout();
3524 register_menu_check_class();
3526 test_menu_locked_by_window();
3527 test_subpopup_locked_by_menu();
3528 test_menu_ownerdraw();
3529 test_getmenubarinfo();
3530 test_menu_bmp_and_string();
3531 test_menu_getmenuinfo();
3532 test_menu_setmenuinfo();
3536 test_menu_hilitemenuitem();
3537 test_menu_trackpopupmenu();
3538 test_menu_trackagain();
3539 test_menu_cancelmode();
3540 test_menu_maxdepth();
3541 test_menu_circref();