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
== ERROR_INVALID_PARAMETER
), /* win2k0 */
394 "Last error is %d\n", gle
);
401 static void test_menu_ownerdraw(void)
407 HWND hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
408 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
409 NULL
, NULL
, NULL
, NULL
);
410 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
412 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_ownerdraw_wnd_proc
);
413 hmenu
= CreatePopupMenu();
414 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
415 if( !hmenu
) { DestroyWindow(hwnd
);return;}
417 for( j
=0;j
<2;j
++) /* create columns */
418 for(i
=0;i
<2;i
++) { /* create rows */
419 ret
= AppendMenu( hmenu
, MF_OWNERDRAW
|
420 (i
==0 ? MF_MENUBREAK
: 0), k
, MAKEINTRESOURCE(k
));
422 ok( ret
, "AppendMenu failed for %d\n", k
-1);
425 assert( k
<= sizeof(MOD_rc
)/sizeof(RECT
));
426 /* display the menu */
427 ret
= TrackPopupMenu( hmenu
, 0x100, 100,100, 0, hwnd
, NULL
);
429 /* columns have a 4 pixel gap between them */
430 ok( MOD_rc
[0].right
+ 4 == MOD_rc
[2].left
,
431 "item rectangles are not separated by 4 pixels space\n");
432 /* height should be what the MEASUREITEM message has returned */
433 ok( MOD_rc
[0].bottom
- MOD_rc
[0].top
== MOD_SIZE
,
434 "menu item has wrong height: %d should be %d\n",
435 MOD_rc
[0].bottom
- MOD_rc
[0].top
, MOD_SIZE
);
436 /* no gaps between the rows */
437 ok( MOD_rc
[0].bottom
- MOD_rc
[1].top
== 0,
438 "There should not be a space between the rows, gap is %d\n",
439 MOD_rc
[0].bottom
- MOD_rc
[1].top
);
440 /* test the correct value of the item height that was sent
441 * by the WM_MEASUREITEM message */
442 ok( MOD_odheight
== HIWORD( GetDialogBaseUnits()) || /* WinNT,2k,XP */
443 MOD_odheight
== MOD_hic
, /* Win95,98,ME */
444 "Wrong height field in MEASUREITEMSTRUCT, expected %d or %d actual %d\n",
445 HIWORD( GetDialogBaseUnits()), MOD_hic
, MOD_odheight
);
446 /* test what MF_MENUBREAK did at the first position. Also show
447 * that an MF_SEPARATOR is ignored in the height calculation. */
448 leftcol
= MOD_rc
[0].left
;
449 ModifyMenu( hmenu
, 0, MF_BYCOMMAND
| MF_OWNERDRAW
| MF_SEPARATOR
, 0, 0);
450 /* display the menu */
451 ret
= TrackPopupMenu( hmenu
, 0x100, 100,100, 0, hwnd
, NULL
);
452 /* left should be 4 pixels less now */
453 ok( leftcol
== MOD_rc
[0].left
+ 4,
454 "columns should be 4 pixels to the left (actual %d).\n",
455 leftcol
- MOD_rc
[0].left
);
457 ok( MOD_rc
[0].right
- MOD_rc
[0].left
== 2 * MOD_avec
+ MOD_SIZE
,
458 "width of owner drawn menu item is wrong. Got %d expected %d\n",
459 MOD_rc
[0].right
- MOD_rc
[0].left
, 2*MOD_avec
+ MOD_SIZE
);
461 ok( MOD_rc
[0].bottom
- MOD_rc
[0].top
== MOD_SIZE
,
462 "Height is incorrect. Got %d expected %d\n",
463 MOD_rc
[0].bottom
- MOD_rc
[0].top
, MOD_SIZE
);
465 /* test width/height of an ownerdraw menu bar as well */
466 ret
= DestroyMenu(hmenu
);
467 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
468 hmenu
= CreateMenu();
469 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
470 if( !hmenu
) { DestroyWindow(hwnd
);return;}
473 ret
= AppendMenu( hmenu
, MF_OWNERDRAW
, i
, 0);
474 ok( ret
, "AppendMenu failed for %d\n", i
);
476 ret
= SetMenu( hwnd
, hmenu
);
477 UpdateWindow( hwnd
); /* hack for wine to draw the window + menu */
478 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
480 ok( MOD_rc
[0].right
- MOD_rc
[0].left
== 2 * MOD_avec
+ MOD_SIZE
,
481 "width of owner drawn menu item is wrong. Got %d expected %d\n",
482 MOD_rc
[0].right
- MOD_rc
[0].left
, 2*MOD_avec
+ MOD_SIZE
);
484 ok( MOD_rc
[0].bottom
- MOD_rc
[0].top
== GetSystemMetrics( SM_CYMENU
) - 1,
485 "Height of owner drawn menu item is wrong. Got %d expected %d\n",
486 MOD_rc
[0].bottom
- MOD_rc
[0].top
, GetSystemMetrics( SM_CYMENU
) - 1);
489 ret
= DestroyMenu(hmenu
);
490 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
494 /* helper for test_menu_bmp_and_string() */
495 static void test_mbs_help( int ispop
, int hassub
, int mnuopt
,
496 HWND hwnd
, int arrowwidth
, int count
, HBITMAP hbmp
,
497 SIZE bmpsize
, LPCSTR text
, SIZE size
, SIZE sc_size
)
500 HMENU hmenu
, submenu
;
501 MENUITEMINFO mii
={ sizeof( MENUITEMINFO
)};
508 MOD_GotDrawItemMsg
= FALSE
;
509 mii
.fMask
= MIIM_FTYPE
| MIIM_DATA
| MIIM_STATE
;
511 /* check the menu item unless MNS_CHECKORBMP is set */
512 mii
.fState
= (mnuopt
!= 2 ? MFS_CHECKED
: MFS_UNCHECKED
);
514 MODsizes
[0] = bmpsize
;
518 mii
.fMask
|= MIIM_STRING
;
519 strcpy(text_copy
, text
);
520 mii
.dwTypeData
= text_copy
; /* structure member declared non-const */
521 if( ( p
= strchr( text
, '\t'))) {
522 hastab
= *(p
+ 1) ? 2 : 1;
525 /* tabs don't make sense in menubars */
526 if(hastab
&& !ispop
) return;
528 mii
.fMask
|= MIIM_BITMAP
;
531 submenu
= CreateMenu();
532 ok( submenu
!= 0, "CreateMenu failed with error %d\n", GetLastError());
534 hmenu
= CreatePopupMenu();
536 hmenu
= CreateMenu();
537 ok( hmenu
!= 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
539 mii
.fMask
|= MIIM_SUBMENU
;
540 mii
.hSubMenu
= submenu
;
543 mi
.cbSize
= sizeof(mi
);
544 mi
.fMask
= MIM_STYLE
;
545 pGetMenuInfo( hmenu
, &mi
);
546 if( mnuopt
) mi
.dwStyle
|= mnuopt
== 1 ? MNS_NOCHECK
: MNS_CHECKORBMP
;
547 ret
= pSetMenuInfo( hmenu
, &mi
);
548 ok( ret
, "SetMenuInfo failed with error %d\n", GetLastError());
550 ret
= InsertMenuItem( hmenu
, 0, FALSE
, &mii
);
551 ok( ret
, "InsertMenuItem failed with error %d\n", GetLastError());
553 if( winetest_debug
) {
555 RECT rc
= {100, 50, 400, 70};
558 sprintf( buf
,"%d text \"%s\" mnuopt %d", count
, text
? text
: "(nil)", mnuopt
);
559 FillRect( hdc
, &rc
, (HBRUSH
) COLOR_WINDOW
);
560 TextOut( hdc
, 10, 50, buf
, strlen( buf
));
561 ReleaseDC( hwnd
, hdc
);
564 ret
= TrackPopupMenu( hmenu
, 0x100, 100,100, 0, hwnd
, NULL
);
566 ret
= SetMenu( hwnd
, hmenu
);
567 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
570 ret
= GetMenuItemRect( hwnd
, hmenu
, 0, &rc
);
571 if (0) /* comment out menu size checks, behavior is different in almost every Windows version */
572 /* the tests should however succeed on win2000, XP and Wine (at least up to 1.1.15) */
573 /* with a variety of dpis and desktop font sizes */
575 /* check menu width */
577 expect
= ( text
|| hbmp
?
578 4 + (mnuopt
!= 1 ? GetSystemMetrics(SM_CXMENUCHECK
) : 0)
580 arrowwidth
+ MOD_avec
+ (hbmp
?
581 ((INT_PTR
)hbmp
<0||(INT_PTR
)hbmp
>12 ? bmpsize
.cx
+ 2 : GetSystemMetrics( SM_CXMENUSIZE
) + 2)
583 (text
&& hastab
? /* TAB space */
584 MOD_avec
+ ( hastab
==2 ? sc_size
.cx
: 0) : 0) +
585 (text
? 2 + (text
[0] ? size
.cx
:0): 0) ;
587 expect
= !(text
|| hbmp
) ? 0 :
588 ( hbmp
? (text
? 2:0) + bmpsize
.cx
: 0 ) +
589 (text
? 2 * MOD_avec
+ (text
[0] ? size
.cx
:0): 0) ;
590 ok( rc
.right
- rc
.left
== expect
,
591 "menu width wrong, got %d expected %d\n", rc
.right
- rc
.left
, expect
);
592 failed
= failed
|| !(rc
.right
- rc
.left
== expect
);
593 /* check menu height */
595 expect
= max( ( !(text
|| hbmp
) ? GetSystemMetrics( SM_CYMENUSIZE
)/2 : 0),
596 max( (text
? max( 2 + size
.cy
, MOD_hic
+ 4) : 0),
598 ((INT_PTR
)hbmp
<0||(INT_PTR
)hbmp
>12 ?
600 : GetSystemMetrics( SM_CYMENUSIZE
) + 2)
603 expect
= ( !(text
|| hbmp
) ? GetSystemMetrics( SM_CYMENUSIZE
)/2 :
604 max( GetSystemMetrics( SM_CYMENU
) - 1, (hbmp
? bmpsize
.cy
: 0)));
605 ok( rc
.bottom
- rc
.top
== expect
,
606 "menu height wrong, got %d expected %d (%d)\n",
607 rc
.bottom
- rc
.top
, expect
, GetSystemMetrics( SM_CYMENU
));
608 failed
= failed
|| !(rc
.bottom
- rc
.top
== expect
);
609 if( hbmp
== HBMMENU_CALLBACK
&& MOD_GotDrawItemMsg
) {
610 /* check the position of the bitmap */
614 else if (mnuopt
== 0)
615 expect
= 4 + GetSystemMetrics(SM_CXMENUCHECK
);
616 else if (mnuopt
== 1)
618 else /* mnuopt == 2 */
620 ok( expect
== MOD_rc
[0].left
,
621 "bitmap left is %d expected %d\n", MOD_rc
[0].left
, expect
);
622 failed
= failed
|| !(expect
== MOD_rc
[0].left
);
624 expect
= (rc
.bottom
- rc
.top
- MOD_rc
[0].bottom
+ MOD_rc
[0].top
) / 2;
625 ok( expect
== MOD_rc
[0].top
,
626 "bitmap top is %d expected %d\n", MOD_rc
[0].top
, expect
);
627 failed
= failed
|| !(expect
== MOD_rc
[0].top
);
630 /* if there was a failure, report details */
632 trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
633 count
, (ispop
? "POPUP": "MENUBAR"),text
? text
: "(nil)", hbmp
, bmpsize
.cx
, bmpsize
.cy
,
634 size
.cx
, size
.cy
, sc_size
.cx
, mnuopt
, hastab
);
635 trace(" check %d,%d arrow %d avechar %d\n",
636 GetSystemMetrics(SM_CXMENUCHECK
),
637 GetSystemMetrics(SM_CYMENUCHECK
),arrowwidth
, MOD_avec
);
638 if( hbmp
== HBMMENU_CALLBACK
)
639 trace( " rc %d,%d-%d,%d bmp.rc %d,%d-%d,%d\n",
640 rc
.left
, rc
.top
, rc
.top
, rc
.bottom
, MOD_rc
[0].left
,
641 MOD_rc
[0].top
,MOD_rc
[0].right
, MOD_rc
[0].bottom
);
644 ret
= DestroyMenu(submenu
);
645 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
646 ret
= DestroyMenu(hmenu
);
647 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
651 static void test_menu_bmp_and_string(void)
659 MENUINFO mi
= {sizeof(MENUINFO
)};
660 MENUITEMINFOA mii
= {sizeof(MENUITEMINFOA
)};
661 int count
, szidx
, txtidx
, bmpidx
, hassub
, mnuopt
, ispop
;
665 win_skip("GetMenuInfo is not available\n");
669 memset( bmfill
, 0xcc, sizeof( bmfill
));
670 hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
, WS_SYSMENU
|
671 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
672 NULL
, NULL
, NULL
, NULL
);
673 hbm_arrow
=LoadBitmap( 0, (CHAR
*)OBM_MNARROW
);
674 GetObject( hbm_arrow
, sizeof(bm
), &bm
);
675 arrowwidth
= bm
.bmWidth
;
676 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
678 /* test system menu */
679 hsysmenu
= GetSystemMenu( hwnd
, FALSE
);
680 ok( hsysmenu
!= NULL
, "GetSystemMenu failed with error %d\n", GetLastError());
681 mi
.fMask
= MIM_STYLE
;
683 ok( pGetMenuInfo( hsysmenu
, &mi
), "GetMenuInfo failed gle=%d\n", GetLastError());
684 ok( MNS_CHECKORBMP
== mi
.dwStyle
, "System Menu Style is %08x, without the bit %08x\n",
685 mi
.dwStyle
, MNS_CHECKORBMP
);
686 mii
.fMask
= MIIM_BITMAP
;
688 ok( GetMenuItemInfoA( hsysmenu
, SC_CLOSE
, FALSE
, &mii
), "GetMenuItemInfoA failed gle=%d\n", GetLastError());
689 ok( HBMMENU_POPUP_CLOSE
== mii
.hbmpItem
, "Item info did not get the right hbitmap: got %p expected %p\n",
690 mii
.hbmpItem
, HBMMENU_POPUP_CLOSE
);
692 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_ownerdraw_wnd_proc
);
695 trace(" check %d,%d arrow %d avechar %d\n",
696 GetSystemMetrics(SM_CXMENUCHECK
),
697 GetSystemMetrics(SM_CYMENUCHECK
),arrowwidth
, MOD_avec
);
700 for( ispop
=1; ispop
>= 0; ispop
--){
701 static SIZE bmsizes
[]= {
702 {10,10},{38,38},{1,30},{55,5}};
703 for( szidx
=0; szidx
< sizeof( bmsizes
) / sizeof( SIZE
); szidx
++) {
704 HBITMAP hbm
= CreateBitmap( bmsizes
[szidx
].cx
, bmsizes
[szidx
].cy
,1,1,bmfill
);
705 HBITMAP bitmaps
[] = { HBMMENU_CALLBACK
, hbm
, HBMMENU_POPUP_CLOSE
, NULL
};
706 ok( hbm
!= 0, "CreateBitmap failed err %d\n", GetLastError());
707 for( txtidx
= 0; txtidx
< sizeof(MOD_txtsizes
)/sizeof(MOD_txtsizes
[0]); txtidx
++) {
708 for( hassub
= 0; hassub
< 2 ; hassub
++) { /* add submenu item */
709 for( mnuopt
= 0; mnuopt
< 3 ; mnuopt
++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
710 for( bmpidx
= 0; bmpidx
<sizeof(bitmaps
)/sizeof(HBITMAP
); bmpidx
++) {
711 /* no need to test NULL bitmaps of several sizes */
712 if( !bitmaps
[bmpidx
] && szidx
> 0) continue;
713 /* the HBMMENU_POPUP not to test for menu bars */
715 bitmaps
[bmpidx
] >= HBMMENU_POPUP_CLOSE
&&
716 bitmaps
[bmpidx
] <= HBMMENU_POPUP_MINIMIZE
) continue;
717 if( !ispop
&& hassub
) continue;
718 test_mbs_help( ispop
, hassub
, mnuopt
,
719 hwnd
, arrowwidth
, ++count
,
722 MOD_txtsizes
[txtidx
].text
,
723 MOD_txtsizes
[txtidx
].size
,
724 MOD_txtsizes
[txtidx
].sc_size
);
736 static void test_menu_add_string( void )
747 WCHAR strbackW
[0x80];
748 static CHAR blah
[] = "blah";
749 static const WCHAR expectedString
[] = {'D','u','m','m','y',' ','s','t','r','i','n','g', 0};
751 hmenu
= CreateMenu();
753 memset( &info
, 0, sizeof info
);
754 info
.cbSize
= sizeof info
;
755 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_ID
;
756 info
.dwTypeData
= blah
;
761 InsertMenuItem(hmenu
, 0, TRUE
, &info
);
763 memset( &info
, 0, sizeof info
);
764 info
.cbSize
= sizeof info
;
765 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_DATA
| MIIM_ID
;
766 info
.dwTypeData
= string
;
767 info
.cch
= sizeof string
;
769 GetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
771 ok( !strcmp( string
, "blah" ), "menu item name differed\n");
773 /* Test combination of ownerdraw and strings with GetMenuItemString(A/W) */
774 strcpy(string
, "Dummy string");
775 memset(&info
, 0x00, sizeof(info
));
776 info
.cbSize
= sizeof(MENUITEMINFO
);
777 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
; /* Set OwnerDraw + typeData */
778 info
.fType
= MFT_OWNERDRAW
;
779 info
.dwTypeData
= string
;
780 rc
= InsertMenuItem( hmenu
, 0, TRUE
, &info
);
781 ok (rc
, "InsertMenuItem failed\n");
783 strcpy(string
,"Garbage");
784 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
785 ok (!strcmp( strback
, "Dummy string" ), "Menu text from Ansi version incorrect\n");
787 SetLastError(0xdeadbeef);
788 ret
= GetMenuStringW( hmenu
, 0, strbackW
, 99, MF_BYPOSITION
);
789 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
790 win_skip("GetMenuStringW is not implemented\n");
793 ok (ret
, "GetMenuStringW on ownerdraw entry failed\n");
794 ok (!lstrcmpW( strbackW
, expectedString
), "Menu text from Unicode version incorrect\n");
797 /* Just change ftype to string and see what text is stored */
798 memset(&info
, 0x00, sizeof(info
));
799 info
.cbSize
= sizeof(MENUITEMINFO
);
800 info
.fMask
= MIIM_FTYPE
; /* Set string type */
801 info
.fType
= MFT_STRING
;
802 info
.dwTypeData
= (char *)0xdeadbeef;
803 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
804 ok (rc
, "SetMenuItemInfo failed\n");
806 /* Did we keep the old dwTypeData? */
807 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
808 ok (!strcmp( strback
, "Dummy string" ), "Menu text from Ansi version incorrect\n");
810 /* Ensure change to bitmap type fails */
811 memset(&info
, 0x00, sizeof(info
));
812 info
.cbSize
= sizeof(MENUITEMINFO
);
813 info
.fMask
= MIIM_FTYPE
; /* Set as bitmap type */
814 info
.fType
= MFT_BITMAP
;
815 info
.dwTypeData
= (char *)0xdeadbee2;
816 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
817 ok (!rc
, "SetMenuItemInfo unexpectedly worked\n");
819 /* Just change ftype back and ensure data hasn't been freed */
820 info
.fType
= MFT_OWNERDRAW
; /* Set as ownerdraw type */
821 info
.dwTypeData
= (char *)0xdeadbee3;
822 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
823 ok (rc
, "SetMenuItemInfo failed\n");
825 /* Did we keep the old dwTypeData? */
826 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
827 ok (!strcmp( strback
, "Dummy string" ), "Menu text from Ansi version incorrect\n");
829 /* Just change string value (not type) */
830 memset(&info
, 0x00, sizeof(info
));
831 info
.cbSize
= sizeof(MENUITEMINFO
);
832 info
.fMask
= MIIM_STRING
; /* Set typeData */
833 strcpy(string2
, "string2");
834 info
.dwTypeData
= string2
;
835 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
836 ok (rc
, "SetMenuItemInfo failed\n");
838 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
839 ok (!strcmp( strback
, "string2" ), "Menu text from Ansi version incorrect\n");
841 /* crashes with wine 0.9.5 */
842 memset(&info
, 0x00, sizeof(info
));
843 info
.cbSize
= sizeof(MENUITEMINFO
);
844 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
; /* Set OwnerDraw + typeData */
845 info
.fType
= MFT_OWNERDRAW
;
846 rc
= InsertMenuItem( hmenu
, 0, TRUE
, &info
);
847 ok (rc
, "InsertMenuItem failed\n");
848 ok (!GetMenuString( hmenu
, 0, NULL
, 0, MF_BYPOSITION
),
849 "GetMenuString on ownerdraw entry succeeded.\n");
850 SetLastError(0xdeadbeef);
851 ret
= GetMenuStringW( hmenu
, 0, NULL
, 0, MF_BYPOSITION
);
852 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
853 win_skip("GetMenuStringW is not implemented\n");
855 ok (!ret
, "GetMenuStringW on ownerdraw entry succeeded.\n");
857 DestroyMenu( hmenu
);
860 /* define building blocks for the menu item info tests */
861 static int strncmpW( const WCHAR
*str1
, const WCHAR
*str2
, int n
)
863 if (n
<= 0) return 0;
864 while ((--n
> 0) && *str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
865 return *str1
- *str2
;
868 static WCHAR
*strcpyW( WCHAR
*dst
, const WCHAR
*src
)
871 while ((*p
++ = *src
++));
875 static void insert_menu_item( int line
, HMENU hmenu
, BOOL ansi
, UINT mask
, UINT type
, UINT state
, UINT id
,
876 HMENU submenu
, HBITMAP checked
, HBITMAP unchecked
, ULONG_PTR data
,
877 void *type_data
, UINT len
, HBITMAP item
, BOOL expect
)
882 /* magic bitmap handle to test smaller cbSize */
883 if (item
== (HBITMAP
)(ULONG_PTR
)0xdeadbeef)
884 info
.cbSize
= FIELD_OFFSET(MENUITEMINFOA
,hbmpItem
);
886 info
.cbSize
= sizeof(info
);
891 info
.hSubMenu
= submenu
;
892 info
.hbmpChecked
= checked
;
893 info
.hbmpUnchecked
= unchecked
;
894 info
.dwItemData
= data
;
895 info
.dwTypeData
= type_data
;
897 info
.hbmpItem
= item
;
898 SetLastError( 0xdeadbeef );
899 if (ansi
) ret
= InsertMenuItemA( hmenu
, 0, TRUE
, &info
);
900 else ret
= InsertMenuItemW( hmenu
, 0, TRUE
, (MENUITEMINFOW
*)&info
);
901 if (!expect
) ok_(__FILE__
, line
)( !ret
, "InsertMenuItem should have failed.\n" );
902 else ok_(__FILE__
, line
)( ret
, "InsertMenuItem failed, err %u\n", GetLastError());
905 static void check_menu_item_info( int line
, HMENU hmenu
, BOOL ansi
, UINT mask
, UINT type
, UINT state
,
906 UINT id
, HMENU submenu
, HBITMAP checked
, HBITMAP unchecked
,
907 ULONG_PTR data
, void *type_data
, UINT in_len
, UINT out_len
,
908 HBITMAP item
, LPCSTR expname
, BOOL expect
, BOOL expstring
)
914 SetLastError( 0xdeadbeef );
915 memset( &info
, 0xcc, sizeof(info
) );
916 info
.cbSize
= sizeof(info
);
918 info
.dwTypeData
= type_data
;
921 ret
= ansi
? GetMenuItemInfoA( hmenu
, 0, TRUE
, &info
) :
922 GetMenuItemInfoW( hmenu
, 0, TRUE
, (MENUITEMINFOW
*)&info
);
925 ok_(__FILE__
, line
)( !ret
, "GetMenuItemInfo should have failed.\n" );
928 ok_(__FILE__
, line
)( ret
, "GetMenuItemInfo failed, err %u\n", GetLastError());
929 if (mask
& MIIM_TYPE
)
930 ok_(__FILE__
, line
)( info
.fType
== type
|| info
.fType
== LOWORD(type
),
931 "wrong type %x/%x\n", info
.fType
, type
);
932 if (mask
& MIIM_STATE
)
933 ok_(__FILE__
, line
)( info
.fState
== state
|| info
.fState
== LOWORD(state
),
934 "wrong state %x/%x\n", info
.fState
, state
);
936 ok_(__FILE__
, line
)( info
.wID
== id
|| info
.wID
== LOWORD(id
),
937 "wrong id %x/%x\n", info
.wID
, id
);
938 if (mask
& MIIM_SUBMENU
)
939 ok_(__FILE__
, line
)( info
.hSubMenu
== submenu
|| (ULONG_PTR
)info
.hSubMenu
== LOWORD(submenu
),
940 "wrong submenu %p/%p\n", info
.hSubMenu
, submenu
);
941 if (mask
& MIIM_CHECKMARKS
)
943 ok_(__FILE__
, line
)( info
.hbmpChecked
== checked
|| (ULONG_PTR
)info
.hbmpChecked
== LOWORD(checked
),
944 "wrong bmpchecked %p/%p\n", info
.hbmpChecked
, checked
);
945 ok_(__FILE__
, line
)( info
.hbmpUnchecked
== unchecked
|| (ULONG_PTR
)info
.hbmpUnchecked
== LOWORD(unchecked
),
946 "wrong bmpunchecked %p/%p\n", info
.hbmpUnchecked
, unchecked
);
948 if (mask
& MIIM_DATA
)
949 ok_(__FILE__
, line
)( info
.dwItemData
== data
|| info
.dwItemData
== LOWORD(data
),
950 "wrong item data %lx/%lx\n", info
.dwItemData
, data
);
951 if (mask
& MIIM_BITMAP
)
952 ok_(__FILE__
, line
)( info
.hbmpItem
== item
|| (ULONG_PTR
)info
.hbmpItem
== LOWORD(item
),
953 "wrong bmpitem %p/%p\n", info
.hbmpItem
, item
);
954 ok_(__FILE__
, line
)( info
.dwTypeData
== type_data
|| (ULONG_PTR
)info
.dwTypeData
== LOWORD(type_data
),
955 "wrong type data %p/%p\n", info
.dwTypeData
, type_data
);
956 ok_(__FILE__
, line
)( info
.cch
== out_len
, "wrong len %x/%x\n", info
.cch
, out_len
);
960 ok_(__FILE__
, line
)( !strncmp( expname
, info
.dwTypeData
, out_len
),
961 "menu item name differed from '%s' '%s'\n", expname
, info
.dwTypeData
);
963 ok_(__FILE__
, line
)( !strncmpW( (WCHAR
*)expname
, (WCHAR
*)info
.dwTypeData
, out_len
),
964 "menu item name wrong\n" );
966 SetLastError( 0xdeadbeef );
967 ret
= ansi
? GetMenuStringA( hmenu
, 0, (char *)buffer
, 80, MF_BYPOSITION
) :
968 GetMenuStringW( hmenu
, 0, buffer
, 80, MF_BYPOSITION
);
970 ok_(__FILE__
, line
)( ret
, "GetMenuString failed, err %u\n", GetLastError());
972 ok_(__FILE__
, line
)( !ret
, "GetMenuString should have failed\n" );
976 static void modify_menu( int line
, HMENU hmenu
, BOOL ansi
, UINT flags
, UINT_PTR id
, void *data
)
980 SetLastError( 0xdeadbeef );
981 if (ansi
) ret
= ModifyMenuA( hmenu
, 0, flags
, id
, data
);
982 else ret
= ModifyMenuW( hmenu
, 0, flags
, id
, data
);
983 ok_(__FILE__
,line
)( ret
, "ModifyMenuA failed, err %u\n", GetLastError());
986 static void set_menu_item_info( int line
, HMENU hmenu
, BOOL ansi
, UINT mask
, UINT type
, UINT state
,
987 UINT id
, HMENU submenu
, HBITMAP checked
, HBITMAP unchecked
, ULONG_PTR data
,
988 void *type_data
, UINT len
, HBITMAP item
)
994 /* magic bitmap handle to test smaller cbSize */
995 if (item
== (HBITMAP
)(ULONG_PTR
)0xdeadbeef)
996 info
.cbSize
= FIELD_OFFSET(MENUITEMINFOA
,hbmpItem
);
998 info
.cbSize
= sizeof(info
);
1001 info
.fState
= state
;
1003 info
.hSubMenu
= submenu
;
1004 info
.hbmpChecked
= checked
;
1005 info
.hbmpUnchecked
= unchecked
;
1006 info
.dwItemData
= data
;
1007 info
.dwTypeData
= type_data
;
1009 info
.hbmpItem
= item
;
1010 SetLastError( 0xdeadbeef );
1011 if (ansi
) ret
= SetMenuItemInfoA( hmenu
, 0, TRUE
, &info
);
1012 else ret
= SetMenuItemInfoW( hmenu
, 0, TRUE
, (MENUITEMINFOW
*)&info
);
1013 ok_(__FILE__
, line
)( ret
, "SetMenuItemInfo failed, err %u\n", GetLastError());
1016 #define TMII_INSMI( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,eret1 )\
1017 hmenu = CreateMenu();\
1018 submenu = CreateMenu();\
1019 if(ansi)strcpy( string, init );\
1020 else strcpyW( string, init );\
1021 insert_menu_item( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, eret1 )
1023 /* GetMenuItemInfo + GetMenuString */
1024 #define TMII_GMII( c2,l2,\
1025 d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,\
1026 expname, eret2, eret3)\
1027 check_menu_item_info( __LINE__, hmenu, ansi, c2, d3, e3, f3, g3, h3, i3, j3, k3, l2, l3, m3, \
1028 expname, eret2, eret3 )
1031 RemoveMenu(hmenu, 0, TRUE );\
1032 DestroyMenu( hmenu );\
1033 DestroyMenu( submenu );
1036 #define TMII_MODM( flags, id, data ) \
1037 modify_menu( __LINE__, hmenu, ansi, flags, id, data )
1039 /* SetMenuItemInfo */
1040 #define TMII_SMII( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1 ) \
1041 set_menu_item_info( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1 )
1048 static void test_menu_iteminfo( void )
1054 WCHAR txtW
[]={'W','i','n','e',0};
1055 WCHAR initW
[]={'X','Y','Z',0};
1057 void *txt
, *init
, *empty
, *string
;
1058 HBITMAP hbm
= CreateBitmap(1,1,1,1,NULL
);
1060 HMENU hmenu
, submenu
=CreateMenu();
1061 HBITMAP dummy_hbm
= (HBITMAP
)(ULONG_PTR
)0xdeadbeef;
1064 if( ansi
) {txt
=txtA
;init
=initA
;empty
=emptyA
;string
=stringA
;}
1065 else {txt
=txtW
;init
=initW
;empty
=emptyW
;string
=stringA
;}
1066 trace( "%s string %p hbm %p txt %p\n", ansi
? "ANSI tests: " : "Unicode tests:", string
, hbm
, txt
);
1067 /* test all combinations of MFT_STRING, MFT_OWNERDRAW and MFT_BITMAP */
1068 /* (since MFT_STRING is zero, there are four of them) */
1069 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, 0, 0, 0, 0, 0, 0, txt
, 0, 0, OK
);
1070 TMII_GMII ( MIIM_TYPE
, 80,
1071 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1074 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1075 TMII_GMII ( MIIM_TYPE
, 80,
1076 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1079 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, 6, 0, OK
);
1080 TMII_GMII ( MIIM_TYPE
, 80,
1081 MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1084 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, hbm
, 6, 0, OK
);
1085 TMII_GMII ( MIIM_TYPE
, 80,
1086 MFT_BITMAP
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1089 /* not enough space for name*/
1090 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1091 TMII_GMII ( MIIM_TYPE
, 0,
1092 MFT_STRING
, 0, 0, 0, 0, 0, 0, NULL
, 4, 0,
1095 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1096 TMII_GMII ( MIIM_TYPE
, 5,
1097 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1100 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1101 TMII_GMII ( MIIM_TYPE
, 4,
1102 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 3, 0,
1105 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1106 TMII_GMII ( MIIM_TYPE
, 0,
1107 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 0, 0,
1110 /* cannot combine MIIM_TYPE with some other flags */
1111 TMII_INSMI( MIIM_TYPE
|MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, ER
);
1113 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1114 TMII_GMII ( MIIM_TYPE
|MIIM_STRING
, 80,
1115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1118 TMII_INSMI( MIIM_TYPE
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, ER
);
1120 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1121 TMII_GMII ( MIIM_TYPE
|MIIM_FTYPE
, 80,
1122 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1125 TMII_INSMI( MIIM_TYPE
|MIIM_BITMAP
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, 6, hbm
, ER
);
1127 /* but succeeds with some others */
1128 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1129 TMII_GMII ( MIIM_TYPE
|MIIM_SUBMENU
, 80,
1130 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1133 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1134 TMII_GMII ( MIIM_TYPE
|MIIM_STATE
, 80,
1135 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1138 TMII_INSMI( MIIM_TYPE
|MIIM_ID
, MFT_STRING
, -1, 888, 0, 0, 0, -1, txt
, 6, 0, OK
);
1139 TMII_GMII ( MIIM_TYPE
|MIIM_ID
, 80,
1140 MFT_STRING
, 0, 888, 0, 0, 0, 0, string
, 4, 0,
1143 TMII_INSMI( MIIM_TYPE
|MIIM_DATA
, MFT_STRING
, -1, -1, 0, 0, 0, 999, txt
, 6, 0, OK
);
1144 TMII_GMII ( MIIM_TYPE
|MIIM_DATA
, 80,
1145 MFT_STRING
, 0, 0, 0, 0, 0, 999, string
, 4, 0,
1148 /* to be continued */
1149 /* set text with MIIM_TYPE and retrieve with MIIM_STRING */
1150 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1151 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1152 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1155 /* set text with MIIM_TYPE and retrieve with MIIM_STRING; MFT_OWNERDRAW causes an empty string */
1156 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1157 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1158 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1161 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1162 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1163 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1166 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1167 TMII_GMII ( MIIM_FTYPE
, 80,
1168 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 80, 0,
1171 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1173 0, 0, 0, 0, 0, 0, 0, string
, 80, 0,
1176 /* contrary to MIIM_TYPE,you can set the text for an owner draw menu */
1177 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1178 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1179 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1182 /* same but retrieve with MIIM_TYPE */
1183 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1184 TMII_GMII ( MIIM_TYPE
, 80,
1185 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1188 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1189 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1190 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1193 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1194 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1195 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1199 /* How is that with bitmaps? */
1200 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1201 TMII_GMII ( MIIM_TYPE
, 80,
1202 MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1205 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1206 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1207 0, 0, 0, 0, 0, 0, 0, string
, 80, hbm
,
1210 /* MIIM_BITMAP does not like MFT_BITMAP */
1211 TMII_INSMI( MIIM_BITMAP
|MIIM_FTYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, ER
);
1213 /* no problem with OWNERDRAWN */
1214 TMII_INSMI( MIIM_BITMAP
|MIIM_FTYPE
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1215 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1216 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 80, hbm
,
1219 /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1220 TMII_INSMI( MIIM_FTYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER
);
1223 /* menu with submenu */
1224 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, submenu
, 0, 0, -1, txt
, 0, 0, OK
);
1225 TMII_GMII ( MIIM_SUBMENU
, 80,
1226 0, 0, 0, submenu
, 0, 0, 0, string
, 80, 0,
1229 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, submenu
, 0, 0, -1, empty
, 0, 0, OK
);
1230 TMII_GMII ( MIIM_SUBMENU
, 80,
1231 0, 0, 0, submenu
, 0, 0, 0, string
, 80, 0,
1234 /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1235 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, submenu
, 0, 0, -1, txt
, 0, 0, OK
);
1236 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1237 MFT_STRING
|MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1239 TMII_GMII ( MIIM_SUBMENU
|MIIM_FTYPE
, 80,
1240 MFT_SEPARATOR
, 0, 0, submenu
, 0, 0, 0, string
, 80, 0,
1243 /* menu with invalid submenu */
1244 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, (HMENU
)999, 0, 0, -1, txt
, 0, 0, ER
);
1247 TMII_INSMI( MIIM_TYPE
, MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, txt
, 0, 0, OK
);
1248 TMII_GMII ( MIIM_TYPE
, 80,
1249 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1252 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
|MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, hbm
, 6, 0, OK
);
1253 TMII_GMII ( MIIM_TYPE
, 80,
1254 MFT_BITMAP
|MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1257 /* SEPARATOR and STRING go well together */
1258 /* BITMAP and STRING go well together */
1259 TMII_INSMI( MIIM_STRING
|MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1260 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, 80,
1261 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, hbm
,
1264 /* BITMAP, SEPARATOR and STRING go well together */
1265 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1266 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, 80,
1267 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 4, hbm
,
1270 /* last two tests, but use MIIM_TYPE to retrieve info */
1271 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1272 TMII_GMII ( MIIM_TYPE
, 80,
1273 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1276 TMII_INSMI( MIIM_STRING
|MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1277 TMII_GMII ( MIIM_TYPE
, 80,
1278 MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1281 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1282 TMII_GMII ( MIIM_TYPE
, 80,
1283 MFT_SEPARATOR
|MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1286 /* same three with MFT_OWNERDRAW */
1287 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
, MFT_SEPARATOR
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1288 TMII_GMII ( MIIM_TYPE
, 80,
1289 MFT_SEPARATOR
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1292 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1293 TMII_GMII ( MIIM_TYPE
, 80,
1294 MFT_BITMAP
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1297 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1298 TMII_GMII ( MIIM_TYPE
, 80,
1299 MFT_SEPARATOR
|MFT_BITMAP
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1303 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
|MIIM_ID
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1304 TMII_GMII ( MIIM_TYPE
, 80,
1305 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1308 /* test with modifymenu: string is preserved after setting OWNERDRAW */
1309 TMII_INSMI( MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1310 TMII_MODM( MFT_OWNERDRAW
, -1, (void*)787 );
1311 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_DATA
, 80,
1312 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 787, string
, 4, 0,
1315 /* same with bitmap: now the text is cleared */
1316 TMII_INSMI( MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1317 TMII_MODM( MFT_BITMAP
, 545, hbm
);
1318 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1319 MFT_BITMAP
, 0, 545, 0, 0, 0, 0, string
, 0, hbm
,
1322 /* start with bitmap: now setting text clears it (though he flag is raised) */
1323 TMII_INSMI( MIIM_BITMAP
, MFT_STRING
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1324 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1325 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 0, hbm
,
1327 TMII_MODM( MFT_STRING
, 545, txt
);
1328 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1329 MFT_STRING
, 0, 545, 0, 0, 0, 0, string
, 4, 0,
1332 /*repeat with text NULL */
1333 TMII_INSMI( MIIM_BITMAP
, MFT_STRING
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1334 TMII_MODM( MFT_STRING
, 545, NULL
);
1335 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1336 MFT_SEPARATOR
, 0, 545, 0, 0, 0, 0, string
, 0, 0,
1339 /* repeat with text "" */
1340 TMII_INSMI( MIIM_BITMAP
, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1341 TMII_MODM( MFT_STRING
, 545, empty
);
1342 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1343 MFT_STRING
, 0, 545, 0, 0, 0, 0, string
, 0, 0,
1346 /* start with bitmap: set ownerdraw */
1347 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1348 TMII_MODM( MFT_OWNERDRAW
, -1, (void *)232 );
1349 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_DATA
, 80,
1350 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 232, string
, 0, hbm
,
1354 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1356 0, 0, 0, 0, 0, 0, 0, string
, 80, 0,
1359 /* some tests with small cbSize: the hbmpItem is to be ignored */
1360 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm
, OK
);
1361 TMII_GMII ( MIIM_TYPE
, 80,
1362 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, NULL
, 0, NULL
,
1365 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm
, OK
);
1366 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1367 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 80, NULL
,
1370 TMII_INSMI( MIIM_STRING
|MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1371 TMII_GMII ( MIIM_TYPE
, 80,
1372 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, NULL
,
1375 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1376 TMII_GMII ( MIIM_TYPE
, 80,
1377 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1380 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1381 TMII_GMII ( MIIM_TYPE
, 80,
1382 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1385 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1386 TMII_GMII ( MIIM_TYPE
, 80,
1387 MFT_SEPARATOR
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1390 /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus */
1391 TMII_INSMI( MIIM_TYPE
|MIIM_DATA
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, 343, txt
, 0, 0, OK
);
1392 TMII_GMII ( MIIM_TYPE
|MIIM_DATA
, 80,
1393 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1396 TMII_INSMI( MIIM_TYPE
|MIIM_DATA
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, 343, txt
, 0, 0, OK
);
1397 TMII_GMII ( MIIM_TYPE
, 80,
1398 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1401 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, 343, txt
, 0, 0, OK
);
1402 TMII_GMII ( MIIM_TYPE
|MIIM_DATA
, 80,
1403 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1406 /* set a string menu to ownerdraw with MIIM_TYPE */
1407 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -2, -2, 0, 0, 0, -2, txt
, -2, 0, OK
);
1408 TMII_SMII ( MIIM_TYPE
, MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1409 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1410 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1413 /* test with modifymenu add submenu */
1414 TMII_INSMI( MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1415 TMII_MODM( MF_POPUP
, (UINT_PTR
)submenu
, txt
);
1416 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_SUBMENU
, 80,
1417 MFT_STRING
, 0, 0, submenu
, 0, 0, 0, string
, 4, 0,
1419 TMII_GMII ( MIIM_TYPE
, 80,
1420 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1423 /* MFT_SEPARATOR bit is kept when the text is added */
1424 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1425 TMII_SMII( MIIM_STRING
, 0, 0, 0, 0, 0, 0, 0, txt
, 0, 0 );
1426 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1427 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1430 /* MFT_SEPARATOR bit is kept when bitmap is added */
1431 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1432 TMII_SMII( MIIM_BITMAP
, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm
);
1433 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1434 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 80, hbm
,
1437 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1438 Only the low word of the dwTypeData is used.
1439 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1440 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_RIGHTJUSTIFY
, -1, -1, 0, 0, 0, -1,
1441 (HMENU
)MAKELONG(HBMMENU_MBAR_CLOSE
, 0x1234), -1, 0, OK
);
1442 TMII_GMII ( MIIM_TYPE
, 80,
1443 MFT_BITMAP
| MFT_RIGHTJUSTIFY
, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE
, 0, HBMMENU_MBAR_CLOSE
,
1447 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1448 TMII_GMII ( MIIM_TYPE
, 80,
1449 MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1453 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1454 TMII_SMII( MIIM_STATE
, -1, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 0, 0 );
1455 TMII_GMII ( MIIM_STATE
, 80,
1456 0, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 80, 0,
1459 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1460 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1461 TMII_SMII( MIIM_CHECKMARKS
, MFT_RADIOCHECK
, 0, 0, 0, hbm
, hbm
, 0, 0, 0, 0 );
1462 TMII_GMII ( MIIM_CHECKMARKS
| MIIM_TYPE
, 80,
1463 MFT_BITMAP
, 0, 0, 0, hbm
, hbm
, 0, hbm
, 0, hbm
,
1466 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1467 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1468 TMII_SMII( MIIM_FTYPE
, MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, (HBITMAP
)0x1234, 0, 0 );
1469 TMII_GMII ( MIIM_FTYPE
, 80,
1470 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1472 TMII_GMII ( MIIM_TYPE
, 80,
1473 MFT_BITMAP
| MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1475 TMII_GMII ( MIIM_FTYPE
, 80,
1476 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1478 TMII_SMII( MIIM_BITMAP
, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
);
1479 TMII_GMII ( MIIM_TYPE
, 80,
1480 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 0, NULL
,
1483 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1484 Only the low word of the dwTypeData is used.
1485 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1486 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_RIGHTJUSTIFY
, -1, -1, 0, 0, 0, -1,
1487 (HMENU
)MAKELONG(HBMMENU_MBAR_CLOSE
, 0x1234), -1, 0, OK
);
1488 TMII_GMII ( MIIM_TYPE
, 80,
1489 MFT_BITMAP
| MFT_RIGHTJUSTIFY
, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE
, 0, HBMMENU_MBAR_CLOSE
,
1493 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1494 TMII_GMII ( MIIM_TYPE
, 80,
1495 MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1499 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1500 TMII_SMII( MIIM_STATE
, -1, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 0, 0 );
1501 TMII_GMII ( MIIM_STATE
, 80,
1502 0, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 80, 0,
1505 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1506 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1507 TMII_SMII( MIIM_CHECKMARKS
, MFT_RADIOCHECK
, 0, 0, 0, hbm
, hbm
, 0, 0, 0, 0 );
1508 TMII_GMII ( MIIM_CHECKMARKS
| MIIM_TYPE
, 80,
1509 MFT_BITMAP
, 0, 0, 0, hbm
, hbm
, 0, hbm
, 0, hbm
,
1512 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1513 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1514 TMII_SMII( MIIM_FTYPE
, MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, (HBITMAP
)0x1234, 0, 0 );
1515 TMII_GMII ( MIIM_FTYPE
, 80,
1516 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1518 TMII_GMII ( MIIM_TYPE
, 80,
1519 MFT_BITMAP
| MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1521 TMII_GMII ( MIIM_FTYPE
, 80,
1522 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1524 TMII_SMII( MIIM_BITMAP
, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
);
1525 TMII_GMII ( MIIM_TYPE
, 80,
1526 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 0, NULL
,
1529 } while( !(ansi
= !ansi
) );
1534 The following tests try to confirm the algorithm used to return the menu items
1535 when there is a collision between a menu item and a popup menu
1537 static void test_menu_search_bycommand( void )
1539 HMENU hmenu
, hmenuSub
, hmenuSub2
;
1545 static CHAR menuitem
[] = "MenuItem",
1546 menuitem2
[] = "MenuItem 2";
1548 /* Case 1: Menu containing a menu item */
1549 hmenu
= CreateMenu();
1551 memset( &info
, 0, sizeof info
);
1552 info
.cbSize
= sizeof info
;
1553 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1554 info
.fType
= MFT_STRING
;
1555 strcpy(strIn
, "Case 1 MenuItem");
1556 info
.dwTypeData
= strIn
;
1557 info
.wID
= (UINT
) 0x1234;
1559 rc
= InsertMenuItem(hmenu
, 0, TRUE
, &info
);
1560 ok (rc
, "Inserting the menuitem failed\n");
1562 id
= GetMenuItemID(hmenu
, 0);
1563 ok (id
== 0x1234, "Getting the menuitem id failed(gave %x)\n", id
);
1565 /* Confirm the menuitem was given the id supplied (getting by position) */
1566 memset( &info
, 0, sizeof info
);
1568 info
.cbSize
= sizeof(MENUITEMINFO
);
1569 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1570 info
.dwTypeData
= strback
;
1571 info
.cch
= sizeof(strback
);
1573 rc
= GetMenuItemInfo(hmenu
, 0, TRUE
, &info
); /* Get by position */
1574 ok (rc
, "Getting the menu items info failed\n");
1575 ok (info
.wID
== 0x1234, "IDs differ for the menuitem\n");
1576 ok (!strcmp(info
.dwTypeData
, "Case 1 MenuItem"), "Returned item has wrong label\n");
1578 /* Search by id - Should return the item */
1579 memset( &info
, 0, sizeof info
);
1581 info
.cbSize
= sizeof(MENUITEMINFO
);
1582 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1583 info
.dwTypeData
= strback
;
1584 info
.cch
= sizeof(strback
);
1585 rc
= GetMenuItemInfo(hmenu
, 0x1234, FALSE
, &info
); /* Get by ID */
1587 ok (rc
, "Getting the menu items info failed\n");
1588 ok (info
.wID
== 0x1234, "IDs differ for the menuitem\n");
1589 ok (!strcmp(info
.dwTypeData
, "Case 1 MenuItem"), "Returned item has wrong label\n");
1591 DestroyMenu( hmenu
);
1593 /* Case 2: Menu containing a popup menu */
1594 hmenu
= CreateMenu();
1595 hmenuSub
= CreateMenu();
1597 strcpy(strIn
, "Case 2 SubMenu");
1598 rc
= InsertMenu(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, strIn
);
1599 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1601 id
= GetMenuItemID(hmenu
, 0);
1602 ok (id
== -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id
);
1604 /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
1605 memset( &info
, 0, sizeof info
);
1607 info
.cbSize
= sizeof(MENUITEMINFO
);
1608 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1609 info
.dwTypeData
= strback
;
1610 info
.cch
= sizeof(strback
);
1611 info
.wID
= 0xdeadbeef;
1613 rc
= GetMenuItemInfo(hmenu
, 0, TRUE
, &info
); /* Get by position */
1614 ok (rc
, "Getting the menu items info failed\n");
1615 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the menuitem\n");
1616 ok (!strcmp(info
.dwTypeData
, "Case 2 SubMenu"), "Returned item has wrong label\n");
1618 /* Search by id - returns the popup menu itself */
1619 memset( &info
, 0, sizeof info
);
1621 info
.cbSize
= sizeof(MENUITEMINFO
);
1622 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1623 info
.dwTypeData
= strback
;
1624 info
.cch
= sizeof(strback
);
1625 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
); /* Get by ID */
1627 ok (rc
, "Getting the menu items info failed\n");
1628 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the popup menu\n");
1629 ok (!strcmp(info
.dwTypeData
, "Case 2 SubMenu"), "Returned item has wrong label\n");
1632 Now add an item after it with the same id
1634 memset( &info
, 0, sizeof info
);
1635 info
.cbSize
= sizeof info
;
1636 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1637 info
.fType
= MFT_STRING
;
1638 strcpy(strIn
, "Case 2 MenuItem 1");
1639 info
.dwTypeData
= strIn
;
1640 info
.wID
= (UINT_PTR
) hmenuSub
;
1641 rc
= InsertMenuItem(hmenu
, -1, TRUE
, &info
);
1642 ok (rc
, "Inserting the menuitem failed\n");
1644 /* Search by id - returns the item which follows the popup menu */
1645 memset( &info
, 0, sizeof info
);
1647 info
.cbSize
= sizeof(MENUITEMINFO
);
1648 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1649 info
.dwTypeData
= strback
;
1650 info
.cch
= sizeof(strback
);
1651 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
); /* Get by ID */
1653 ok (rc
, "Getting the menu items info failed\n");
1654 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the popup menu\n");
1655 ok (!strcmp(info
.dwTypeData
, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1658 Now add an item before the popup (with the same id)
1660 memset( &info
, 0, sizeof info
);
1661 info
.cbSize
= sizeof info
;
1662 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1663 info
.fType
= MFT_STRING
;
1664 strcpy(strIn
, "Case 2 MenuItem 2");
1665 info
.dwTypeData
= strIn
;
1666 info
.wID
= (UINT_PTR
) hmenuSub
;
1667 rc
= InsertMenuItem(hmenu
, 0, TRUE
, &info
);
1668 ok (rc
, "Inserting the menuitem failed\n");
1670 /* Search by id - returns the item which precedes the popup menu */
1671 memset( &info
, 0, sizeof info
);
1673 info
.cbSize
= sizeof(MENUITEMINFO
);
1674 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1675 info
.dwTypeData
= strback
;
1676 info
.cch
= sizeof(strback
);
1677 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
); /* Get by ID */
1679 ok (rc
, "Getting the menu items info failed\n");
1680 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the popup menu\n");
1681 ok (!strcmp(info
.dwTypeData
, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1683 DestroyMenu( hmenu
);
1684 DestroyMenu( hmenuSub
);
1687 Case 3: Menu containing a popup menu which in turn
1688 contains 2 items with the same id as the popup itself
1691 hmenu
= CreateMenu();
1692 hmenuSub
= CreateMenu();
1694 memset( &info
, 0, sizeof info
);
1695 info
.cbSize
= sizeof info
;
1696 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1697 info
.fType
= MFT_STRING
;
1698 info
.dwTypeData
= menuitem
;
1699 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1701 rc
= InsertMenu(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, "Submenu");
1702 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1704 rc
= InsertMenuItem(hmenuSub
, 0, TRUE
, &info
);
1705 ok (rc
, "Inserting the sub menu menuitem failed\n");
1707 memset( &info
, 0, sizeof info
);
1708 info
.cbSize
= sizeof info
;
1709 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1710 info
.fType
= MFT_STRING
;
1711 info
.dwTypeData
= menuitem2
;
1712 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1714 rc
= InsertMenuItem(hmenuSub
, 1, TRUE
, &info
);
1715 ok (rc
, "Inserting the sub menu menuitem 2 failed\n");
1717 /* Prove that you can't query the id of a popup directly (By position) */
1718 id
= GetMenuItemID(hmenu
, 0);
1719 ok (id
== -1, "Getting the sub menu id should have failed because its a popup (gave %x)\n", id
);
1721 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1722 memset( &info
, 0, sizeof info
);
1724 info
.cbSize
= sizeof(MENUITEMINFO
);
1725 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1726 info
.dwTypeData
= strback
;
1727 info
.cch
= sizeof(strback
);
1729 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
);
1730 ok (rc
, "Getting the menus info failed\n");
1731 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for popup menu\n");
1732 ok (!strcmp(info
.dwTypeData
, "MenuItem"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1733 DestroyMenu( hmenu
);
1734 DestroyMenu( hmenuSub
);
1737 Case 4: Menu containing 2 popup menus, the second
1738 contains 2 items with the same id as the first popup menu
1740 hmenu
= CreateMenu();
1741 hmenuSub
= CreateMenu();
1742 hmenuSub2
= CreateMenu();
1744 rc
= InsertMenu(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, "Submenu");
1745 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1747 rc
= InsertMenu(hmenu
, 1, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub2
, "Submenu2");
1748 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1750 memset( &info
, 0, sizeof info
);
1751 info
.cbSize
= sizeof info
;
1752 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1753 info
.fType
= MFT_STRING
;
1754 info
.dwTypeData
= menuitem
;
1755 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1757 rc
= InsertMenuItem(hmenuSub2
, 0, TRUE
, &info
);
1758 ok (rc
, "Inserting the sub menu menuitem failed\n");
1760 memset( &info
, 0, sizeof info
);
1761 info
.cbSize
= sizeof info
;
1762 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1763 info
.fType
= MFT_STRING
;
1764 info
.dwTypeData
= menuitem2
;
1765 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1767 rc
= InsertMenuItem(hmenuSub2
, 1, TRUE
, &info
);
1768 ok (rc
, "Inserting the sub menu menuitem 2 failed\n");
1770 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1771 memset( &info
, 0, sizeof info
);
1773 info
.cbSize
= sizeof(MENUITEMINFO
);
1774 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1775 info
.dwTypeData
= strback
;
1776 info
.cch
= sizeof(strback
);
1778 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
);
1779 ok (rc
, "Getting the menus info failed\n");
1780 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for popup menu\n");
1781 ok (!strcmp(info
.dwTypeData
, "MenuItem"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1783 memset( &info
, 0, sizeof info
);
1785 info
.cbSize
= sizeof(MENUITEMINFO
);
1786 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1787 info
.dwTypeData
= strback
;
1788 info
.cch
= sizeof(strback
);
1790 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub2
, FALSE
, &info
);
1791 ok (rc
, "Getting the menus info failed\n");
1792 ok (info
.wID
== (UINT_PTR
)hmenuSub2
, "IDs differ for popup menu\n");
1793 ok (!strcmp(info
.dwTypeData
, "Submenu2"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1795 DestroyMenu( hmenu
);
1796 DestroyMenu( hmenuSub
);
1797 DestroyMenu( hmenuSub2
);
1801 Case 5: Menu containing a popup menu which in turn
1802 contains an item with a different id than the popup menu.
1803 This tests the fallback to a popup menu ID.
1806 hmenu
= CreateMenu();
1807 hmenuSub
= CreateMenu();
1809 rc
= AppendMenu(hmenu
, MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, "Submenu");
1810 ok (rc
, "Appending the popup menu to the main menu failed\n");
1812 rc
= AppendMenu(hmenuSub
, MF_STRING
, 102, "Item");
1813 ok (rc
, "Appending the item to the popup menu failed\n");
1815 /* Set the ID for hmenuSub */
1816 info
.cbSize
= sizeof(info
);
1817 info
.fMask
= MIIM_ID
;
1820 rc
= SetMenuItemInfo(hmenu
, 0, TRUE
, &info
);
1821 ok(rc
, "Setting the ID for the popup menu failed\n");
1823 /* Check if the ID has been set */
1825 rc
= GetMenuItemInfo(hmenu
, 0, TRUE
, &info
);
1826 ok(rc
, "Getting the ID for the popup menu failed\n");
1827 ok(info
.wID
== 101, "The ID for the popup menu has not been set\n");
1829 /* Prove getting the item info via ID returns the popup menu */
1830 memset( &info
, 0, sizeof(info
));
1832 info
.cbSize
= sizeof(MENUITEMINFO
);
1833 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1834 info
.dwTypeData
= strback
;
1835 info
.cch
= sizeof(strback
);
1837 rc
= GetMenuItemInfo(hmenu
, 101, FALSE
, &info
);
1838 ok (rc
, "Getting the menu info failed\n");
1839 ok (info
.wID
== 101, "IDs differ\n");
1840 ok (!strcmp(info
.dwTypeData
, "Submenu"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1842 /* Also look for the menu item */
1843 memset( &info
, 0, sizeof(info
));
1845 info
.cbSize
= sizeof(MENUITEMINFO
);
1846 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1847 info
.dwTypeData
= strback
;
1848 info
.cch
= sizeof(strback
);
1850 rc
= GetMenuItemInfo(hmenu
, 102, FALSE
, &info
);
1851 ok (rc
, "Getting the menu info failed\n");
1852 ok (info
.wID
== 102, "IDs differ\n");
1853 ok (!strcmp(info
.dwTypeData
, "Item"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1856 DestroyMenu(hmenuSub
);
1859 struct menu_item_pair_s
{
1860 UINT uMenu
; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
1861 * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
1862 * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
1866 static struct menu_mouse_tests_s
{
1868 struct menu_item_pair_s menu_item_pairs
[5]; /* for mousing */
1869 WORD wVk
[5]; /* keys */
1873 /* for each test, send keys or clicks and check for menu visibility */
1874 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 0}, TRUE
, FALSE
}, /* test 0 */
1875 { INPUT_KEYBOARD
, {{0}}, {VK_ESCAPE
, 0}, FALSE
, FALSE
},
1876 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 0}, TRUE
, FALSE
},
1877 { INPUT_KEYBOARD
, {{0}}, {'D', 0}, FALSE
, FALSE
},
1878 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 0}, TRUE
, FALSE
},
1879 { INPUT_KEYBOARD
, {{0}}, {'E', 0}, FALSE
, FALSE
},
1880 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 0}, TRUE
, FALSE
},
1881 { INPUT_KEYBOARD
, {{0}}, {VK_ESCAPE
, VK_ESCAPE
, 0}, FALSE
, FALSE
},
1882 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', VK_ESCAPE
, 0}, TRUE
, FALSE
},
1883 { INPUT_KEYBOARD
, {{0}}, {VK_ESCAPE
, 0}, FALSE
, FALSE
},
1884 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 0}, TRUE
, FALSE
},
1885 { INPUT_KEYBOARD
, {{0}}, {'D', 0}, FALSE
, FALSE
},
1886 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 0}, TRUE
, FALSE
},
1887 { INPUT_KEYBOARD
, {{0}}, {'E', 0}, FALSE
, FALSE
},
1888 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 'P', 0}, TRUE
, FALSE
},
1889 { INPUT_KEYBOARD
, {{0}}, {'D', 0}, FALSE
, FALSE
},
1890 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 'P', 0}, TRUE
, FALSE
},
1891 { INPUT_KEYBOARD
, {{0}}, {'E', 0}, FALSE
, FALSE
},
1893 { INPUT_MOUSE
, {{1, 2}, {0}}, {0}, TRUE
, TRUE
}, /* test 18 */
1894 { INPUT_MOUSE
, {{1, 1}, {0}}, {0}, FALSE
, FALSE
},
1895 { INPUT_MOUSE
, {{1, 0}, {0}}, {0}, TRUE
, TRUE
},
1896 { INPUT_MOUSE
, {{1, 1}, {0}}, {0}, FALSE
, FALSE
},
1897 { INPUT_MOUSE
, {{1, 0}, {2, 2}, {0}}, {0}, TRUE
, TRUE
},
1898 { INPUT_MOUSE
, {{2, 1}, {0}}, {0}, FALSE
, FALSE
},
1899 { INPUT_MOUSE
, {{1, 0}, {2, 0}, {0}}, {0}, TRUE
, TRUE
},
1900 { INPUT_MOUSE
, {{3, 0}, {0}}, {0}, FALSE
, FALSE
},
1901 { INPUT_MOUSE
, {{1, 0}, {2, 0}, {0}}, {0}, TRUE
, TRUE
},
1902 { INPUT_MOUSE
, {{3, 1}, {0}}, {0}, TRUE
, TRUE
},
1903 { INPUT_MOUSE
, {{1, 1}, {0}}, {0}, FALSE
, FALSE
},
1907 static void send_key(WORD wVk
)
1910 memset(i
, 0, sizeof(i
));
1911 i
[0].type
= i
[1].type
= INPUT_KEYBOARD
;
1912 i
[0].u
.ki
.wVk
= i
[1].u
.ki
.wVk
= wVk
;
1913 i
[1].u
.ki
.dwFlags
= KEYEVENTF_KEYUP
;
1914 pSendInput(2, (INPUT
*) i
, sizeof(INPUT
));
1917 static BOOL
click_menu(HANDLE hWnd
, struct menu_item_pair_s
*mi
)
1919 HMENU hMenu
= hMenus
[mi
->uMenu
];
1923 int screen_w
= GetSystemMetrics(SM_CXSCREEN
);
1924 int screen_h
= GetSystemMetrics(SM_CYSCREEN
);
1925 BOOL ret
= GetMenuItemRect(mi
->uMenu
> 2 ? NULL
: hWnd
, hMenu
, mi
->uItem
, &r
);
1926 if(!ret
) return FALSE
;
1928 memset(i
, 0, sizeof(i
));
1929 i
[0].type
= i
[1].type
= i
[2].type
= INPUT_MOUSE
;
1930 i
[0].u
.mi
.dx
= i
[1].u
.mi
.dx
= i
[2].u
.mi
.dx
1931 = ((r
.left
+ 5) * 65535) / screen_w
;
1932 i
[0].u
.mi
.dy
= i
[1].u
.mi
.dy
= i
[2].u
.mi
.dy
1933 = ((r
.top
+ 5) * 65535) / screen_h
;
1934 i
[0].u
.mi
.dwFlags
= i
[1].u
.mi
.dwFlags
= i
[2].u
.mi
.dwFlags
1935 = MOUSEEVENTF_ABSOLUTE
;
1936 i
[0].u
.mi
.dwFlags
|= MOUSEEVENTF_MOVE
;
1937 i
[1].u
.mi
.dwFlags
|= MOUSEEVENTF_LEFTDOWN
;
1938 i
[2].u
.mi
.dwFlags
|= MOUSEEVENTF_LEFTUP
;
1939 ret
= pSendInput(3, (INPUT
*) i
, sizeof(INPUT
));
1941 /* hack to prevent mouse message buildup in Wine */
1942 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
1946 static DWORD WINAPI
test_menu_input_thread(LPVOID lpParameter
)
1949 HANDLE hWnd
= lpParameter
;
1952 /* mixed keyboard/mouse test */
1953 for (i
= 0; menu_tests
[i
].type
!= -1; i
++)
1955 int ret
= TRUE
, elapsed
= 0;
1957 got_input
= i
&& menu_tests
[i
-1].bMenuVisible
;
1959 if (menu_tests
[i
].type
== INPUT_KEYBOARD
)
1960 for (j
= 0; menu_tests
[i
].wVk
[j
] != 0; j
++)
1961 send_key(menu_tests
[i
].wVk
[j
]);
1963 for (j
= 0; menu_tests
[i
].menu_item_pairs
[j
].uMenu
!= 0; j
++)
1964 if (!(ret
= click_menu(hWnd
, &menu_tests
[i
].menu_item_pairs
[j
]))) break;
1968 skip( "test %u: failed to send input\n", i
);
1969 PostMessage( hWnd
, WM_CANCELMODE
, 0, 0 );
1972 while (menu_tests
[i
].bMenuVisible
!= bMenuVisible
)
1982 skip( "test %u: didn't receive input\n", i
);
1983 PostMessage( hWnd
, WM_CANCELMODE
, 0, 0 );
1987 if (menu_tests
[i
]._todo_wine
)
1990 ok(menu_tests
[i
].bMenuVisible
== bMenuVisible
, "test %d\n", i
);
1994 ok(menu_tests
[i
].bMenuVisible
== bMenuVisible
, "test %d\n", i
);
1999 static LRESULT CALLBACK
WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
,
2003 case WM_ENTERMENULOOP
:
2004 bMenuVisible
= TRUE
;
2006 case WM_EXITMENULOOP
:
2007 bMenuVisible
= FALSE
;
2012 case WM_LBUTTONDOWN
:
2014 case WM_NCMOUSEMOVE
:
2015 case WM_NCLBUTTONDOWN
:
2016 case WM_NCLBUTTONUP
:
2020 return( DefWindowProcA( hWnd
, msg
, wParam
, lParam
) );
2025 static void test_menu_input(void) {
2028 HINSTANCE hInstance
= GetModuleHandleA( NULL
);
2029 HANDLE hThread
, hWnd
;
2032 wclass
.lpszClassName
= "MenuTestClass";
2033 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
2034 wclass
.lpfnWndProc
= WndProc
;
2035 wclass
.hInstance
= hInstance
;
2036 wclass
.hIcon
= LoadIconA( 0, IDI_APPLICATION
);
2037 wclass
.hCursor
= LoadCursorA( NULL
, IDC_ARROW
);
2038 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
2039 wclass
.lpszMenuName
= 0;
2040 wclass
.cbClsExtra
= 0;
2041 wclass
.cbWndExtra
= 0;
2042 assert (RegisterClassA( &wclass
));
2043 assert (hWnd
= CreateWindowA( wclass
.lpszClassName
, "MenuTest",
2044 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0,
2045 400, 200, NULL
, NULL
, hInstance
, NULL
) );
2048 hMenus
[3] = CreatePopupMenu();
2049 AppendMenu(hMenus
[3], MF_STRING
, 0, "&Enabled");
2050 AppendMenu(hMenus
[3], MF_STRING
|MF_DISABLED
, 0, "&Disabled");
2052 hMenus
[2] = CreatePopupMenu();
2053 AppendMenu(hMenus
[2], MF_STRING
|MF_POPUP
, (UINT_PTR
) hMenus
[3], "&Popup");
2054 AppendMenu(hMenus
[2], MF_STRING
, 0, "&Enabled");
2055 AppendMenu(hMenus
[2], MF_STRING
|MF_DISABLED
, 0, "&Disabled");
2057 hMenus
[1] = CreateMenu();
2058 AppendMenu(hMenus
[1], MF_STRING
|MF_POPUP
, (UINT_PTR
) hMenus
[2], "&Menu");
2059 AppendMenu(hMenus
[1], MF_STRING
, 0, "&Enabled");
2060 AppendMenu(hMenus
[1], MF_STRING
|MF_DISABLED
, 0, "&Disabled");
2062 SetMenu(hWnd
, hMenus
[1]);
2063 ShowWindow(hWnd
, SW_SHOW
);
2066 hThread
= CreateThread(NULL
, 0, test_menu_input_thread
, hWnd
, 0, &tid
);
2069 if (WAIT_TIMEOUT
!= WaitForSingleObject(hThread
, 50))
2071 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2073 DestroyWindow(hWnd
);
2076 static void test_menu_flags( void )
2078 HMENU hMenu
, hPopupMenu
;
2080 hMenu
= CreateMenu();
2081 hPopupMenu
= CreatePopupMenu();
2083 AppendMenu(hMenu
, MF_POPUP
| MF_STRING
, (UINT_PTR
)hPopupMenu
, "Popup");
2085 AppendMenu(hPopupMenu
, MF_STRING
| MF_HILITE
| MF_DEFAULT
, 101, "Item 1");
2086 InsertMenu(hPopupMenu
, 1, MF_BYPOSITION
| MF_STRING
| MF_HILITE
| MF_DEFAULT
, 102, "Item 2");
2087 AppendMenu(hPopupMenu
, MF_STRING
, 103, "Item 3");
2088 ModifyMenu(hPopupMenu
, 2, MF_BYPOSITION
| MF_STRING
| MF_HILITE
| MF_DEFAULT
, 103, "Item 3");
2090 ok(GetMenuState(hPopupMenu
, 0, MF_BYPOSITION
) & MF_HILITE
,
2091 "AppendMenu should accept MF_HILITE\n");
2092 ok(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
,
2093 "InsertMenu should accept MF_HILITE\n");
2094 ok(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_HILITE
,
2095 "ModifyMenu should accept MF_HILITE\n");
2097 ok(!(GetMenuState(hPopupMenu
, 0, MF_BYPOSITION
) & MF_DEFAULT
),
2098 "AppendMenu must not accept MF_DEFAULT\n");
2099 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_DEFAULT
),
2100 "InsertMenu must not accept MF_DEFAULT\n");
2101 ok(!(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_DEFAULT
),
2102 "ModifyMenu must not accept MF_DEFAULT\n");
2107 static void test_menu_hilitemenuitem( void )
2109 HMENU hMenu
, hPopupMenu
;
2113 wclass
.lpszClassName
= "HiliteMenuTestClass";
2114 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
2115 wclass
.lpfnWndProc
= WndProc
;
2116 wclass
.hInstance
= GetModuleHandleA( NULL
);
2117 wclass
.hIcon
= LoadIconA( 0, IDI_APPLICATION
);
2118 wclass
.hCursor
= LoadCursorA( NULL
, IDC_ARROW
);
2119 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
2120 wclass
.lpszMenuName
= 0;
2121 wclass
.cbClsExtra
= 0;
2122 wclass
.cbWndExtra
= 0;
2123 assert (RegisterClassA( &wclass
));
2124 assert (hWnd
= CreateWindowA( wclass
.lpszClassName
, "HiliteMenuTest",
2125 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0,
2126 400, 200, NULL
, NULL
, wclass
.hInstance
, NULL
) );
2128 hMenu
= CreateMenu();
2129 hPopupMenu
= CreatePopupMenu();
2131 AppendMenu(hMenu
, MF_POPUP
| MF_STRING
, (UINT_PTR
)hPopupMenu
, "Popup");
2133 AppendMenu(hPopupMenu
, MF_STRING
, 101, "Item 1");
2134 AppendMenu(hPopupMenu
, MF_STRING
, 102, "Item 2");
2135 AppendMenu(hPopupMenu
, MF_STRING
, 103, "Item 3");
2137 SetMenu(hWnd
, hMenu
);
2139 /* test invalid arguments */
2141 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2142 "HiliteMenuItem: Item 2 is hilited\n");
2144 SetLastError(0xdeadbeef);
2147 ok(!HiliteMenuItem(NULL
, hPopupMenu
, 1, MF_HILITE
| MF_BYPOSITION
),
2148 "HiliteMenuItem: call should have failed.\n");
2150 ok(GetLastError() == 0xdeadbeef || /* 9x */
2151 GetLastError() == ERROR_INVALID_WINDOW_HANDLE
/* NT */,
2152 "HiliteMenuItem: expected error ERROR_INVALID_WINDOW_HANDLE, got: %d\n", GetLastError());
2154 SetLastError(0xdeadbeef);
2155 ok(!HiliteMenuItem(hWnd
, NULL
, 1, MF_HILITE
| MF_BYPOSITION
),
2156 "HiliteMenuItem: call should have failed.\n");
2157 ok(GetLastError() == 0xdeadbeef || /* 9x */
2158 GetLastError() == ERROR_INVALID_MENU_HANDLE
/* NT */,
2159 "HiliteMenuItem: expected error ERROR_INVALID_MENU_HANDLE, got: %d\n", GetLastError());
2161 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2162 "HiliteMenuItem: Item 2 is hilited\n");
2164 /* either MF_HILITE or MF_UNHILITE *and* MF_BYCOMMAND or MF_BYPOSITION need to be set */
2166 SetLastError(0xdeadbeef);
2167 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_BYPOSITION
),
2168 "HiliteMenuItem: call should have succeeded.\n");
2169 ok(GetLastError() == 0xdeadbeef,
2170 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2172 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2173 "HiliteMenuItem: Item 2 is hilited\n");
2175 SetLastError(0xdeadbeef);
2178 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_HILITE
),
2179 "HiliteMenuItem: call should have succeeded.\n");
2181 ok(GetLastError() == 0xdeadbeef,
2182 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2184 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2185 "HiliteMenuItem: Item 2 is hilited\n");
2187 /* hilite a menu item (by position) */
2189 SetLastError(0xdeadbeef);
2190 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_HILITE
| MF_BYPOSITION
),
2191 "HiliteMenuItem: call should not have failed.\n");
2192 ok(GetLastError() == 0xdeadbeef,
2193 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2197 ok(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
,
2198 "HiliteMenuItem: Item 2 is not hilited\n");
2201 /* unhilite a menu item (by position) */
2203 SetLastError(0xdeadbeef);
2204 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_UNHILITE
| MF_BYPOSITION
),
2205 "HiliteMenuItem: call should not have failed.\n");
2206 ok(GetLastError() == 0xdeadbeef,
2207 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2209 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2210 "HiliteMenuItem: Item 2 is hilited\n");
2212 /* hilite a menu item (by command) */
2214 SetLastError(0xdeadbeef);
2215 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 103, MF_HILITE
| MF_BYCOMMAND
),
2216 "HiliteMenuItem: call should not have failed.\n");
2217 ok(GetLastError() == 0xdeadbeef,
2218 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2222 ok(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_HILITE
,
2223 "HiliteMenuItem: Item 3 is not hilited\n");
2226 /* unhilite a menu item (by command) */
2228 SetLastError(0xdeadbeef);
2229 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 103, MF_UNHILITE
| MF_BYCOMMAND
),
2230 "HiliteMenuItem: call should not have failed.\n");
2231 ok(GetLastError() == 0xdeadbeef,
2232 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2234 ok(!(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_HILITE
),
2235 "HiliteMenuItem: Item 3 is hilited\n");
2237 DestroyWindow(hWnd
);
2240 static void check_menu_items(HMENU hmenu
, UINT checked_cmd
, UINT checked_type
,
2245 count
= GetMenuItemCount(hmenu
);
2246 ok (count
!= -1, "GetMenuItemCount returned -1\n");
2248 for (i
= 0; i
< count
; i
++)
2253 memset(&mii
, 0, sizeof(mii
));
2254 mii
.cbSize
= sizeof(mii
);
2255 mii
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_ID
| MIIM_SUBMENU
;
2256 ret
= GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
);
2257 ok(ret
, "GetMenuItemInfo(%u) failed\n", i
);
2259 trace("item #%u: fType %04x, fState %04x, wID %u, hSubMenu %p\n",
2260 i
, mii
.fType
, mii
.fState
, mii
.wID
, mii
.hSubMenu
);
2264 ok(mii
.wID
== (UINT_PTR
)mii
.hSubMenu
, "id %u: wID should be equal to hSubMenu\n", checked_cmd
);
2265 check_menu_items(mii
.hSubMenu
, checked_cmd
, checked_type
, checked_state
);
2269 if (mii
.wID
== checked_cmd
)
2271 ok(mii
.fType
== checked_type
, "id %u: expected fType %04x, got %04x\n", checked_cmd
, checked_type
, mii
.fType
);
2272 ok(mii
.fState
== checked_state
, "id %u: expected fState %04x, got %04x\n", checked_cmd
, checked_state
, mii
.fState
);
2273 ok(mii
.wID
!= 0, "id %u: not expected wID 0\n", checked_cmd
);
2277 ok(mii
.fType
!= MFT_RADIOCHECK
, "id %u: not expected fType MFT_RADIOCHECK on cmd %u\n", checked_cmd
, mii
.wID
);
2279 if (mii
.fType
== MFT_SEPARATOR
)
2281 ok(mii
.fState
== MFS_GRAYED
, "id %u: expected fState MFS_GRAYED, got %04x\n", checked_cmd
, mii
.fState
);
2282 ok(mii
.wID
== 0, "id %u: expected wID 0, got %u\n", checked_cmd
, mii
.wID
);
2286 ok(mii
.fState
== 0, "id %u: expected fState 0, got %04x\n", checked_cmd
, mii
.fState
);
2287 ok(mii
.wID
!= 0, "id %u: not expected wID 0\n", checked_cmd
);
2294 static void clear_ftype_and_state(HMENU hmenu
, UINT id
, UINT flags
)
2299 memset(&mii
, 0, sizeof(mii
));
2300 mii
.cbSize
= sizeof(mii
);
2301 mii
.fMask
= MIIM_FTYPE
| MIIM_STATE
;
2302 ret
= SetMenuItemInfo(hmenu
, id
, (flags
& MF_BYPOSITION
) != 0, &mii
);
2303 ok(ret
, "SetMenuItemInfo(%u) failed\n", id
);
2306 static void test_CheckMenuRadioItem(void)
2311 hmenu
= LoadMenu(GetModuleHandle(0), MAKEINTRESOURCE(1));
2314 check_menu_items(hmenu
, -1, 0, 0);
2316 ret
= CheckMenuRadioItem(hmenu
, 100, 100, 100, MF_BYCOMMAND
);
2317 ok(ret
, "CheckMenuRadioItem failed\n");
2318 check_menu_items(hmenu
, 100, MFT_RADIOCHECK
, MFS_CHECKED
);
2320 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2321 ret
= CheckMenuRadioItem(hmenu
, 100, 100, -1, MF_BYCOMMAND
);
2322 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2323 check_menu_items(hmenu
, 100, MFT_RADIOCHECK
, 0);
2326 clear_ftype_and_state(hmenu
, 100, MF_BYCOMMAND
);
2327 check_menu_items(hmenu
, -1, 0, 0);
2329 /* first and checked items are on different menus */
2330 ret
= CheckMenuRadioItem(hmenu
, 0, 300, 202, MF_BYCOMMAND
);
2331 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2332 check_menu_items(hmenu
, -1, 0, 0);
2334 ret
= CheckMenuRadioItem(hmenu
, 200, 300, 202, MF_BYCOMMAND
);
2335 ok(ret
, "CheckMenuRadioItem failed\n");
2336 check_menu_items(hmenu
, 202, MFT_RADIOCHECK
, MFS_CHECKED
);
2338 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2339 ret
= CheckMenuRadioItem(hmenu
, 202, 202, -1, MF_BYCOMMAND
);
2340 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2341 check_menu_items(hmenu
, 202, MFT_RADIOCHECK
, 0);
2344 clear_ftype_and_state(hmenu
, 202, MF_BYCOMMAND
);
2345 check_menu_items(hmenu
, -1, 0, 0);
2347 /* just for fun, try to check separator */
2348 ret
= CheckMenuRadioItem(hmenu
, 0, 300, 0, MF_BYCOMMAND
);
2349 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2350 check_menu_items(hmenu
, -1, 0, 0);
2353 static void test_menu_resource_layout(void)
2357 MENUITEMTEMPLATEHEADER mith
;
2361 { 0, 0 }, /* versionNumber, offset */
2363 /* mtOption, mtID, mtString[] '\0' terminated */
2364 MF_STRING
, 1, 'F', 0,
2367 /* MF_SEPARATOR, 4, 'S', 0, FIXME: Wine ignores 'S' */
2368 MF_STRING
|MF_GRAYED
|MF_END
, 5, 'E', 0
2373 UINT type
, state
, id
;
2377 { MF_STRING
, MF_ENABLED
, 1, "F" },
2378 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 2, "" },
2379 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 3, "" },
2380 /*{ MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 4, "S" }, FIXME: Wine ignores 'S'*/
2381 { MF_STRING
, MF_GRAYED
, 5, "E" },
2382 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 6, "" },
2383 { MF_STRING
, MF_ENABLED
, 7, "" },
2384 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 8, "" }
2390 hmenu
= LoadMenuIndirect(&menu_template
);
2391 ok(hmenu
!= 0, "LoadMenuIndirect error %u\n", GetLastError());
2393 ret
= AppendMenu(hmenu
, MF_STRING
, 6, NULL
);
2394 ok(ret
, "AppendMenu failed\n");
2395 ret
= AppendMenu(hmenu
, MF_STRING
, 7, "\0");
2396 ok(ret
, "AppendMenu failed\n");
2397 ret
= AppendMenu(hmenu
, MF_SEPARATOR
, 8, "separator");
2398 ok(ret
, "AppendMenu failed\n");
2400 count
= GetMenuItemCount(hmenu
);
2401 ok(count
== sizeof(menu_data
)/sizeof(menu_data
[0]),
2402 "expected %u menu items, got %u\n",
2403 (UINT
)(sizeof(menu_data
)/sizeof(menu_data
[0])), count
);
2405 for (i
= 0; i
< count
; i
++)
2410 memset(&mii
, 0, sizeof(mii
));
2411 mii
.cbSize
= sizeof(mii
);
2412 mii
.dwTypeData
= buf
;
2413 mii
.cch
= sizeof(buf
);
2414 mii
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_ID
| MIIM_STRING
;
2415 ret
= GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
);
2416 ok(ret
, "GetMenuItemInfo(%u) failed\n", i
);
2418 trace("item #%u: fType %04x, fState %04x, wID %u, dwTypeData %s\n",
2419 i
, mii
.fType
, mii
.fState
, mii
.wID
, (LPCSTR
)mii
.dwTypeData
);
2421 ok(mii
.fType
== menu_data
[i
].type
,
2422 "%u: expected fType %04x, got %04x\n", i
, menu_data
[i
].type
, mii
.fType
);
2423 ok(mii
.fState
== menu_data
[i
].state
,
2424 "%u: expected fState %04x, got %04x\n", i
, menu_data
[i
].state
, mii
.fState
);
2425 ok(mii
.wID
== menu_data
[i
].id
,
2426 "%u: expected wID %04x, got %04x\n", i
, menu_data
[i
].id
, mii
.wID
);
2427 ok(mii
.cch
== strlen(menu_data
[i
].str
),
2428 "%u: expected cch %u, got %u\n", i
, (UINT
)strlen(menu_data
[i
].str
), mii
.cch
);
2429 ok(!strcmp(mii
.dwTypeData
, menu_data
[i
].str
),
2430 "%u: expected dwTypeData %s, got %s\n", i
, menu_data
[i
].str
, (LPCSTR
)mii
.dwTypeData
);
2442 static HMENU
create_menu_from_data(const struct menu_data
*item
, INT item_count
)
2448 hmenu
= CreateMenu();
2451 for (i
= 0; i
< item_count
; i
++)
2453 SetLastError(0xdeadbeef);
2454 ret
= AppendMenu(hmenu
, item
[i
].type
, item
[i
].id
, item
[i
].str
);
2455 ok(ret
, "%d: AppendMenu(%04x, %04x, %p) error %u\n",
2456 i
, item
[i
].type
, item
[i
].id
, item
[i
].str
, GetLastError());
2461 /* use InsertMenuItem: does not set the MFT_BITMAP flag,
2462 * and does not accept non-magic bitmaps with invalid
2464 static HMENU
create_menuitem_from_data(const struct menu_data
*item
, INT item_count
)
2469 MENUITEMINFO mii
= { sizeof( MENUITEMINFO
)};
2471 hmenu
= CreateMenu();
2474 for (i
= 0; i
< item_count
; i
++)
2476 SetLastError(0xdeadbeef);
2478 mii
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STATE
;
2480 if( item
[i
].type
& MFT_BITMAP
)
2482 mii
.fMask
|= MIIM_BITMAP
;
2483 mii
.hbmpItem
= (HBITMAP
)item
[i
].str
;
2485 else if( item
[i
].type
& MFT_SEPARATOR
)
2486 mii
.fType
= MFT_SEPARATOR
;
2489 mii
.fMask
|= MIIM_STRING
;
2490 mii
.dwTypeData
= (LPSTR
)item
[i
].str
;
2491 mii
.cch
= strlen( item
[i
].str
);
2494 if( item
[i
].type
& MF_HELP
) mii
.fType
|= MF_HELP
;
2495 mii
.wID
= item
[i
].id
;
2496 ret
= InsertMenuItem( hmenu
, -1, TRUE
, &mii
);
2497 ok(ret
, "%d: InsertMenuItem(%04x, %04x, %p) error %u\n",
2498 i
, item
[i
].type
, item
[i
].id
, item
[i
].str
, GetLastError());
2503 static void compare_menu_data(HMENU hmenu
, const struct menu_data
*item
, INT item_count
)
2508 count
= GetMenuItemCount(hmenu
);
2509 ok(count
== item_count
, "expected %d, got %d menu items\n", count
, item_count
);
2511 for (i
= 0; i
< count
; i
++)
2516 memset(&mii
, 0, sizeof(mii
));
2517 mii
.cbSize
= sizeof(mii
);
2518 mii
.dwTypeData
= buf
;
2519 mii
.cch
= sizeof(buf
);
2520 mii
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
| MIIM_BITMAP
;
2521 ret
= GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
);
2522 ok(ret
, "GetMenuItemInfo(%u) failed\n", i
);
2524 trace("item #%u: fType %04x, fState %04x, wID %04x, hbmp %p\n",
2525 i
, mii
.fType
, mii
.fState
, mii
.wID
, mii
.hbmpItem
);
2527 ok(mii
.fType
== item
[i
].type
,
2528 "%u: expected fType %04x, got %04x\n", i
, item
[i
].type
, mii
.fType
);
2529 ok(mii
.wID
== item
[i
].id
,
2530 "%u: expected wID %04x, got %04x\n", i
, item
[i
].id
, mii
.wID
);
2531 if (mii
.hbmpItem
|| !item
[i
].str
)
2532 /* For some reason Windows sets high word to not 0 for
2535 ok(LOWORD(mii
.hbmpItem
) == LOWORD(item
[i
].str
),
2536 "%u: expected hbmpItem %p, got %p\n", i
, item
[i
].str
, mii
.hbmpItem
);
2539 ok(mii
.cch
== strlen(item
[i
].str
),
2540 "%u: expected cch %u, got %u\n", i
, (UINT
)strlen(item
[i
].str
), mii
.cch
);
2541 ok(!strcmp(mii
.dwTypeData
, item
[i
].str
),
2542 "%u: expected dwTypeData %s, got %s\n", i
, item
[i
].str
, (LPCSTR
)mii
.dwTypeData
);
2547 static void test_InsertMenu(void)
2549 HBITMAP hbm
= CreateBitmap(1,1,1,1,NULL
);
2550 /* Note: XP treats only bitmap handles 1 - 6 as "magic" ones
2551 * regardless of their id.
2553 static const struct menu_data in1
[] =
2555 { MF_STRING
, 1, "File" },
2556 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(1) },
2557 { MF_STRING
|MF_HELP
, 2, "Help" }
2559 static const struct menu_data out1
[] =
2561 { MF_STRING
, 1, "File" },
2562 { MF_STRING
|MF_HELP
, 2, "Help" },
2563 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(1) }
2565 static const struct menu_data out1a
[] =
2567 { MF_STRING
, 1, "File" },
2568 { MF_STRING
|MF_HELP
, 2, "Help" },
2569 { MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(1) }
2571 const struct menu_data in2
[] =
2573 { MF_STRING
, 1, "File" },
2574 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, (char*)hbm
},
2575 { MF_STRING
|MF_HELP
, 2, "Help" }
2577 const struct menu_data out2
[] =
2579 { MF_STRING
, 1, "File" },
2580 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, (char*)hbm
},
2581 { MF_STRING
|MF_HELP
, 2, "Help" }
2583 const struct menu_data out2a
[] =
2585 { MF_STRING
, 1, "File" },
2586 { MF_HELP
, SC_CLOSE
, (char*)hbm
},
2587 { MF_STRING
|MF_HELP
, 2, "Help" }
2589 static const struct menu_data in3
[] =
2591 { MF_STRING
, 1, "File" },
2592 { MF_SEPARATOR
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(1) },
2593 { MF_STRING
|MF_HELP
, 2, "Help" }
2595 static const struct menu_data out3
[] =
2597 { MF_STRING
, 1, "File" },
2598 { MF_SEPARATOR
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(0) },
2599 { MF_STRING
|MF_HELP
, 2, "Help" },
2601 static const struct menu_data in4
[] =
2603 { MF_STRING
, 1, "File" },
2604 { MF_BITMAP
|MF_HELP
, 1, MAKEINTRESOURCE(1) },
2605 { MF_STRING
|MF_HELP
, 2, "Help" }
2607 static const struct menu_data out4
[] =
2609 { MF_STRING
, 1, "File" },
2610 { MF_STRING
|MF_HELP
, 2, "Help" },
2611 { MF_BITMAP
|MF_HELP
, 1, MAKEINTRESOURCE(1) }
2613 static const struct menu_data out4a
[] =
2615 { MF_STRING
, 1, "File" },
2616 { MF_STRING
|MF_HELP
, 2, "Help" },
2617 { MF_HELP
, 1, MAKEINTRESOURCE(1) }
2621 #define create_menu(a) create_menu_from_data((a), sizeof(a)/sizeof((a)[0]))
2622 #define create_menuitem(a) create_menuitem_from_data((a), sizeof(a)/sizeof((a)[0]))
2623 #define compare_menu(h, a) compare_menu_data((h), (a), sizeof(a)/sizeof((a)[0]))
2625 hmenu
= create_menu(in1
);
2626 compare_menu(hmenu
, out1
);
2629 hmenu
= create_menu(in2
);
2630 compare_menu(hmenu
, out2
);
2633 hmenu
= create_menu(in3
);
2634 compare_menu(hmenu
, out3
);
2637 hmenu
= create_menu(in4
);
2638 compare_menu(hmenu
, out4
);
2641 /* now using InsertMenuItemInfo */
2642 hmenu
= create_menuitem(in1
);
2643 compare_menu(hmenu
, out1a
);
2646 hmenu
= create_menuitem(in2
);
2647 compare_menu(hmenu
, out2a
);
2650 hmenu
= create_menuitem(in3
);
2651 compare_menu(hmenu
, out3
);
2654 hmenu
= create_menuitem(in4
);
2655 compare_menu(hmenu
, out4a
);
2659 #undef create_menuitem
2663 static void test_menu_getmenuinfo(void)
2671 hmenu
= CreateMenu();
2673 /* test some parameter errors */
2674 SetLastError(0xdeadbeef);
2675 ret
= pGetMenuInfo( hmenu
, NULL
);
2676 gle
= GetLastError();
2677 ok( !ret
, "GetMenuInfo() should have failed\n");
2678 ok( gle
== ERROR_INVALID_PARAMETER
||
2679 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2680 "GetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2681 SetLastError(0xdeadbeef);
2683 ret
= pGetMenuInfo( hmenu
, &mi
);
2684 gle
= GetLastError();
2685 ok( !ret
, "GetMenuInfo() should have failed\n");
2686 ok( gle
== ERROR_INVALID_PARAMETER
||
2687 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2688 "GetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2689 SetLastError(0xdeadbeef);
2690 mi
.cbSize
= sizeof( MENUINFO
);
2691 ret
= pGetMenuInfo( hmenu
, &mi
);
2692 gle
= GetLastError();
2693 ok( ret
, "GetMenuInfo() should have succeeded\n");
2694 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2695 SetLastError(0xdeadbeef);
2697 ret
= pGetMenuInfo( NULL
, &mi
);
2698 gle
= GetLastError();
2699 ok( !ret
, "GetMenuInfo() should have failed\n");
2700 ok( gle
== ERROR_INVALID_PARAMETER
||
2701 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2702 "GetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2704 DestroyMenu( hmenu
);
2708 static void test_menu_setmenuinfo(void)
2710 HMENU hmenu
, hsubmenu
;
2712 MENUITEMINFOA mii
= {sizeof( MENUITEMINFOA
)};
2716 /* create a menu with a submenu */
2717 hmenu
= CreateMenu();
2718 hsubmenu
= CreateMenu();
2719 assert( hmenu
&& hsubmenu
);
2720 mii
.fMask
= MIIM_SUBMENU
;
2721 mii
.hSubMenu
= hsubmenu
;
2722 ret
= InsertMenuItem( hmenu
, 0, FALSE
, &mii
);
2723 ok( ret
, "InsertMenuItem failed with error %d\n", GetLastError());
2724 /* test some parameter errors */
2725 SetLastError(0xdeadbeef);
2726 ret
= pSetMenuInfo( hmenu
, NULL
);
2727 gle
= GetLastError();
2728 ok( !ret
, "SetMenuInfo() should have failed\n");
2729 ok( gle
== ERROR_INVALID_PARAMETER
||
2730 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2731 "SetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2732 SetLastError(0xdeadbeef);
2734 ret
= pSetMenuInfo( hmenu
, &mi
);
2735 gle
= GetLastError();
2736 ok( !ret
, "SetMenuInfo() should have failed\n");
2737 ok( gle
== ERROR_INVALID_PARAMETER
||
2738 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2739 "SetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2740 SetLastError(0xdeadbeef);
2741 mi
.cbSize
= sizeof( MENUINFO
);
2742 ret
= pSetMenuInfo( hmenu
, &mi
);
2743 gle
= GetLastError();
2744 ok( ret
, "SetMenuInfo() should have succeeded\n");
2745 ok( gle
== 0xdeadbeef, "SetMenuInfo() error got %u\n", gle
);
2746 SetLastError(0xdeadbeef);
2748 ret
= pSetMenuInfo( NULL
, &mi
);
2749 gle
= GetLastError();
2750 ok( !ret
, "SetMenuInfo() should have failed\n");
2751 ok( gle
== ERROR_INVALID_PARAMETER
||
2752 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2753 "SetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2754 /* functional tests */
2755 /* menu and submenu should have the CHECKORBMP style bit cleared */
2756 SetLastError(0xdeadbeef);
2757 mi
.cbSize
= sizeof( MENUINFO
);
2758 mi
.fMask
= MIM_STYLE
;
2759 ret
= pGetMenuInfo( hmenu
, &mi
);
2760 gle
= GetLastError();
2761 ok( ret
, "GetMenuInfo() should have succeeded\n");
2762 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2763 ok( !(mi
.dwStyle
& MNS_CHECKORBMP
), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2764 SetLastError(0xdeadbeef);
2765 mi
.cbSize
= sizeof( MENUINFO
);
2766 mi
.fMask
= MIM_STYLE
;
2767 ret
= pGetMenuInfo( hsubmenu
, &mi
);
2768 gle
= GetLastError();
2769 ok( ret
, "GetMenuInfo() should have succeeded\n");
2770 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2771 ok( !(mi
.dwStyle
& MNS_CHECKORBMP
), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2773 SetLastError(0xdeadbeef);
2774 mi
.cbSize
= sizeof( MENUINFO
);
2775 mi
.fMask
= MIM_STYLE
| MIM_APPLYTOSUBMENUS
;
2776 mi
.dwStyle
= MNS_CHECKORBMP
;
2777 ret
= pSetMenuInfo( hmenu
, &mi
);
2778 gle
= GetLastError();
2779 ok( ret
, "SetMenuInfo() should have succeeded\n");
2780 ok( gle
== 0xdeadbeef, "SetMenuInfo() error got %u\n", gle
);
2781 /* Now both menus should have the MNS_CHECKORBMP style bit set */
2782 SetLastError(0xdeadbeef);
2783 mi
.cbSize
= sizeof( MENUINFO
);
2784 mi
.fMask
= MIM_STYLE
;
2785 ret
= pGetMenuInfo( hmenu
, &mi
);
2786 gle
= GetLastError();
2787 ok( ret
, "GetMenuInfo() should have succeeded\n");
2788 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2789 ok( mi
.dwStyle
& MNS_CHECKORBMP
, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2790 SetLastError(0xdeadbeef);
2791 mi
.cbSize
= sizeof( MENUINFO
);
2792 mi
.fMask
= MIM_STYLE
;
2793 ret
= pGetMenuInfo( hsubmenu
, &mi
);
2794 gle
= GetLastError();
2795 ok( ret
, "GetMenuInfo() should have succeeded\n");
2796 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2797 ok( mi
.dwStyle
& MNS_CHECKORBMP
, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2798 /* now repeat that without the APPLYTOSUBMENUS flag and another style bit */
2799 SetLastError(0xdeadbeef);
2800 mi
.cbSize
= sizeof( MENUINFO
);
2801 mi
.fMask
= MIM_STYLE
;
2802 mi
.dwStyle
= MNS_NOCHECK
;
2803 ret
= pSetMenuInfo( hmenu
, &mi
);
2804 gle
= GetLastError();
2805 ok( ret
, "SetMenuInfo() should have succeeded\n");
2806 ok( gle
== 0xdeadbeef, "SetMenuInfo() error got %u\n", gle
);
2807 /* Now only the top menu should have the MNS_NOCHECK style bit set */
2808 SetLastError(0xdeadbeef);
2809 mi
.cbSize
= sizeof( MENUINFO
);
2810 mi
.fMask
= MIM_STYLE
;
2811 ret
= pGetMenuInfo( hmenu
, &mi
);
2812 gle
= GetLastError();
2813 ok( ret
, "GetMenuInfo() should have succeeded\n");
2814 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2815 ok( mi
.dwStyle
& MNS_NOCHECK
, "menustyle was expected to have the MNS_NOCHECK flag\n");
2816 SetLastError(0xdeadbeef);
2817 mi
.cbSize
= sizeof( MENUINFO
);
2818 mi
.fMask
= MIM_STYLE
;
2819 ret
= pGetMenuInfo( hsubmenu
, &mi
);
2820 gle
= GetLastError();
2821 ok( ret
, "GetMenuInfo() should have succeeded\n");
2822 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2823 ok( !(mi
.dwStyle
& MNS_NOCHECK
), "menustyle was not expected to have the MNS_NOCHECK flag\n");
2825 DestroyMenu( hsubmenu
);
2826 DestroyMenu( hmenu
);
2830 /* little func to easy switch either TrackPopupMenu() or TrackPopupMenuEx() */
2831 static DWORD
MyTrackPopupMenu( int ex
, HMENU hmenu
, UINT flags
, INT x
, INT y
, HWND hwnd
, LPTPMPARAMS ptpm
)
2834 ? TrackPopupMenuEx( hmenu
, flags
, x
, y
, hwnd
, ptpm
)
2835 : TrackPopupMenu( hmenu
, flags
, x
, y
, 0, hwnd
, NULL
);
2838 /* some TrackPopupMenu and TrackPopupMenuEx tests */
2839 /* the LastError values differ between NO_ERROR and invalid handle */
2840 /* between all windows versions tested. The first value is that valid on XP */
2841 /* Vista was the only that made returned different error values */
2842 /* between the TrackPopupMenu and TrackPopupMenuEx functions */
2843 static void test_menu_trackpopupmenu(void)
2849 HWND hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
2850 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
2851 NULL
, NULL
, NULL
, NULL
);
2852 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
2854 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_ownerdraw_wnd_proc
);
2855 for( Ex
= 0; Ex
< 2; Ex
++)
2857 hmenu
= CreatePopupMenu();
2858 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
2861 DestroyWindow(hwnd
);
2864 /* display the menu */
2865 /* start with an invalid menu handle */
2867 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= 0;
2868 ret
= MyTrackPopupMenu( Ex
, NULL
, 0x100, 100,100, hwnd
, NULL
);
2869 gle
= GetLastError();
2870 ok( !ret
, "TrackPopupMenu%s should have failed\n", Ex
? "Ex" : "");
2871 ok( gle
== ERROR_INVALID_MENU_HANDLE
2872 || broken (gle
== 0xdeadbeef) /* win95 */
2873 || broken (gle
== NO_ERROR
) /* win98/ME */
2874 ,"TrackPopupMenu%s error got %u expected %u\n",
2875 Ex
? "Ex" : "", gle
, ERROR_INVALID_MENU_HANDLE
);
2876 ok( !(gflag_initmenupopup
|| gflag_entermenuloop
|| gflag_initmenu
),
2877 "got unexpected message(s)%s%s%s\n",
2878 gflag_initmenupopup
? " WM_INITMENUPOPUP ": " ",
2879 gflag_entermenuloop
? "WM_INITMENULOOP ": "",
2880 gflag_initmenu
? "WM_INITMENU": "");
2881 /* another one but not NULL */
2883 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= 0;
2884 ret
= MyTrackPopupMenu( Ex
, (HMENU
)hwnd
, 0x100, 100,100, hwnd
, NULL
);
2885 gle
= GetLastError();
2886 ok( !ret
, "TrackPopupMenu%s should have failed\n", Ex
? "Ex" : "");
2887 ok( gle
== ERROR_INVALID_MENU_HANDLE
2888 || broken (gle
== 0xdeadbeef) /* win95 */
2889 || broken (gle
== NO_ERROR
) /* win98/ME */
2890 ,"TrackPopupMenu%s error got %u expected %u\n",
2891 Ex
? "Ex" : "", gle
, ERROR_INVALID_MENU_HANDLE
);
2892 ok( !(gflag_initmenupopup
|| gflag_entermenuloop
|| gflag_initmenu
),
2893 "got unexpected message(s)%s%s%s\n",
2894 gflag_initmenupopup
? " WM_INITMENUPOPUP ": " ",
2895 gflag_entermenuloop
? "WM_INITMENULOOP ": "",
2896 gflag_initmenu
? "WM_INITMENU": "");
2897 /* now a somewhat successful call */
2899 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= 0;
2900 ret
= MyTrackPopupMenu( Ex
, hmenu
, 0x100, 100,100, hwnd
, NULL
);
2901 gle
= GetLastError();
2902 ok( ret
== 0, "TrackPopupMenu%s returned %d expected zero\n", Ex
? "Ex" : "", ret
);
2904 || gle
== ERROR_INVALID_MENU_HANDLE
/* NT4, win2k */
2905 || broken (gle
== 0xdeadbeef) /* win95 */
2906 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
2907 Ex
? "Ex" : "", gle
, NO_ERROR
, ERROR_INVALID_MENU_HANDLE
);
2908 ok( gflag_initmenupopup
&& gflag_entermenuloop
&& gflag_initmenu
,
2909 "missed expected message(s)%s%s%s\n",
2910 !gflag_initmenupopup
? " WM_INITMENUPOPUP ": " ",
2911 !gflag_entermenuloop
? "WM_INITMENULOOP ": "",
2912 !gflag_initmenu
? "WM_INITMENU": "");
2914 ret
= AppendMenuA( hmenu
, MF_STRING
, 1, "winetest");
2915 ok( ret
, "AppendMenA has failed!\n");
2917 gflag_initmenupopup
= gflag_entermenuloop
= gflag_initmenu
= 0;
2918 ret
= MyTrackPopupMenu( Ex
, hmenu
, 0x100, 100,100, hwnd
, NULL
);
2919 gle
= GetLastError();
2920 ok( ret
== 0, "TrackPopupMenu%s returned %d expected zero\n", Ex
? "Ex" : "", ret
);
2922 || gle
== ERROR_INVALID_MENU_HANDLE
/* NT4, win2k and Vista in the TrackPopupMenuEx case */
2923 || broken (gle
== 0xdeadbeef) /* win95 */
2924 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
2925 Ex
? "Ex" : "", gle
, NO_ERROR
, ERROR_INVALID_MENU_HANDLE
);
2926 ok( gflag_initmenupopup
&& gflag_entermenuloop
&& gflag_initmenu
,
2927 "missed expected message(s)%s%s%s\n",
2928 !gflag_initmenupopup
? " WM_INITMENUPOPUP ": " ",
2929 !gflag_entermenuloop
? "WM_INITMENULOOP ": "",
2930 !gflag_initmenu
? "WM_INITMENU": "");
2934 DestroyWindow(hwnd
);
2937 /* test handling of WM_CANCELMODE messages */
2938 static int g_got_enteridle
;
2939 static HWND g_hwndtosend
;
2940 static LRESULT WINAPI
menu_cancelmode_wnd_proc(HWND hwnd
, UINT msg
,
2941 WPARAM wparam
, LPARAM lparam
)
2945 case WM_ENTERMENULOOP
:
2946 g_got_enteridle
= 0;
2947 return SendMessage( g_hwndtosend
, WM_CANCELMODE
, 0, 0);
2950 if( g_got_enteridle
++ == 0) {
2951 /* little hack to get another WM_ENTERIDLE message */
2952 PostMessage( hwnd
, WM_MOUSEMOVE
, 0, 0);
2953 return SendMessage( g_hwndtosend
, WM_CANCELMODE
, 0, 0);
2959 return DefWindowProc( hwnd
, msg
, wparam
, lparam
);
2962 static void test_menu_cancelmode(void)
2965 HWND hwnd
, hwndchild
;
2967 if( !pEndMenu
) { /* win95 */
2968 win_skip( "EndMenu is not available\n");
2971 hwnd
= CreateWindowEx( 0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
2972 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
2973 NULL
, NULL
, NULL
, NULL
);
2974 hwndchild
= CreateWindowEx( 0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
2975 WS_VISIBLE
| WS_CHILD
, 10, 10, 20, 20,
2976 hwnd
, NULL
, NULL
, NULL
);
2977 ok( hwnd
!= NULL
&& hwndchild
!= NULL
,
2978 "CreateWindowEx failed with error %d\n", GetLastError());
2979 g_hwndtosend
= hwnd
;
2980 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_cancelmode_wnd_proc
);
2981 SetWindowLongPtr( hwndchild
, GWLP_WNDPROC
, (LONG_PTR
)menu_cancelmode_wnd_proc
);
2982 menu
= CreatePopupMenu();
2983 ok( menu
!= NULL
, "CreatePopupMenu failed with error %d\n", GetLastError());
2984 ret
= AppendMenuA( menu
, MF_STRING
, 1, "winetest");
2985 ok( ret
, "Functie failed lasterror is %u\n", GetLastError());
2986 /* seems to be needed only on wine :( */
2987 {MSG msg
; while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage(&msg
);}
2988 /* test the effect of sending a WM_CANCELMODE message in the WM_INITMENULOOP
2989 * handler of the menu owner */
2990 /* test results is exctracted from variable g_got_enteridle. Possible values:
2991 * 0 : complete conformance. Sending WM_CANCELMODE cancels a menu initializing tracking
2992 * 1 : Sending WM_CANCELMODE cancels a menu that is in tracking state
2993 * 2 : Sending WM_CANCELMODE does not work
2995 /* menu owner is top level window */
2996 g_hwndtosend
= hwnd
;
2997 ret
= TrackPopupMenu( menu
, 0x100, 100,100, 0, hwnd
, NULL
);
2999 ok( g_got_enteridle
== 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle
);
3001 ok( g_got_enteridle
< 2, "received %d WM_ENTERIDLE messages, should be less than 2\n", g_got_enteridle
);
3002 /* menu owner is child window */
3003 g_hwndtosend
= hwndchild
;
3004 ret
= TrackPopupMenu( menu
, 0x100, 100,100, 0, hwndchild
, NULL
);
3006 ok(g_got_enteridle
== 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle
);
3008 ok(g_got_enteridle
< 2, "received %d WM_ENTERIDLE messages, should be less than 2\n", g_got_enteridle
);
3009 /* now send the WM_CANCELMODE messages to the WRONG window */
3010 /* those should fail ( to have any effect) */
3011 g_hwndtosend
= hwnd
;
3012 ret
= TrackPopupMenu( menu
, 0x100, 100,100, 0, hwndchild
, NULL
);
3013 ok( g_got_enteridle
== 2, "received %d WM_ENTERIDLE messages, should be 2\n", g_got_enteridle
);
3016 DestroyWindow( hwndchild
);
3017 DestroyWindow( hwnd
);
3020 /* show menu trees have a maximum depth */
3021 static void test_menu_maxdepth(void)
3023 #define NR_MENUS 100
3024 HMENU hmenus
[ NR_MENUS
];
3028 SetLastError(12345678);
3029 for( i
= 0; i
< NR_MENUS
; i
++) {
3030 hmenus
[i
] = CreatePopupMenu();
3031 if( !hmenus
[i
]) break;
3033 ok( i
== NR_MENUS
, "could not create more than %d menu's\n", i
);
3034 for( i
= 1; i
< NR_MENUS
; i
++) {
3035 ret
= AppendMenuA( hmenus
[i
], MF_POPUP
, (UINT_PTR
)hmenus
[i
-1],"test");
3038 trace("Maximum depth is %d\n", i
);
3039 ok( GetLastError() == 12345678, "unexpected error %d\n", GetLastError());
3041 broken( i
== NR_MENUS
), /* win98, NT */
3042 "no ( or very large) limit on menu depth!\n");
3044 for( i
= 0; i
< NR_MENUS
; i
++)
3045 DestroyMenu( hmenus
[i
]);
3049 static void test_menu_circref(void)
3054 menu1
= CreatePopupMenu();
3055 menu2
= CreatePopupMenu();
3056 ok( menu1
&& menu2
, "error creating menus.\n");
3057 ret
= AppendMenuA( menu1
, MF_POPUP
, (UINT_PTR
)menu2
, "winetest");
3058 ok( ret
, "AppendMenu failed, error is %d\n", GetLastError());
3059 ret
= AppendMenuA( menu1
, MF_STRING
| MF_HILITE
, 123, "winetest");
3060 ok( ret
, "AppendMenu failed, error is %d\n", GetLastError());
3061 /* app chooses an id that happens to clash with its own hmenu */
3062 ret
= AppendMenuA( menu2
, MF_STRING
, (UINT_PTR
)menu2
, "winetest");
3063 ok( ret
, "AppendMenu failed, error is %d\n", GetLastError());
3064 /* now attempt to change the string of the first item of menu1 */
3065 ret
= ModifyMenuA( menu1
, (UINT_PTR
)menu2
, MF_POPUP
, (UINT_PTR
)menu2
, "menu 2");
3067 broken( ret
), /* win98, NT */
3068 "ModifyMenu should have failed.\n");
3069 if( !ret
) { /* will probably stack fault if the ModifyMenu succeeded */
3070 ret
= GetMenuState( menu1
, 123, 0);
3071 ok( ret
== MF_HILITE
, "GetMenuState returned %x\n",ret
);
3073 DestroyMenu( menu2
);
3074 DestroyMenu( menu1
);
3077 /* test how the menu texts are aligned when the menu items have
3078 * different combinations of text and bitmaps (bug #13350) */
3079 static void test_menualign(void)
3083 HBITMAP hbm1
, hbm2
, hbm3
;
3084 MENUITEMINFO mii
= { sizeof(MENUITEMINFO
)};
3087 MENUINFO mi
= { sizeof( MENUINFO
)};
3089 if( !winetest_interactive
) {
3090 skip( "interactive alignment tests.\n");
3093 hwnd
= CreateWindowEx(0,
3095 "Menu text alignment Test\nPlease make a selection.",
3096 WS_OVERLAPPEDWINDOW
,
3099 NULL
, NULL
, 0, NULL
);
3100 ShowWindow( hwnd
, SW_SHOW
);
3101 /* create bitmaps */
3102 memset( bmfill
, 0xcc, sizeof( bmfill
));
3103 hbm1
= CreateBitmap( 10,10,1,1,bmfill
);
3104 hbm2
= CreateBitmap( 20,20,1,1,bmfill
);
3105 hbm3
= CreateBitmap( 50,6,1,1,bmfill
);
3106 ok( hbm1
&& hbm2
&& hbm3
, "Creating bitmaps failed\n");
3107 menu
= CreatePopupMenu();
3108 ok( menu
!= NULL
, "CreatePopupMenu() failed\n");
3110 mi
.fMask
= MIM_STYLE
;
3111 ret
= pGetMenuInfo( menu
, &mi
);
3112 ok( menu
!= NULL
, "GetMenuInfo() failed\n");
3113 ok( 0 == mi
.dwStyle
, "menuinfo style is %x\n", mi
.dwStyle
);
3116 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3118 mii
.hbmpItem
= hbm1
;
3119 mii
.dwTypeData
= (LPSTR
) " OK: menu texts are correctly left-aligned.";
3120 ret
= InsertMenuItem( menu
, -1, TRUE
, &mii
);
3121 ok( ret
, "InsertMenuItem() failed\n");
3122 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3124 mii
.hbmpItem
= hbm2
;
3125 mii
.dwTypeData
= (LPSTR
) " FAIL: menu texts are NOT left-aligned.";
3126 ret
= InsertMenuItem( menu
, -1, TRUE
, &mii
);
3127 ok( ret
, "InsertMenuItem() failed\n");
3128 ret
= TrackPopupMenu( menu
, TPM_RETURNCMD
, 110, 200, 0, hwnd
, NULL
);
3129 ok( ret
!= 2, "User indicated that menu text alignment test 1 failed %d\n", ret
);
3131 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3133 mii
.hbmpItem
= hbm3
;
3134 mii
.dwTypeData
= NULL
;
3135 ret
= InsertMenuItem( menu
, 0, TRUE
, &mii
);
3136 ok( ret
, "InsertMenuItem() failed\n");
3137 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3139 mii
.hbmpItem
= hbm1
;
3140 /* make the text a bit longer, to keep it readable */
3141 /* this bug is on winXP and reproduced on wine */
3142 mii
.dwTypeData
= (LPSTR
) " OK: menu texts are to the right of the bitmaps........";
3143 ret
= SetMenuItemInfo( menu
, 1, TRUE
, &mii
);
3144 ok( ret
, "SetMenuItemInfo() failed\n");
3146 mii
.hbmpItem
= hbm2
;
3147 mii
.dwTypeData
= (LPSTR
) " FAIL: menu texts are below the first bitmap. ";
3148 ret
= SetMenuItemInfo( menu
, 2, TRUE
, &mii
);
3149 ok( ret
, "SetMenuItemInfo() failed\n");
3150 ret
= TrackPopupMenu( menu
, TPM_RETURNCMD
, 110, 200, 0, hwnd
, NULL
);
3151 ok( ret
!= 2, "User indicated that menu text alignment test 2 failed %d\n", ret
);
3153 mii
.fMask
= MIIM_TYPE
| MIIM_ID
;
3155 mii
.fType
= MFT_BITMAP
;
3156 mii
.dwTypeData
= (LPSTR
) hbm3
;
3157 ret
= SetMenuItemInfo( menu
, 0, TRUE
, &mii
);
3158 ok( ret
, "SetMenuItemInfo() failed\n");
3159 mii
.fMask
= MIIM_BITMAP
| MIIM_STRING
| MIIM_ID
;
3161 mii
.hbmpItem
= NULL
;
3162 mii
.dwTypeData
= (LPSTR
) " OK: menu texts are below the bitmap.";
3163 ret
= SetMenuItemInfo( menu
, 1, TRUE
, &mii
);
3164 ok( ret
, "SetMenuItemInfo() failed\n");
3166 mii
.hbmpItem
= NULL
;
3167 mii
.dwTypeData
= (LPSTR
) " FAIL: menu texts are NOT below the bitmap.";
3168 ret
= SetMenuItemInfo( menu
, 2, TRUE
, &mii
);
3169 ok( ret
, "SetMenuItemInfo() failed\n");
3170 ret
= TrackPopupMenu( menu
, TPM_RETURNCMD
, 110, 200, 0, hwnd
, NULL
);
3171 ok( ret
!= 2, "User indicated that menu text alignment test 3 failed %d\n", ret
);
3173 DeleteObject( hbm1
);
3174 DeleteObject( hbm2
);
3175 DeleteObject( hbm3
);
3177 DestroyWindow( hwnd
);
3182 init_function_pointers();
3184 /* Wine defines MENUITEMINFO for W2K and above. NT4 and below can't
3187 if (correct_behavior())
3189 test_menu_add_string();
3190 test_menu_iteminfo();
3191 test_menu_search_bycommand();
3192 test_CheckMenuRadioItem();
3193 test_menu_resource_layout();
3198 register_menu_check_class();
3200 test_menu_locked_by_window();
3201 test_subpopup_locked_by_menu();
3202 test_menu_ownerdraw();
3203 test_menu_bmp_and_string();
3204 /* test Get/SetMenuInfo if available */
3205 if( pGetMenuInfo
&& pSetMenuInfo
) {
3206 test_menu_getmenuinfo();
3207 test_menu_setmenuinfo();
3209 win_skip("Get/SetMenuInfo are not available\n");
3211 win_skip("SendInput is not available\n");
3216 test_menu_hilitemenuitem();
3217 test_menu_trackpopupmenu();
3218 test_menu_cancelmode();
3219 test_menu_maxdepth();
3220 test_menu_circref();