push eb25bf65c4616aa55a810ed5c29198b1a080b208
[wine/hacks.git] / dlls / user32 / tests / menu.c
blob06fa35018fa82af2bf1c249ce552eb1558a77fad
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 static int gflag_initmenupopup,
144 gflag_entermenuloop,
145 gflag_initmenu;
147 /* wndproc used by test_menu_ownerdraw() */
148 static LRESULT WINAPI menu_ownerdraw_wnd_proc(HWND hwnd, UINT msg,
149 WPARAM wparam, LPARAM lparam)
151 switch (msg)
153 case WM_INITMENUPOPUP:
154 gflag_initmenupopup++;
155 break;
156 case WM_ENTERMENULOOP:
157 gflag_entermenuloop++;
158 break;
159 case WM_INITMENU:
160 gflag_initmenu++;
161 break;
162 case WM_MEASUREITEM:
164 MEASUREITEMSTRUCT* pmis = (MEASUREITEMSTRUCT*)lparam;
165 if( winetest_debug)
166 trace("WM_MEASUREITEM received data %lx size %dx%d\n",
167 pmis->itemData, pmis->itemWidth, pmis->itemHeight);
168 MOD_odheight = pmis->itemHeight;
169 pmis->itemWidth = MODsizes[pmis->itemData].cx;
170 pmis->itemHeight = MODsizes[pmis->itemData].cy;
171 return TRUE;
173 case WM_DRAWITEM:
175 DRAWITEMSTRUCT * pdis;
176 TEXTMETRIC tm;
177 HPEN oldpen;
178 char chrs[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
179 SIZE sz;
180 int i;
181 pdis = (DRAWITEMSTRUCT *) lparam;
182 if( winetest_debug) {
183 RECT rc;
184 GetMenuItemRect( hwnd, (HMENU)pdis->hwndItem, pdis->itemData ,&rc);
185 trace("WM_DRAWITEM received hwnd %p hmenu %p itemdata %ld item %d rc %d,%d-%d,%d itemrc: %d,%d-%d,%d\n",
186 hwnd, pdis->hwndItem, pdis->itemData, pdis->itemID,
187 pdis->rcItem.left, pdis->rcItem.top,
188 pdis->rcItem.right,pdis->rcItem.bottom,
189 rc.left,rc.top,rc.right,rc.bottom);
190 oldpen=SelectObject( pdis->hDC, GetStockObject(
191 pdis->itemState & ODS_SELECTED ? WHITE_PEN :BLACK_PEN));
192 Rectangle( pdis->hDC, pdis->rcItem.left,pdis->rcItem.top,
193 pdis->rcItem.right,pdis->rcItem.bottom );
194 SelectObject( pdis->hDC, oldpen);
196 /* calculate widths of some menu texts */
197 if( ! MOD_txtsizes[0].size.cx)
198 for(i = 0; MOD_txtsizes[i].text; i++) {
199 char buf[100], *p;
200 RECT rc={0,0,0,0};
201 strcpy( buf, MOD_txtsizes[i].text);
202 if( ( p = strchr( buf, '\t'))) {
203 *p = '\0';
204 DrawText( pdis->hDC, p + 1, -1, &rc,
205 DT_SINGLELINE|DT_CALCRECT);
206 MOD_txtsizes[i].sc_size.cx= rc.right - rc.left;
207 MOD_txtsizes[i].sc_size.cy= rc.bottom - rc.top;
209 DrawText( pdis->hDC, buf, -1, &rc,
210 DT_SINGLELINE|DT_CALCRECT);
211 MOD_txtsizes[i].size.cx= rc.right - rc.left;
212 MOD_txtsizes[i].size.cy= rc.bottom - rc.top;
215 if( pdis->itemData > MOD_maxid) return TRUE;
216 /* store the rectangl */
217 MOD_rc[pdis->itemData] = pdis->rcItem;
218 /* calculate average character width */
219 GetTextExtentPoint( pdis->hDC, chrs, 52, &sz );
220 MOD_avec = (sz.cx + 26)/52;
221 GetTextMetrics( pdis->hDC, &tm);
222 MOD_hic = tm.tmHeight;
223 MOD_GotDrawItemMsg = TRUE;
224 return TRUE;
226 case WM_ENTERIDLE:
228 ok( lparam || broken(!lparam), /* win9x, nt4 */
229 "Menu window handle is NULL!\n");
230 PostMessage(hwnd, WM_CANCELMODE, 0, 0);
231 return TRUE;
235 return DefWindowProc(hwnd, msg, wparam, lparam);
238 static void register_menu_check_class(void)
240 WNDCLASS wc =
243 menu_check_wnd_proc,
246 GetModuleHandle(NULL),
247 NULL,
248 LoadCursor(NULL, IDC_ARROW),
249 (HBRUSH)(COLOR_BTNFACE+1),
250 NULL,
251 TEXT("WineMenuCheck"),
254 atomMenuCheckClass = RegisterClass(&wc);
257 /* demonstrates that windows locks the menu object so that it is still valid
258 * even after a client calls DestroyMenu on it */
259 static void test_menu_locked_by_window(void)
261 BOOL ret;
262 HMENU hmenu;
263 HWND hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
264 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
265 NULL, NULL, NULL, NULL);
266 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
267 hmenu = CreateMenu();
268 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
269 ret = InsertMenu(hmenu, 0, MF_STRING, 0, TEXT("&Test"));
270 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
271 ret = SetMenu(hwnd, hmenu);
272 ok(ret, "SetMenu failed with error %d\n", GetLastError());
273 ret = DestroyMenu(hmenu);
274 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
276 ret = DrawMenuBar(hwnd);
277 todo_wine {
278 ok(ret, "DrawMenuBar failed with error %d\n", GetLastError());
280 ret = IsMenu(GetMenu(hwnd));
281 ok(!ret || broken(ret) /* nt4 */, "Menu handle should have been destroyed\n");
283 SendMessage(hwnd, WM_SYSCOMMAND, SC_KEYMENU, 0);
284 /* did we process the WM_INITMENU message? */
285 ret = GetWindowLongPtr(hwnd, GWLP_USERDATA);
286 todo_wine {
287 ok(ret, "WM_INITMENU should have been sent\n");
290 DestroyWindow(hwnd);
293 static void test_menu_ownerdraw(void)
295 int i,j,k;
296 BOOL ret;
297 HMENU hmenu;
298 LONG leftcol;
299 HWND hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
300 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
301 NULL, NULL, NULL, NULL);
302 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
303 if( !hwnd) return;
304 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
305 hmenu = CreatePopupMenu();
306 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
307 if( !hmenu) { DestroyWindow(hwnd);return;}
308 k=0;
309 for( j=0;j<2;j++) /* create columns */
310 for(i=0;i<2;i++) { /* create rows */
311 ret = AppendMenu( hmenu, MF_OWNERDRAW |
312 (i==0 ? MF_MENUBREAK : 0), k, MAKEINTRESOURCE(k));
313 k++;
314 ok( ret, "AppendMenu failed for %d\n", k-1);
316 MOD_maxid = k-1;
317 assert( k <= sizeof(MOD_rc)/sizeof(RECT));
318 /* display the menu */
319 ret = TrackPopupMenu( hmenu, 0x100, 100,100, 0, hwnd, NULL);
321 /* columns have a 4 pixel gap between them */
322 ok( MOD_rc[0].right + 4 == MOD_rc[2].left,
323 "item rectangles are not separated by 4 pixels space\n");
324 /* height should be what the MEASUREITEM message has returned */
325 ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
326 "menu item has wrong height: %d should be %d\n",
327 MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
328 /* no gaps between the rows */
329 ok( MOD_rc[0].bottom - MOD_rc[1].top == 0,
330 "There should not be a space between the rows, gap is %d\n",
331 MOD_rc[0].bottom - MOD_rc[1].top);
332 /* test the correct value of the item height that was sent
333 * by the WM_MEASUREITEM message */
334 ok( MOD_odheight == HIWORD( GetDialogBaseUnits()) || /* WinNT,2k,XP */
335 MOD_odheight == MOD_hic, /* Win95,98,ME */
336 "Wrong height field in MEASUREITEMSTRUCT, expected %d or %d actual %d\n",
337 HIWORD( GetDialogBaseUnits()), MOD_hic, MOD_odheight);
338 /* test what MF_MENUBREAK did at the first position. Also show
339 * that an MF_SEPARATOR is ignored in the height calculation. */
340 leftcol= MOD_rc[0].left;
341 ModifyMenu( hmenu, 0, MF_BYCOMMAND| MF_OWNERDRAW| MF_SEPARATOR, 0, 0);
342 /* display the menu */
343 ret = TrackPopupMenu( hmenu, 0x100, 100,100, 0, hwnd, NULL);
344 /* left should be 4 pixels less now */
345 ok( leftcol == MOD_rc[0].left + 4,
346 "columns should be 4 pixels to the left (actual %d).\n",
347 leftcol - MOD_rc[0].left);
348 /* test width */
349 ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
350 "width of owner drawn menu item is wrong. Got %d expected %d\n",
351 MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
352 /* and height */
353 ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
354 "Height is incorrect. Got %d expected %d\n",
355 MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
357 /* test width/height of an ownerdraw menu bar as well */
358 ret = DestroyMenu(hmenu);
359 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
360 hmenu = CreateMenu();
361 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
362 if( !hmenu) { DestroyWindow(hwnd);return;}
363 MOD_maxid=1;
364 for(i=0;i<2;i++) {
365 ret = AppendMenu( hmenu, MF_OWNERDRAW , i, 0);
366 ok( ret, "AppendMenu failed for %d\n", i);
368 ret = SetMenu( hwnd, hmenu);
369 UpdateWindow( hwnd); /* hack for wine to draw the window + menu */
370 ok(ret, "SetMenu failed with error %d\n", GetLastError());
371 /* test width */
372 ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
373 "width of owner drawn menu item is wrong. Got %d expected %d\n",
374 MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
375 /* test hight */
376 ok( MOD_rc[0].bottom - MOD_rc[0].top == GetSystemMetrics( SM_CYMENU) - 1,
377 "Height of owner drawn menu item is wrong. Got %d expected %d\n",
378 MOD_rc[0].bottom - MOD_rc[0].top, GetSystemMetrics( SM_CYMENU) - 1);
380 /* clean up */
381 ret = DestroyMenu(hmenu);
382 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
383 DestroyWindow(hwnd);
386 /* helper for test_menu_bmp_and_string() */
387 static void test_mbs_help( int ispop, int hassub, int mnuopt,
388 HWND hwnd, int arrowwidth, int count, HBITMAP hbmp,
389 SIZE bmpsize, LPCSTR text, SIZE size, SIZE sc_size)
391 BOOL ret;
392 HMENU hmenu, submenu;
393 MENUITEMINFO mii={ sizeof( MENUITEMINFO )};
394 MENUINFO mi;
395 RECT rc;
396 CHAR text_copy[16];
397 int hastab, expect;
398 int failed = 0;
400 MOD_GotDrawItemMsg = FALSE;
401 mii.fMask = MIIM_FTYPE | MIIM_DATA | MIIM_STATE;
402 mii.fType = 0;
403 /* check the menu item unless MNS_CHECKORBMP is set */
404 mii.fState = (mnuopt != 2 ? MFS_CHECKED : MFS_UNCHECKED);
405 mii.dwItemData =0;
406 MODsizes[0] = bmpsize;
407 hastab = 0;
408 if( text ) {
409 char *p;
410 mii.fMask |= MIIM_STRING;
411 strcpy(text_copy, text);
412 mii.dwTypeData = text_copy; /* structure member declared non-const */
413 if( ( p = strchr( text, '\t'))) {
414 hastab = *(p + 1) ? 2 : 1;
417 /* tabs don't make sense in menubars */
418 if(hastab && !ispop) return;
419 if( hbmp) {
420 mii.fMask |= MIIM_BITMAP;
421 mii.hbmpItem = hbmp;
423 submenu = CreateMenu();
424 ok( submenu != 0, "CreateMenu failed with error %d\n", GetLastError());
425 if( ispop)
426 hmenu = CreatePopupMenu();
427 else
428 hmenu = CreateMenu();
429 ok( hmenu != 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
430 if( hassub) {
431 mii.fMask |= MIIM_SUBMENU;
432 mii.hSubMenu = submenu;
434 if( mnuopt) {
435 mi.cbSize = sizeof(mi);
436 mi.fMask = MIM_STYLE;
437 pGetMenuInfo( hmenu, &mi);
438 mi.dwStyle |= mnuopt == 1 ? MNS_NOCHECK : MNS_CHECKORBMP;
439 ret = pSetMenuInfo( hmenu, &mi);
440 ok( ret, "SetMenuInfo failed with error %d\n", GetLastError());
442 ret = InsertMenuItem( hmenu, 0, FALSE, &mii);
443 ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
444 failed = !ret;
445 if( winetest_debug) {
446 HDC hdc=GetDC(hwnd);
447 RECT rc = {100, 50, 400, 70};
448 char buf[100];
450 sprintf( buf,"%d text \"%s\" mnuopt %d", count, text ? text: "(nil)", mnuopt);
451 FillRect( hdc, &rc, (HBRUSH) COLOR_WINDOW);
452 TextOut( hdc, 10, 50, buf, strlen( buf));
453 ReleaseDC( hwnd, hdc);
455 if(ispop)
456 ret = TrackPopupMenu( hmenu, 0x100, 100,100, 0, hwnd, NULL);
457 else {
458 ret = SetMenu( hwnd, hmenu);
459 ok(ret, "SetMenu failed with error %d\n", GetLastError());
460 DrawMenuBar( hwnd);
462 ret = GetMenuItemRect( hwnd, hmenu, 0, &rc);
463 if (0) /* comment out menu size checks, behavior is different in almost every Windows version */
464 /* the tests should however succeed on win2000, XP and Wine (at least upto 1.1.15) */
465 /* with a variety of dpi's and desktop font sizes */
467 /* check menu width */
468 if( ispop)
469 expect = ( text || hbmp ?
470 4 + (mnuopt != 1 ? GetSystemMetrics(SM_CXMENUCHECK) : 0)
471 : 0) +
472 arrowwidth + MOD_avec + (hbmp ?
473 ((int)hbmp<0||(int)hbmp>12 ? bmpsize.cx + 2 : GetSystemMetrics( SM_CXMENUSIZE) + 2)
474 : 0) +
475 (text && hastab ? /* TAB space */
476 MOD_avec + ( hastab==2 ? sc_size.cx : 0) : 0) +
477 (text ? 2 + (text[0] ? size.cx :0): 0) ;
478 else
479 expect = !(text || hbmp) ? 0 :
480 ( hbmp ? (text ? 2:0) + bmpsize.cx : 0 ) +
481 (text ? 2 * MOD_avec + (text[0] ? size.cx :0): 0) ;
482 ok( rc.right - rc.left == expect,
483 "menu width wrong, got %d expected %d\n", rc.right - rc.left, expect);
484 failed = failed || !(rc.right - rc.left == expect);
485 /* check menu height */
486 if( ispop)
487 expect = max( ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 : 0),
488 max( (text ? max( 2 + size.cy, MOD_hic + 4) : 0),
489 (hbmp ?
490 ((int)hbmp<0||(int)hbmp>12 ?
491 bmpsize.cy + 2
492 : GetSystemMetrics( SM_CYMENUSIZE) + 2)
493 : 0)));
494 else
495 expect = ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 :
496 max( GetSystemMetrics( SM_CYMENU) - 1, (hbmp ? bmpsize.cy : 0)));
497 ok( rc.bottom - rc.top == expect,
498 "menu height wrong, got %d expected %d (%d)\n",
499 rc.bottom - rc.top, expect, GetSystemMetrics( SM_CYMENU));
500 failed = failed || !(rc.bottom - rc.top == expect);
501 if( hbmp == HBMMENU_CALLBACK && MOD_GotDrawItemMsg) {
502 /* check the position of the bitmap */
503 /* horizontal */
504 if (!ispop)
505 expect = 3;
506 else if (mnuopt == 0)
507 expect = 4 + GetSystemMetrics(SM_CXMENUCHECK);
508 else if (mnuopt == 1)
509 expect = 4;
510 else /* mnuopt == 2 */
511 expect = 2;
512 ok( expect == MOD_rc[0].left,
513 "bitmap left is %d expected %d\n", MOD_rc[0].left, expect);
514 failed = failed || !(expect == MOD_rc[0].left);
515 /* vertical */
516 expect = (rc.bottom - rc.top - MOD_rc[0].bottom + MOD_rc[0].top) / 2;
517 ok( expect == MOD_rc[0].top,
518 "bitmap top is %d expected %d\n", MOD_rc[0].top, expect);
519 failed = failed || !(expect == MOD_rc[0].top);
522 /* if there was a failure, report details */
523 if( failed) {
524 trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
525 count, (ispop? "POPUP": "MENUBAR"),text ? text: "(nil)", hbmp, bmpsize.cx, bmpsize.cy,
526 size.cx, size.cy, sc_size.cx, mnuopt, hastab);
527 trace(" check %d,%d arrow %d avechar %d\n",
528 GetSystemMetrics(SM_CXMENUCHECK ),
529 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
530 if( hbmp == HBMMENU_CALLBACK)
531 trace( " rc %d,%d-%d,%d bmp.rc %d,%d-%d,%d\n",
532 rc.left, rc.top, rc.top, rc.bottom, MOD_rc[0].left,
533 MOD_rc[0].top,MOD_rc[0].right, MOD_rc[0].bottom);
535 /* clean up */
536 ret = DestroyMenu(submenu);
537 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
538 ret = DestroyMenu(hmenu);
539 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
543 static void test_menu_bmp_and_string(void)
545 BYTE bmfill[300];
546 HBITMAP hbm_arrow;
547 BITMAP bm;
548 INT arrowwidth;
549 HWND hwnd;
550 HMENU hsysmenu;
551 MENUINFO mi= {sizeof(MENUINFO)};
552 MENUITEMINFOA mii= {sizeof(MENUITEMINFOA)};
553 int count, szidx, txtidx, bmpidx, hassub, mnuopt, ispop;
555 if( !pGetMenuInfo)
557 win_skip("GetMenuInfo is not available\n");
558 return;
561 memset( bmfill, 0xcc, sizeof( bmfill));
562 hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL, WS_SYSMENU |
563 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
564 NULL, NULL, NULL, NULL);
565 hbm_arrow=LoadBitmap( 0, (CHAR*)OBM_MNARROW);
566 GetObject( hbm_arrow, sizeof(bm), &bm);
567 arrowwidth = bm.bmWidth;
568 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
569 if( !hwnd) return;
570 /* test system menu */
571 hsysmenu = GetSystemMenu( hwnd, FALSE);
572 ok( hsysmenu != NULL, "GetSystemMenu failed with error %d\n", GetLastError());
573 mi.fMask = MIM_STYLE;
574 mi.dwStyle = 0;
575 ok( pGetMenuInfo( hsysmenu, &mi), "GetMenuInfo failed gle=%d\n", GetLastError());
576 ok( MNS_CHECKORBMP == mi.dwStyle, "System Menu Style is %08x, without the bit %08x\n",
577 mi.dwStyle, MNS_CHECKORBMP);
578 mii.fMask = MIIM_BITMAP;
579 mii.hbmpItem = NULL;
580 ok( GetMenuItemInfoA( hsysmenu, SC_CLOSE, FALSE, &mii), "GetMenuItemInfoA failed gle=%d\n", GetLastError());
581 ok( HBMMENU_POPUP_CLOSE == mii.hbmpItem, "Item info did not get the right hbitmap: got %p expected %p\n",
582 mii.hbmpItem, HBMMENU_POPUP_CLOSE);
584 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
586 if( winetest_debug)
587 trace(" check %d,%d arrow %d avechar %d\n",
588 GetSystemMetrics(SM_CXMENUCHECK ),
589 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
590 count = 0;
591 MOD_maxid = 0;
592 for( ispop=1; ispop >= 0; ispop--){
593 static SIZE bmsizes[]= {
594 {10,10},{38,38},{1,30},{55,5}};
595 for( szidx=0; szidx < sizeof( bmsizes) / sizeof( SIZE); szidx++) {
596 HBITMAP hbm = CreateBitmap( bmsizes[szidx].cx, bmsizes[szidx].cy,1,1,bmfill);
597 HBITMAP bitmaps[] = { HBMMENU_CALLBACK, hbm, HBMMENU_POPUP_CLOSE, NULL };
598 ok( hbm != 0, "CreateBitmap failed err %d\n", GetLastError());
599 for( txtidx = 0; txtidx < sizeof(MOD_txtsizes)/sizeof(MOD_txtsizes[0]); txtidx++) {
600 for( hassub = 0; hassub < 2 ; hassub++) { /* add submenu item */
601 for( mnuopt = 0; mnuopt < 3 ; mnuopt++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
602 for( bmpidx = 0; bmpidx <sizeof(bitmaps)/sizeof(HBITMAP); bmpidx++) {
603 /* no need to test NULL bitmaps of several sizes */
604 if( !bitmaps[bmpidx] && szidx > 0) continue;
605 /* the HBMMENU_POPUP not to test for menu bars */
606 if( !ispop &&
607 bitmaps[bmpidx] >= HBMMENU_POPUP_CLOSE &&
608 bitmaps[bmpidx] <= HBMMENU_POPUP_MINIMIZE) continue;
609 if( !ispop && hassub) continue;
610 test_mbs_help( ispop, hassub, mnuopt,
611 hwnd, arrowwidth, ++count,
612 bitmaps[bmpidx],
613 bmsizes[szidx],
614 MOD_txtsizes[txtidx].text,
615 MOD_txtsizes[txtidx].size,
616 MOD_txtsizes[txtidx].sc_size);
621 DeleteObject( hbm);
624 /* clean up */
625 DestroyWindow(hwnd);
628 static void test_menu_add_string( void )
630 HMENU hmenu;
631 MENUITEMINFO info;
632 BOOL rc;
633 int ret;
635 char string[0x80];
636 char string2[0x80];
638 char strback[0x80];
639 WCHAR strbackW[0x80];
640 static CHAR blah[] = "blah";
641 static const WCHAR expectedString[] = {'D','u','m','m','y',' ','s','t','r','i','n','g', 0};
643 hmenu = CreateMenu();
645 memset( &info, 0, sizeof info );
646 info.cbSize = sizeof info;
647 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_ID;
648 info.dwTypeData = blah;
649 info.cch = 6;
650 info.dwItemData = 0;
651 info.wID = 1;
652 info.fState = 0;
653 InsertMenuItem(hmenu, 0, TRUE, &info );
655 memset( &info, 0, sizeof info );
656 info.cbSize = sizeof info;
657 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_DATA | MIIM_ID;
658 info.dwTypeData = string;
659 info.cch = sizeof string;
660 string[0] = 0;
661 GetMenuItemInfo( hmenu, 0, TRUE, &info );
663 ok( !strcmp( string, "blah" ), "menu item name differed\n");
665 /* Test combination of ownerdraw and strings with GetMenuItemString(A/W) */
666 strcpy(string, "Dummy string");
667 memset(&info, 0x00, sizeof(info));
668 info.cbSize= sizeof(MENUITEMINFO);
669 info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
670 info.fType= MFT_OWNERDRAW;
671 info.dwTypeData= string;
672 rc = InsertMenuItem( hmenu, 0, TRUE, &info );
673 ok (rc, "InsertMenuItem failed\n");
675 strcpy(string,"Garbage");
676 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
677 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
679 SetLastError(0xdeadbeef);
680 ret = GetMenuStringW( hmenu, 0, strbackW, 99, MF_BYPOSITION );
681 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
682 win_skip("GetMenuStringW is not implemented\n");
683 else
685 ok (ret, "GetMenuStringW on ownerdraw entry failed\n");
686 ok (!lstrcmpW( strbackW, expectedString ), "Menu text from Unicode version incorrect\n");
689 /* Just change ftype to string and see what text is stored */
690 memset(&info, 0x00, sizeof(info));
691 info.cbSize= sizeof(MENUITEMINFO);
692 info.fMask= MIIM_FTYPE; /* Set string type */
693 info.fType= MFT_STRING;
694 info.dwTypeData= (char *)0xdeadbeef;
695 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
696 ok (rc, "SetMenuItemInfo failed\n");
698 /* Did we keep the old dwTypeData? */
699 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
700 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
702 /* Ensure change to bitmap type fails */
703 memset(&info, 0x00, sizeof(info));
704 info.cbSize= sizeof(MENUITEMINFO);
705 info.fMask= MIIM_FTYPE; /* Set as bitmap type */
706 info.fType= MFT_BITMAP;
707 info.dwTypeData= (char *)0xdeadbee2;
708 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
709 ok (!rc, "SetMenuItemInfo unexpectedly worked\n");
711 /* Just change ftype back and ensure data hasn't been freed */
712 info.fType= MFT_OWNERDRAW; /* Set as ownerdraw type */
713 info.dwTypeData= (char *)0xdeadbee3;
714 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
715 ok (rc, "SetMenuItemInfo failed\n");
717 /* Did we keep the old dwTypeData? */
718 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
719 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
721 /* Just change string value (not type) */
722 memset(&info, 0x00, sizeof(info));
723 info.cbSize= sizeof(MENUITEMINFO);
724 info.fMask= MIIM_STRING; /* Set typeData */
725 strcpy(string2, "string2");
726 info.dwTypeData= string2;
727 rc = SetMenuItemInfo( hmenu, 0, TRUE, &info );
728 ok (rc, "SetMenuItemInfo failed\n");
730 ok (GetMenuString( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
731 ok (!strcmp( strback, "string2" ), "Menu text from Ansi version incorrect\n");
733 /* crashes with wine 0.9.5 */
734 memset(&info, 0x00, sizeof(info));
735 info.cbSize= sizeof(MENUITEMINFO);
736 info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
737 info.fType= MFT_OWNERDRAW;
738 rc = InsertMenuItem( hmenu, 0, TRUE, &info );
739 ok (rc, "InsertMenuItem failed\n");
740 ok (!GetMenuString( hmenu, 0, NULL, 0, MF_BYPOSITION),
741 "GetMenuString on ownerdraw entry succeeded.\n");
742 SetLastError(0xdeadbeef);
743 ret = GetMenuStringW( hmenu, 0, NULL, 0, MF_BYPOSITION);
744 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
745 win_skip("GetMenuStringW is not implemented\n");
746 else
747 ok (!ret, "GetMenuStringW on ownerdraw entry succeeded.\n");
749 DestroyMenu( hmenu );
752 /* define building blocks for the menu item info tests */
753 static int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
755 if (n <= 0) return 0;
756 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
757 return *str1 - *str2;
760 static WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
762 WCHAR *p = dst;
763 while ((*p++ = *src++));
764 return dst;
767 static void insert_menu_item( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state, UINT id,
768 HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
769 void *type_data, UINT len, HBITMAP item, BOOL expect )
771 MENUITEMINFOA info;
772 BOOL ret;
774 /* magic bitmap handle to test smaller cbSize */
775 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
776 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
777 else
778 info.cbSize = sizeof(info);
779 info.fMask = mask;
780 info.fType = type;
781 info.fState = state;
782 info.wID = id;
783 info.hSubMenu = submenu;
784 info.hbmpChecked = checked;
785 info.hbmpUnchecked = unchecked;
786 info.dwItemData = data;
787 info.dwTypeData = type_data;
788 info.cch = len;
789 info.hbmpItem = item;
790 SetLastError( 0xdeadbeef );
791 if (ansi) ret = InsertMenuItemA( hmenu, 0, TRUE, &info );
792 else ret = InsertMenuItemW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
793 if (!expect) ok_(__FILE__, line)( !ret, "InsertMenuItem should have failed.\n" );
794 else ok_(__FILE__, line)( ret, "InsertMenuItem failed, err %u\n", GetLastError());
797 static void check_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
798 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked,
799 ULONG_PTR data, void *type_data, UINT in_len, UINT out_len,
800 HBITMAP item, LPCSTR expname, BOOL expect, BOOL expstring )
802 MENUITEMINFOA info;
803 BOOL ret;
804 WCHAR buffer[80];
806 SetLastError( 0xdeadbeef );
807 memset( &info, 0xcc, sizeof(info) );
808 info.cbSize = sizeof(info);
809 info.fMask = mask;
810 info.dwTypeData = type_data;
811 info.cch = in_len;
813 ret = ansi ? GetMenuItemInfoA( hmenu, 0, TRUE, &info ) :
814 GetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW *)&info );
815 if (!expect)
817 ok_(__FILE__, line)( !ret, "GetMenuItemInfo should have failed.\n" );
818 return;
820 ok_(__FILE__, line)( ret, "GetMenuItemInfo failed, err %u\n", GetLastError());
821 if (mask & MIIM_TYPE)
822 ok_(__FILE__, line)( info.fType == type || info.fType == LOWORD(type),
823 "wrong type %x/%x\n", info.fType, type );
824 if (mask & MIIM_STATE)
825 ok_(__FILE__, line)( info.fState == state || info.fState == LOWORD(state),
826 "wrong state %x/%x\n", info.fState, state );
827 if (mask & MIIM_ID)
828 ok_(__FILE__, line)( info.wID == id || info.wID == LOWORD(id),
829 "wrong id %x/%x\n", info.wID, id );
830 if (mask & MIIM_SUBMENU)
831 ok_(__FILE__, line)( info.hSubMenu == submenu || (ULONG_PTR)info.hSubMenu == LOWORD(submenu),
832 "wrong submenu %p/%p\n", info.hSubMenu, submenu );
833 if (mask & MIIM_CHECKMARKS)
835 ok_(__FILE__, line)( info.hbmpChecked == checked || (ULONG_PTR)info.hbmpChecked == LOWORD(checked),
836 "wrong bmpchecked %p/%p\n", info.hbmpChecked, checked );
837 ok_(__FILE__, line)( info.hbmpUnchecked == unchecked || (ULONG_PTR)info.hbmpUnchecked == LOWORD(unchecked),
838 "wrong bmpunchecked %p/%p\n", info.hbmpUnchecked, unchecked );
840 if (mask & MIIM_DATA)
841 ok_(__FILE__, line)( info.dwItemData == data || info.dwItemData == LOWORD(data),
842 "wrong item data %lx/%lx\n", info.dwItemData, data );
843 if (mask & MIIM_BITMAP)
844 ok_(__FILE__, line)( info.hbmpItem == item || (ULONG_PTR)info.hbmpItem == LOWORD(item),
845 "wrong bmpitem %p/%p\n", info.hbmpItem, item );
846 ok_(__FILE__, line)( info.dwTypeData == type_data || (ULONG_PTR)info.dwTypeData == LOWORD(type_data),
847 "wrong type data %p/%p\n", info.dwTypeData, type_data );
848 ok_(__FILE__, line)( info.cch == out_len, "wrong len %x/%x\n", info.cch, out_len );
849 if (expname)
851 if(ansi)
852 ok_(__FILE__, line)( !strncmp( expname, info.dwTypeData, out_len ),
853 "menu item name differed from '%s' '%s'\n", expname, info.dwTypeData );
854 else
855 ok_(__FILE__, line)( !strncmpW( (WCHAR *)expname, (WCHAR *)info.dwTypeData, out_len ),
856 "menu item name wrong\n" );
858 SetLastError( 0xdeadbeef );
859 ret = ansi ? GetMenuStringA( hmenu, 0, (char *)buffer, 80, MF_BYPOSITION ) :
860 GetMenuStringW( hmenu, 0, buffer, 80, MF_BYPOSITION );
861 if (expstring)
862 ok_(__FILE__, line)( ret, "GetMenuString failed, err %u\n", GetLastError());
863 else
864 ok_(__FILE__, line)( !ret, "GetMenuString should have failed\n" );
868 static void modify_menu( int line, HMENU hmenu, BOOL ansi, UINT flags, UINT_PTR id, void *data )
870 BOOL ret;
872 SetLastError( 0xdeadbeef );
873 if (ansi) ret = ModifyMenuA( hmenu, 0, flags, id, data );
874 else ret = ModifyMenuW( hmenu, 0, flags, id, data );
875 ok_(__FILE__,line)( ret, "ModifyMenuA failed, err %u\n", GetLastError());
878 static void set_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
879 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
880 void *type_data, UINT len, HBITMAP item )
883 MENUITEMINFOA info;
884 BOOL ret;
886 /* magic bitmap handle to test smaller cbSize */
887 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
888 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
889 else
890 info.cbSize = sizeof(info);
891 info.fMask = mask;
892 info.fType = type;
893 info.fState = state;
894 info.wID = id;
895 info.hSubMenu = submenu;
896 info.hbmpChecked = checked;
897 info.hbmpUnchecked = unchecked;
898 info.dwItemData = data;
899 info.dwTypeData = type_data;
900 info.cch = len;
901 info.hbmpItem = item;
902 SetLastError( 0xdeadbeef );
903 if (ansi) ret = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
904 else ret = SetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
905 ok_(__FILE__, line)( ret, "SetMenuItemInfo failed, err %u\n", GetLastError());
908 #define TMII_INSMI( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,eret1 )\
909 hmenu = CreateMenu();\
910 submenu = CreateMenu();\
911 if(ansi)strcpy( string, init );\
912 else strcpyW( string, init );\
913 insert_menu_item( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, eret1 )
915 /* GetMenuItemInfo + GetMenuString */
916 #define TMII_GMII( c2,l2,\
917 d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,\
918 expname, eret2, eret3)\
919 check_menu_item_info( __LINE__, hmenu, ansi, c2, d3, e3, f3, g3, h3, i3, j3, k3, l2, l3, m3, \
920 expname, eret2, eret3 )
922 #define TMII_DONE \
923 RemoveMenu(hmenu, 0, TRUE );\
924 DestroyMenu( hmenu );\
925 DestroyMenu( submenu );
927 /* modify menu */
928 #define TMII_MODM( flags, id, data ) \
929 modify_menu( __LINE__, hmenu, ansi, flags, id, data )
931 /* SetMenuItemInfo */
932 #define TMII_SMII( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1 ) \
933 set_menu_item_info( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1 )
936 #define OK 1
937 #define ER 0
940 static void test_menu_iteminfo( void )
942 int ansi = TRUE;
943 char txtA[]="wine";
944 char initA[]="XYZ";
945 char emptyA[]="";
946 WCHAR txtW[]={'W','i','n','e',0};
947 WCHAR initW[]={'X','Y','Z',0};
948 WCHAR emptyW[]={0};
949 void *txt, *init, *empty, *string;
950 HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
951 char stringA[0x80];
952 HMENU hmenu, submenu=CreateMenu();
953 HBITMAP dummy_hbm = (HBITMAP)(ULONG_PTR)0xdeadbeef;
955 do {
956 if( ansi) {txt=txtA;init=initA;empty=emptyA;string=stringA;}
957 else {txt=txtW;init=initW;empty=emptyW;string=stringA;}
958 trace( "%s string %p hbm %p txt %p\n", ansi ? "ANSI tests: " : "Unicode tests:", string, hbm, txt);
959 /* test all combinations of MFT_STRING, MFT_OWNERDRAW and MFT_BITMAP */
960 /* (since MFT_STRING is zero, there are four of them) */
961 TMII_INSMI( MIIM_TYPE, MFT_STRING, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
962 TMII_GMII ( MIIM_TYPE, 80,
963 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
964 txt, OK, OK );
965 TMII_DONE
966 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
967 TMII_GMII ( MIIM_TYPE, 80,
968 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
969 NULL, OK, ER );
970 TMII_DONE
971 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
972 TMII_GMII ( MIIM_TYPE, 80,
973 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
974 NULL, OK, ER );
975 TMII_DONE
976 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
977 TMII_GMII ( MIIM_TYPE, 80,
978 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
979 NULL, OK, ER );
980 TMII_DONE
981 /* not enough space for name*/
982 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
983 TMII_GMII ( MIIM_TYPE, 0,
984 MFT_STRING, 0, 0, 0, 0, 0, 0, NULL, 4, 0,
985 NULL, OK, OK );
986 TMII_DONE
987 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
988 TMII_GMII ( MIIM_TYPE, 5,
989 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
990 txt, OK, OK );
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, 4,
994 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 3, 0,
995 txt, OK, OK );
996 TMII_DONE
997 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
998 TMII_GMII ( MIIM_TYPE, 0,
999 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, 0,
1000 NULL, OK, ER );
1001 TMII_DONE
1002 /* cannot combine MIIM_TYPE with some other flags */
1003 TMII_INSMI( MIIM_TYPE|MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1004 TMII_DONE
1005 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1006 TMII_GMII ( MIIM_TYPE|MIIM_STRING, 80,
1007 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1008 NULL, ER, OK );
1009 TMII_DONE
1010 TMII_INSMI( MIIM_TYPE|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
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_FTYPE, 80,
1014 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1015 NULL, ER, OK );
1016 TMII_DONE
1017 TMII_INSMI( MIIM_TYPE|MIIM_BITMAP, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, hbm, ER );
1018 TMII_DONE
1019 /* but succeeds with some others */
1020 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1021 TMII_GMII ( MIIM_TYPE|MIIM_SUBMENU, 80,
1022 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1023 txt, OK, OK );
1024 TMII_DONE
1025 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1026 TMII_GMII ( MIIM_TYPE|MIIM_STATE, 80,
1027 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1028 txt, OK, OK );
1029 TMII_DONE
1030 TMII_INSMI( MIIM_TYPE|MIIM_ID, MFT_STRING, -1, 888, 0, 0, 0, -1, txt, 6, 0, OK );
1031 TMII_GMII ( MIIM_TYPE|MIIM_ID, 80,
1032 MFT_STRING, 0, 888, 0, 0, 0, 0, string, 4, 0,
1033 txt, OK, OK );
1034 TMII_DONE
1035 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING, -1, -1, 0, 0, 0, 999, txt, 6, 0, OK );
1036 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1037 MFT_STRING, 0, 0, 0, 0, 0, 999, string, 4, 0,
1038 txt, OK, OK );
1039 TMII_DONE
1040 /* to be continued */
1041 /* set text with MIIM_TYPE and retrieve with MIIM_STRING */
1042 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1043 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1044 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1045 txt, OK, OK );
1046 TMII_DONE
1047 /* set text with MIIM_TYPE and retrieve with MIIM_STRING; MFT_OWNERDRAW causes an empty string */
1048 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1049 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1050 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1051 empty, OK, ER );
1052 TMII_DONE
1053 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1054 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1055 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1056 empty, OK, ER );
1057 TMII_DONE
1058 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1059 TMII_GMII ( MIIM_FTYPE, 80,
1060 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, 0,
1061 init, OK, ER );
1062 TMII_DONE
1063 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1064 TMII_GMII ( 0, 80,
1065 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1066 init, OK, OK );
1067 TMII_DONE
1068 /* contrary to MIIM_TYPE,you can set the text for an owner draw menu */
1069 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1070 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1071 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1072 txt, OK, OK );
1073 TMII_DONE
1074 /* same but retrieve with MIIM_TYPE */
1075 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1076 TMII_GMII ( MIIM_TYPE, 80,
1077 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1078 NULL, OK, OK );
1079 TMII_DONE
1080 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1081 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1082 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1083 empty, OK, ER );
1084 TMII_DONE
1085 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1086 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1087 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1088 empty, OK, ER );
1089 TMII_DONE
1091 /* How is that with bitmaps? */
1092 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1093 TMII_GMII ( MIIM_TYPE, 80,
1094 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1095 NULL, OK, ER );
1096 TMII_DONE
1097 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1098 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1099 0, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1100 init, OK, ER );
1101 TMII_DONE
1102 /* MIIM_BITMAP does not like MFT_BITMAP */
1103 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, hbm, ER );
1104 TMII_DONE
1105 /* no problem with OWNERDRAWN */
1106 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1107 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1108 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1109 init, OK, ER );
1110 TMII_DONE
1111 /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1112 TMII_INSMI( MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER );
1113 TMII_DONE
1115 /* menu with submenu */
1116 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1117 TMII_GMII ( MIIM_SUBMENU, 80,
1118 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1119 init, OK, ER );
1120 TMII_DONE
1121 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, empty, 0, 0, OK );
1122 TMII_GMII ( MIIM_SUBMENU, 80,
1123 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1124 init, OK, ER );
1125 TMII_DONE
1126 /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1127 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1128 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1129 MFT_STRING|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1130 empty, OK, ER );
1131 TMII_GMII ( MIIM_SUBMENU|MIIM_FTYPE, 80,
1132 MFT_SEPARATOR, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1133 empty, OK, ER );
1134 TMII_DONE
1135 /* menu with invalid submenu */
1136 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, (HMENU)999, 0, 0, -1, txt, 0, 0, ER );
1137 TMII_DONE
1138 /* Separator */
1139 TMII_INSMI( MIIM_TYPE, MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1140 TMII_GMII ( MIIM_TYPE, 80,
1141 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1142 NULL, OK, ER );
1143 TMII_DONE
1144 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1145 TMII_GMII ( MIIM_TYPE, 80,
1146 MFT_BITMAP|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1147 NULL, OK, ER );
1148 TMII_DONE
1149 /* SEPARATOR and STRING go well together */
1150 /* BITMAP and STRING go well together */
1151 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1152 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1153 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1154 txt, OK, OK );
1155 TMII_DONE
1156 /* BITMAP, SEPARATOR and STRING go well together */
1157 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1158 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1159 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1160 txt, OK, OK );
1161 TMII_DONE
1162 /* last two tests, but use MIIM_TYPE to retrieve info */
1163 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1164 TMII_GMII ( MIIM_TYPE, 80,
1165 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1166 NULL, OK, OK );
1167 TMII_DONE
1168 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1169 TMII_GMII ( MIIM_TYPE, 80,
1170 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1171 NULL, OK, OK );
1172 TMII_DONE
1173 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1174 TMII_GMII ( MIIM_TYPE, 80,
1175 MFT_SEPARATOR|MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1176 NULL, OK, OK );
1177 TMII_DONE
1178 /* same three with MFT_OWNERDRAW */
1179 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1180 TMII_GMII ( MIIM_TYPE, 80,
1181 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1182 NULL, OK, OK );
1183 TMII_DONE
1184 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1185 TMII_GMII ( MIIM_TYPE, 80,
1186 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1187 NULL, OK, OK );
1188 TMII_DONE
1189 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1190 TMII_GMII ( MIIM_TYPE, 80,
1191 MFT_SEPARATOR|MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1192 NULL, OK, OK );
1193 TMII_DONE
1195 TMII_INSMI( MIIM_STRING|MIIM_FTYPE|MIIM_ID, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1196 TMII_GMII ( MIIM_TYPE, 80,
1197 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1198 NULL, OK, OK );
1199 TMII_DONE
1200 /* test with modifymenu: string is preserved after setting OWNERDRAW */
1201 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1202 TMII_MODM( MFT_OWNERDRAW, -1, (void*)787 );
1203 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_DATA, 80,
1204 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 787, string, 4, 0,
1205 txt, OK, OK );
1206 TMII_DONE
1207 /* same with bitmap: now the text is cleared */
1208 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1209 TMII_MODM( MFT_BITMAP, 545, hbm );
1210 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1211 MFT_BITMAP, 0, 545, 0, 0, 0, 0, string, 0, hbm,
1212 empty, OK, ER );
1213 TMII_DONE
1214 /* start with bitmap: now setting text clears it (though he flag is raised) */
1215 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1216 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1217 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 0, hbm,
1218 empty, OK, ER );
1219 TMII_MODM( MFT_STRING, 545, txt );
1220 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1221 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 4, 0,
1222 txt, OK, OK );
1223 TMII_DONE
1224 /*repeat with text NULL */
1225 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1226 TMII_MODM( MFT_STRING, 545, NULL );
1227 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1228 MFT_SEPARATOR, 0, 545, 0, 0, 0, 0, string, 0, 0,
1229 empty, OK, ER );
1230 TMII_DONE
1231 /* repeat with text "" */
1232 TMII_INSMI( MIIM_BITMAP, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1233 TMII_MODM( MFT_STRING, 545, empty );
1234 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1235 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 0, 0,
1236 empty, OK, ER );
1237 TMII_DONE
1238 /* start with bitmap: set ownerdraw */
1239 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1240 TMII_MODM( MFT_OWNERDRAW, -1, (void *)232 );
1241 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_DATA, 80,
1242 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 232, string, 0, hbm,
1243 empty, OK, ER );
1244 TMII_DONE
1245 /* ask nothing */
1246 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1247 TMII_GMII ( 0, 80,
1248 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1249 init, OK, OK );
1250 TMII_DONE
1251 /* some tests with small cbSize: the hbmpItem is to be ignored */
1252 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1253 TMII_GMII ( MIIM_TYPE, 80,
1254 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1255 NULL, OK, ER );
1256 TMII_DONE
1257 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1258 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1259 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, NULL,
1260 init, OK, ER );
1261 TMII_DONE
1262 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1263 TMII_GMII ( MIIM_TYPE, 80,
1264 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, NULL,
1265 txt, OK, OK );
1266 TMII_DONE
1267 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1268 TMII_GMII ( MIIM_TYPE, 80,
1269 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1270 NULL, OK, OK );
1271 TMII_DONE
1272 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1273 TMII_GMII ( MIIM_TYPE, 80,
1274 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1275 NULL, OK, OK );
1276 TMII_DONE
1277 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1278 TMII_GMII ( MIIM_TYPE, 80,
1279 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1280 NULL, OK, OK );
1281 TMII_DONE
1282 /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus */
1283 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1284 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1285 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1286 NULL, OK, ER );
1287 TMII_DONE
1288 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1289 TMII_GMII ( MIIM_TYPE, 80,
1290 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1291 NULL, OK, ER );
1292 TMII_DONE
1293 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1294 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1295 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1296 NULL, OK, ER );
1297 TMII_DONE
1298 /* set a string menu to ownerdraw with MIIM_TYPE */
1299 TMII_INSMI( MIIM_TYPE, MFT_STRING, -2, -2, 0, 0, 0, -2, txt, -2, 0, OK );
1300 TMII_SMII ( MIIM_TYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1301 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1302 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1303 txt, OK, OK );
1304 TMII_DONE
1305 /* test with modifymenu add submenu */
1306 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1307 TMII_MODM( MF_POPUP, (UINT_PTR)submenu, txt );
1308 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_SUBMENU, 80,
1309 MFT_STRING, 0, 0, submenu, 0, 0, 0, string, 4, 0,
1310 txt, OK, OK );
1311 TMII_GMII ( MIIM_TYPE, 80,
1312 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1313 txt, OK, OK );
1314 TMII_DONE
1315 /* MFT_SEPARATOR bit is kept when the text is added */
1316 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1317 TMII_SMII( MIIM_STRING, 0, 0, 0, 0, 0, 0, 0, txt, 0, 0 );
1318 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1319 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, 0,
1320 txt, OK, OK );
1321 TMII_DONE
1322 /* MFT_SEPARATOR bit is kept when bitmap is added */
1323 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1324 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm );
1325 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1326 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1327 init, OK, ER );
1328 TMII_DONE
1329 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1330 Only the low word of the dwTypeData is used.
1331 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1332 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1333 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1334 TMII_GMII ( MIIM_TYPE, 80,
1335 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1336 NULL, OK, OK );
1337 TMII_DONE
1338 /* Type flags */
1339 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1340 TMII_GMII ( MIIM_TYPE, 80,
1341 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1342 NULL, OK, OK );
1343 TMII_DONE
1344 /* State flags */
1345 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1346 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1347 TMII_GMII ( MIIM_STATE, 80,
1348 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1349 NULL, OK, OK );
1350 TMII_DONE
1351 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1352 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1353 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1354 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1355 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1356 NULL, OK, OK );
1357 TMII_DONE
1358 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1359 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1360 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1361 TMII_GMII ( MIIM_FTYPE, 80,
1362 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1363 NULL, OK, OK );
1364 TMII_GMII ( MIIM_TYPE, 80,
1365 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1366 NULL, OK, OK );
1367 TMII_GMII ( MIIM_FTYPE, 80,
1368 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1369 NULL, OK, OK );
1370 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1371 TMII_GMII ( MIIM_TYPE, 80,
1372 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1373 NULL, OK, OK );
1374 TMII_DONE
1375 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1376 Only the low word of the dwTypeData is used.
1377 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1378 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1379 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1380 TMII_GMII ( MIIM_TYPE, 80,
1381 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1382 NULL, OK, OK );
1383 TMII_DONE
1384 /* Type flags */
1385 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1386 TMII_GMII ( MIIM_TYPE, 80,
1387 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1388 NULL, OK, OK );
1389 TMII_DONE
1390 /* State flags */
1391 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1392 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1393 TMII_GMII ( MIIM_STATE, 80,
1394 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1395 NULL, OK, OK );
1396 TMII_DONE
1397 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1398 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1399 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1400 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1401 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1402 NULL, OK, OK );
1403 TMII_DONE
1404 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1405 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1406 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1407 TMII_GMII ( MIIM_FTYPE, 80,
1408 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1409 NULL, OK, OK );
1410 TMII_GMII ( MIIM_TYPE, 80,
1411 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1412 NULL, OK, OK );
1413 TMII_GMII ( MIIM_FTYPE, 80,
1414 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1415 NULL, OK, OK );
1416 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1417 TMII_GMII ( MIIM_TYPE, 80,
1418 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1419 NULL, OK, OK );
1420 TMII_DONE
1421 } while( !(ansi = !ansi) );
1422 DeleteObject( hbm);
1426 The following tests try to confirm the algorithm used to return the menu items
1427 when there is a collision between a menu item and a popup menu
1429 static void test_menu_search_bycommand( void )
1431 HMENU hmenu, hmenuSub, hmenuSub2;
1432 MENUITEMINFO info;
1433 BOOL rc;
1434 UINT id;
1435 char strback[0x80];
1436 char strIn[0x80];
1437 static CHAR menuitem[] = "MenuItem",
1438 menuitem2[] = "MenuItem 2";
1440 /* Case 1: Menu containing a menu item */
1441 hmenu = CreateMenu();
1443 memset( &info, 0, sizeof info );
1444 info.cbSize = sizeof info;
1445 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1446 info.fType = MFT_STRING;
1447 strcpy(strIn, "Case 1 MenuItem");
1448 info.dwTypeData = strIn;
1449 info.wID = (UINT) 0x1234;
1451 rc = InsertMenuItem(hmenu, 0, TRUE, &info );
1452 ok (rc, "Inserting the menuitem failed\n");
1454 id = GetMenuItemID(hmenu, 0);
1455 ok (id == 0x1234, "Getting the menuitem id failed(gave %x)\n", id);
1457 /* Confirm the menuitem was given the id supplied (getting by position) */
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);
1465 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info); /* Get by position */
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 /* Search by id - Should return the item */
1471 memset( &info, 0, sizeof info );
1472 strback[0] = 0x00;
1473 info.cbSize = sizeof(MENUITEMINFO);
1474 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1475 info.dwTypeData = strback;
1476 info.cch = sizeof(strback);
1477 rc = GetMenuItemInfo(hmenu, 0x1234, FALSE, &info); /* Get by ID */
1479 ok (rc, "Getting the menu items info failed\n");
1480 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1481 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1483 DestroyMenu( hmenu );
1485 /* Case 2: Menu containing a popup menu */
1486 hmenu = CreateMenu();
1487 hmenuSub = CreateMenu();
1489 strcpy(strIn, "Case 2 SubMenu");
1490 rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, strIn);
1491 ok (rc, "Inserting the popup menu into the main menu failed\n");
1493 id = GetMenuItemID(hmenu, 0);
1494 ok (id == -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id);
1496 /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
1497 memset( &info, 0, sizeof info );
1498 strback[0] = 0x00;
1499 info.cbSize = sizeof(MENUITEMINFO);
1500 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1501 info.dwTypeData = strback;
1502 info.cch = sizeof(strback);
1503 info.wID = 0xdeadbeef;
1505 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info); /* Get by position */
1506 ok (rc, "Getting the menu items info failed\n");
1507 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the menuitem\n");
1508 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1510 /* Search by id - returns the popup menu itself */
1511 memset( &info, 0, sizeof info );
1512 strback[0] = 0x00;
1513 info.cbSize = sizeof(MENUITEMINFO);
1514 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1515 info.dwTypeData = strback;
1516 info.cch = sizeof(strback);
1517 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1519 ok (rc, "Getting the menu items info failed\n");
1520 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1521 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1524 Now add an item after it with the same id
1526 memset( &info, 0, sizeof info );
1527 info.cbSize = sizeof info;
1528 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1529 info.fType = MFT_STRING;
1530 strcpy(strIn, "Case 2 MenuItem 1");
1531 info.dwTypeData = strIn;
1532 info.wID = (UINT_PTR) hmenuSub;
1533 rc = InsertMenuItem(hmenu, -1, TRUE, &info );
1534 ok (rc, "Inserting the menuitem failed\n");
1536 /* Search by id - returns the item which follows the popup menu */
1537 memset( &info, 0, sizeof info );
1538 strback[0] = 0x00;
1539 info.cbSize = sizeof(MENUITEMINFO);
1540 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1541 info.dwTypeData = strback;
1542 info.cch = sizeof(strback);
1543 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1545 ok (rc, "Getting the menu items info failed\n");
1546 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1547 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1550 Now add an item before the popup (with the same id)
1552 memset( &info, 0, sizeof info );
1553 info.cbSize = sizeof info;
1554 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1555 info.fType = MFT_STRING;
1556 strcpy(strIn, "Case 2 MenuItem 2");
1557 info.dwTypeData = strIn;
1558 info.wID = (UINT_PTR) hmenuSub;
1559 rc = InsertMenuItem(hmenu, 0, TRUE, &info );
1560 ok (rc, "Inserting the menuitem failed\n");
1562 /* Search by id - returns the item which precedes the popup menu */
1563 memset( &info, 0, sizeof info );
1564 strback[0] = 0x00;
1565 info.cbSize = sizeof(MENUITEMINFO);
1566 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1567 info.dwTypeData = strback;
1568 info.cch = sizeof(strback);
1569 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1571 ok (rc, "Getting the menu items info failed\n");
1572 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1573 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1575 DestroyMenu( hmenu );
1576 DestroyMenu( hmenuSub );
1579 Case 3: Menu containing a popup menu which in turn
1580 contains 2 items with the same id as the popup itself
1583 hmenu = CreateMenu();
1584 hmenuSub = CreateMenu();
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 = menuitem;
1591 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1593 rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1594 ok (rc, "Inserting the popup menu into the main menu failed\n");
1596 rc = InsertMenuItem(hmenuSub, 0, TRUE, &info );
1597 ok (rc, "Inserting the sub menu menuitem failed\n");
1599 memset( &info, 0, sizeof info );
1600 info.cbSize = sizeof info;
1601 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1602 info.fType = MFT_STRING;
1603 info.dwTypeData = menuitem2;
1604 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1606 rc = InsertMenuItem(hmenuSub, 1, TRUE, &info );
1607 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
1609 /* Prove that you can't query the id of a popup directly (By position) */
1610 id = GetMenuItemID(hmenu, 0);
1611 ok (id == -1, "Getting the sub menu id should have failed because its a popup (gave %x)\n", id);
1613 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1614 memset( &info, 0, sizeof info );
1615 strback[0] = 0x00;
1616 info.cbSize = sizeof(MENUITEMINFO);
1617 info.fMask = MIIM_STRING | MIIM_ID;
1618 info.dwTypeData = strback;
1619 info.cch = sizeof(strback);
1621 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
1622 ok (rc, "Getting the menus info failed\n");
1623 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
1624 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1625 DestroyMenu( hmenu );
1626 DestroyMenu( hmenuSub );
1629 Case 4: Menu containing 2 popup menus, the second
1630 contains 2 items with the same id as the first popup menu
1632 hmenu = CreateMenu();
1633 hmenuSub = CreateMenu();
1634 hmenuSub2 = CreateMenu();
1636 rc = InsertMenu(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1637 ok (rc, "Inserting the popup menu into the main menu failed\n");
1639 rc = InsertMenu(hmenu, 1, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub2, "Submenu2");
1640 ok (rc, "Inserting the popup menu into the main menu failed\n");
1642 memset( &info, 0, sizeof info );
1643 info.cbSize = sizeof info;
1644 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1645 info.fType = MFT_STRING;
1646 info.dwTypeData = menuitem;
1647 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1649 rc = InsertMenuItem(hmenuSub2, 0, TRUE, &info );
1650 ok (rc, "Inserting the sub menu menuitem failed\n");
1652 memset( &info, 0, sizeof info );
1653 info.cbSize = sizeof info;
1654 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1655 info.fType = MFT_STRING;
1656 info.dwTypeData = menuitem2;
1657 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
1659 rc = InsertMenuItem(hmenuSub2, 1, TRUE, &info );
1660 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
1662 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
1663 memset( &info, 0, sizeof info );
1664 strback[0] = 0x00;
1665 info.cbSize = sizeof(MENUITEMINFO);
1666 info.fMask = MIIM_STRING | MIIM_ID;
1667 info.dwTypeData = strback;
1668 info.cch = sizeof(strback);
1670 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
1671 ok (rc, "Getting the menus info failed\n");
1672 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
1673 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1675 memset( &info, 0, sizeof info );
1676 strback[0] = 0x00;
1677 info.cbSize = sizeof(MENUITEMINFO);
1678 info.fMask = MIIM_STRING | MIIM_ID;
1679 info.dwTypeData = strback;
1680 info.cch = sizeof(strback);
1682 rc = GetMenuItemInfo(hmenu, (UINT_PTR)hmenuSub2, FALSE, &info);
1683 ok (rc, "Getting the menus info failed\n");
1684 ok (info.wID == (UINT_PTR)hmenuSub2, "IDs differ for popup menu\n");
1685 ok (!strcmp(info.dwTypeData, "Submenu2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1687 DestroyMenu( hmenu );
1688 DestroyMenu( hmenuSub );
1689 DestroyMenu( hmenuSub2 );
1693 Case 5: Menu containing a popup menu which in turn
1694 contains an item with a different id than the popup menu.
1695 This tests the fallback to a popup menu ID.
1698 hmenu = CreateMenu();
1699 hmenuSub = CreateMenu();
1701 rc = AppendMenu(hmenu, MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
1702 ok (rc, "Appending the popup menu to the main menu failed\n");
1704 rc = AppendMenu(hmenuSub, MF_STRING, 102, "Item");
1705 ok (rc, "Appending the item to the popup menu failed\n");
1707 /* Set the ID for hmenuSub */
1708 info.cbSize = sizeof(info);
1709 info.fMask = MIIM_ID;
1710 info.wID = 101;
1712 rc = SetMenuItemInfo(hmenu, 0, TRUE, &info);
1713 ok(rc, "Setting the ID for the popup menu failed\n");
1715 /* Check if the ID has been set */
1716 info.wID = 0;
1717 rc = GetMenuItemInfo(hmenu, 0, TRUE, &info);
1718 ok(rc, "Getting the ID for the popup menu failed\n");
1719 ok(info.wID == 101, "The ID for the popup menu has not been set\n");
1721 /* Prove getting the item info via ID returns the popup menu */
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, 101, FALSE, &info);
1730 ok (rc, "Getting the menu info failed\n");
1731 ok (info.wID == 101, "IDs differ\n");
1732 ok (!strcmp(info.dwTypeData, "Submenu"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1734 /* Also look for the menu item */
1735 memset( &info, 0, sizeof(info));
1736 strback[0] = 0x00;
1737 info.cbSize = sizeof(MENUITEMINFO);
1738 info.fMask = MIIM_STRING | MIIM_ID;
1739 info.dwTypeData = strback;
1740 info.cch = sizeof(strback);
1742 rc = GetMenuItemInfo(hmenu, 102, FALSE, &info);
1743 ok (rc, "Getting the menu info failed\n");
1744 ok (info.wID == 102, "IDs differ\n");
1745 ok (!strcmp(info.dwTypeData, "Item"), "Returned item has wrong label (%s)\n", info.dwTypeData);
1747 DestroyMenu(hmenu);
1748 DestroyMenu(hmenuSub);
1751 struct menu_item_pair_s {
1752 UINT uMenu; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
1753 * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
1754 * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
1755 UINT uItem;
1758 static struct menu_mouse_tests_s {
1759 DWORD type;
1760 struct menu_item_pair_s menu_item_pairs[5]; /* for mousing */
1761 WORD wVk[5]; /* keys */
1762 BOOL bMenuVisible;
1763 BOOL _todo_wine;
1764 } menu_tests[] = {
1765 /* for each test, send keys or clicks and check for menu visibility */
1766 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE }, /* test 0 */
1767 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
1768 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
1769 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
1770 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
1771 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
1772 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
1773 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, VK_ESCAPE, 0}, FALSE, FALSE },
1774 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', VK_ESCAPE, 0}, TRUE, FALSE },
1775 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
1776 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
1777 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
1778 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
1779 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
1780 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
1781 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
1782 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
1783 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
1785 { INPUT_MOUSE, {{1, 2}, {0}}, {0}, TRUE, TRUE }, /* test 18 */
1786 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
1787 { INPUT_MOUSE, {{1, 0}, {0}}, {0}, TRUE, TRUE },
1788 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
1789 { INPUT_MOUSE, {{1, 0}, {2, 2}, {0}}, {0}, TRUE, TRUE },
1790 { INPUT_MOUSE, {{2, 1}, {0}}, {0}, FALSE, FALSE },
1791 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
1792 { INPUT_MOUSE, {{3, 0}, {0}}, {0}, FALSE, FALSE },
1793 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
1794 { INPUT_MOUSE, {{3, 1}, {0}}, {0}, TRUE, TRUE },
1795 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
1796 { -1 }
1799 static void send_key(WORD wVk)
1801 TEST_INPUT i[2];
1802 memset(i, 0, sizeof(i));
1803 i[0].type = i[1].type = INPUT_KEYBOARD;
1804 i[0].u.ki.wVk = i[1].u.ki.wVk = wVk;
1805 i[1].u.ki.dwFlags = KEYEVENTF_KEYUP;
1806 pSendInput(2, (INPUT *) i, sizeof(INPUT));
1809 static BOOL click_menu(HANDLE hWnd, struct menu_item_pair_s *mi)
1811 HMENU hMenu = hMenus[mi->uMenu];
1812 TEST_INPUT i[3];
1813 MSG msg;
1814 RECT r;
1815 int screen_w = GetSystemMetrics(SM_CXSCREEN);
1816 int screen_h = GetSystemMetrics(SM_CYSCREEN);
1817 BOOL ret = GetMenuItemRect(mi->uMenu > 2 ? NULL : hWnd, hMenu, mi->uItem, &r);
1818 if(!ret) return FALSE;
1820 memset(i, 0, sizeof(i));
1821 i[0].type = i[1].type = i[2].type = INPUT_MOUSE;
1822 i[0].u.mi.dx = i[1].u.mi.dx = i[2].u.mi.dx
1823 = ((r.left + 5) * 65535) / screen_w;
1824 i[0].u.mi.dy = i[1].u.mi.dy = i[2].u.mi.dy
1825 = ((r.top + 5) * 65535) / screen_h;
1826 i[0].u.mi.dwFlags = i[1].u.mi.dwFlags = i[2].u.mi.dwFlags
1827 = MOUSEEVENTF_ABSOLUTE;
1828 i[0].u.mi.dwFlags |= MOUSEEVENTF_MOVE;
1829 i[1].u.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
1830 i[2].u.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
1831 ret = pSendInput(3, (INPUT *) i, sizeof(INPUT));
1833 /* hack to prevent mouse message buildup in Wine */
1834 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
1835 return ret;
1838 static DWORD WINAPI test_menu_input_thread(LPVOID lpParameter)
1840 int i, j;
1841 HANDLE hWnd = lpParameter;
1843 Sleep(500);
1844 /* mixed keyboard/mouse test */
1845 for (i = 0; menu_tests[i].type != -1; i++)
1847 int ret = TRUE, elapsed = 0;
1849 got_input = i && menu_tests[i-1].bMenuVisible;
1851 if (menu_tests[i].type == INPUT_KEYBOARD)
1852 for (j = 0; menu_tests[i].wVk[j] != 0; j++)
1853 send_key(menu_tests[i].wVk[j]);
1854 else
1855 for (j = 0; menu_tests[i].menu_item_pairs[j].uMenu != 0; j++)
1856 if (!(ret = click_menu(hWnd, &menu_tests[i].menu_item_pairs[j]))) break;
1858 if (!ret)
1860 skip( "test %u: failed to send input\n", i );
1861 PostMessage( hWnd, WM_CANCELMODE, 0, 0 );
1862 return 0;
1864 while (menu_tests[i].bMenuVisible != bMenuVisible)
1866 if (elapsed > 200)
1867 break;
1868 elapsed += 20;
1869 Sleep(20);
1872 if (!got_input)
1874 skip( "test %u: didn't receive input\n", i );
1875 PostMessage( hWnd, WM_CANCELMODE, 0, 0 );
1876 return 0;
1879 if (menu_tests[i]._todo_wine)
1881 todo_wine {
1882 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
1885 else
1886 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
1888 return 0;
1891 static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam,
1892 LPARAM lParam)
1894 switch (msg) {
1895 case WM_ENTERMENULOOP:
1896 bMenuVisible = TRUE;
1897 break;
1898 case WM_EXITMENULOOP:
1899 bMenuVisible = FALSE;
1900 break;
1901 case WM_KEYDOWN:
1902 case WM_SYSKEYDOWN:
1903 case WM_MOUSEMOVE:
1904 case WM_LBUTTONDOWN:
1905 case WM_LBUTTONUP:
1906 case WM_NCMOUSEMOVE:
1907 case WM_NCLBUTTONDOWN:
1908 case WM_NCLBUTTONUP:
1909 got_input = TRUE;
1910 /* fall through */
1911 default:
1912 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
1914 return 0;
1917 static void test_menu_input(void) {
1918 MSG msg;
1919 WNDCLASSA wclass;
1920 HINSTANCE hInstance = GetModuleHandleA( NULL );
1921 HANDLE hThread, hWnd;
1922 DWORD tid;
1924 wclass.lpszClassName = "MenuTestClass";
1925 wclass.style = CS_HREDRAW | CS_VREDRAW;
1926 wclass.lpfnWndProc = WndProc;
1927 wclass.hInstance = hInstance;
1928 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
1929 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
1930 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
1931 wclass.lpszMenuName = 0;
1932 wclass.cbClsExtra = 0;
1933 wclass.cbWndExtra = 0;
1934 assert (RegisterClassA( &wclass ));
1935 assert (hWnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
1936 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
1937 400, 200, NULL, NULL, hInstance, NULL) );
1939 /* fixed menus */
1940 hMenus[3] = CreatePopupMenu();
1941 AppendMenu(hMenus[3], MF_STRING, 0, "&Enabled");
1942 AppendMenu(hMenus[3], MF_STRING|MF_DISABLED, 0, "&Disabled");
1944 hMenus[2] = CreatePopupMenu();
1945 AppendMenu(hMenus[2], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[3], "&Popup");
1946 AppendMenu(hMenus[2], MF_STRING, 0, "&Enabled");
1947 AppendMenu(hMenus[2], MF_STRING|MF_DISABLED, 0, "&Disabled");
1949 hMenus[1] = CreateMenu();
1950 AppendMenu(hMenus[1], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[2], "&Menu");
1951 AppendMenu(hMenus[1], MF_STRING, 0, "&Enabled");
1952 AppendMenu(hMenus[1], MF_STRING|MF_DISABLED, 0, "&Disabled");
1954 SetMenu(hWnd, hMenus[1]);
1955 ShowWindow(hWnd, SW_SHOW);
1956 UpdateWindow(hWnd);
1958 hThread = CreateThread(NULL, 0, test_menu_input_thread, hWnd, 0, &tid);
1959 while(1)
1961 if (WAIT_TIMEOUT != WaitForSingleObject(hThread, 50))
1962 break;
1963 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
1965 DestroyWindow(hWnd);
1968 static void test_menu_flags( void )
1970 HMENU hMenu, hPopupMenu;
1972 hMenu = CreateMenu();
1973 hPopupMenu = CreatePopupMenu();
1975 AppendMenu(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
1977 AppendMenu(hPopupMenu, MF_STRING | MF_HILITE | MF_DEFAULT, 101, "Item 1");
1978 InsertMenu(hPopupMenu, 1, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 102, "Item 2");
1979 AppendMenu(hPopupMenu, MF_STRING, 103, "Item 3");
1980 ModifyMenu(hPopupMenu, 2, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 103, "Item 3");
1982 ok(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_HILITE,
1983 "AppendMenu should accept MF_HILITE\n");
1984 ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
1985 "InsertMenu should accept MF_HILITE\n");
1986 ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
1987 "ModifyMenu should accept MF_HILITE\n");
1989 ok(!(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_DEFAULT),
1990 "AppendMenu must not accept MF_DEFAULT\n");
1991 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_DEFAULT),
1992 "InsertMenu must not accept MF_DEFAULT\n");
1993 ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_DEFAULT),
1994 "ModifyMenu must not accept MF_DEFAULT\n");
1996 DestroyMenu(hMenu);
1999 static void test_menu_hilitemenuitem( void )
2001 HMENU hMenu, hPopupMenu;
2002 WNDCLASSA wclass;
2003 HWND hWnd;
2005 wclass.lpszClassName = "HiliteMenuTestClass";
2006 wclass.style = CS_HREDRAW | CS_VREDRAW;
2007 wclass.lpfnWndProc = WndProc;
2008 wclass.hInstance = GetModuleHandleA( NULL );
2009 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
2010 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
2011 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2012 wclass.lpszMenuName = 0;
2013 wclass.cbClsExtra = 0;
2014 wclass.cbWndExtra = 0;
2015 assert (RegisterClassA( &wclass ));
2016 assert (hWnd = CreateWindowA( wclass.lpszClassName, "HiliteMenuTest",
2017 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2018 400, 200, NULL, NULL, wclass.hInstance, NULL) );
2020 hMenu = CreateMenu();
2021 hPopupMenu = CreatePopupMenu();
2023 AppendMenu(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2025 AppendMenu(hPopupMenu, MF_STRING, 101, "Item 1");
2026 AppendMenu(hPopupMenu, MF_STRING, 102, "Item 2");
2027 AppendMenu(hPopupMenu, MF_STRING, 103, "Item 3");
2029 SetMenu(hWnd, hMenu);
2031 /* test invalid arguments */
2033 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2034 "HiliteMenuItem: Item 2 is hilited\n");
2036 SetLastError(0xdeadbeef);
2037 todo_wine
2039 ok(!HiliteMenuItem(NULL, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2040 "HiliteMenuItem: call should have failed.\n");
2042 ok(GetLastError() == 0xdeadbeef || /* 9x */
2043 GetLastError() == ERROR_INVALID_WINDOW_HANDLE /* NT */,
2044 "HiliteMenuItem: expected error ERROR_INVALID_WINDOW_HANDLE, got: %d\n", GetLastError());
2046 SetLastError(0xdeadbeef);
2047 ok(!HiliteMenuItem(hWnd, NULL, 1, MF_HILITE | MF_BYPOSITION),
2048 "HiliteMenuItem: call should have failed.\n");
2049 ok(GetLastError() == 0xdeadbeef || /* 9x */
2050 GetLastError() == ERROR_INVALID_MENU_HANDLE /* NT */,
2051 "HiliteMenuItem: expected error ERROR_INVALID_MENU_HANDLE, got: %d\n", GetLastError());
2053 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2054 "HiliteMenuItem: Item 2 is hilited\n");
2056 /* either MF_HILITE or MF_UNHILITE *and* MF_BYCOMMAND or MF_BYPOSITION need to be set */
2058 SetLastError(0xdeadbeef);
2059 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_BYPOSITION),
2060 "HiliteMenuItem: call should have succeeded.\n");
2061 ok(GetLastError() == 0xdeadbeef,
2062 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2064 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2065 "HiliteMenuItem: Item 2 is hilited\n");
2067 SetLastError(0xdeadbeef);
2068 todo_wine
2070 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE),
2071 "HiliteMenuItem: call should have succeeded.\n");
2073 ok(GetLastError() == 0xdeadbeef,
2074 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2076 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2077 "HiliteMenuItem: Item 2 is hilited\n");
2079 /* hilite a menu item (by position) */
2081 SetLastError(0xdeadbeef);
2082 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2083 "HiliteMenuItem: call should not have failed.\n");
2084 ok(GetLastError() == 0xdeadbeef,
2085 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2087 todo_wine
2089 ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2090 "HiliteMenuItem: Item 2 is not hilited\n");
2093 /* unhilite a menu item (by position) */
2095 SetLastError(0xdeadbeef);
2096 ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_UNHILITE | MF_BYPOSITION),
2097 "HiliteMenuItem: call should not have failed.\n");
2098 ok(GetLastError() == 0xdeadbeef,
2099 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2101 ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2102 "HiliteMenuItem: Item 2 is hilited\n");
2104 /* hilite a menu item (by command) */
2106 SetLastError(0xdeadbeef);
2107 ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_HILITE | MF_BYCOMMAND),
2108 "HiliteMenuItem: call should not have failed.\n");
2109 ok(GetLastError() == 0xdeadbeef,
2110 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2112 todo_wine
2114 ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2115 "HiliteMenuItem: Item 3 is not hilited\n");
2118 /* unhilite a menu item (by command) */
2120 SetLastError(0xdeadbeef);
2121 ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_UNHILITE | MF_BYCOMMAND),
2122 "HiliteMenuItem: call should not have failed.\n");
2123 ok(GetLastError() == 0xdeadbeef,
2124 "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2126 ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE),
2127 "HiliteMenuItem: Item 3 is hilited\n");
2129 DestroyWindow(hWnd);
2132 static void check_menu_items(HMENU hmenu, UINT checked_cmd, UINT checked_type,
2133 UINT checked_state)
2135 INT i, count;
2137 count = GetMenuItemCount(hmenu);
2138 ok (count != -1, "GetMenuItemCount returned -1\n");
2140 for (i = 0; i < count; i++)
2142 BOOL ret;
2143 MENUITEMINFO mii;
2145 memset(&mii, 0, sizeof(mii));
2146 mii.cbSize = sizeof(mii);
2147 mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU;
2148 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2149 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2150 #if 0
2151 trace("item #%u: fType %04x, fState %04x, wID %u, hSubMenu %p\n",
2152 i, mii.fType, mii.fState, mii.wID, mii.hSubMenu);
2153 #endif
2154 if (mii.hSubMenu)
2156 ok(mii.wID == (UINT_PTR)mii.hSubMenu, "id %u: wID should be equal to hSubMenu\n", checked_cmd);
2157 check_menu_items(mii.hSubMenu, checked_cmd, checked_type, checked_state);
2159 else
2161 if (mii.wID == checked_cmd)
2163 ok(mii.fType == checked_type, "id %u: expected fType %04x, got %04x\n", checked_cmd, checked_type, mii.fType);
2164 ok(mii.fState == checked_state, "id %u: expected fState %04x, got %04x\n", checked_cmd, checked_state, mii.fState);
2165 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2167 else
2169 ok(mii.fType != MFT_RADIOCHECK, "id %u: not expected fType MFT_RADIOCHECK on cmd %u\n", checked_cmd, mii.wID);
2171 if (mii.fType == MFT_SEPARATOR)
2173 ok(mii.fState == MFS_GRAYED, "id %u: expected fState MFS_GRAYED, got %04x\n", checked_cmd, mii.fState);
2174 ok(mii.wID == 0, "id %u: expected wID 0, got %u\n", checked_cmd, mii.wID);
2176 else
2178 ok(mii.fState == 0, "id %u: expected fState 0, got %04x\n", checked_cmd, mii.fState);
2179 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2186 static void clear_ftype_and_state(HMENU hmenu, UINT id, UINT flags)
2188 BOOL ret;
2189 MENUITEMINFO mii;
2191 memset(&mii, 0, sizeof(mii));
2192 mii.cbSize = sizeof(mii);
2193 mii.fMask = MIIM_FTYPE | MIIM_STATE;
2194 ret = SetMenuItemInfo(hmenu, id, (flags & MF_BYPOSITION) != 0, &mii);
2195 ok(ret, "SetMenuItemInfo(%u) failed\n", id);
2198 static void test_CheckMenuRadioItem(void)
2200 BOOL ret;
2201 HMENU hmenu;
2203 hmenu = LoadMenu(GetModuleHandle(0), MAKEINTRESOURCE(1));
2204 assert(hmenu != 0);
2206 check_menu_items(hmenu, -1, 0, 0);
2208 ret = CheckMenuRadioItem(hmenu, 100, 100, 100, MF_BYCOMMAND);
2209 ok(ret, "CheckMenuRadioItem failed\n");
2210 check_menu_items(hmenu, 100, MFT_RADIOCHECK, MFS_CHECKED);
2212 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2213 ret = CheckMenuRadioItem(hmenu, 100, 100, -1, MF_BYCOMMAND);
2214 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2215 check_menu_items(hmenu, 100, MFT_RADIOCHECK, 0);
2217 /* clear check */
2218 clear_ftype_and_state(hmenu, 100, MF_BYCOMMAND);
2219 check_menu_items(hmenu, -1, 0, 0);
2221 /* first and checked items are on different menus */
2222 ret = CheckMenuRadioItem(hmenu, 0, 300, 202, MF_BYCOMMAND);
2223 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2224 check_menu_items(hmenu, -1, 0, 0);
2226 ret = CheckMenuRadioItem(hmenu, 200, 300, 202, MF_BYCOMMAND);
2227 ok(ret, "CheckMenuRadioItem failed\n");
2228 check_menu_items(hmenu, 202, MFT_RADIOCHECK, MFS_CHECKED);
2230 /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2231 ret = CheckMenuRadioItem(hmenu, 202, 202, -1, MF_BYCOMMAND);
2232 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2233 check_menu_items(hmenu, 202, MFT_RADIOCHECK, 0);
2235 /* clear check */
2236 clear_ftype_and_state(hmenu, 202, MF_BYCOMMAND);
2237 check_menu_items(hmenu, -1, 0, 0);
2239 /* just for fun, try to check separator */
2240 ret = CheckMenuRadioItem(hmenu, 0, 300, 0, MF_BYCOMMAND);
2241 ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2242 check_menu_items(hmenu, -1, 0, 0);
2245 static void test_menu_resource_layout(void)
2247 static const struct
2249 MENUITEMTEMPLATEHEADER mith;
2250 WORD data[14];
2251 } menu_template =
2253 { 0, 0 }, /* versionNumber, offset */
2255 /* mtOption, mtID, mtString[] '\0' terminated */
2256 MF_STRING, 1, 'F', 0,
2257 MF_STRING, 2, 0,
2258 MF_SEPARATOR, 3, 0,
2259 /* MF_SEPARATOR, 4, 'S', 0, FIXME: Wine ignores 'S' */
2260 MF_STRING|MF_GRAYED|MF_END, 5, 'E', 0
2263 static const struct
2265 UINT type, state, id;
2266 const char *str;
2267 } menu_data[] =
2269 { MF_STRING, MF_ENABLED, 1, "F" },
2270 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 2, "" },
2271 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 3, "" },
2272 /*{ MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 4, "S" }, FIXME: Wine ignores 'S'*/
2273 { MF_STRING, MF_GRAYED, 5, "E" },
2274 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 6, "" },
2275 { MF_STRING, MF_ENABLED, 7, "" },
2276 { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 8, "" }
2278 HMENU hmenu;
2279 INT count, i;
2280 BOOL ret;
2282 hmenu = LoadMenuIndirect(&menu_template);
2283 ok(hmenu != 0, "LoadMenuIndirect error %u\n", GetLastError());
2285 ret = AppendMenu(hmenu, MF_STRING, 6, NULL);
2286 ok(ret, "AppendMenu failed\n");
2287 ret = AppendMenu(hmenu, MF_STRING, 7, "\0");
2288 ok(ret, "AppendMenu failed\n");
2289 ret = AppendMenu(hmenu, MF_SEPARATOR, 8, "separator");
2290 ok(ret, "AppendMenu failed\n");
2292 count = GetMenuItemCount(hmenu);
2293 ok(count == sizeof(menu_data)/sizeof(menu_data[0]),
2294 "expected %u menu items, got %u\n",
2295 (UINT)(sizeof(menu_data)/sizeof(menu_data[0])), count);
2297 for (i = 0; i < count; i++)
2299 char buf[20];
2300 MENUITEMINFO mii;
2302 memset(&mii, 0, sizeof(mii));
2303 mii.cbSize = sizeof(mii);
2304 mii.dwTypeData = buf;
2305 mii.cch = sizeof(buf);
2306 mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_STRING;
2307 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2308 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2309 #if 0
2310 trace("item #%u: fType %04x, fState %04x, wID %u, dwTypeData %s\n",
2311 i, mii.fType, mii.fState, mii.wID, (LPCSTR)mii.dwTypeData);
2312 #endif
2313 ok(mii.fType == menu_data[i].type,
2314 "%u: expected fType %04x, got %04x\n", i, menu_data[i].type, mii.fType);
2315 ok(mii.fState == menu_data[i].state,
2316 "%u: expected fState %04x, got %04x\n", i, menu_data[i].state, mii.fState);
2317 ok(mii.wID == menu_data[i].id,
2318 "%u: expected wID %04x, got %04x\n", i, menu_data[i].id, mii.wID);
2319 ok(mii.cch == strlen(menu_data[i].str),
2320 "%u: expected cch %u, got %u\n", i, (UINT)strlen(menu_data[i].str), mii.cch);
2321 ok(!strcmp(mii.dwTypeData, menu_data[i].str),
2322 "%u: expected dwTypeData %s, got %s\n", i, menu_data[i].str, (LPCSTR)mii.dwTypeData);
2325 DestroyMenu(hmenu);
2328 struct menu_data
2330 UINT type, id;
2331 const char *str;
2334 static HMENU create_menu_from_data(const struct menu_data *item, INT item_count)
2336 HMENU hmenu;
2337 INT i;
2338 BOOL ret;
2340 hmenu = CreateMenu();
2341 assert(hmenu != 0);
2343 for (i = 0; i < item_count; i++)
2345 SetLastError(0xdeadbeef);
2346 ret = AppendMenu(hmenu, item[i].type, item[i].id, item[i].str);
2347 ok(ret, "%d: AppendMenu(%04x, %04x, %p) error %u\n",
2348 i, item[i].type, item[i].id, item[i].str, GetLastError());
2350 return hmenu;
2353 static void compare_menu_data(HMENU hmenu, const struct menu_data *item, INT item_count)
2355 INT count, i;
2356 BOOL ret;
2358 count = GetMenuItemCount(hmenu);
2359 ok(count == item_count, "expected %d, got %d menu items\n", count, item_count);
2361 for (i = 0; i < count; i++)
2363 char buf[20];
2364 MENUITEMINFO mii;
2366 memset(&mii, 0, sizeof(mii));
2367 mii.cbSize = sizeof(mii);
2368 mii.dwTypeData = buf;
2369 mii.cch = sizeof(buf);
2370 mii.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_BITMAP;
2371 ret = GetMenuItemInfo(hmenu, i, TRUE, &mii);
2372 ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2373 #if 0
2374 trace("item #%u: fType %04x, fState %04x, wID %04x, hbmp %p\n",
2375 i, mii.fType, mii.fState, mii.wID, mii.hbmpItem);
2376 #endif
2377 ok(mii.fType == item[i].type,
2378 "%u: expected fType %04x, got %04x\n", i, item[i].type, mii.fType);
2379 ok(mii.wID == item[i].id,
2380 "%u: expected wID %04x, got %04x\n", i, item[i].id, mii.wID);
2381 if (item[i].type & (MF_BITMAP | MF_SEPARATOR))
2383 /* For some reason Windows sets high word to not 0 for
2384 * not "magic" ids.
2386 ok(LOWORD(mii.hbmpItem) == LOWORD(item[i].str),
2387 "%u: expected hbmpItem %p, got %p\n", i, item[i].str, mii.hbmpItem);
2389 else
2391 ok(mii.cch == strlen(item[i].str),
2392 "%u: expected cch %u, got %u\n", i, (UINT)strlen(item[i].str), mii.cch);
2393 ok(!strcmp(mii.dwTypeData, item[i].str),
2394 "%u: expected dwTypeData %s, got %s\n", i, item[i].str, (LPCSTR)mii.dwTypeData);
2399 static void test_InsertMenu(void)
2401 /* Note: XP treats only bitmap handles 1 - 6 as "magic" ones
2402 * regardless of their id.
2404 static const struct menu_data in1[] =
2406 { MF_STRING, 1, "File" },
2407 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) },
2408 { MF_STRING|MF_HELP, 2, "Help" }
2410 static const struct menu_data out1[] =
2412 { MF_STRING, 1, "File" },
2413 { MF_STRING|MF_HELP, 2, "Help" },
2414 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) }
2416 static const struct menu_data in2[] =
2418 { MF_STRING, 1, "File" },
2419 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(100) },
2420 { MF_STRING|MF_HELP, 2, "Help" }
2422 static const struct menu_data out2[] =
2424 { MF_STRING, 1, "File" },
2425 { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(100) },
2426 { MF_STRING|MF_HELP, 2, "Help" }
2428 static const struct menu_data in3[] =
2430 { MF_STRING, 1, "File" },
2431 { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(1) },
2432 { MF_STRING|MF_HELP, 2, "Help" }
2434 static const struct menu_data out3[] =
2436 { MF_STRING, 1, "File" },
2437 { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCE(0) },
2438 { MF_STRING|MF_HELP, 2, "Help" },
2440 static const struct menu_data in4[] =
2442 { MF_STRING, 1, "File" },
2443 { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCE(1) },
2444 { MF_STRING|MF_HELP, 2, "Help" }
2446 static const struct menu_data out4[] =
2448 { MF_STRING, 1, "File" },
2449 { MF_STRING|MF_HELP, 2, "Help" },
2450 { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCE(1) }
2452 HMENU hmenu;
2454 #define create_menu(a) create_menu_from_data((a), sizeof(a)/sizeof((a)[0]))
2455 #define compare_menu(h, a) compare_menu_data((h), (a), sizeof(a)/sizeof((a)[0]))
2457 hmenu = create_menu(in1);
2458 compare_menu(hmenu, out1);
2459 DestroyMenu(hmenu);
2461 hmenu = create_menu(in2);
2462 compare_menu(hmenu, out2);
2463 DestroyMenu(hmenu);
2465 hmenu = create_menu(in3);
2466 compare_menu(hmenu, out3);
2467 DestroyMenu(hmenu);
2469 hmenu = create_menu(in4);
2470 compare_menu(hmenu, out4);
2471 DestroyMenu(hmenu);
2473 #undef create_menu
2474 #undef compare_menu
2477 static void test_menu_getmenuinfo(void)
2479 HMENU hmenu;
2480 MENUINFO mi = {0};
2481 BOOL ret;
2482 DWORD gle;
2484 /* create a menu */
2485 hmenu = CreateMenu();
2486 assert( hmenu);
2487 /* test some parameter errors */
2488 SetLastError(0xdeadbeef);
2489 ret = pGetMenuInfo( hmenu, NULL);
2490 gle= GetLastError();
2491 ok( !ret, "GetMenuInfo() should have failed\n");
2492 ok( gle == ERROR_INVALID_PARAMETER ||
2493 broken(gle == 0xdeadbeef), /* Win98, WinME */
2494 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2495 SetLastError(0xdeadbeef);
2496 mi.cbSize = 0;
2497 ret = pGetMenuInfo( hmenu, &mi);
2498 gle= GetLastError();
2499 ok( !ret, "GetMenuInfo() should have failed\n");
2500 ok( gle == ERROR_INVALID_PARAMETER ||
2501 broken(gle == 0xdeadbeef), /* Win98, WinME */
2502 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2503 SetLastError(0xdeadbeef);
2504 mi.cbSize = sizeof( MENUINFO);
2505 ret = pGetMenuInfo( hmenu, &mi);
2506 gle= GetLastError();
2507 ok( ret, "GetMenuInfo() should have succeeded\n");
2508 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2509 SetLastError(0xdeadbeef);
2510 mi.cbSize = 0;
2511 ret = pGetMenuInfo( NULL, &mi);
2512 gle= GetLastError();
2513 ok( !ret, "GetMenuInfo() should have failed\n");
2514 ok( gle == ERROR_INVALID_PARAMETER ||
2515 broken(gle == 0xdeadbeef), /* Win98, WinME */
2516 "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2517 /* clean up */
2518 DestroyMenu( hmenu);
2519 return;
2522 static void test_menu_setmenuinfo(void)
2524 HMENU hmenu, hsubmenu;
2525 MENUINFO mi = {0};
2526 MENUITEMINFOA mii = {sizeof( MENUITEMINFOA)};
2527 BOOL ret;
2528 DWORD gle;
2530 /* create a menu with a submenu */
2531 hmenu = CreateMenu();
2532 hsubmenu = CreateMenu();
2533 assert( hmenu && hsubmenu);
2534 mii.fMask = MIIM_SUBMENU;
2535 mii.hSubMenu = hsubmenu;
2536 ret = InsertMenuItem( hmenu, 0, FALSE, &mii);
2537 ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
2538 /* test some parameter errors */
2539 SetLastError(0xdeadbeef);
2540 ret = pSetMenuInfo( hmenu, NULL);
2541 gle= GetLastError();
2542 ok( !ret, "SetMenuInfo() should have failed\n");
2543 ok( gle == ERROR_INVALID_PARAMETER ||
2544 broken(gle == 0xdeadbeef), /* Win98, WinME */
2545 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2546 SetLastError(0xdeadbeef);
2547 mi.cbSize = 0;
2548 ret = pSetMenuInfo( hmenu, &mi);
2549 gle= GetLastError();
2550 ok( !ret, "SetMenuInfo() should have failed\n");
2551 ok( gle == ERROR_INVALID_PARAMETER ||
2552 broken(gle == 0xdeadbeef), /* Win98, WinME */
2553 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2554 SetLastError(0xdeadbeef);
2555 mi.cbSize = sizeof( MENUINFO);
2556 ret = pSetMenuInfo( hmenu, &mi);
2557 gle= GetLastError();
2558 ok( ret, "SetMenuInfo() should have succeeded\n");
2559 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2560 SetLastError(0xdeadbeef);
2561 mi.cbSize = 0;
2562 ret = pSetMenuInfo( NULL, &mi);
2563 gle= GetLastError();
2564 ok( !ret, "SetMenuInfo() should have failed\n");
2565 ok( gle == ERROR_INVALID_PARAMETER ||
2566 broken(gle == 0xdeadbeef), /* Win98, WinME */
2567 "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
2568 /* functional tests */
2569 /* menu and submenu should have the CHECKORBMP style bit cleared */
2570 SetLastError(0xdeadbeef);
2571 mi.cbSize = sizeof( MENUINFO);
2572 mi.fMask = MIM_STYLE;
2573 ret = pGetMenuInfo( hmenu, &mi);
2574 gle= GetLastError();
2575 ok( ret, "GetMenuInfo() should have succeeded\n");
2576 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2577 ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2578 SetLastError(0xdeadbeef);
2579 mi.cbSize = sizeof( MENUINFO);
2580 mi.fMask = MIM_STYLE;
2581 ret = pGetMenuInfo( hsubmenu, &mi);
2582 gle= GetLastError();
2583 ok( ret, "GetMenuInfo() should have succeeded\n");
2584 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2585 ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
2586 /* SetMenuInfo() */
2587 SetLastError(0xdeadbeef);
2588 mi.cbSize = sizeof( MENUINFO);
2589 mi.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS;
2590 mi.dwStyle = MNS_CHECKORBMP;
2591 ret = pSetMenuInfo( hmenu, &mi);
2592 gle= GetLastError();
2593 ok( ret, "SetMenuInfo() should have succeeded\n");
2594 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2595 /* Now both menus should have the MNS_CHECKORBMP style bit set */
2596 SetLastError(0xdeadbeef);
2597 mi.cbSize = sizeof( MENUINFO);
2598 mi.fMask = MIM_STYLE;
2599 ret = pGetMenuInfo( hmenu, &mi);
2600 gle= GetLastError();
2601 ok( ret, "GetMenuInfo() should have succeeded\n");
2602 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2603 ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2604 SetLastError(0xdeadbeef);
2605 mi.cbSize = sizeof( MENUINFO);
2606 mi.fMask = MIM_STYLE;
2607 ret = pGetMenuInfo( hsubmenu, &mi);
2608 gle= GetLastError();
2609 ok( ret, "GetMenuInfo() should have succeeded\n");
2610 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2611 ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
2612 /* now repeat that without the APPLYTOSUBMENUS flag and another style bit */
2613 SetLastError(0xdeadbeef);
2614 mi.cbSize = sizeof( MENUINFO);
2615 mi.fMask = MIM_STYLE ;
2616 mi.dwStyle = MNS_NOCHECK;
2617 ret = pSetMenuInfo( hmenu, &mi);
2618 gle= GetLastError();
2619 ok( ret, "SetMenuInfo() should have succeeded\n");
2620 ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
2621 /* Now only the top menu should have the MNS_NOCHECK style bit set */
2622 SetLastError(0xdeadbeef);
2623 mi.cbSize = sizeof( MENUINFO);
2624 mi.fMask = MIM_STYLE;
2625 ret = pGetMenuInfo( hmenu, &mi);
2626 gle= GetLastError();
2627 ok( ret, "GetMenuInfo() should have succeeded\n");
2628 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2629 ok( mi.dwStyle & MNS_NOCHECK, "menustyle was expected to have the MNS_NOCHECK flag\n");
2630 SetLastError(0xdeadbeef);
2631 mi.cbSize = sizeof( MENUINFO);
2632 mi.fMask = MIM_STYLE;
2633 ret = pGetMenuInfo( hsubmenu, &mi);
2634 gle= GetLastError();
2635 ok( ret, "GetMenuInfo() should have succeeded\n");
2636 ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
2637 ok( !(mi.dwStyle & MNS_NOCHECK), "menustyle was not expected to have the MNS_NOCHECK flag\n");
2638 /* clean up */
2639 DestroyMenu( hsubmenu);
2640 DestroyMenu( hmenu);
2641 return;
2644 /* little func to easy switch either TrackPopupMenu() or TrackPopupMenuEx() */
2645 static DWORD MyTrackPopupMenu( int ex, HMENU hmenu, UINT flags, INT x, INT y, HWND hwnd, LPTPMPARAMS ptpm)
2647 return ex
2648 ? TrackPopupMenuEx( hmenu, flags, x, y, hwnd, ptpm)
2649 : TrackPopupMenu( hmenu, flags, x, y, 0, hwnd, NULL);
2652 /* some TrackPopupMenu and TrackPopupMenuEx tests */
2653 /* the LastError values differ between NO_ERROR and invalid handle */
2654 /* between all windows versions tested. The first value is that valid on XP */
2655 /* Vista was the only that made returned different error values */
2656 /* between the TrackPopupMenu and TrackPopupMenuEx functions */
2657 static void test_menu_trackpopupmenu(void)
2659 BOOL ret;
2660 HMENU hmenu;
2661 DWORD gle;
2662 int Ex;
2663 HWND hwnd = CreateWindowEx(0, MAKEINTATOM(atomMenuCheckClass), NULL,
2664 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
2665 NULL, NULL, NULL, NULL);
2666 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
2667 if (!hwnd) return;
2668 SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
2669 for( Ex = 0; Ex < 2; Ex++)
2671 hmenu = CreatePopupMenu();
2672 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
2673 if (!hmenu)
2675 DestroyWindow(hwnd);
2676 return;
2678 /* display the menu */
2679 /* start with an invalid menu handle */
2680 gle = 0xdeadbeef;
2681 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2682 ret = MyTrackPopupMenu( Ex, NULL, 0x100, 100,100, hwnd, NULL);
2683 gle = GetLastError();
2684 ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
2685 ok( gle == ERROR_INVALID_MENU_HANDLE
2686 || broken (gle == 0xdeadbeef) /* win95 */
2687 || broken (gle == NO_ERROR) /* win98/ME */
2688 ,"TrackPopupMenu%s error got %u expected %u\n",
2689 Ex ? "Ex" : "", gle, ERROR_INVALID_MENU_HANDLE);
2690 ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
2691 "got unexpected message(s)%s%s%s\n",
2692 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2693 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2694 gflag_initmenu ? "WM_INITMENU": "");
2695 /* another one but not NULL */
2696 gle = 0xdeadbeef;
2697 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2698 ret = MyTrackPopupMenu( Ex, (HMENU)hwnd, 0x100, 100,100, hwnd, NULL);
2699 gle = GetLastError();
2700 ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
2701 ok( gle == ERROR_INVALID_MENU_HANDLE
2702 || broken (gle == 0xdeadbeef) /* win95 */
2703 || broken (gle == NO_ERROR) /* win98/ME */
2704 ,"TrackPopupMenu%s error got %u expected %u\n",
2705 Ex ? "Ex" : "", gle, ERROR_INVALID_MENU_HANDLE);
2706 ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
2707 "got unexpected message(s)%s%s%s\n",
2708 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2709 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2710 gflag_initmenu ? "WM_INITMENU": "");
2711 /* now a somewhat successfull call */
2712 gle = 0xdeadbeef;
2713 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2714 ret = MyTrackPopupMenu( Ex, hmenu, 0x100, 100,100, hwnd, NULL);
2715 gle = GetLastError();
2716 ok( ret == 0, "TrackPopupMenu%s returned %d expected zero\n", Ex ? "Ex" : "", ret);
2717 ok( gle == NO_ERROR
2718 || gle == ERROR_INVALID_MENU_HANDLE /* NT4, win2k */
2719 || broken (gle == 0xdeadbeef) /* win95 */
2720 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
2721 Ex ? "Ex" : "", gle, NO_ERROR, ERROR_INVALID_MENU_HANDLE);
2722 ok( gflag_initmenupopup && gflag_entermenuloop && gflag_initmenu,
2723 "missed expected message(s)%s%s%s\n",
2724 !gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2725 !gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2726 !gflag_initmenu ? "WM_INITMENU": "");
2727 /* and another */
2728 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest");
2729 ok( ret, "AppendMenA has failed!\n");
2730 gle = 0xdeadbeef;
2731 gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
2732 ret = MyTrackPopupMenu( Ex, hmenu, 0x100, 100,100, hwnd, NULL);
2733 gle = GetLastError();
2734 ok( ret == 0, "TrackPopupMenu%s returned %d expected zero\n", Ex ? "Ex" : "", ret);
2735 ok( gle == NO_ERROR
2736 || gle == ERROR_INVALID_MENU_HANDLE /* NT4, win2k and Vista in the TrackPopupMenuEx case */
2737 || broken (gle == 0xdeadbeef) /* win95 */
2738 ,"TrackPopupMenu%s error got %u expected %u or %u\n",
2739 Ex ? "Ex" : "", gle, NO_ERROR, ERROR_INVALID_MENU_HANDLE);
2740 ok( gflag_initmenupopup && gflag_entermenuloop && gflag_initmenu,
2741 "missed expected message(s)%s%s%s\n",
2742 !gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
2743 !gflag_entermenuloop ? "WM_INITMENULOOP ": "",
2744 !gflag_initmenu ? "WM_INITMENU": "");
2745 DestroyMenu(hmenu);
2747 /* clean up */
2748 DestroyWindow(hwnd);
2751 START_TEST(menu)
2753 init_function_pointers();
2755 /* Wine defines MENUITEMINFO for W2K and above. NT4 and below can't
2756 * handle that.
2758 if (correct_behavior())
2760 test_menu_add_string();
2761 test_menu_iteminfo();
2762 test_menu_search_bycommand();
2763 test_CheckMenuRadioItem();
2764 test_menu_resource_layout();
2765 test_InsertMenu();
2768 register_menu_check_class();
2770 test_menu_locked_by_window();
2771 test_menu_ownerdraw();
2772 test_menu_bmp_and_string();
2773 /* test Get/SetMenuInfo if available */
2774 if( pGetMenuInfo && pSetMenuInfo) {
2775 test_menu_getmenuinfo();
2776 test_menu_setmenuinfo();
2777 } else
2778 win_skip("Get/SetMenuInfo are not available\n");
2779 if( !pSendInput)
2780 win_skip("SendInput is not available\n");
2781 else
2782 test_menu_input();
2783 test_menu_flags();
2785 test_menu_hilitemenuitem();
2786 test_menu_trackpopupmenu();