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 BOOL got_input
;
118 static HMENU hMenus
[4];
121 #define MOD_NRMENUS 8
123 /* menu texts with their sizes */
126 SIZE size
; /* size of text up to any \t */
127 SIZE sc_size
; /* size of the short-cut */
131 { "Shira&z\tAlt+S" },
136 static unsigned int MOD_maxid
;
137 static RECT MOD_rc
[MOD_NRMENUS
];
138 static int MOD_avec
, MOD_hic
;
139 static int MOD_odheight
;
140 static SIZE MODsizes
[MOD_NRMENUS
]= { {MOD_SIZE
, MOD_SIZE
},{MOD_SIZE
, MOD_SIZE
},
141 {MOD_SIZE
, MOD_SIZE
},{MOD_SIZE
, MOD_SIZE
}};
142 static int MOD_GotDrawItemMsg
= FALSE
;
143 /* wndproc used by test_menu_ownerdraw() */
144 static LRESULT WINAPI
menu_ownerdraw_wnd_proc(HWND hwnd
, UINT msg
,
145 WPARAM wparam
, LPARAM lparam
)
151 MEASUREITEMSTRUCT
* pmis
= (MEASUREITEMSTRUCT
*)lparam
;
153 trace("WM_MEASUREITEM received data %lx size %dx%d\n",
154 pmis
->itemData
, pmis
->itemWidth
, pmis
->itemHeight
);
155 MOD_odheight
= pmis
->itemHeight
;
156 pmis
->itemWidth
= MODsizes
[pmis
->itemData
].cx
;
157 pmis
->itemHeight
= MODsizes
[pmis
->itemData
].cy
;
162 DRAWITEMSTRUCT
* pdis
;
165 char chrs
[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
168 pdis
= (DRAWITEMSTRUCT
*) lparam
;
169 if( winetest_debug
) {
171 GetMenuItemRect( hwnd
, (HMENU
)pdis
->hwndItem
, pdis
->itemData
,&rc
);
172 trace("WM_DRAWITEM received hwnd %p hmenu %p itemdata %ld item %d rc %d,%d-%d,%d itemrc: %d,%d-%d,%d\n",
173 hwnd
, pdis
->hwndItem
, pdis
->itemData
, pdis
->itemID
,
174 pdis
->rcItem
.left
, pdis
->rcItem
.top
,
175 pdis
->rcItem
.right
,pdis
->rcItem
.bottom
,
176 rc
.left
,rc
.top
,rc
.right
,rc
.bottom
);
177 oldpen
=SelectObject( pdis
->hDC
, GetStockObject(
178 pdis
->itemState
& ODS_SELECTED
? WHITE_PEN
:BLACK_PEN
));
179 Rectangle( pdis
->hDC
, pdis
->rcItem
.left
,pdis
->rcItem
.top
,
180 pdis
->rcItem
.right
,pdis
->rcItem
.bottom
);
181 SelectObject( pdis
->hDC
, oldpen
);
183 /* calculate widths of some menu texts */
184 if( ! MOD_txtsizes
[0].size
.cx
)
185 for(i
= 0; MOD_txtsizes
[i
].text
; i
++) {
188 strcpy( buf
, MOD_txtsizes
[i
].text
);
189 if( ( p
= strchr( buf
, '\t'))) {
191 DrawText( pdis
->hDC
, p
+ 1, -1, &rc
,
192 DT_SINGLELINE
|DT_CALCRECT
);
193 MOD_txtsizes
[i
].sc_size
.cx
= rc
.right
- rc
.left
;
194 MOD_txtsizes
[i
].sc_size
.cy
= rc
.bottom
- rc
.top
;
196 DrawText( pdis
->hDC
, buf
, -1, &rc
,
197 DT_SINGLELINE
|DT_CALCRECT
);
198 MOD_txtsizes
[i
].size
.cx
= rc
.right
- rc
.left
;
199 MOD_txtsizes
[i
].size
.cy
= rc
.bottom
- rc
.top
;
202 if( pdis
->itemData
> MOD_maxid
) return TRUE
;
203 /* store the rectangl */
204 MOD_rc
[pdis
->itemData
] = pdis
->rcItem
;
205 /* calculate average character width */
206 GetTextExtentPoint( pdis
->hDC
, chrs
, 52, &sz
);
207 MOD_avec
= (sz
.cx
+ 26)/52;
208 GetTextMetrics( pdis
->hDC
, &tm
);
209 MOD_hic
= tm
.tmHeight
;
210 MOD_GotDrawItemMsg
= TRUE
;
215 ok( lparam
|| broken(!lparam
), /* win9x, nt4 */
216 "Menu window handle is NULL!\n");
217 PostMessage(hwnd
, WM_CANCELMODE
, 0, 0);
222 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
225 static void register_menu_check_class(void)
233 GetModuleHandle(NULL
),
235 LoadCursor(NULL
, IDC_ARROW
),
236 (HBRUSH
)(COLOR_BTNFACE
+1),
238 TEXT("WineMenuCheck"),
241 atomMenuCheckClass
= RegisterClass(&wc
);
244 /* demonstrates that windows locks the menu object so that it is still valid
245 * even after a client calls DestroyMenu on it */
246 static void test_menu_locked_by_window(void)
250 HWND hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
251 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
252 NULL
, NULL
, NULL
, NULL
);
253 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
254 hmenu
= CreateMenu();
255 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
256 ret
= InsertMenu(hmenu
, 0, MF_STRING
, 0, TEXT("&Test"));
257 ok(ret
, "InsertMenu failed with error %d\n", GetLastError());
258 ret
= SetMenu(hwnd
, hmenu
);
259 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
260 ret
= DestroyMenu(hmenu
);
261 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
263 ret
= DrawMenuBar(hwnd
);
265 ok(ret
, "DrawMenuBar failed with error %d\n", GetLastError());
267 ret
= IsMenu(GetMenu(hwnd
));
268 ok(!ret
|| broken(ret
) /* nt4 */, "Menu handle should have been destroyed\n");
270 SendMessage(hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, 0);
271 /* did we process the WM_INITMENU message? */
272 ret
= GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
274 ok(ret
, "WM_INITMENU should have been sent\n");
280 static void test_menu_ownerdraw(void)
286 HWND hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
,
287 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
288 NULL
, NULL
, NULL
, NULL
);
289 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
291 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_ownerdraw_wnd_proc
);
292 hmenu
= CreatePopupMenu();
293 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
294 if( !hmenu
) { DestroyWindow(hwnd
);return;}
296 for( j
=0;j
<2;j
++) /* create columns */
297 for(i
=0;i
<2;i
++) { /* create rows */
298 ret
= AppendMenu( hmenu
, MF_OWNERDRAW
|
299 (i
==0 ? MF_MENUBREAK
: 0), k
, MAKEINTRESOURCE(k
));
301 ok( ret
, "AppendMenu failed for %d\n", k
-1);
304 assert( k
<= sizeof(MOD_rc
)/sizeof(RECT
));
305 /* display the menu */
306 ret
= TrackPopupMenu( hmenu
, 0x100, 100,100, 0, hwnd
, NULL
);
308 /* columns have a 4 pixel gap between them */
309 ok( MOD_rc
[0].right
+ 4 == MOD_rc
[2].left
,
310 "item rectangles are not separated by 4 pixels space\n");
311 /* height should be what the MEASUREITEM message has returned */
312 ok( MOD_rc
[0].bottom
- MOD_rc
[0].top
== MOD_SIZE
,
313 "menu item has wrong height: %d should be %d\n",
314 MOD_rc
[0].bottom
- MOD_rc
[0].top
, MOD_SIZE
);
315 /* no gaps between the rows */
316 ok( MOD_rc
[0].bottom
- MOD_rc
[1].top
== 0,
317 "There should not be a space between the rows, gap is %d\n",
318 MOD_rc
[0].bottom
- MOD_rc
[1].top
);
319 /* test the correct value of the item height that was sent
320 * by the WM_MEASUREITEM message */
321 ok( MOD_odheight
== HIWORD( GetDialogBaseUnits()) || /* WinNT,2k,XP */
322 MOD_odheight
== MOD_hic
, /* Win95,98,ME */
323 "Wrong height field in MEASUREITEMSTRUCT, expected %d or %d actual %d\n",
324 HIWORD( GetDialogBaseUnits()), MOD_hic
, MOD_odheight
);
325 /* test what MF_MENUBREAK did at the first position. Also show
326 * that an MF_SEPARATOR is ignored in the height calculation. */
327 leftcol
= MOD_rc
[0].left
;
328 ModifyMenu( hmenu
, 0, MF_BYCOMMAND
| MF_OWNERDRAW
| MF_SEPARATOR
, 0, 0);
329 /* display the menu */
330 ret
= TrackPopupMenu( hmenu
, 0x100, 100,100, 0, hwnd
, NULL
);
331 /* left should be 4 pixels less now */
332 ok( leftcol
== MOD_rc
[0].left
+ 4,
333 "columns should be 4 pixels to the left (actual %d).\n",
334 leftcol
- MOD_rc
[0].left
);
336 ok( MOD_rc
[0].right
- MOD_rc
[0].left
== 2 * MOD_avec
+ MOD_SIZE
,
337 "width of owner drawn menu item is wrong. Got %d expected %d\n",
338 MOD_rc
[0].right
- MOD_rc
[0].left
, 2*MOD_avec
+ MOD_SIZE
);
340 ok( MOD_rc
[0].bottom
- MOD_rc
[0].top
== MOD_SIZE
,
341 "Height is incorrect. Got %d expected %d\n",
342 MOD_rc
[0].bottom
- MOD_rc
[0].top
, MOD_SIZE
);
344 /* test width/height of an ownerdraw menu bar as well */
345 ret
= DestroyMenu(hmenu
);
346 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
347 hmenu
= CreateMenu();
348 ok(hmenu
!= NULL
, "CreateMenu failed with error %d\n", GetLastError());
349 if( !hmenu
) { DestroyWindow(hwnd
);return;}
352 ret
= AppendMenu( hmenu
, MF_OWNERDRAW
, i
, 0);
353 ok( ret
, "AppendMenu failed for %d\n", i
);
355 ret
= SetMenu( hwnd
, hmenu
);
356 UpdateWindow( hwnd
); /* hack for wine to draw the window + menu */
357 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
359 ok( MOD_rc
[0].right
- MOD_rc
[0].left
== 2 * MOD_avec
+ MOD_SIZE
,
360 "width of owner drawn menu item is wrong. Got %d expected %d\n",
361 MOD_rc
[0].right
- MOD_rc
[0].left
, 2*MOD_avec
+ MOD_SIZE
);
363 ok( MOD_rc
[0].bottom
- MOD_rc
[0].top
== GetSystemMetrics( SM_CYMENU
) - 1,
364 "Height of owner drawn menu item is wrong. Got %d expected %d\n",
365 MOD_rc
[0].bottom
- MOD_rc
[0].top
, GetSystemMetrics( SM_CYMENU
) - 1);
368 ret
= DestroyMenu(hmenu
);
369 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
373 /* helper for test_menu_bmp_and_string() */
374 static void test_mbs_help( int ispop
, int hassub
, int mnuopt
,
375 HWND hwnd
, int arrowwidth
, int count
, HBITMAP hbmp
,
376 SIZE bmpsize
, LPCSTR text
, SIZE size
, SIZE sc_size
)
379 HMENU hmenu
, submenu
;
380 MENUITEMINFO mii
={ sizeof( MENUITEMINFO
)};
387 MOD_GotDrawItemMsg
= FALSE
;
388 mii
.fMask
= MIIM_FTYPE
| MIIM_DATA
| MIIM_STATE
;
390 /* check the menu item unless MNS_CHECKORBMP is set */
391 mii
.fState
= (mnuopt
!= 2 ? MFS_CHECKED
: MFS_UNCHECKED
);
393 MODsizes
[0] = bmpsize
;
397 mii
.fMask
|= MIIM_STRING
;
398 strcpy(text_copy
, text
);
399 mii
.dwTypeData
= text_copy
; /* structure member declared non-const */
400 if( ( p
= strchr( text
, '\t'))) {
401 hastab
= *(p
+ 1) ? 2 : 1;
404 /* tabs don't make sense in menubars */
405 if(hastab
&& !ispop
) return;
407 mii
.fMask
|= MIIM_BITMAP
;
410 submenu
= CreateMenu();
411 ok( submenu
!= 0, "CreateMenu failed with error %d\n", GetLastError());
413 hmenu
= CreatePopupMenu();
415 hmenu
= CreateMenu();
416 ok( hmenu
!= 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
418 mii
.fMask
|= MIIM_SUBMENU
;
419 mii
.hSubMenu
= submenu
;
422 mi
.cbSize
= sizeof(mi
);
423 mi
.fMask
= MIM_STYLE
;
424 pGetMenuInfo( hmenu
, &mi
);
425 mi
.dwStyle
|= mnuopt
== 1 ? MNS_NOCHECK
: MNS_CHECKORBMP
;
426 ret
= pSetMenuInfo( hmenu
, &mi
);
427 ok( ret
, "SetMenuInfo failed with error %d\n", GetLastError());
429 ret
= InsertMenuItem( hmenu
, 0, FALSE
, &mii
);
430 ok( ret
, "InsertMenuItem failed with error %d\n", GetLastError());
432 if( winetest_debug
) {
434 RECT rc
= {100, 50, 400, 70};
437 sprintf( buf
,"%d text \"%s\" mnuopt %d", count
, text
? text
: "(nil)", mnuopt
);
438 FillRect( hdc
, &rc
, (HBRUSH
) COLOR_WINDOW
);
439 TextOut( hdc
, 10, 50, buf
, strlen( buf
));
440 ReleaseDC( hwnd
, hdc
);
443 ret
= TrackPopupMenu( hmenu
, 0x100, 100,100, 0, hwnd
, NULL
);
445 ret
= SetMenu( hwnd
, hmenu
);
446 ok(ret
, "SetMenu failed with error %d\n", GetLastError());
449 ret
= GetMenuItemRect( hwnd
, hmenu
, 0, &rc
);
450 if (0) /* comment out menu size checks, behavior is different in almost every Windows version */
451 /* the tests should however succeed on win2000, XP and Wine (at least upto 1.1.15) */
452 /* with a variety of dpi's and desktop font sizes */
454 /* check menu width */
456 expect
= ( text
|| hbmp
?
457 4 + (mnuopt
!= 1 ? GetSystemMetrics(SM_CXMENUCHECK
) : 0)
459 arrowwidth
+ MOD_avec
+ (hbmp
?
460 ((int)hbmp
<0||(int)hbmp
>12 ? bmpsize
.cx
+ 2 : GetSystemMetrics( SM_CXMENUSIZE
) + 2)
462 (text
&& hastab
? /* TAB space */
463 MOD_avec
+ ( hastab
==2 ? sc_size
.cx
: 0) : 0) +
464 (text
? 2 + (text
[0] ? size
.cx
:0): 0) ;
466 expect
= !(text
|| hbmp
) ? 0 :
467 ( hbmp
? (text
? 2:0) + bmpsize
.cx
: 0 ) +
468 (text
? 2 * MOD_avec
+ (text
[0] ? size
.cx
:0): 0) ;
469 ok( rc
.right
- rc
.left
== expect
,
470 "menu width wrong, got %d expected %d\n", rc
.right
- rc
.left
, expect
);
471 failed
= failed
|| !(rc
.right
- rc
.left
== expect
);
472 /* check menu height */
474 expect
= max( ( !(text
|| hbmp
) ? GetSystemMetrics( SM_CYMENUSIZE
)/2 : 0),
475 max( (text
? max( 2 + size
.cy
, MOD_hic
+ 4) : 0),
477 ((int)hbmp
<0||(int)hbmp
>12 ?
479 : GetSystemMetrics( SM_CYMENUSIZE
) + 2)
482 expect
= ( !(text
|| hbmp
) ? GetSystemMetrics( SM_CYMENUSIZE
)/2 :
483 max( GetSystemMetrics( SM_CYMENU
) - 1, (hbmp
? bmpsize
.cy
: 0)));
484 ok( rc
.bottom
- rc
.top
== expect
,
485 "menu height wrong, got %d expected %d (%d)\n",
486 rc
.bottom
- rc
.top
, expect
, GetSystemMetrics( SM_CYMENU
));
487 failed
= failed
|| !(rc
.bottom
- rc
.top
== expect
);
488 if( hbmp
== HBMMENU_CALLBACK
&& MOD_GotDrawItemMsg
) {
489 /* check the position of the bitmap */
493 else if (mnuopt
== 0)
494 expect
= 4 + GetSystemMetrics(SM_CXMENUCHECK
);
495 else if (mnuopt
== 1)
497 else /* mnuopt == 2 */
499 ok( expect
== MOD_rc
[0].left
,
500 "bitmap left is %d expected %d\n", MOD_rc
[0].left
, expect
);
501 failed
= failed
|| !(expect
== MOD_rc
[0].left
);
503 expect
= (rc
.bottom
- rc
.top
- MOD_rc
[0].bottom
+ MOD_rc
[0].top
) / 2;
504 ok( expect
== MOD_rc
[0].top
,
505 "bitmap top is %d expected %d\n", MOD_rc
[0].top
, expect
);
506 failed
= failed
|| !(expect
== MOD_rc
[0].top
);
509 /* if there was a failure, report details */
511 trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
512 count
, (ispop
? "POPUP": "MENUBAR"),text
? text
: "(nil)", hbmp
, bmpsize
.cx
, bmpsize
.cy
,
513 size
.cx
, size
.cy
, sc_size
.cx
, mnuopt
, hastab
);
514 trace(" check %d,%d arrow %d avechar %d\n",
515 GetSystemMetrics(SM_CXMENUCHECK
),
516 GetSystemMetrics(SM_CYMENUCHECK
),arrowwidth
, MOD_avec
);
517 if( hbmp
== HBMMENU_CALLBACK
)
518 trace( " rc %d,%d-%d,%d bmp.rc %d,%d-%d,%d\n",
519 rc
.left
, rc
.top
, rc
.top
, rc
.bottom
, MOD_rc
[0].left
,
520 MOD_rc
[0].top
,MOD_rc
[0].right
, MOD_rc
[0].bottom
);
523 ret
= DestroyMenu(submenu
);
524 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
525 ret
= DestroyMenu(hmenu
);
526 ok(ret
, "DestroyMenu failed with error %d\n", GetLastError());
530 static void test_menu_bmp_and_string(void)
538 MENUINFO mi
= {sizeof(MENUINFO
)};
539 MENUITEMINFOA mii
= {sizeof(MENUITEMINFOA
)};
540 int count
, szidx
, txtidx
, bmpidx
, hassub
, mnuopt
, ispop
;
544 win_skip("GetMenuInfo is not available\n");
548 memset( bmfill
, 0xcc, sizeof( bmfill
));
549 hwnd
= CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass
), NULL
, WS_SYSMENU
|
550 WS_VISIBLE
, CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 200,
551 NULL
, NULL
, NULL
, NULL
);
552 hbm_arrow
=LoadBitmap( 0, (CHAR
*)OBM_MNARROW
);
553 GetObject( hbm_arrow
, sizeof(bm
), &bm
);
554 arrowwidth
= bm
.bmWidth
;
555 ok(hwnd
!= NULL
, "CreateWindowEx failed with error %d\n", GetLastError());
557 /* test system menu */
558 hsysmenu
= GetSystemMenu( hwnd
, FALSE
);
559 ok( hsysmenu
!= NULL
, "GetSystemMenu failed with error %d\n", GetLastError());
560 mi
.fMask
= MIM_STYLE
;
562 ok( pGetMenuInfo( hsysmenu
, &mi
), "GetMenuInfo failed gle=%d\n", GetLastError());
563 ok( MNS_CHECKORBMP
== mi
.dwStyle
, "System Menu Style is %08x, without the bit %08x\n",
564 mi
.dwStyle
, MNS_CHECKORBMP
);
565 mii
.fMask
= MIIM_BITMAP
;
567 ok( GetMenuItemInfoA( hsysmenu
, SC_CLOSE
, FALSE
, &mii
), "GetMenuItemInfoA failed gle=%d\n", GetLastError());
568 ok( HBMMENU_POPUP_CLOSE
== mii
.hbmpItem
, "Item info did not get the right hbitmap: got %p expected %p\n",
569 mii
.hbmpItem
, HBMMENU_POPUP_CLOSE
);
571 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)menu_ownerdraw_wnd_proc
);
574 trace(" check %d,%d arrow %d avechar %d\n",
575 GetSystemMetrics(SM_CXMENUCHECK
),
576 GetSystemMetrics(SM_CYMENUCHECK
),arrowwidth
, MOD_avec
);
579 for( ispop
=1; ispop
>= 0; ispop
--){
580 static SIZE bmsizes
[]= {
581 {10,10},{38,38},{1,30},{55,5}};
582 for( szidx
=0; szidx
< sizeof( bmsizes
) / sizeof( SIZE
); szidx
++) {
583 HBITMAP hbm
= CreateBitmap( bmsizes
[szidx
].cx
, bmsizes
[szidx
].cy
,1,1,bmfill
);
584 HBITMAP bitmaps
[] = { HBMMENU_CALLBACK
, hbm
, HBMMENU_POPUP_CLOSE
, NULL
};
585 ok( hbm
!= 0, "CreateBitmap failed err %d\n", GetLastError());
586 for( txtidx
= 0; txtidx
< sizeof(MOD_txtsizes
)/sizeof(MOD_txtsizes
[0]); txtidx
++) {
587 for( hassub
= 0; hassub
< 2 ; hassub
++) { /* add submenu item */
588 for( mnuopt
= 0; mnuopt
< 3 ; mnuopt
++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
589 for( bmpidx
= 0; bmpidx
<sizeof(bitmaps
)/sizeof(HBITMAP
); bmpidx
++) {
590 /* no need to test NULL bitmaps of several sizes */
591 if( !bitmaps
[bmpidx
] && szidx
> 0) continue;
592 /* the HBMMENU_POPUP not to test for menu bars */
594 bitmaps
[bmpidx
] >= HBMMENU_POPUP_CLOSE
&&
595 bitmaps
[bmpidx
] <= HBMMENU_POPUP_MINIMIZE
) continue;
596 if( !ispop
&& hassub
) continue;
597 test_mbs_help( ispop
, hassub
, mnuopt
,
598 hwnd
, arrowwidth
, ++count
,
601 MOD_txtsizes
[txtidx
].text
,
602 MOD_txtsizes
[txtidx
].size
,
603 MOD_txtsizes
[txtidx
].sc_size
);
615 static void test_menu_add_string( void )
626 WCHAR strbackW
[0x80];
627 static CHAR blah
[] = "blah";
628 static const WCHAR expectedString
[] = {'D','u','m','m','y',' ','s','t','r','i','n','g', 0};
630 hmenu
= CreateMenu();
632 memset( &info
, 0, sizeof info
);
633 info
.cbSize
= sizeof info
;
634 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_ID
;
635 info
.dwTypeData
= blah
;
640 InsertMenuItem(hmenu
, 0, TRUE
, &info
);
642 memset( &info
, 0, sizeof info
);
643 info
.cbSize
= sizeof info
;
644 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_DATA
| MIIM_ID
;
645 info
.dwTypeData
= string
;
646 info
.cch
= sizeof string
;
648 GetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
650 ok( !strcmp( string
, "blah" ), "menu item name differed\n");
652 /* Test combination of ownerdraw and strings with GetMenuItemString(A/W) */
653 strcpy(string
, "Dummy string");
654 memset(&info
, 0x00, sizeof(info
));
655 info
.cbSize
= sizeof(MENUITEMINFO
);
656 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
; /* Set OwnerDraw + typeData */
657 info
.fType
= MFT_OWNERDRAW
;
658 info
.dwTypeData
= string
;
659 rc
= InsertMenuItem( hmenu
, 0, TRUE
, &info
);
660 ok (rc
, "InsertMenuItem failed\n");
662 strcpy(string
,"Garbage");
663 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
664 ok (!strcmp( strback
, "Dummy string" ), "Menu text from Ansi version incorrect\n");
666 SetLastError(0xdeadbeef);
667 ret
= GetMenuStringW( hmenu
, 0, strbackW
, 99, MF_BYPOSITION
);
668 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
669 win_skip("GetMenuStringW is not implemented\n");
672 ok (ret
, "GetMenuStringW on ownerdraw entry failed\n");
673 ok (!lstrcmpW( strbackW
, expectedString
), "Menu text from Unicode version incorrect\n");
676 /* Just change ftype to string and see what text is stored */
677 memset(&info
, 0x00, sizeof(info
));
678 info
.cbSize
= sizeof(MENUITEMINFO
);
679 info
.fMask
= MIIM_FTYPE
; /* Set string type */
680 info
.fType
= MFT_STRING
;
681 info
.dwTypeData
= (char *)0xdeadbeef;
682 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
683 ok (rc
, "SetMenuItemInfo failed\n");
685 /* Did we keep the old dwTypeData? */
686 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
687 ok (!strcmp( strback
, "Dummy string" ), "Menu text from Ansi version incorrect\n");
689 /* Ensure change to bitmap type fails */
690 memset(&info
, 0x00, sizeof(info
));
691 info
.cbSize
= sizeof(MENUITEMINFO
);
692 info
.fMask
= MIIM_FTYPE
; /* Set as bitmap type */
693 info
.fType
= MFT_BITMAP
;
694 info
.dwTypeData
= (char *)0xdeadbee2;
695 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
696 ok (!rc
, "SetMenuItemInfo unexpectedly worked\n");
698 /* Just change ftype back and ensure data hasn't been freed */
699 info
.fType
= MFT_OWNERDRAW
; /* Set as ownerdraw type */
700 info
.dwTypeData
= (char *)0xdeadbee3;
701 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
702 ok (rc
, "SetMenuItemInfo failed\n");
704 /* Did we keep the old dwTypeData? */
705 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
706 ok (!strcmp( strback
, "Dummy string" ), "Menu text from Ansi version incorrect\n");
708 /* Just change string value (not type) */
709 memset(&info
, 0x00, sizeof(info
));
710 info
.cbSize
= sizeof(MENUITEMINFO
);
711 info
.fMask
= MIIM_STRING
; /* Set typeData */
712 strcpy(string2
, "string2");
713 info
.dwTypeData
= string2
;
714 rc
= SetMenuItemInfo( hmenu
, 0, TRUE
, &info
);
715 ok (rc
, "SetMenuItemInfo failed\n");
717 ok (GetMenuString( hmenu
, 0, strback
, 99, MF_BYPOSITION
), "GetMenuString on ownerdraw entry failed\n");
718 ok (!strcmp( strback
, "string2" ), "Menu text from Ansi version incorrect\n");
720 /* crashes with wine 0.9.5 */
721 memset(&info
, 0x00, sizeof(info
));
722 info
.cbSize
= sizeof(MENUITEMINFO
);
723 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
; /* Set OwnerDraw + typeData */
724 info
.fType
= MFT_OWNERDRAW
;
725 rc
= InsertMenuItem( hmenu
, 0, TRUE
, &info
);
726 ok (rc
, "InsertMenuItem failed\n");
727 ok (!GetMenuString( hmenu
, 0, NULL
, 0, MF_BYPOSITION
),
728 "GetMenuString on ownerdraw entry succeeded.\n");
729 SetLastError(0xdeadbeef);
730 ret
= GetMenuStringW( hmenu
, 0, NULL
, 0, MF_BYPOSITION
);
731 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
732 win_skip("GetMenuStringW is not implemented\n");
734 ok (!ret
, "GetMenuStringW on ownerdraw entry succeeded.\n");
736 DestroyMenu( hmenu
);
739 /* define building blocks for the menu item info tests */
740 static int strncmpW( const WCHAR
*str1
, const WCHAR
*str2
, int n
)
742 if (n
<= 0) return 0;
743 while ((--n
> 0) && *str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
744 return *str1
- *str2
;
747 static WCHAR
*strcpyW( WCHAR
*dst
, const WCHAR
*src
)
750 while ((*p
++ = *src
++));
754 static void insert_menu_item( int line
, HMENU hmenu
, BOOL ansi
, UINT mask
, UINT type
, UINT state
, UINT id
,
755 HMENU submenu
, HBITMAP checked
, HBITMAP unchecked
, ULONG_PTR data
,
756 void *type_data
, UINT len
, HBITMAP item
, BOOL expect
)
761 /* magic bitmap handle to test smaller cbSize */
762 if (item
== (HBITMAP
)(ULONG_PTR
)0xdeadbeef)
763 info
.cbSize
= FIELD_OFFSET(MENUITEMINFOA
,hbmpItem
);
765 info
.cbSize
= sizeof(info
);
770 info
.hSubMenu
= submenu
;
771 info
.hbmpChecked
= checked
;
772 info
.hbmpUnchecked
= unchecked
;
773 info
.dwItemData
= data
;
774 info
.dwTypeData
= type_data
;
776 info
.hbmpItem
= item
;
777 SetLastError( 0xdeadbeef );
778 if (ansi
) ret
= InsertMenuItemA( hmenu
, 0, TRUE
, &info
);
779 else ret
= InsertMenuItemW( hmenu
, 0, TRUE
, (MENUITEMINFOW
*)&info
);
780 if (!expect
) ok_(__FILE__
, line
)( !ret
, "InsertMenuItem should have failed.\n" );
781 else ok_(__FILE__
, line
)( ret
, "InsertMenuItem failed, err %u\n", GetLastError());
784 static void check_menu_item_info( int line
, HMENU hmenu
, BOOL ansi
, UINT mask
, UINT type
, UINT state
,
785 UINT id
, HMENU submenu
, HBITMAP checked
, HBITMAP unchecked
,
786 ULONG_PTR data
, void *type_data
, UINT in_len
, UINT out_len
,
787 HBITMAP item
, LPCSTR expname
, BOOL expect
, BOOL expstring
)
793 SetLastError( 0xdeadbeef );
794 memset( &info
, 0xcc, sizeof(info
) );
795 info
.cbSize
= sizeof(info
);
797 info
.dwTypeData
= type_data
;
800 ret
= ansi
? GetMenuItemInfoA( hmenu
, 0, TRUE
, &info
) :
801 GetMenuItemInfoW( hmenu
, 0, TRUE
, (MENUITEMINFOW
*)&info
);
804 ok_(__FILE__
, line
)( !ret
, "GetMenuItemInfo should have failed.\n" );
807 ok_(__FILE__
, line
)( ret
, "GetMenuItemInfo failed, err %u\n", GetLastError());
808 if (mask
& MIIM_TYPE
)
809 ok_(__FILE__
, line
)( info
.fType
== type
|| info
.fType
== LOWORD(type
),
810 "wrong type %x/%x\n", info
.fType
, type
);
811 if (mask
& MIIM_STATE
)
812 ok_(__FILE__
, line
)( info
.fState
== state
|| info
.fState
== LOWORD(state
),
813 "wrong state %x/%x\n", info
.fState
, state
);
815 ok_(__FILE__
, line
)( info
.wID
== id
|| info
.wID
== LOWORD(id
),
816 "wrong id %x/%x\n", info
.wID
, id
);
817 if (mask
& MIIM_SUBMENU
)
818 ok_(__FILE__
, line
)( info
.hSubMenu
== submenu
|| (ULONG_PTR
)info
.hSubMenu
== LOWORD(submenu
),
819 "wrong submenu %p/%p\n", info
.hSubMenu
, submenu
);
820 if (mask
& MIIM_CHECKMARKS
)
822 ok_(__FILE__
, line
)( info
.hbmpChecked
== checked
|| (ULONG_PTR
)info
.hbmpChecked
== LOWORD(checked
),
823 "wrong bmpchecked %p/%p\n", info
.hbmpChecked
, checked
);
824 ok_(__FILE__
, line
)( info
.hbmpUnchecked
== unchecked
|| (ULONG_PTR
)info
.hbmpUnchecked
== LOWORD(unchecked
),
825 "wrong bmpunchecked %p/%p\n", info
.hbmpUnchecked
, unchecked
);
827 if (mask
& MIIM_DATA
)
828 ok_(__FILE__
, line
)( info
.dwItemData
== data
|| info
.dwItemData
== LOWORD(data
),
829 "wrong item data %lx/%lx\n", info
.dwItemData
, data
);
830 if (mask
& MIIM_BITMAP
)
831 ok_(__FILE__
, line
)( info
.hbmpItem
== item
|| (ULONG_PTR
)info
.hbmpItem
== LOWORD(item
),
832 "wrong bmpitem %p/%p\n", info
.hbmpItem
, item
);
833 ok_(__FILE__
, line
)( info
.dwTypeData
== type_data
|| (ULONG_PTR
)info
.dwTypeData
== LOWORD(type_data
),
834 "wrong type data %p/%p\n", info
.dwTypeData
, type_data
);
835 ok_(__FILE__
, line
)( info
.cch
== out_len
, "wrong len %x/%x\n", info
.cch
, out_len
);
839 ok_(__FILE__
, line
)( !strncmp( expname
, info
.dwTypeData
, out_len
),
840 "menu item name differed from '%s' '%s'\n", expname
, info
.dwTypeData
);
842 ok_(__FILE__
, line
)( !strncmpW( (WCHAR
*)expname
, (WCHAR
*)info
.dwTypeData
, out_len
),
843 "menu item name wrong\n" );
845 SetLastError( 0xdeadbeef );
846 ret
= ansi
? GetMenuStringA( hmenu
, 0, (char *)buffer
, 80, MF_BYPOSITION
) :
847 GetMenuStringW( hmenu
, 0, buffer
, 80, MF_BYPOSITION
);
849 ok_(__FILE__
, line
)( ret
, "GetMenuString failed, err %u\n", GetLastError());
851 ok_(__FILE__
, line
)( !ret
, "GetMenuString should have failed\n" );
855 static void modify_menu( int line
, HMENU hmenu
, BOOL ansi
, UINT flags
, UINT_PTR id
, void *data
)
859 SetLastError( 0xdeadbeef );
860 if (ansi
) ret
= ModifyMenuA( hmenu
, 0, flags
, id
, data
);
861 else ret
= ModifyMenuW( hmenu
, 0, flags
, id
, data
);
862 ok_(__FILE__
,line
)( ret
, "ModifyMenuA failed, err %u\n", GetLastError());
865 static void set_menu_item_info( int line
, HMENU hmenu
, BOOL ansi
, UINT mask
, UINT type
, UINT state
,
866 UINT id
, HMENU submenu
, HBITMAP checked
, HBITMAP unchecked
, ULONG_PTR data
,
867 void *type_data
, UINT len
, HBITMAP item
)
873 /* magic bitmap handle to test smaller cbSize */
874 if (item
== (HBITMAP
)(ULONG_PTR
)0xdeadbeef)
875 info
.cbSize
= FIELD_OFFSET(MENUITEMINFOA
,hbmpItem
);
877 info
.cbSize
= sizeof(info
);
882 info
.hSubMenu
= submenu
;
883 info
.hbmpChecked
= checked
;
884 info
.hbmpUnchecked
= unchecked
;
885 info
.dwItemData
= data
;
886 info
.dwTypeData
= type_data
;
888 info
.hbmpItem
= item
;
889 SetLastError( 0xdeadbeef );
890 if (ansi
) ret
= SetMenuItemInfoA( hmenu
, 0, TRUE
, &info
);
891 else ret
= SetMenuItemInfoW( hmenu
, 0, TRUE
, (MENUITEMINFOW
*)&info
);
892 ok_(__FILE__
, line
)( ret
, "SetMenuItemInfo failed, err %u\n", GetLastError());
895 #define TMII_INSMI( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,eret1 )\
896 hmenu = CreateMenu();\
897 submenu = CreateMenu();\
898 if(ansi)strcpy( string, init );\
899 else strcpyW( string, init );\
900 insert_menu_item( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, eret1 )
902 /* GetMenuItemInfo + GetMenuString */
903 #define TMII_GMII( c2,l2,\
904 d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,\
905 expname, eret2, eret3)\
906 check_menu_item_info( __LINE__, hmenu, ansi, c2, d3, e3, f3, g3, h3, i3, j3, k3, l2, l3, m3, \
907 expname, eret2, eret3 )
910 RemoveMenu(hmenu, 0, TRUE );\
911 DestroyMenu( hmenu );\
912 DestroyMenu( submenu );
915 #define TMII_MODM( flags, id, data ) \
916 modify_menu( __LINE__, hmenu, ansi, flags, id, data )
918 /* SetMenuItemInfo */
919 #define TMII_SMII( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1 ) \
920 set_menu_item_info( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1 )
927 static void test_menu_iteminfo( void )
933 WCHAR txtW
[]={'W','i','n','e',0};
934 WCHAR initW
[]={'X','Y','Z',0};
936 void *txt
, *init
, *empty
, *string
;
937 HBITMAP hbm
= CreateBitmap(1,1,1,1,NULL
);
939 HMENU hmenu
, submenu
=CreateMenu();
940 HBITMAP dummy_hbm
= (HBITMAP
)(ULONG_PTR
)0xdeadbeef;
943 if( ansi
) {txt
=txtA
;init
=initA
;empty
=emptyA
;string
=stringA
;}
944 else {txt
=txtW
;init
=initW
;empty
=emptyW
;string
=stringA
;}
945 trace( "%s string %p hbm %p txt %p\n", ansi
? "ANSI tests: " : "Unicode tests:", string
, hbm
, txt
);
946 /* test all combinations of MFT_STRING, MFT_OWNERDRAW and MFT_BITMAP */
947 /* (since MFT_STRING is zero, there are four of them) */
948 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, 0, 0, 0, 0, 0, 0, txt
, 0, 0, OK
);
949 TMII_GMII ( MIIM_TYPE
, 80,
950 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
953 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
954 TMII_GMII ( MIIM_TYPE
, 80,
955 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
958 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, 6, 0, OK
);
959 TMII_GMII ( MIIM_TYPE
, 80,
960 MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
963 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, hbm
, 6, 0, OK
);
964 TMII_GMII ( MIIM_TYPE
, 80,
965 MFT_BITMAP
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
968 /* not enough space for name*/
969 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
970 TMII_GMII ( MIIM_TYPE
, 0,
971 MFT_STRING
, 0, 0, 0, 0, 0, 0, NULL
, 4, 0,
974 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
975 TMII_GMII ( MIIM_TYPE
, 5,
976 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
979 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
980 TMII_GMII ( MIIM_TYPE
, 4,
981 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 3, 0,
984 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
985 TMII_GMII ( MIIM_TYPE
, 0,
986 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 0, 0,
989 /* cannot combine MIIM_TYPE with some other flags */
990 TMII_INSMI( MIIM_TYPE
|MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, ER
);
992 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
993 TMII_GMII ( MIIM_TYPE
|MIIM_STRING
, 80,
994 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
997 TMII_INSMI( MIIM_TYPE
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, ER
);
999 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1000 TMII_GMII ( MIIM_TYPE
|MIIM_FTYPE
, 80,
1001 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1004 TMII_INSMI( MIIM_TYPE
|MIIM_BITMAP
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, 6, hbm
, ER
);
1006 /* but succeeds with some others */
1007 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1008 TMII_GMII ( MIIM_TYPE
|MIIM_SUBMENU
, 80,
1009 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1012 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1013 TMII_GMII ( MIIM_TYPE
|MIIM_STATE
, 80,
1014 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1017 TMII_INSMI( MIIM_TYPE
|MIIM_ID
, MFT_STRING
, -1, 888, 0, 0, 0, -1, txt
, 6, 0, OK
);
1018 TMII_GMII ( MIIM_TYPE
|MIIM_ID
, 80,
1019 MFT_STRING
, 0, 888, 0, 0, 0, 0, string
, 4, 0,
1022 TMII_INSMI( MIIM_TYPE
|MIIM_DATA
, MFT_STRING
, -1, -1, 0, 0, 0, 999, txt
, 6, 0, OK
);
1023 TMII_GMII ( MIIM_TYPE
|MIIM_DATA
, 80,
1024 MFT_STRING
, 0, 0, 0, 0, 0, 999, string
, 4, 0,
1027 /* to be continued */
1028 /* set text with MIIM_TYPE and retrieve with MIIM_STRING */
1029 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1030 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1031 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1034 /* set text with MIIM_TYPE and retrieve with MIIM_STRING; MFT_OWNERDRAW causes an empty string */
1035 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1036 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1037 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1040 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1041 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1042 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1045 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1046 TMII_GMII ( MIIM_FTYPE
, 80,
1047 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 80, 0,
1050 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1052 0, 0, 0, 0, 0, 0, 0, string
, 80, 0,
1055 /* contrary to MIIM_TYPE,you can set the text for an owner draw menu */
1056 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1057 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1058 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1061 /* same but retrieve with MIIM_TYPE */
1062 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1063 TMII_GMII ( MIIM_TYPE
, 80,
1064 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1067 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1068 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1069 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1072 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1073 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1074 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1078 /* How is that with bitmaps? */
1079 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1080 TMII_GMII ( MIIM_TYPE
, 80,
1081 MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1084 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1085 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1086 0, 0, 0, 0, 0, 0, 0, string
, 80, hbm
,
1089 /* MIIM_BITMAP does not like MFT_BITMAP */
1090 TMII_INSMI( MIIM_BITMAP
|MIIM_FTYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, ER
);
1092 /* no problem with OWNERDRAWN */
1093 TMII_INSMI( MIIM_BITMAP
|MIIM_FTYPE
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1094 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1095 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 80, hbm
,
1098 /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1099 TMII_INSMI( MIIM_FTYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER
);
1102 /* menu with submenu */
1103 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, submenu
, 0, 0, -1, txt
, 0, 0, OK
);
1104 TMII_GMII ( MIIM_SUBMENU
, 80,
1105 0, 0, 0, submenu
, 0, 0, 0, string
, 80, 0,
1108 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, submenu
, 0, 0, -1, empty
, 0, 0, OK
);
1109 TMII_GMII ( MIIM_SUBMENU
, 80,
1110 0, 0, 0, submenu
, 0, 0, 0, string
, 80, 0,
1113 /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1114 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, submenu
, 0, 0, -1, txt
, 0, 0, OK
);
1115 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1116 MFT_STRING
|MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 0, 0,
1118 TMII_GMII ( MIIM_SUBMENU
|MIIM_FTYPE
, 80,
1119 MFT_SEPARATOR
, 0, 0, submenu
, 0, 0, 0, string
, 80, 0,
1122 /* menu with invalid submenu */
1123 TMII_INSMI( MIIM_SUBMENU
|MIIM_FTYPE
, MFT_STRING
, -1, -1, (HMENU
)999, 0, 0, -1, txt
, 0, 0, ER
);
1126 TMII_INSMI( MIIM_TYPE
, MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, txt
, 0, 0, OK
);
1127 TMII_GMII ( MIIM_TYPE
, 80,
1128 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1131 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
|MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, hbm
, 6, 0, OK
);
1132 TMII_GMII ( MIIM_TYPE
, 80,
1133 MFT_BITMAP
|MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1136 /* SEPARATOR and STRING go well together */
1137 /* BITMAP and STRING go well together */
1138 TMII_INSMI( MIIM_STRING
|MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1139 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, 80,
1140 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, hbm
,
1143 /* BITMAP, SEPARATOR and STRING go well together */
1144 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1145 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, 80,
1146 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 4, hbm
,
1149 /* last two tests, but use MIIM_TYPE to retrieve info */
1150 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1151 TMII_GMII ( MIIM_TYPE
, 80,
1152 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1155 TMII_INSMI( MIIM_STRING
|MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1156 TMII_GMII ( MIIM_TYPE
, 80,
1157 MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1160 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1161 TMII_GMII ( MIIM_TYPE
, 80,
1162 MFT_SEPARATOR
|MFT_BITMAP
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1165 /* same three with MFT_OWNERDRAW */
1166 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
, MFT_SEPARATOR
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, 0, OK
);
1167 TMII_GMII ( MIIM_TYPE
, 80,
1168 MFT_SEPARATOR
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1171 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1172 TMII_GMII ( MIIM_TYPE
, 80,
1173 MFT_BITMAP
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1176 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1177 TMII_GMII ( MIIM_TYPE
, 80,
1178 MFT_SEPARATOR
|MFT_BITMAP
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 4, hbm
,
1182 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
|MIIM_ID
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1183 TMII_GMII ( MIIM_TYPE
, 80,
1184 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1187 /* test with modifymenu: string is preserved after setting OWNERDRAW */
1188 TMII_INSMI( MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1189 TMII_MODM( MFT_OWNERDRAW
, -1, (void*)787 );
1190 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_DATA
, 80,
1191 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 787, string
, 4, 0,
1194 /* same with bitmap: now the text is cleared */
1195 TMII_INSMI( MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1196 TMII_MODM( MFT_BITMAP
, 545, hbm
);
1197 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1198 MFT_BITMAP
, 0, 545, 0, 0, 0, 0, string
, 0, hbm
,
1201 /* start with bitmap: now setting text clears it (though he flag is raised) */
1202 TMII_INSMI( MIIM_BITMAP
, MFT_STRING
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1203 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1204 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 0, hbm
,
1206 TMII_MODM( MFT_STRING
, 545, txt
);
1207 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1208 MFT_STRING
, 0, 545, 0, 0, 0, 0, string
, 4, 0,
1211 /*repeat with text NULL */
1212 TMII_INSMI( MIIM_BITMAP
, MFT_STRING
, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1213 TMII_MODM( MFT_STRING
, 545, NULL
);
1214 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1215 MFT_SEPARATOR
, 0, 545, 0, 0, 0, 0, string
, 0, 0,
1218 /* repeat with text "" */
1219 TMII_INSMI( MIIM_BITMAP
, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1220 TMII_MODM( MFT_STRING
, 545, empty
);
1221 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_ID
, 80,
1222 MFT_STRING
, 0, 545, 0, 0, 0, 0, string
, 0, 0,
1225 /* start with bitmap: set ownerdraw */
1226 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm
, OK
);
1227 TMII_MODM( MFT_OWNERDRAW
, -1, (void *)232 );
1228 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
|MIIM_DATA
, 80,
1229 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 232, string
, 0, hbm
,
1233 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, hbm
, OK
);
1235 0, 0, 0, 0, 0, 0, 0, string
, 80, 0,
1238 /* some tests with small cbSize: the hbmpItem is to be ignored */
1239 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm
, OK
);
1240 TMII_GMII ( MIIM_TYPE
, 80,
1241 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, NULL
, 0, NULL
,
1244 TMII_INSMI( MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm
, OK
);
1245 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1246 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 80, NULL
,
1249 TMII_INSMI( MIIM_STRING
|MIIM_BITMAP
, -1, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1250 TMII_GMII ( MIIM_TYPE
, 80,
1251 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, NULL
,
1254 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1255 TMII_GMII ( MIIM_TYPE
, 80,
1256 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1259 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1260 TMII_GMII ( MIIM_TYPE
, 80,
1261 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1264 TMII_INSMI( MIIM_FTYPE
|MIIM_STRING
|MIIM_BITMAP
, MFT_SEPARATOR
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, -1, txt
, 6, dummy_hbm
, OK
);
1265 TMII_GMII ( MIIM_TYPE
, 80,
1266 MFT_SEPARATOR
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 4, NULL
,
1269 /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus */
1270 TMII_INSMI( MIIM_TYPE
|MIIM_DATA
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, 343, txt
, 0, 0, OK
);
1271 TMII_GMII ( MIIM_TYPE
|MIIM_DATA
, 80,
1272 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1275 TMII_INSMI( MIIM_TYPE
|MIIM_DATA
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, 343, txt
, 0, 0, OK
);
1276 TMII_GMII ( MIIM_TYPE
, 80,
1277 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1280 TMII_INSMI( MIIM_TYPE
, MFT_STRING
|MFT_OWNERDRAW
, -1, -1, 0, 0, 0, 343, txt
, 0, 0, OK
);
1281 TMII_GMII ( MIIM_TYPE
|MIIM_DATA
, 80,
1282 MFT_STRING
|MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1285 /* set a string menu to ownerdraw with MIIM_TYPE */
1286 TMII_INSMI( MIIM_TYPE
, MFT_STRING
, -2, -2, 0, 0, 0, -2, txt
, -2, 0, OK
);
1287 TMII_SMII ( MIIM_TYPE
, MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1288 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1289 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1292 /* test with modifymenu add submenu */
1293 TMII_INSMI( MIIM_STRING
, MFT_STRING
, -1, -1, 0, 0, 0, -1, txt
, 0, 0, OK
);
1294 TMII_MODM( MF_POPUP
, (UINT_PTR
)submenu
, txt
);
1295 TMII_GMII ( MIIM_FTYPE
|MIIM_STRING
|MIIM_SUBMENU
, 80,
1296 MFT_STRING
, 0, 0, submenu
, 0, 0, 0, string
, 4, 0,
1298 TMII_GMII ( MIIM_TYPE
, 80,
1299 MFT_STRING
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1302 /* MFT_SEPARATOR bit is kept when the text is added */
1303 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1304 TMII_SMII( MIIM_STRING
, 0, 0, 0, 0, 0, 0, 0, txt
, 0, 0 );
1305 TMII_GMII ( MIIM_STRING
|MIIM_FTYPE
, 80,
1306 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 4, 0,
1309 /* MFT_SEPARATOR bit is kept when bitmap is added */
1310 TMII_INSMI( MIIM_STRING
|MIIM_FTYPE
, MFT_STRING
, -1, -1, 0, 0, 0, -1, NULL
, 0, 0, OK
);
1311 TMII_SMII( MIIM_BITMAP
, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm
);
1312 TMII_GMII ( MIIM_BITMAP
|MIIM_FTYPE
, 80,
1313 MFT_SEPARATOR
, 0, 0, 0, 0, 0, 0, string
, 80, hbm
,
1316 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1317 Only the low word of the dwTypeData is used.
1318 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1319 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_RIGHTJUSTIFY
, -1, -1, 0, 0, 0, -1,
1320 (HMENU
)MAKELONG(HBMMENU_MBAR_CLOSE
, 0x1234), -1, 0, OK
);
1321 TMII_GMII ( MIIM_TYPE
, 80,
1322 MFT_BITMAP
| MFT_RIGHTJUSTIFY
, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE
, 0, HBMMENU_MBAR_CLOSE
,
1326 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1327 TMII_GMII ( MIIM_TYPE
, 80,
1328 MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1332 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1333 TMII_SMII( MIIM_STATE
, -1, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 0, 0 );
1334 TMII_GMII ( MIIM_STATE
, 80,
1335 0, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 80, 0,
1338 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1339 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1340 TMII_SMII( MIIM_CHECKMARKS
, MFT_RADIOCHECK
, 0, 0, 0, hbm
, hbm
, 0, 0, 0, 0 );
1341 TMII_GMII ( MIIM_CHECKMARKS
| MIIM_TYPE
, 80,
1342 MFT_BITMAP
, 0, 0, 0, hbm
, hbm
, 0, hbm
, 0, hbm
,
1345 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1346 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1347 TMII_SMII( MIIM_FTYPE
, MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, (HBITMAP
)0x1234, 0, 0 );
1348 TMII_GMII ( MIIM_FTYPE
, 80,
1349 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1351 TMII_GMII ( MIIM_TYPE
, 80,
1352 MFT_BITMAP
| MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1354 TMII_GMII ( MIIM_FTYPE
, 80,
1355 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1357 TMII_SMII( MIIM_BITMAP
, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
);
1358 TMII_GMII ( MIIM_TYPE
, 80,
1359 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 0, NULL
,
1362 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1363 Only the low word of the dwTypeData is used.
1364 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1365 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_RIGHTJUSTIFY
, -1, -1, 0, 0, 0, -1,
1366 (HMENU
)MAKELONG(HBMMENU_MBAR_CLOSE
, 0x1234), -1, 0, OK
);
1367 TMII_GMII ( MIIM_TYPE
, 80,
1368 MFT_BITMAP
| MFT_RIGHTJUSTIFY
, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE
, 0, HBMMENU_MBAR_CLOSE
,
1372 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1373 TMII_GMII ( MIIM_TYPE
, 80,
1374 MFT_BITMAP
| MFT_MENUBARBREAK
| MFT_RADIOCHECK
| MFT_RIGHTJUSTIFY
| MFT_RIGHTORDER
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1378 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1379 TMII_SMII( MIIM_STATE
, -1, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 0, 0 );
1380 TMII_GMII ( MIIM_STATE
, 80,
1381 0, MFS_CHECKED
| MFS_DEFAULT
| MFS_GRAYED
| MFS_HILITE
, 0, 0, 0, 0, 0, 0, 80, 0,
1384 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1385 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1386 TMII_SMII( MIIM_CHECKMARKS
, MFT_RADIOCHECK
, 0, 0, 0, hbm
, hbm
, 0, 0, 0, 0 );
1387 TMII_GMII ( MIIM_CHECKMARKS
| MIIM_TYPE
, 80,
1388 MFT_BITMAP
, 0, 0, 0, hbm
, hbm
, 0, hbm
, 0, hbm
,
1391 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1392 TMII_INSMI( MIIM_TYPE
, MFT_BITMAP
, -1, -1, 0, 0, 0, -1, hbm
, -1, 0, OK
);
1393 TMII_SMII( MIIM_FTYPE
, MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, (HBITMAP
)0x1234, 0, 0 );
1394 TMII_GMII ( MIIM_FTYPE
, 80,
1395 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1397 TMII_GMII ( MIIM_TYPE
, 80,
1398 MFT_BITMAP
| MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, hbm
, 0, hbm
,
1400 TMII_GMII ( MIIM_FTYPE
, 80,
1401 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1403 TMII_SMII( MIIM_BITMAP
, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
);
1404 TMII_GMII ( MIIM_TYPE
, 80,
1405 MFT_OWNERDRAW
, 0, 0, 0, 0, 0, 0, NULL
, 0, NULL
,
1408 } while( !(ansi
= !ansi
) );
1413 The following tests try to confirm the algorithm used to return the menu items
1414 when there is a collision between a menu item and a popup menu
1416 static void test_menu_search_bycommand( void )
1418 HMENU hmenu
, hmenuSub
, hmenuSub2
;
1424 static CHAR menuitem
[] = "MenuItem",
1425 menuitem2
[] = "MenuItem 2";
1427 /* Case 1: Menu containing a menu item */
1428 hmenu
= CreateMenu();
1430 memset( &info
, 0, sizeof info
);
1431 info
.cbSize
= sizeof info
;
1432 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1433 info
.fType
= MFT_STRING
;
1434 strcpy(strIn
, "Case 1 MenuItem");
1435 info
.dwTypeData
= strIn
;
1436 info
.wID
= (UINT
) 0x1234;
1438 rc
= InsertMenuItem(hmenu
, 0, TRUE
, &info
);
1439 ok (rc
, "Inserting the menuitem failed\n");
1441 id
= GetMenuItemID(hmenu
, 0);
1442 ok (id
== 0x1234, "Getting the menuitem id failed(gave %x)\n", id
);
1444 /* Confirm the menuitem was given the id supplied (getting by position) */
1445 memset( &info
, 0, sizeof info
);
1447 info
.cbSize
= sizeof(MENUITEMINFO
);
1448 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1449 info
.dwTypeData
= strback
;
1450 info
.cch
= sizeof(strback
);
1452 rc
= GetMenuItemInfo(hmenu
, 0, TRUE
, &info
); /* Get by position */
1453 ok (rc
, "Getting the menu items info failed\n");
1454 ok (info
.wID
== 0x1234, "IDs differ for the menuitem\n");
1455 ok (!strcmp(info
.dwTypeData
, "Case 1 MenuItem"), "Returned item has wrong label\n");
1457 /* Search by id - Should return the item */
1458 memset( &info
, 0, sizeof info
);
1460 info
.cbSize
= sizeof(MENUITEMINFO
);
1461 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1462 info
.dwTypeData
= strback
;
1463 info
.cch
= sizeof(strback
);
1464 rc
= GetMenuItemInfo(hmenu
, 0x1234, FALSE
, &info
); /* Get by ID */
1466 ok (rc
, "Getting the menu items info failed\n");
1467 ok (info
.wID
== 0x1234, "IDs differ for the menuitem\n");
1468 ok (!strcmp(info
.dwTypeData
, "Case 1 MenuItem"), "Returned item has wrong label\n");
1470 DestroyMenu( hmenu
);
1472 /* Case 2: Menu containing a popup menu */
1473 hmenu
= CreateMenu();
1474 hmenuSub
= CreateMenu();
1476 strcpy(strIn
, "Case 2 SubMenu");
1477 rc
= InsertMenu(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, strIn
);
1478 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1480 id
= GetMenuItemID(hmenu
, 0);
1481 ok (id
== -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id
);
1483 /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
1484 memset( &info
, 0, sizeof info
);
1486 info
.cbSize
= sizeof(MENUITEMINFO
);
1487 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1488 info
.dwTypeData
= strback
;
1489 info
.cch
= sizeof(strback
);
1490 info
.wID
= 0xdeadbeef;
1492 rc
= GetMenuItemInfo(hmenu
, 0, TRUE
, &info
); /* Get by position */
1493 ok (rc
, "Getting the menu items info failed\n");
1494 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the menuitem\n");
1495 ok (!strcmp(info
.dwTypeData
, "Case 2 SubMenu"), "Returned item has wrong label\n");
1497 /* Search by id - returns the popup menu itself */
1498 memset( &info
, 0, sizeof info
);
1500 info
.cbSize
= sizeof(MENUITEMINFO
);
1501 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1502 info
.dwTypeData
= strback
;
1503 info
.cch
= sizeof(strback
);
1504 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
); /* Get by ID */
1506 ok (rc
, "Getting the menu items info failed\n");
1507 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the popup menu\n");
1508 ok (!strcmp(info
.dwTypeData
, "Case 2 SubMenu"), "Returned item has wrong label\n");
1511 Now add an item after it with the same id
1513 memset( &info
, 0, sizeof info
);
1514 info
.cbSize
= sizeof info
;
1515 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1516 info
.fType
= MFT_STRING
;
1517 strcpy(strIn
, "Case 2 MenuItem 1");
1518 info
.dwTypeData
= strIn
;
1519 info
.wID
= (UINT_PTR
) hmenuSub
;
1520 rc
= InsertMenuItem(hmenu
, -1, TRUE
, &info
);
1521 ok (rc
, "Inserting the menuitem failed\n");
1523 /* Search by id - returns the item which follows the popup menu */
1524 memset( &info
, 0, sizeof info
);
1526 info
.cbSize
= sizeof(MENUITEMINFO
);
1527 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1528 info
.dwTypeData
= strback
;
1529 info
.cch
= sizeof(strback
);
1530 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
); /* Get by ID */
1532 ok (rc
, "Getting the menu items info failed\n");
1533 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the popup menu\n");
1534 ok (!strcmp(info
.dwTypeData
, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1537 Now add an item before the popup (with the same id)
1539 memset( &info
, 0, sizeof info
);
1540 info
.cbSize
= sizeof info
;
1541 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1542 info
.fType
= MFT_STRING
;
1543 strcpy(strIn
, "Case 2 MenuItem 2");
1544 info
.dwTypeData
= strIn
;
1545 info
.wID
= (UINT_PTR
) hmenuSub
;
1546 rc
= InsertMenuItem(hmenu
, 0, TRUE
, &info
);
1547 ok (rc
, "Inserting the menuitem failed\n");
1549 /* Search by id - returns the item which precedes the popup menu */
1550 memset( &info
, 0, sizeof info
);
1552 info
.cbSize
= sizeof(MENUITEMINFO
);
1553 info
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
1554 info
.dwTypeData
= strback
;
1555 info
.cch
= sizeof(strback
);
1556 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
); /* Get by ID */
1558 ok (rc
, "Getting the menu items info failed\n");
1559 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for the popup menu\n");
1560 ok (!strcmp(info
.dwTypeData
, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1562 DestroyMenu( hmenu
);
1563 DestroyMenu( hmenuSub
);
1566 Case 3: Menu containing a popup menu which in turn
1567 contains 2 items with the same id as the popup itself
1570 hmenu
= CreateMenu();
1571 hmenuSub
= CreateMenu();
1573 memset( &info
, 0, sizeof info
);
1574 info
.cbSize
= sizeof info
;
1575 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1576 info
.fType
= MFT_STRING
;
1577 info
.dwTypeData
= menuitem
;
1578 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1580 rc
= InsertMenu(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, "Submenu");
1581 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1583 rc
= InsertMenuItem(hmenuSub
, 0, TRUE
, &info
);
1584 ok (rc
, "Inserting the sub menu menuitem failed\n");
1586 memset( &info
, 0, sizeof info
);
1587 info
.cbSize
= sizeof info
;
1588 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1589 info
.fType
= MFT_STRING
;
1590 info
.dwTypeData
= menuitem2
;
1591 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1593 rc
= InsertMenuItem(hmenuSub
, 1, TRUE
, &info
);
1594 ok (rc
, "Inserting the sub menu menuitem 2 failed\n");
1596 /* Prove that you can't query the id of a popup directly (By position) */
1597 id
= GetMenuItemID(hmenu
, 0);
1598 ok (id
== -1, "Getting the sub menu id should have failed because its a popup (gave %x)\n", id
);
1600 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1601 memset( &info
, 0, sizeof info
);
1603 info
.cbSize
= sizeof(MENUITEMINFO
);
1604 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1605 info
.dwTypeData
= strback
;
1606 info
.cch
= sizeof(strback
);
1608 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
);
1609 ok (rc
, "Getting the menus info failed\n");
1610 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for popup menu\n");
1611 ok (!strcmp(info
.dwTypeData
, "MenuItem"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1612 DestroyMenu( hmenu
);
1613 DestroyMenu( hmenuSub
);
1616 Case 4: Menu containing 2 popup menus, the second
1617 contains 2 items with the same id as the first popup menu
1619 hmenu
= CreateMenu();
1620 hmenuSub
= CreateMenu();
1621 hmenuSub2
= CreateMenu();
1623 rc
= InsertMenu(hmenu
, 0, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, "Submenu");
1624 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1626 rc
= InsertMenu(hmenu
, 1, MF_BYPOSITION
| MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub2
, "Submenu2");
1627 ok (rc
, "Inserting the popup menu into the main menu failed\n");
1629 memset( &info
, 0, sizeof info
);
1630 info
.cbSize
= sizeof info
;
1631 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1632 info
.fType
= MFT_STRING
;
1633 info
.dwTypeData
= menuitem
;
1634 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1636 rc
= InsertMenuItem(hmenuSub2
, 0, TRUE
, &info
);
1637 ok (rc
, "Inserting the sub menu menuitem failed\n");
1639 memset( &info
, 0, sizeof info
);
1640 info
.cbSize
= sizeof info
;
1641 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_ID
;
1642 info
.fType
= MFT_STRING
;
1643 info
.dwTypeData
= menuitem2
;
1644 info
.wID
= (UINT_PTR
) hmenuSub
; /* Enforce id collisions with the hmenu of the popup submenu*/
1646 rc
= InsertMenuItem(hmenuSub2
, 1, TRUE
, &info
);
1647 ok (rc
, "Inserting the sub menu menuitem 2 failed\n");
1649 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1650 memset( &info
, 0, sizeof info
);
1652 info
.cbSize
= sizeof(MENUITEMINFO
);
1653 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1654 info
.dwTypeData
= strback
;
1655 info
.cch
= sizeof(strback
);
1657 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub
, FALSE
, &info
);
1658 ok (rc
, "Getting the menus info failed\n");
1659 ok (info
.wID
== (UINT_PTR
)hmenuSub
, "IDs differ for popup menu\n");
1660 ok (!strcmp(info
.dwTypeData
, "MenuItem"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1662 memset( &info
, 0, sizeof info
);
1664 info
.cbSize
= sizeof(MENUITEMINFO
);
1665 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1666 info
.dwTypeData
= strback
;
1667 info
.cch
= sizeof(strback
);
1669 rc
= GetMenuItemInfo(hmenu
, (UINT_PTR
)hmenuSub2
, FALSE
, &info
);
1670 ok (rc
, "Getting the menus info failed\n");
1671 ok (info
.wID
== (UINT_PTR
)hmenuSub2
, "IDs differ for popup menu\n");
1672 ok (!strcmp(info
.dwTypeData
, "Submenu2"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1674 DestroyMenu( hmenu
);
1675 DestroyMenu( hmenuSub
);
1676 DestroyMenu( hmenuSub2
);
1680 Case 5: Menu containing a popup menu which in turn
1681 contains an item with a different id than the popup menu.
1682 This tests the fallback to a popup menu ID.
1685 hmenu
= CreateMenu();
1686 hmenuSub
= CreateMenu();
1688 rc
= AppendMenu(hmenu
, MF_POPUP
| MF_STRING
, (UINT_PTR
)hmenuSub
, "Submenu");
1689 ok (rc
, "Appending the popup menu to the main menu failed\n");
1691 rc
= AppendMenu(hmenuSub
, MF_STRING
, 102, "Item");
1692 ok (rc
, "Appending the item to the popup menu failed\n");
1694 /* Set the ID for hmenuSub */
1695 info
.cbSize
= sizeof(info
);
1696 info
.fMask
= MIIM_ID
;
1699 rc
= SetMenuItemInfo(hmenu
, 0, TRUE
, &info
);
1700 ok(rc
, "Setting the ID for the popup menu failed\n");
1702 /* Check if the ID has been set */
1704 rc
= GetMenuItemInfo(hmenu
, 0, TRUE
, &info
);
1705 ok(rc
, "Getting the ID for the popup menu failed\n");
1706 ok(info
.wID
== 101, "The ID for the popup menu has not been set\n");
1708 /* Prove getting the item info via ID returns the popup menu */
1709 memset( &info
, 0, sizeof(info
));
1711 info
.cbSize
= sizeof(MENUITEMINFO
);
1712 info
.fMask
= MIIM_STRING
| MIIM_ID
;
1713 info
.dwTypeData
= strback
;
1714 info
.cch
= sizeof(strback
);
1716 rc
= GetMenuItemInfo(hmenu
, 101, FALSE
, &info
);
1717 ok (rc
, "Getting the menu info failed\n");
1718 ok (info
.wID
== 101, "IDs differ\n");
1719 ok (!strcmp(info
.dwTypeData
, "Submenu"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1721 /* Also look for the menu 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
, 102, FALSE
, &info
);
1730 ok (rc
, "Getting the menu info failed\n");
1731 ok (info
.wID
== 102, "IDs differ\n");
1732 ok (!strcmp(info
.dwTypeData
, "Item"), "Returned item has wrong label (%s)\n", info
.dwTypeData
);
1735 DestroyMenu(hmenuSub
);
1738 struct menu_item_pair_s
{
1739 UINT uMenu
; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
1740 * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
1741 * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
1745 static struct menu_mouse_tests_s
{
1747 struct menu_item_pair_s menu_item_pairs
[5]; /* for mousing */
1748 WORD wVk
[5]; /* keys */
1752 /* for each test, send keys or clicks and check for menu visibility */
1753 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 0}, TRUE
, FALSE
}, /* test 0 */
1754 { INPUT_KEYBOARD
, {{0}}, {VK_ESCAPE
, 0}, FALSE
, FALSE
},
1755 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 0}, TRUE
, FALSE
},
1756 { INPUT_KEYBOARD
, {{0}}, {'D', 0}, FALSE
, FALSE
},
1757 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 0}, TRUE
, FALSE
},
1758 { INPUT_KEYBOARD
, {{0}}, {'E', 0}, FALSE
, FALSE
},
1759 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 0}, TRUE
, FALSE
},
1760 { INPUT_KEYBOARD
, {{0}}, {VK_ESCAPE
, VK_ESCAPE
, 0}, FALSE
, FALSE
},
1761 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', VK_ESCAPE
, 0}, TRUE
, FALSE
},
1762 { INPUT_KEYBOARD
, {{0}}, {VK_ESCAPE
, 0}, FALSE
, FALSE
},
1763 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 0}, TRUE
, FALSE
},
1764 { INPUT_KEYBOARD
, {{0}}, {'D', 0}, FALSE
, FALSE
},
1765 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 0}, TRUE
, FALSE
},
1766 { INPUT_KEYBOARD
, {{0}}, {'E', 0}, FALSE
, FALSE
},
1767 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 'P', 0}, TRUE
, FALSE
},
1768 { INPUT_KEYBOARD
, {{0}}, {'D', 0}, FALSE
, FALSE
},
1769 { INPUT_KEYBOARD
, {{0}}, {VK_MENU
, 'M', 'P', 0}, TRUE
, FALSE
},
1770 { INPUT_KEYBOARD
, {{0}}, {'E', 0}, FALSE
, FALSE
},
1772 { INPUT_MOUSE
, {{1, 2}, {0}}, {0}, TRUE
, TRUE
}, /* test 18 */
1773 { INPUT_MOUSE
, {{1, 1}, {0}}, {0}, FALSE
, FALSE
},
1774 { INPUT_MOUSE
, {{1, 0}, {0}}, {0}, TRUE
, TRUE
},
1775 { INPUT_MOUSE
, {{1, 1}, {0}}, {0}, FALSE
, FALSE
},
1776 { INPUT_MOUSE
, {{1, 0}, {2, 2}, {0}}, {0}, TRUE
, TRUE
},
1777 { INPUT_MOUSE
, {{2, 1}, {0}}, {0}, FALSE
, FALSE
},
1778 { INPUT_MOUSE
, {{1, 0}, {2, 0}, {0}}, {0}, TRUE
, TRUE
},
1779 { INPUT_MOUSE
, {{3, 0}, {0}}, {0}, FALSE
, FALSE
},
1780 { INPUT_MOUSE
, {{1, 0}, {2, 0}, {0}}, {0}, TRUE
, TRUE
},
1781 { INPUT_MOUSE
, {{3, 1}, {0}}, {0}, TRUE
, TRUE
},
1782 { INPUT_MOUSE
, {{1, 1}, {0}}, {0}, FALSE
, FALSE
},
1786 static void send_key(WORD wVk
)
1789 memset(i
, 0, sizeof(i
));
1790 i
[0].type
= i
[1].type
= INPUT_KEYBOARD
;
1791 i
[0].u
.ki
.wVk
= i
[1].u
.ki
.wVk
= wVk
;
1792 i
[1].u
.ki
.dwFlags
= KEYEVENTF_KEYUP
;
1793 pSendInput(2, (INPUT
*) i
, sizeof(INPUT
));
1796 static BOOL
click_menu(HANDLE hWnd
, struct menu_item_pair_s
*mi
)
1798 HMENU hMenu
= hMenus
[mi
->uMenu
];
1802 int screen_w
= GetSystemMetrics(SM_CXSCREEN
);
1803 int screen_h
= GetSystemMetrics(SM_CYSCREEN
);
1804 BOOL ret
= GetMenuItemRect(mi
->uMenu
> 2 ? NULL
: hWnd
, hMenu
, mi
->uItem
, &r
);
1805 if(!ret
) return FALSE
;
1807 memset(i
, 0, sizeof(i
));
1808 i
[0].type
= i
[1].type
= i
[2].type
= INPUT_MOUSE
;
1809 i
[0].u
.mi
.dx
= i
[1].u
.mi
.dx
= i
[2].u
.mi
.dx
1810 = ((r
.left
+ 5) * 65535) / screen_w
;
1811 i
[0].u
.mi
.dy
= i
[1].u
.mi
.dy
= i
[2].u
.mi
.dy
1812 = ((r
.top
+ 5) * 65535) / screen_h
;
1813 i
[0].u
.mi
.dwFlags
= i
[1].u
.mi
.dwFlags
= i
[2].u
.mi
.dwFlags
1814 = MOUSEEVENTF_ABSOLUTE
;
1815 i
[0].u
.mi
.dwFlags
|= MOUSEEVENTF_MOVE
;
1816 i
[1].u
.mi
.dwFlags
|= MOUSEEVENTF_LEFTDOWN
;
1817 i
[2].u
.mi
.dwFlags
|= MOUSEEVENTF_LEFTUP
;
1818 ret
= pSendInput(3, (INPUT
*) i
, sizeof(INPUT
));
1820 /* hack to prevent mouse message buildup in Wine */
1821 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
1825 static DWORD WINAPI
test_menu_input_thread(LPVOID lpParameter
)
1828 HANDLE hWnd
= lpParameter
;
1831 /* mixed keyboard/mouse test */
1832 for (i
= 0; menu_tests
[i
].type
!= -1; i
++)
1834 int ret
= TRUE
, elapsed
= 0;
1836 got_input
= i
&& menu_tests
[i
-1].bMenuVisible
;
1838 if (menu_tests
[i
].type
== INPUT_KEYBOARD
)
1839 for (j
= 0; menu_tests
[i
].wVk
[j
] != 0; j
++)
1840 send_key(menu_tests
[i
].wVk
[j
]);
1842 for (j
= 0; menu_tests
[i
].menu_item_pairs
[j
].uMenu
!= 0; j
++)
1843 if (!(ret
= click_menu(hWnd
, &menu_tests
[i
].menu_item_pairs
[j
]))) break;
1847 skip( "test %u: failed to send input\n", i
);
1848 PostMessage( hWnd
, WM_CANCELMODE
, 0, 0 );
1851 while (menu_tests
[i
].bMenuVisible
!= bMenuVisible
)
1861 skip( "test %u: didn't receive input\n", i
);
1862 PostMessage( hWnd
, WM_CANCELMODE
, 0, 0 );
1866 if (menu_tests
[i
]._todo_wine
)
1869 ok(menu_tests
[i
].bMenuVisible
== bMenuVisible
, "test %d\n", i
);
1873 ok(menu_tests
[i
].bMenuVisible
== bMenuVisible
, "test %d\n", i
);
1878 static LRESULT CALLBACK
WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
,
1882 case WM_ENTERMENULOOP
:
1883 bMenuVisible
= TRUE
;
1885 case WM_EXITMENULOOP
:
1886 bMenuVisible
= FALSE
;
1891 case WM_LBUTTONDOWN
:
1893 case WM_NCMOUSEMOVE
:
1894 case WM_NCLBUTTONDOWN
:
1895 case WM_NCLBUTTONUP
:
1899 return( DefWindowProcA( hWnd
, msg
, wParam
, lParam
) );
1904 static void test_menu_input(void) {
1907 HINSTANCE hInstance
= GetModuleHandleA( NULL
);
1908 HANDLE hThread
, hWnd
;
1911 wclass
.lpszClassName
= "MenuTestClass";
1912 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
1913 wclass
.lpfnWndProc
= WndProc
;
1914 wclass
.hInstance
= hInstance
;
1915 wclass
.hIcon
= LoadIconA( 0, IDI_APPLICATION
);
1916 wclass
.hCursor
= LoadCursorA( NULL
, IDC_ARROW
);
1917 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
1918 wclass
.lpszMenuName
= 0;
1919 wclass
.cbClsExtra
= 0;
1920 wclass
.cbWndExtra
= 0;
1921 assert (RegisterClassA( &wclass
));
1922 assert (hWnd
= CreateWindowA( wclass
.lpszClassName
, "MenuTest",
1923 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0,
1924 400, 200, NULL
, NULL
, hInstance
, NULL
) );
1927 hMenus
[3] = CreatePopupMenu();
1928 AppendMenu(hMenus
[3], MF_STRING
, 0, "&Enabled");
1929 AppendMenu(hMenus
[3], MF_STRING
|MF_DISABLED
, 0, "&Disabled");
1931 hMenus
[2] = CreatePopupMenu();
1932 AppendMenu(hMenus
[2], MF_STRING
|MF_POPUP
, (UINT_PTR
) hMenus
[3], "&Popup");
1933 AppendMenu(hMenus
[2], MF_STRING
, 0, "&Enabled");
1934 AppendMenu(hMenus
[2], MF_STRING
|MF_DISABLED
, 0, "&Disabled");
1936 hMenus
[1] = CreateMenu();
1937 AppendMenu(hMenus
[1], MF_STRING
|MF_POPUP
, (UINT_PTR
) hMenus
[2], "&Menu");
1938 AppendMenu(hMenus
[1], MF_STRING
, 0, "&Enabled");
1939 AppendMenu(hMenus
[1], MF_STRING
|MF_DISABLED
, 0, "&Disabled");
1941 SetMenu(hWnd
, hMenus
[1]);
1942 ShowWindow(hWnd
, SW_SHOW
);
1945 hThread
= CreateThread(NULL
, 0, test_menu_input_thread
, hWnd
, 0, &tid
);
1948 if (WAIT_TIMEOUT
!= WaitForSingleObject(hThread
, 50))
1950 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
1952 DestroyWindow(hWnd
);
1955 static void test_menu_flags( void )
1957 HMENU hMenu
, hPopupMenu
;
1959 hMenu
= CreateMenu();
1960 hPopupMenu
= CreatePopupMenu();
1962 AppendMenu(hMenu
, MF_POPUP
| MF_STRING
, (UINT_PTR
)hPopupMenu
, "Popup");
1964 AppendMenu(hPopupMenu
, MF_STRING
| MF_HILITE
| MF_DEFAULT
, 101, "Item 1");
1965 InsertMenu(hPopupMenu
, 1, MF_BYPOSITION
| MF_STRING
| MF_HILITE
| MF_DEFAULT
, 102, "Item 2");
1966 AppendMenu(hPopupMenu
, MF_STRING
, 103, "Item 3");
1967 ModifyMenu(hPopupMenu
, 2, MF_BYPOSITION
| MF_STRING
| MF_HILITE
| MF_DEFAULT
, 103, "Item 3");
1969 ok(GetMenuState(hPopupMenu
, 0, MF_BYPOSITION
) & MF_HILITE
,
1970 "AppendMenu should accept MF_HILITE\n");
1971 ok(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
,
1972 "InsertMenu should accept MF_HILITE\n");
1973 ok(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_HILITE
,
1974 "ModifyMenu should accept MF_HILITE\n");
1976 ok(!(GetMenuState(hPopupMenu
, 0, MF_BYPOSITION
) & MF_DEFAULT
),
1977 "AppendMenu must not accept MF_DEFAULT\n");
1978 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_DEFAULT
),
1979 "InsertMenu must not accept MF_DEFAULT\n");
1980 ok(!(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_DEFAULT
),
1981 "ModifyMenu must not accept MF_DEFAULT\n");
1986 static void test_menu_hilitemenuitem( void )
1988 HMENU hMenu
, hPopupMenu
;
1992 wclass
.lpszClassName
= "HiliteMenuTestClass";
1993 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
1994 wclass
.lpfnWndProc
= WndProc
;
1995 wclass
.hInstance
= GetModuleHandleA( NULL
);
1996 wclass
.hIcon
= LoadIconA( 0, IDI_APPLICATION
);
1997 wclass
.hCursor
= LoadCursorA( NULL
, IDC_ARROW
);
1998 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
1999 wclass
.lpszMenuName
= 0;
2000 wclass
.cbClsExtra
= 0;
2001 wclass
.cbWndExtra
= 0;
2002 assert (RegisterClassA( &wclass
));
2003 assert (hWnd
= CreateWindowA( wclass
.lpszClassName
, "HiliteMenuTest",
2004 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0,
2005 400, 200, NULL
, NULL
, wclass
.hInstance
, NULL
) );
2007 hMenu
= CreateMenu();
2008 hPopupMenu
= CreatePopupMenu();
2010 AppendMenu(hMenu
, MF_POPUP
| MF_STRING
, (UINT_PTR
)hPopupMenu
, "Popup");
2012 AppendMenu(hPopupMenu
, MF_STRING
, 101, "Item 1");
2013 AppendMenu(hPopupMenu
, MF_STRING
, 102, "Item 2");
2014 AppendMenu(hPopupMenu
, MF_STRING
, 103, "Item 3");
2016 SetMenu(hWnd
, hMenu
);
2018 /* test invalid arguments */
2020 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2021 "HiliteMenuItem: Item 2 is hilited\n");
2023 SetLastError(0xdeadbeef);
2026 ok(!HiliteMenuItem(NULL
, hPopupMenu
, 1, MF_HILITE
| MF_BYPOSITION
),
2027 "HiliteMenuItem: call should have failed.\n");
2029 ok(GetLastError() == 0xdeadbeef || /* 9x */
2030 GetLastError() == ERROR_INVALID_WINDOW_HANDLE
/* NT */,
2031 "HiliteMenuItem: expected error ERROR_INVALID_WINDOW_HANDLE, got: %d\n", GetLastError());
2033 SetLastError(0xdeadbeef);
2034 ok(!HiliteMenuItem(hWnd
, NULL
, 1, MF_HILITE
| MF_BYPOSITION
),
2035 "HiliteMenuItem: call should have failed.\n");
2036 ok(GetLastError() == 0xdeadbeef || /* 9x */
2037 GetLastError() == ERROR_INVALID_MENU_HANDLE
/* NT */,
2038 "HiliteMenuItem: expected error ERROR_INVALID_MENU_HANDLE, got: %d\n", GetLastError());
2040 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2041 "HiliteMenuItem: Item 2 is hilited\n");
2043 /* either MF_HILITE or MF_UNHILITE *and* MF_BYCOMMAND or MF_BYPOSITION need to be set */
2045 SetLastError(0xdeadbeef);
2046 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_BYPOSITION
),
2047 "HiliteMenuItem: call should have succeeded.\n");
2048 ok(GetLastError() == 0xdeadbeef,
2049 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2051 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2052 "HiliteMenuItem: Item 2 is hilited\n");
2054 SetLastError(0xdeadbeef);
2057 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_HILITE
),
2058 "HiliteMenuItem: call should have succeeded.\n");
2060 ok(GetLastError() == 0xdeadbeef,
2061 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2063 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2064 "HiliteMenuItem: Item 2 is hilited\n");
2066 /* hilite a menu item (by position) */
2068 SetLastError(0xdeadbeef);
2069 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_HILITE
| MF_BYPOSITION
),
2070 "HiliteMenuItem: call should not have failed.\n");
2071 ok(GetLastError() == 0xdeadbeef,
2072 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2076 ok(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
,
2077 "HiliteMenuItem: Item 2 is not hilited\n");
2080 /* unhilite a menu item (by position) */
2082 SetLastError(0xdeadbeef);
2083 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 1, MF_UNHILITE
| MF_BYPOSITION
),
2084 "HiliteMenuItem: call should not have failed.\n");
2085 ok(GetLastError() == 0xdeadbeef,
2086 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2088 ok(!(GetMenuState(hPopupMenu
, 1, MF_BYPOSITION
) & MF_HILITE
),
2089 "HiliteMenuItem: Item 2 is hilited\n");
2091 /* hilite a menu item (by command) */
2093 SetLastError(0xdeadbeef);
2094 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 103, MF_HILITE
| MF_BYCOMMAND
),
2095 "HiliteMenuItem: call should not have failed.\n");
2096 ok(GetLastError() == 0xdeadbeef,
2097 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2101 ok(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_HILITE
,
2102 "HiliteMenuItem: Item 3 is not hilited\n");
2105 /* unhilite a menu item (by command) */
2107 SetLastError(0xdeadbeef);
2108 ok(HiliteMenuItem(hWnd
, hPopupMenu
, 103, MF_UNHILITE
| MF_BYCOMMAND
),
2109 "HiliteMenuItem: call should not have failed.\n");
2110 ok(GetLastError() == 0xdeadbeef,
2111 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2113 ok(!(GetMenuState(hPopupMenu
, 2, MF_BYPOSITION
) & MF_HILITE
),
2114 "HiliteMenuItem: Item 3 is hilited\n");
2116 DestroyWindow(hWnd
);
2119 static void check_menu_items(HMENU hmenu
, UINT checked_cmd
, UINT checked_type
,
2124 count
= GetMenuItemCount(hmenu
);
2125 ok (count
!= -1, "GetMenuItemCount returned -1\n");
2127 for (i
= 0; i
< count
; i
++)
2132 memset(&mii
, 0, sizeof(mii
));
2133 mii
.cbSize
= sizeof(mii
);
2134 mii
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_ID
| MIIM_SUBMENU
;
2135 ret
= GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
);
2136 ok(ret
, "GetMenuItemInfo(%u) failed\n", i
);
2138 trace("item #%u: fType %04x, fState %04x, wID %u, hSubMenu %p\n",
2139 i
, mii
.fType
, mii
.fState
, mii
.wID
, mii
.hSubMenu
);
2143 ok(mii
.wID
== (UINT_PTR
)mii
.hSubMenu
, "id %u: wID should be equal to hSubMenu\n", checked_cmd
);
2144 check_menu_items(mii
.hSubMenu
, checked_cmd
, checked_type
, checked_state
);
2148 if (mii
.wID
== checked_cmd
)
2150 ok(mii
.fType
== checked_type
, "id %u: expected fType %04x, got %04x\n", checked_cmd
, checked_type
, mii
.fType
);
2151 ok(mii
.fState
== checked_state
, "id %u: expected fState %04x, got %04x\n", checked_cmd
, checked_state
, mii
.fState
);
2152 ok(mii
.wID
!= 0, "id %u: not expected wID 0\n", checked_cmd
);
2156 ok(mii
.fType
!= MFT_RADIOCHECK
, "id %u: not expected fType MFT_RADIOCHECK on cmd %u\n", checked_cmd
, mii
.wID
);
2158 if (mii
.fType
== MFT_SEPARATOR
)
2160 ok(mii
.fState
== MFS_GRAYED
, "id %u: expected fState MFS_GRAYED, got %04x\n", checked_cmd
, mii
.fState
);
2161 ok(mii
.wID
== 0, "id %u: expected wID 0, got %u\n", checked_cmd
, mii
.wID
);
2165 ok(mii
.fState
== 0, "id %u: expected fState 0, got %04x\n", checked_cmd
, mii
.fState
);
2166 ok(mii
.wID
!= 0, "id %u: not expected wID 0\n", checked_cmd
);
2173 static void clear_ftype_and_state(HMENU hmenu
, UINT id
, UINT flags
)
2178 memset(&mii
, 0, sizeof(mii
));
2179 mii
.cbSize
= sizeof(mii
);
2180 mii
.fMask
= MIIM_FTYPE
| MIIM_STATE
;
2181 ret
= SetMenuItemInfo(hmenu
, id
, (flags
& MF_BYPOSITION
) != 0, &mii
);
2182 ok(ret
, "SetMenuItemInfo(%u) failed\n", id
);
2185 static void test_CheckMenuRadioItem(void)
2190 hmenu
= LoadMenu(GetModuleHandle(0), MAKEINTRESOURCE(1));
2193 check_menu_items(hmenu
, -1, 0, 0);
2195 ret
= CheckMenuRadioItem(hmenu
, 100, 100, 100, MF_BYCOMMAND
);
2196 ok(ret
, "CheckMenuRadioItem failed\n");
2197 check_menu_items(hmenu
, 100, MFT_RADIOCHECK
, MFS_CHECKED
);
2199 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2200 ret
= CheckMenuRadioItem(hmenu
, 100, 100, -1, MF_BYCOMMAND
);
2201 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2202 check_menu_items(hmenu
, 100, MFT_RADIOCHECK
, 0);
2205 clear_ftype_and_state(hmenu
, 100, MF_BYCOMMAND
);
2206 check_menu_items(hmenu
, -1, 0, 0);
2208 /* first and checked items are on different menus */
2209 ret
= CheckMenuRadioItem(hmenu
, 0, 300, 202, MF_BYCOMMAND
);
2210 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2211 check_menu_items(hmenu
, -1, 0, 0);
2213 ret
= CheckMenuRadioItem(hmenu
, 200, 300, 202, MF_BYCOMMAND
);
2214 ok(ret
, "CheckMenuRadioItem failed\n");
2215 check_menu_items(hmenu
, 202, MFT_RADIOCHECK
, MFS_CHECKED
);
2217 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2218 ret
= CheckMenuRadioItem(hmenu
, 202, 202, -1, MF_BYCOMMAND
);
2219 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2220 check_menu_items(hmenu
, 202, MFT_RADIOCHECK
, 0);
2223 clear_ftype_and_state(hmenu
, 202, MF_BYCOMMAND
);
2224 check_menu_items(hmenu
, -1, 0, 0);
2226 /* just for fun, try to check separator */
2227 ret
= CheckMenuRadioItem(hmenu
, 0, 300, 0, MF_BYCOMMAND
);
2228 ok(!ret
, "CheckMenuRadioItem should return FALSE\n");
2229 check_menu_items(hmenu
, -1, 0, 0);
2232 static void test_menu_resource_layout(void)
2236 MENUITEMTEMPLATEHEADER mith
;
2240 { 0, 0 }, /* versionNumber, offset */
2242 /* mtOption, mtID, mtString[] '\0' terminated */
2243 MF_STRING
, 1, 'F', 0,
2246 /* MF_SEPARATOR, 4, 'S', 0, FIXME: Wine ignores 'S' */
2247 MF_STRING
|MF_GRAYED
|MF_END
, 5, 'E', 0
2252 UINT type
, state
, id
;
2256 { MF_STRING
, MF_ENABLED
, 1, "F" },
2257 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 2, "" },
2258 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 3, "" },
2259 /*{ MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 4, "S" }, FIXME: Wine ignores 'S'*/
2260 { MF_STRING
, MF_GRAYED
, 5, "E" },
2261 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 6, "" },
2262 { MF_STRING
, MF_ENABLED
, 7, "" },
2263 { MF_SEPARATOR
, MF_GRAYED
|MF_DISABLED
, 8, "" }
2269 hmenu
= LoadMenuIndirect(&menu_template
);
2270 ok(hmenu
!= 0, "LoadMenuIndirect error %u\n", GetLastError());
2272 ret
= AppendMenu(hmenu
, MF_STRING
, 6, NULL
);
2273 ok(ret
, "AppendMenu failed\n");
2274 ret
= AppendMenu(hmenu
, MF_STRING
, 7, "\0");
2275 ok(ret
, "AppendMenu failed\n");
2276 ret
= AppendMenu(hmenu
, MF_SEPARATOR
, 8, "separator");
2277 ok(ret
, "AppendMenu failed\n");
2279 count
= GetMenuItemCount(hmenu
);
2280 ok(count
== sizeof(menu_data
)/sizeof(menu_data
[0]),
2281 "expected %u menu items, got %u\n",
2282 (UINT
)(sizeof(menu_data
)/sizeof(menu_data
[0])), count
);
2284 for (i
= 0; i
< count
; i
++)
2289 memset(&mii
, 0, sizeof(mii
));
2290 mii
.cbSize
= sizeof(mii
);
2291 mii
.dwTypeData
= buf
;
2292 mii
.cch
= sizeof(buf
);
2293 mii
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_ID
| MIIM_STRING
;
2294 ret
= GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
);
2295 ok(ret
, "GetMenuItemInfo(%u) failed\n", i
);
2297 trace("item #%u: fType %04x, fState %04x, wID %u, dwTypeData %s\n",
2298 i
, mii
.fType
, mii
.fState
, mii
.wID
, (LPCSTR
)mii
.dwTypeData
);
2300 ok(mii
.fType
== menu_data
[i
].type
,
2301 "%u: expected fType %04x, got %04x\n", i
, menu_data
[i
].type
, mii
.fType
);
2302 ok(mii
.fState
== menu_data
[i
].state
,
2303 "%u: expected fState %04x, got %04x\n", i
, menu_data
[i
].state
, mii
.fState
);
2304 ok(mii
.wID
== menu_data
[i
].id
,
2305 "%u: expected wID %04x, got %04x\n", i
, menu_data
[i
].id
, mii
.wID
);
2306 ok(mii
.cch
== strlen(menu_data
[i
].str
),
2307 "%u: expected cch %u, got %u\n", i
, (UINT
)strlen(menu_data
[i
].str
), mii
.cch
);
2308 ok(!strcmp(mii
.dwTypeData
, menu_data
[i
].str
),
2309 "%u: expected dwTypeData %s, got %s\n", i
, menu_data
[i
].str
, (LPCSTR
)mii
.dwTypeData
);
2321 static HMENU
create_menu_from_data(const struct menu_data
*item
, INT item_count
)
2327 hmenu
= CreateMenu();
2330 for (i
= 0; i
< item_count
; i
++)
2332 SetLastError(0xdeadbeef);
2333 ret
= AppendMenu(hmenu
, item
[i
].type
, item
[i
].id
, item
[i
].str
);
2334 ok(ret
, "%d: AppendMenu(%04x, %04x, %p) error %u\n",
2335 i
, item
[i
].type
, item
[i
].id
, item
[i
].str
, GetLastError());
2340 static void compare_menu_data(HMENU hmenu
, const struct menu_data
*item
, INT item_count
)
2345 count
= GetMenuItemCount(hmenu
);
2346 ok(count
== item_count
, "expected %d, got %d menu items\n", count
, item_count
);
2348 for (i
= 0; i
< count
; i
++)
2353 memset(&mii
, 0, sizeof(mii
));
2354 mii
.cbSize
= sizeof(mii
);
2355 mii
.dwTypeData
= buf
;
2356 mii
.cch
= sizeof(buf
);
2357 mii
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
| MIIM_BITMAP
;
2358 ret
= GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
);
2359 ok(ret
, "GetMenuItemInfo(%u) failed\n", i
);
2361 trace("item #%u: fType %04x, fState %04x, wID %04x, hbmp %p\n",
2362 i
, mii
.fType
, mii
.fState
, mii
.wID
, mii
.hbmpItem
);
2364 ok(mii
.fType
== item
[i
].type
,
2365 "%u: expected fType %04x, got %04x\n", i
, item
[i
].type
, mii
.fType
);
2366 ok(mii
.wID
== item
[i
].id
,
2367 "%u: expected wID %04x, got %04x\n", i
, item
[i
].id
, mii
.wID
);
2368 if (item
[i
].type
& (MF_BITMAP
| MF_SEPARATOR
))
2370 /* For some reason Windows sets high word to not 0 for
2373 ok(LOWORD(mii
.hbmpItem
) == LOWORD(item
[i
].str
),
2374 "%u: expected hbmpItem %p, got %p\n", i
, item
[i
].str
, mii
.hbmpItem
);
2378 ok(mii
.cch
== strlen(item
[i
].str
),
2379 "%u: expected cch %u, got %u\n", i
, (UINT
)strlen(item
[i
].str
), mii
.cch
);
2380 ok(!strcmp(mii
.dwTypeData
, item
[i
].str
),
2381 "%u: expected dwTypeData %s, got %s\n", i
, item
[i
].str
, (LPCSTR
)mii
.dwTypeData
);
2386 static void test_InsertMenu(void)
2388 /* Note: XP treats only bitmap handles 1 - 6 as "magic" ones
2389 * regardless of their id.
2391 static const struct menu_data in1
[] =
2393 { MF_STRING
, 1, "File" },
2394 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(1) },
2395 { MF_STRING
|MF_HELP
, 2, "Help" }
2397 static const struct menu_data out1
[] =
2399 { MF_STRING
, 1, "File" },
2400 { MF_STRING
|MF_HELP
, 2, "Help" },
2401 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(1) }
2403 static const struct menu_data in2
[] =
2405 { MF_STRING
, 1, "File" },
2406 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(100) },
2407 { MF_STRING
|MF_HELP
, 2, "Help" }
2409 static const struct menu_data out2
[] =
2411 { MF_STRING
, 1, "File" },
2412 { MF_BITMAP
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(100) },
2413 { MF_STRING
|MF_HELP
, 2, "Help" }
2415 static const struct menu_data in3
[] =
2417 { MF_STRING
, 1, "File" },
2418 { MF_SEPARATOR
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(1) },
2419 { MF_STRING
|MF_HELP
, 2, "Help" }
2421 static const struct menu_data out3
[] =
2423 { MF_STRING
, 1, "File" },
2424 { MF_SEPARATOR
|MF_HELP
, SC_CLOSE
, MAKEINTRESOURCE(0) },
2425 { MF_STRING
|MF_HELP
, 2, "Help" },
2427 static const struct menu_data in4
[] =
2429 { MF_STRING
, 1, "File" },
2430 { MF_BITMAP
|MF_HELP
, 1, MAKEINTRESOURCE(1) },
2431 { MF_STRING
|MF_HELP
, 2, "Help" }
2433 static const struct menu_data out4
[] =
2435 { MF_STRING
, 1, "File" },
2436 { MF_STRING
|MF_HELP
, 2, "Help" },
2437 { MF_BITMAP
|MF_HELP
, 1, MAKEINTRESOURCE(1) }
2441 #define create_menu(a) create_menu_from_data((a), sizeof(a)/sizeof((a)[0]))
2442 #define compare_menu(h, a) compare_menu_data((h), (a), sizeof(a)/sizeof((a)[0]))
2444 hmenu
= create_menu(in1
);
2445 compare_menu(hmenu
, out1
);
2448 hmenu
= create_menu(in2
);
2449 compare_menu(hmenu
, out2
);
2452 hmenu
= create_menu(in3
);
2453 compare_menu(hmenu
, out3
);
2456 hmenu
= create_menu(in4
);
2457 compare_menu(hmenu
, out4
);
2464 static void test_menu_getmenuinfo(void)
2472 hmenu
= CreateMenu();
2474 /* test some parameter errors */
2475 SetLastError(0xdeadbeef);
2476 ret
= pGetMenuInfo( hmenu
, NULL
);
2477 gle
= GetLastError();
2478 ok( !ret
, "GetMenuInfo() should have failed\n");
2479 ok( gle
== ERROR_INVALID_PARAMETER
||
2480 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2481 "GetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2482 SetLastError(0xdeadbeef);
2484 ret
= pGetMenuInfo( hmenu
, &mi
);
2485 gle
= GetLastError();
2486 ok( !ret
, "GetMenuInfo() should have failed\n");
2487 ok( gle
== ERROR_INVALID_PARAMETER
||
2488 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2489 "GetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2490 SetLastError(0xdeadbeef);
2491 mi
.cbSize
= sizeof( MENUINFO
);
2492 ret
= pGetMenuInfo( hmenu
, &mi
);
2493 gle
= GetLastError();
2494 ok( ret
, "GetMenuInfo() should have succeeded\n");
2495 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2496 SetLastError(0xdeadbeef);
2498 ret
= pGetMenuInfo( NULL
, &mi
);
2499 gle
= GetLastError();
2500 ok( !ret
, "GetMenuInfo() should have failed\n");
2501 ok( gle
== ERROR_INVALID_PARAMETER
||
2502 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2503 "GetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2505 DestroyMenu( hmenu
);
2509 static void test_menu_setmenuinfo(void)
2511 HMENU hmenu
, hsubmenu
;
2513 MENUITEMINFOA mii
= {sizeof( MENUITEMINFOA
)};
2517 /* create a menu with a submenu */
2518 hmenu
= CreateMenu();
2519 hsubmenu
= CreateMenu();
2520 assert( hmenu
&& hsubmenu
);
2521 mii
.fMask
= MIIM_SUBMENU
;
2522 mii
.hSubMenu
= hsubmenu
;
2523 ret
= InsertMenuItem( hmenu
, 0, FALSE
, &mii
);
2524 ok( ret
, "InsertMenuItem failed with error %d\n", GetLastError());
2525 /* test some parameter errors */
2526 SetLastError(0xdeadbeef);
2527 ret
= pSetMenuInfo( hmenu
, NULL
);
2528 gle
= GetLastError();
2529 ok( !ret
, "SetMenuInfo() should have failed\n");
2530 ok( gle
== ERROR_INVALID_PARAMETER
||
2531 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2532 "SetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2533 SetLastError(0xdeadbeef);
2535 ret
= pSetMenuInfo( hmenu
, &mi
);
2536 gle
= GetLastError();
2537 ok( !ret
, "SetMenuInfo() should have failed\n");
2538 ok( gle
== ERROR_INVALID_PARAMETER
||
2539 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2540 "SetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2541 SetLastError(0xdeadbeef);
2542 mi
.cbSize
= sizeof( MENUINFO
);
2543 ret
= pSetMenuInfo( hmenu
, &mi
);
2544 gle
= GetLastError();
2545 ok( ret
, "SetMenuInfo() should have succeeded\n");
2546 ok( gle
== 0xdeadbeef, "SetMenuInfo() error got %u\n", gle
);
2547 SetLastError(0xdeadbeef);
2549 ret
= pSetMenuInfo( NULL
, &mi
);
2550 gle
= GetLastError();
2551 ok( !ret
, "SetMenuInfo() should have failed\n");
2552 ok( gle
== ERROR_INVALID_PARAMETER
||
2553 broken(gle
== 0xdeadbeef), /* Win98, WinME */
2554 "SetMenuInfo() error got %u expected %u\n", gle
, ERROR_INVALID_PARAMETER
);
2555 /* functional tests */
2556 /* menu and submenu should have the CHECKORBMP style bit cleared */
2557 SetLastError(0xdeadbeef);
2558 mi
.cbSize
= sizeof( MENUINFO
);
2559 mi
.fMask
= MIM_STYLE
;
2560 ret
= pGetMenuInfo( hmenu
, &mi
);
2561 gle
= GetLastError();
2562 ok( ret
, "GetMenuInfo() should have succeeded\n");
2563 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2564 ok( !(mi
.dwStyle
& MNS_CHECKORBMP
), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2565 SetLastError(0xdeadbeef);
2566 mi
.cbSize
= sizeof( MENUINFO
);
2567 mi
.fMask
= MIM_STYLE
;
2568 ret
= pGetMenuInfo( hsubmenu
, &mi
);
2569 gle
= GetLastError();
2570 ok( ret
, "GetMenuInfo() should have succeeded\n");
2571 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2572 ok( !(mi
.dwStyle
& MNS_CHECKORBMP
), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2574 SetLastError(0xdeadbeef);
2575 mi
.cbSize
= sizeof( MENUINFO
);
2576 mi
.fMask
= MIM_STYLE
| MIM_APPLYTOSUBMENUS
;
2577 mi
.dwStyle
= MNS_CHECKORBMP
;
2578 ret
= pSetMenuInfo( hmenu
, &mi
);
2579 gle
= GetLastError();
2580 ok( ret
, "SetMenuInfo() should have succeeded\n");
2581 ok( gle
== 0xdeadbeef, "SetMenuInfo() error got %u\n", gle
);
2582 /* Now both menus should have the MNS_CHECKORBMP style bit set */
2583 SetLastError(0xdeadbeef);
2584 mi
.cbSize
= sizeof( MENUINFO
);
2585 mi
.fMask
= MIM_STYLE
;
2586 ret
= pGetMenuInfo( hmenu
, &mi
);
2587 gle
= GetLastError();
2588 ok( ret
, "GetMenuInfo() should have succeeded\n");
2589 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2590 ok( mi
.dwStyle
& MNS_CHECKORBMP
, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2591 SetLastError(0xdeadbeef);
2592 mi
.cbSize
= sizeof( MENUINFO
);
2593 mi
.fMask
= MIM_STYLE
;
2594 ret
= pGetMenuInfo( hsubmenu
, &mi
);
2595 gle
= GetLastError();
2596 ok( ret
, "GetMenuInfo() should have succeeded\n");
2597 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2598 ok( mi
.dwStyle
& MNS_CHECKORBMP
, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2599 /* now repeat that without the APPLYTOSUBMENUS flag and another style bit */
2600 SetLastError(0xdeadbeef);
2601 mi
.cbSize
= sizeof( MENUINFO
);
2602 mi
.fMask
= MIM_STYLE
;
2603 mi
.dwStyle
= MNS_NOCHECK
;
2604 ret
= pSetMenuInfo( hmenu
, &mi
);
2605 gle
= GetLastError();
2606 ok( ret
, "SetMenuInfo() should have succeeded\n");
2607 ok( gle
== 0xdeadbeef, "SetMenuInfo() error got %u\n", gle
);
2608 /* Now only the top menu should have the MNS_NOCHECK style bit set */
2609 SetLastError(0xdeadbeef);
2610 mi
.cbSize
= sizeof( MENUINFO
);
2611 mi
.fMask
= MIM_STYLE
;
2612 ret
= pGetMenuInfo( hmenu
, &mi
);
2613 gle
= GetLastError();
2614 ok( ret
, "GetMenuInfo() should have succeeded\n");
2615 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2616 ok( mi
.dwStyle
& MNS_NOCHECK
, "menustyle was expected to have the MNS_NOCHECK flag\n");
2617 SetLastError(0xdeadbeef);
2618 mi
.cbSize
= sizeof( MENUINFO
);
2619 mi
.fMask
= MIM_STYLE
;
2620 ret
= pGetMenuInfo( hsubmenu
, &mi
);
2621 gle
= GetLastError();
2622 ok( ret
, "GetMenuInfo() should have succeeded\n");
2623 ok( gle
== 0xdeadbeef, "GetMenuInfo() error got %u\n", gle
);
2624 ok( !(mi
.dwStyle
& MNS_NOCHECK
), "menustyle was not expected to have the MNS_NOCHECK flag\n");
2626 DestroyMenu( hsubmenu
);
2627 DestroyMenu( hmenu
);
2633 init_function_pointers();
2635 /* Wine defines MENUITEMINFO for W2K and above. NT4 and below can't
2638 if (correct_behavior())
2640 test_menu_add_string();
2641 test_menu_iteminfo();
2642 test_menu_search_bycommand();
2643 test_CheckMenuRadioItem();
2644 test_menu_resource_layout();
2648 register_menu_check_class();
2650 test_menu_locked_by_window();
2651 test_menu_ownerdraw();
2652 test_menu_bmp_and_string();
2653 /* test Get/SetMenuInfo if available */
2654 if( pGetMenuInfo
&& pSetMenuInfo
) {
2655 test_menu_getmenuinfo();
2656 test_menu_setmenuinfo();
2658 win_skip("Get/SetMenuInfo are not available\n");
2660 win_skip("SendInput is not available\n");
2665 test_menu_hilitemenuitem();