user32/tests: Fix a couple of failing menu tests.
[wine/multimedia.git] / dlls / user32 / tests / menu.c
blobf51bf48c203566a0cdbc5077a72aac81dfb148c4
1 /*
2 * Unit tests for menus
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
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <assert.h>
29 #define OEMRESOURCE /* For OBM_MNARROW */
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
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); \
50 if(!p ## func) \
51 trace("GetProcAddress(%s) failed\n", #func);
53 GET_PROC(GetMenuInfo)
54 GET_PROC(SendInput)
55 GET_PROC(SetMenuInfo)
57 #undef GET_PROC
60 static BOOL correct_behavior(void)
62 HMENU hmenu;
63 MENUITEMINFO info;
64 BOOL rc;
66 hmenu = CreateMenu();
68 memset(&info, 0, sizeof(MENUITEMINFO));
69 info.cbSize= sizeof(MENUITEMINFO);
70 SetLastError(0xdeadbeef);
71 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info);
72 /* Win9x : 0xdeadbeef
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");
79 DestroyMenu(hmenu);
80 return FALSE;
83 DestroyMenu(hmenu);
84 return TRUE;
87 static LRESULT WINAPI menu_check_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
89 switch (msg)
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
102 * our own type */
103 typedef struct
105 DWORD type;
106 union
108 MOUSEINPUT mi;
109 KEYBDINPUT ki;
110 HARDWAREINPUT hi;
111 } u;
112 } TEST_INPUT;
114 /* globals to communicate between test and wndproc */
116 static BOOL bMenuVisible;
117 static BOOL got_input;
118 static HMENU hMenus[4];
120 #define MOD_SIZE 10
121 #define MOD_NRMENUS 8
123 /* menu texts with their sizes */
124 static struct {
125 LPCSTR text;
126 SIZE size; /* size of text up to any \t */
127 SIZE sc_size; /* size of the short-cut */
128 } MOD_txtsizes[] = {
129 { "Pinot &Noir" },
130 { "&Merlot\bF4" },
131 { "Shira&z\tAlt+S" },
132 { "" },
133 { NULL }
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)
147 switch (msg)
149 case WM_MEASUREITEM:
151 MEASUREITEMSTRUCT* pmis = (MEASUREITEMSTRUCT*)lparam;
152 if( winetest_debug)
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;
158 return TRUE;
160 case WM_DRAWITEM:
162 DRAWITEMSTRUCT * pdis;
163 TEXTMETRIC tm;
164 HPEN oldpen;
165 char chrs[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
166 SIZE sz;
167 int i;
168 pdis = (DRAWITEMSTRUCT *) lparam;
169 if( winetest_debug) {
170 RECT rc;
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++) {
186 char buf[100], *p;
187 RECT rc={0,0,0,0};
188 strcpy( buf, MOD_txtsizes[i].text);
189 if( ( p = strchr( buf, '\t'))) {
190 *p = '\0';
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;
211 return TRUE;
213 case WM_ENTERIDLE:
215 ok( lparam || broken(!lparam), /* win9x, nt4 */
216 "Menu window handle is NULL!\n");
217 PostMessage(hwnd, WM_CANCELMODE, 0, 0);
218 return TRUE;
222 return DefWindowProc(hwnd, msg, wparam, lparam);
225 static void register_menu_check_class(void)
227 WNDCLASS wc =
230 menu_check_wnd_proc,
233 GetModuleHandle(NULL),
234 NULL,
235 LoadCursor(NULL, IDC_ARROW),
236 (HBRUSH)(COLOR_BTNFACE+1),
237 NULL,
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)
248 BOOL ret;
249 HMENU hmenu;
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);
264 todo_wine {
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);
273 todo_wine {
274 ok(ret, "WM_INITMENU should have been sent\n");
277 DestroyWindow(hwnd);
280 static void test_menu_ownerdraw(void)
282 int i,j,k;
283 BOOL ret;
284 HMENU hmenu;
285 LONG leftcol;
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());
290 if( !hwnd) return;
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;}
295 k=0;
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));
300 k++;
301 ok( ret, "AppendMenu failed for %d\n", k-1);
303 MOD_maxid = 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);
335 /* test width */
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);
339 /* and height */
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;}
350 MOD_maxid=1;
351 for(i=0;i<2;i++) {
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());
358 /* test width */
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);
362 /* test hight */
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);
367 /* clean up */
368 ret = DestroyMenu(hmenu);
369 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
370 DestroyWindow(hwnd);
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)
378 BOOL ret;
379 HMENU hmenu, submenu;
380 MENUITEMINFO mii={ sizeof( MENUITEMINFO )};
381 MENUINFO mi;
382 RECT rc;
383 CHAR text_copy[16];
384 int hastab, expect;
385 int failed = 0;
387 MOD_GotDrawItemMsg = FALSE;
388 mii.fMask = MIIM_FTYPE | MIIM_DATA | MIIM_STATE;
389 mii.fType = 0;
390 /* check the menu item unless MNS_CHECKORBMP is set */
391 mii.fState = (mnuopt != 2 ? MFS_CHECKED : MFS_UNCHECKED);
392 mii.dwItemData =0;
393 MODsizes[0] = bmpsize;
394 hastab = 0;
395 if( text ) {
396 char *p;
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;
406 if( hbmp) {
407 mii.fMask |= MIIM_BITMAP;
408 mii.hbmpItem = hbmp;
410 submenu = CreateMenu();
411 ok( submenu != 0, "CreateMenu failed with error %d\n", GetLastError());
412 if( ispop)
413 hmenu = CreatePopupMenu();
414 else
415 hmenu = CreateMenu();
416 ok( hmenu != 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
417 if( hassub) {
418 mii.fMask |= MIIM_SUBMENU;
419 mii.hSubMenu = submenu;
421 if( mnuopt) {
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());
431 failed = !ret;
432 if( winetest_debug) {
433 HDC hdc=GetDC(hwnd);
434 RECT rc = {100, 50, 400, 70};
435 char buf[100];
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);
442 if(ispop)
443 ret = TrackPopupMenu( hmenu, 0x100, 100,100, 0, hwnd, NULL);
444 else {
445 ret = SetMenu( hwnd, hmenu);
446 ok(ret, "SetMenu failed with error %d\n", GetLastError());
447 DrawMenuBar( hwnd);
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 */
455 if( ispop)
456 expect = ( text || hbmp ?
457 4 + (mnuopt != 1 ? GetSystemMetrics(SM_CXMENUCHECK) : 0)
458 : 0) +
459 arrowwidth + MOD_avec + (hbmp ?
460 ((int)hbmp<0||(int)hbmp>12 ? bmpsize.cx + 2 : GetSystemMetrics( SM_CXMENUSIZE) + 2)
461 : 0) +
462 (text && hastab ? /* TAB space */
463 MOD_avec + ( hastab==2 ? sc_size.cx : 0) : 0) +
464 (text ? 2 + (text[0] ? size.cx :0): 0) ;
465 else
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 */
473 if( ispop)
474 expect = max( ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 : 0),
475 max( (text ? max( 2 + size.cy, MOD_hic + 4) : 0),
476 (hbmp ?
477 ((int)hbmp<0||(int)hbmp>12 ?
478 bmpsize.cy + 2
479 : GetSystemMetrics( SM_CYMENUSIZE) + 2)
480 : 0)));
481 else
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 */
490 /* horizontal */
491 if (!ispop)
492 expect = 3;
493 else if (mnuopt == 0)
494 expect = 4 + GetSystemMetrics(SM_CXMENUCHECK);
495 else if (mnuopt == 1)
496 expect = 4;
497 else /* mnuopt == 2 */
498 expect = 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);
502 /* vertical */
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 */
510 if( failed) {
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);
522 /* clean up */
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)
532 BYTE bmfill[300];
533 HBITMAP hbm_arrow;
534 BITMAP bm;
535 INT arrowwidth;
536 HWND hwnd;
537 HMENU hsysmenu;
538 MENUINFO mi= {sizeof(MENUINFO)};
539 MENUITEMINFOA mii= {sizeof(MENUITEMINFOA)};
540 int count, szidx, txtidx, bmpidx, hassub, mnuopt, ispop;
542 if( !pGetMenuInfo)
544 win_skip("GetMenuInfo is not available\n");
545 return;
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());
556 if( !hwnd) return;
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;
561 mi.dwStyle = 0;
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;
566 mii.hbmpItem = NULL;
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);
573 if( winetest_debug)
574 trace(" check %d,%d arrow %d avechar %d\n",
575 GetSystemMetrics(SM_CXMENUCHECK ),
576 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
577 count = 0;
578 MOD_maxid = 0;
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 */
593 if( !ispop &&
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,
599 bitmaps[bmpidx],
600 bmsizes[szidx],
601 MOD_txtsizes[txtidx].text,
602 MOD_txtsizes[txtidx].size,
603 MOD_txtsizes[txtidx].sc_size);
608 DeleteObject( hbm);
611 /* clean up */
612 DestroyWindow(hwnd);
615 static void test_menu_add_string( void )
617 HMENU hmenu;
618 MENUITEMINFO info;
619 BOOL rc;
620 int ret;
622 char string[0x80];
623 char string2[0x80];
625 char strback[0x80];
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;
636 info.cch = 6;
637 info.dwItemData = 0;
638 info.wID = 1;
639 info.fState = 0;
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;
647 string[0] = 0;
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");
670 else
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");
733 else
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 )
749 WCHAR *p = dst;
750 while ((*p++ = *src++));
751 return dst;
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 )
758 MENUITEMINFOA info;
759 BOOL ret;
761 /* magic bitmap handle to test smaller cbSize */
762 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
763 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
764 else
765 info.cbSize = sizeof(info);
766 info.fMask = mask;
767 info.fType = type;
768 info.fState = state;
769 info.wID = id;
770 info.hSubMenu = submenu;
771 info.hbmpChecked = checked;
772 info.hbmpUnchecked = unchecked;
773 info.dwItemData = data;
774 info.dwTypeData = type_data;
775 info.cch = len;
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 )
789 MENUITEMINFOA info;
790 BOOL ret;
791 WCHAR buffer[80];
793 SetLastError( 0xdeadbeef );
794 memset( &info, 0xcc, sizeof(info) );
795 info.cbSize = sizeof(info);
796 info.fMask = mask;
797 info.dwTypeData = type_data;
798 info.cch = in_len;
800 ret = ansi ? GetMenuItemInfoA( hmenu, 0, TRUE, &info ) :
801 GetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW *)&info );
802 if (!expect)
804 ok_(__FILE__, line)( !ret, "GetMenuItemInfo should have failed.\n" );
805 return;
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 );
814 if (mask & MIIM_ID)
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 );
836 if (expname)
838 if(ansi)
839 ok_(__FILE__, line)( !strncmp( expname, info.dwTypeData, out_len ),
840 "menu item name differed from '%s' '%s'\n", expname, info.dwTypeData );
841 else
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 );
848 if (expstring)
849 ok_(__FILE__, line)( ret, "GetMenuString failed, err %u\n", GetLastError());
850 else
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 )
857 BOOL ret;
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 )
870 MENUITEMINFOA info;
871 BOOL ret;
873 /* magic bitmap handle to test smaller cbSize */
874 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
875 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
876 else
877 info.cbSize = sizeof(info);
878 info.fMask = mask;
879 info.fType = type;
880 info.fState = state;
881 info.wID = id;
882 info.hSubMenu = submenu;
883 info.hbmpChecked = checked;
884 info.hbmpUnchecked = unchecked;
885 info.dwItemData = data;
886 info.dwTypeData = type_data;
887 info.cch = len;
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 )
909 #define TMII_DONE \
910 RemoveMenu(hmenu, 0, TRUE );\
911 DestroyMenu( hmenu );\
912 DestroyMenu( submenu );
914 /* modify menu */
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 )
923 #define OK 1
924 #define ER 0
927 static void test_menu_iteminfo( void )
929 int ansi = TRUE;
930 char txtA[]="wine";
931 char initA[]="XYZ";
932 char emptyA[]="";
933 WCHAR txtW[]={'W','i','n','e',0};
934 WCHAR initW[]={'X','Y','Z',0};
935 WCHAR emptyW[]={0};
936 void *txt, *init, *empty, *string;
937 HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
938 char stringA[0x80];
939 HMENU hmenu, submenu=CreateMenu();
940 HBITMAP dummy_hbm = (HBITMAP)(ULONG_PTR)0xdeadbeef;
942 do {
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,
951 txt, OK, OK );
952 TMII_DONE
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,
956 NULL, OK, ER );
957 TMII_DONE
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,
961 NULL, OK, ER );
962 TMII_DONE
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,
966 NULL, OK, ER );
967 TMII_DONE
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,
972 NULL, OK, OK );
973 TMII_DONE
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,
977 txt, OK, OK );
978 TMII_DONE
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,
982 txt, OK, OK );
983 TMII_DONE
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,
987 NULL, OK, ER );
988 TMII_DONE
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 );
991 TMII_DONE
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,
995 NULL, ER, OK );
996 TMII_DONE
997 TMII_INSMI( MIIM_TYPE|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
998 TMII_DONE
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,
1002 NULL, ER, OK );
1003 TMII_DONE
1004 TMII_INSMI( MIIM_TYPE|MIIM_BITMAP, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, hbm, ER );
1005 TMII_DONE
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,
1010 txt, OK, OK );
1011 TMII_DONE
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,
1015 txt, OK, OK );
1016 TMII_DONE
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,
1020 txt, OK, OK );
1021 TMII_DONE
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,
1025 txt, OK, OK );
1026 TMII_DONE
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,
1032 txt, OK, OK );
1033 TMII_DONE
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,
1038 empty, OK, ER );
1039 TMII_DONE
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,
1043 empty, OK, ER );
1044 TMII_DONE
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,
1048 init, OK, ER );
1049 TMII_DONE
1050 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1051 TMII_GMII ( 0, 80,
1052 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1053 init, OK, OK );
1054 TMII_DONE
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,
1059 txt, OK, OK );
1060 TMII_DONE
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,
1065 NULL, OK, OK );
1066 TMII_DONE
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,
1070 empty, OK, ER );
1071 TMII_DONE
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,
1075 empty, OK, ER );
1076 TMII_DONE
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,
1082 NULL, OK, ER );
1083 TMII_DONE
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,
1087 init, OK, ER );
1088 TMII_DONE
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 );
1091 TMII_DONE
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,
1096 init, OK, ER );
1097 TMII_DONE
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 );
1100 TMII_DONE
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,
1106 init, OK, ER );
1107 TMII_DONE
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,
1111 init, OK, ER );
1112 TMII_DONE
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,
1117 empty, OK, ER );
1118 TMII_GMII ( MIIM_SUBMENU|MIIM_FTYPE, 80,
1119 MFT_SEPARATOR, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1120 empty, OK, ER );
1121 TMII_DONE
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 );
1124 TMII_DONE
1125 /* Separator */
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,
1129 NULL, OK, ER );
1130 TMII_DONE
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,
1134 NULL, OK, ER );
1135 TMII_DONE
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,
1141 txt, OK, OK );
1142 TMII_DONE
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,
1147 txt, OK, OK );
1148 TMII_DONE
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,
1153 NULL, OK, OK );
1154 TMII_DONE
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,
1158 NULL, OK, OK );
1159 TMII_DONE
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,
1163 NULL, OK, OK );
1164 TMII_DONE
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,
1169 NULL, OK, OK );
1170 TMII_DONE
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,
1174 NULL, OK, OK );
1175 TMII_DONE
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,
1179 NULL, OK, OK );
1180 TMII_DONE
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,
1185 NULL, OK, OK );
1186 TMII_DONE
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,
1192 txt, OK, OK );
1193 TMII_DONE
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,
1199 empty, OK, ER );
1200 TMII_DONE
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,
1205 empty, OK, ER );
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,
1209 txt, OK, OK );
1210 TMII_DONE
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,
1216 empty, OK, ER );
1217 TMII_DONE
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,
1223 empty, OK, ER );
1224 TMII_DONE
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,
1230 empty, OK, ER );
1231 TMII_DONE
1232 /* ask nothing */
1233 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1234 TMII_GMII ( 0, 80,
1235 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1236 init, OK, OK );
1237 TMII_DONE
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,
1242 NULL, OK, ER );
1243 TMII_DONE
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,
1247 init, OK, ER );
1248 TMII_DONE
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,
1252 txt, OK, OK );
1253 TMII_DONE
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,
1257 NULL, OK, OK );
1258 TMII_DONE
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,
1262 NULL, OK, OK );
1263 TMII_DONE
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,
1267 NULL, OK, OK );
1268 TMII_DONE
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,
1273 NULL, OK, ER );
1274 TMII_DONE
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,
1278 NULL, OK, ER );
1279 TMII_DONE
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,
1283 NULL, OK, ER );
1284 TMII_DONE
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,
1290 txt, OK, OK );
1291 TMII_DONE
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,
1297 txt, OK, OK );
1298 TMII_GMII ( MIIM_TYPE, 80,
1299 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1300 txt, OK, OK );
1301 TMII_DONE
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,
1307 txt, OK, OK );
1308 TMII_DONE
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,
1314 init, OK, ER );
1315 TMII_DONE
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,
1323 NULL, OK, OK );
1324 TMII_DONE
1325 /* Type flags */
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,
1329 NULL, OK, OK );
1330 TMII_DONE
1331 /* State flags */
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,
1336 NULL, OK, OK );
1337 TMII_DONE
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,
1343 NULL, OK, OK );
1344 TMII_DONE
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,
1350 NULL, OK, OK );
1351 TMII_GMII ( MIIM_TYPE, 80,
1352 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1353 NULL, OK, OK );
1354 TMII_GMII ( MIIM_FTYPE, 80,
1355 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1356 NULL, OK, OK );
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,
1360 NULL, OK, OK );
1361 TMII_DONE
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,
1369 NULL, OK, OK );
1370 TMII_DONE
1371 /* Type flags */
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,
1375 NULL, OK, OK );
1376 TMII_DONE
1377 /* State flags */
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,
1382 NULL, OK, OK );
1383 TMII_DONE
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,
1389 NULL, OK, OK );
1390 TMII_DONE
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,
1396 NULL, OK, OK );
1397 TMII_GMII ( MIIM_TYPE, 80,
1398 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1399 NULL, OK, OK );
1400 TMII_GMII ( MIIM_FTYPE, 80,
1401 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1402 NULL, OK, OK );
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,
1406 NULL, OK, OK );
1407 TMII_DONE
1408 } while( !(ansi = !ansi) );
1409 DeleteObject( hbm);
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;
1419 MENUITEMINFO info;
1420 BOOL rc;
1421 UINT id;
1422 char strback[0x80];
1423 char strIn[0x80];
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 );
1446 strback[0] = 0x00;
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 );
1459 strback[0] = 0x00;
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 );
1485 strback[0] = 0x00;
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 );
1499 strback[0] = 0x00;
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 );
1525 strback[0] = 0x00;
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 );
1551 strback[0] = 0x00;
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 );
1602 strback[0] = 0x00;
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 );
1651 strback[0] = 0x00;
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 );
1663 strback[0] = 0x00;
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;
1697 info.wID = 101;
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 */
1703 info.wID = 0;
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));
1710 strback[0] = 0x00;
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));
1723 strback[0] = 0x00;
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);
1734 DestroyMenu(hmenu);
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] */
1742 UINT uItem;
1745 static struct menu_mouse_tests_s {
1746 DWORD type;
1747 struct menu_item_pair_s menu_item_pairs[5]; /* for mousing */
1748 WORD wVk[5]; /* keys */
1749 BOOL bMenuVisible;
1750 BOOL _todo_wine;
1751 } menu_tests[] = {
1752 /* for each test, send keys or clicks and check for menu visibility */
1753 { INPUT_KEYBOARD, {{0}}, {VK_LMENU, 0}, TRUE, FALSE }, /* test 0 */
1754 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
1755 { INPUT_KEYBOARD, {{0}}, {VK_LMENU, 0}, TRUE, FALSE },
1756 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
1757 { INPUT_KEYBOARD, {{0}}, {VK_LMENU, 0}, TRUE, FALSE },
1758 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
1759 { INPUT_KEYBOARD, {{0}}, {VK_LMENU, 'M', 0}, TRUE, FALSE },
1760 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, VK_ESCAPE, 0}, FALSE, FALSE },
1761 { INPUT_KEYBOARD, {{0}}, {VK_LMENU, 'M', VK_ESCAPE, 0}, TRUE, FALSE },
1762 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
1763 { INPUT_KEYBOARD, {{0}}, {VK_LMENU, 'M', 0}, TRUE, FALSE },
1764 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
1765 { INPUT_KEYBOARD, {{0}}, {VK_LMENU, 'M', 0}, TRUE, FALSE },
1766 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
1767 { INPUT_KEYBOARD, {{0}}, {VK_LMENU, 'M', 'P', 0}, TRUE, FALSE },
1768 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
1769 { INPUT_KEYBOARD, {{0}}, {VK_LMENU, '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 },
1783 { -1 }
1786 static void send_key(WORD wVk)
1788 TEST_INPUT i[2];
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 void click_menu(HANDLE hWnd, struct menu_item_pair_s *mi)
1798 HMENU hMenu = hMenus[mi->uMenu];
1799 TEST_INPUT i[3];
1800 MSG msg;
1801 RECT r;
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;
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 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 );
1824 static DWORD WINAPI test_menu_input_thread(LPVOID lpParameter)
1826 int i, j;
1827 HANDLE hWnd = lpParameter;
1829 Sleep(500);
1830 /* mixed keyboard/mouse test */
1831 for (i = 0; menu_tests[i].type != -1; i++)
1833 int elapsed = 0;
1835 got_input = i && menu_tests[i-1].bMenuVisible;
1837 if (menu_tests[i].type == INPUT_KEYBOARD)
1838 for (j = 0; menu_tests[i].wVk[j] != 0; j++)
1839 send_key(menu_tests[i].wVk[j]);
1840 else
1841 for (j = 0; menu_tests[i].menu_item_pairs[j].uMenu != 0; j++)
1842 click_menu(hWnd, &menu_tests[i].menu_item_pairs[j]);
1844 while (menu_tests[i].bMenuVisible != bMenuVisible)
1846 if (elapsed > 200)
1847 break;
1848 elapsed += 20;
1849 Sleep(20);
1852 if (!got_input)
1854 skip( "test %u: didn't receive input\n", i );
1855 return 0;
1858 if (menu_tests[i]._todo_wine)
1860 todo_wine {
1861 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
1864 else
1865 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
1867 return 0;
1870 static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam,
1871 LPARAM lParam)
1873 switch (msg) {
1874 case WM_ENTERMENULOOP:
1875 bMenuVisible = TRUE;
1876 break;
1877 case WM_EXITMENULOOP:
1878 bMenuVisible = FALSE;
1879 break;
1880 case WM_KEYDOWN:
1881 case WM_SYSKEYDOWN:
1882 case WM_MOUSEMOVE:
1883 case WM_LBUTTONDOWN:
1884 case WM_LBUTTONUP:
1885 case WM_NCMOUSEMOVE:
1886 case WM_NCLBUTTONDOWN:
1887 case WM_NCLBUTTONUP:
1888 got_input = TRUE;
1889 /* fall through */
1890 default:
1891 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
1893 return 0;
1896 static void test_menu_input(void) {
1897 MSG msg;
1898 WNDCLASSA wclass;
1899 HINSTANCE hInstance = GetModuleHandleA( NULL );
1900 HANDLE hThread, hWnd;
1901 DWORD tid;
1903 wclass.lpszClassName = "MenuTestClass";
1904 wclass.style = CS_HREDRAW | CS_VREDRAW;
1905 wclass.lpfnWndProc = WndProc;
1906 wclass.hInstance = hInstance;
1907 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
1908 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
1909 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
1910 wclass.lpszMenuName = 0;
1911 wclass.cbClsExtra = 0;
1912 wclass.cbWndExtra = 0;
1913 assert (RegisterClassA( &wclass ));
1914 assert (hWnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
1915 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
1916 400, 200, NULL, NULL, hInstance, NULL) );
1918 /* fixed menus */
1919 hMenus[3] = CreatePopupMenu();
1920 AppendMenu(hMenus[3], MF_STRING, 0, "&Enabled");
1921 AppendMenu(hMenus[3], MF_STRING|MF_DISABLED, 0, "&Disabled");
1923 hMenus[2] = CreatePopupMenu();
1924 AppendMenu(hMenus[2], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[3], "&Popup");
1925 AppendMenu(hMenus[2], MF_STRING, 0, "&Enabled");
1926 AppendMenu(hMenus[2], MF_STRING|MF_DISABLED, 0, "&Disabled");
1928 hMenus[1] = CreateMenu();
1929 AppendMenu(hMenus[1], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[2], "&Menu");
1930 AppendMenu(hMenus[1], MF_STRING, 0, "&Enabled");
1931 AppendMenu(hMenus[1], MF_STRING|MF_DISABLED, 0, "&Disabled");
1933 SetMenu(hWnd, hMenus[1]);
1934 ShowWindow(hWnd, SW_SHOW);
1935 UpdateWindow(hWnd);
1937 hThread = CreateThread(NULL, 0, test_menu_input_thread, hWnd, 0, &tid);
1938 while(1)
1940 if (WAIT_TIMEOUT != WaitForSingleObject(hThread, 50))
1941 break;
1942 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
1944 DestroyWindow(hWnd);
1947 static void test_menu_flags( void )
1949 HMENU hMenu, hPopupMenu;
1951 hMenu = CreateMenu();
1952 hPopupMenu = CreatePopupMenu();
1954 AppendMenu(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
1956 AppendMenu(hPopupMenu, MF_STRING | MF_HILITE | MF_DEFAULT, 101, "Item 1");
1957 InsertMenu(hPopupMenu, 1, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 102, "Item 2");
1958 AppendMenu(hPopupMenu, MF_STRING, 103, "Item 3");
1959 ModifyMenu(hPopupMenu, 2, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 103, "Item 3");
1961 ok(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_HILITE,
1962 "AppendMenu should accept MF_HILITE\n");
1963 ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
1964 "InsertMenu should accept MF_HILITE\n");
1965 ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
1966 "ModifyMenu should accept MF_HILITE\n");
1968 ok(!(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_DEFAULT),
1969 "AppendMenu must not accept MF_DEFAULT\n");
1970 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_DEFAULT),
1971 "InsertMenu must not accept MF_DEFAULT\n");
1972 ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_DEFAULT),
1973 "ModifyMenu must not accept MF_DEFAULT\n");
1975 DestroyMenu(hMenu);
1978 static void test_menu_hilitemenuitem( void )
1980 HMENU hMenu, hPopupMenu;
1981 WNDCLASSA wclass;
1982 HWND hWnd;
1984 wclass.lpszClassName = "HiliteMenuTestClass";
1985 wclass.style = CS_HREDRAW | CS_VREDRAW;
1986 wclass.lpfnWndProc = WndProc;
1987 wclass.hInstance = GetModuleHandleA( NULL );
1988 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
1989 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
1990 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
1991 wclass.lpszMenuName = 0;
1992 wclass.cbClsExtra = 0;
1993 wclass.cbWndExtra = 0;
1994 assert (RegisterClassA( &wclass ));
1995 assert (hWnd = CreateWindowA( wclass.lpszClassName, "HiliteMenuTest",
1996 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
1997 400, 200, NULL, NULL, wclass.hInstance, NULL) );
1999 hMenu = CreateMenu();
2000 hPopupMenu = CreatePopupMenu();
2002 AppendMenu(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2004 AppendMenu(hPopupMenu, MF_STRING, 101, "Item 1");
2005 AppendMenu(hPopupMenu, MF_STRING, 102, "Item 2");
2006 AppendMenu(hPopupMenu, MF_STRING, 103, "Item 3");
2008 SetMenu(hWnd, hMenu);
2010 /* test invalid arguments */
2012 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2013 "HiliteMenuItem: Item 2 is hilited\n");
2015 SetLastError(0xdeadbeef);
2016 todo_wine
2018 ok(!HiliteMenuItem(NULL, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2019 "HiliteMenuItem: call should have failed.\n");
2021 ok(GetLastError() == 0xdeadbeef || /* 9x */
2022 GetLastError() == ERROR_INVALID_WINDOW_HANDLE /* NT */,
2023 "HiliteMenuItem: expected error ERROR_INVALID_WINDOW_HANDLE, got: %d\n", GetLastError());
2025 SetLastError(0xdeadbeef);
2026 ok(!HiliteMenuItem(hWnd, NULL, 1, MF_HILITE | MF_BYPOSITION),
2027 "HiliteMenuItem: call should have failed.\n");
2028 ok(GetLastError() == 0xdeadbeef || /* 9x */
2029 GetLastError() == ERROR_INVALID_MENU_HANDLE /* NT */,
2030 "HiliteMenuItem: expected error ERROR_INVALID_MENU_HANDLE, got: %d\n", GetLastError());
2032 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2033 "HiliteMenuItem: Item 2 is hilited\n");
2035 /* either MF_HILITE or MF_UNHILITE *and* MF_BYCOMMAND or MF_BYPOSITION need to be set */
2037 SetLastError(0xdeadbeef);
2038 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_BYPOSITION),
2039 "HiliteMenuItem: call should have succeeded.\n");
2040 ok(GetLastError() == 0xdeadbeef,
2041 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2043 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2044 "HiliteMenuItem: Item 2 is hilited\n");
2046 SetLastError(0xdeadbeef);
2047 todo_wine
2049 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE),
2050 "HiliteMenuItem: call should have succeeded.\n");
2052 ok(GetLastError() == 0xdeadbeef,
2053 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2055 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2056 "HiliteMenuItem: Item 2 is hilited\n");
2058 /* hilite a menu item (by position) */
2060 SetLastError(0xdeadbeef);
2061 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2062 "HiliteMenuItem: call should not have failed.\n");
2063 ok(GetLastError() == 0xdeadbeef,
2064 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2066 todo_wine
2068 ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2069 "HiliteMenuItem: Item 2 is not hilited\n");
2072 /* unhilite a menu item (by position) */
2074 SetLastError(0xdeadbeef);
2075 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_UNHILITE | MF_BYPOSITION),
2076 "HiliteMenuItem: call should not have failed.\n");
2077 ok(GetLastError() == 0xdeadbeef,
2078 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2080 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2081 "HiliteMenuItem: Item 2 is hilited\n");
2083 /* hilite a menu item (by command) */
2085 SetLastError(0xdeadbeef);
2086 ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_HILITE | MF_BYCOMMAND),
2087 "HiliteMenuItem: call should not have failed.\n");
2088 ok(GetLastError() == 0xdeadbeef,
2089 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2091 todo_wine
2093 ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2094 "HiliteMenuItem: Item 3 is not hilited\n");
2097 /* unhilite a menu item (by command) */
2099 SetLastError(0xdeadbeef);
2100 ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_UNHILITE | MF_BYCOMMAND),
2101 "HiliteMenuItem: call should not have failed.\n");
2102 ok(GetLastError() == 0xdeadbeef,
2103 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2105 ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE),
2106 "HiliteMenuItem: Item 3 is hilited\n");
2108 DestroyWindow(hWnd);
2111 static void check_menu_items(HMENU hmenu, UINT checked_cmd, UINT checked_type,
2112 UINT checked_state)
2114 INT i, count;
2116 count = GetMenuItemCount(hmenu);
2117 ok (count != -1, "GetMenuItemCount returned -1\n");
2119 for (i = 0; i < count; i++)
2121 BOOL ret;
2122 MENUITEMINFO mii;
2124 memset(&mii, 0, sizeof(mii));
2125 mii.cbSize = sizeof(mii);
2126 mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU;
2127 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2128 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2129 #if 0
2130 trace("item #%u: fType %04x, fState %04x, wID %u, hSubMenu %p\n",
2131 i, mii.fType, mii.fState, mii.wID, mii.hSubMenu);
2132 #endif
2133 if (mii.hSubMenu)
2135 ok(mii.wID == (UINT_PTR)mii.hSubMenu, "id %u: wID should be equal to hSubMenu\n", checked_cmd);
2136 check_menu_items(mii.hSubMenu, checked_cmd, checked_type, checked_state);
2138 else
2140 if (mii.wID == checked_cmd)
2142 ok(mii.fType == checked_type, "id %u: expected fType %04x, got %04x\n", checked_cmd, checked_type, mii.fType);
2143 ok(mii.fState == checked_state, "id %u: expected fState %04x, got %04x\n", checked_cmd, checked_state, mii.fState);
2144 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2146 else
2148 ok(mii.fType != MFT_RADIOCHECK, "id %u: not expected fType MFT_RADIOCHECK on cmd %u\n", checked_cmd, mii.wID);
2150 if (mii.fType == MFT_SEPARATOR)
2152 ok(mii.fState == MFS_GRAYED, "id %u: expected fState MFS_GRAYED, got %04x\n", checked_cmd, mii.fState);
2153 ok(mii.wID == 0, "id %u: expected wID 0, got %u\n", checked_cmd, mii.wID);
2155 else
2157 ok(mii.fState == 0, "id %u: expected fState 0, got %04x\n", checked_cmd, mii.fState);
2158 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2165 static void clear_ftype_and_state(HMENU hmenu, UINT id, UINT flags)
2167 BOOL ret;
2168 MENUITEMINFO mii;
2170 memset(&mii, 0, sizeof(mii));
2171 mii.cbSize = sizeof(mii);
2172 mii.fMask = MIIM_FTYPE | MIIM_STATE;
2173 ret = SetMenuItemInfo(hmenu, id, (flags & MF_BYPOSITION) != 0, &mii);
2174 ok(ret, "SetMenuItemInfo(%u) failed\n", id);
2177 static void test_CheckMenuRadioItem(void)
2179 BOOL ret;
2180 HMENU hmenu;
2182 hmenu = LoadMenu(GetModuleHandle(0), MAKEINTRESOURCE(1));
2183 assert(hmenu != 0);
2185 check_menu_items(hmenu, -1, 0, 0);
2187 ret = CheckMenuRadioItem(hmenu, 100, 100, 100, MF_BYCOMMAND);
2188 ok(ret, "CheckMenuRadioItem failed\n");
2189 check_menu_items(hmenu, 100, MFT_RADIOCHECK, MFS_CHECKED);
2191 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2192 ret = CheckMenuRadioItem(hmenu, 100, 100, -1, MF_BYCOMMAND);
2193 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2194 check_menu_items(hmenu, 100, MFT_RADIOCHECK, 0);
2196 /* clear check */
2197 clear_ftype_and_state(hmenu, 100, MF_BYCOMMAND);
2198 check_menu_items(hmenu, -1, 0, 0);
2200 /* first and checked items are on different menus */
2201 ret = CheckMenuRadioItem(hmenu, 0, 300, 202, MF_BYCOMMAND);
2202 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2203 check_menu_items(hmenu, -1, 0, 0);
2205 ret = CheckMenuRadioItem(hmenu, 200, 300, 202, MF_BYCOMMAND);
2206 ok(ret, "CheckMenuRadioItem failed\n");
2207 check_menu_items(hmenu, 202, MFT_RADIOCHECK, MFS_CHECKED);
2209 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2210 ret = CheckMenuRadioItem(hmenu, 202, 202, -1, MF_BYCOMMAND);
2211 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2212 check_menu_items(hmenu, 202, MFT_RADIOCHECK, 0);
2214 /* clear check */
2215 clear_ftype_and_state(hmenu, 202, MF_BYCOMMAND);
2216 check_menu_items(hmenu, -1, 0, 0);
2218 /* just for fun, try to check separator */
2219 ret = CheckMenuRadioItem(hmenu, 0, 300, 0, MF_BYCOMMAND);
2220 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2221 check_menu_items(hmenu, -1, 0, 0);
2224 static void test_menu_resource_layout(void)
2226 static const struct
2228 MENUITEMTEMPLATEHEADER mith;
2229 WORD data[14];
2230 } menu_template =
2232 { 0, 0 }, /* versionNumber, offset */
2234 /* mtOption, mtID, mtString[] '\0' terminated */
2235 MF_STRING, 1, 'F', 0,
2236 MF_STRING, 2, 0,
2237 MF_SEPARATOR, 3, 0,
2238 /* MF_SEPARATOR, 4, 'S', 0, FIXME: Wine ignores 'S' */
2239 MF_STRING|MF_GRAYED|MF_END, 5, 'E', 0
2242 static const struct
2244 UINT type, state, id;
2245 const char *str;
2246 } menu_data[] =
2248 { MF_STRING, MF_ENABLED, 1, "F" },
2249 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 2, "" },
2250 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 3, "" },
2251 /*{ MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 4, "S" }, FIXME: Wine ignores 'S'*/
2252 { MF_STRING, MF_GRAYED, 5, "E" },
2253 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 6, "" },
2254 { MF_STRING, MF_ENABLED, 7, "" },
2255 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 8, "" }
2257 HMENU hmenu;
2258 INT count, i;
2259 BOOL ret;
2261 hmenu = LoadMenuIndirect(&menu_template);
2262 ok(hmenu != 0, "LoadMenuIndirect error %u\n", GetLastError());
2264 ret = AppendMenu(hmenu, MF_STRING, 6, NULL);
2265 ok(ret, "AppendMenu failed\n");
2266 ret = AppendMenu(hmenu, MF_STRING, 7, "\0");
2267 ok(ret, "AppendMenu failed\n");
2268 ret = AppendMenu(hmenu, MF_SEPARATOR, 8, "separator");
2269 ok(ret, "AppendMenu failed\n");
2271 count = GetMenuItemCount(hmenu);
2272 ok(count == sizeof(menu_data)/sizeof(menu_data[0]),
2273 "expected %u menu items, got %u\n",
2274 (UINT)(sizeof(menu_data)/sizeof(menu_data[0])), count);
2276 for (i = 0; i < count; i++)
2278 char buf[20];
2279 MENUITEMINFO mii;
2281 memset(&mii, 0, sizeof(mii));
2282 mii.cbSize = sizeof(mii);
2283 mii.dwTypeData = buf;
2284 mii.cch = sizeof(buf);
2285 mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_STRING;
2286 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2287 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2288 #if 0
2289 trace("item #%u: fType %04x, fState %04x, wID %u, dwTypeData %s\n",
2290 i, mii.fType, mii.fState, mii.wID, (LPCSTR)mii.dwTypeData);
2291 #endif
2292 ok(mii.fType == menu_data[i].type,
2293 "%u: expected fType %04x, got %04x\n", i, menu_data[i].type, mii.fType);
2294 ok(mii.fState == menu_data[i].state,
2295 "%u: expected fState %04x, got %04x\n", i, menu_data[i].state, mii.fState);
2296 ok(mii.wID == menu_data[i].id,
2297 "%u: expected wID %04x, got %04x\n", i, menu_data[i].id, mii.wID);
2298 ok(mii.cch == strlen(menu_data[i].str),
2299 "%u: expected cch %u, got %u\n", i, (UINT)strlen(menu_data[i].str), mii.cch);
2300 ok(!strcmp(mii.dwTypeData, menu_data[i].str),
2301 "%u: expected dwTypeData %s, got %s\n", i, menu_data[i].str, (LPCSTR)mii.dwTypeData);
2304 DestroyMenu(hmenu);
2307 struct menu_data
2309 UINT type, id;
2310 const char *str;
2313 static HMENU create_menu_from_data(const struct menu_data *item, INT item_count)
2315 HMENU hmenu;
2316 INT i;
2317 BOOL ret;
2319 hmenu = CreateMenu();
2320 assert(hmenu != 0);
2322 for (i = 0; i < item_count; i++)
2324 SetLastError(0xdeadbeef);
2325 ret = AppendMenu(hmenu, item[i].type, item[i].id, item[i].str);
2326 ok(ret, "%d: AppendMenu(%04x, %04x, %p) error %u\n",
2327 i, item[i].type, item[i].id, item[i].str, GetLastError());
2329 return hmenu;
2332 static void compare_menu_data(HMENU hmenu, const struct menu_data *item, INT item_count)
2334 INT count, i;
2335 BOOL ret;
2337 count = GetMenuItemCount(hmenu);
2338 ok(count == item_count, "expected %d, got %d menu items\n", count, item_count);
2340 for (i = 0; i < count; i++)
2342 char buf[20];
2343 MENUITEMINFO mii;
2345 memset(&mii, 0, sizeof(mii));
2346 mii.cbSize = sizeof(mii);
2347 mii.dwTypeData = buf;
2348 mii.cch = sizeof(buf);
2349 mii.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_BITMAP;
2350 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2351 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2352 #if 0
2353 trace("item #%u: fType %04x, fState %04x, wID %04x, hbmp %p\n",
2354 i, mii.fType, mii.fState, mii.wID, mii.hbmpItem);
2355 #endif
2356 ok(mii.fType == item[i].type,
2357 "%u: expected fType %04x, got %04x\n", i, item[i].type, mii.fType);
2358 ok(mii.wID == item[i].id,
2359 "%u: expected wID %04x, got %04x\n", i, item[i].id, mii.wID);
2360 if (item[i].type & (MF_BITMAP | MF_SEPARATOR))
2362 /* For some reason Windows sets high word to not 0 for
2363 * not "magic" ids.
2365 ok(LOWORD(mii.hbmpItem) == LOWORD(item[i].str),
2366 "%u: expected hbmpItem %p, got %p\n", i, item[i].str, mii.hbmpItem);
2368 else
2370 ok(mii.cch == strlen(item[i].str),
2371 "%u: expected cch %u, got %u\n", i, (UINT)strlen(item[i].str), mii.cch);
2372 ok(!strcmp(mii.dwTypeData, item[i].str),
2373 "%u: expected dwTypeData %s, got %s\n", i, item[i].str, (LPCSTR)mii.dwTypeData);
2378 static void test_InsertMenu(void)
2380 /* Note: XP treats only bitmap handles 1 - 6 as "magic" ones
2381 * regardless of their id.
2383 static const struct menu_data in1[] =
2385 { MF_STRING, 1, "File" },
2386 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) },
2387 { MF_STRING|MF_HELP, 2, "Help" }
2389 static const struct menu_data out1[] =
2391 { MF_STRING, 1, "File" },
2392 { MF_STRING|MF_HELP, 2, "Help" },
2393 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) }
2395 static const struct menu_data in2[] =
2397 { MF_STRING, 1, "File" },
2398 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(100) },
2399 { MF_STRING|MF_HELP, 2, "Help" }
2401 static const struct menu_data out2[] =
2403 { MF_STRING, 1, "File" },
2404 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(100) },
2405 { MF_STRING|MF_HELP, 2, "Help" }
2407 static const struct menu_data in3[] =
2409 { MF_STRING, 1, "File" },
2410 { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) },
2411 { MF_STRING|MF_HELP, 2, "Help" }
2413 static const struct menu_data out3[] =
2415 { MF_STRING, 1, "File" },
2416 { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(0) },
2417 { MF_STRING|MF_HELP, 2, "Help" },
2419 static const struct menu_data in4[] =
2421 { MF_STRING, 1, "File" },
2422 { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCE(1) },
2423 { MF_STRING|MF_HELP, 2, "Help" }
2425 static const struct menu_data out4[] =
2427 { MF_STRING, 1, "File" },
2428 { MF_STRING|MF_HELP, 2, "Help" },
2429 { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCE(1) }
2431 HMENU hmenu;
2433 #define create_menu(a) create_menu_from_data((a), sizeof(a)/sizeof((a)[0]))
2434 #define compare_menu(h, a) compare_menu_data((h), (a), sizeof(a)/sizeof((a)[0]))
2436 hmenu = create_menu(in1);
2437 compare_menu(hmenu, out1);
2438 DestroyMenu(hmenu);
2440 hmenu = create_menu(in2);
2441 compare_menu(hmenu, out2);
2442 DestroyMenu(hmenu);
2444 hmenu = create_menu(in3);
2445 compare_menu(hmenu, out3);
2446 DestroyMenu(hmenu);
2448 hmenu = create_menu(in4);
2449 compare_menu(hmenu, out4);
2450 DestroyMenu(hmenu);
2452 #undef create_menu
2453 #undef compare_menu
2456 static void test_menu_getmenuinfo(void)
2458 HMENU hmenu;
2459 MENUINFO mi = {0};
2460 BOOL ret;
2461 DWORD gle;
2463 /* create a menu */
2464 hmenu = CreateMenu();
2465 assert( hmenu);
2466 /* test some parameter errors */
2467 SetLastError(0xdeadbeef);
2468 ret = pGetMenuInfo( hmenu, NULL);
2469 gle= GetLastError();
2470 ok( !ret, "GetMenuInfo() should have failed\n");
2471 ok( gle == ERROR_INVALID_PARAMETER ||
2472 broken(gle == 0xdeadbeef), /* Win98, WinME */
2473 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2474 SetLastError(0xdeadbeef);
2475 mi.cbSize = 0;
2476 ret = pGetMenuInfo( hmenu, &mi);
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);
2483 mi.cbSize = sizeof( MENUINFO);
2484 ret = pGetMenuInfo( hmenu, &mi);
2485 gle= GetLastError();
2486 ok( ret, "GetMenuInfo() should have succeeded\n");
2487 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2488 SetLastError(0xdeadbeef);
2489 mi.cbSize = 0;
2490 ret = pGetMenuInfo( NULL, &mi);
2491 gle= GetLastError();
2492 ok( !ret, "GetMenuInfo() should have failed\n");
2493 ok( gle == ERROR_INVALID_PARAMETER ||
2494 broken(gle == 0xdeadbeef), /* Win98, WinME */
2495 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2496 /* clean up */
2497 DestroyMenu( hmenu);
2498 return;
2501 static void test_menu_setmenuinfo(void)
2503 HMENU hmenu, hsubmenu;
2504 MENUINFO mi = {0};
2505 MENUITEMINFOA mii = {sizeof( MENUITEMINFOA)};
2506 BOOL ret;
2507 DWORD gle;
2509 /* create a menu with a submenu */
2510 hmenu = CreateMenu();
2511 hsubmenu = CreateMenu();
2512 assert( hmenu && hsubmenu);
2513 mii.fMask = MIIM_SUBMENU;
2514 mii.hSubMenu = hsubmenu;
2515 ret = InsertMenuItem( hmenu, 0, FALSE, &mii);
2516 ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
2517 /* test some parameter errors */
2518 SetLastError(0xdeadbeef);
2519 ret = pSetMenuInfo( hmenu, NULL);
2520 gle= GetLastError();
2521 ok( !ret, "SetMenuInfo() should have failed\n");
2522 ok( gle == ERROR_INVALID_PARAMETER ||
2523 broken(gle == 0xdeadbeef), /* Win98, WinME */
2524 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2525 SetLastError(0xdeadbeef);
2526 mi.cbSize = 0;
2527 ret = pSetMenuInfo( hmenu, &mi);
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);
2534 mi.cbSize = sizeof( MENUINFO);
2535 ret = pSetMenuInfo( hmenu, &mi);
2536 gle= GetLastError();
2537 ok( ret, "SetMenuInfo() should have succeeded\n");
2538 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2539 SetLastError(0xdeadbeef);
2540 mi.cbSize = 0;
2541 ret = pSetMenuInfo( NULL, &mi);
2542 gle= GetLastError();
2543 ok( !ret, "SetMenuInfo() should have failed\n");
2544 ok( gle == ERROR_INVALID_PARAMETER ||
2545 broken(gle == 0xdeadbeef), /* Win98, WinME */
2546 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2547 /* functional tests */
2548 /* menu and submenu should have the CHECKORBMP style bit cleared */
2549 SetLastError(0xdeadbeef);
2550 mi.cbSize = sizeof( MENUINFO);
2551 mi.fMask = MIM_STYLE;
2552 ret = pGetMenuInfo( hmenu, &mi);
2553 gle= GetLastError();
2554 ok( ret, "GetMenuInfo() should have succeeded\n");
2555 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2556 ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2557 SetLastError(0xdeadbeef);
2558 mi.cbSize = sizeof( MENUINFO);
2559 mi.fMask = MIM_STYLE;
2560 ret = pGetMenuInfo( hsubmenu, &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 /* SetMenuInfo() */
2566 SetLastError(0xdeadbeef);
2567 mi.cbSize = sizeof( MENUINFO);
2568 mi.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS;
2569 mi.dwStyle = MNS_CHECKORBMP;
2570 ret = pSetMenuInfo( hmenu, &mi);
2571 gle= GetLastError();
2572 ok( ret, "SetMenuInfo() should have succeeded\n");
2573 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2574 /* Now both menus should have the MNS_CHECKORBMP style bit set */
2575 SetLastError(0xdeadbeef);
2576 mi.cbSize = sizeof( MENUINFO);
2577 mi.fMask = MIM_STYLE;
2578 ret = pGetMenuInfo( hmenu, &mi);
2579 gle= GetLastError();
2580 ok( ret, "GetMenuInfo() should have succeeded\n");
2581 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2582 ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2583 SetLastError(0xdeadbeef);
2584 mi.cbSize = sizeof( MENUINFO);
2585 mi.fMask = MIM_STYLE;
2586 ret = pGetMenuInfo( hsubmenu, &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 /* now repeat that without the APPLYTOSUBMENUS flag and another style bit */
2592 SetLastError(0xdeadbeef);
2593 mi.cbSize = sizeof( MENUINFO);
2594 mi.fMask = MIM_STYLE ;
2595 mi.dwStyle = MNS_NOCHECK;
2596 ret = pSetMenuInfo( hmenu, &mi);
2597 gle= GetLastError();
2598 ok( ret, "SetMenuInfo() should have succeeded\n");
2599 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2600 /* Now only the top menu should have the MNS_NOCHECK style bit set */
2601 SetLastError(0xdeadbeef);
2602 mi.cbSize = sizeof( MENUINFO);
2603 mi.fMask = MIM_STYLE;
2604 ret = pGetMenuInfo( hmenu, &mi);
2605 gle= GetLastError();
2606 ok( ret, "GetMenuInfo() should have succeeded\n");
2607 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2608 ok( mi.dwStyle & MNS_NOCHECK, "menustyle was expected to have the MNS_NOCHECK flag\n");
2609 SetLastError(0xdeadbeef);
2610 mi.cbSize = sizeof( MENUINFO);
2611 mi.fMask = MIM_STYLE;
2612 ret = pGetMenuInfo( hsubmenu, &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 not expected to have the MNS_NOCHECK flag\n");
2617 /* clean up */
2618 DestroyMenu( hsubmenu);
2619 DestroyMenu( hmenu);
2620 return;
2623 START_TEST(menu)
2625 init_function_pointers();
2627 /* Wine defines MENUITEMINFO for W2K and above. NT4 and below can't
2628 * handle that.
2630 if (correct_behavior())
2632 test_menu_add_string();
2633 test_menu_iteminfo();
2634 test_menu_search_bycommand();
2635 test_CheckMenuRadioItem();
2636 test_menu_resource_layout();
2637 test_InsertMenu();
2640 register_menu_check_class();
2642 test_menu_locked_by_window();
2643 test_menu_ownerdraw();
2644 test_menu_bmp_and_string();
2645 /* test Get/SetMenuInfo if available */
2646 if( pGetMenuInfo && pSetMenuInfo) {
2647 test_menu_getmenuinfo();
2648 test_menu_setmenuinfo();
2649 } else
2650 win_skip("Get/SetMenuInfo are not available\n");
2651 if( !pSendInput)
2652 win_skip("SendInput is not available\n");
2653 else
2654 test_menu_input();
2655 test_menu_flags();
2657 test_menu_hilitemenuitem();