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
);
44 static void init_function_pointers(void)
46 HMODULE hdll
= GetModuleHandleA("user32");
48 #define GET_PROC(func) \
49 p ## func = (void*)GetProcAddress(hdll, #func); \
51 trace("GetProcAddress(%s) failed\n", #func);
60 static BOOL
correct_behavior(void)
68 memset(&info
, 0, sizeof(MENUITEMINFO
));
69 info
.cbSize
= sizeof(MENUITEMINFO
);
70 SetLastError(0xdeadbeef);
71 rc
= GetMenuItemInfo(hmenu
, 0, TRUE
, &info
);
73 * NT4 : ERROR_INVALID_PARAMETER
74 * >= W2K : ERROR_MENU_ITEM_NOT_FOUND
76 if (!rc
&& GetLastError() != ERROR_MENU_ITEM_NOT_FOUND
)
78 win_skip("NT4 and below can't handle a bigger MENUITEMINFO struct\n");
87 static LRESULT WINAPI
menu_check_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
91 case WM_ENTERMENULOOP
:
92 /* mark window as having entered menu loop */
93 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, TRUE
);
94 /* exit menu modal loop
95 * ( A SendMessage does not work on NT3.51 here ) */
96 return PostMessage(hwnd
, WM_CANCELMODE
, 0, 0);
98 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
101 /* The MSVC headers ignore our NONAMELESSUNION requests so we have to define
114 /* globals to communicate between test and wndproc */
116 static BOOL bMenuVisible
;
117 static HMENU hMenus
[4];
120 #define MOD_NRMENUS 8
122 /* menu texts with their sizes */
125 SIZE size
; /* size of text up to any \t */
126 SIZE sc_size
; /* size of the short-cut */
130 { "Shira&z\tAlt+S" },
135 static unsigned int MOD_maxid
;
136 static RECT MOD_rc
[MOD_NRMENUS
];
137 static int MOD_avec
, MOD_hic
;
138 static int MOD_odheight
;
139 static SIZE MODsizes
[MOD_NRMENUS
]= { {MOD_SIZE
, MOD_SIZE
},{MOD_SIZE
, MOD_SIZE
},
140 {MOD_SIZE
, MOD_SIZE
},{MOD_SIZE
, MOD_SIZE
}};
141 static int MOD_GotDrawItemMsg
= FALSE
;
142 /* wndproc used by test_menu_ownerdraw() */
143 static LRESULT WINAPI
menu_ownerdraw_wnd_proc(HWND hwnd
, UINT msg
,
144 WPARAM wparam
, LPARAM lparam
)
150 MEASUREITEMSTRUCT
* pmis
= (MEASUREITEMSTRUCT
*)lparam
;
152 trace("WM_MEASUREITEM received data %lx size %dx%d\n",
153 pmis
->itemData
, pmis
->itemWidth
, pmis
->itemHeight
);
154 MOD_odheight
= pmis
->itemHeight
;
155 pmis
->itemWidth
= MODsizes
[pmis
->itemData
].cx
;
156 pmis
->itemHeight
= MODsizes
[pmis
->itemData
].cy
;
161 DRAWITEMSTRUCT
* pdis
;
164 char chrs
[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
167 pdis
= (DRAWITEMSTRUCT
*) lparam
;
168 if( winetest_debug
) {
170 GetMenuItemRect( hwnd
, (HMENU
)pdis
->hwndItem
, pdis
->itemData
,&rc
);
171 trace("WM_DRAWITEM received hwnd %p hmenu %p itemdata %ld item %d rc %d,%d-%d,%d itemrc: %d,%d-%d,%d\n",
172 hwnd
, pdis
->hwndItem
, pdis
->itemData
, pdis
->itemID
,
173 pdis
->rcItem
.left
, pdis
->rcItem
.top
,
174 pdis
->rcItem
.right
,pdis
->rcItem
.bottom
,
175 rc
.left
,rc
.top
,rc
.right
,rc
.bottom
);
176 oldpen
=SelectObject( pdis
->hDC
, GetStockObject(
177 pdis
->itemState
& ODS_SELECTED
? WHITE_PEN
:BLACK_PEN
));
178 Rectangle( pdis
->hDC
, pdis
->rcItem
.left
,pdis
->rcItem
.top
,
179 pdis
->rcItem
.right
,pdis
->rcItem
.bottom
);
180 SelectObject( pdis
->hDC
, oldpen
);
182 /* calculate widths of some menu texts */
183 if( ! MOD_txtsizes
[0].size
.cx
)
184 for(i
= 0; MOD_txtsizes
[i
].text
; i
++) {
187 strcpy( buf
, MOD_txtsizes
[i
].text
);
188 if( ( p
= strchr( buf
, '\t'))) {
190 DrawText( pdis
->hDC
, p
+ 1, -1, &rc
,
191 DT_SINGLELINE
|DT_CALCRECT
);
192 MOD_txtsizes
[i
].sc_size
.cx
= rc
.right
- rc
.left
;
193 MOD_txtsizes
[i
].sc_size
.cy
= rc
.bottom
- rc
.top
;
195 DrawText( pdis
->hDC
, buf
, -1, &rc
,
196 DT_SINGLELINE
|DT_CALCRECT
);
197 MOD_txtsizes
[i
].size
.cx
= rc
.right
- rc
.left
;
198 MOD_txtsizes
[i
].size
.cy
= rc
.bottom
- rc
.top
;
201 if( pdis
->itemData
> MOD_maxid
) return TRUE
;
202 /* store the rectangl */
203 MOD_rc
[pdis
->itemData
] = pdis
->rcItem
;
204 /* calculate average character width */
205 GetTextExtentPoint( pdis
->hDC
, chrs
, 52, &sz
);
206 MOD_avec
= (sz
.cx
+ 26)/52;
207 GetTextMetrics( pdis
->hDC
, &tm
);
208 MOD_hic
= tm
.tmHeight
;
209 MOD_GotDrawItemMsg
= TRUE
;
214 ok( lparam
, "Menu window handle is NULL!\n");
215 PostMessage(hwnd
, WM_CANCELMODE
, 0, 0);
220 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
223 static void register_menu_check_class(void)
231 GetModuleHandle(NULL
),
233 LoadCursor(NULL
, IDC_ARROW
),
234 (HBRUSH
)(COLOR_BTNFACE
+1),
236 TEXT("WineMenuCheck"),
239 atomMenuCheckClass
= RegisterClass(&wc
);
242 /* demonstrates that windows locks the menu object so that it is still valid
243 * even after a client calls DestroyMenu on it */
244 static void test_menu_locked_by_window(void)
248 HWND hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
249 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
250 NULL
, NULL
, NULL
, NULL
);
251 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
252 hmenu
= CreateMenu();
253 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
254 ret
= InsertMenu(hmenu
, 0, MF_STRING
, 0, TEXT("&Test"));
255 ok(ret
, "InsertMenu failed with error %d\n", GetLastError());
256 ret
= SetMenu(hwnd
, hmenu
);
257 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
258 ret
= DestroyMenu(hmenu
);
259 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
261 ret
= DrawMenuBar(hwnd
);
263 ok(ret
, "DrawMenuBar failed with error %d\n", GetLastError());
265 ret
= IsMenu(GetMenu(hwnd
));
266 ok(!ret
, "Menu handle should have been destroyed\n");
268 SendMessage(hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, 0);
269 /* did we process the WM_INITMENU message? */
270 ret
= GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
272 ok(ret
, "WM_INITMENU should have been sent\n");
278 static void test_menu_ownerdraw(void)
284 HWND hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
285 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
286 NULL
, NULL
, NULL
, NULL
);
287 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
289 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_ownerdraw_wnd_proc
);
290 hmenu
= CreatePopupMenu();
291 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
292 if( !hmenu
) { DestroyWindow(hwnd
);return;}
294 for( j
=0;j
<2;j
++) /* create columns */
295 for(i
=0;i
<2;i
++) { /* create rows */
296 ret
= AppendMenu( hmenu
, MF_OWNERDRAW
|
297 (i
==0 ? MF_MENUBREAK
: 0), k
, MAKEINTRESOURCE(k
));
299 ok( ret
, "AppendMenu failed for %d\n", k
-1);
302 assert( k
<= sizeof(MOD_rc
)/sizeof(RECT
));
303 /* display the menu */
304 ret
= TrackPopupMenu( hmenu
, 0x100, 100,100, 0, hwnd
, NULL
);
306 /* columns have a 4 pixel gap between them */
307 ok( MOD_rc
[0].right
+ 4 == MOD_rc
[2].left
,
308 "item rectangles are not separated by 4 pixels space\n");
309 /* height should be what the MEASUREITEM message has returned */
310 ok( MOD_rc
[0].bottom
- MOD_rc
[0].top
== MOD_SIZE
,
311 "menu item has wrong height: %d should be %d\n",
312 MOD_rc
[0].bottom
- MOD_rc
[0].top
, MOD_SIZE
);
313 /* no gaps between the rows */
314 ok( MOD_rc
[0].bottom
- MOD_rc
[1].top
== 0,
315 "There should not be a space between the rows, gap is %d\n",
316 MOD_rc
[0].bottom
- MOD_rc
[1].top
);
317 /* test the correct value of the item height that was sent
318 * by the WM_MEASUREITEM message */
319 ok( MOD_odheight
== HIWORD( GetDialogBaseUnits()) || /* WinNT,2k,XP */
320 MOD_odheight
== MOD_hic
, /* Win95,98,ME */
321 "Wrong height field in MEASUREITEMSTRUCT, expected %d or %d actual %d\n",
322 HIWORD( GetDialogBaseUnits()), MOD_hic
, MOD_odheight
);
323 /* test what MF_MENUBREAK did at the first position. Also show
324 * that an MF_SEPARATOR is ignored in the height calculation. */
325 leftcol
= MOD_rc
[0].left
;
326 ModifyMenu( hmenu
, 0, MF_BYCOMMAND
| MF_OWNERDRAW
| MF_SEPARATOR
, 0, 0);
327 /* display the menu */
328 ret
= TrackPopupMenu( hmenu
, 0x100, 100,100, 0, hwnd
, NULL
);
329 /* left should be 4 pixels less now */
330 ok( leftcol
== MOD_rc
[0].left
+ 4,
331 "columns should be 4 pixels to the left (actual %d).\n",
332 leftcol
- MOD_rc
[0].left
);
334 ok( MOD_rc
[0].right
- MOD_rc
[0].left
== 2 * MOD_avec
+ MOD_SIZE
,
335 "width of owner drawn menu item is wrong. Got %d expected %d\n",
336 MOD_rc
[0].right
- MOD_rc
[0].left
, 2*MOD_avec
+ MOD_SIZE
);
338 ok( MOD_rc
[0].bottom
- MOD_rc
[0].top
== MOD_SIZE
,
339 "Height is incorrect. Got %d expected %d\n",
340 MOD_rc
[0].bottom
- MOD_rc
[0].top
, MOD_SIZE
);
342 /* test width/height of an ownerdraw menu bar as well */
343 ret
= DestroyMenu(hmenu
);
344 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
345 hmenu
= CreateMenu();
346 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
347 if( !hmenu
) { DestroyWindow(hwnd
);return;}
350 ret
= AppendMenu( hmenu
, MF_OWNERDRAW
, i
, 0);
351 ok( ret
, "AppendMenu failed for %d\n", i
);
353 ret
= SetMenu( hwnd
, hmenu
);
354 UpdateWindow( hwnd
); /* hack for wine to draw the window + menu */
355 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
357 ok( MOD_rc
[0].right
- MOD_rc
[0].left
== 2 * MOD_avec
+ MOD_SIZE
,
358 "width of owner drawn menu item is wrong. Got %d expected %d\n",
359 MOD_rc
[0].right
- MOD_rc
[0].left
, 2*MOD_avec
+ MOD_SIZE
);
361 ok( MOD_rc
[0].bottom
- MOD_rc
[0].top
== GetSystemMetrics( SM_CYMENU
) - 1,
362 "Height of owner drawn menu item is wrong. Got %d expected %d\n",
363 MOD_rc
[0].bottom
- MOD_rc
[0].top
, GetSystemMetrics( SM_CYMENU
) - 1);
366 ret
= DestroyMenu(hmenu
);
367 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
371 /* helper for test_menu_bmp_and_string() */
372 static void test_mbs_help( int ispop
, int hassub
, int mnuopt
,
373 HWND hwnd
, int arrowwidth
, int count
, HBITMAP hbmp
,
374 SIZE bmpsize
, LPCSTR text
, SIZE size
, SIZE sc_size
)
377 HMENU hmenu
, submenu
;
378 MENUITEMINFO mii
={ sizeof( MENUITEMINFO
)};
385 MOD_GotDrawItemMsg
= FALSE
;
386 mii
.fMask
= MIIM_FTYPE
| MIIM_DATA
| MIIM_STATE
;
388 /* check the menu item unless MNS_CHECKORBMP is set */
389 mii
.fState
= (mnuopt
!= 2 ? MFS_CHECKED
: MFS_UNCHECKED
);
391 MODsizes
[0] = bmpsize
;
395 mii
.fMask
|= MIIM_STRING
;
396 strcpy(text_copy
, text
);
397 mii
.dwTypeData
= text_copy
; /* structure member declared non-const */
398 if( ( p
= strchr( text
, '\t'))) {
399 hastab
= *(p
+ 1) ? 2 : 1;
402 /* tabs don't make sense in menubars */
403 if(hastab
&& !ispop
) return;
405 mii
.fMask
|= MIIM_BITMAP
;
408 submenu
= CreateMenu();
409 ok( submenu
!= 0, "CreateMenu failed with error %d\n", GetLastError());
411 hmenu
= CreatePopupMenu();
413 hmenu
= CreateMenu();
414 ok( hmenu
!= 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
416 mii
.fMask
|= MIIM_SUBMENU
;
417 mii
.hSubMenu
= submenu
;
420 mi
.cbSize
= sizeof(mi
);
421 mi
.fMask
= MIM_STYLE
;
422 pGetMenuInfo( hmenu
, &mi
);
423 mi
.dwStyle
|= mnuopt
== 1 ? MNS_NOCHECK
: MNS_CHECKORBMP
;
424 ret
= pSetMenuInfo( hmenu
, &mi
);
425 ok( ret
, "SetMenuInfo failed with error %d\n", GetLastError());
427 ret
= InsertMenuItem( hmenu
, 0, FALSE
, &mii
);
428 ok( ret
, "InsertMenuItem failed with error %d\n", GetLastError());
430 if( winetest_debug
) {
432 RECT rc
= {100, 50, 400, 70};
435 sprintf( buf
,"%d text \"%s\" mnuopt %d", count
, text
? text
: "(nil)", mnuopt
);
436 FillRect( hdc
, &rc
, (HBRUSH
) COLOR_WINDOW
);
437 TextOut( hdc
, 10, 50, buf
, strlen( buf
));
438 ReleaseDC( hwnd
, hdc
);
441 ret
= TrackPopupMenu( hmenu
, 0x100, 100,100, 0, hwnd
, NULL
);
443 ret
= SetMenu( hwnd
, hmenu
);
444 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
447 ret
= GetMenuItemRect( hwnd
, hmenu
, 0, &rc
);
448 if (0) /* comment out menu size checks, behavior is different in almost every Windows version */
449 /* the tests should however succeed on win2000, XP and Wine (at least upto 1.1.15) */
450 /* with a variety of dpi's and desktop font sizes */
452 /* check menu width */
454 expect
= ( text
|| hbmp
?
455 4 + (mnuopt
!= 1 ? GetSystemMetrics(SM_CXMENUCHECK
) : 0)
457 arrowwidth
+ MOD_avec
+ (hbmp
?
458 ((int)hbmp
<0||(int)hbmp
>12 ? bmpsize
.cx
+ 2 : GetSystemMetrics( SM_CXMENUSIZE
) + 2)
460 (text
&& hastab
? /* TAB space */
461 MOD_avec
+ ( hastab
==2 ? sc_size
.cx
: 0) : 0) +
462 (text
? 2 + (text
[0] ? size
.cx
:0): 0) ;
464 expect
= !(text
|| hbmp
) ? 0 :
465 ( hbmp
? (text
? 2:0) + bmpsize
.cx
: 0 ) +
466 (text
? 2 * MOD_avec
+ (text
[0] ? size
.cx
:0): 0) ;
467 ok( rc
.right
- rc
.left
== expect
,
468 "menu width wrong, got %d expected %d\n", rc
.right
- rc
.left
, expect
);
469 failed
= failed
|| !(rc
.right
- rc
.left
== expect
);
470 /* check menu height */
472 expect
= max( ( !(text
|| hbmp
) ? GetSystemMetrics( SM_CYMENUSIZE
)/2 : 0),
473 max( (text
? max( 2 + size
.cy
, MOD_hic
+ 4) : 0),
475 ((int)hbmp
<0||(int)hbmp
>12 ?
477 : GetSystemMetrics( SM_CYMENUSIZE
) + 2)
480 expect
= ( !(text
|| hbmp
) ? GetSystemMetrics( SM_CYMENUSIZE
)/2 :
481 max( GetSystemMetrics( SM_CYMENU
) - 1, (hbmp
? bmpsize
.cy
: 0)));
482 ok( rc
.bottom
- rc
.top
== expect
,
483 "menu height wrong, got %d expected %d (%d)\n",
484 rc
.bottom
- rc
.top
, expect
, GetSystemMetrics( SM_CYMENU
));
485 failed
= failed
|| !(rc
.bottom
- rc
.top
== expect
);
486 if( hbmp
== HBMMENU_CALLBACK
&& MOD_GotDrawItemMsg
) {
487 /* check the position of the bitmap */
491 else if (mnuopt
== 0)
492 expect
= 4 + GetSystemMetrics(SM_CXMENUCHECK
);
493 else if (mnuopt
== 1)
495 else /* mnuopt == 2 */
497 ok( expect
== MOD_rc
[0].left
,
498 "bitmap left is %d expected %d\n", MOD_rc
[0].left
, expect
);
499 failed
= failed
|| !(expect
== MOD_rc
[0].left
);
501 expect
= (rc
.bottom
- rc
.top
- MOD_rc
[0].bottom
+ MOD_rc
[0].top
) / 2;
502 ok( expect
== MOD_rc
[0].top
,
503 "bitmap top is %d expected %d\n", MOD_rc
[0].top
, expect
);
504 failed
= failed
|| !(expect
== MOD_rc
[0].top
);
507 /* if there was a failure, report details */
509 trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
510 count
, (ispop
? "POPUP": "MENUBAR"),text
? text
: "(nil)", hbmp
, bmpsize
.cx
, bmpsize
.cy
,
511 size
.cx
, size
.cy
, sc_size
.cx
, mnuopt
, hastab
);
512 trace(" check %d,%d arrow %d avechar %d\n",
513 GetSystemMetrics(SM_CXMENUCHECK
),
514 GetSystemMetrics(SM_CYMENUCHECK
),arrowwidth
, MOD_avec
);
515 if( hbmp
== HBMMENU_CALLBACK
)
516 trace( " rc %d,%d-%d,%d bmp.rc %d,%d-%d,%d\n",
517 rc
.left
, rc
.top
, rc
.top
, rc
.bottom
, MOD_rc
[0].left
,
518 MOD_rc
[0].top
,MOD_rc
[0].right
, MOD_rc
[0].bottom
);
521 ret
= DestroyMenu(submenu
);
522 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
523 ret
= DestroyMenu(hmenu
);
524 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
528 static void test_menu_bmp_and_string(void)
536 MENUINFO mi
= {sizeof(MENUINFO
)};
537 MENUITEMINFOA mii
= {sizeof(MENUITEMINFOA
)};
538 int count
, szidx
, txtidx
, bmpidx
, hassub
, mnuopt
, ispop
;
542 win_skip("GetMenuInfo is not available\n");
546 memset( bmfill
, 0xcc, sizeof( bmfill
));
547 hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
, WS_SYSMENU
|
548 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
549 NULL
, NULL
, NULL
, NULL
);
550 hbm_arrow
=LoadBitmap( 0, (CHAR
*)OBM_MNARROW
);
551 GetObject( hbm_arrow
, sizeof(bm
), &bm
);
552 arrowwidth
= bm
.bmWidth
;
553 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
555 /* test system menu */
556 hsysmenu
= GetSystemMenu( hwnd
, FALSE
);
557 ok( hsysmenu
!= NULL
, "GetSystemMenu failed with error %d\n", GetLastError());
558 mi
.fMask
= MIM_STYLE
;
560 ok( pGetMenuInfo( hsysmenu
, &mi
), "GetMenuInfo failed gle=%d\n", GetLastError());
561 ok( MNS_CHECKORBMP
== mi
.dwStyle
, "System Menu Style is %08x, without the bit %08x\n",
562 mi
.dwStyle
, MNS_CHECKORBMP
);
563 mii
.fMask
= MIIM_BITMAP
;
565 ok( GetMenuItemInfoA( hsysmenu
, SC_CLOSE
, FALSE
, &mii
), "GetMenuItemInfoA failed gle=%d\n", GetLastError());
566 ok( HBMMENU_POPUP_CLOSE
== mii
.hbmpItem
, "Item info did not get the right hbitmap: got %p expected %p\n",
567 mii
.hbmpItem
, HBMMENU_POPUP_CLOSE
);
569 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_ownerdraw_wnd_proc
);
572 trace(" check %d,%d arrow %d avechar %d\n",
573 GetSystemMetrics(SM_CXMENUCHECK
),
574 GetSystemMetrics(SM_CYMENUCHECK
),arrowwidth
, MOD_avec
);
577 for( ispop
=1; ispop
>= 0; ispop
--){
578 static SIZE bmsizes
[]= {
579 {10,10},{38,38},{1,30},{55,5}};
580 for( szidx
=0; szidx
< sizeof( bmsizes
) / sizeof( SIZE
); szidx
++) {
581 HBITMAP hbm
= CreateBitmap( bmsizes
[szidx
].cx
, bmsizes
[szidx
].cy
,1,1,bmfill
);
582 HBITMAP bitmaps
[] = { HBMMENU_CALLBACK
, hbm
, HBMMENU_POPUP_CLOSE
, NULL
};
583 ok( hbm
!= 0, "CreateBitmap failed err %d\n", GetLastError());
584 for( txtidx
= 0; txtidx
< sizeof(MOD_txtsizes
)/sizeof(MOD_txtsizes
[0]); txtidx
++) {
585 for( hassub
= 0; hassub
< 2 ; hassub
++) { /* add submenu item */
586 for( mnuopt
= 0; mnuopt
< 3 ; mnuopt
++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
587 for( bmpidx
= 0; bmpidx
<sizeof(bitmaps
)/sizeof(HBITMAP
); bmpidx
++) {
588 /* no need to test NULL bitmaps of several sizes */
589 if( !bitmaps
[bmpidx
] && szidx
> 0) continue;
590 /* the HBMMENU_POPUP not to test for menu bars */
592 bitmaps
[bmpidx
] >= HBMMENU_POPUP_CLOSE
&&
593 bitmaps
[bmpidx
] <= HBMMENU_POPUP_MINIMIZE
) continue;
594 if( !ispop
&& hassub
) continue;
595 test_mbs_help( ispop
, hassub
, mnuopt
,
596 hwnd
, arrowwidth
, ++count
,
599 MOD_txtsizes
[txtidx
].text
,
600 MOD_txtsizes
[txtidx
].size
,
601 MOD_txtsizes
[txtidx
].sc_size
);
613 static void test_menu_add_string( void )
624 WCHAR strbackW
[0x80];
625 static CHAR blah
[] = "blah";
626 static const WCHAR expectedString
[] = {'D','u','m','m','y',' ','s','t','r','i','n','g', 0};
628 hmenu
= CreateMenu();
630 memset( &info
, 0, sizeof info
);
631 info
.cbSize
= sizeof info
;
632 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_ID
;
633 info
.dwTypeData
= blah
;
638 InsertMenuItem(hmenu
, 0, TRUE
, &info
);
640 memset( &info
, 0, sizeof info
);
641 info
.cbSize
= sizeof info
;
642 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_DATA
| MIIM_ID
;
643 info
.dwTypeData
= string
;
644 info
.cch
= sizeof string
;
646 GetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
648 ok( !strcmp( string
, "blah" ), "menu item name differed\n");
650 /* Test combination of ownerdraw and strings with GetMenuItemString(A/W) */
651 strcpy(string
, "Dummy string");
652 memset(&info
, 0x00, sizeof(info
));
653 info
.cbSize
= sizeof(MENUITEMINFO
);
654 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
; /* Set OwnerDraw + typeData */
655 info
.fType
= MFT_OWNERDRAW
;
656 info
.dwTypeData
= string
;
657 rc
= InsertMenuItem( hmenu
, 0, TRUE
, &info
);
658 ok (rc
, "InsertMenuItem failed\n");
660 strcpy(string
,"Garbage");
661 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
662 ok (!strcmp( strback
, "Dummy string" ), "Menu text from Ansi version incorrect\n");
664 SetLastError(0xdeadbeef);
665 ret
= GetMenuStringW( hmenu
, 0, strbackW
, 99, MF_BYPOSITION
);
666 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
667 win_skip("GetMenuStringW is not implemented\n");
670 ok (ret
, "GetMenuStringW on ownerdraw entry failed\n");
671 ok (!lstrcmpW( strbackW
, expectedString
), "Menu text from Unicode version incorrect\n");
674 /* Just change ftype to string and see what text is stored */
675 memset(&info
, 0x00, sizeof(info
));
676 info
.cbSize
= sizeof(MENUITEMINFO
);
677 info
.fMask
= MIIM_FTYPE
; /* Set string type */
678 info
.fType
= MFT_STRING
;
679 info
.dwTypeData
= (char *)0xdeadbeef;
680 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
681 ok (rc
, "SetMenuItemInfo failed\n");
683 /* Did we keep the old dwTypeData? */
684 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
685 ok (!strcmp( strback
, "Dummy string" ), "Menu text from Ansi version incorrect\n");
687 /* Ensure change to bitmap type fails */
688 memset(&info
, 0x00, sizeof(info
));
689 info
.cbSize
= sizeof(MENUITEMINFO
);
690 info
.fMask
= MIIM_FTYPE
; /* Set as bitmap type */
691 info
.fType
= MFT_BITMAP
;
692 info
.dwTypeData
= (char *)0xdeadbee2;
693 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
694 ok (!rc
, "SetMenuItemInfo unexpectedly worked\n");
696 /* Just change ftype back and ensure data hasn't been freed */
697 info
.fType
= MFT_OWNERDRAW
; /* Set as ownerdraw type */
698 info
.dwTypeData
= (char *)0xdeadbee3;
699 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
700 ok (rc
, "SetMenuItemInfo failed\n");
702 /* Did we keep the old dwTypeData? */
703 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
704 ok (!strcmp( strback
, "Dummy string" ), "Menu text from Ansi version incorrect\n");
706 /* Just change string value (not type) */
707 memset(&info
, 0x00, sizeof(info
));
708 info
.cbSize
= sizeof(MENUITEMINFO
);
709 info
.fMask
= MIIM_STRING
; /* Set typeData */
710 strcpy(string2
, "string2");
711 info
.dwTypeData
= string2
;
712 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
713 ok (rc
, "SetMenuItemInfo failed\n");
715 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
716 ok (!strcmp( strback
, "string2" ), "Menu text from Ansi version incorrect\n");
718 /* crashes with wine 0.9.5 */
719 memset(&info
, 0x00, sizeof(info
));
720 info
.cbSize
= sizeof(MENUITEMINFO
);
721 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
; /* Set OwnerDraw + typeData */
722 info
.fType
= MFT_OWNERDRAW
;
723 rc
= InsertMenuItem( hmenu
, 0, TRUE
, &info
);
724 ok (rc
, "InsertMenuItem failed\n");
725 ok (!GetMenuString( hmenu
, 0, NULL
, 0, MF_BYPOSITION
),
726 "GetMenuString on ownerdraw entry succeeded.\n");
727 SetLastError(0xdeadbeef);
728 ret
= GetMenuStringW( hmenu
, 0, NULL
, 0, MF_BYPOSITION
);
729 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
730 win_skip("GetMenuStringW is not implemented\n");
732 ok (!ret
, "GetMenuStringW on ownerdraw entry succeeded.\n");
734 DestroyMenu( hmenu
);
737 /* define building blocks for the menu item info tests */
738 static int strncmpW( const WCHAR
*str1
, const WCHAR
*str2
, int n
)
740 if (n
<= 0) return 0;
741 while ((--n
> 0) && *str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
742 return *str1
- *str2
;
745 static WCHAR
*strcpyW( WCHAR
*dst
, const WCHAR
*src
)
748 while ((*p
++ = *src
++));
752 static void insert_menu_item( int line
, HMENU hmenu
, BOOL ansi
, UINT mask
, UINT type
, UINT state
, UINT id
,
753 HMENU submenu
, HBITMAP checked
, HBITMAP unchecked
, ULONG_PTR data
,
754 void *type_data
, UINT len
, HBITMAP item
, BOOL expect
)
759 /* magic bitmap handle to test smaller cbSize */
760 if (item
== (HBITMAP
)(ULONG_PTR
)0xdeadbeef)
761 info
.cbSize
= FIELD_OFFSET(MENUITEMINFOA
,hbmpItem
);
763 info
.cbSize
= sizeof(info
);
768 info
.hSubMenu
= submenu
;
769 info
.hbmpChecked
= checked
;
770 info
.hbmpUnchecked
= unchecked
;
771 info
.dwItemData
= data
;
772 info
.dwTypeData
= type_data
;
774 info
.hbmpItem
= item
;
775 SetLastError( 0xdeadbeef );
776 if (ansi
) ret
= InsertMenuItemA( hmenu
, 0, TRUE
, &info
);
777 else ret
= InsertMenuItemW( hmenu
, 0, TRUE
, (MENUITEMINFOW
*)&info
);
778 if (!expect
) ok_(__FILE__
, line
)( !ret
, "InsertMenuItem should have failed.\n" );
779 else ok_(__FILE__
, line
)( ret
, "InsertMenuItem failed, err %u\n", GetLastError());
782 static void check_menu_item_info( int line
, HMENU hmenu
, BOOL ansi
, UINT mask
, UINT type
, UINT state
,
783 UINT id
, HMENU submenu
, HBITMAP checked
, HBITMAP unchecked
,
784 ULONG_PTR data
, void *type_data
, UINT in_len
, UINT out_len
,
785 HBITMAP item
, LPCSTR expname
, BOOL expect
, BOOL expstring
)
791 SetLastError( 0xdeadbeef );
792 memset( &info
, 0xcc, sizeof(info
) );
793 info
.cbSize
= sizeof(info
);
795 info
.dwTypeData
= type_data
;
798 ret
= ansi
? GetMenuItemInfoA( hmenu
, 0, TRUE
, &info
) :
799 GetMenuItemInfoW( hmenu
, 0, TRUE
, (MENUITEMINFOW
*)&info
);
802 ok_(__FILE__
, line
)( !ret
, "GetMenuItemInfo should have failed.\n" );
805 ok_(__FILE__
, line
)( ret
, "GetMenuItemInfo failed, err %u\n", GetLastError());
806 if (mask
& MIIM_TYPE
)
807 ok_(__FILE__
, line
)( info
.fType
== type
|| info
.fType
== LOWORD(type
),
808 "wrong type %x/%x\n", info
.fType
, type
);
809 if (mask
& MIIM_STATE
)
810 ok_(__FILE__
, line
)( info
.fState
== state
|| info
.fState
== LOWORD(state
),
811 "wrong state %x/%x\n", info
.fState
, state
);
813 ok_(__FILE__
, line
)( info
.wID
== id
|| info
.wID
== LOWORD(id
),
814 "wrong id %x/%x\n", info
.wID
, id
);
815 if (mask
& MIIM_SUBMENU
)
816 ok_(__FILE__
, line
)( info
.hSubMenu
== submenu
|| (ULONG_PTR
)info
.hSubMenu
== LOWORD(submenu
),
817 "wrong submenu %p/%p\n", info
.hSubMenu
, submenu
);
818 if (mask
& MIIM_CHECKMARKS
)
820 ok_(__FILE__
, line
)( info
.hbmpChecked
== checked
|| (ULONG_PTR
)info
.hbmpChecked
== LOWORD(checked
),
821 "wrong bmpchecked %p/%p\n", info
.hbmpChecked
, checked
);
822 ok_(__FILE__
, line
)( info
.hbmpUnchecked
== unchecked
|| (ULONG_PTR
)info
.hbmpUnchecked
== LOWORD(unchecked
),
823 "wrong bmpunchecked %p/%p\n", info
.hbmpUnchecked
, unchecked
);
825 if (mask
& MIIM_DATA
)
826 ok_(__FILE__
, line
)( info
.dwItemData
== data
|| info
.dwItemData
== LOWORD(data
),
827 "wrong item data %lx/%lx\n", info
.dwItemData
, data
);
828 if (mask
& MIIM_BITMAP
)
829 ok_(__FILE__
, line
)( info
.hbmpItem
== item
|| (ULONG_PTR
)info
.hbmpItem
== LOWORD(item
),
830 "wrong bmpitem %p/%p\n", info
.hbmpItem
, item
);
831 ok_(__FILE__
, line
)( info
.dwTypeData
== type_data
|| (ULONG_PTR
)info
.dwTypeData
== LOWORD(type_data
),
832 "wrong type data %p/%p\n", info
.dwTypeData
, type_data
);
833 ok_(__FILE__
, line
)( info
.cch
== out_len
, "wrong len %x/%x\n", info
.cch
, out_len
);
837 ok_(__FILE__
, line
)( !strncmp( expname
, info
.dwTypeData
, out_len
),
838 "menu item name differed from '%s' '%s'\n", expname
, info
.dwTypeData
);
840 ok_(__FILE__
, line
)( !strncmpW( (WCHAR
*)expname
, (WCHAR
*)info
.dwTypeData
, out_len
),
841 "menu item name wrong\n" );
843 SetLastError( 0xdeadbeef );
844 ret
= ansi
? GetMenuStringA( hmenu
, 0, (char *)buffer
, 80, MF_BYPOSITION
) :
845 GetMenuStringW( hmenu
, 0, buffer
, 80, MF_BYPOSITION
);
847 ok_(__FILE__
, line
)( ret
, "GetMenuString failed, err %u\n", GetLastError());
849 ok_(__FILE__
, line
)( !ret
, "GetMenuString should have failed\n" );
853 static void modify_menu( int line
, HMENU hmenu
, BOOL ansi
, UINT flags
, UINT_PTR id
, void *data
)
857 SetLastError( 0xdeadbeef );
858 if (ansi
) ret
= ModifyMenuA( hmenu
, 0, flags
, id
, data
);
859 else ret
= ModifyMenuW( hmenu
, 0, flags
, id
, data
);
860 ok_(__FILE__
,line
)( ret
, "ModifyMenuA failed, err %u\n", GetLastError());
863 static void set_menu_item_info( int line
, HMENU hmenu
, BOOL ansi
, UINT mask
, UINT type
, UINT state
,
864 UINT id
, HMENU submenu
, HBITMAP checked
, HBITMAP unchecked
, ULONG_PTR data
,
865 void *type_data
, UINT len
, HBITMAP item
)
871 /* magic bitmap handle to test smaller cbSize */
872 if (item
== (HBITMAP
)(ULONG_PTR
)0xdeadbeef)
873 info
.cbSize
= FIELD_OFFSET(MENUITEMINFOA
,hbmpItem
);
875 info
.cbSize
= sizeof(info
);
880 info
.hSubMenu
= submenu
;
881 info
.hbmpChecked
= checked
;
882 info
.hbmpUnchecked
= unchecked
;
883 info
.dwItemData
= data
;
884 info
.dwTypeData
= type_data
;
886 info
.hbmpItem
= item
;
887 SetLastError( 0xdeadbeef );
888 if (ansi
) ret
= SetMenuItemInfoA( hmenu
, 0, TRUE
, &info
);
889 else ret
= SetMenuItemInfoW( hmenu
, 0, TRUE
, (MENUITEMINFOW
*)&info
);
890 ok_(__FILE__
, line
)( ret
, "SetMenuItemInfo failed, err %u\n", GetLastError());
893 #define TMII_INSMI( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,eret1 )\
894 hmenu = CreateMenu();\
895 submenu = CreateMenu();\
896 if(ansi)strcpy( string, init );\
897 else strcpyW( string, init );\
898 insert_menu_item( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, eret1 )
900 /* GetMenuItemInfo + GetMenuString */
901 #define TMII_GMII( c2,l2,\
902 d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,\
903 expname, eret2, eret3)\
904 check_menu_item_info( __LINE__, hmenu, ansi, c2, d3, e3, f3, g3, h3, i3, j3, k3, l2, l3, m3, \
905 expname, eret2, eret3 )
908 RemoveMenu(hmenu, 0, TRUE );\
909 DestroyMenu( hmenu );\
910 DestroyMenu( submenu );
913 #define TMII_MODM( flags, id, data ) \
914 modify_menu( __LINE__, hmenu, ansi, flags, id, data )
916 /* SetMenuItemInfo */
917 #define TMII_SMII( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1 ) \
918 set_menu_item_info( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1 )
925 static void test_menu_iteminfo( void )
931 WCHAR txtW
[]={'W','i','n','e',0};
932 WCHAR initW
[]={'X','Y','Z',0};
934 void *txt
, *init
, *empty
, *string
;
935 HBITMAP hbm
= CreateBitmap(1,1,1,1,NULL
);
937 HMENU hmenu
, submenu
=CreateMenu();
938 HBITMAP dummy_hbm
= (HBITMAP
)(ULONG_PTR
)0xdeadbeef;
941 if( ansi
) {txt
=txtA
;init
=initA
;empty
=emptyA
;string
=stringA
;}
942 else {txt
=txtW
;init
=initW
;empty
=emptyW
;string
=stringA
;}
943 trace( "%s string %p hbm %p txt %p\n", ansi
? "ANSI tests: " : "Unicode tests:", string
, hbm
, txt
);
944 /* test all combinations of MFT_STRING, MFT_OWNERDRAW and MFT_BITMAP */
945 /* (since MFT_STRING is zero, there are four of them) */
946 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, 0, 0, 0, 0, 0, 0, txt
, 0, 0, OK
);
947 TMII_GMII ( MIIM_TYPE
, 80,
948 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
951 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
952 TMII_GMII ( MIIM_TYPE
, 80,
953 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
956 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, 6, 0, OK
);
957 TMII_GMII ( MIIM_TYPE
, 80,
958 MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
961 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, hbm
, 6, 0, OK
);
962 TMII_GMII ( MIIM_TYPE
, 80,
963 MFT_BITMAP
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
966 /* not enough space for name*/
967 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
968 TMII_GMII ( MIIM_TYPE
, 0,
969 MFT_STRING
, 0, 0, 0, 0, 0, 0, NULL
, 4, 0,
972 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
973 TMII_GMII ( MIIM_TYPE
, 5,
974 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
977 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
978 TMII_GMII ( MIIM_TYPE
, 4,
979 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 3, 0,
982 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
983 TMII_GMII ( MIIM_TYPE
, 0,
984 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 0, 0,
987 /* cannot combine MIIM_TYPE with some other flags */
988 TMII_INSMI( MIIM_TYPE
|MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, ER
);
990 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
991 TMII_GMII ( MIIM_TYPE
|MIIM_STRING
, 80,
992 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
995 TMII_INSMI( MIIM_TYPE
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, ER
);
997 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
998 TMII_GMII ( MIIM_TYPE
|MIIM_FTYPE
, 80,
999 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1002 TMII_INSMI( MIIM_TYPE
|MIIM_BITMAP
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, 6, hbm
, ER
);
1004 /* but succeeds with some others */
1005 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1006 TMII_GMII ( MIIM_TYPE
|MIIM_SUBMENU
, 80,
1007 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1010 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1011 TMII_GMII ( MIIM_TYPE
|MIIM_STATE
, 80,
1012 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1015 TMII_INSMI( MIIM_TYPE
|MIIM_ID
, MFT_STRING
, -1, 888, 0, 0, 0, -1, txt
, 6, 0, OK
);
1016 TMII_GMII ( MIIM_TYPE
|MIIM_ID
, 80,
1017 MFT_STRING
, 0, 888, 0, 0, 0, 0, string
, 4, 0,
1020 TMII_INSMI( MIIM_TYPE
|MIIM_DATA
, MFT_STRING
, -1, -1, 0, 0, 0, 999, txt
, 6, 0, OK
);
1021 TMII_GMII ( MIIM_TYPE
|MIIM_DATA
, 80,
1022 MFT_STRING
, 0, 0, 0, 0, 0, 999, string
, 4, 0,
1025 /* to be continued */
1026 /* set text with MIIM_TYPE and retrieve with MIIM_STRING */
1027 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1028 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1029 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1032 /* set text with MIIM_TYPE and retrieve with MIIM_STRING; MFT_OWNERDRAW causes an empty string */
1033 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1034 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1035 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1038 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1039 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1040 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1043 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1044 TMII_GMII ( MIIM_FTYPE
, 80,
1045 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 80, 0,
1048 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1050 0, 0, 0, 0, 0, 0, 0, string
, 80, 0,
1053 /* contrary to MIIM_TYPE,you can set the text for an owner draw menu */
1054 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1055 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1056 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1059 /* same but retrieve with MIIM_TYPE */
1060 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1061 TMII_GMII ( MIIM_TYPE
, 80,
1062 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1065 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1066 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1067 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1070 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1071 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1072 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1076 /* How is that with bitmaps? */
1077 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1078 TMII_GMII ( MIIM_TYPE
, 80,
1079 MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1082 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1083 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1084 0, 0, 0, 0, 0, 0, 0, string
, 80, hbm
,
1087 /* MIIM_BITMAP does not like MFT_BITMAP */
1088 TMII_INSMI( MIIM_BITMAP
|MIIM_FTYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, ER
);
1090 /* no problem with OWNERDRAWN */
1091 TMII_INSMI( MIIM_BITMAP
|MIIM_FTYPE
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1092 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1093 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 80, hbm
,
1096 /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1097 TMII_INSMI( MIIM_FTYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER
);
1100 /* menu with submenu */
1101 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, submenu
, 0, 0, -1, txt
, 0, 0, OK
);
1102 TMII_GMII ( MIIM_SUBMENU
, 80,
1103 0, 0, 0, submenu
, 0, 0, 0, string
, 80, 0,
1106 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, submenu
, 0, 0, -1, empty
, 0, 0, OK
);
1107 TMII_GMII ( MIIM_SUBMENU
, 80,
1108 0, 0, 0, submenu
, 0, 0, 0, string
, 80, 0,
1111 /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1112 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, submenu
, 0, 0, -1, txt
, 0, 0, OK
);
1113 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1114 MFT_STRING
|MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1116 TMII_GMII ( MIIM_SUBMENU
|MIIM_FTYPE
, 80,
1117 MFT_SEPARATOR
, 0, 0, submenu
, 0, 0, 0, string
, 80, 0,
1120 /* menu with invalid submenu */
1121 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, (HMENU
)999, 0, 0, -1, txt
, 0, 0, ER
);
1124 TMII_INSMI( MIIM_TYPE
, MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, txt
, 0, 0, OK
);
1125 TMII_GMII ( MIIM_TYPE
, 80,
1126 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1129 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
|MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, hbm
, 6, 0, OK
);
1130 TMII_GMII ( MIIM_TYPE
, 80,
1131 MFT_BITMAP
|MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1134 /* SEPARATOR and STRING go well together */
1135 /* BITMAP and STRING go well together */
1136 TMII_INSMI( MIIM_STRING
|MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1137 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, 80,
1138 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, hbm
,
1141 /* BITMAP, SEPARATOR and STRING go well together */
1142 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1143 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, 80,
1144 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 4, hbm
,
1147 /* last two tests, but use MIIM_TYPE to retrieve info */
1148 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1149 TMII_GMII ( MIIM_TYPE
, 80,
1150 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1153 TMII_INSMI( MIIM_STRING
|MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1154 TMII_GMII ( MIIM_TYPE
, 80,
1155 MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1158 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1159 TMII_GMII ( MIIM_TYPE
, 80,
1160 MFT_SEPARATOR
|MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1163 /* same three with MFT_OWNERDRAW */
1164 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
, MFT_SEPARATOR
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1165 TMII_GMII ( MIIM_TYPE
, 80,
1166 MFT_SEPARATOR
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1169 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1170 TMII_GMII ( MIIM_TYPE
, 80,
1171 MFT_BITMAP
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1174 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1175 TMII_GMII ( MIIM_TYPE
, 80,
1176 MFT_SEPARATOR
|MFT_BITMAP
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1180 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
|MIIM_ID
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1181 TMII_GMII ( MIIM_TYPE
, 80,
1182 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1185 /* test with modifymenu: string is preserved after setting OWNERDRAW */
1186 TMII_INSMI( MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1187 TMII_MODM( MFT_OWNERDRAW
, -1, (void*)787 );
1188 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_DATA
, 80,
1189 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 787, string
, 4, 0,
1192 /* same with bitmap: now the text is cleared */
1193 TMII_INSMI( MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1194 TMII_MODM( MFT_BITMAP
, 545, hbm
);
1195 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1196 MFT_BITMAP
, 0, 545, 0, 0, 0, 0, string
, 0, hbm
,
1199 /* start with bitmap: now setting text clears it (though he flag is raised) */
1200 TMII_INSMI( MIIM_BITMAP
, MFT_STRING
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1201 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1202 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 0, hbm
,
1204 TMII_MODM( MFT_STRING
, 545, txt
);
1205 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1206 MFT_STRING
, 0, 545, 0, 0, 0, 0, string
, 4, 0,
1209 /*repeat with text NULL */
1210 TMII_INSMI( MIIM_BITMAP
, MFT_STRING
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1211 TMII_MODM( MFT_STRING
, 545, NULL
);
1212 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1213 MFT_SEPARATOR
, 0, 545, 0, 0, 0, 0, string
, 0, 0,
1216 /* repeat with text "" */
1217 TMII_INSMI( MIIM_BITMAP
, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1218 TMII_MODM( MFT_STRING
, 545, empty
);
1219 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1220 MFT_STRING
, 0, 545, 0, 0, 0, 0, string
, 0, 0,
1223 /* start with bitmap: set ownerdraw */
1224 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1225 TMII_MODM( MFT_OWNERDRAW
, -1, (void *)232 );
1226 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_DATA
, 80,
1227 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 232, string
, 0, hbm
,
1231 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1233 0, 0, 0, 0, 0, 0, 0, string
, 80, 0,
1236 /* some tests with small cbSize: the hbmpItem is to be ignored */
1237 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm
, OK
);
1238 TMII_GMII ( MIIM_TYPE
, 80,
1239 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, NULL
, 0, NULL
,
1242 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm
, OK
);
1243 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1244 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 80, NULL
,
1247 TMII_INSMI( MIIM_STRING
|MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1248 TMII_GMII ( MIIM_TYPE
, 80,
1249 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, NULL
,
1252 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1253 TMII_GMII ( MIIM_TYPE
, 80,
1254 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1257 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1258 TMII_GMII ( MIIM_TYPE
, 80,
1259 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1262 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1263 TMII_GMII ( MIIM_TYPE
, 80,
1264 MFT_SEPARATOR
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1267 /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus */
1268 TMII_INSMI( MIIM_TYPE
|MIIM_DATA
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, 343, txt
, 0, 0, OK
);
1269 TMII_GMII ( MIIM_TYPE
|MIIM_DATA
, 80,
1270 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1273 TMII_INSMI( MIIM_TYPE
|MIIM_DATA
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, 343, txt
, 0, 0, OK
);
1274 TMII_GMII ( MIIM_TYPE
, 80,
1275 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1278 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, 343, txt
, 0, 0, OK
);
1279 TMII_GMII ( MIIM_TYPE
|MIIM_DATA
, 80,
1280 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1283 /* set a string menu to ownerdraw with MIIM_TYPE */
1284 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -2, -2, 0, 0, 0, -2, txt
, -2, 0, OK
);
1285 TMII_SMII ( MIIM_TYPE
, MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1286 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1287 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1290 /* test with modifymenu add submenu */
1291 TMII_INSMI( MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1292 TMII_MODM( MF_POPUP
, (UINT_PTR
)submenu
, txt
);
1293 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_SUBMENU
, 80,
1294 MFT_STRING
, 0, 0, submenu
, 0, 0, 0, string
, 4, 0,
1296 TMII_GMII ( MIIM_TYPE
, 80,
1297 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1300 /* MFT_SEPARATOR bit is kept when the text is added */
1301 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1302 TMII_SMII( MIIM_STRING
, 0, 0, 0, 0, 0, 0, 0, txt
, 0, 0 );
1303 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1304 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1307 /* MFT_SEPARATOR bit is kept when bitmap is added */
1308 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1309 TMII_SMII( MIIM_BITMAP
, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm
);
1310 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1311 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 80, hbm
,
1314 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1315 Only the low word of the dwTypeData is used.
1316 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1317 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_RIGHTJUSTIFY
, -1, -1, 0, 0, 0, -1,
1318 (HMENU
)MAKELONG(HBMMENU_MBAR_CLOSE
, 0x1234), -1, 0, OK
);
1319 TMII_GMII ( MIIM_TYPE
, 80,
1320 MFT_BITMAP
| MFT_RIGHTJUSTIFY
, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE
, 0, HBMMENU_MBAR_CLOSE
,
1324 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1325 TMII_GMII ( MIIM_TYPE
, 80,
1326 MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1330 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1331 TMII_SMII( MIIM_STATE
, -1, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 0, 0 );
1332 TMII_GMII ( MIIM_STATE
, 80,
1333 0, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 80, 0,
1336 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1337 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1338 TMII_SMII( MIIM_CHECKMARKS
, MFT_RADIOCHECK
, 0, 0, 0, hbm
, hbm
, 0, 0, 0, 0 );
1339 TMII_GMII ( MIIM_CHECKMARKS
| MIIM_TYPE
, 80,
1340 MFT_BITMAP
, 0, 0, 0, hbm
, hbm
, 0, hbm
, 0, hbm
,
1343 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1344 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1345 TMII_SMII( MIIM_FTYPE
, MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, (HBITMAP
)0x1234, 0, 0 );
1346 TMII_GMII ( MIIM_FTYPE
, 80,
1347 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1349 TMII_GMII ( MIIM_TYPE
, 80,
1350 MFT_BITMAP
| MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1352 TMII_GMII ( MIIM_FTYPE
, 80,
1353 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1355 TMII_SMII( MIIM_BITMAP
, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
);
1356 TMII_GMII ( MIIM_TYPE
, 80,
1357 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 0, NULL
,
1360 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1361 Only the low word of the dwTypeData is used.
1362 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1363 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_RIGHTJUSTIFY
, -1, -1, 0, 0, 0, -1,
1364 (HMENU
)MAKELONG(HBMMENU_MBAR_CLOSE
, 0x1234), -1, 0, OK
);
1365 TMII_GMII ( MIIM_TYPE
, 80,
1366 MFT_BITMAP
| MFT_RIGHTJUSTIFY
, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE
, 0, HBMMENU_MBAR_CLOSE
,
1370 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1371 TMII_GMII ( MIIM_TYPE
, 80,
1372 MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1376 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1377 TMII_SMII( MIIM_STATE
, -1, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 0, 0 );
1378 TMII_GMII ( MIIM_STATE
, 80,
1379 0, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 80, 0,
1382 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1383 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1384 TMII_SMII( MIIM_CHECKMARKS
, MFT_RADIOCHECK
, 0, 0, 0, hbm
, hbm
, 0, 0, 0, 0 );
1385 TMII_GMII ( MIIM_CHECKMARKS
| MIIM_TYPE
, 80,
1386 MFT_BITMAP
, 0, 0, 0, hbm
, hbm
, 0, hbm
, 0, hbm
,
1389 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1390 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1391 TMII_SMII( MIIM_FTYPE
, MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, (HBITMAP
)0x1234, 0, 0 );
1392 TMII_GMII ( MIIM_FTYPE
, 80,
1393 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1395 TMII_GMII ( MIIM_TYPE
, 80,
1396 MFT_BITMAP
| MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1398 TMII_GMII ( MIIM_FTYPE
, 80,
1399 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1401 TMII_SMII( MIIM_BITMAP
, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
);
1402 TMII_GMII ( MIIM_TYPE
, 80,
1403 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 0, NULL
,
1406 } while( !(ansi
= !ansi
) );
1411 The following tests try to confirm the algorithm used to return the menu items
1412 when there is a collision between a menu item and a popup menu
1414 static void test_menu_search_bycommand( void )
1416 HMENU hmenu
, hmenuSub
, hmenuSub2
;
1422 static CHAR menuitem
[] = "MenuItem",
1423 menuitem2
[] = "MenuItem 2";
1425 /* Case 1: Menu containing a menu item */
1426 hmenu
= CreateMenu();
1428 memset( &info
, 0, sizeof info
);
1429 info
.cbSize
= sizeof info
;
1430 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1431 info
.fType
= MFT_STRING
;
1432 strcpy(strIn
, "Case 1 MenuItem");
1433 info
.dwTypeData
= strIn
;
1434 info
.wID
= (UINT
) 0x1234;
1436 rc
= InsertMenuItem(hmenu
, 0, TRUE
, &info
);
1437 ok (rc
, "Inserting the menuitem failed\n");
1439 id
= GetMenuItemID(hmenu
, 0);
1440 ok (id
== 0x1234, "Getting the menuitem id failed(gave %x)\n", id
);
1442 /* Confirm the menuitem was given the id supplied (getting by position) */
1443 memset( &info
, 0, sizeof info
);
1445 info
.cbSize
= sizeof(MENUITEMINFO
);
1446 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1447 info
.dwTypeData
= strback
;
1448 info
.cch
= sizeof(strback
);
1450 rc
= GetMenuItemInfo(hmenu
, 0, TRUE
, &info
); /* Get by position */
1451 ok (rc
, "Getting the menu items info failed\n");
1452 ok (info
.wID
== 0x1234, "IDs differ for the menuitem\n");
1453 ok (!strcmp(info
.dwTypeData
, "Case 1 MenuItem"), "Returned item has wrong label\n");
1455 /* Search by id - Should return the item */
1456 memset( &info
, 0, sizeof info
);
1458 info
.cbSize
= sizeof(MENUITEMINFO
);
1459 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1460 info
.dwTypeData
= strback
;
1461 info
.cch
= sizeof(strback
);
1462 rc
= GetMenuItemInfo(hmenu
, 0x1234, FALSE
, &info
); /* Get by ID */
1464 ok (rc
, "Getting the menu items info failed\n");
1465 ok (info
.wID
== 0x1234, "IDs differ for the menuitem\n");
1466 ok (!strcmp(info
.dwTypeData
, "Case 1 MenuItem"), "Returned item has wrong label\n");
1468 DestroyMenu( hmenu
);
1470 /* Case 2: Menu containing a popup menu */
1471 hmenu
= CreateMenu();
1472 hmenuSub
= CreateMenu();
1474 strcpy(strIn
, "Case 2 SubMenu");
1475 rc
= InsertMenu(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, strIn
);
1476 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1478 id
= GetMenuItemID(hmenu
, 0);
1479 ok (id
== -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id
);
1481 /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
1482 memset( &info
, 0, sizeof info
);
1484 info
.cbSize
= sizeof(MENUITEMINFO
);
1485 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1486 info
.dwTypeData
= strback
;
1487 info
.cch
= sizeof(strback
);
1488 info
.wID
= 0xdeadbeef;
1490 rc
= GetMenuItemInfo(hmenu
, 0, TRUE
, &info
); /* Get by position */
1491 ok (rc
, "Getting the menu items info failed\n");
1492 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the menuitem\n");
1493 ok (!strcmp(info
.dwTypeData
, "Case 2 SubMenu"), "Returned item has wrong label\n");
1495 /* Search by id - returns the popup menu itself */
1496 memset( &info
, 0, sizeof info
);
1498 info
.cbSize
= sizeof(MENUITEMINFO
);
1499 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1500 info
.dwTypeData
= strback
;
1501 info
.cch
= sizeof(strback
);
1502 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
); /* Get by ID */
1504 ok (rc
, "Getting the menu items info failed\n");
1505 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the popup menu\n");
1506 ok (!strcmp(info
.dwTypeData
, "Case 2 SubMenu"), "Returned item has wrong label\n");
1509 Now add an item after it with the same id
1511 memset( &info
, 0, sizeof info
);
1512 info
.cbSize
= sizeof info
;
1513 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1514 info
.fType
= MFT_STRING
;
1515 strcpy(strIn
, "Case 2 MenuItem 1");
1516 info
.dwTypeData
= strIn
;
1517 info
.wID
= (UINT_PTR
) hmenuSub
;
1518 rc
= InsertMenuItem(hmenu
, -1, TRUE
, &info
);
1519 ok (rc
, "Inserting the menuitem failed\n");
1521 /* Search by id - returns the item which follows the popup menu */
1522 memset( &info
, 0, sizeof info
);
1524 info
.cbSize
= sizeof(MENUITEMINFO
);
1525 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1526 info
.dwTypeData
= strback
;
1527 info
.cch
= sizeof(strback
);
1528 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
); /* Get by ID */
1530 ok (rc
, "Getting the menu items info failed\n");
1531 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the popup menu\n");
1532 ok (!strcmp(info
.dwTypeData
, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1535 Now add an item before the popup (with the same id)
1537 memset( &info
, 0, sizeof info
);
1538 info
.cbSize
= sizeof info
;
1539 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1540 info
.fType
= MFT_STRING
;
1541 strcpy(strIn
, "Case 2 MenuItem 2");
1542 info
.dwTypeData
= strIn
;
1543 info
.wID
= (UINT_PTR
) hmenuSub
;
1544 rc
= InsertMenuItem(hmenu
, 0, TRUE
, &info
);
1545 ok (rc
, "Inserting the menuitem failed\n");
1547 /* Search by id - returns the item which precedes the popup menu */
1548 memset( &info
, 0, sizeof info
);
1550 info
.cbSize
= sizeof(MENUITEMINFO
);
1551 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1552 info
.dwTypeData
= strback
;
1553 info
.cch
= sizeof(strback
);
1554 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
); /* Get by ID */
1556 ok (rc
, "Getting the menu items info failed\n");
1557 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the popup menu\n");
1558 ok (!strcmp(info
.dwTypeData
, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1560 DestroyMenu( hmenu
);
1561 DestroyMenu( hmenuSub
);
1564 Case 3: Menu containing a popup menu which in turn
1565 contains 2 items with the same id as the popup itself
1568 hmenu
= CreateMenu();
1569 hmenuSub
= CreateMenu();
1571 memset( &info
, 0, sizeof info
);
1572 info
.cbSize
= sizeof info
;
1573 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1574 info
.fType
= MFT_STRING
;
1575 info
.dwTypeData
= menuitem
;
1576 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1578 rc
= InsertMenu(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, "Submenu");
1579 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1581 rc
= InsertMenuItem(hmenuSub
, 0, TRUE
, &info
);
1582 ok (rc
, "Inserting the sub menu menuitem failed\n");
1584 memset( &info
, 0, sizeof info
);
1585 info
.cbSize
= sizeof info
;
1586 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1587 info
.fType
= MFT_STRING
;
1588 info
.dwTypeData
= menuitem2
;
1589 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1591 rc
= InsertMenuItem(hmenuSub
, 1, TRUE
, &info
);
1592 ok (rc
, "Inserting the sub menu menuitem 2 failed\n");
1594 /* Prove that you can't query the id of a popup directly (By position) */
1595 id
= GetMenuItemID(hmenu
, 0);
1596 ok (id
== -1, "Getting the sub menu id should have failed because its a popup (gave %x)\n", id
);
1598 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1599 memset( &info
, 0, sizeof info
);
1601 info
.cbSize
= sizeof(MENUITEMINFO
);
1602 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1603 info
.dwTypeData
= strback
;
1604 info
.cch
= sizeof(strback
);
1606 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
);
1607 ok (rc
, "Getting the menus info failed\n");
1608 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for popup menu\n");
1609 ok (!strcmp(info
.dwTypeData
, "MenuItem"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1610 DestroyMenu( hmenu
);
1611 DestroyMenu( hmenuSub
);
1614 Case 4: Menu containing 2 popup menus, the second
1615 contains 2 items with the same id as the first popup menu
1617 hmenu
= CreateMenu();
1618 hmenuSub
= CreateMenu();
1619 hmenuSub2
= CreateMenu();
1621 rc
= InsertMenu(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, "Submenu");
1622 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1624 rc
= InsertMenu(hmenu
, 1, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub2
, "Submenu2");
1625 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1627 memset( &info
, 0, sizeof info
);
1628 info
.cbSize
= sizeof info
;
1629 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1630 info
.fType
= MFT_STRING
;
1631 info
.dwTypeData
= menuitem
;
1632 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1634 rc
= InsertMenuItem(hmenuSub2
, 0, TRUE
, &info
);
1635 ok (rc
, "Inserting the sub menu menuitem failed\n");
1637 memset( &info
, 0, sizeof info
);
1638 info
.cbSize
= sizeof info
;
1639 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1640 info
.fType
= MFT_STRING
;
1641 info
.dwTypeData
= menuitem2
;
1642 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1644 rc
= InsertMenuItem(hmenuSub2
, 1, TRUE
, &info
);
1645 ok (rc
, "Inserting the sub menu menuitem 2 failed\n");
1647 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1648 memset( &info
, 0, sizeof info
);
1650 info
.cbSize
= sizeof(MENUITEMINFO
);
1651 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1652 info
.dwTypeData
= strback
;
1653 info
.cch
= sizeof(strback
);
1655 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
);
1656 ok (rc
, "Getting the menus info failed\n");
1657 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for popup menu\n");
1658 ok (!strcmp(info
.dwTypeData
, "MenuItem"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1660 memset( &info
, 0, sizeof info
);
1662 info
.cbSize
= sizeof(MENUITEMINFO
);
1663 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1664 info
.dwTypeData
= strback
;
1665 info
.cch
= sizeof(strback
);
1667 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub2
, FALSE
, &info
);
1668 ok (rc
, "Getting the menus info failed\n");
1669 ok (info
.wID
== (UINT_PTR
)hmenuSub2
, "IDs differ for popup menu\n");
1670 ok (!strcmp(info
.dwTypeData
, "Submenu2"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1672 DestroyMenu( hmenu
);
1673 DestroyMenu( hmenuSub
);
1674 DestroyMenu( hmenuSub2
);
1678 Case 5: Menu containing a popup menu which in turn
1679 contains an item with a different id than the popup menu.
1680 This tests the fallback to a popup menu ID.
1683 hmenu
= CreateMenu();
1684 hmenuSub
= CreateMenu();
1686 rc
= AppendMenu(hmenu
, MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, "Submenu");
1687 ok (rc
, "Appending the popup menu to the main menu failed\n");
1689 rc
= AppendMenu(hmenuSub
, MF_STRING
, 102, "Item");
1690 ok (rc
, "Appending the item to the popup menu failed\n");
1692 /* Set the ID for hmenuSub */
1693 info
.cbSize
= sizeof(info
);
1694 info
.fMask
= MIIM_ID
;
1697 rc
= SetMenuItemInfo(hmenu
, 0, TRUE
, &info
);
1698 ok(rc
, "Setting the ID for the popup menu failed\n");
1700 /* Check if the ID has been set */
1702 rc
= GetMenuItemInfo(hmenu
, 0, TRUE
, &info
);
1703 ok(rc
, "Getting the ID for the popup menu failed\n");
1704 ok(info
.wID
== 101, "The ID for the popup menu has not been set\n");
1706 /* Prove getting the item info via ID returns the popup menu */
1707 memset( &info
, 0, sizeof(info
));
1709 info
.cbSize
= sizeof(MENUITEMINFO
);
1710 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1711 info
.dwTypeData
= strback
;
1712 info
.cch
= sizeof(strback
);
1714 rc
= GetMenuItemInfo(hmenu
, 101, FALSE
, &info
);
1715 ok (rc
, "Getting the menu info failed\n");
1716 ok (info
.wID
== 101, "IDs differ\n");
1717 ok (!strcmp(info
.dwTypeData
, "Submenu"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1719 /* Also look for the menu item */
1720 memset( &info
, 0, sizeof(info
));
1722 info
.cbSize
= sizeof(MENUITEMINFO
);
1723 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1724 info
.dwTypeData
= strback
;
1725 info
.cch
= sizeof(strback
);
1727 rc
= GetMenuItemInfo(hmenu
, 102, FALSE
, &info
);
1728 ok (rc
, "Getting the menu info failed\n");
1729 ok (info
.wID
== 102, "IDs differ\n");
1730 ok (!strcmp(info
.dwTypeData
, "Item"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1733 DestroyMenu(hmenuSub
);
1736 struct menu_item_pair_s
{
1737 UINT uMenu
; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
1738 * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
1739 * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
1743 static struct menu_mouse_tests_s
{
1745 struct menu_item_pair_s menu_item_pairs
[5]; /* for mousing */
1746 WORD wVk
[5]; /* keys */
1750 /* for each test, send keys or clicks and check for menu visibility */
1751 { INPUT_KEYBOARD
, {{0}}, {VK_LMENU
, 0}, TRUE
, FALSE
}, /* test 0 */
1752 { INPUT_KEYBOARD
, {{0}}, {VK_ESCAPE
, 0}, FALSE
, FALSE
},
1753 { INPUT_KEYBOARD
, {{0}}, {VK_LMENU
, 0}, TRUE
, FALSE
},
1754 { INPUT_KEYBOARD
, {{0}}, {'D', 0}, FALSE
, FALSE
},
1755 { INPUT_KEYBOARD
, {{0}}, {VK_LMENU
, 0}, TRUE
, FALSE
},
1756 { INPUT_KEYBOARD
, {{0}}, {'E', 0}, FALSE
, FALSE
},
1757 { INPUT_KEYBOARD
, {{0}}, {VK_LMENU
, 'M', 0}, TRUE
, FALSE
},
1758 { INPUT_KEYBOARD
, {{0}}, {VK_ESCAPE
, VK_ESCAPE
, 0}, FALSE
, FALSE
},
1759 { INPUT_KEYBOARD
, {{0}}, {VK_LMENU
, 'M', VK_ESCAPE
, 0}, TRUE
, FALSE
},
1760 { INPUT_KEYBOARD
, {{0}}, {VK_ESCAPE
, 0}, FALSE
, FALSE
},
1761 { INPUT_KEYBOARD
, {{0}}, {VK_LMENU
, 'M', 0}, TRUE
, FALSE
},
1762 { INPUT_KEYBOARD
, {{0}}, {'D', 0}, FALSE
, FALSE
},
1763 { INPUT_KEYBOARD
, {{0}}, {VK_LMENU
, 'M', 0}, TRUE
, FALSE
},
1764 { INPUT_KEYBOARD
, {{0}}, {'E', 0}, FALSE
, FALSE
},
1765 { INPUT_KEYBOARD
, {{0}}, {VK_LMENU
, 'M', 'P', 0}, TRUE
, FALSE
},
1766 { INPUT_KEYBOARD
, {{0}}, {'D', 0}, FALSE
, FALSE
},
1767 { INPUT_KEYBOARD
, {{0}}, {VK_LMENU
, 'M', 'P', 0}, TRUE
, FALSE
},
1768 { INPUT_KEYBOARD
, {{0}}, {'E', 0}, FALSE
, FALSE
},
1770 { INPUT_MOUSE
, {{1, 2}, {0}}, {0}, TRUE
, TRUE
}, /* test 18 */
1771 { INPUT_MOUSE
, {{1, 1}, {0}}, {0}, FALSE
, FALSE
},
1772 { INPUT_MOUSE
, {{1, 0}, {0}}, {0}, TRUE
, TRUE
},
1773 { INPUT_MOUSE
, {{1, 1}, {0}}, {0}, FALSE
, FALSE
},
1774 { INPUT_MOUSE
, {{1, 0}, {2, 2}, {0}}, {0}, TRUE
, TRUE
},
1775 { INPUT_MOUSE
, {{2, 1}, {0}}, {0}, FALSE
, FALSE
},
1776 { INPUT_MOUSE
, {{1, 0}, {2, 0}, {0}}, {0}, TRUE
, TRUE
},
1777 { INPUT_MOUSE
, {{3, 0}, {0}}, {0}, FALSE
, FALSE
},
1778 { INPUT_MOUSE
, {{1, 0}, {2, 0}, {0}}, {0}, TRUE
, TRUE
},
1779 { INPUT_MOUSE
, {{3, 1}, {0}}, {0}, TRUE
, TRUE
},
1780 { INPUT_MOUSE
, {{1, 1}, {0}}, {0}, FALSE
, FALSE
},
1784 static void send_key(WORD wVk
)
1787 memset(i
, 0, sizeof(i
));
1788 i
[0].type
= i
[1].type
= INPUT_KEYBOARD
;
1789 i
[0].u
.ki
.wVk
= i
[1].u
.ki
.wVk
= wVk
;
1790 i
[1].u
.ki
.dwFlags
= KEYEVENTF_KEYUP
;
1791 pSendInput(2, (INPUT
*) i
, sizeof(INPUT
));
1794 static void click_menu(HANDLE hWnd
, struct menu_item_pair_s
*mi
)
1796 HMENU hMenu
= hMenus
[mi
->uMenu
];
1800 int screen_w
= GetSystemMetrics(SM_CXSCREEN
);
1801 int screen_h
= GetSystemMetrics(SM_CYSCREEN
);
1802 BOOL ret
= GetMenuItemRect(mi
->uMenu
> 2 ? NULL
: hWnd
, hMenu
, mi
->uItem
, &r
);
1805 memset(i
, 0, sizeof(i
));
1806 i
[0].type
= i
[1].type
= i
[2].type
= INPUT_MOUSE
;
1807 i
[0].u
.mi
.dx
= i
[1].u
.mi
.dx
= i
[2].u
.mi
.dx
1808 = ((r
.left
+ 5) * 65535) / screen_w
;
1809 i
[0].u
.mi
.dy
= i
[1].u
.mi
.dy
= i
[2].u
.mi
.dy
1810 = ((r
.top
+ 5) * 65535) / screen_h
;
1811 i
[0].u
.mi
.dwFlags
= i
[1].u
.mi
.dwFlags
= i
[2].u
.mi
.dwFlags
1812 = MOUSEEVENTF_ABSOLUTE
;
1813 i
[0].u
.mi
.dwFlags
|= MOUSEEVENTF_MOVE
;
1814 i
[1].u
.mi
.dwFlags
|= MOUSEEVENTF_LEFTDOWN
;
1815 i
[2].u
.mi
.dwFlags
|= MOUSEEVENTF_LEFTUP
;
1816 pSendInput(3, (INPUT
*) i
, sizeof(INPUT
));
1818 /* hack to prevent mouse message buildup in Wine */
1819 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
1822 static DWORD WINAPI
test_menu_input_thread(LPVOID lpParameter
)
1825 HANDLE hWnd
= lpParameter
;
1828 /* mixed keyboard/mouse test */
1829 for (i
= 0; menu_tests
[i
].type
!= -1; i
++)
1833 if (menu_tests
[i
].type
== INPUT_KEYBOARD
)
1834 for (j
= 0; menu_tests
[i
].wVk
[j
] != 0; j
++)
1835 send_key(menu_tests
[i
].wVk
[j
]);
1837 for (j
= 0; menu_tests
[i
].menu_item_pairs
[j
].uMenu
!= 0; j
++)
1838 click_menu(hWnd
, &menu_tests
[i
].menu_item_pairs
[j
]);
1840 while (menu_tests
[i
].bMenuVisible
!= bMenuVisible
)
1848 if (menu_tests
[i
]._todo_wine
)
1851 ok(menu_tests
[i
].bMenuVisible
== bMenuVisible
, "test %d\n", i
);
1855 ok(menu_tests
[i
].bMenuVisible
== bMenuVisible
, "test %d\n", i
);
1860 static LRESULT CALLBACK
WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
,
1864 case WM_ENTERMENULOOP
:
1865 bMenuVisible
= TRUE
;
1867 case WM_EXITMENULOOP
:
1868 bMenuVisible
= FALSE
;
1871 return( DefWindowProcA( hWnd
, msg
, wParam
, lParam
) );
1876 static void test_menu_input(void) {
1879 HINSTANCE hInstance
= GetModuleHandleA( NULL
);
1880 HANDLE hThread
, hWnd
;
1883 wclass
.lpszClassName
= "MenuTestClass";
1884 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
1885 wclass
.lpfnWndProc
= WndProc
;
1886 wclass
.hInstance
= hInstance
;
1887 wclass
.hIcon
= LoadIconA( 0, IDI_APPLICATION
);
1888 wclass
.hCursor
= LoadCursorA( NULL
, IDC_ARROW
);
1889 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
1890 wclass
.lpszMenuName
= 0;
1891 wclass
.cbClsExtra
= 0;
1892 wclass
.cbWndExtra
= 0;
1893 assert (RegisterClassA( &wclass
));
1894 assert (hWnd
= CreateWindowA( wclass
.lpszClassName
, "MenuTest",
1895 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0,
1896 400, 200, NULL
, NULL
, hInstance
, NULL
) );
1899 hMenus
[3] = CreatePopupMenu();
1900 AppendMenu(hMenus
[3], MF_STRING
, 0, "&Enabled");
1901 AppendMenu(hMenus
[3], MF_STRING
|MF_DISABLED
, 0, "&Disabled");
1903 hMenus
[2] = CreatePopupMenu();
1904 AppendMenu(hMenus
[2], MF_STRING
|MF_POPUP
, (UINT_PTR
) hMenus
[3], "&Popup");
1905 AppendMenu(hMenus
[2], MF_STRING
, 0, "&Enabled");
1906 AppendMenu(hMenus
[2], MF_STRING
|MF_DISABLED
, 0, "&Disabled");
1908 hMenus
[1] = CreateMenu();
1909 AppendMenu(hMenus
[1], MF_STRING
|MF_POPUP
, (UINT_PTR
) hMenus
[2], "&Menu");
1910 AppendMenu(hMenus
[1], MF_STRING
, 0, "&Enabled");
1911 AppendMenu(hMenus
[1], MF_STRING
|MF_DISABLED
, 0, "&Disabled");
1913 SetMenu(hWnd
, hMenus
[1]);
1914 ShowWindow(hWnd
, SW_SHOW
);
1917 hThread
= CreateThread(NULL
, 0, test_menu_input_thread
, hWnd
, 0, &tid
);
1920 if (WAIT_TIMEOUT
!= WaitForSingleObject(hThread
, 50))
1922 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
1924 DestroyWindow(hWnd
);
1927 static void test_menu_flags( void )
1929 HMENU hMenu
, hPopupMenu
;
1931 hMenu
= CreateMenu();
1932 hPopupMenu
= CreatePopupMenu();
1934 AppendMenu(hMenu
, MF_POPUP
| MF_STRING
, (UINT_PTR
)hPopupMenu
, "Popup");
1936 AppendMenu(hPopupMenu
, MF_STRING
| MF_HILITE
| MF_DEFAULT
, 101, "Item 1");
1937 InsertMenu(hPopupMenu
, 1, MF_BYPOSITION
| MF_STRING
| MF_HILITE
| MF_DEFAULT
, 102, "Item 2");
1938 AppendMenu(hPopupMenu
, MF_STRING
, 103, "Item 3");
1939 ModifyMenu(hPopupMenu
, 2, MF_BYPOSITION
| MF_STRING
| MF_HILITE
| MF_DEFAULT
, 103, "Item 3");
1941 ok(GetMenuState(hPopupMenu
, 0, MF_BYPOSITION
) & MF_HILITE
,
1942 "AppendMenu should accept MF_HILITE\n");
1943 ok(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
,
1944 "InsertMenu should accept MF_HILITE\n");
1945 ok(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_HILITE
,
1946 "ModifyMenu should accept MF_HILITE\n");
1948 ok(!(GetMenuState(hPopupMenu
, 0, MF_BYPOSITION
) & MF_DEFAULT
),
1949 "AppendMenu must not accept MF_DEFAULT\n");
1950 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_DEFAULT
),
1951 "InsertMenu must not accept MF_DEFAULT\n");
1952 ok(!(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_DEFAULT
),
1953 "ModifyMenu must not accept MF_DEFAULT\n");
1958 static void test_menu_hilitemenuitem( void )
1960 HMENU hMenu
, hPopupMenu
;
1964 wclass
.lpszClassName
= "HiliteMenuTestClass";
1965 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
1966 wclass
.lpfnWndProc
= WndProc
;
1967 wclass
.hInstance
= GetModuleHandleA( NULL
);
1968 wclass
.hIcon
= LoadIconA( 0, IDI_APPLICATION
);
1969 wclass
.hCursor
= LoadCursorA( NULL
, IDC_ARROW
);
1970 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
1971 wclass
.lpszMenuName
= 0;
1972 wclass
.cbClsExtra
= 0;
1973 wclass
.cbWndExtra
= 0;
1974 assert (RegisterClassA( &wclass
));
1975 assert (hWnd
= CreateWindowA( wclass
.lpszClassName
, "HiliteMenuTest",
1976 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0,
1977 400, 200, NULL
, NULL
, wclass
.hInstance
, NULL
) );
1979 hMenu
= CreateMenu();
1980 hPopupMenu
= CreatePopupMenu();
1982 AppendMenu(hMenu
, MF_POPUP
| MF_STRING
, (UINT_PTR
)hPopupMenu
, "Popup");
1984 AppendMenu(hPopupMenu
, MF_STRING
, 101, "Item 1");
1985 AppendMenu(hPopupMenu
, MF_STRING
, 102, "Item 2");
1986 AppendMenu(hPopupMenu
, MF_STRING
, 103, "Item 3");
1988 SetMenu(hWnd
, hMenu
);
1990 /* test invalid arguments */
1992 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
1993 "HiliteMenuItem: Item 2 is hilited\n");
1995 SetLastError(0xdeadbeef);
1998 ok(!HiliteMenuItem(NULL
, hPopupMenu
, 1, MF_HILITE
| MF_BYPOSITION
),
1999 "HiliteMenuItem: call should have failed.\n");
2001 ok(GetLastError() == 0xdeadbeef || /* 9x */
2002 GetLastError() == ERROR_INVALID_WINDOW_HANDLE
/* NT */,
2003 "HiliteMenuItem: expected error ERROR_INVALID_WINDOW_HANDLE, got: %d\n", GetLastError());
2005 SetLastError(0xdeadbeef);
2006 ok(!HiliteMenuItem(hWnd
, NULL
, 1, MF_HILITE
| MF_BYPOSITION
),
2007 "HiliteMenuItem: call should have failed.\n");
2008 ok(GetLastError() == 0xdeadbeef || /* 9x */
2009 GetLastError() == ERROR_INVALID_MENU_HANDLE
/* NT */,
2010 "HiliteMenuItem: expected error ERROR_INVALID_MENU_HANDLE, got: %d\n", GetLastError());
2012 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2013 "HiliteMenuItem: Item 2 is hilited\n");
2015 /* either MF_HILITE or MF_UNHILITE *and* MF_BYCOMMAND or MF_BYPOSITION need to be set */
2017 SetLastError(0xdeadbeef);
2018 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_BYPOSITION
),
2019 "HiliteMenuItem: call should have succeeded.\n");
2020 ok(GetLastError() == 0xdeadbeef,
2021 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2023 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2024 "HiliteMenuItem: Item 2 is hilited\n");
2026 SetLastError(0xdeadbeef);
2029 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_HILITE
),
2030 "HiliteMenuItem: call should have succeeded.\n");
2032 ok(GetLastError() == 0xdeadbeef,
2033 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2035 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2036 "HiliteMenuItem: Item 2 is hilited\n");
2038 /* hilite a menu item (by position) */
2040 SetLastError(0xdeadbeef);
2041 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_HILITE
| MF_BYPOSITION
),
2042 "HiliteMenuItem: call should not have failed.\n");
2043 ok(GetLastError() == 0xdeadbeef,
2044 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2048 ok(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
,
2049 "HiliteMenuItem: Item 2 is not hilited\n");
2052 /* unhilite a menu item (by position) */
2054 SetLastError(0xdeadbeef);
2055 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_UNHILITE
| MF_BYPOSITION
),
2056 "HiliteMenuItem: call should not have failed.\n");
2057 ok(GetLastError() == 0xdeadbeef,
2058 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2060 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2061 "HiliteMenuItem: Item 2 is hilited\n");
2063 /* hilite a menu item (by command) */
2065 SetLastError(0xdeadbeef);
2066 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 103, MF_HILITE
| MF_BYCOMMAND
),
2067 "HiliteMenuItem: call should not have failed.\n");
2068 ok(GetLastError() == 0xdeadbeef,
2069 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2073 ok(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_HILITE
,
2074 "HiliteMenuItem: Item 3 is not hilited\n");
2077 /* unhilite a menu item (by command) */
2079 SetLastError(0xdeadbeef);
2080 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 103, MF_UNHILITE
| MF_BYCOMMAND
),
2081 "HiliteMenuItem: call should not have failed.\n");
2082 ok(GetLastError() == 0xdeadbeef,
2083 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2085 ok(!(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_HILITE
),
2086 "HiliteMenuItem: Item 3 is hilited\n");
2088 DestroyWindow(hWnd
);
2091 static void check_menu_items(HMENU hmenu
, UINT checked_cmd
, UINT checked_type
,
2096 count
= GetMenuItemCount(hmenu
);
2097 ok (count
!= -1, "GetMenuItemCount returned -1\n");
2099 for (i
= 0; i
< count
; i
++)
2104 memset(&mii
, 0, sizeof(mii
));
2105 mii
.cbSize
= sizeof(mii
);
2106 mii
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_ID
| MIIM_SUBMENU
;
2107 ret
= GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
);
2108 ok(ret
, "GetMenuItemInfo(%u) failed\n", i
);
2110 trace("item #%u: fType %04x, fState %04x, wID %u, hSubMenu %p\n",
2111 i
, mii
.fType
, mii
.fState
, mii
.wID
, mii
.hSubMenu
);
2115 ok(mii
.wID
== (UINT_PTR
)mii
.hSubMenu
, "id %u: wID should be equal to hSubMenu\n", checked_cmd
);
2116 check_menu_items(mii
.hSubMenu
, checked_cmd
, checked_type
, checked_state
);
2120 if (mii
.wID
== checked_cmd
)
2122 ok(mii
.fType
== checked_type
, "id %u: expected fType %04x, got %04x\n", checked_cmd
, checked_type
, mii
.fType
);
2123 ok(mii
.fState
== checked_state
, "id %u: expected fState %04x, got %04x\n", checked_cmd
, checked_state
, mii
.fState
);
2124 ok(mii
.wID
!= 0, "id %u: not expected wID 0\n", checked_cmd
);
2128 ok(mii
.fType
!= MFT_RADIOCHECK
, "id %u: not expected fType MFT_RADIOCHECK on cmd %u\n", checked_cmd
, mii
.wID
);
2130 if (mii
.fType
== MFT_SEPARATOR
)
2132 ok(mii
.fState
== MFS_GRAYED
, "id %u: expected fState MFS_GRAYED, got %04x\n", checked_cmd
, mii
.fState
);
2133 ok(mii
.wID
== 0, "id %u: expected wID 0, got %u\n", checked_cmd
, mii
.wID
);
2137 ok(mii
.fState
== 0, "id %u: expected fState 0, got %04x\n", checked_cmd
, mii
.fState
);
2138 ok(mii
.wID
!= 0, "id %u: not expected wID 0\n", checked_cmd
);
2145 static void clear_ftype_and_state(HMENU hmenu
, UINT id
, UINT flags
)
2150 memset(&mii
, 0, sizeof(mii
));
2151 mii
.cbSize
= sizeof(mii
);
2152 mii
.fMask
= MIIM_FTYPE
| MIIM_STATE
;
2153 ret
= SetMenuItemInfo(hmenu
, id
, (flags
& MF_BYPOSITION
) != 0, &mii
);
2154 ok(ret
, "SetMenuItemInfo(%u) failed\n", id
);
2157 static void test_CheckMenuRadioItem(void)
2162 hmenu
= LoadMenu(GetModuleHandle(0), MAKEINTRESOURCE(1));
2165 check_menu_items(hmenu
, -1, 0, 0);
2167 ret
= CheckMenuRadioItem(hmenu
, 100, 100, 100, MF_BYCOMMAND
);
2168 ok(ret
, "CheckMenuRadioItem failed\n");
2169 check_menu_items(hmenu
, 100, MFT_RADIOCHECK
, MFS_CHECKED
);
2171 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2172 ret
= CheckMenuRadioItem(hmenu
, 100, 100, -1, MF_BYCOMMAND
);
2173 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2174 check_menu_items(hmenu
, 100, MFT_RADIOCHECK
, 0);
2177 clear_ftype_and_state(hmenu
, 100, MF_BYCOMMAND
);
2178 check_menu_items(hmenu
, -1, 0, 0);
2180 /* first and checked items are on different menus */
2181 ret
= CheckMenuRadioItem(hmenu
, 0, 300, 202, MF_BYCOMMAND
);
2182 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2183 check_menu_items(hmenu
, -1, 0, 0);
2185 ret
= CheckMenuRadioItem(hmenu
, 200, 300, 202, MF_BYCOMMAND
);
2186 ok(ret
, "CheckMenuRadioItem failed\n");
2187 check_menu_items(hmenu
, 202, MFT_RADIOCHECK
, MFS_CHECKED
);
2189 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2190 ret
= CheckMenuRadioItem(hmenu
, 202, 202, -1, MF_BYCOMMAND
);
2191 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2192 check_menu_items(hmenu
, 202, MFT_RADIOCHECK
, 0);
2195 clear_ftype_and_state(hmenu
, 202, MF_BYCOMMAND
);
2196 check_menu_items(hmenu
, -1, 0, 0);
2198 /* just for fun, try to check separator */
2199 ret
= CheckMenuRadioItem(hmenu
, 0, 300, 0, MF_BYCOMMAND
);
2200 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2201 check_menu_items(hmenu
, -1, 0, 0);
2204 static void test_menu_resource_layout(void)
2208 MENUITEMTEMPLATEHEADER mith
;
2212 { 0, 0 }, /* versionNumber, offset */
2214 /* mtOption, mtID, mtString[] '\0' terminated */
2215 MF_STRING
, 1, 'F', 0,
2218 /* MF_SEPARATOR, 4, 'S', 0, FIXME: Wine ignores 'S' */
2219 MF_STRING
|MF_GRAYED
|MF_END
, 5, 'E', 0
2224 UINT type
, state
, id
;
2228 { MF_STRING
, MF_ENABLED
, 1, "F" },
2229 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 2, "" },
2230 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 3, "" },
2231 /*{ MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 4, "S" }, FIXME: Wine ignores 'S'*/
2232 { MF_STRING
, MF_GRAYED
, 5, "E" },
2233 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 6, "" },
2234 { MF_STRING
, MF_ENABLED
, 7, "" },
2235 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 8, "" }
2241 hmenu
= LoadMenuIndirect(&menu_template
);
2242 ok(hmenu
!= 0, "LoadMenuIndirect error %u\n", GetLastError());
2244 ret
= AppendMenu(hmenu
, MF_STRING
, 6, NULL
);
2245 ok(ret
, "AppendMenu failed\n");
2246 ret
= AppendMenu(hmenu
, MF_STRING
, 7, "\0");
2247 ok(ret
, "AppendMenu failed\n");
2248 ret
= AppendMenu(hmenu
, MF_SEPARATOR
, 8, "separator");
2249 ok(ret
, "AppendMenu failed\n");
2251 count
= GetMenuItemCount(hmenu
);
2252 ok(count
== sizeof(menu_data
)/sizeof(menu_data
[0]),
2253 "expected %u menu items, got %u\n",
2254 (UINT
)(sizeof(menu_data
)/sizeof(menu_data
[0])), count
);
2256 for (i
= 0; i
< count
; i
++)
2261 memset(&mii
, 0, sizeof(mii
));
2262 mii
.cbSize
= sizeof(mii
);
2263 mii
.dwTypeData
= buf
;
2264 mii
.cch
= sizeof(buf
);
2265 mii
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_ID
| MIIM_STRING
;
2266 ret
= GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
);
2267 ok(ret
, "GetMenuItemInfo(%u) failed\n", i
);
2269 trace("item #%u: fType %04x, fState %04x, wID %u, dwTypeData %s\n",
2270 i
, mii
.fType
, mii
.fState
, mii
.wID
, (LPCSTR
)mii
.dwTypeData
);
2272 ok(mii
.fType
== menu_data
[i
].type
,
2273 "%u: expected fType %04x, got %04x\n", i
, menu_data
[i
].type
, mii
.fType
);
2274 ok(mii
.fState
== menu_data
[i
].state
,
2275 "%u: expected fState %04x, got %04x\n", i
, menu_data
[i
].state
, mii
.fState
);
2276 ok(mii
.wID
== menu_data
[i
].id
,
2277 "%u: expected wID %04x, got %04x\n", i
, menu_data
[i
].id
, mii
.wID
);
2278 ok(mii
.cch
== strlen(menu_data
[i
].str
),
2279 "%u: expected cch %u, got %u\n", i
, (UINT
)strlen(menu_data
[i
].str
), mii
.cch
);
2280 ok(!strcmp(mii
.dwTypeData
, menu_data
[i
].str
),
2281 "%u: expected dwTypeData %s, got %s\n", i
, menu_data
[i
].str
, (LPCSTR
)mii
.dwTypeData
);
2293 static HMENU
create_menu_from_data(const struct menu_data
*item
, INT item_count
)
2299 hmenu
= CreateMenu();
2302 for (i
= 0; i
< item_count
; i
++)
2304 SetLastError(0xdeadbeef);
2305 ret
= AppendMenu(hmenu
, item
[i
].type
, item
[i
].id
, item
[i
].str
);
2306 ok(ret
, "%d: AppendMenu(%04x, %04x, %p) error %u\n",
2307 i
, item
[i
].type
, item
[i
].id
, item
[i
].str
, GetLastError());
2312 static void compare_menu_data(HMENU hmenu
, const struct menu_data
*item
, INT item_count
)
2317 count
= GetMenuItemCount(hmenu
);
2318 ok(count
== item_count
, "expected %d, got %d menu items\n", count
, item_count
);
2320 for (i
= 0; i
< count
; i
++)
2325 memset(&mii
, 0, sizeof(mii
));
2326 mii
.cbSize
= sizeof(mii
);
2327 mii
.dwTypeData
= buf
;
2328 mii
.cch
= sizeof(buf
);
2329 mii
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
| MIIM_BITMAP
;
2330 ret
= GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
);
2331 ok(ret
, "GetMenuItemInfo(%u) failed\n", i
);
2333 trace("item #%u: fType %04x, fState %04x, wID %04x, hbmp %p\n",
2334 i
, mii
.fType
, mii
.fState
, mii
.wID
, mii
.hbmpItem
);
2336 ok(mii
.fType
== item
[i
].type
,
2337 "%u: expected fType %04x, got %04x\n", i
, item
[i
].type
, mii
.fType
);
2338 ok(mii
.wID
== item
[i
].id
,
2339 "%u: expected wID %04x, got %04x\n", i
, item
[i
].id
, mii
.wID
);
2340 if (item
[i
].type
& (MF_BITMAP
| MF_SEPARATOR
))
2342 /* For some reason Windows sets high word to not 0 for
2345 ok(LOWORD(mii
.hbmpItem
) == LOWORD(item
[i
].str
),
2346 "%u: expected hbmpItem %p, got %p\n", i
, item
[i
].str
, mii
.hbmpItem
);
2350 ok(mii
.cch
== strlen(item
[i
].str
),
2351 "%u: expected cch %u, got %u\n", i
, (UINT
)strlen(item
[i
].str
), mii
.cch
);
2352 ok(!strcmp(mii
.dwTypeData
, item
[i
].str
),
2353 "%u: expected dwTypeData %s, got %s\n", i
, item
[i
].str
, (LPCSTR
)mii
.dwTypeData
);
2358 static void test_InsertMenu(void)
2360 /* Note: XP treats only bitmap handles 1 - 6 as "magic" ones
2361 * regardless of their id.
2363 static const struct menu_data in1
[] =
2365 { MF_STRING
, 1, "File" },
2366 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(1) },
2367 { MF_STRING
|MF_HELP
, 2, "Help" }
2369 static const struct menu_data out1
[] =
2371 { MF_STRING
, 1, "File" },
2372 { MF_STRING
|MF_HELP
, 2, "Help" },
2373 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(1) }
2375 static const struct menu_data in2
[] =
2377 { MF_STRING
, 1, "File" },
2378 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(100) },
2379 { MF_STRING
|MF_HELP
, 2, "Help" }
2381 static const struct menu_data out2
[] =
2383 { MF_STRING
, 1, "File" },
2384 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(100) },
2385 { MF_STRING
|MF_HELP
, 2, "Help" }
2387 static const struct menu_data in3
[] =
2389 { MF_STRING
, 1, "File" },
2390 { MF_SEPARATOR
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(1) },
2391 { MF_STRING
|MF_HELP
, 2, "Help" }
2393 static const struct menu_data out3
[] =
2395 { MF_STRING
, 1, "File" },
2396 { MF_SEPARATOR
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(0) },
2397 { MF_STRING
|MF_HELP
, 2, "Help" },
2399 static const struct menu_data in4
[] =
2401 { MF_STRING
, 1, "File" },
2402 { MF_BITMAP
|MF_HELP
, 1, MAKEINTRESOURCE(1) },
2403 { MF_STRING
|MF_HELP
, 2, "Help" }
2405 static const struct menu_data out4
[] =
2407 { MF_STRING
, 1, "File" },
2408 { MF_STRING
|MF_HELP
, 2, "Help" },
2409 { MF_BITMAP
|MF_HELP
, 1, MAKEINTRESOURCE(1) }
2413 #define create_menu(a) create_menu_from_data((a), sizeof(a)/sizeof((a)[0]))
2414 #define compare_menu(h, a) compare_menu_data((h), (a), sizeof(a)/sizeof((a)[0]))
2416 hmenu
= create_menu(in1
);
2417 compare_menu(hmenu
, out1
);
2420 hmenu
= create_menu(in2
);
2421 compare_menu(hmenu
, out2
);
2424 hmenu
= create_menu(in3
);
2425 compare_menu(hmenu
, out3
);
2428 hmenu
= create_menu(in4
);
2429 compare_menu(hmenu
, out4
);
2436 static void test_menu_getmenuinfo(void)
2444 hmenu
= CreateMenu();
2446 /* test some parameter errors */
2447 SetLastError(0xdeadbeef);
2448 ret
= pGetMenuInfo( hmenu
, NULL
);
2449 gle
= GetLastError();
2450 ok( !ret
, "GetMenuInfo() should have failed\n");
2451 ok( gle
== ERROR_INVALID_PARAMETER
||
2452 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2453 "GetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2454 SetLastError(0xdeadbeef);
2456 ret
= pGetMenuInfo( hmenu
, &mi
);
2457 gle
= GetLastError();
2458 ok( !ret
, "GetMenuInfo() should have failed\n");
2459 ok( gle
== ERROR_INVALID_PARAMETER
||
2460 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2461 "GetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2462 SetLastError(0xdeadbeef);
2463 mi
.cbSize
= sizeof( MENUINFO
);
2464 ret
= pGetMenuInfo( hmenu
, &mi
);
2465 gle
= GetLastError();
2466 ok( ret
, "GetMenuInfo() should have succeeded\n");
2467 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2468 SetLastError(0xdeadbeef);
2470 ret
= pGetMenuInfo( NULL
, &mi
);
2471 gle
= GetLastError();
2472 ok( !ret
, "GetMenuInfo() should have failed\n");
2473 ok( gle
== ERROR_INVALID_PARAMETER
||
2474 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2475 "GetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2477 DestroyMenu( hmenu
);
2481 static void test_menu_setmenuinfo(void)
2483 HMENU hmenu
, hsubmenu
;
2485 MENUITEMINFOA mii
= {sizeof( MENUITEMINFOA
)};
2489 /* create a menu with a submenu */
2490 hmenu
= CreateMenu();
2491 hsubmenu
= CreateMenu();
2492 assert( hmenu
&& hsubmenu
);
2493 mii
.fMask
= MIIM_SUBMENU
;
2494 mii
.hSubMenu
= hsubmenu
;
2495 ret
= InsertMenuItem( hmenu
, 0, FALSE
, &mii
);
2496 ok( ret
, "InsertMenuItem failed with error %d\n", GetLastError());
2497 /* test some parameter errors */
2498 SetLastError(0xdeadbeef);
2499 ret
= pSetMenuInfo( hmenu
, NULL
);
2500 gle
= GetLastError();
2501 ok( !ret
, "SetMenuInfo() should have failed\n");
2502 ok( gle
== ERROR_INVALID_PARAMETER
||
2503 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2504 "SetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2505 SetLastError(0xdeadbeef);
2507 ret
= pSetMenuInfo( hmenu
, &mi
);
2508 gle
= GetLastError();
2509 ok( !ret
, "SetMenuInfo() should have failed\n");
2510 ok( gle
== ERROR_INVALID_PARAMETER
||
2511 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2512 "SetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2513 SetLastError(0xdeadbeef);
2514 mi
.cbSize
= sizeof( MENUINFO
);
2515 ret
= pSetMenuInfo( hmenu
, &mi
);
2516 gle
= GetLastError();
2517 ok( ret
, "SetMenuInfo() should have succeeded\n");
2518 ok( gle
== 0xdeadbeef, "SetMenuInfo() error got %u\n", gle
);
2519 SetLastError(0xdeadbeef);
2521 ret
= pSetMenuInfo( NULL
, &mi
);
2522 gle
= GetLastError();
2523 ok( !ret
, "SetMenuInfo() should have failed\n");
2524 ok( gle
== ERROR_INVALID_PARAMETER
||
2525 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2526 "SetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2527 /* functional tests */
2528 /* menu and submenu should have the CHECKORBMP style bit cleared */
2529 SetLastError(0xdeadbeef);
2530 mi
.cbSize
= sizeof( MENUINFO
);
2531 mi
.fMask
= MIM_STYLE
;
2532 ret
= pGetMenuInfo( hmenu
, &mi
);
2533 gle
= GetLastError();
2534 ok( ret
, "GetMenuInfo() should have succeeded\n");
2535 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2536 ok( !(mi
.dwStyle
& MNS_CHECKORBMP
), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2537 SetLastError(0xdeadbeef);
2538 mi
.cbSize
= sizeof( MENUINFO
);
2539 mi
.fMask
= MIM_STYLE
;
2540 ret
= pGetMenuInfo( hsubmenu
, &mi
);
2541 gle
= GetLastError();
2542 ok( ret
, "GetMenuInfo() should have succeeded\n");
2543 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2544 ok( !(mi
.dwStyle
& MNS_CHECKORBMP
), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2546 SetLastError(0xdeadbeef);
2547 mi
.cbSize
= sizeof( MENUINFO
);
2548 mi
.fMask
= MIM_STYLE
| MIM_APPLYTOSUBMENUS
;
2549 mi
.dwStyle
= MNS_CHECKORBMP
;
2550 ret
= pSetMenuInfo( hmenu
, &mi
);
2551 gle
= GetLastError();
2552 ok( ret
, "SetMenuInfo() should have succeeded\n");
2553 ok( gle
== 0xdeadbeef, "SetMenuInfo() error got %u\n", gle
);
2554 /* Now both menus should have the MNS_CHECKORBMP style bit set */
2555 SetLastError(0xdeadbeef);
2556 mi
.cbSize
= sizeof( MENUINFO
);
2557 mi
.fMask
= MIM_STYLE
;
2558 ret
= pGetMenuInfo( hmenu
, &mi
);
2559 gle
= GetLastError();
2560 ok( ret
, "GetMenuInfo() should have succeeded\n");
2561 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2562 ok( mi
.dwStyle
& MNS_CHECKORBMP
, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2563 SetLastError(0xdeadbeef);
2564 mi
.cbSize
= sizeof( MENUINFO
);
2565 mi
.fMask
= MIM_STYLE
;
2566 ret
= pGetMenuInfo( hsubmenu
, &mi
);
2567 gle
= GetLastError();
2568 ok( ret
, "GetMenuInfo() should have succeeded\n");
2569 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2570 ok( mi
.dwStyle
& MNS_CHECKORBMP
, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2571 /* now repeat that without the APPLYTOSUBMENUS flag and another style bit */
2572 SetLastError(0xdeadbeef);
2573 mi
.cbSize
= sizeof( MENUINFO
);
2574 mi
.fMask
= MIM_STYLE
;
2575 mi
.dwStyle
= MNS_NOCHECK
;
2576 ret
= pSetMenuInfo( hmenu
, &mi
);
2577 gle
= GetLastError();
2578 ok( ret
, "SetMenuInfo() should have succeeded\n");
2579 ok( gle
== 0xdeadbeef, "SetMenuInfo() error got %u\n", gle
);
2580 /* Now only the top menu should have the MNS_NOCHECK style bit set */
2581 SetLastError(0xdeadbeef);
2582 mi
.cbSize
= sizeof( MENUINFO
);
2583 mi
.fMask
= MIM_STYLE
;
2584 ret
= pGetMenuInfo( hmenu
, &mi
);
2585 gle
= GetLastError();
2586 ok( ret
, "GetMenuInfo() should have succeeded\n");
2587 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2588 ok( mi
.dwStyle
& MNS_NOCHECK
, "menustyle was expected to have the MNS_NOCHECK flag\n");
2589 SetLastError(0xdeadbeef);
2590 mi
.cbSize
= sizeof( MENUINFO
);
2591 mi
.fMask
= MIM_STYLE
;
2592 ret
= pGetMenuInfo( hsubmenu
, &mi
);
2593 gle
= GetLastError();
2594 ok( ret
, "GetMenuInfo() should have succeeded\n");
2595 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2596 ok( !(mi
.dwStyle
& MNS_NOCHECK
), "menustyle was not expected to have the MNS_NOCHECK flag\n");
2598 DestroyMenu( hsubmenu
);
2599 DestroyMenu( hmenu
);
2605 init_function_pointers();
2607 /* Wine defines MENUITEMINFO for W2K and above. NT4 and below can't
2610 if (correct_behavior())
2612 test_menu_add_string();
2613 test_menu_iteminfo();
2614 test_menu_search_bycommand();
2615 test_CheckMenuRadioItem();
2616 test_menu_resource_layout();
2620 register_menu_check_class();
2622 test_menu_locked_by_window();
2623 test_menu_ownerdraw();
2624 test_menu_bmp_and_string();
2625 /* test Get/SetMenuInfo if available */
2626 if( pGetMenuInfo
&& pSetMenuInfo
) {
2627 test_menu_getmenuinfo();
2628 test_menu_setmenuinfo();
2630 win_skip("Get/SetMenuInfo are not available\n");
2632 win_skip("SendInput is not available\n");
2637 test_menu_hilitemenuitem();