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 UINT (WINAPI
*pSendInput
)(UINT
, INPUT
*, size_t);
42 static BOOL (WINAPI
*pSetMenuInfo
)(HMENU
,LPCMENUINFO
);
43 static BOOL (WINAPI
*pEndMenu
) (void);
45 static void init_function_pointers(void)
47 HMODULE hdll
= GetModuleHandleA("user32");
49 #define GET_PROC(func) \
50 p ## func = (void*)GetProcAddress(hdll, #func); \
52 trace("GetProcAddress(%s) failed\n", #func);
62 static BOOL
correct_behavior(void)
70 memset(&info
, 0, sizeof(MENUITEMINFO
));
71 info
.cbSize
= sizeof(MENUITEMINFO
);
72 SetLastError(0xdeadbeef);
73 rc
= GetMenuItemInfo(hmenu
, 0, TRUE
, &info
);
75 * NT4 : ERROR_INVALID_PARAMETER
76 * >= W2K : ERROR_MENU_ITEM_NOT_FOUND
78 if (!rc
&& GetLastError() != ERROR_MENU_ITEM_NOT_FOUND
)
80 win_skip("NT4 and below can't handle a bigger MENUITEMINFO struct\n");
89 static LRESULT WINAPI
menu_check_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
93 case WM_ENTERMENULOOP
:
94 /* mark window as having entered menu loop */
95 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, TRUE
);
96 /* exit menu modal loop
97 * ( A SendMessage does not work on NT3.51 here ) */
98 return PostMessage(hwnd
, WM_CANCELMODE
, 0, 0);
100 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
103 /* The MSVC headers ignore our NONAMELESSUNION requests so we have to define
116 /* globals to communicate between test and wndproc */
118 static BOOL bMenuVisible
;
119 static BOOL got_input
;
120 static HMENU hMenus
[4];
123 #define MOD_NRMENUS 8
125 /* menu texts with their sizes */
128 SIZE size
; /* size of text up to any \t */
129 SIZE sc_size
; /* size of the short-cut */
133 { "Shira&z\tAlt+S" },
138 static unsigned int MOD_maxid
;
139 static RECT MOD_rc
[MOD_NRMENUS
];
140 static int MOD_avec
, MOD_hic
;
141 static int MOD_odheight
;
142 static SIZE MODsizes
[MOD_NRMENUS
]= { {MOD_SIZE
, MOD_SIZE
},{MOD_SIZE
, MOD_SIZE
},
143 {MOD_SIZE
, MOD_SIZE
},{MOD_SIZE
, MOD_SIZE
}};
144 static int MOD_GotDrawItemMsg
= FALSE
;
145 static int gflag_initmenupopup
,
149 /* wndproc used by test_menu_ownerdraw() */
150 static LRESULT WINAPI
menu_ownerdraw_wnd_proc(HWND hwnd
, UINT msg
,
151 WPARAM wparam
, LPARAM lparam
)
153 static HMENU hmenupopup
;
156 case WM_INITMENUPOPUP
:
157 gflag_initmenupopup
++;
158 hmenupopup
= (HMENU
) wparam
;
160 case WM_ENTERMENULOOP
:
161 gflag_entermenuloop
++;
168 MEASUREITEMSTRUCT
* pmis
= (MEASUREITEMSTRUCT
*)lparam
;
170 trace("WM_MEASUREITEM received data %lx size %dx%d\n",
171 pmis
->itemData
, pmis
->itemWidth
, pmis
->itemHeight
);
172 MOD_odheight
= pmis
->itemHeight
;
173 pmis
->itemWidth
= MODsizes
[pmis
->itemData
].cx
;
174 pmis
->itemHeight
= MODsizes
[pmis
->itemData
].cy
;
179 DRAWITEMSTRUCT
* pdis
;
182 char chrs
[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
185 pdis
= (DRAWITEMSTRUCT
*) lparam
;
186 if( winetest_debug
) {
188 GetMenuItemRect( hwnd
, (HMENU
)pdis
->hwndItem
, pdis
->itemData
,&rc
);
189 trace("WM_DRAWITEM received hwnd %p hmenu %p itemdata %ld item %d rc %d,%d-%d,%d itemrc: %d,%d-%d,%d\n",
190 hwnd
, pdis
->hwndItem
, pdis
->itemData
, pdis
->itemID
,
191 pdis
->rcItem
.left
, pdis
->rcItem
.top
,
192 pdis
->rcItem
.right
,pdis
->rcItem
.bottom
,
193 rc
.left
,rc
.top
,rc
.right
,rc
.bottom
);
194 oldpen
=SelectObject( pdis
->hDC
, GetStockObject(
195 pdis
->itemState
& ODS_SELECTED
? WHITE_PEN
:BLACK_PEN
));
196 Rectangle( pdis
->hDC
, pdis
->rcItem
.left
,pdis
->rcItem
.top
,
197 pdis
->rcItem
.right
,pdis
->rcItem
.bottom
);
198 SelectObject( pdis
->hDC
, oldpen
);
200 /* calculate widths of some menu texts */
201 if( ! MOD_txtsizes
[0].size
.cx
)
202 for(i
= 0; MOD_txtsizes
[i
].text
; i
++) {
205 strcpy( buf
, MOD_txtsizes
[i
].text
);
206 if( ( p
= strchr( buf
, '\t'))) {
208 DrawText( pdis
->hDC
, p
+ 1, -1, &rc
,
209 DT_SINGLELINE
|DT_CALCRECT
);
210 MOD_txtsizes
[i
].sc_size
.cx
= rc
.right
- rc
.left
;
211 MOD_txtsizes
[i
].sc_size
.cy
= rc
.bottom
- rc
.top
;
213 DrawText( pdis
->hDC
, buf
, -1, &rc
,
214 DT_SINGLELINE
|DT_CALCRECT
);
215 MOD_txtsizes
[i
].size
.cx
= rc
.right
- rc
.left
;
216 MOD_txtsizes
[i
].size
.cy
= rc
.bottom
- rc
.top
;
219 if( pdis
->itemData
> MOD_maxid
) return TRUE
;
220 /* store the rectangl */
221 MOD_rc
[pdis
->itemData
] = pdis
->rcItem
;
222 /* calculate average character width */
223 GetTextExtentPoint( pdis
->hDC
, chrs
, 52, &sz
);
224 MOD_avec
= (sz
.cx
+ 26)/52;
225 GetTextMetrics( pdis
->hDC
, &tm
);
226 MOD_hic
= tm
.tmHeight
;
227 MOD_GotDrawItemMsg
= TRUE
;
232 ok( lparam
|| broken(!lparam
), /* win9x, nt4 */
233 "Menu window handle is NULL!\n");
235 HMENU hmenu
= (HMENU
)SendMessageA( (HWND
)lparam
, MN_GETHMENU
, 0, 0);
236 ok( hmenupopup
== hmenu
, "MN_GETHMENU returns %p expected %p\n",
239 PostMessage(hwnd
, WM_CANCELMODE
, 0, 0);
244 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
247 static void register_menu_check_class(void)
255 GetModuleHandle(NULL
),
257 LoadCursor(NULL
, IDC_ARROW
),
258 (HBRUSH
)(COLOR_BTNFACE
+1),
260 TEXT("WineMenuCheck"),
263 atomMenuCheckClass
= RegisterClass(&wc
);
266 /* demonstrates that windows locks the menu object so that it is still valid
267 * even after a client calls DestroyMenu on it */
268 static void test_menu_locked_by_window(void)
272 HWND hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
273 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
274 NULL
, NULL
, NULL
, NULL
);
275 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
276 hmenu
= CreateMenu();
277 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
278 ret
= InsertMenu(hmenu
, 0, MF_STRING
, 0, TEXT("&Test"));
279 ok(ret
, "InsertMenu failed with error %d\n", GetLastError());
280 ret
= SetMenu(hwnd
, hmenu
);
281 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
282 ret
= DestroyMenu(hmenu
);
283 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
285 ret
= DrawMenuBar(hwnd
);
287 ok(ret
, "DrawMenuBar failed with error %d\n", GetLastError());
289 ret
= IsMenu(GetMenu(hwnd
));
290 ok(!ret
|| broken(ret
) /* nt4 */, "Menu handle should have been destroyed\n");
292 SendMessage(hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, 0);
293 /* did we process the WM_INITMENU message? */
294 ret
= GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
296 ok(ret
, "WM_INITMENU should have been sent\n");
302 /* demonstrates that subpopup's are locked
303 * even after a client calls DestroyMenu on it */
304 static LRESULT WINAPI
subpopuplocked_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
310 hwndmenu
= GetCapture();
312 PostMessage( hwndmenu
, WM_KEYDOWN
, VK_DOWN
, 0);
313 PostMessage( hwndmenu
, WM_KEYDOWN
, VK_RIGHT
, 0);
314 PostMessage( hwndmenu
, WM_KEYDOWN
, VK_RETURN
, 0);
317 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
320 static void test_subpopup_locked_by_menu(void)
324 HMENU hmenu
, hsubmenu
;
325 MENUINFO mi
= { sizeof( MENUINFO
)};
326 MENUITEMINFO mii
= { sizeof( MENUITEMINFO
)};
328 const int itemid
= 0x1234567;
331 win_skip("GetMenuInfo is not available\n");
334 /* create window, popupmenu with one subpopup */
335 hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
336 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
337 NULL
, NULL
, NULL
, NULL
);
338 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
339 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
) subpopuplocked_wnd_proc
);
340 hmenu
= CreatePopupMenu();
341 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
342 hsubmenu
= CreatePopupMenu();
343 ok(hsubmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
344 ret
= InsertMenu(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hsubmenu
,
345 TEXT("PopUpLockTest"));
346 ok(ret
, "InsertMenu failed with error %d\n", GetLastError());
347 ret
= InsertMenu(hsubmenu
, 0, MF_BYPOSITION
| MF_STRING
, itemid
, TEXT("PopUpMenu"));
348 ok(ret
, "InsertMenu failed with error %d\n", GetLastError());
349 /* first some tests that all this functions properly */
350 mii
.fMask
= MIIM_SUBMENU
;
351 ret
= GetMenuItemInfo( hmenu
, 0, TRUE
, &mii
);
352 ok( ret
, "GetMenuItemInfo failed error %d\n", GetLastError());
353 ok( mii
.hSubMenu
== hsubmenu
, "submenu is %p\n", mii
.hSubMenu
);
354 mi
.fMask
|= MIM_STYLE
;
355 ret
= pGetMenuInfo( hsubmenu
, &mi
);
356 ok( ret
, "GetMenuInfo returned 0 with error %d\n", GetLastError());
357 ret
= IsMenu( hsubmenu
);
358 ok( ret
, "Menu handle is not valid\n");
359 SetLastError( 0xdeadbeef);
360 ret
= TrackPopupMenu( hmenu
, 0x100, 100,100, 0, hwnd
, NULL
);
361 if( ret
== (itemid
& 0xffff)) {
362 win_skip("not on 16 bit menu subsystem\n");
363 DestroyMenu( hsubmenu
);
365 gle
= GetLastError();
366 ok( ret
== itemid
, "TrackPopupMenu returned %d error is %d\n", ret
, gle
);
368 broken( gle
== 0xdeadbeef), /* win2k0 */
369 "Last error is %d\n", gle
);
370 /* then destroy the sub-popup */
371 ret
= DestroyMenu( hsubmenu
);
372 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
373 /* and repeat the tests */
374 mii
.fMask
= MIIM_SUBMENU
;
375 ret
= GetMenuItemInfo( hmenu
, 0, TRUE
, &mii
);
376 ok( ret
, "GetMenuItemInfo failed error %d\n", GetLastError());
377 /* GetMenuInfo fails now */
378 ok( mii
.hSubMenu
== hsubmenu
, "submenu is %p\n", mii
.hSubMenu
);
379 mi
.fMask
|= MIM_STYLE
;
380 ret
= pGetMenuInfo( hsubmenu
, &mi
);
381 ok( !ret
, "GetMenuInfo should have failed\n");
382 /* IsMenu says it is not */
383 ret
= IsMenu( hsubmenu
);
384 ok( !ret
, "Menu handle should be invalid\n");
385 /* but TrackPopupMenu still works! */
386 SetLastError( 0xdeadbeef);
387 ret
= TrackPopupMenu( hmenu
, 0x100, 100,100, 0, hwnd
, NULL
);
388 gle
= GetLastError();
390 ok( ret
== itemid
, "TrackPopupMenu returned %d error is %d\n", ret
, gle
);
393 broken(gle
== 0xdeadbeef) || /* wow64 */
394 broken(gle
== ERROR_INVALID_PARAMETER
), /* win2k0 */
395 "Last error is %d\n", gle
);
402 static void test_menu_ownerdraw(void)
408 HWND hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
409 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
410 NULL
, NULL
, NULL
, NULL
);
411 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
413 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_ownerdraw_wnd_proc
);
414 hmenu
= CreatePopupMenu();
415 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
416 if( !hmenu
) { DestroyWindow(hwnd
);return;}
418 for( j
=0;j
<2;j
++) /* create columns */
419 for(i
=0;i
<2;i
++) { /* create rows */
420 ret
= AppendMenu( hmenu
, MF_OWNERDRAW
|
421 (i
==0 ? MF_MENUBREAK
: 0), k
, MAKEINTRESOURCE(k
));
423 ok( ret
, "AppendMenu failed for %d\n", k
-1);
426 assert( k
<= sizeof(MOD_rc
)/sizeof(RECT
));
427 /* display the menu */
428 ret
= TrackPopupMenu( hmenu
, 0x100, 100,100, 0, hwnd
, NULL
);
430 /* columns have a 4 pixel gap between them */
431 ok( MOD_rc
[0].right
+ 4 == MOD_rc
[2].left
,
432 "item rectangles are not separated by 4 pixels space\n");
433 /* height should be what the MEASUREITEM message has returned */
434 ok( MOD_rc
[0].bottom
- MOD_rc
[0].top
== MOD_SIZE
,
435 "menu item has wrong height: %d should be %d\n",
436 MOD_rc
[0].bottom
- MOD_rc
[0].top
, MOD_SIZE
);
437 /* no gaps between the rows */
438 ok( MOD_rc
[0].bottom
- MOD_rc
[1].top
== 0,
439 "There should not be a space between the rows, gap is %d\n",
440 MOD_rc
[0].bottom
- MOD_rc
[1].top
);
441 /* test the correct value of the item height that was sent
442 * by the WM_MEASUREITEM message */
443 ok( MOD_odheight
== HIWORD( GetDialogBaseUnits()) || /* WinNT,2k,XP */
444 MOD_odheight
== MOD_hic
, /* Win95,98,ME */
445 "Wrong height field in MEASUREITEMSTRUCT, expected %d or %d actual %d\n",
446 HIWORD( GetDialogBaseUnits()), MOD_hic
, MOD_odheight
);
447 /* test what MF_MENUBREAK did at the first position. Also show
448 * that an MF_SEPARATOR is ignored in the height calculation. */
449 leftcol
= MOD_rc
[0].left
;
450 ModifyMenu( hmenu
, 0, MF_BYCOMMAND
| MF_OWNERDRAW
| MF_SEPARATOR
, 0, 0);
451 /* display the menu */
452 ret
= TrackPopupMenu( hmenu
, 0x100, 100,100, 0, hwnd
, NULL
);
453 /* left should be 4 pixels less now */
454 ok( leftcol
== MOD_rc
[0].left
+ 4,
455 "columns should be 4 pixels to the left (actual %d).\n",
456 leftcol
- MOD_rc
[0].left
);
458 ok( MOD_rc
[0].right
- MOD_rc
[0].left
== 2 * MOD_avec
+ MOD_SIZE
,
459 "width of owner drawn menu item is wrong. Got %d expected %d\n",
460 MOD_rc
[0].right
- MOD_rc
[0].left
, 2*MOD_avec
+ MOD_SIZE
);
462 ok( MOD_rc
[0].bottom
- MOD_rc
[0].top
== MOD_SIZE
,
463 "Height is incorrect. Got %d expected %d\n",
464 MOD_rc
[0].bottom
- MOD_rc
[0].top
, MOD_SIZE
);
466 /* test width/height of an ownerdraw menu bar as well */
467 ret
= DestroyMenu(hmenu
);
468 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
469 hmenu
= CreateMenu();
470 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
471 if( !hmenu
) { DestroyWindow(hwnd
);return;}
474 ret
= AppendMenu( hmenu
, MF_OWNERDRAW
, i
, 0);
475 ok( ret
, "AppendMenu failed for %d\n", i
);
477 ret
= SetMenu( hwnd
, hmenu
);
478 UpdateWindow( hwnd
); /* hack for wine to draw the window + menu */
479 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
481 ok( MOD_rc
[0].right
- MOD_rc
[0].left
== 2 * MOD_avec
+ MOD_SIZE
,
482 "width of owner drawn menu item is wrong. Got %d expected %d\n",
483 MOD_rc
[0].right
- MOD_rc
[0].left
, 2*MOD_avec
+ MOD_SIZE
);
485 ok( MOD_rc
[0].bottom
- MOD_rc
[0].top
== GetSystemMetrics( SM_CYMENU
) - 1,
486 "Height of owner drawn menu item is wrong. Got %d expected %d\n",
487 MOD_rc
[0].bottom
- MOD_rc
[0].top
, GetSystemMetrics( SM_CYMENU
) - 1);
490 ret
= DestroyMenu(hmenu
);
491 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
495 /* helper for test_menu_bmp_and_string() */
496 static void test_mbs_help( int ispop
, int hassub
, int mnuopt
,
497 HWND hwnd
, int arrowwidth
, int count
, HBITMAP hbmp
,
498 SIZE bmpsize
, LPCSTR text
, SIZE size
, SIZE sc_size
)
501 HMENU hmenu
, submenu
;
502 MENUITEMINFO mii
={ sizeof( MENUITEMINFO
)};
509 MOD_GotDrawItemMsg
= FALSE
;
510 mii
.fMask
= MIIM_FTYPE
| MIIM_DATA
| MIIM_STATE
;
512 /* check the menu item unless MNS_CHECKORBMP is set */
513 mii
.fState
= (mnuopt
!= 2 ? MFS_CHECKED
: MFS_UNCHECKED
);
515 MODsizes
[0] = bmpsize
;
519 mii
.fMask
|= MIIM_STRING
;
520 strcpy(text_copy
, text
);
521 mii
.dwTypeData
= text_copy
; /* structure member declared non-const */
522 if( ( p
= strchr( text
, '\t'))) {
523 hastab
= *(p
+ 1) ? 2 : 1;
526 /* tabs don't make sense in menubars */
527 if(hastab
&& !ispop
) return;
529 mii
.fMask
|= MIIM_BITMAP
;
532 submenu
= CreateMenu();
533 ok( submenu
!= 0, "CreateMenu failed with error %d\n", GetLastError());
535 hmenu
= CreatePopupMenu();
537 hmenu
= CreateMenu();
538 ok( hmenu
!= 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
540 mii
.fMask
|= MIIM_SUBMENU
;
541 mii
.hSubMenu
= submenu
;
544 mi
.cbSize
= sizeof(mi
);
545 mi
.fMask
= MIM_STYLE
;
546 pGetMenuInfo( hmenu
, &mi
);
547 if( mnuopt
) mi
.dwStyle
|= mnuopt
== 1 ? MNS_NOCHECK
: MNS_CHECKORBMP
;
548 ret
= pSetMenuInfo( hmenu
, &mi
);
549 ok( ret
, "SetMenuInfo failed with error %d\n", GetLastError());
551 ret
= InsertMenuItem( hmenu
, 0, FALSE
, &mii
);
552 ok( ret
, "InsertMenuItem failed with error %d\n", GetLastError());
554 if( winetest_debug
) {
556 RECT rc
= {100, 50, 400, 70};
559 sprintf( buf
,"%d text \"%s\" mnuopt %d", count
, text
? text
: "(nil)", mnuopt
);
560 FillRect( hdc
, &rc
, (HBRUSH
) COLOR_WINDOW
);
561 TextOut( hdc
, 10, 50, buf
, strlen( buf
));
562 ReleaseDC( hwnd
, hdc
);
565 ret
= TrackPopupMenu( hmenu
, 0x100, 100,100, 0, hwnd
, NULL
);
567 ret
= SetMenu( hwnd
, hmenu
);
568 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
571 ret
= GetMenuItemRect( hwnd
, hmenu
, 0, &rc
);
572 if (0) /* comment out menu size checks, behavior is different in almost every Windows version */
573 /* the tests should however succeed on win2000, XP and Wine (at least up to 1.1.15) */
574 /* with a variety of dpis and desktop font sizes */
576 /* check menu width */
578 expect
= ( text
|| hbmp
?
579 4 + (mnuopt
!= 1 ? GetSystemMetrics(SM_CXMENUCHECK
) : 0)
581 arrowwidth
+ MOD_avec
+ (hbmp
?
582 ((INT_PTR
)hbmp
<0||(INT_PTR
)hbmp
>12 ? bmpsize
.cx
+ 2 : GetSystemMetrics( SM_CXMENUSIZE
) + 2)
584 (text
&& hastab
? /* TAB space */
585 MOD_avec
+ ( hastab
==2 ? sc_size
.cx
: 0) : 0) +
586 (text
? 2 + (text
[0] ? size
.cx
:0): 0) ;
588 expect
= !(text
|| hbmp
) ? 0 :
589 ( hbmp
? (text
? 2:0) + bmpsize
.cx
: 0 ) +
590 (text
? 2 * MOD_avec
+ (text
[0] ? size
.cx
:0): 0) ;
591 ok( rc
.right
- rc
.left
== expect
,
592 "menu width wrong, got %d expected %d\n", rc
.right
- rc
.left
, expect
);
593 failed
= failed
|| !(rc
.right
- rc
.left
== expect
);
594 /* check menu height */
596 expect
= max( ( !(text
|| hbmp
) ? GetSystemMetrics( SM_CYMENUSIZE
)/2 : 0),
597 max( (text
? max( 2 + size
.cy
, MOD_hic
+ 4) : 0),
599 ((INT_PTR
)hbmp
<0||(INT_PTR
)hbmp
>12 ?
601 : GetSystemMetrics( SM_CYMENUSIZE
) + 2)
604 expect
= ( !(text
|| hbmp
) ? GetSystemMetrics( SM_CYMENUSIZE
)/2 :
605 max( GetSystemMetrics( SM_CYMENU
) - 1, (hbmp
? bmpsize
.cy
: 0)));
606 ok( rc
.bottom
- rc
.top
== expect
,
607 "menu height wrong, got %d expected %d (%d)\n",
608 rc
.bottom
- rc
.top
, expect
, GetSystemMetrics( SM_CYMENU
));
609 failed
= failed
|| !(rc
.bottom
- rc
.top
== expect
);
610 if( hbmp
== HBMMENU_CALLBACK
&& MOD_GotDrawItemMsg
) {
611 /* check the position of the bitmap */
615 else if (mnuopt
== 0)
616 expect
= 4 + GetSystemMetrics(SM_CXMENUCHECK
);
617 else if (mnuopt
== 1)
619 else /* mnuopt == 2 */
621 ok( expect
== MOD_rc
[0].left
,
622 "bitmap left is %d expected %d\n", MOD_rc
[0].left
, expect
);
623 failed
= failed
|| !(expect
== MOD_rc
[0].left
);
625 expect
= (rc
.bottom
- rc
.top
- MOD_rc
[0].bottom
+ MOD_rc
[0].top
) / 2;
626 ok( expect
== MOD_rc
[0].top
,
627 "bitmap top is %d expected %d\n", MOD_rc
[0].top
, expect
);
628 failed
= failed
|| !(expect
== MOD_rc
[0].top
);
631 /* if there was a failure, report details */
633 trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
634 count
, (ispop
? "POPUP": "MENUBAR"),text
? text
: "(nil)", hbmp
, bmpsize
.cx
, bmpsize
.cy
,
635 size
.cx
, size
.cy
, sc_size
.cx
, mnuopt
, hastab
);
636 trace(" check %d,%d arrow %d avechar %d\n",
637 GetSystemMetrics(SM_CXMENUCHECK
),
638 GetSystemMetrics(SM_CYMENUCHECK
),arrowwidth
, MOD_avec
);
639 if( hbmp
== HBMMENU_CALLBACK
)
640 trace( " rc %d,%d-%d,%d bmp.rc %d,%d-%d,%d\n",
641 rc
.left
, rc
.top
, rc
.top
, rc
.bottom
, MOD_rc
[0].left
,
642 MOD_rc
[0].top
,MOD_rc
[0].right
, MOD_rc
[0].bottom
);
645 ret
= DestroyMenu(submenu
);
646 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
647 ret
= DestroyMenu(hmenu
);
648 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
652 static void test_menu_bmp_and_string(void)
660 MENUINFO mi
= {sizeof(MENUINFO
)};
661 MENUITEMINFOA mii
= {sizeof(MENUITEMINFOA
)};
662 int count
, szidx
, txtidx
, bmpidx
, hassub
, mnuopt
, ispop
;
666 win_skip("GetMenuInfo is not available\n");
670 memset( bmfill
, 0xcc, sizeof( bmfill
));
671 hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
, WS_SYSMENU
|
672 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
673 NULL
, NULL
, NULL
, NULL
);
674 hbm_arrow
=LoadBitmap( 0, (CHAR
*)OBM_MNARROW
);
675 GetObject( hbm_arrow
, sizeof(bm
), &bm
);
676 arrowwidth
= bm
.bmWidth
;
677 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
679 /* test system menu */
680 hsysmenu
= GetSystemMenu( hwnd
, FALSE
);
681 ok( hsysmenu
!= NULL
, "GetSystemMenu failed with error %d\n", GetLastError());
682 mi
.fMask
= MIM_STYLE
;
684 ok( pGetMenuInfo( hsysmenu
, &mi
), "GetMenuInfo failed gle=%d\n", GetLastError());
685 ok( MNS_CHECKORBMP
== mi
.dwStyle
, "System Menu Style is %08x, without the bit %08x\n",
686 mi
.dwStyle
, MNS_CHECKORBMP
);
687 mii
.fMask
= MIIM_BITMAP
;
689 ok( GetMenuItemInfoA( hsysmenu
, SC_CLOSE
, FALSE
, &mii
), "GetMenuItemInfoA failed gle=%d\n", GetLastError());
690 ok( HBMMENU_POPUP_CLOSE
== mii
.hbmpItem
, "Item info did not get the right hbitmap: got %p expected %p\n",
691 mii
.hbmpItem
, HBMMENU_POPUP_CLOSE
);
693 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_ownerdraw_wnd_proc
);
696 trace(" check %d,%d arrow %d avechar %d\n",
697 GetSystemMetrics(SM_CXMENUCHECK
),
698 GetSystemMetrics(SM_CYMENUCHECK
),arrowwidth
, MOD_avec
);
701 for( ispop
=1; ispop
>= 0; ispop
--){
702 static SIZE bmsizes
[]= {
703 {10,10},{38,38},{1,30},{55,5}};
704 for( szidx
=0; szidx
< sizeof( bmsizes
) / sizeof( SIZE
); szidx
++) {
705 HBITMAP hbm
= CreateBitmap( bmsizes
[szidx
].cx
, bmsizes
[szidx
].cy
,1,1,bmfill
);
706 HBITMAP bitmaps
[] = { HBMMENU_CALLBACK
, hbm
, HBMMENU_POPUP_CLOSE
, NULL
};
707 ok( hbm
!= 0, "CreateBitmap failed err %d\n", GetLastError());
708 for( txtidx
= 0; txtidx
< sizeof(MOD_txtsizes
)/sizeof(MOD_txtsizes
[0]); txtidx
++) {
709 for( hassub
= 0; hassub
< 2 ; hassub
++) { /* add submenu item */
710 for( mnuopt
= 0; mnuopt
< 3 ; mnuopt
++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
711 for( bmpidx
= 0; bmpidx
<sizeof(bitmaps
)/sizeof(HBITMAP
); bmpidx
++) {
712 /* no need to test NULL bitmaps of several sizes */
713 if( !bitmaps
[bmpidx
] && szidx
> 0) continue;
714 /* the HBMMENU_POPUP not to test for menu bars */
716 bitmaps
[bmpidx
] >= HBMMENU_POPUP_CLOSE
&&
717 bitmaps
[bmpidx
] <= HBMMENU_POPUP_MINIMIZE
) continue;
718 if( !ispop
&& hassub
) continue;
719 test_mbs_help( ispop
, hassub
, mnuopt
,
720 hwnd
, arrowwidth
, ++count
,
723 MOD_txtsizes
[txtidx
].text
,
724 MOD_txtsizes
[txtidx
].size
,
725 MOD_txtsizes
[txtidx
].sc_size
);
737 static void test_menu_add_string( void )
748 WCHAR strbackW
[0x80];
749 static CHAR blah
[] = "blah";
750 static const WCHAR expectedString
[] = {'D','u','m','m','y',' ','s','t','r','i','n','g', 0};
752 hmenu
= CreateMenu();
754 memset( &info
, 0, sizeof info
);
755 info
.cbSize
= sizeof info
;
756 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_ID
;
757 info
.dwTypeData
= blah
;
762 InsertMenuItem(hmenu
, 0, TRUE
, &info
);
764 memset( &info
, 0, sizeof info
);
765 info
.cbSize
= sizeof info
;
766 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_DATA
| MIIM_ID
;
767 info
.dwTypeData
= string
;
768 info
.cch
= sizeof string
;
770 GetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
772 ok( !strcmp( string
, "blah" ), "menu item name differed\n");
774 /* Test combination of ownerdraw and strings with GetMenuItemString(A/W) */
775 strcpy(string
, "Dummy string");
776 memset(&info
, 0x00, sizeof(info
));
777 info
.cbSize
= sizeof(MENUITEMINFO
);
778 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
; /* Set OwnerDraw + typeData */
779 info
.fType
= MFT_OWNERDRAW
;
780 info
.dwTypeData
= string
;
781 rc
= InsertMenuItem( hmenu
, 0, TRUE
, &info
);
782 ok (rc
, "InsertMenuItem failed\n");
784 strcpy(string
,"Garbage");
785 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
786 ok (!strcmp( strback
, "Dummy string" ), "Menu text from Ansi version incorrect\n");
788 SetLastError(0xdeadbeef);
789 ret
= GetMenuStringW( hmenu
, 0, strbackW
, 99, MF_BYPOSITION
);
790 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
791 win_skip("GetMenuStringW is not implemented\n");
794 ok (ret
, "GetMenuStringW on ownerdraw entry failed\n");
795 ok (!lstrcmpW( strbackW
, expectedString
), "Menu text from Unicode version incorrect\n");
798 /* Just change ftype to string and see what text is stored */
799 memset(&info
, 0x00, sizeof(info
));
800 info
.cbSize
= sizeof(MENUITEMINFO
);
801 info
.fMask
= MIIM_FTYPE
; /* Set string type */
802 info
.fType
= MFT_STRING
;
803 info
.dwTypeData
= (char *)0xdeadbeef;
804 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
805 ok (rc
, "SetMenuItemInfo failed\n");
807 /* Did we keep the old dwTypeData? */
808 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
809 ok (!strcmp( strback
, "Dummy string" ), "Menu text from Ansi version incorrect\n");
811 /* Ensure change to bitmap type fails */
812 memset(&info
, 0x00, sizeof(info
));
813 info
.cbSize
= sizeof(MENUITEMINFO
);
814 info
.fMask
= MIIM_FTYPE
; /* Set as bitmap type */
815 info
.fType
= MFT_BITMAP
;
816 info
.dwTypeData
= (char *)0xdeadbee2;
817 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
818 ok (!rc
, "SetMenuItemInfo unexpectedly worked\n");
820 /* Just change ftype back and ensure data hasn't been freed */
821 info
.fType
= MFT_OWNERDRAW
; /* Set as ownerdraw type */
822 info
.dwTypeData
= (char *)0xdeadbee3;
823 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
824 ok (rc
, "SetMenuItemInfo failed\n");
826 /* Did we keep the old dwTypeData? */
827 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
828 ok (!strcmp( strback
, "Dummy string" ), "Menu text from Ansi version incorrect\n");
830 /* Just change string value (not type) */
831 memset(&info
, 0x00, sizeof(info
));
832 info
.cbSize
= sizeof(MENUITEMINFO
);
833 info
.fMask
= MIIM_STRING
; /* Set typeData */
834 strcpy(string2
, "string2");
835 info
.dwTypeData
= string2
;
836 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
837 ok (rc
, "SetMenuItemInfo failed\n");
839 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
840 ok (!strcmp( strback
, "string2" ), "Menu text from Ansi version incorrect\n");
842 /* crashes with wine 0.9.5 */
843 memset(&info
, 0x00, sizeof(info
));
844 info
.cbSize
= sizeof(MENUITEMINFO
);
845 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
; /* Set OwnerDraw + typeData */
846 info
.fType
= MFT_OWNERDRAW
;
847 rc
= InsertMenuItem( hmenu
, 0, TRUE
, &info
);
848 ok (rc
, "InsertMenuItem failed\n");
849 ok (!GetMenuString( hmenu
, 0, NULL
, 0, MF_BYPOSITION
),
850 "GetMenuString on ownerdraw entry succeeded.\n");
851 SetLastError(0xdeadbeef);
852 ret
= GetMenuStringW( hmenu
, 0, NULL
, 0, MF_BYPOSITION
);
853 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
854 win_skip("GetMenuStringW is not implemented\n");
856 ok (!ret
, "GetMenuStringW on ownerdraw entry succeeded.\n");
858 DestroyMenu( hmenu
);
861 /* define building blocks for the menu item info tests */
862 static int strncmpW( const WCHAR
*str1
, const WCHAR
*str2
, int n
)
864 if (n
<= 0) return 0;
865 while ((--n
> 0) && *str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
866 return *str1
- *str2
;
869 static WCHAR
*strcpyW( WCHAR
*dst
, const WCHAR
*src
)
872 while ((*p
++ = *src
++));
876 static void insert_menu_item( int line
, HMENU hmenu
, BOOL ansi
, UINT mask
, UINT type
, UINT state
, UINT id
,
877 HMENU submenu
, HBITMAP checked
, HBITMAP unchecked
, ULONG_PTR data
,
878 void *type_data
, UINT len
, HBITMAP item
, BOOL expect
)
883 /* magic bitmap handle to test smaller cbSize */
884 if (item
== (HBITMAP
)(ULONG_PTR
)0xdeadbeef)
885 info
.cbSize
= FIELD_OFFSET(MENUITEMINFOA
,hbmpItem
);
887 info
.cbSize
= sizeof(info
);
892 info
.hSubMenu
= submenu
;
893 info
.hbmpChecked
= checked
;
894 info
.hbmpUnchecked
= unchecked
;
895 info
.dwItemData
= data
;
896 info
.dwTypeData
= type_data
;
898 info
.hbmpItem
= item
;
899 SetLastError( 0xdeadbeef );
900 if (ansi
) ret
= InsertMenuItemA( hmenu
, 0, TRUE
, &info
);
901 else ret
= InsertMenuItemW( hmenu
, 0, TRUE
, (MENUITEMINFOW
*)&info
);
902 if (!expect
) ok_(__FILE__
, line
)( !ret
, "InsertMenuItem should have failed.\n" );
903 else ok_(__FILE__
, line
)( ret
, "InsertMenuItem failed, err %u\n", GetLastError());
906 static void check_menu_item_info( int line
, HMENU hmenu
, BOOL ansi
, UINT mask
, UINT type
, UINT state
,
907 UINT id
, HMENU submenu
, HBITMAP checked
, HBITMAP unchecked
,
908 ULONG_PTR data
, void *type_data
, UINT in_len
, UINT out_len
,
909 HBITMAP item
, LPCSTR expname
, BOOL expect
, BOOL expstring
)
915 SetLastError( 0xdeadbeef );
916 memset( &info
, 0xcc, sizeof(info
) );
917 info
.cbSize
= sizeof(info
);
919 info
.dwTypeData
= type_data
;
922 ret
= ansi
? GetMenuItemInfoA( hmenu
, 0, TRUE
, &info
) :
923 GetMenuItemInfoW( hmenu
, 0, TRUE
, (MENUITEMINFOW
*)&info
);
926 ok_(__FILE__
, line
)( !ret
, "GetMenuItemInfo should have failed.\n" );
929 ok_(__FILE__
, line
)( ret
, "GetMenuItemInfo failed, err %u\n", GetLastError());
930 if (mask
& MIIM_TYPE
)
931 ok_(__FILE__
, line
)( info
.fType
== type
|| info
.fType
== LOWORD(type
),
932 "wrong type %x/%x\n", info
.fType
, type
);
933 if (mask
& MIIM_STATE
)
934 ok_(__FILE__
, line
)( info
.fState
== state
|| info
.fState
== LOWORD(state
),
935 "wrong state %x/%x\n", info
.fState
, state
);
937 ok_(__FILE__
, line
)( info
.wID
== id
|| info
.wID
== LOWORD(id
),
938 "wrong id %x/%x\n", info
.wID
, id
);
939 if (mask
& MIIM_SUBMENU
)
940 ok_(__FILE__
, line
)( info
.hSubMenu
== submenu
|| (ULONG_PTR
)info
.hSubMenu
== LOWORD(submenu
),
941 "wrong submenu %p/%p\n", info
.hSubMenu
, submenu
);
942 if (mask
& MIIM_CHECKMARKS
)
944 ok_(__FILE__
, line
)( info
.hbmpChecked
== checked
|| (ULONG_PTR
)info
.hbmpChecked
== LOWORD(checked
),
945 "wrong bmpchecked %p/%p\n", info
.hbmpChecked
, checked
);
946 ok_(__FILE__
, line
)( info
.hbmpUnchecked
== unchecked
|| (ULONG_PTR
)info
.hbmpUnchecked
== LOWORD(unchecked
),
947 "wrong bmpunchecked %p/%p\n", info
.hbmpUnchecked
, unchecked
);
949 if (mask
& MIIM_DATA
)
950 ok_(__FILE__
, line
)( info
.dwItemData
== data
|| info
.dwItemData
== LOWORD(data
),
951 "wrong item data %lx/%lx\n", info
.dwItemData
, data
);
952 if (mask
& MIIM_BITMAP
)
953 ok_(__FILE__
, line
)( info
.hbmpItem
== item
|| (ULONG_PTR
)info
.hbmpItem
== LOWORD(item
),
954 "wrong bmpitem %p/%p\n", info
.hbmpItem
, item
);
955 ok_(__FILE__
, line
)( info
.dwTypeData
== type_data
|| (ULONG_PTR
)info
.dwTypeData
== LOWORD(type_data
),
956 "wrong type data %p/%p\n", info
.dwTypeData
, type_data
);
957 ok_(__FILE__
, line
)( info
.cch
== out_len
, "wrong len %x/%x\n", info
.cch
, out_len
);
961 ok_(__FILE__
, line
)( !strncmp( expname
, info
.dwTypeData
, out_len
),
962 "menu item name differed from '%s' '%s'\n", expname
, info
.dwTypeData
);
964 ok_(__FILE__
, line
)( !strncmpW( (WCHAR
*)expname
, (WCHAR
*)info
.dwTypeData
, out_len
),
965 "menu item name wrong\n" );
967 SetLastError( 0xdeadbeef );
968 ret
= ansi
? GetMenuStringA( hmenu
, 0, (char *)buffer
, 80, MF_BYPOSITION
) :
969 GetMenuStringW( hmenu
, 0, buffer
, 80, MF_BYPOSITION
);
971 ok_(__FILE__
, line
)( ret
, "GetMenuString failed, err %u\n", GetLastError());
973 ok_(__FILE__
, line
)( !ret
, "GetMenuString should have failed\n" );
977 static void modify_menu( int line
, HMENU hmenu
, BOOL ansi
, UINT flags
, UINT_PTR id
, void *data
)
981 SetLastError( 0xdeadbeef );
982 if (ansi
) ret
= ModifyMenuA( hmenu
, 0, flags
, id
, data
);
983 else ret
= ModifyMenuW( hmenu
, 0, flags
, id
, data
);
984 ok_(__FILE__
,line
)( ret
, "ModifyMenuA failed, err %u\n", GetLastError());
987 static void set_menu_item_info( int line
, HMENU hmenu
, BOOL ansi
, UINT mask
, UINT type
, UINT state
,
988 UINT id
, HMENU submenu
, HBITMAP checked
, HBITMAP unchecked
, ULONG_PTR data
,
989 void *type_data
, UINT len
, HBITMAP item
)
995 /* magic bitmap handle to test smaller cbSize */
996 if (item
== (HBITMAP
)(ULONG_PTR
)0xdeadbeef)
997 info
.cbSize
= FIELD_OFFSET(MENUITEMINFOA
,hbmpItem
);
999 info
.cbSize
= sizeof(info
);
1002 info
.fState
= state
;
1004 info
.hSubMenu
= submenu
;
1005 info
.hbmpChecked
= checked
;
1006 info
.hbmpUnchecked
= unchecked
;
1007 info
.dwItemData
= data
;
1008 info
.dwTypeData
= type_data
;
1010 info
.hbmpItem
= item
;
1011 SetLastError( 0xdeadbeef );
1012 if (ansi
) ret
= SetMenuItemInfoA( hmenu
, 0, TRUE
, &info
);
1013 else ret
= SetMenuItemInfoW( hmenu
, 0, TRUE
, (MENUITEMINFOW
*)&info
);
1014 ok_(__FILE__
, line
)( ret
, "SetMenuItemInfo failed, err %u\n", GetLastError());
1017 #define TMII_INSMI( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,eret1 )\
1018 hmenu = CreateMenu();\
1019 submenu = CreateMenu();\
1020 if(ansi)strcpy( string, init );\
1021 else strcpyW( string, init );\
1022 insert_menu_item( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, eret1 )
1024 /* GetMenuItemInfo + GetMenuString */
1025 #define TMII_GMII( c2,l2,\
1026 d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,\
1027 expname, eret2, eret3)\
1028 check_menu_item_info( __LINE__, hmenu, ansi, c2, d3, e3, f3, g3, h3, i3, j3, k3, l2, l3, m3, \
1029 expname, eret2, eret3 )
1032 RemoveMenu(hmenu, 0, TRUE );\
1033 DestroyMenu( hmenu );\
1034 DestroyMenu( submenu );
1037 #define TMII_MODM( flags, id, data ) \
1038 modify_menu( __LINE__, hmenu, ansi, flags, id, data )
1040 /* SetMenuItemInfo */
1041 #define TMII_SMII( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1 ) \
1042 set_menu_item_info( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1 )
1049 static void test_menu_iteminfo( void )
1055 WCHAR txtW
[]={'W','i','n','e',0};
1056 WCHAR initW
[]={'X','Y','Z',0};
1058 void *txt
, *init
, *empty
, *string
;
1059 HBITMAP hbm
= CreateBitmap(1,1,1,1,NULL
);
1061 HMENU hmenu
, submenu
=CreateMenu();
1062 HBITMAP dummy_hbm
= (HBITMAP
)(ULONG_PTR
)0xdeadbeef;
1065 if( ansi
) {txt
=txtA
;init
=initA
;empty
=emptyA
;string
=stringA
;}
1066 else {txt
=txtW
;init
=initW
;empty
=emptyW
;string
=stringA
;}
1067 trace( "%s string %p hbm %p txt %p\n", ansi
? "ANSI tests: " : "Unicode tests:", string
, hbm
, txt
);
1068 /* test all combinations of MFT_STRING, MFT_OWNERDRAW and MFT_BITMAP */
1069 /* (since MFT_STRING is zero, there are four of them) */
1070 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, 0, 0, 0, 0, 0, 0, txt
, 0, 0, OK
);
1071 TMII_GMII ( MIIM_TYPE
, 80,
1072 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1075 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1076 TMII_GMII ( MIIM_TYPE
, 80,
1077 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1080 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, 6, 0, OK
);
1081 TMII_GMII ( MIIM_TYPE
, 80,
1082 MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1085 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, hbm
, 6, 0, OK
);
1086 TMII_GMII ( MIIM_TYPE
, 80,
1087 MFT_BITMAP
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1090 /* not enough space for name*/
1091 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1092 TMII_GMII ( MIIM_TYPE
, 0,
1093 MFT_STRING
, 0, 0, 0, 0, 0, 0, NULL
, 4, 0,
1096 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1097 TMII_GMII ( MIIM_TYPE
, 5,
1098 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1101 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1102 TMII_GMII ( MIIM_TYPE
, 4,
1103 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 3, 0,
1106 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1107 TMII_GMII ( MIIM_TYPE
, 0,
1108 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 0, 0,
1111 /* cannot combine MIIM_TYPE with some other flags */
1112 TMII_INSMI( MIIM_TYPE
|MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, ER
);
1114 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1115 TMII_GMII ( MIIM_TYPE
|MIIM_STRING
, 80,
1116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1119 TMII_INSMI( MIIM_TYPE
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, ER
);
1121 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1122 TMII_GMII ( MIIM_TYPE
|MIIM_FTYPE
, 80,
1123 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1126 TMII_INSMI( MIIM_TYPE
|MIIM_BITMAP
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, 6, hbm
, ER
);
1128 /* but succeeds with some others */
1129 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1130 TMII_GMII ( MIIM_TYPE
|MIIM_SUBMENU
, 80,
1131 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1134 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1135 TMII_GMII ( MIIM_TYPE
|MIIM_STATE
, 80,
1136 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1139 TMII_INSMI( MIIM_TYPE
|MIIM_ID
, MFT_STRING
, -1, 888, 0, 0, 0, -1, txt
, 6, 0, OK
);
1140 TMII_GMII ( MIIM_TYPE
|MIIM_ID
, 80,
1141 MFT_STRING
, 0, 888, 0, 0, 0, 0, string
, 4, 0,
1144 TMII_INSMI( MIIM_TYPE
|MIIM_DATA
, MFT_STRING
, -1, -1, 0, 0, 0, 999, txt
, 6, 0, OK
);
1145 TMII_GMII ( MIIM_TYPE
|MIIM_DATA
, 80,
1146 MFT_STRING
, 0, 0, 0, 0, 0, 999, string
, 4, 0,
1149 /* to be continued */
1150 /* set text with MIIM_TYPE and retrieve with MIIM_STRING */
1151 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1152 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1153 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1156 /* set text with MIIM_TYPE and retrieve with MIIM_STRING; MFT_OWNERDRAW causes an empty string */
1157 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1158 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1159 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1162 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1163 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1164 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1167 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1168 TMII_GMII ( MIIM_FTYPE
, 80,
1169 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 80, 0,
1172 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1174 0, 0, 0, 0, 0, 0, 0, string
, 80, 0,
1177 /* contrary to MIIM_TYPE,you can set the text for an owner draw menu */
1178 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1179 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1180 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1183 /* same but retrieve with MIIM_TYPE */
1184 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1185 TMII_GMII ( MIIM_TYPE
, 80,
1186 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1189 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1190 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1191 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1194 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1195 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1196 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1200 /* How is that with bitmaps? */
1201 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1202 TMII_GMII ( MIIM_TYPE
, 80,
1203 MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1206 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1207 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1208 0, 0, 0, 0, 0, 0, 0, string
, 80, hbm
,
1211 /* MIIM_BITMAP does not like MFT_BITMAP */
1212 TMII_INSMI( MIIM_BITMAP
|MIIM_FTYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, ER
);
1214 /* no problem with OWNERDRAWN */
1215 TMII_INSMI( MIIM_BITMAP
|MIIM_FTYPE
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1216 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1217 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 80, hbm
,
1220 /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1221 TMII_INSMI( MIIM_FTYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER
);
1224 /* menu with submenu */
1225 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, submenu
, 0, 0, -1, txt
, 0, 0, OK
);
1226 TMII_GMII ( MIIM_SUBMENU
, 80,
1227 0, 0, 0, submenu
, 0, 0, 0, string
, 80, 0,
1230 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, submenu
, 0, 0, -1, empty
, 0, 0, OK
);
1231 TMII_GMII ( MIIM_SUBMENU
, 80,
1232 0, 0, 0, submenu
, 0, 0, 0, string
, 80, 0,
1235 /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1236 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, submenu
, 0, 0, -1, txt
, 0, 0, OK
);
1237 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1238 MFT_STRING
|MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1240 TMII_GMII ( MIIM_SUBMENU
|MIIM_FTYPE
, 80,
1241 MFT_SEPARATOR
, 0, 0, submenu
, 0, 0, 0, string
, 80, 0,
1244 /* menu with invalid submenu */
1245 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, (HMENU
)999, 0, 0, -1, txt
, 0, 0, ER
);
1248 TMII_INSMI( MIIM_TYPE
, MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, txt
, 0, 0, OK
);
1249 TMII_GMII ( MIIM_TYPE
, 80,
1250 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1253 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
|MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, hbm
, 6, 0, OK
);
1254 TMII_GMII ( MIIM_TYPE
, 80,
1255 MFT_BITMAP
|MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1258 /* SEPARATOR and STRING go well together */
1259 /* BITMAP and STRING go well together */
1260 TMII_INSMI( MIIM_STRING
|MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1261 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, 80,
1262 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, hbm
,
1265 /* BITMAP, SEPARATOR and STRING go well together */
1266 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1267 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, 80,
1268 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 4, hbm
,
1271 /* last two tests, but use MIIM_TYPE to retrieve info */
1272 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1273 TMII_GMII ( MIIM_TYPE
, 80,
1274 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1277 TMII_INSMI( MIIM_STRING
|MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1278 TMII_GMII ( MIIM_TYPE
, 80,
1279 MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1282 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1283 TMII_GMII ( MIIM_TYPE
, 80,
1284 MFT_SEPARATOR
|MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1287 /* same three with MFT_OWNERDRAW */
1288 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
, MFT_SEPARATOR
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1289 TMII_GMII ( MIIM_TYPE
, 80,
1290 MFT_SEPARATOR
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1293 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1294 TMII_GMII ( MIIM_TYPE
, 80,
1295 MFT_BITMAP
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1298 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1299 TMII_GMII ( MIIM_TYPE
, 80,
1300 MFT_SEPARATOR
|MFT_BITMAP
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1304 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
|MIIM_ID
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1305 TMII_GMII ( MIIM_TYPE
, 80,
1306 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1309 /* test with modifymenu: string is preserved after setting OWNERDRAW */
1310 TMII_INSMI( MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1311 TMII_MODM( MFT_OWNERDRAW
, -1, (void*)787 );
1312 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_DATA
, 80,
1313 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 787, string
, 4, 0,
1316 /* same with bitmap: now the text is cleared */
1317 TMII_INSMI( MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1318 TMII_MODM( MFT_BITMAP
, 545, hbm
);
1319 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1320 MFT_BITMAP
, 0, 545, 0, 0, 0, 0, string
, 0, hbm
,
1323 /* start with bitmap: now setting text clears it (though he flag is raised) */
1324 TMII_INSMI( MIIM_BITMAP
, MFT_STRING
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1325 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1326 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 0, hbm
,
1328 TMII_MODM( MFT_STRING
, 545, txt
);
1329 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1330 MFT_STRING
, 0, 545, 0, 0, 0, 0, string
, 4, 0,
1333 /*repeat with text NULL */
1334 TMII_INSMI( MIIM_BITMAP
, MFT_STRING
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1335 TMII_MODM( MFT_STRING
, 545, NULL
);
1336 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1337 MFT_SEPARATOR
, 0, 545, 0, 0, 0, 0, string
, 0, 0,
1340 /* repeat with text "" */
1341 TMII_INSMI( MIIM_BITMAP
, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1342 TMII_MODM( MFT_STRING
, 545, empty
);
1343 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1344 MFT_STRING
, 0, 545, 0, 0, 0, 0, string
, 0, 0,
1347 /* start with bitmap: set ownerdraw */
1348 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1349 TMII_MODM( MFT_OWNERDRAW
, -1, (void *)232 );
1350 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_DATA
, 80,
1351 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 232, string
, 0, hbm
,
1355 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1357 0, 0, 0, 0, 0, 0, 0, string
, 80, 0,
1360 /* some tests with small cbSize: the hbmpItem is to be ignored */
1361 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm
, OK
);
1362 TMII_GMII ( MIIM_TYPE
, 80,
1363 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, NULL
, 0, NULL
,
1366 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm
, OK
);
1367 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1368 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 80, NULL
,
1371 TMII_INSMI( MIIM_STRING
|MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1372 TMII_GMII ( MIIM_TYPE
, 80,
1373 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, NULL
,
1376 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1377 TMII_GMII ( MIIM_TYPE
, 80,
1378 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1381 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1382 TMII_GMII ( MIIM_TYPE
, 80,
1383 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1386 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1387 TMII_GMII ( MIIM_TYPE
, 80,
1388 MFT_SEPARATOR
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1391 /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus */
1392 TMII_INSMI( MIIM_TYPE
|MIIM_DATA
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, 343, txt
, 0, 0, OK
);
1393 TMII_GMII ( MIIM_TYPE
|MIIM_DATA
, 80,
1394 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1397 TMII_INSMI( MIIM_TYPE
|MIIM_DATA
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, 343, txt
, 0, 0, OK
);
1398 TMII_GMII ( MIIM_TYPE
, 80,
1399 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1402 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, 343, txt
, 0, 0, OK
);
1403 TMII_GMII ( MIIM_TYPE
|MIIM_DATA
, 80,
1404 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1407 /* set a string menu to ownerdraw with MIIM_TYPE */
1408 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -2, -2, 0, 0, 0, -2, txt
, -2, 0, OK
);
1409 TMII_SMII ( MIIM_TYPE
, MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1410 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1411 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1414 /* test with modifymenu add submenu */
1415 TMII_INSMI( MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1416 TMII_MODM( MF_POPUP
, (UINT_PTR
)submenu
, txt
);
1417 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_SUBMENU
, 80,
1418 MFT_STRING
, 0, 0, submenu
, 0, 0, 0, string
, 4, 0,
1420 TMII_GMII ( MIIM_TYPE
, 80,
1421 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1424 /* MFT_SEPARATOR bit is kept when the text is added */
1425 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1426 TMII_SMII( MIIM_STRING
, 0, 0, 0, 0, 0, 0, 0, txt
, 0, 0 );
1427 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1428 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1431 /* MFT_SEPARATOR bit is kept when bitmap is added */
1432 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1433 TMII_SMII( MIIM_BITMAP
, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm
);
1434 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1435 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 80, hbm
,
1438 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1439 Only the low word of the dwTypeData is used.
1440 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1441 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_RIGHTJUSTIFY
, -1, -1, 0, 0, 0, -1,
1442 (HMENU
)MAKELONG(HBMMENU_MBAR_CLOSE
, 0x1234), -1, 0, OK
);
1443 TMII_GMII ( MIIM_TYPE
, 80,
1444 MFT_BITMAP
| MFT_RIGHTJUSTIFY
, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE
, 0, HBMMENU_MBAR_CLOSE
,
1448 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1449 TMII_GMII ( MIIM_TYPE
, 80,
1450 MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1454 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1455 TMII_SMII( MIIM_STATE
, -1, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 0, 0 );
1456 TMII_GMII ( MIIM_STATE
, 80,
1457 0, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 80, 0,
1460 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1461 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1462 TMII_SMII( MIIM_CHECKMARKS
, MFT_RADIOCHECK
, 0, 0, 0, hbm
, hbm
, 0, 0, 0, 0 );
1463 TMII_GMII ( MIIM_CHECKMARKS
| MIIM_TYPE
, 80,
1464 MFT_BITMAP
, 0, 0, 0, hbm
, hbm
, 0, hbm
, 0, hbm
,
1467 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1468 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1469 TMII_SMII( MIIM_FTYPE
, MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, (HBITMAP
)0x1234, 0, 0 );
1470 TMII_GMII ( MIIM_FTYPE
, 80,
1471 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1473 TMII_GMII ( MIIM_TYPE
, 80,
1474 MFT_BITMAP
| MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1476 TMII_GMII ( MIIM_FTYPE
, 80,
1477 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1479 TMII_SMII( MIIM_BITMAP
, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
);
1480 TMII_GMII ( MIIM_TYPE
, 80,
1481 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 0, NULL
,
1484 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1485 Only the low word of the dwTypeData is used.
1486 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1487 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_RIGHTJUSTIFY
, -1, -1, 0, 0, 0, -1,
1488 (HMENU
)MAKELONG(HBMMENU_MBAR_CLOSE
, 0x1234), -1, 0, OK
);
1489 TMII_GMII ( MIIM_TYPE
, 80,
1490 MFT_BITMAP
| MFT_RIGHTJUSTIFY
, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE
, 0, HBMMENU_MBAR_CLOSE
,
1494 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1495 TMII_GMII ( MIIM_TYPE
, 80,
1496 MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1500 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1501 TMII_SMII( MIIM_STATE
, -1, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 0, 0 );
1502 TMII_GMII ( MIIM_STATE
, 80,
1503 0, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 80, 0,
1506 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1507 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1508 TMII_SMII( MIIM_CHECKMARKS
, MFT_RADIOCHECK
, 0, 0, 0, hbm
, hbm
, 0, 0, 0, 0 );
1509 TMII_GMII ( MIIM_CHECKMARKS
| MIIM_TYPE
, 80,
1510 MFT_BITMAP
, 0, 0, 0, hbm
, hbm
, 0, hbm
, 0, hbm
,
1513 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1514 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1515 TMII_SMII( MIIM_FTYPE
, MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, (HBITMAP
)0x1234, 0, 0 );
1516 TMII_GMII ( MIIM_FTYPE
, 80,
1517 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1519 TMII_GMII ( MIIM_TYPE
, 80,
1520 MFT_BITMAP
| MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1522 TMII_GMII ( MIIM_FTYPE
, 80,
1523 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1525 TMII_SMII( MIIM_BITMAP
, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
);
1526 TMII_GMII ( MIIM_TYPE
, 80,
1527 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 0, NULL
,
1530 } while( !(ansi
= !ansi
) );
1535 The following tests try to confirm the algorithm used to return the menu items
1536 when there is a collision between a menu item and a popup menu
1538 static void test_menu_search_bycommand( void )
1540 HMENU hmenu
, hmenuSub
, hmenuSub2
;
1546 static CHAR menuitem
[] = "MenuItem",
1547 menuitem2
[] = "MenuItem 2";
1549 /* Case 1: Menu containing a menu item */
1550 hmenu
= CreateMenu();
1552 memset( &info
, 0, sizeof info
);
1553 info
.cbSize
= sizeof info
;
1554 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1555 info
.fType
= MFT_STRING
;
1556 strcpy(strIn
, "Case 1 MenuItem");
1557 info
.dwTypeData
= strIn
;
1558 info
.wID
= (UINT
) 0x1234;
1560 rc
= InsertMenuItem(hmenu
, 0, TRUE
, &info
);
1561 ok (rc
, "Inserting the menuitem failed\n");
1563 id
= GetMenuItemID(hmenu
, 0);
1564 ok (id
== 0x1234, "Getting the menuitem id failed(gave %x)\n", id
);
1566 /* Confirm the menuitem was given the id supplied (getting by position) */
1567 memset( &info
, 0, sizeof info
);
1569 info
.cbSize
= sizeof(MENUITEMINFO
);
1570 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1571 info
.dwTypeData
= strback
;
1572 info
.cch
= sizeof(strback
);
1574 rc
= GetMenuItemInfo(hmenu
, 0, TRUE
, &info
); /* Get by position */
1575 ok (rc
, "Getting the menu items info failed\n");
1576 ok (info
.wID
== 0x1234, "IDs differ for the menuitem\n");
1577 ok (!strcmp(info
.dwTypeData
, "Case 1 MenuItem"), "Returned item has wrong label\n");
1579 /* Search by id - Should return the item */
1580 memset( &info
, 0, sizeof info
);
1582 info
.cbSize
= sizeof(MENUITEMINFO
);
1583 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1584 info
.dwTypeData
= strback
;
1585 info
.cch
= sizeof(strback
);
1586 rc
= GetMenuItemInfo(hmenu
, 0x1234, FALSE
, &info
); /* Get by ID */
1588 ok (rc
, "Getting the menu items info failed\n");
1589 ok (info
.wID
== 0x1234, "IDs differ for the menuitem\n");
1590 ok (!strcmp(info
.dwTypeData
, "Case 1 MenuItem"), "Returned item has wrong label\n");
1592 DestroyMenu( hmenu
);
1594 /* Case 2: Menu containing a popup menu */
1595 hmenu
= CreateMenu();
1596 hmenuSub
= CreateMenu();
1598 strcpy(strIn
, "Case 2 SubMenu");
1599 rc
= InsertMenu(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, strIn
);
1600 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1602 id
= GetMenuItemID(hmenu
, 0);
1603 ok (id
== -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id
);
1605 /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
1606 memset( &info
, 0, sizeof info
);
1608 info
.cbSize
= sizeof(MENUITEMINFO
);
1609 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1610 info
.dwTypeData
= strback
;
1611 info
.cch
= sizeof(strback
);
1612 info
.wID
= 0xdeadbeef;
1614 rc
= GetMenuItemInfo(hmenu
, 0, TRUE
, &info
); /* Get by position */
1615 ok (rc
, "Getting the menu items info failed\n");
1616 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the menuitem\n");
1617 ok (!strcmp(info
.dwTypeData
, "Case 2 SubMenu"), "Returned item has wrong label\n");
1619 /* Search by id - returns the popup menu itself */
1620 memset( &info
, 0, sizeof info
);
1622 info
.cbSize
= sizeof(MENUITEMINFO
);
1623 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1624 info
.dwTypeData
= strback
;
1625 info
.cch
= sizeof(strback
);
1626 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
); /* Get by ID */
1628 ok (rc
, "Getting the menu items info failed\n");
1629 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the popup menu\n");
1630 ok (!strcmp(info
.dwTypeData
, "Case 2 SubMenu"), "Returned item has wrong label\n");
1633 Now add an item after it with the same id
1635 memset( &info
, 0, sizeof info
);
1636 info
.cbSize
= sizeof info
;
1637 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1638 info
.fType
= MFT_STRING
;
1639 strcpy(strIn
, "Case 2 MenuItem 1");
1640 info
.dwTypeData
= strIn
;
1641 info
.wID
= (UINT_PTR
) hmenuSub
;
1642 rc
= InsertMenuItem(hmenu
, -1, TRUE
, &info
);
1643 ok (rc
, "Inserting the menuitem failed\n");
1645 /* Search by id - returns the item which follows the popup menu */
1646 memset( &info
, 0, sizeof info
);
1648 info
.cbSize
= sizeof(MENUITEMINFO
);
1649 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1650 info
.dwTypeData
= strback
;
1651 info
.cch
= sizeof(strback
);
1652 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
); /* Get by ID */
1654 ok (rc
, "Getting the menu items info failed\n");
1655 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the popup menu\n");
1656 ok (!strcmp(info
.dwTypeData
, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1659 Now add an item before the popup (with the same id)
1661 memset( &info
, 0, sizeof info
);
1662 info
.cbSize
= sizeof info
;
1663 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1664 info
.fType
= MFT_STRING
;
1665 strcpy(strIn
, "Case 2 MenuItem 2");
1666 info
.dwTypeData
= strIn
;
1667 info
.wID
= (UINT_PTR
) hmenuSub
;
1668 rc
= InsertMenuItem(hmenu
, 0, TRUE
, &info
);
1669 ok (rc
, "Inserting the menuitem failed\n");
1671 /* Search by id - returns the item which precedes the popup menu */
1672 memset( &info
, 0, sizeof info
);
1674 info
.cbSize
= sizeof(MENUITEMINFO
);
1675 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1676 info
.dwTypeData
= strback
;
1677 info
.cch
= sizeof(strback
);
1678 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
); /* Get by ID */
1680 ok (rc
, "Getting the menu items info failed\n");
1681 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the popup menu\n");
1682 ok (!strcmp(info
.dwTypeData
, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1684 DestroyMenu( hmenu
);
1685 DestroyMenu( hmenuSub
);
1688 Case 3: Menu containing a popup menu which in turn
1689 contains 2 items with the same id as the popup itself
1692 hmenu
= CreateMenu();
1693 hmenuSub
= CreateMenu();
1695 memset( &info
, 0, sizeof info
);
1696 info
.cbSize
= sizeof info
;
1697 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1698 info
.fType
= MFT_STRING
;
1699 info
.dwTypeData
= menuitem
;
1700 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1702 rc
= InsertMenu(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, "Submenu");
1703 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1705 rc
= InsertMenuItem(hmenuSub
, 0, TRUE
, &info
);
1706 ok (rc
, "Inserting the sub menu menuitem failed\n");
1708 memset( &info
, 0, sizeof info
);
1709 info
.cbSize
= sizeof info
;
1710 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1711 info
.fType
= MFT_STRING
;
1712 info
.dwTypeData
= menuitem2
;
1713 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1715 rc
= InsertMenuItem(hmenuSub
, 1, TRUE
, &info
);
1716 ok (rc
, "Inserting the sub menu menuitem 2 failed\n");
1718 /* Prove that you can't query the id of a popup directly (By position) */
1719 id
= GetMenuItemID(hmenu
, 0);
1720 ok (id
== -1, "Getting the sub menu id should have failed because its a popup (gave %x)\n", id
);
1722 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1723 memset( &info
, 0, sizeof info
);
1725 info
.cbSize
= sizeof(MENUITEMINFO
);
1726 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1727 info
.dwTypeData
= strback
;
1728 info
.cch
= sizeof(strback
);
1730 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
);
1731 ok (rc
, "Getting the menus info failed\n");
1732 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for popup menu\n");
1733 ok (!strcmp(info
.dwTypeData
, "MenuItem"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1734 DestroyMenu( hmenu
);
1735 DestroyMenu( hmenuSub
);
1738 Case 4: Menu containing 2 popup menus, the second
1739 contains 2 items with the same id as the first popup menu
1741 hmenu
= CreateMenu();
1742 hmenuSub
= CreateMenu();
1743 hmenuSub2
= CreateMenu();
1745 rc
= InsertMenu(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, "Submenu");
1746 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1748 rc
= InsertMenu(hmenu
, 1, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub2
, "Submenu2");
1749 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1751 memset( &info
, 0, sizeof info
);
1752 info
.cbSize
= sizeof info
;
1753 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1754 info
.fType
= MFT_STRING
;
1755 info
.dwTypeData
= menuitem
;
1756 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1758 rc
= InsertMenuItem(hmenuSub2
, 0, TRUE
, &info
);
1759 ok (rc
, "Inserting the sub menu menuitem failed\n");
1761 memset( &info
, 0, sizeof info
);
1762 info
.cbSize
= sizeof info
;
1763 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1764 info
.fType
= MFT_STRING
;
1765 info
.dwTypeData
= menuitem2
;
1766 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1768 rc
= InsertMenuItem(hmenuSub2
, 1, TRUE
, &info
);
1769 ok (rc
, "Inserting the sub menu menuitem 2 failed\n");
1771 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1772 memset( &info
, 0, sizeof info
);
1774 info
.cbSize
= sizeof(MENUITEMINFO
);
1775 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1776 info
.dwTypeData
= strback
;
1777 info
.cch
= sizeof(strback
);
1779 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
);
1780 ok (rc
, "Getting the menus info failed\n");
1781 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for popup menu\n");
1782 ok (!strcmp(info
.dwTypeData
, "MenuItem"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1784 memset( &info
, 0, sizeof info
);
1786 info
.cbSize
= sizeof(MENUITEMINFO
);
1787 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1788 info
.dwTypeData
= strback
;
1789 info
.cch
= sizeof(strback
);
1791 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub2
, FALSE
, &info
);
1792 ok (rc
, "Getting the menus info failed\n");
1793 ok (info
.wID
== (UINT_PTR
)hmenuSub2
, "IDs differ for popup menu\n");
1794 ok (!strcmp(info
.dwTypeData
, "Submenu2"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1796 DestroyMenu( hmenu
);
1797 DestroyMenu( hmenuSub
);
1798 DestroyMenu( hmenuSub2
);
1802 Case 5: Menu containing a popup menu which in turn
1803 contains an item with a different id than the popup menu.
1804 This tests the fallback to a popup menu ID.
1807 hmenu
= CreateMenu();
1808 hmenuSub
= CreateMenu();
1810 rc
= AppendMenu(hmenu
, MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, "Submenu");
1811 ok (rc
, "Appending the popup menu to the main menu failed\n");
1813 rc
= AppendMenu(hmenuSub
, MF_STRING
, 102, "Item");
1814 ok (rc
, "Appending the item to the popup menu failed\n");
1816 /* Set the ID for hmenuSub */
1817 info
.cbSize
= sizeof(info
);
1818 info
.fMask
= MIIM_ID
;
1821 rc
= SetMenuItemInfo(hmenu
, 0, TRUE
, &info
);
1822 ok(rc
, "Setting the ID for the popup menu failed\n");
1824 /* Check if the ID has been set */
1826 rc
= GetMenuItemInfo(hmenu
, 0, TRUE
, &info
);
1827 ok(rc
, "Getting the ID for the popup menu failed\n");
1828 ok(info
.wID
== 101, "The ID for the popup menu has not been set\n");
1830 /* Prove getting the item info via ID returns the popup menu */
1831 memset( &info
, 0, sizeof(info
));
1833 info
.cbSize
= sizeof(MENUITEMINFO
);
1834 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1835 info
.dwTypeData
= strback
;
1836 info
.cch
= sizeof(strback
);
1838 rc
= GetMenuItemInfo(hmenu
, 101, FALSE
, &info
);
1839 ok (rc
, "Getting the menu info failed\n");
1840 ok (info
.wID
== 101, "IDs differ\n");
1841 ok (!strcmp(info
.dwTypeData
, "Submenu"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1843 /* Also look for the menu item */
1844 memset( &info
, 0, sizeof(info
));
1846 info
.cbSize
= sizeof(MENUITEMINFO
);
1847 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1848 info
.dwTypeData
= strback
;
1849 info
.cch
= sizeof(strback
);
1851 rc
= GetMenuItemInfo(hmenu
, 102, FALSE
, &info
);
1852 ok (rc
, "Getting the menu info failed\n");
1853 ok (info
.wID
== 102, "IDs differ\n");
1854 ok (!strcmp(info
.dwTypeData
, "Item"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1857 DestroyMenu(hmenuSub
);
1860 struct menu_item_pair_s
{
1861 UINT uMenu
; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
1862 * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
1863 * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
1867 static struct menu_mouse_tests_s
{
1869 struct menu_item_pair_s menu_item_pairs
[5]; /* for mousing */
1870 WORD wVk
[5]; /* keys */
1874 /* for each test, send keys or clicks and check for menu visibility */
1875 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 0}, TRUE
, FALSE
}, /* test 0 */
1876 { INPUT_KEYBOARD
, {{0}}, {VK_ESCAPE
, 0}, FALSE
, FALSE
},
1877 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 0}, TRUE
, FALSE
},
1878 { INPUT_KEYBOARD
, {{0}}, {'D', 0}, FALSE
, FALSE
},
1879 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 0}, TRUE
, FALSE
},
1880 { INPUT_KEYBOARD
, {{0}}, {'E', 0}, FALSE
, FALSE
},
1881 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 0}, TRUE
, FALSE
},
1882 { INPUT_KEYBOARD
, {{0}}, {VK_ESCAPE
, VK_ESCAPE
, 0}, FALSE
, FALSE
},
1883 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', VK_ESCAPE
, 0}, TRUE
, FALSE
},
1884 { INPUT_KEYBOARD
, {{0}}, {VK_ESCAPE
, 0}, FALSE
, FALSE
},
1885 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 0}, TRUE
, FALSE
},
1886 { INPUT_KEYBOARD
, {{0}}, {'D', 0}, FALSE
, FALSE
},
1887 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 0}, TRUE
, FALSE
},
1888 { INPUT_KEYBOARD
, {{0}}, {'E', 0}, FALSE
, FALSE
},
1889 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 'P', 0}, TRUE
, FALSE
},
1890 { INPUT_KEYBOARD
, {{0}}, {'D', 0}, FALSE
, FALSE
},
1891 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 'P', 0}, TRUE
, FALSE
},
1892 { INPUT_KEYBOARD
, {{0}}, {'E', 0}, FALSE
, FALSE
},
1893 { INPUT_KEYBOARD
, {{0}}, {VK_F10
, 0}, TRUE
, FALSE
},
1894 { INPUT_KEYBOARD
, {{0}}, {VK_F10
, 0}, FALSE
, FALSE
},
1896 { INPUT_MOUSE
, {{1, 2}, {0}}, {0}, TRUE
, TRUE
}, /* test 20 */
1897 { INPUT_MOUSE
, {{1, 1}, {0}}, {0}, FALSE
, FALSE
},
1898 { INPUT_MOUSE
, {{1, 0}, {0}}, {0}, TRUE
, TRUE
},
1899 { INPUT_MOUSE
, {{1, 1}, {0}}, {0}, FALSE
, FALSE
},
1900 { INPUT_MOUSE
, {{1, 0}, {2, 2}, {0}}, {0}, TRUE
, TRUE
},
1901 { INPUT_MOUSE
, {{2, 1}, {0}}, {0}, FALSE
, FALSE
},
1902 { INPUT_MOUSE
, {{1, 0}, {2, 0}, {0}}, {0}, TRUE
, TRUE
},
1903 { INPUT_MOUSE
, {{3, 0}, {0}}, {0}, FALSE
, FALSE
},
1904 { INPUT_MOUSE
, {{1, 0}, {2, 0}, {0}}, {0}, TRUE
, TRUE
},
1905 { INPUT_MOUSE
, {{3, 1}, {0}}, {0}, TRUE
, TRUE
},
1906 { INPUT_MOUSE
, {{1, 1}, {0}}, {0}, FALSE
, FALSE
},
1910 static void send_key(WORD wVk
)
1913 memset(i
, 0, sizeof(i
));
1914 i
[0].type
= i
[1].type
= INPUT_KEYBOARD
;
1915 i
[0].u
.ki
.wVk
= i
[1].u
.ki
.wVk
= wVk
;
1916 i
[1].u
.ki
.dwFlags
= KEYEVENTF_KEYUP
;
1917 pSendInput(2, (INPUT
*) i
, sizeof(INPUT
));
1920 static BOOL
click_menu(HANDLE hWnd
, struct menu_item_pair_s
*mi
)
1922 HMENU hMenu
= hMenus
[mi
->uMenu
];
1926 int screen_w
= GetSystemMetrics(SM_CXSCREEN
);
1927 int screen_h
= GetSystemMetrics(SM_CYSCREEN
);
1928 BOOL ret
= GetMenuItemRect(mi
->uMenu
> 2 ? NULL
: hWnd
, hMenu
, mi
->uItem
, &r
);
1929 if(!ret
) return FALSE
;
1931 memset(i
, 0, sizeof(i
));
1932 i
[0].type
= i
[1].type
= i
[2].type
= INPUT_MOUSE
;
1933 i
[0].u
.mi
.dx
= i
[1].u
.mi
.dx
= i
[2].u
.mi
.dx
1934 = ((r
.left
+ 5) * 65535) / screen_w
;
1935 i
[0].u
.mi
.dy
= i
[1].u
.mi
.dy
= i
[2].u
.mi
.dy
1936 = ((r
.top
+ 5) * 65535) / screen_h
;
1937 i
[0].u
.mi
.dwFlags
= i
[1].u
.mi
.dwFlags
= i
[2].u
.mi
.dwFlags
1938 = MOUSEEVENTF_ABSOLUTE
;
1939 i
[0].u
.mi
.dwFlags
|= MOUSEEVENTF_MOVE
;
1940 i
[1].u
.mi
.dwFlags
|= MOUSEEVENTF_LEFTDOWN
;
1941 i
[2].u
.mi
.dwFlags
|= MOUSEEVENTF_LEFTUP
;
1942 ret
= pSendInput(3, (INPUT
*) i
, sizeof(INPUT
));
1944 /* hack to prevent mouse message buildup in Wine */
1945 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
1949 static DWORD WINAPI
test_menu_input_thread(LPVOID lpParameter
)
1952 HANDLE hWnd
= lpParameter
;
1955 /* mixed keyboard/mouse test */
1956 for (i
= 0; menu_tests
[i
].type
!= -1; i
++)
1958 int ret
= TRUE
, elapsed
= 0;
1960 got_input
= i
&& menu_tests
[i
-1].bMenuVisible
;
1962 if (menu_tests
[i
].type
== INPUT_KEYBOARD
)
1963 for (j
= 0; menu_tests
[i
].wVk
[j
] != 0; j
++)
1964 send_key(menu_tests
[i
].wVk
[j
]);
1966 for (j
= 0; menu_tests
[i
].menu_item_pairs
[j
].uMenu
!= 0; j
++)
1967 if (!(ret
= click_menu(hWnd
, &menu_tests
[i
].menu_item_pairs
[j
]))) break;
1971 skip( "test %u: failed to send input\n", i
);
1972 PostMessage( hWnd
, WM_CANCELMODE
, 0, 0 );
1975 while (menu_tests
[i
].bMenuVisible
!= bMenuVisible
)
1985 skip( "test %u: didn't receive input\n", i
);
1986 PostMessage( hWnd
, WM_CANCELMODE
, 0, 0 );
1990 if (menu_tests
[i
]._todo_wine
)
1993 ok(menu_tests
[i
].bMenuVisible
== bMenuVisible
, "test %d\n", i
);
1997 ok(menu_tests
[i
].bMenuVisible
== bMenuVisible
, "test %d\n", i
);
2002 static LRESULT CALLBACK
WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
,
2006 case WM_ENTERMENULOOP
:
2007 bMenuVisible
= TRUE
;
2009 case WM_EXITMENULOOP
:
2010 bMenuVisible
= FALSE
;
2015 case WM_LBUTTONDOWN
:
2017 case WM_NCMOUSEMOVE
:
2018 case WM_NCLBUTTONDOWN
:
2019 case WM_NCLBUTTONUP
:
2023 return( DefWindowProcA( hWnd
, msg
, wParam
, lParam
) );
2028 static void test_menu_input(void) {
2031 HINSTANCE hInstance
= GetModuleHandleA( NULL
);
2032 HANDLE hThread
, hWnd
;
2035 wclass
.lpszClassName
= "MenuTestClass";
2036 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
2037 wclass
.lpfnWndProc
= WndProc
;
2038 wclass
.hInstance
= hInstance
;
2039 wclass
.hIcon
= LoadIconA( 0, IDI_APPLICATION
);
2040 wclass
.hCursor
= LoadCursorA( NULL
, IDC_ARROW
);
2041 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
2042 wclass
.lpszMenuName
= 0;
2043 wclass
.cbClsExtra
= 0;
2044 wclass
.cbWndExtra
= 0;
2045 assert (RegisterClassA( &wclass
));
2046 assert (hWnd
= CreateWindowA( wclass
.lpszClassName
, "MenuTest",
2047 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0,
2048 400, 200, NULL
, NULL
, hInstance
, NULL
) );
2051 hMenus
[3] = CreatePopupMenu();
2052 AppendMenu(hMenus
[3], MF_STRING
, 0, "&Enabled");
2053 AppendMenu(hMenus
[3], MF_STRING
|MF_DISABLED
, 0, "&Disabled");
2055 hMenus
[2] = CreatePopupMenu();
2056 AppendMenu(hMenus
[2], MF_STRING
|MF_POPUP
, (UINT_PTR
) hMenus
[3], "&Popup");
2057 AppendMenu(hMenus
[2], MF_STRING
, 0, "&Enabled");
2058 AppendMenu(hMenus
[2], MF_STRING
|MF_DISABLED
, 0, "&Disabled");
2060 hMenus
[1] = CreateMenu();
2061 AppendMenu(hMenus
[1], MF_STRING
|MF_POPUP
, (UINT_PTR
) hMenus
[2], "&Menu");
2062 AppendMenu(hMenus
[1], MF_STRING
, 0, "&Enabled");
2063 AppendMenu(hMenus
[1], MF_STRING
|MF_DISABLED
, 0, "&Disabled");
2065 SetMenu(hWnd
, hMenus
[1]);
2066 ShowWindow(hWnd
, SW_SHOW
);
2069 hThread
= CreateThread(NULL
, 0, test_menu_input_thread
, hWnd
, 0, &tid
);
2072 if (WAIT_TIMEOUT
!= WaitForSingleObject(hThread
, 50))
2074 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2076 DestroyWindow(hWnd
);
2079 static void test_menu_flags( void )
2081 HMENU hMenu
, hPopupMenu
;
2083 hMenu
= CreateMenu();
2084 hPopupMenu
= CreatePopupMenu();
2086 AppendMenu(hMenu
, MF_POPUP
| MF_STRING
, (UINT_PTR
)hPopupMenu
, "Popup");
2088 AppendMenu(hPopupMenu
, MF_STRING
| MF_HILITE
| MF_DEFAULT
, 101, "Item 1");
2089 InsertMenu(hPopupMenu
, 1, MF_BYPOSITION
| MF_STRING
| MF_HILITE
| MF_DEFAULT
, 102, "Item 2");
2090 AppendMenu(hPopupMenu
, MF_STRING
, 103, "Item 3");
2091 ModifyMenu(hPopupMenu
, 2, MF_BYPOSITION
| MF_STRING
| MF_HILITE
| MF_DEFAULT
, 103, "Item 3");
2093 ok(GetMenuState(hPopupMenu
, 0, MF_BYPOSITION
) & MF_HILITE
,
2094 "AppendMenu should accept MF_HILITE\n");
2095 ok(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
,
2096 "InsertMenu should accept MF_HILITE\n");
2097 ok(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_HILITE
,
2098 "ModifyMenu should accept MF_HILITE\n");
2100 ok(!(GetMenuState(hPopupMenu
, 0, MF_BYPOSITION
) & MF_DEFAULT
),
2101 "AppendMenu must not accept MF_DEFAULT\n");
2102 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_DEFAULT
),
2103 "InsertMenu must not accept MF_DEFAULT\n");
2104 ok(!(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_DEFAULT
),
2105 "ModifyMenu must not accept MF_DEFAULT\n");
2110 static void test_menu_hilitemenuitem( void )
2112 HMENU hMenu
, hPopupMenu
;
2116 wclass
.lpszClassName
= "HiliteMenuTestClass";
2117 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
2118 wclass
.lpfnWndProc
= WndProc
;
2119 wclass
.hInstance
= GetModuleHandleA( NULL
);
2120 wclass
.hIcon
= LoadIconA( 0, IDI_APPLICATION
);
2121 wclass
.hCursor
= LoadCursorA( NULL
, IDC_ARROW
);
2122 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
2123 wclass
.lpszMenuName
= 0;
2124 wclass
.cbClsExtra
= 0;
2125 wclass
.cbWndExtra
= 0;
2126 assert (RegisterClassA( &wclass
));
2127 assert (hWnd
= CreateWindowA( wclass
.lpszClassName
, "HiliteMenuTest",
2128 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0,
2129 400, 200, NULL
, NULL
, wclass
.hInstance
, NULL
) );
2131 hMenu
= CreateMenu();
2132 hPopupMenu
= CreatePopupMenu();
2134 AppendMenu(hMenu
, MF_POPUP
| MF_STRING
, (UINT_PTR
)hPopupMenu
, "Popup");
2136 AppendMenu(hPopupMenu
, MF_STRING
, 101, "Item 1");
2137 AppendMenu(hPopupMenu
, MF_STRING
, 102, "Item 2");
2138 AppendMenu(hPopupMenu
, MF_STRING
, 103, "Item 3");
2140 SetMenu(hWnd
, hMenu
);
2142 /* test invalid arguments */
2144 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2145 "HiliteMenuItem: Item 2 is hilited\n");
2147 SetLastError(0xdeadbeef);
2150 ok(!HiliteMenuItem(NULL
, hPopupMenu
, 1, MF_HILITE
| MF_BYPOSITION
),
2151 "HiliteMenuItem: call should have failed.\n");
2153 ok(GetLastError() == 0xdeadbeef || /* 9x */
2154 GetLastError() == ERROR_INVALID_WINDOW_HANDLE
/* NT */,
2155 "HiliteMenuItem: expected error ERROR_INVALID_WINDOW_HANDLE, got: %d\n", GetLastError());
2157 SetLastError(0xdeadbeef);
2158 ok(!HiliteMenuItem(hWnd
, NULL
, 1, MF_HILITE
| MF_BYPOSITION
),
2159 "HiliteMenuItem: call should have failed.\n");
2160 ok(GetLastError() == 0xdeadbeef || /* 9x */
2161 GetLastError() == ERROR_INVALID_MENU_HANDLE
/* NT */,
2162 "HiliteMenuItem: expected error ERROR_INVALID_MENU_HANDLE, got: %d\n", GetLastError());
2164 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2165 "HiliteMenuItem: Item 2 is hilited\n");
2167 /* either MF_HILITE or MF_UNHILITE *and* MF_BYCOMMAND or MF_BYPOSITION need to be set */
2169 SetLastError(0xdeadbeef);
2170 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_BYPOSITION
),
2171 "HiliteMenuItem: call should have succeeded.\n");
2172 ok(GetLastError() == 0xdeadbeef,
2173 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2175 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2176 "HiliteMenuItem: Item 2 is hilited\n");
2178 SetLastError(0xdeadbeef);
2181 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_HILITE
),
2182 "HiliteMenuItem: call should have succeeded.\n");
2184 ok(GetLastError() == 0xdeadbeef,
2185 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2187 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2188 "HiliteMenuItem: Item 2 is hilited\n");
2190 /* hilite a menu item (by position) */
2192 SetLastError(0xdeadbeef);
2193 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_HILITE
| MF_BYPOSITION
),
2194 "HiliteMenuItem: call should not have failed.\n");
2195 ok(GetLastError() == 0xdeadbeef,
2196 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2200 ok(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
,
2201 "HiliteMenuItem: Item 2 is not hilited\n");
2204 /* unhilite a menu item (by position) */
2206 SetLastError(0xdeadbeef);
2207 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_UNHILITE
| MF_BYPOSITION
),
2208 "HiliteMenuItem: call should not have failed.\n");
2209 ok(GetLastError() == 0xdeadbeef,
2210 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2212 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2213 "HiliteMenuItem: Item 2 is hilited\n");
2215 /* hilite a menu item (by command) */
2217 SetLastError(0xdeadbeef);
2218 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 103, MF_HILITE
| MF_BYCOMMAND
),
2219 "HiliteMenuItem: call should not have failed.\n");
2220 ok(GetLastError() == 0xdeadbeef,
2221 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2225 ok(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_HILITE
,
2226 "HiliteMenuItem: Item 3 is not hilited\n");
2229 /* unhilite a menu item (by command) */
2231 SetLastError(0xdeadbeef);
2232 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 103, MF_UNHILITE
| MF_BYCOMMAND
),
2233 "HiliteMenuItem: call should not have failed.\n");
2234 ok(GetLastError() == 0xdeadbeef,
2235 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2237 ok(!(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_HILITE
),
2238 "HiliteMenuItem: Item 3 is hilited\n");
2240 DestroyWindow(hWnd
);
2243 static void check_menu_items(HMENU hmenu
, UINT checked_cmd
, UINT checked_type
,
2248 count
= GetMenuItemCount(hmenu
);
2249 ok (count
!= -1, "GetMenuItemCount returned -1\n");
2251 for (i
= 0; i
< count
; i
++)
2256 memset(&mii
, 0, sizeof(mii
));
2257 mii
.cbSize
= sizeof(mii
);
2258 mii
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_ID
| MIIM_SUBMENU
;
2259 ret
= GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
);
2260 ok(ret
, "GetMenuItemInfo(%u) failed\n", i
);
2262 trace("item #%u: fType %04x, fState %04x, wID %u, hSubMenu %p\n",
2263 i
, mii
.fType
, mii
.fState
, mii
.wID
, mii
.hSubMenu
);
2267 ok(mii
.wID
== (UINT_PTR
)mii
.hSubMenu
, "id %u: wID should be equal to hSubMenu\n", checked_cmd
);
2268 check_menu_items(mii
.hSubMenu
, checked_cmd
, checked_type
, checked_state
);
2272 if (mii
.wID
== checked_cmd
)
2274 ok(mii
.fType
== checked_type
, "id %u: expected fType %04x, got %04x\n", checked_cmd
, checked_type
, mii
.fType
);
2275 ok(mii
.fState
== checked_state
, "id %u: expected fState %04x, got %04x\n", checked_cmd
, checked_state
, mii
.fState
);
2276 ok(mii
.wID
!= 0, "id %u: not expected wID 0\n", checked_cmd
);
2280 ok(mii
.fType
!= MFT_RADIOCHECK
, "id %u: not expected fType MFT_RADIOCHECK on cmd %u\n", checked_cmd
, mii
.wID
);
2282 if (mii
.fType
== MFT_SEPARATOR
)
2284 ok(mii
.fState
== MFS_GRAYED
, "id %u: expected fState MFS_GRAYED, got %04x\n", checked_cmd
, mii
.fState
);
2285 ok(mii
.wID
== 0, "id %u: expected wID 0, got %u\n", checked_cmd
, mii
.wID
);
2289 ok(mii
.fState
== 0, "id %u: expected fState 0, got %04x\n", checked_cmd
, mii
.fState
);
2290 ok(mii
.wID
!= 0, "id %u: not expected wID 0\n", checked_cmd
);
2297 static void clear_ftype_and_state(HMENU hmenu
, UINT id
, UINT flags
)
2302 memset(&mii
, 0, sizeof(mii
));
2303 mii
.cbSize
= sizeof(mii
);
2304 mii
.fMask
= MIIM_FTYPE
| MIIM_STATE
;
2305 ret
= SetMenuItemInfo(hmenu
, id
, (flags
& MF_BYPOSITION
) != 0, &mii
);
2306 ok(ret
, "SetMenuItemInfo(%u) failed\n", id
);
2309 static void test_CheckMenuRadioItem(void)
2314 hmenu
= LoadMenu(GetModuleHandle(0), MAKEINTRESOURCE(1));
2317 check_menu_items(hmenu
, -1, 0, 0);
2319 ret
= CheckMenuRadioItem(hmenu
, 100, 100, 100, MF_BYCOMMAND
);
2320 ok(ret
, "CheckMenuRadioItem failed\n");
2321 check_menu_items(hmenu
, 100, MFT_RADIOCHECK
, MFS_CHECKED
);
2323 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2324 ret
= CheckMenuRadioItem(hmenu
, 100, 100, -1, MF_BYCOMMAND
);
2325 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2326 check_menu_items(hmenu
, 100, MFT_RADIOCHECK
, 0);
2329 clear_ftype_and_state(hmenu
, 100, MF_BYCOMMAND
);
2330 check_menu_items(hmenu
, -1, 0, 0);
2332 /* first and checked items are on different menus */
2333 ret
= CheckMenuRadioItem(hmenu
, 0, 300, 202, MF_BYCOMMAND
);
2334 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2335 check_menu_items(hmenu
, -1, 0, 0);
2337 ret
= CheckMenuRadioItem(hmenu
, 200, 300, 202, MF_BYCOMMAND
);
2338 ok(ret
, "CheckMenuRadioItem failed\n");
2339 check_menu_items(hmenu
, 202, MFT_RADIOCHECK
, MFS_CHECKED
);
2341 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2342 ret
= CheckMenuRadioItem(hmenu
, 202, 202, -1, MF_BYCOMMAND
);
2343 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2344 check_menu_items(hmenu
, 202, MFT_RADIOCHECK
, 0);
2347 clear_ftype_and_state(hmenu
, 202, MF_BYCOMMAND
);
2348 check_menu_items(hmenu
, -1, 0, 0);
2350 /* just for fun, try to check separator */
2351 ret
= CheckMenuRadioItem(hmenu
, 0, 300, 0, MF_BYCOMMAND
);
2352 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2353 check_menu_items(hmenu
, -1, 0, 0);
2356 static void test_menu_resource_layout(void)
2360 MENUITEMTEMPLATEHEADER mith
;
2364 { 0, 0 }, /* versionNumber, offset */
2366 /* mtOption, mtID, mtString[] '\0' terminated */
2367 MF_STRING
, 1, 'F', 0,
2370 /* MF_SEPARATOR, 4, 'S', 0, FIXME: Wine ignores 'S' */
2371 MF_STRING
|MF_GRAYED
|MF_END
, 5, 'E', 0
2376 UINT type
, state
, id
;
2380 { MF_STRING
, MF_ENABLED
, 1, "F" },
2381 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 2, "" },
2382 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 3, "" },
2383 /*{ MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 4, "S" }, FIXME: Wine ignores 'S'*/
2384 { MF_STRING
, MF_GRAYED
, 5, "E" },
2385 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 6, "" },
2386 { MF_STRING
, MF_ENABLED
, 7, "" },
2387 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 8, "" }
2393 hmenu
= LoadMenuIndirect(&menu_template
);
2394 ok(hmenu
!= 0, "LoadMenuIndirect error %u\n", GetLastError());
2396 ret
= AppendMenu(hmenu
, MF_STRING
, 6, NULL
);
2397 ok(ret
, "AppendMenu failed\n");
2398 ret
= AppendMenu(hmenu
, MF_STRING
, 7, "\0");
2399 ok(ret
, "AppendMenu failed\n");
2400 ret
= AppendMenu(hmenu
, MF_SEPARATOR
, 8, "separator");
2401 ok(ret
, "AppendMenu failed\n");
2403 count
= GetMenuItemCount(hmenu
);
2404 ok(count
== sizeof(menu_data
)/sizeof(menu_data
[0]),
2405 "expected %u menu items, got %u\n",
2406 (UINT
)(sizeof(menu_data
)/sizeof(menu_data
[0])), count
);
2408 for (i
= 0; i
< count
; i
++)
2413 memset(&mii
, 0, sizeof(mii
));
2414 mii
.cbSize
= sizeof(mii
);
2415 mii
.dwTypeData
= buf
;
2416 mii
.cch
= sizeof(buf
);
2417 mii
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_ID
| MIIM_STRING
;
2418 ret
= GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
);
2419 ok(ret
, "GetMenuItemInfo(%u) failed\n", i
);
2421 trace("item #%u: fType %04x, fState %04x, wID %u, dwTypeData %s\n",
2422 i
, mii
.fType
, mii
.fState
, mii
.wID
, (LPCSTR
)mii
.dwTypeData
);
2424 ok(mii
.fType
== menu_data
[i
].type
,
2425 "%u: expected fType %04x, got %04x\n", i
, menu_data
[i
].type
, mii
.fType
);
2426 ok(mii
.fState
== menu_data
[i
].state
,
2427 "%u: expected fState %04x, got %04x\n", i
, menu_data
[i
].state
, mii
.fState
);
2428 ok(mii
.wID
== menu_data
[i
].id
,
2429 "%u: expected wID %04x, got %04x\n", i
, menu_data
[i
].id
, mii
.wID
);
2430 ok(mii
.cch
== strlen(menu_data
[i
].str
),
2431 "%u: expected cch %u, got %u\n", i
, (UINT
)strlen(menu_data
[i
].str
), mii
.cch
);
2432 ok(!strcmp(mii
.dwTypeData
, menu_data
[i
].str
),
2433 "%u: expected dwTypeData %s, got %s\n", i
, menu_data
[i
].str
, (LPCSTR
)mii
.dwTypeData
);
2445 static HMENU
create_menu_from_data(const struct menu_data
*item
, INT item_count
)
2451 hmenu
= CreateMenu();
2454 for (i
= 0; i
< item_count
; i
++)
2456 SetLastError(0xdeadbeef);
2457 ret
= AppendMenu(hmenu
, item
[i
].type
, item
[i
].id
, item
[i
].str
);
2458 ok(ret
, "%d: AppendMenu(%04x, %04x, %p) error %u\n",
2459 i
, item
[i
].type
, item
[i
].id
, item
[i
].str
, GetLastError());
2464 /* use InsertMenuItem: does not set the MFT_BITMAP flag,
2465 * and does not accept non-magic bitmaps with invalid
2467 static HMENU
create_menuitem_from_data(const struct menu_data
*item
, INT item_count
)
2472 MENUITEMINFO mii
= { sizeof( MENUITEMINFO
)};
2474 hmenu
= CreateMenu();
2477 for (i
= 0; i
< item_count
; i
++)
2479 SetLastError(0xdeadbeef);
2481 mii
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STATE
;
2483 if( item
[i
].type
& MFT_BITMAP
)
2485 mii
.fMask
|= MIIM_BITMAP
;
2486 mii
.hbmpItem
= (HBITMAP
)item
[i
].str
;
2488 else if( item
[i
].type
& MFT_SEPARATOR
)
2489 mii
.fType
= MFT_SEPARATOR
;
2492 mii
.fMask
|= MIIM_STRING
;
2493 mii
.dwTypeData
= (LPSTR
)item
[i
].str
;
2494 mii
.cch
= strlen( item
[i
].str
);
2497 if( item
[i
].type
& MF_HELP
) mii
.fType
|= MF_HELP
;
2498 mii
.wID
= item
[i
].id
;
2499 ret
= InsertMenuItem( hmenu
, -1, TRUE
, &mii
);
2500 ok(ret
, "%d: InsertMenuItem(%04x, %04x, %p) error %u\n",
2501 i
, item
[i
].type
, item
[i
].id
, item
[i
].str
, GetLastError());
2506 static void compare_menu_data(HMENU hmenu
, const struct menu_data
*item
, INT item_count
)
2511 count
= GetMenuItemCount(hmenu
);
2512 ok(count
== item_count
, "expected %d, got %d menu items\n", count
, item_count
);
2514 for (i
= 0; i
< count
; i
++)
2519 memset(&mii
, 0, sizeof(mii
));
2520 mii
.cbSize
= sizeof(mii
);
2521 mii
.dwTypeData
= buf
;
2522 mii
.cch
= sizeof(buf
);
2523 mii
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
| MIIM_BITMAP
;
2524 ret
= GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
);
2525 ok(ret
, "GetMenuItemInfo(%u) failed\n", i
);
2527 trace("item #%u: fType %04x, fState %04x, wID %04x, hbmp %p\n",
2528 i
, mii
.fType
, mii
.fState
, mii
.wID
, mii
.hbmpItem
);
2530 ok(mii
.fType
== item
[i
].type
,
2531 "%u: expected fType %04x, got %04x\n", i
, item
[i
].type
, mii
.fType
);
2532 ok(mii
.wID
== item
[i
].id
,
2533 "%u: expected wID %04x, got %04x\n", i
, item
[i
].id
, mii
.wID
);
2534 if (mii
.hbmpItem
|| !item
[i
].str
)
2535 /* For some reason Windows sets high word to not 0 for
2538 ok(LOWORD(mii
.hbmpItem
) == LOWORD(item
[i
].str
),
2539 "%u: expected hbmpItem %p, got %p\n", i
, item
[i
].str
, mii
.hbmpItem
);
2542 ok(mii
.cch
== strlen(item
[i
].str
),
2543 "%u: expected cch %u, got %u\n", i
, (UINT
)strlen(item
[i
].str
), mii
.cch
);
2544 ok(!strcmp(mii
.dwTypeData
, item
[i
].str
),
2545 "%u: expected dwTypeData %s, got %s\n", i
, item
[i
].str
, (LPCSTR
)mii
.dwTypeData
);
2550 static void test_InsertMenu(void)
2552 HBITMAP hbm
= CreateBitmap(1,1,1,1,NULL
);
2553 /* Note: XP treats only bitmap handles 1 - 6 as "magic" ones
2554 * regardless of their id.
2556 static const struct menu_data in1
[] =
2558 { MF_STRING
, 1, "File" },
2559 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(1) },
2560 { MF_STRING
|MF_HELP
, 2, "Help" }
2562 static const struct menu_data out1
[] =
2564 { MF_STRING
, 1, "File" },
2565 { MF_STRING
|MF_HELP
, 2, "Help" },
2566 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(1) }
2568 static const struct menu_data out1a
[] =
2570 { MF_STRING
, 1, "File" },
2571 { MF_STRING
|MF_HELP
, 2, "Help" },
2572 { MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(1) }
2574 const struct menu_data in2
[] =
2576 { MF_STRING
, 1, "File" },
2577 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, (char*)hbm
},
2578 { MF_STRING
|MF_HELP
, 2, "Help" }
2580 const struct menu_data out2
[] =
2582 { MF_STRING
, 1, "File" },
2583 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, (char*)hbm
},
2584 { MF_STRING
|MF_HELP
, 2, "Help" }
2586 const struct menu_data out2a
[] =
2588 { MF_STRING
, 1, "File" },
2589 { MF_HELP
, SC_CLOSE
, (char*)hbm
},
2590 { MF_STRING
|MF_HELP
, 2, "Help" }
2592 static const struct menu_data in3
[] =
2594 { MF_STRING
, 1, "File" },
2595 { MF_SEPARATOR
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(1) },
2596 { MF_STRING
|MF_HELP
, 2, "Help" }
2598 static const struct menu_data out3
[] =
2600 { MF_STRING
, 1, "File" },
2601 { MF_SEPARATOR
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(0) },
2602 { MF_STRING
|MF_HELP
, 2, "Help" },
2604 static const struct menu_data in4
[] =
2606 { MF_STRING
, 1, "File" },
2607 { MF_BITMAP
|MF_HELP
, 1, MAKEINTRESOURCE(1) },
2608 { MF_STRING
|MF_HELP
, 2, "Help" }
2610 static const struct menu_data out4
[] =
2612 { MF_STRING
, 1, "File" },
2613 { MF_STRING
|MF_HELP
, 2, "Help" },
2614 { MF_BITMAP
|MF_HELP
, 1, MAKEINTRESOURCE(1) }
2616 static const struct menu_data out4a
[] =
2618 { MF_STRING
, 1, "File" },
2619 { MF_STRING
|MF_HELP
, 2, "Help" },
2620 { MF_HELP
, 1, MAKEINTRESOURCE(1) }
2624 #define create_menu(a) create_menu_from_data((a), sizeof(a)/sizeof((a)[0]))
2625 #define create_menuitem(a) create_menuitem_from_data((a), sizeof(a)/sizeof((a)[0]))
2626 #define compare_menu(h, a) compare_menu_data((h), (a), sizeof(a)/sizeof((a)[0]))
2628 hmenu
= create_menu(in1
);
2629 compare_menu(hmenu
, out1
);
2632 hmenu
= create_menu(in2
);
2633 compare_menu(hmenu
, out2
);
2636 hmenu
= create_menu(in3
);
2637 compare_menu(hmenu
, out3
);
2640 hmenu
= create_menu(in4
);
2641 compare_menu(hmenu
, out4
);
2644 /* now using InsertMenuItemInfo */
2645 hmenu
= create_menuitem(in1
);
2646 compare_menu(hmenu
, out1a
);
2649 hmenu
= create_menuitem(in2
);
2650 compare_menu(hmenu
, out2a
);
2653 hmenu
= create_menuitem(in3
);
2654 compare_menu(hmenu
, out3
);
2657 hmenu
= create_menuitem(in4
);
2658 compare_menu(hmenu
, out4a
);
2662 #undef create_menuitem
2666 static void test_menu_getmenuinfo(void)
2674 hmenu
= CreateMenu();
2676 /* test some parameter errors */
2677 SetLastError(0xdeadbeef);
2678 ret
= pGetMenuInfo( hmenu
, NULL
);
2679 gle
= GetLastError();
2680 ok( !ret
, "GetMenuInfo() should have failed\n");
2681 ok( gle
== ERROR_INVALID_PARAMETER
||
2682 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2683 "GetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2684 SetLastError(0xdeadbeef);
2686 ret
= pGetMenuInfo( hmenu
, &mi
);
2687 gle
= GetLastError();
2688 ok( !ret
, "GetMenuInfo() should have failed\n");
2689 ok( gle
== ERROR_INVALID_PARAMETER
||
2690 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2691 "GetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2692 SetLastError(0xdeadbeef);
2693 mi
.cbSize
= sizeof( MENUINFO
);
2694 ret
= pGetMenuInfo( hmenu
, &mi
);
2695 gle
= GetLastError();
2696 ok( ret
, "GetMenuInfo() should have succeeded\n");
2697 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2698 SetLastError(0xdeadbeef);
2700 ret
= pGetMenuInfo( NULL
, &mi
);
2701 gle
= GetLastError();
2702 ok( !ret
, "GetMenuInfo() should have failed\n");
2703 ok( gle
== ERROR_INVALID_PARAMETER
||
2704 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2705 "GetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2707 DestroyMenu( hmenu
);
2711 static void test_menu_setmenuinfo(void)
2713 HMENU hmenu
, hsubmenu
;
2715 MENUITEMINFOA mii
= {sizeof( MENUITEMINFOA
)};
2719 /* create a menu with a submenu */
2720 hmenu
= CreateMenu();
2721 hsubmenu
= CreateMenu();
2722 assert( hmenu
&& hsubmenu
);
2723 mii
.fMask
= MIIM_SUBMENU
;
2724 mii
.hSubMenu
= hsubmenu
;
2725 ret
= InsertMenuItem( hmenu
, 0, FALSE
, &mii
);
2726 ok( ret
, "InsertMenuItem failed with error %d\n", GetLastError());
2727 /* test some parameter errors */
2728 SetLastError(0xdeadbeef);
2729 ret
= pSetMenuInfo( hmenu
, NULL
);
2730 gle
= GetLastError();
2731 ok( !ret
, "SetMenuInfo() should have failed\n");
2732 ok( gle
== ERROR_INVALID_PARAMETER
||
2733 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2734 "SetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2735 SetLastError(0xdeadbeef);
2737 ret
= pSetMenuInfo( hmenu
, &mi
);
2738 gle
= GetLastError();
2739 ok( !ret
, "SetMenuInfo() should have failed\n");
2740 ok( gle
== ERROR_INVALID_PARAMETER
||
2741 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2742 "SetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2743 SetLastError(0xdeadbeef);
2744 mi
.cbSize
= sizeof( MENUINFO
);
2745 ret
= pSetMenuInfo( hmenu
, &mi
);
2746 gle
= GetLastError();
2747 ok( ret
, "SetMenuInfo() should have succeeded\n");
2748 ok( gle
== 0xdeadbeef, "SetMenuInfo() error got %u\n", gle
);
2749 SetLastError(0xdeadbeef);
2751 ret
= pSetMenuInfo( NULL
, &mi
);
2752 gle
= GetLastError();
2753 ok( !ret
, "SetMenuInfo() should have failed\n");
2754 ok( gle
== ERROR_INVALID_PARAMETER
||
2755 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2756 "SetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2757 /* functional tests */
2758 /* menu and submenu should have the CHECKORBMP style bit cleared */
2759 SetLastError(0xdeadbeef);
2760 mi
.cbSize
= sizeof( MENUINFO
);
2761 mi
.fMask
= MIM_STYLE
;
2762 ret
= pGetMenuInfo( hmenu
, &mi
);
2763 gle
= GetLastError();
2764 ok( ret
, "GetMenuInfo() should have succeeded\n");
2765 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2766 ok( !(mi
.dwStyle
& MNS_CHECKORBMP
), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2767 SetLastError(0xdeadbeef);
2768 mi
.cbSize
= sizeof( MENUINFO
);
2769 mi
.fMask
= MIM_STYLE
;
2770 ret
= pGetMenuInfo( hsubmenu
, &mi
);
2771 gle
= GetLastError();
2772 ok( ret
, "GetMenuInfo() should have succeeded\n");
2773 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2774 ok( !(mi
.dwStyle
& MNS_CHECKORBMP
), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2776 SetLastError(0xdeadbeef);
2777 mi
.cbSize
= sizeof( MENUINFO
);
2778 mi
.fMask
= MIM_STYLE
| MIM_APPLYTOSUBMENUS
;
2779 mi
.dwStyle
= MNS_CHECKORBMP
;
2780 ret
= pSetMenuInfo( hmenu
, &mi
);
2781 gle
= GetLastError();
2782 ok( ret
, "SetMenuInfo() should have succeeded\n");
2783 ok( gle
== 0xdeadbeef, "SetMenuInfo() error got %u\n", gle
);
2784 /* Now both menus should have the MNS_CHECKORBMP style bit set */
2785 SetLastError(0xdeadbeef);
2786 mi
.cbSize
= sizeof( MENUINFO
);
2787 mi
.fMask
= MIM_STYLE
;
2788 ret
= pGetMenuInfo( hmenu
, &mi
);
2789 gle
= GetLastError();
2790 ok( ret
, "GetMenuInfo() should have succeeded\n");
2791 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2792 ok( mi
.dwStyle
& MNS_CHECKORBMP
, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2793 SetLastError(0xdeadbeef);
2794 mi
.cbSize
= sizeof( MENUINFO
);
2795 mi
.fMask
= MIM_STYLE
;
2796 ret
= pGetMenuInfo( hsubmenu
, &mi
);
2797 gle
= GetLastError();
2798 ok( ret
, "GetMenuInfo() should have succeeded\n");
2799 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2800 ok( mi
.dwStyle
& MNS_CHECKORBMP
, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2801 /* now repeat that without the APPLYTOSUBMENUS flag and another style bit */
2802 SetLastError(0xdeadbeef);
2803 mi
.cbSize
= sizeof( MENUINFO
);
2804 mi
.fMask
= MIM_STYLE
;
2805 mi
.dwStyle
= MNS_NOCHECK
;
2806 ret
= pSetMenuInfo( hmenu
, &mi
);
2807 gle
= GetLastError();
2808 ok( ret
, "SetMenuInfo() should have succeeded\n");
2809 ok( gle
== 0xdeadbeef, "SetMenuInfo() error got %u\n", gle
);
2810 /* Now only the top menu should have the MNS_NOCHECK style bit set */
2811 SetLastError(0xdeadbeef);
2812 mi
.cbSize
= sizeof( MENUINFO
);
2813 mi
.fMask
= MIM_STYLE
;
2814 ret
= pGetMenuInfo( hmenu
, &mi
);
2815 gle
= GetLastError();
2816 ok( ret
, "GetMenuInfo() should have succeeded\n");
2817 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2818 ok( mi
.dwStyle
& MNS_NOCHECK
, "menustyle was expected to have the MNS_NOCHECK flag\n");
2819 SetLastError(0xdeadbeef);
2820 mi
.cbSize
= sizeof( MENUINFO
);
2821 mi
.fMask
= MIM_STYLE
;
2822 ret
= pGetMenuInfo( hsubmenu
, &mi
);
2823 gle
= GetLastError();
2824 ok( ret
, "GetMenuInfo() should have succeeded\n");
2825 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2826 ok( !(mi
.dwStyle
& MNS_NOCHECK
), "menustyle was not expected to have the MNS_NOCHECK flag\n");
2828 DestroyMenu( hsubmenu
);
2829 DestroyMenu( hmenu
);
2833 /* little func to easy switch either TrackPopupMenu() or TrackPopupMenuEx() */
2834 static DWORD
MyTrackPopupMenu( int ex
, HMENU hmenu
, UINT flags
, INT x
, INT y
, HWND hwnd
, LPTPMPARAMS ptpm
)
2837 ? TrackPopupMenuEx( hmenu
, flags
, x
, y
, hwnd
, ptpm
)
2838 : TrackPopupMenu( hmenu
, flags
, x
, y
, 0, hwnd
, NULL
);
2841 /* some TrackPopupMenu and TrackPopupMenuEx tests */
2842 /* the LastError values differ between NO_ERROR and invalid handle */
2843 /* between all windows versions tested. The first value is that valid on XP */
2844 /* Vista was the only that made returned different error values */
2845 /* between the TrackPopupMenu and TrackPopupMenuEx functions */
2846 static void test_menu_trackpopupmenu(void)
2852 HWND hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
2853 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
2854 NULL
, NULL
, NULL
, NULL
);
2855 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
2857 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_ownerdraw_wnd_proc
);
2858 for( Ex
= 0; Ex
< 2; Ex
++)
2860 hmenu
= CreatePopupMenu();
2861 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
2864 DestroyWindow(hwnd
);
2867 /* display the menu */
2868 /* start with an invalid menu handle */
2870 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= 0;
2871 ret
= MyTrackPopupMenu( Ex
, NULL
, 0x100, 100,100, hwnd
, NULL
);
2872 gle
= GetLastError();
2873 ok( !ret
, "TrackPopupMenu%s should have failed\n", Ex
? "Ex" : "");
2874 ok( gle
== ERROR_INVALID_MENU_HANDLE
2875 || broken (gle
== 0xdeadbeef) /* win95 */
2876 || broken (gle
== NO_ERROR
) /* win98/ME */
2877 ,"TrackPopupMenu%s error got %u expected %u\n",
2878 Ex
? "Ex" : "", gle
, ERROR_INVALID_MENU_HANDLE
);
2879 ok( !(gflag_initmenupopup
|| gflag_entermenuloop
|| gflag_initmenu
),
2880 "got unexpected message(s)%s%s%s\n",
2881 gflag_initmenupopup
? " WM_INITMENUPOPUP ": " ",
2882 gflag_entermenuloop
? "WM_INITMENULOOP ": "",
2883 gflag_initmenu
? "WM_INITMENU": "");
2884 /* another one but not NULL */
2886 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= 0;
2887 ret
= MyTrackPopupMenu( Ex
, (HMENU
)hwnd
, 0x100, 100,100, hwnd
, NULL
);
2888 gle
= GetLastError();
2889 ok( !ret
, "TrackPopupMenu%s should have failed\n", Ex
? "Ex" : "");
2890 ok( gle
== ERROR_INVALID_MENU_HANDLE
2891 || broken (gle
== 0xdeadbeef) /* win95 */
2892 || broken (gle
== NO_ERROR
) /* win98/ME */
2893 ,"TrackPopupMenu%s error got %u expected %u\n",
2894 Ex
? "Ex" : "", gle
, ERROR_INVALID_MENU_HANDLE
);
2895 ok( !(gflag_initmenupopup
|| gflag_entermenuloop
|| gflag_initmenu
),
2896 "got unexpected message(s)%s%s%s\n",
2897 gflag_initmenupopup
? " WM_INITMENUPOPUP ": " ",
2898 gflag_entermenuloop
? "WM_INITMENULOOP ": "",
2899 gflag_initmenu
? "WM_INITMENU": "");
2900 /* now a somewhat successful call */
2902 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= 0;
2903 ret
= MyTrackPopupMenu( Ex
, hmenu
, 0x100, 100,100, hwnd
, NULL
);
2904 gle
= GetLastError();
2905 ok( ret
== 0, "TrackPopupMenu%s returned %d expected zero\n", Ex
? "Ex" : "", ret
);
2907 || gle
== ERROR_INVALID_MENU_HANDLE
/* NT4, win2k */
2908 || broken (gle
== 0xdeadbeef) /* win95 */
2909 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
2910 Ex
? "Ex" : "", gle
, NO_ERROR
, ERROR_INVALID_MENU_HANDLE
);
2911 ok( gflag_initmenupopup
&& gflag_entermenuloop
&& gflag_initmenu
,
2912 "missed expected message(s)%s%s%s\n",
2913 !gflag_initmenupopup
? " WM_INITMENUPOPUP ": " ",
2914 !gflag_entermenuloop
? "WM_INITMENULOOP ": "",
2915 !gflag_initmenu
? "WM_INITMENU": "");
2917 ret
= AppendMenuA( hmenu
, MF_STRING
, 1, "winetest");
2918 ok( ret
, "AppendMenA has failed!\n");
2920 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= 0;
2921 ret
= MyTrackPopupMenu( Ex
, hmenu
, 0x100, 100,100, hwnd
, NULL
);
2922 gle
= GetLastError();
2923 ok( ret
== 0, "TrackPopupMenu%s returned %d expected zero\n", Ex
? "Ex" : "", ret
);
2925 || gle
== ERROR_INVALID_MENU_HANDLE
/* NT4, win2k and Vista in the TrackPopupMenuEx case */
2926 || broken (gle
== 0xdeadbeef) /* win95 */
2927 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
2928 Ex
? "Ex" : "", gle
, NO_ERROR
, ERROR_INVALID_MENU_HANDLE
);
2929 ok( gflag_initmenupopup
&& gflag_entermenuloop
&& gflag_initmenu
,
2930 "missed expected message(s)%s%s%s\n",
2931 !gflag_initmenupopup
? " WM_INITMENUPOPUP ": " ",
2932 !gflag_entermenuloop
? "WM_INITMENULOOP ": "",
2933 !gflag_initmenu
? "WM_INITMENU": "");
2937 DestroyWindow(hwnd
);
2940 /* test handling of WM_CANCELMODE messages */
2941 static int g_got_enteridle
;
2942 static HWND g_hwndtosend
;
2943 static LRESULT WINAPI
menu_cancelmode_wnd_proc(HWND hwnd
, UINT msg
,
2944 WPARAM wparam
, LPARAM lparam
)
2948 case WM_ENTERMENULOOP
:
2949 g_got_enteridle
= 0;
2950 return SendMessage( g_hwndtosend
, WM_CANCELMODE
, 0, 0);
2953 if( g_got_enteridle
++ == 0) {
2954 /* little hack to get another WM_ENTERIDLE message */
2955 PostMessage( hwnd
, WM_MOUSEMOVE
, 0, 0);
2956 return SendMessage( g_hwndtosend
, WM_CANCELMODE
, 0, 0);
2962 return DefWindowProc( hwnd
, msg
, wparam
, lparam
);
2965 static void test_menu_cancelmode(void)
2968 HWND hwnd
, hwndchild
;
2970 if( !pEndMenu
) { /* win95 */
2971 win_skip( "EndMenu is not available\n");
2974 hwnd
= CreateWindowEx( 0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
2975 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
2976 NULL
, NULL
, NULL
, NULL
);
2977 hwndchild
= CreateWindowEx( 0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
2978 WS_VISIBLE
| WS_CHILD
, 10, 10, 20, 20,
2979 hwnd
, NULL
, NULL
, NULL
);
2980 ok( hwnd
!= NULL
&& hwndchild
!= NULL
,
2981 "CreateWindowEx failed with error %d\n", GetLastError());
2982 g_hwndtosend
= hwnd
;
2983 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_cancelmode_wnd_proc
);
2984 SetWindowLongPtr( hwndchild
, GWLP_WNDPROC
, (LONG_PTR
)menu_cancelmode_wnd_proc
);
2985 menu
= CreatePopupMenu();
2986 ok( menu
!= NULL
, "CreatePopupMenu failed with error %d\n", GetLastError());
2987 ret
= AppendMenuA( menu
, MF_STRING
, 1, "winetest");
2988 ok( ret
, "Functie failed lasterror is %u\n", GetLastError());
2989 /* seems to be needed only on wine :( */
2990 {MSG msg
; while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage(&msg
);}
2991 /* test the effect of sending a WM_CANCELMODE message in the WM_INITMENULOOP
2992 * handler of the menu owner */
2993 /* test results is exctracted from variable g_got_enteridle. Possible values:
2994 * 0 : complete conformance. Sending WM_CANCELMODE cancels a menu initializing tracking
2995 * 1 : Sending WM_CANCELMODE cancels a menu that is in tracking state
2996 * 2 : Sending WM_CANCELMODE does not work
2998 /* menu owner is top level window */
2999 g_hwndtosend
= hwnd
;
3000 ret
= TrackPopupMenu( menu
, 0x100, 100,100, 0, hwnd
, NULL
);
3002 ok( g_got_enteridle
== 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle
);
3004 ok( g_got_enteridle
< 2, "received %d WM_ENTERIDLE messages, should be less than 2\n", g_got_enteridle
);
3005 /* menu owner is child window */
3006 g_hwndtosend
= hwndchild
;
3007 ret
= TrackPopupMenu( menu
, 0x100, 100,100, 0, hwndchild
, NULL
);
3009 ok(g_got_enteridle
== 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle
);
3011 ok(g_got_enteridle
< 2, "received %d WM_ENTERIDLE messages, should be less than 2\n", g_got_enteridle
);
3012 /* now send the WM_CANCELMODE messages to the WRONG window */
3013 /* those should fail ( to have any effect) */
3014 g_hwndtosend
= hwnd
;
3015 ret
= TrackPopupMenu( menu
, 0x100, 100,100, 0, hwndchild
, NULL
);
3016 ok( g_got_enteridle
== 2, "received %d WM_ENTERIDLE messages, should be 2\n", g_got_enteridle
);
3019 DestroyWindow( hwndchild
);
3020 DestroyWindow( hwnd
);
3023 /* show menu trees have a maximum depth */
3024 static void test_menu_maxdepth(void)
3026 #define NR_MENUS 100
3027 HMENU hmenus
[ NR_MENUS
];
3031 SetLastError(12345678);
3032 for( i
= 0; i
< NR_MENUS
; i
++) {
3033 hmenus
[i
] = CreatePopupMenu();
3034 if( !hmenus
[i
]) break;
3036 ok( i
== NR_MENUS
, "could not create more than %d menu's\n", i
);
3037 for( i
= 1; i
< NR_MENUS
; i
++) {
3038 ret
= AppendMenuA( hmenus
[i
], MF_POPUP
, (UINT_PTR
)hmenus
[i
-1],"test");
3041 trace("Maximum depth is %d\n", i
);
3042 ok( GetLastError() == 12345678, "unexpected error %d\n", GetLastError());
3044 broken( i
== NR_MENUS
), /* win98, NT */
3045 "no ( or very large) limit on menu depth!\n");
3047 for( i
= 0; i
< NR_MENUS
; i
++)
3048 DestroyMenu( hmenus
[i
]);
3052 static void test_menu_circref(void)
3057 menu1
= CreatePopupMenu();
3058 menu2
= CreatePopupMenu();
3059 ok( menu1
&& menu2
, "error creating menus.\n");
3060 ret
= AppendMenuA( menu1
, MF_POPUP
, (UINT_PTR
)menu2
, "winetest");
3061 ok( ret
, "AppendMenu failed, error is %d\n", GetLastError());
3062 ret
= AppendMenuA( menu1
, MF_STRING
| MF_HILITE
, 123, "winetest");
3063 ok( ret
, "AppendMenu failed, error is %d\n", GetLastError());
3064 /* app chooses an id that happens to clash with its own hmenu */
3065 ret
= AppendMenuA( menu2
, MF_STRING
, (UINT_PTR
)menu2
, "winetest");
3066 ok( ret
, "AppendMenu failed, error is %d\n", GetLastError());
3067 /* now attempt to change the string of the first item of menu1 */
3068 ret
= ModifyMenuA( menu1
, (UINT_PTR
)menu2
, MF_POPUP
, (UINT_PTR
)menu2
, "menu 2");
3070 broken( ret
), /* win98, NT */
3071 "ModifyMenu should have failed.\n");
3072 if( !ret
) { /* will probably stack fault if the ModifyMenu succeeded */
3073 ret
= GetMenuState( menu1
, 123, 0);
3074 ok( ret
== MF_HILITE
, "GetMenuState returned %x\n",ret
);
3076 DestroyMenu( menu2
);
3077 DestroyMenu( menu1
);
3080 /* test how the menu texts are aligned when the menu items have
3081 * different combinations of text and bitmaps (bug #13350) */
3082 static void test_menualign(void)
3086 HBITMAP hbm1
, hbm2
, hbm3
;
3087 MENUITEMINFO mii
= { sizeof(MENUITEMINFO
)};
3090 MENUINFO mi
= { sizeof( MENUINFO
)};
3092 if( !winetest_interactive
) {
3093 skip( "interactive alignment tests.\n");
3096 hwnd
= CreateWindowEx(0,
3098 "Menu text alignment Test\nPlease make a selection.",
3099 WS_OVERLAPPEDWINDOW
,
3102 NULL
, NULL
, 0, NULL
);
3103 ShowWindow( hwnd
, SW_SHOW
);
3104 /* create bitmaps */
3105 memset( bmfill
, 0xcc, sizeof( bmfill
));
3106 hbm1
= CreateBitmap( 10,10,1,1,bmfill
);
3107 hbm2
= CreateBitmap( 20,20,1,1,bmfill
);
3108 hbm3
= CreateBitmap( 50,6,1,1,bmfill
);
3109 ok( hbm1
&& hbm2
&& hbm3
, "Creating bitmaps failed\n");
3110 menu
= CreatePopupMenu();
3111 ok( menu
!= NULL
, "CreatePopupMenu() failed\n");
3113 mi
.fMask
= MIM_STYLE
;
3114 ret
= pGetMenuInfo( menu
, &mi
);
3115 ok( menu
!= NULL
, "GetMenuInfo() failed\n");
3116 ok( 0 == mi
.dwStyle
, "menuinfo style is %x\n", mi
.dwStyle
);
3119 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3121 mii
.hbmpItem
= hbm1
;
3122 mii
.dwTypeData
= (LPSTR
) " OK: menu texts are correctly left-aligned.";
3123 ret
= InsertMenuItem( menu
, -1, TRUE
, &mii
);
3124 ok( ret
, "InsertMenuItem() failed\n");
3125 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3127 mii
.hbmpItem
= hbm2
;
3128 mii
.dwTypeData
= (LPSTR
) " FAIL: menu texts are NOT left-aligned.";
3129 ret
= InsertMenuItem( menu
, -1, TRUE
, &mii
);
3130 ok( ret
, "InsertMenuItem() failed\n");
3131 ret
= TrackPopupMenu( menu
, TPM_RETURNCMD
, 110, 200, 0, hwnd
, NULL
);
3132 ok( ret
!= 2, "User indicated that menu text alignment test 1 failed %d\n", ret
);
3134 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3136 mii
.hbmpItem
= hbm3
;
3137 mii
.dwTypeData
= NULL
;
3138 ret
= InsertMenuItem( menu
, 0, TRUE
, &mii
);
3139 ok( ret
, "InsertMenuItem() failed\n");
3140 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3142 mii
.hbmpItem
= hbm1
;
3143 /* make the text a bit longer, to keep it readable */
3144 /* this bug is on winXP and reproduced on wine */
3145 mii
.dwTypeData
= (LPSTR
) " OK: menu texts are to the right of the bitmaps........";
3146 ret
= SetMenuItemInfo( menu
, 1, TRUE
, &mii
);
3147 ok( ret
, "SetMenuItemInfo() failed\n");
3149 mii
.hbmpItem
= hbm2
;
3150 mii
.dwTypeData
= (LPSTR
) " FAIL: menu texts are below the first bitmap. ";
3151 ret
= SetMenuItemInfo( menu
, 2, TRUE
, &mii
);
3152 ok( ret
, "SetMenuItemInfo() failed\n");
3153 ret
= TrackPopupMenu( menu
, TPM_RETURNCMD
, 110, 200, 0, hwnd
, NULL
);
3154 ok( ret
!= 2, "User indicated that menu text alignment test 2 failed %d\n", ret
);
3156 mii
.fMask
= MIIM_TYPE
| MIIM_ID
;
3158 mii
.fType
= MFT_BITMAP
;
3159 mii
.dwTypeData
= (LPSTR
) hbm3
;
3160 ret
= SetMenuItemInfo( menu
, 0, TRUE
, &mii
);
3161 ok( ret
, "SetMenuItemInfo() failed\n");
3162 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3164 mii
.hbmpItem
= NULL
;
3165 mii
.dwTypeData
= (LPSTR
) " OK: menu texts are below the bitmap.";
3166 ret
= SetMenuItemInfo( menu
, 1, TRUE
, &mii
);
3167 ok( ret
, "SetMenuItemInfo() failed\n");
3169 mii
.hbmpItem
= NULL
;
3170 mii
.dwTypeData
= (LPSTR
) " FAIL: menu texts are NOT below the bitmap.";
3171 ret
= SetMenuItemInfo( menu
, 2, TRUE
, &mii
);
3172 ok( ret
, "SetMenuItemInfo() failed\n");
3173 ret
= TrackPopupMenu( menu
, TPM_RETURNCMD
, 110, 200, 0, hwnd
, NULL
);
3174 ok( ret
!= 2, "User indicated that menu text alignment test 3 failed %d\n", ret
);
3176 DeleteObject( hbm1
);
3177 DeleteObject( hbm2
);
3178 DeleteObject( hbm3
);
3180 DestroyWindow( hwnd
);
3185 init_function_pointers();
3187 /* Wine defines MENUITEMINFO for W2K and above. NT4 and below can't
3190 if (correct_behavior())
3192 test_menu_add_string();
3193 test_menu_iteminfo();
3194 test_menu_search_bycommand();
3195 test_CheckMenuRadioItem();
3196 test_menu_resource_layout();
3201 register_menu_check_class();
3203 test_menu_locked_by_window();
3204 test_subpopup_locked_by_menu();
3205 test_menu_ownerdraw();
3206 test_menu_bmp_and_string();
3207 /* test Get/SetMenuInfo if available */
3208 if( pGetMenuInfo
&& pSetMenuInfo
) {
3209 test_menu_getmenuinfo();
3210 test_menu_setmenuinfo();
3212 win_skip("Get/SetMenuInfo are not available\n");
3214 win_skip("SendInput is not available\n");
3219 test_menu_hilitemenuitem();
3220 test_menu_trackpopupmenu();
3221 test_menu_cancelmode();
3222 test_menu_maxdepth();
3223 test_menu_circref();