[USER32_WINETEST] Add a PCH.
[reactos.git] / modules / rostests / winetests / user32 / menu.c
1 /*
2 * Unit tests for menus
3 *
4 * Copyright 2005 Robert Shearman
5 * Copyright 2007 Dmitry Timoshkov
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #include "precomp.h"
23
24 static ATOM atomMenuCheckClass;
25
26 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
27 static BOOL (WINAPI *pGetMenuBarInfo)(HWND,LONG,LONG,PMENUBARINFO);
28 static UINT (WINAPI *pSendInput)(UINT, INPUT*, size_t);
29 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
30 static BOOL (WINAPI *pEndMenu) (void);
31
32 static void init_function_pointers(void)
33 {
34 HMODULE hdll = GetModuleHandleA("user32");
35
36 #define GET_PROC(func) \
37 p ## func = (void*)GetProcAddress(hdll, #func); \
38 if(!p ## func) \
39 trace("GetProcAddress(%s) failed\n", #func);
40
41 GET_PROC(GetMenuInfo)
42 GET_PROC(GetMenuBarInfo)
43 GET_PROC(SendInput)
44 GET_PROC(SetMenuInfo)
45 GET_PROC(EndMenu)
46
47 #undef GET_PROC
48 }
49
50 static BOOL correct_behavior(void)
51 {
52 HMENU hmenu;
53 MENUITEMINFOA info;
54 BOOL rc;
55
56 hmenu = CreateMenu();
57
58 memset(&info, 0, sizeof(MENUITEMINFOA));
59 info.cbSize= sizeof(MENUITEMINFOA);
60 SetLastError(0xdeadbeef);
61 rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info);
62 /* Win9x : 0xdeadbeef
63 * NT4 : ERROR_INVALID_PARAMETER
64 * >= W2K : ERROR_MENU_ITEM_NOT_FOUND
65 */
66 if (!rc && GetLastError() != ERROR_MENU_ITEM_NOT_FOUND)
67 {
68 win_skip("NT4 and below can't handle a bigger MENUITEMINFO struct\n");
69 DestroyMenu(hmenu);
70 return FALSE;
71 }
72
73 DestroyMenu(hmenu);
74 return TRUE;
75 }
76
77 static LRESULT WINAPI menu_check_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
78 {
79 switch (msg)
80 {
81 case WM_ENTERMENULOOP:
82 /* mark window as having entered menu loop */
83 SetWindowLongPtrA(hwnd, GWLP_USERDATA, TRUE);
84 /* exit menu modal loop
85 * ( A SendMessage does not work on NT3.51 here ) */
86 return PostMessageA(hwnd, WM_CANCELMODE, 0, 0);
87 }
88 return DefWindowProcA(hwnd, msg, wparam, lparam);
89 }
90
91 /* The MSVC headers ignore our NONAMELESSUNION requests so we have to define
92 * our own type */
93 typedef struct
94 {
95 DWORD type;
96 union
97 {
98 MOUSEINPUT mi;
99 KEYBDINPUT ki;
100 HARDWAREINPUT hi;
101 } u;
102 } TEST_INPUT;
103
104 /* globals to communicate between test and wndproc */
105
106 static BOOL bMenuVisible;
107 static INT popmenu;
108 static BOOL got_input;
109 static HMENU hMenus[4];
110
111 #define MOD_SIZE 10
112 #define MOD_NRMENUS 8
113
114 /* menu texts with their sizes */
115 static struct {
116 LPCSTR text;
117 SIZE size; /* size of text up to any \t */
118 SIZE sc_size; /* size of the short-cut */
119 } MOD_txtsizes[] = {
120 { "Pinot &Noir" },
121 { "&Merlot\bF4" },
122 { "Shira&z\tAlt+S" },
123 { "" },
124 { NULL }
125 };
126
127 static unsigned int MOD_maxid;
128 static RECT MOD_rc[MOD_NRMENUS];
129 static int MOD_avec, MOD_hic;
130 static int MOD_odheight;
131 static SIZE MODsizes[MOD_NRMENUS]= { {MOD_SIZE, MOD_SIZE},{MOD_SIZE, MOD_SIZE},
132 {MOD_SIZE, MOD_SIZE},{MOD_SIZE, MOD_SIZE}};
133 static BOOL MOD_GotDrawItemMsg = FALSE;
134 static int gflag_initmenupopup,
135 gflag_entermenuloop,
136 gflag_initmenu,
137 gflag_enteridle;
138 static WPARAM selectitem_wp;
139 static LPARAM selectitem_lp;
140
141 /* wndproc used by test_menu_ownerdraw() */
142 static LRESULT WINAPI menu_ownerdraw_wnd_proc(HWND hwnd, UINT msg,
143 WPARAM wparam, LPARAM lparam)
144 {
145 static HMENU hmenupopup;
146 switch (msg)
147 {
148 case WM_INITMENUPOPUP:
149 gflag_initmenupopup++;
150 hmenupopup = (HMENU) wparam;
151 break;
152 case WM_ENTERMENULOOP:
153 gflag_entermenuloop++;
154 break;
155 case WM_INITMENU:
156 gflag_initmenu++;
157 break;
158 case WM_MEASUREITEM:
159 {
160 MEASUREITEMSTRUCT* pmis = (MEASUREITEMSTRUCT*)lparam;
161 if (winetest_debug > 1)
162 trace("WM_MEASUREITEM received data %lx size %dx%d\n",
163 pmis->itemData, pmis->itemWidth, pmis->itemHeight);
164 ok( !wparam, "wrong wparam %lx\n", wparam );
165 ok( pmis->CtlType == ODT_MENU, "wrong type %x\n", pmis->CtlType );
166 MOD_odheight = pmis->itemHeight;
167 pmis->itemWidth = MODsizes[pmis->itemData].cx;
168 pmis->itemHeight = MODsizes[pmis->itemData].cy;
169 return TRUE;
170 }
171 case WM_DRAWITEM:
172 {
173 DRAWITEMSTRUCT * pdis;
174 TEXTMETRICA tm;
175 HPEN oldpen;
176 char chrs[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
177 SIZE sz;
178 int i;
179 pdis = (DRAWITEMSTRUCT *) lparam;
180 if (winetest_debug > 1) {
181 RECT rc;
182 GetMenuItemRect( hwnd, (HMENU)pdis->hwndItem, pdis->itemData ,&rc);
183 trace("WM_DRAWITEM received hwnd %p hmenu %p itemdata %ld item %d rc %s itemrc: %s\n",
184 hwnd, pdis->hwndItem, pdis->itemData, pdis->itemID,
185 wine_dbgstr_rect(&pdis->rcItem), wine_dbgstr_rect(&rc));
186 oldpen=SelectObject( pdis->hDC, GetStockObject(
187 pdis->itemState & ODS_SELECTED ? WHITE_PEN :BLACK_PEN));
188 Rectangle( pdis->hDC, pdis->rcItem.left,pdis->rcItem.top,
189 pdis->rcItem.right,pdis->rcItem.bottom );
190 SelectObject( pdis->hDC, oldpen);
191 }
192 ok( !wparam, "wrong wparam %lx\n", wparam );
193 ok( pdis->CtlType == ODT_MENU, "wrong type %x\n", pdis->CtlType );
194 /* calculate widths of some menu texts */
195 if( ! MOD_txtsizes[0].size.cx)
196 for(i = 0; MOD_txtsizes[i].text; i++) {
197 char buf[100], *p;
198 RECT rc={0,0,0,0};
199 strcpy( buf, MOD_txtsizes[i].text);
200 if( ( p = strchr( buf, '\t'))) {
201 *p = '\0';
202 DrawTextA( pdis->hDC, p + 1, -1, &rc,
203 DT_SINGLELINE|DT_CALCRECT);
204 MOD_txtsizes[i].sc_size.cx= rc.right - rc.left;
205 MOD_txtsizes[i].sc_size.cy= rc.bottom - rc.top;
206 }
207 DrawTextA( pdis->hDC, buf, -1, &rc,
208 DT_SINGLELINE|DT_CALCRECT);
209 MOD_txtsizes[i].size.cx= rc.right - rc.left;
210 MOD_txtsizes[i].size.cy= rc.bottom - rc.top;
211 }
212
213 if( pdis->itemData > MOD_maxid) return TRUE;
214 /* store the rectangle */
215 MOD_rc[pdis->itemData] = pdis->rcItem;
216 /* calculate average character width */
217 GetTextExtentPointA( pdis->hDC, chrs, 52, &sz );
218 MOD_avec = (sz.cx + 26)/52;
219 GetTextMetricsA( pdis->hDC, &tm);
220 MOD_hic = tm.tmHeight;
221 MOD_GotDrawItemMsg = TRUE;
222 return TRUE;
223 }
224 case WM_ENTERIDLE:
225 {
226 gflag_enteridle++;
227 ok( lparam || broken(!lparam), /* win9x, nt4 */
228 "Menu window handle is NULL!\n");
229 if( lparam) {
230 HMENU hmenu = (HMENU)SendMessageA( (HWND)lparam, MN_GETHMENU, 0, 0);
231 ok( hmenupopup == hmenu, "MN_GETHMENU returns %p expected %p\n",
232 hmenu, hmenupopup);
233 }
234 PostMessageA(hwnd, WM_CANCELMODE, 0, 0);
235 return TRUE;
236 }
237 case WM_MENUSELECT:
238 selectitem_wp = wparam;
239 selectitem_lp = lparam;
240 break;
241 }
242 return DefWindowProcA(hwnd, msg, wparam, lparam);
243 }
244
245 static void register_menu_check_class(void)
246 {
247 WNDCLASSA wc =
248 {
249 0,
250 menu_check_wnd_proc,
251 0,
252 0,
253 GetModuleHandleA(NULL),
254 NULL,
255 LoadCursorA(NULL, (LPCSTR)IDC_ARROW),
256 (HBRUSH)(COLOR_BTNFACE+1),
257 NULL,
258 "WineMenuCheck",
259 };
260
261 atomMenuCheckClass = RegisterClassA(&wc);
262 }
263
264 static void test_getmenubarinfo(void)
265 {
266 BOOL ret;
267 HMENU hmenu;
268 MENUBARINFO mbi;
269 RECT rcw, rci;
270 HWND hwnd;
271 INT err;
272
273 if (!pGetMenuBarInfo) {
274 win_skip("GetMenuBarInfo is not available\n");
275 return;
276 }
277
278 mbi.cbSize = sizeof(MENUBARINFO);
279
280 hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
281 WS_SYSMENU | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
282 NULL, NULL, NULL, NULL);
283 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
284
285 /* no menu: getmenubarinfo should fail */
286 SetLastError(0xdeadbeef);
287 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
288 err = GetLastError();
289 ok(ret == FALSE, "GetMenuBarInfo should not have been successful\n");
290 ok(err == 0xdeadbeef, "err = %d\n", err);
291
292 /* create menubar, no items yet */
293 hmenu = CreateMenu();
294 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
295
296 ret = SetMenu(hwnd, hmenu);
297 ok(ret, "SetMenu failed with error %d\n", GetLastError());
298
299 SetLastError(0xdeadbeef);
300 ret = pGetMenuBarInfo(NULL, OBJID_CLIENT, 0, &mbi);
301 err = GetLastError();
302 ok(!ret, "GetMenuBarInfo succeeded\n");
303 ok(err == ERROR_INVALID_WINDOW_HANDLE, "err = %d\n", err);
304
305 SetLastError(0xdeadbeef);
306 ret = pGetMenuBarInfo(hwnd, OBJID_CLIENT, 0, &mbi);
307 err = GetLastError();
308 ok(!ret, "GetMenuBarInfo succeeded\n");
309 ok(err==ERROR_INVALID_MENU_HANDLE || broken(err==0xdeadbeef) /* NT, W2K, XP */, "err = %d\n", err);
310
311 SetLastError(0xdeadbeef);
312 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, -1, &mbi);
313 err = GetLastError();
314 ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
315 ok(err == 0xdeadbeef, "err = %d\n", err);
316
317 mbi.cbSize = 1000;
318 SetLastError(0xdeadbeef);
319 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
320 err = GetLastError();
321 ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
322 ok(err == ERROR_INVALID_PARAMETER, "err = %d\n", err);
323 mbi.cbSize = sizeof(MENUBARINFO);
324
325 SetLastError(0xdeadbeef);
326 ret = pGetMenuBarInfo(hwnd, 123, 0, &mbi);
327 err = GetLastError();
328 ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
329 ok(err == 0xdeadbeef, "err = %d\n", err);
330
331 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
332 ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
333
334 ok(mbi.rcBar.left == 0 && mbi.rcBar.top == 0 && mbi.rcBar.bottom == 0 && mbi.rcBar.right == 0,
335 "rcBar: Expected (0,0)-(0,0), got: %s\n", wine_dbgstr_rect(&mbi.rcBar));
336 ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n",
337 mbi.hMenu, hmenu);
338 ok(mbi.fBarFocused == 0, "fBarFocused: Got %d instead of 0.\n", mbi.fBarFocused);
339 ok(mbi.fFocused == 0, "fFocused: Got %d instead of 0.\n", mbi.fFocused);
340
341 /* add some items */
342 ret = AppendMenuA(hmenu, MF_STRING , 100, "item 1");
343 ok(ret, "AppendMenu failed.\n");
344 ret = AppendMenuA(hmenu, MF_STRING , 101, "item 2");
345 ok(ret, "AppendMenu failed.\n");
346 ret = SetMenu(hwnd, hmenu);
347 ok(ret, "SetMenu failed with error %d\n", GetLastError());
348
349 SetLastError(0xdeadbeef);
350 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 200, &mbi);
351 err = GetLastError();
352 ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
353 ok(err == 0xdeadbeef, "err = %d\n", err);
354
355 /* get info for the whole menu */
356 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
357 ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
358
359 /* calculate menu rectangle, from window rectangle and the position of the first item */
360 ret = GetWindowRect(hwnd, &rcw);
361 ok(ret, "GetWindowRect failed.\n");
362 ret = GetMenuItemRect(hwnd, hmenu, 0, &rci);
363 ok(ret, "GetMenuItemRect failed.\n");
364 todo_wine ok(mbi.rcBar.left == rci.left && mbi.rcBar.top == rci.top &&
365 mbi.rcBar.bottom == rci.bottom && mbi.rcBar.right == rcw.right - rci.left + rcw.left,
366 "rcBar: Got %s instead of (%d,%d)-(%d,%d)\n", wine_dbgstr_rect(&mbi.rcBar),
367 rci.left, rci.top, rcw.right - rci.left + rcw.left, rci.bottom);
368 ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n", mbi.hMenu, hmenu);
369 ok(mbi.fBarFocused == 0, "fBarFocused: got %d instead of 0\n", mbi.fBarFocused);
370 ok(mbi.fFocused == 0, "fFocused: got %d instead of 0\n", mbi.fFocused);
371
372 /* get info for item nr.2 */
373 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 2, &mbi);
374 ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
375 ret = GetMenuItemRect(hwnd, hmenu, 1, &rci);
376 ok(ret, "GetMenuItemRect failed.\n");
377 ok(EqualRect(&mbi.rcBar, &rci), "rcBar: Got %s instead of %s\n", wine_dbgstr_rect(&mbi.rcBar),
378 wine_dbgstr_rect(&rci));
379 ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n", mbi.hMenu, hmenu);
380 ok(mbi.fBarFocused == 0, "fBarFocused: got %d instead of 0\n", mbi.fBarFocused);
381 ok(mbi.fFocused == 0, "fFocused: got %d instead of 0\n", mbi.fFocused);
382
383 DestroyWindow(hwnd);
384 }
385
386 static void test_system_menu(void)
387 {
388 WCHAR testW[] = {'t','e','s','t',0};
389 BOOL ret;
390 HMENU menu;
391 HWND hwnd;
392 MENUITEMINFOA info;
393 MENUITEMINFOW infoW;
394 char buffer[80];
395 char found[0x200];
396 int i, res;
397
398 hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
399 WS_SYSMENU | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
400 NULL, NULL, NULL, NULL);
401 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
402 menu = GetSystemMenu( hwnd, FALSE );
403 ok( menu != NULL, "no system menu\n" );
404
405 for (i = 0xf000; i < 0xf200; i++)
406 {
407 memset( &info, 0xcc, sizeof(info) );
408 info.cbSize = sizeof(info);
409 info.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID;
410 info.dwTypeData = buffer;
411 info.cch = sizeof( buffer );
412 ret = GetMenuItemInfoA( menu, i, FALSE, &info );
413 if (ret) trace( "found %x: '%s'\n", i, buffer );
414 switch (i)
415 {
416 case SC_RESTORE:
417 case SC_SIZE:
418 case SC_MOVE:
419 case SC_MINIMIZE:
420 case SC_MAXIMIZE:
421 case SC_CLOSE:
422 ok( ret, "%x menu item not found\n", i );
423 break;
424 case SC_SCREENSAVE+1: /* used for the 'About Wine' entry, don't test */
425 break;
426 default:
427 ok( !ret, "%x menu item found\n", i );
428 break;
429 }
430 found[i - 0xf000] = ret;
431 }
432
433 for (i = 0xf000; i < 0xf200; i++)
434 {
435 res = CheckMenuItem( menu, i, 0 );
436 if (res == -1) ok( !found[i - 0xf000], "could not check existent item %x\n", i );
437 else ok( found[i - 0xf000], "could check non-existent item %x\n", i );
438
439 res = EnableMenuItem( menu, i, 0 );
440 if (res == -1) ok( !found[i - 0xf000], "could not enable existent item %x\n", i );
441 else ok( found[i - 0xf000], "could enable non-existent item %x\n", i );
442
443 res = GetMenuState( menu, i, 0 );
444 if (res == -1) ok( !found[i - 0xf000], "could not get state existent item %x\n", i );
445 else ok( found[i - 0xf000], "could get state of non-existent item %x\n", i );
446
447 if (!found[i - 0xf000]) /* don't remove the existing ones */
448 {
449 ret = RemoveMenu( menu, i, 0 );
450 ok( !ret, "could remove non-existent item %x\n", i );
451 }
452
453 ret = ModifyMenuA( menu, i, 0, i, "test" );
454 if (i == SC_TASKLIST) ok( ret, "failed to modify SC_TASKLIST\n" );
455 else if (!ret) ok( !found[i - 0xf000], "could not modify existent item %x\n", i );
456 else ok( found[i - 0xf000], "could modify non-existent item %x\n", i );
457
458 ret = ModifyMenuW( menu, i, 0, i, testW );
459 if (i == SC_TASKLIST) ok( ret, "failed to modify SC_TASKLIST\n" );
460 else if (!ret) ok( !found[i - 0xf000], "could not modify existent item %x\n", i );
461 else ok( found[i - 0xf000], "could modify non-existent item %x\n", i );
462
463 ret = ModifyMenuA( menu, i, MF_BYPOSITION, i, "test" );
464 ok( !ret, "could modify non-existent item %x\n", i );
465
466 strcpy( buffer, "test" );
467 memset( &info, 0xcc, sizeof(info) );
468 info.cbSize = sizeof(info);
469 info.fMask = MIIM_STRING | MIIM_ID;
470 info.wID = i;
471 info.dwTypeData = buffer;
472 info.cch = strlen( buffer );
473 ret = SetMenuItemInfoA( menu, i, FALSE, &info );
474 if (i == SC_TASKLIST) ok( ret, "failed to set SC_TASKLIST\n" );
475 else if (!ret) ok( !found[i - 0xf000], "could not set existent item %x\n", i );
476 else ok( found[i - 0xf000], "could set non-existent item %x\n", i );
477 ret = SetMenuItemInfoA( menu, i, TRUE, &info );
478 ok( !ret, "could modify non-existent item %x\n", i );
479
480 memset( &infoW, 0xcc, sizeof(infoW) );
481 infoW.cbSize = sizeof(infoW);
482 infoW.fMask = MIIM_STRING | MIIM_ID;
483 infoW.wID = i;
484 infoW.dwTypeData = testW;
485 infoW.cch = lstrlenW( testW );
486 ret = SetMenuItemInfoW( menu, i, FALSE, &infoW );
487 if (i == SC_TASKLIST) ok( ret, "failed to set SC_TASKLIST\n" );
488 else if (!ret) ok( !found[i - 0xf000], "could not set existent item %x\n", i );
489 else ok( found[i - 0xf000], "could set non-existent item %x\n", i );
490 ret = SetMenuItemInfoW( menu, i, TRUE, &infoW );
491 ok( !ret, "could modify non-existent item %x\n", i );
492 }
493
494 /* confirm that SC_TASKLIST still does not exist */
495 for (i = 0xf000; i < 0xf200; i++)
496 {
497 memset( &info, 0xcc, sizeof(info) );
498 info.cbSize = sizeof(info);
499 info.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID;
500 info.dwTypeData = buffer;
501 info.cch = sizeof( buffer );
502 ret = GetMenuItemInfoA( menu, i, FALSE, &info );
503 switch (i)
504 {
505 case SC_RESTORE:
506 case SC_SIZE:
507 case SC_MOVE:
508 case SC_MINIMIZE:
509 case SC_MAXIMIZE:
510 case SC_CLOSE:
511 ok( ret, "%x menu item not found\n", i );
512 break;
513 case SC_SCREENSAVE+1: /* used for the 'About Wine' entry, don't test */
514 break;
515 default:
516 ok( !ret, "%x menu item found\n", i );
517 break;
518 }
519 }
520
521 /* now a normal (non-system) menu */
522
523 menu = CreateMenu();
524 ok( menu != NULL, "CreateMenu failed with error %d\n", GetLastError() );
525
526 res = CheckMenuItem( menu, SC_TASKLIST, 0 );
527 ok( res == -1, "CheckMenuItem succeeded\n" );
528 res = EnableMenuItem( menu, SC_TASKLIST, 0 );
529 ok( res == -1, "EnableMenuItem succeeded\n" );
530 res = GetMenuState( menu, SC_TASKLIST, 0 );
531 ok( res == -1, "GetMenuState succeeded\n" );
532 ret = RemoveMenu( menu, SC_TASKLIST, 0 );
533 ok( !ret, "RemoveMenu succeeded\n" );
534 ret = ModifyMenuA( menu, SC_TASKLIST, 0, SC_TASKLIST, "test" );
535 ok( ret, "ModifyMenuA failed err %d\n", GetLastError() );
536 ret = ModifyMenuW( menu, SC_TASKLIST, 0, SC_TASKLIST, testW );
537 ok( ret, "ModifyMenuW failed err %d\n", GetLastError() );
538 ret = ModifyMenuA( menu, SC_TASKLIST-1, 0, SC_TASKLIST, "test" );
539 ok( !ret, "ModifyMenu succeeded on SC_TASKLIST-1\n" );
540 strcpy( buffer, "test" );
541 memset( &info, 0xcc, sizeof(info) );
542 info.cbSize = sizeof(info);
543 info.fMask = MIIM_STRING | MIIM_ID;
544 info.wID = SC_TASKLIST;
545 info.dwTypeData = buffer;
546 info.cch = strlen( buffer );
547 ret = SetMenuItemInfoA( menu, SC_TASKLIST, FALSE, &info );
548 ok( ret, "failed to set SC_TASKLIST\n" );
549 ret = SetMenuItemInfoA( menu, SC_TASKLIST+1, FALSE, &info );
550 ok( !ret, "succeeded setting SC_TASKLIST+1\n" );
551 ret = SetMenuItemInfoA( menu, SC_TASKLIST, TRUE, &info );
552 ok( !ret, "succeeded setting by position\n" );
553
554 memset( &infoW, 0xcc, sizeof(infoW) );
555 infoW.cbSize = sizeof(infoW);
556 infoW.fMask = MIIM_STRING | MIIM_ID;
557 infoW.wID = SC_TASKLIST;
558 infoW.dwTypeData = testW;
559 infoW.cch = lstrlenW( testW );
560 ret = SetMenuItemInfoW( menu, SC_TASKLIST, FALSE, &infoW );
561 ok( ret, "failed to set SC_TASKLIST\n" );
562 ret = SetMenuItemInfoW( menu, SC_TASKLIST+1, FALSE, &infoW );
563 ok( !ret, "succeeded setting SC_TASKLIST+1\n" );
564 ret = SetMenuItemInfoW( menu, SC_TASKLIST, TRUE, &infoW );
565 ok( !ret, "succeeded setting by position\n" );
566
567 DestroyMenu( menu );
568 DestroyWindow( hwnd );
569 }
570
571 /* demonstrates that windows locks the menu object so that it is still valid
572 * even after a client calls DestroyMenu on it */
573 static void test_menu_locked_by_window(void)
574 {
575 BOOL ret;
576 HMENU hmenu;
577 HWND hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
578 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
579 NULL, NULL, NULL, NULL);
580 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
581 hmenu = CreateMenu();
582 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
583 ret = InsertMenuA(hmenu, 0, MF_STRING, 0, "&Test");
584 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
585 ret = SetMenu(hwnd, hmenu);
586 ok(ret, "SetMenu failed with error %d\n", GetLastError());
587 ret = DestroyMenu(hmenu);
588 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
589
590 ret = DrawMenuBar(hwnd);
591 ok(ret, "DrawMenuBar failed with error %d\n", GetLastError());
592 ret = IsMenu(GetMenu(hwnd));
593 ok(!ret || broken(ret) /* nt4 */, "Menu handle should have been destroyed\n");
594
595 SendMessageA(hwnd, WM_SYSCOMMAND, SC_KEYMENU, 0);
596 /* did we process the WM_INITMENU message? */
597 ret = GetWindowLongPtrA(hwnd, GWLP_USERDATA);
598 todo_wine {
599 ok(ret, "WM_INITMENU should have been sent\n");
600 }
601
602 DestroyWindow(hwnd);
603 }
604
605 /* demonstrates that subpopup's are locked
606 * even after a client calls DestroyMenu on it */
607 static LRESULT WINAPI subpopuplocked_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
608 {
609 HWND hwndmenu;
610 switch (msg)
611 {
612 case WM_ENTERIDLE:
613 hwndmenu = GetCapture();
614 if( hwndmenu) {
615 PostMessageA( hwndmenu, WM_KEYDOWN, VK_DOWN, 0);
616 PostMessageA( hwndmenu, WM_KEYDOWN, VK_RIGHT, 0);
617 PostMessageA( hwndmenu, WM_KEYDOWN, VK_RETURN, 0);
618 }
619 }
620 return DefWindowProcA(hwnd, msg, wparam, lparam);
621 }
622
623 static void test_subpopup_locked_by_menu(void)
624 {
625 DWORD gle;
626 BOOL ret;
627 HMENU hmenu, hsubmenu;
628 MENUINFO mi = { sizeof( MENUINFO)};
629 MENUITEMINFOA mii = { sizeof( MENUITEMINFOA)};
630 HWND hwnd;
631 const int itemid = 0x1234567;
632 if( !pGetMenuInfo)
633 {
634 win_skip("GetMenuInfo is not available\n");
635 return;
636 }
637 /* create window, popupmenu with one subpopup */
638 hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
639 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
640 NULL, NULL, NULL, NULL);
641 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
642 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR) subpopuplocked_wnd_proc);
643 hmenu = CreatePopupMenu();
644 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
645 hsubmenu = CreatePopupMenu();
646 ok(hsubmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
647 ret = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hsubmenu,
648 "PopUpLockTest");
649 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
650 ret = InsertMenuA(hsubmenu, 0, MF_BYPOSITION | MF_STRING, itemid, "PopUpMenu");
651 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
652 /* first some tests that all this functions properly */
653 mii.fMask = MIIM_SUBMENU;
654 ret = GetMenuItemInfoA( hmenu, 0, TRUE, &mii);
655 ok( ret, "GetMenuItemInfo failed error %d\n", GetLastError());
656 ok( mii.hSubMenu == hsubmenu, "submenu is %p\n", mii.hSubMenu);
657 mi.fMask |= MIM_STYLE;
658 ret = pGetMenuInfo( hsubmenu, &mi);
659 ok( ret , "GetMenuInfo returned 0 with error %d\n", GetLastError());
660 ret = IsMenu( hsubmenu);
661 ok( ret , "Menu handle is not valid\n");
662 SetLastError( 0xdeadbeef);
663 ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
664 if( ret == (itemid & 0xffff)) {
665 win_skip("not on 16 bit menu subsystem\n");
666 DestroyMenu( hsubmenu);
667 } else {
668 gle = GetLastError();
669 ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, gle);
670 ok( gle == 0 ||
671 broken( gle == 0xdeadbeef), /* win2k0 */
672 "Last error is %d\n", gle);
673 /* then destroy the sub-popup */
674 ret = DestroyMenu( hsubmenu);
675 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
676 /* and repeat the tests */
677 mii.fMask = MIIM_SUBMENU;
678 ret = GetMenuItemInfoA( hmenu, 0, TRUE, &mii);
679 ok( ret, "GetMenuItemInfo failed error %d\n", GetLastError());
680 /* GetMenuInfo fails now */
681 ok( mii.hSubMenu == hsubmenu, "submenu is %p\n", mii.hSubMenu);
682 mi.fMask |= MIM_STYLE;
683 ret = pGetMenuInfo( hsubmenu, &mi);
684 ok( !ret , "GetMenuInfo should have failed\n");
685 /* IsMenu says it is not */
686 ret = IsMenu( hsubmenu);
687 ok( !ret , "Menu handle should be invalid\n");
688 /* but TrackPopupMenu still works! */
689 SetLastError( 0xdeadbeef);
690 ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
691 gle = GetLastError();
692 todo_wine {
693 ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, gle);
694 }
695 ok( gle == 0 ||
696 broken(gle == 0xdeadbeef) || /* wow64 */
697 broken(gle == ERROR_INVALID_PARAMETER), /* win2k0 */
698 "Last error is %d\n", gle);
699 }
700 /* clean up */
701 DestroyMenu( hmenu);
702 DestroyWindow(hwnd);
703 }
704
705 static void test_menu_ownerdraw(void)
706 {
707 int i,j,k;
708 BOOL ret;
709 HMENU hmenu;
710 MENUITEMINFOA mii;
711 LONG leftcol;
712 HWND hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
713 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
714 NULL, NULL, NULL, NULL);
715 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
716 if( !hwnd) return;
717 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
718 hmenu = CreatePopupMenu();
719 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
720 if( !hmenu) { DestroyWindow(hwnd);return;}
721 k=0;
722 for( j=0;j<2;j++) /* create columns */
723 for(i=0;i<2;i++) { /* create rows */
724 ret = AppendMenuA( hmenu, MF_OWNERDRAW |
725 (i==0 ? MF_MENUBREAK : 0), k, (LPCSTR)MAKEINTRESOURCE(k));
726 k++;
727 ok( ret, "AppendMenu failed for %d\n", k-1);
728 }
729 MOD_maxid = k-1;
730 assert( k <= sizeof(MOD_rc)/sizeof(RECT));
731 /* display the menu */
732 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
733
734 /* columns have a 4 pixel gap between them */
735 ok( MOD_rc[0].right + 4 == MOD_rc[2].left,
736 "item rectangles are not separated by 4 pixels space\n");
737 /* height should be what the MEASUREITEM message has returned */
738 ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
739 "menu item has wrong height: %d should be %d\n",
740 MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
741 /* no gaps between the rows */
742 ok( MOD_rc[0].bottom - MOD_rc[1].top == 0,
743 "There should not be a space between the rows, gap is %d\n",
744 MOD_rc[0].bottom - MOD_rc[1].top);
745 /* test the correct value of the item height that was sent
746 * by the WM_MEASUREITEM message */
747 ok( MOD_odheight == HIWORD( GetDialogBaseUnits()) || /* WinNT,2k,XP */
748 MOD_odheight == MOD_hic, /* Win95,98,ME */
749 "Wrong height field in MEASUREITEMSTRUCT, expected %d or %d actual %d\n",
750 HIWORD( GetDialogBaseUnits()), MOD_hic, MOD_odheight);
751 /* test what MF_MENUBREAK did at the first position. Also show
752 * that an MF_SEPARATOR is ignored in the height calculation. */
753 leftcol= MOD_rc[0].left;
754 ModifyMenuA( hmenu, 0, MF_BYCOMMAND| MF_OWNERDRAW| MF_SEPARATOR, 0, 0);
755 /* display the menu */
756 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
757 /* left should be 4 pixels less now */
758 ok( leftcol == MOD_rc[0].left + 4,
759 "columns should be 4 pixels to the left (actual %d).\n",
760 leftcol - MOD_rc[0].left);
761 /* test width */
762 ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
763 "width of owner drawn menu item is wrong. Got %d expected %d\n",
764 MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
765 /* and height */
766 ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
767 "Height is incorrect. Got %d expected %d\n",
768 MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
769
770 /* test owner-drawn callback bitmap */
771 ModifyMenuA( hmenu, 1, MF_BYPOSITION | MFT_BITMAP, 1, (LPCSTR)HBMMENU_CALLBACK );
772 mii.cbSize = sizeof(mii);
773 mii.fMask = MIIM_BITMAP | MIIM_FTYPE | MIIM_ID;
774 if (GetMenuItemInfoA( hmenu, 1, TRUE, &mii ))
775 {
776 ok( mii.fType == MFT_BITMAP, "wrong type %x\n", mii.fType );
777 ok( mii.wID == 1, "wrong id %x\n", mii.wID );
778 ok( mii.hbmpItem == HBMMENU_CALLBACK, "wrong data %p\n", mii.hbmpItem );
779 }
780 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
781
782 /* test width/height of an ownerdraw menu bar as well */
783 ret = DestroyMenu(hmenu);
784 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
785 hmenu = CreateMenu();
786 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
787 if( !hmenu) { DestroyWindow(hwnd);return;}
788 MOD_maxid=1;
789 for(i=0;i<2;i++) {
790 ret = AppendMenuA( hmenu, MF_OWNERDRAW, i, 0 );
791 ok( ret, "AppendMenu failed for %d\n", i);
792 }
793 ret = SetMenu( hwnd, hmenu);
794 UpdateWindow( hwnd); /* hack for wine to draw the window + menu */
795 ok(ret, "SetMenu failed with error %d\n", GetLastError());
796 /* test width */
797 ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
798 "width of owner drawn menu item is wrong. Got %d expected %d\n",
799 MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
800 /* test height */
801 ok( MOD_rc[0].bottom - MOD_rc[0].top == GetSystemMetrics( SM_CYMENU) - 1,
802 "Height of owner drawn menu item is wrong. Got %d expected %d\n",
803 MOD_rc[0].bottom - MOD_rc[0].top, GetSystemMetrics( SM_CYMENU) - 1);
804
805 /* clean up */
806 ret = DestroyMenu(hmenu);
807 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
808 DestroyWindow(hwnd);
809 }
810
811 /* helper for test_menu_bmp_and_string() */
812 static void test_mbs_help( int ispop, int hassub, int mnuopt,
813 HWND hwnd, int arrowwidth, int count, HBITMAP hbmp,
814 SIZE bmpsize, LPCSTR text, SIZE size, SIZE sc_size)
815 {
816 BOOL ret;
817 HMENU hmenu, submenu;
818 MENUITEMINFOA mii={ sizeof( MENUITEMINFOA )};
819 MENUINFO mi;
820 RECT rc;
821 CHAR text_copy[16];
822 int hastab, expect;
823 BOOL failed = FALSE;
824
825 MOD_GotDrawItemMsg = FALSE;
826 mii.fMask = MIIM_FTYPE | MIIM_DATA | MIIM_STATE;
827 mii.fType = 0;
828 /* check the menu item unless MNS_CHECKORBMP is set */
829 mii.fState = (mnuopt != 2 ? MFS_CHECKED : MFS_UNCHECKED);
830 mii.dwItemData =0;
831 MODsizes[0] = bmpsize;
832 hastab = 0;
833 if( text ) {
834 char *p;
835 mii.fMask |= MIIM_STRING;
836 strcpy(text_copy, text);
837 mii.dwTypeData = text_copy; /* structure member declared non-const */
838 if( ( p = strchr( text, '\t'))) {
839 hastab = *(p + 1) ? 2 : 1;
840 }
841 }
842 /* tabs don't make sense in menubars */
843 if(hastab && !ispop) return;
844 if( hbmp) {
845 mii.fMask |= MIIM_BITMAP;
846 mii.hbmpItem = hbmp;
847 }
848 submenu = CreateMenu();
849 ok( submenu != 0, "CreateMenu failed with error %d\n", GetLastError());
850 if( ispop)
851 hmenu = CreatePopupMenu();
852 else
853 hmenu = CreateMenu();
854 ok( hmenu != 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
855 if( hassub) {
856 mii.fMask |= MIIM_SUBMENU;
857 mii.hSubMenu = submenu;
858 }
859 if( mnuopt) {
860 mi.cbSize = sizeof(mi);
861 mi.fMask = MIM_STYLE;
862 pGetMenuInfo( hmenu, &mi);
863 if( mnuopt) mi.dwStyle |= mnuopt == 1 ? MNS_NOCHECK : MNS_CHECKORBMP;
864 ret = pSetMenuInfo( hmenu, &mi);
865 ok( ret, "SetMenuInfo failed with error %d\n", GetLastError());
866 }
867 ret = InsertMenuItemA( hmenu, 0, FALSE, &mii);
868 ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
869 failed = !ret;
870 if( winetest_debug) {
871 HDC hdc=GetDC(hwnd);
872 RECT rc = {100, 50, 400, 70};
873 char buf[100];
874
875 sprintf( buf,"%d text \"%s\" mnuopt %d", count, text ? text: "(nil)", mnuopt);
876 FillRect( hdc, &rc, (HBRUSH) COLOR_WINDOW);
877 TextOutA( hdc, 10, 50, buf, strlen( buf));
878 ReleaseDC( hwnd, hdc);
879 }
880 if(ispop)
881 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
882 else {
883 ret = SetMenu( hwnd, hmenu);
884 ok(ret, "SetMenu failed with error %d\n", GetLastError());
885 DrawMenuBar( hwnd);
886 }
887 ret = GetMenuItemRect( hwnd, hmenu, 0, &rc);
888 ok(ret, "GetMenuItemRect failed with error %d\n", GetLastError());
889
890 if (0) /* comment out menu size checks, behavior is different in almost every Windows version */
891 /* the tests should however succeed on win2000, XP and Wine (at least up to 1.1.15) */
892 /* with a variety of dpis and desktop font sizes */
893 {
894 /* check menu width */
895 if( ispop)
896 expect = ( text || hbmp ?
897 4 + (mnuopt != 1 ? GetSystemMetrics(SM_CXMENUCHECK) : 0)
898 : 0) +
899 arrowwidth + MOD_avec + (hbmp ?
900 ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ? bmpsize.cx + 2 : GetSystemMetrics( SM_CXMENUSIZE) + 2)
901 : 0) +
902 (text && hastab ? /* TAB space */
903 MOD_avec + ( hastab==2 ? sc_size.cx : 0) : 0) +
904 (text ? 2 + (text[0] ? size.cx :0): 0) ;
905 else
906 expect = !(text || hbmp) ? 0 :
907 ( hbmp ? (text ? 2:0) + bmpsize.cx : 0 ) +
908 (text ? 2 * MOD_avec + (text[0] ? size.cx :0): 0) ;
909 ok( rc.right - rc.left == expect,
910 "menu width wrong, got %d expected %d\n", rc.right - rc.left, expect);
911 failed = failed || !(rc.right - rc.left == expect);
912 /* check menu height */
913 if( ispop)
914 expect = max( ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 : 0),
915 max( (text ? max( 2 + size.cy, MOD_hic + 4) : 0),
916 (hbmp ?
917 ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ?
918 bmpsize.cy + 2
919 : GetSystemMetrics( SM_CYMENUSIZE) + 2)
920 : 0)));
921 else
922 expect = ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 :
923 max( GetSystemMetrics( SM_CYMENU) - 1, (hbmp ? bmpsize.cy : 0)));
924 ok( rc.bottom - rc.top == expect,
925 "menu height wrong, got %d expected %d (%d)\n",
926 rc.bottom - rc.top, expect, GetSystemMetrics( SM_CYMENU));
927 failed = failed || !(rc.bottom - rc.top == expect);
928 if( hbmp == HBMMENU_CALLBACK && MOD_GotDrawItemMsg) {
929 /* check the position of the bitmap */
930 /* horizontal */
931 if (!ispop)
932 expect = 3;
933 else if (mnuopt == 0)
934 expect = 4 + GetSystemMetrics(SM_CXMENUCHECK);
935 else if (mnuopt == 1)
936 expect = 4;
937 else /* mnuopt == 2 */
938 expect = 2;
939 ok( expect == MOD_rc[0].left,
940 "bitmap left is %d expected %d\n", MOD_rc[0].left, expect);
941 failed = failed || !(expect == MOD_rc[0].left);
942 /* vertical */
943 expect = (rc.bottom - rc.top - MOD_rc[0].bottom + MOD_rc[0].top) / 2;
944 ok( expect == MOD_rc[0].top,
945 "bitmap top is %d expected %d\n", MOD_rc[0].top, expect);
946 failed = failed || !(expect == MOD_rc[0].top);
947 }
948 }
949 /* if there was a failure, report details */
950 if( failed) {
951 trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
952 count, (ispop? "POPUP": "MENUBAR"),text ? text: "(nil)", hbmp, bmpsize.cx, bmpsize.cy,
953 size.cx, size.cy, sc_size.cx, mnuopt, hastab);
954 trace(" check %d,%d arrow %d avechar %d\n",
955 GetSystemMetrics(SM_CXMENUCHECK ),
956 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
957 if( hbmp == HBMMENU_CALLBACK)
958 trace( " rc %s bmp.rc %s\n", wine_dbgstr_rect(&rc), wine_dbgstr_rect(&MOD_rc[0]));
959 }
960 /* clean up */
961 ret = DestroyMenu(submenu);
962 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
963 ret = DestroyMenu(hmenu);
964 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
965 }
966
967
968 static void test_menu_bmp_and_string(void)
969 {
970 BYTE bmfill[300];
971 HBITMAP hbm_arrow;
972 BITMAP bm;
973 INT arrowwidth;
974 HWND hwnd;
975 HMENU hsysmenu;
976 MENUINFO mi= {sizeof(MENUINFO)};
977 MENUITEMINFOA mii= {sizeof(MENUITEMINFOA)};
978 int count, szidx, txtidx, bmpidx, hassub, mnuopt, ispop;
979 BOOL got;
980
981 if( !pGetMenuInfo)
982 {
983 win_skip("GetMenuInfo is not available\n");
984 return;
985 }
986
987 memset( bmfill, 0xcc, sizeof( bmfill));
988 hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL, WS_SYSMENU |
989 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
990 NULL, NULL, NULL, NULL);
991 hbm_arrow = LoadBitmapA( 0, (LPCSTR)OBM_MNARROW);
992 GetObjectA( hbm_arrow, sizeof(bm), &bm);
993 arrowwidth = bm.bmWidth;
994 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
995 if( !hwnd) return;
996 /* test system menu */
997 hsysmenu = GetSystemMenu( hwnd, FALSE);
998 ok( hsysmenu != NULL, "GetSystemMenu failed with error %d\n", GetLastError());
999 mi.fMask = MIM_STYLE;
1000 mi.dwStyle = 0;
1001 got = pGetMenuInfo( hsysmenu, &mi);
1002 ok( got, "GetMenuInfo failed gle=%d\n", GetLastError());
1003 ok( MNS_CHECKORBMP == mi.dwStyle, "System Menu Style is %08x, without the bit %08x\n",
1004 mi.dwStyle, MNS_CHECKORBMP);
1005 mii.fMask = MIIM_BITMAP;
1006 mii.hbmpItem = NULL;
1007 got = GetMenuItemInfoA( hsysmenu, SC_CLOSE, FALSE, &mii);
1008 ok( got, "GetMenuItemInfoA failed gle=%d\n", GetLastError());
1009 ok( HBMMENU_POPUP_CLOSE == mii.hbmpItem, "Item info did not get the right hbitmap: got %p expected %p\n",
1010 mii.hbmpItem, HBMMENU_POPUP_CLOSE);
1011
1012 memset(&mii, 0x81, sizeof(mii));
1013 mii.cbSize = sizeof(mii);
1014 mii.fMask = MIIM_STATE | MIIM_ID | MIIM_TYPE | MIIM_DATA;
1015 mii.dwTypeData = (LPSTR)bmfill;
1016 mii.cch = sizeof(bmfill);
1017 mii.dwItemData = 0x81818181;
1018 got = GetMenuItemInfoA(hsysmenu, SC_RESTORE, FALSE, &mii);
1019 ok(got, "GetMenuItemInfo failed\n");
1020 ok((mii.fType & ~(MFT_RIGHTJUSTIFY|MFT_RIGHTORDER)) == MFT_STRING, "expected MFT_STRING, got %#x\n", mii.fType);
1021 ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
1022 ok(mii.wID == SC_RESTORE, "expected SC_RESTORE, got %#x\n", mii.wID);
1023 ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
1024 ok(mii.dwItemData == 0, "expected 0, got %#lx\n", mii.dwItemData);
1025 ok(mii.dwTypeData == (LPSTR)bmfill, "expected %p, got %p\n", bmfill, mii.dwTypeData);
1026 ok(mii.cch != 0, "cch should not be 0\n");
1027 ok(mii.hbmpItem == HBMMENU_POPUP_RESTORE, "expected HBMMENU_POPUP_RESTORE, got %p\n", mii.hbmpItem);
1028
1029 mii.cbSize = sizeof(mii);
1030 mii.fMask = MIIM_TYPE;
1031 mii.hbmpItem = (HBITMAP)0x81818181;
1032 got = GetMenuItemInfoA(hsysmenu, SC_CLOSE, FALSE, &mii);
1033 ok(got, "GetMenuItemInfo failed\n");
1034 ok((mii.fType & ~(MFT_RIGHTJUSTIFY|MFT_RIGHTORDER)) == MFT_STRING, "expected MFT_STRING, got %#x\n", mii.fType);
1035 ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
1036 ok(mii.wID == SC_RESTORE, "expected SC_RESTORE, got %#x\n", mii.wID);
1037 ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
1038 ok(mii.dwItemData == 0, "expected 0, got %#lx\n", mii.dwItemData);
1039 ok(mii.dwTypeData == (LPSTR)bmfill, "expected %p, got %p\n", bmfill, mii.dwTypeData);
1040 ok(mii.cch != 0, "cch should not be 0\n");
1041 ok(mii.hbmpItem == HBMMENU_POPUP_CLOSE, "expected HBMMENU_POPUP_CLOSE, got %p\n", mii.hbmpItem);
1042
1043 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
1044
1045 if( winetest_debug)
1046 trace(" check %d,%d arrow %d avechar %d\n",
1047 GetSystemMetrics(SM_CXMENUCHECK ),
1048 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
1049 count = 0;
1050 MOD_maxid = 0;
1051 for( ispop=1; ispop >= 0; ispop--){
1052 static SIZE bmsizes[]= {
1053 {10,10},{38,38},{1,30},{55,5}};
1054 for( szidx=0; szidx < sizeof( bmsizes) / sizeof( SIZE); szidx++) {
1055 HBITMAP hbm = CreateBitmap( bmsizes[szidx].cx, bmsizes[szidx].cy,1,1,bmfill);
1056 HBITMAP bitmaps[] = { HBMMENU_CALLBACK, hbm, HBMMENU_POPUP_CLOSE, NULL };
1057 ok( hbm != 0, "CreateBitmap failed err %d\n", GetLastError());
1058 for( txtidx = 0; txtidx < sizeof(MOD_txtsizes)/sizeof(MOD_txtsizes[0]); txtidx++) {
1059 for( hassub = 0; hassub < 2 ; hassub++) { /* add submenu item */
1060 for( mnuopt = 0; mnuopt < 3 ; mnuopt++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
1061 for( bmpidx = 0; bmpidx <sizeof(bitmaps)/sizeof(HBITMAP); bmpidx++) {
1062 /* no need to test NULL bitmaps of several sizes */
1063 if( !bitmaps[bmpidx] && szidx > 0) continue;
1064 /* the HBMMENU_POPUP not to test for menu bars */
1065 if( !ispop &&
1066 bitmaps[bmpidx] >= HBMMENU_POPUP_CLOSE &&
1067 bitmaps[bmpidx] <= HBMMENU_POPUP_MINIMIZE) continue;
1068 if( !ispop && hassub) continue;
1069 test_mbs_help( ispop, hassub, mnuopt,
1070 hwnd, arrowwidth, ++count,
1071 bitmaps[bmpidx],
1072 bmsizes[szidx],
1073 MOD_txtsizes[txtidx].text,
1074 MOD_txtsizes[txtidx].size,
1075 MOD_txtsizes[txtidx].sc_size);
1076 }
1077 }
1078 }
1079 }
1080 DeleteObject( hbm);
1081 }
1082 }
1083 /* clean up */
1084 DestroyWindow(hwnd);
1085 }
1086
1087 static void test_menu_add_string( void )
1088 {
1089 HMENU hmenu;
1090 MENUITEMINFOA info;
1091 BOOL rc;
1092 int ret;
1093
1094 char string[0x80];
1095 char string2[0x80];
1096
1097 char strback[0x80];
1098 WCHAR strbackW[0x80];
1099 static CHAR blah[] = "blah";
1100 static const WCHAR expectedString[] = {'D','u','m','m','y',' ','s','t','r','i','n','g', 0};
1101
1102 hmenu = CreateMenu();
1103
1104 memset( &info, 0, sizeof info );
1105 info.cbSize = sizeof info;
1106 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_ID;
1107 info.dwTypeData = blah;
1108 info.cch = 6;
1109 info.dwItemData = 0;
1110 info.wID = 1;
1111 info.fState = 0;
1112 InsertMenuItemA(hmenu, 0, TRUE, &info );
1113
1114 memset( &info, 0, sizeof info );
1115 info.cbSize = sizeof info;
1116 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_DATA | MIIM_ID;
1117 info.dwTypeData = string;
1118 info.cch = sizeof string;
1119 string[0] = 0;
1120 GetMenuItemInfoA( hmenu, 0, TRUE, &info );
1121
1122 ok( !strcmp( string, "blah" ), "menu item name differed\n");
1123
1124 /* Test combination of ownerdraw and strings with GetMenuItemString(A/W) */
1125 strcpy(string, "Dummy string");
1126 memset(&info, 0x00, sizeof(info));
1127 info.cbSize= sizeof(MENUITEMINFOA);
1128 info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
1129 info.fType= MFT_OWNERDRAW;
1130 info.dwTypeData= string;
1131 rc = InsertMenuItemA( hmenu, 0, TRUE, &info );
1132 ok (rc, "InsertMenuItem failed\n");
1133
1134 strcpy(string,"Garbage");
1135 ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1136 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
1137
1138 SetLastError(0xdeadbeef);
1139 ret = GetMenuStringW( hmenu, 0, strbackW, 99, MF_BYPOSITION );
1140 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1141 win_skip("GetMenuStringW is not implemented\n");
1142 else
1143 {
1144 ok (ret, "GetMenuStringW on ownerdraw entry failed\n");
1145 ok (!lstrcmpW( strbackW, expectedString ), "Menu text from Unicode version incorrect\n");
1146 }
1147
1148 /* Just try some invalid parameter tests */
1149 SetLastError(0xdeadbeef);
1150 rc = SetMenuItemInfoA( hmenu, 0, TRUE, NULL );
1151 ret = GetLastError();
1152 ok (!rc, "SetMenuItemInfoA succeeded unexpectedly\n");
1153 ok (ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
1154
1155 SetLastError(0xdeadbeef);
1156 rc = SetMenuItemInfoA( hmenu, 0, FALSE, NULL );
1157 ret = GetLastError();
1158 ok (!rc, "SetMenuItemInfoA succeeded unexpectedly\n");
1159 ok (ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
1160
1161 /* Just change ftype to string and see what text is stored */
1162 memset(&info, 0x00, sizeof(info));
1163 info.cbSize= sizeof(MENUITEMINFOA);
1164 info.fMask= MIIM_FTYPE; /* Set string type */
1165 info.fType= MFT_STRING;
1166 info.dwTypeData= (char *)0xdeadbeef;
1167 rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1168 ok (rc, "SetMenuItemInfo failed\n");
1169
1170 /* Did we keep the old dwTypeData? */
1171 ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1172 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
1173
1174 /* Ensure change to bitmap type fails */
1175 memset(&info, 0x00, sizeof(info));
1176 info.cbSize= sizeof(MENUITEMINFOA);
1177 info.fMask= MIIM_FTYPE; /* Set as bitmap type */
1178 info.fType= MFT_BITMAP;
1179 info.dwTypeData= (char *)0xdeadbee2;
1180 rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1181 ok (!rc, "SetMenuItemInfo unexpectedly worked\n");
1182
1183 /* Just change ftype back and ensure data hasn't been freed */
1184 info.fType= MFT_OWNERDRAW; /* Set as ownerdraw type */
1185 info.dwTypeData= (char *)0xdeadbee3;
1186 rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1187 ok (rc, "SetMenuItemInfo failed\n");
1188
1189 /* Did we keep the old dwTypeData? */
1190 ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1191 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
1192
1193 /* Just change string value (not type) */
1194 memset(&info, 0x00, sizeof(info));
1195 info.cbSize= sizeof(MENUITEMINFOA);
1196 info.fMask= MIIM_STRING; /* Set typeData */
1197 strcpy(string2, "string2");
1198 info.dwTypeData= string2;
1199 rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1200 ok (rc, "SetMenuItemInfo failed\n");
1201
1202 ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1203 ok (!strcmp( strback, "string2" ), "Menu text from Ansi version incorrect\n");
1204
1205 /* crashes with wine 0.9.5 */
1206 memset(&info, 0x00, sizeof(info));
1207 info.cbSize= sizeof(MENUITEMINFOA);
1208 info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
1209 info.fType= MFT_OWNERDRAW;
1210 rc = InsertMenuItemA( hmenu, 0, TRUE, &info );
1211 ok (rc, "InsertMenuItem failed\n");
1212 ok (!GetMenuStringA( hmenu, 0, NULL, 0, MF_BYPOSITION),
1213 "GetMenuString on ownerdraw entry succeeded.\n");
1214 SetLastError(0xdeadbeef);
1215 ret = GetMenuStringW( hmenu, 0, NULL, 0, MF_BYPOSITION);
1216 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1217 win_skip("GetMenuStringW is not implemented\n");
1218 else
1219 ok (!ret, "GetMenuStringW on ownerdraw entry succeeded.\n");
1220
1221 DestroyMenu( hmenu );
1222 }
1223
1224 /* define building blocks for the menu item info tests */
1225 static int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
1226 {
1227 if (n <= 0) return 0;
1228 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
1229 return *str1 - *str2;
1230 }
1231
1232 static WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
1233 {
1234 WCHAR *p = dst;
1235 while ((*p++ = *src++));
1236 return dst;
1237 }
1238
1239 static void insert_menu_item( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state, UINT id,
1240 HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
1241 void *type_data, UINT len, HBITMAP item, BOOL expect )
1242 {
1243 MENUITEMINFOA info;
1244 BOOL ret;
1245
1246 /* magic bitmap handle to test smaller cbSize */
1247 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
1248 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
1249 else
1250 info.cbSize = sizeof(info);
1251 info.fMask = mask;
1252 info.fType = type;
1253 info.fState = state;
1254 info.wID = id;
1255 info.hSubMenu = submenu;
1256 info.hbmpChecked = checked;
1257 info.hbmpUnchecked = unchecked;
1258 info.dwItemData = data;
1259 info.dwTypeData = type_data;
1260 info.cch = len;
1261 info.hbmpItem = item;
1262 SetLastError( 0xdeadbeef );
1263 if (ansi) ret = InsertMenuItemA( hmenu, 0, TRUE, &info );
1264 else ret = InsertMenuItemW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
1265 if (!expect) ok_(__FILE__, line)( !ret, "InsertMenuItem should have failed.\n" );
1266 else ok_(__FILE__, line)( ret, "InsertMenuItem failed, err %u\n", GetLastError());
1267 }
1268
1269 static void check_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
1270 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked,
1271 ULONG_PTR data, void *type_data, UINT in_len, UINT out_len,
1272 HBITMAP item, LPCSTR expname, BOOL expect, BOOL expstring )
1273 {
1274 MENUITEMINFOA info;
1275 BOOL ret;
1276 WCHAR buffer[80];
1277
1278 SetLastError( 0xdeadbeef );
1279 memset( &info, 0xcc, sizeof(info) );
1280 info.cbSize = sizeof(info);
1281 info.fMask = mask;
1282 info.dwTypeData = type_data;
1283 info.cch = in_len;
1284
1285 ret = ansi ? GetMenuItemInfoA( hmenu, 0, TRUE, &info ) :
1286 GetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW *)&info );
1287 if (!expect)
1288 {
1289 ok_(__FILE__, line)( !ret, "GetMenuItemInfo should have failed.\n" );
1290 return;
1291 }
1292 ok_(__FILE__, line)( ret, "GetMenuItemInfo failed, err %u\n", GetLastError());
1293 if (mask & MIIM_TYPE)
1294 ok_(__FILE__, line)( info.fType == type || info.fType == LOWORD(type),
1295 "wrong type %x/%x\n", info.fType, type );
1296 if (mask & MIIM_STATE)
1297 ok_(__FILE__, line)( info.fState == state || info.fState == LOWORD(state),
1298 "wrong state %x/%x\n", info.fState, state );
1299 if (mask & MIIM_ID)
1300 ok_(__FILE__, line)( info.wID == id || info.wID == LOWORD(id),
1301 "wrong id %x/%x\n", info.wID, id );
1302 if (mask & MIIM_SUBMENU)
1303 ok_(__FILE__, line)( info.hSubMenu == submenu || (ULONG_PTR)info.hSubMenu == LOWORD(submenu),
1304 "wrong submenu %p/%p\n", info.hSubMenu, submenu );
1305 if (mask & MIIM_CHECKMARKS)
1306 {
1307 ok_(__FILE__, line)( info.hbmpChecked == checked || (ULONG_PTR)info.hbmpChecked == LOWORD(checked),
1308 "wrong bmpchecked %p/%p\n", info.hbmpChecked, checked );
1309 ok_(__FILE__, line)( info.hbmpUnchecked == unchecked || (ULONG_PTR)info.hbmpUnchecked == LOWORD(unchecked),
1310 "wrong bmpunchecked %p/%p\n", info.hbmpUnchecked, unchecked );
1311 }
1312 if (mask & MIIM_DATA)
1313 ok_(__FILE__, line)( info.dwItemData == data || info.dwItemData == LOWORD(data),
1314 "wrong item data %lx/%lx\n", info.dwItemData, data );
1315 if (mask & MIIM_BITMAP)
1316 ok_(__FILE__, line)( info.hbmpItem == item || (ULONG_PTR)info.hbmpItem == LOWORD(item),
1317 "wrong bmpitem %p/%p\n", info.hbmpItem, item );
1318 ok_(__FILE__, line)( info.dwTypeData == type_data || (ULONG_PTR)info.dwTypeData == LOWORD(type_data),
1319 "wrong type data %p/%p\n", info.dwTypeData, type_data );
1320 ok_(__FILE__, line)( info.cch == out_len ||
1321 broken(! ansi && info.cch == 2 * out_len) /* East-Asian */,
1322 "wrong len %x/%x\n", info.cch, out_len );
1323 if (expname)
1324 {
1325 if(ansi)
1326 ok_(__FILE__, line)( !strncmp( expname, info.dwTypeData, out_len ),
1327 "menu item name differed from '%s' '%s'\n", expname, info.dwTypeData );
1328 else
1329 ok_(__FILE__, line)( !strncmpW( (WCHAR *)expname, (WCHAR *)info.dwTypeData, out_len ),
1330 "menu item name wrong\n" );
1331
1332 SetLastError( 0xdeadbeef );
1333 ret = ansi ? GetMenuStringA( hmenu, 0, (char *)buffer, 80, MF_BYPOSITION ) :
1334 GetMenuStringW( hmenu, 0, buffer, 80, MF_BYPOSITION );
1335 if (expstring)
1336 ok_(__FILE__, line)( ret, "GetMenuString failed, err %u\n", GetLastError());
1337 else
1338 ok_(__FILE__, line)( !ret, "GetMenuString should have failed\n" );
1339 }
1340 }
1341
1342 static void modify_menu( int line, HMENU hmenu, BOOL ansi, UINT flags, UINT_PTR id, void *data )
1343 {
1344 BOOL ret;
1345
1346 SetLastError( 0xdeadbeef );
1347 if (ansi) ret = ModifyMenuA( hmenu, 0, flags, id, data );
1348 else ret = ModifyMenuW( hmenu, 0, flags, id, data );
1349 ok_(__FILE__,line)( ret, "ModifyMenuA failed, err %u\n", GetLastError());
1350 }
1351
1352 static void set_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
1353 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
1354 void *type_data, UINT len, HBITMAP item )
1355
1356 {
1357 MENUITEMINFOA info;
1358 BOOL ret;
1359
1360 /* magic bitmap handle to test smaller cbSize */
1361 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
1362 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
1363 else
1364 info.cbSize = sizeof(info);
1365 info.fMask = mask;
1366 info.fType = type;
1367 info.fState = state;
1368 info.wID = id;
1369 info.hSubMenu = submenu;
1370 info.hbmpChecked = checked;
1371 info.hbmpUnchecked = unchecked;
1372 info.dwItemData = data;
1373 info.dwTypeData = type_data;
1374 info.cch = len;
1375 info.hbmpItem = item;
1376 SetLastError( 0xdeadbeef );
1377 if (ansi) ret = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1378 else ret = SetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
1379 ok_(__FILE__, line)( ret, "SetMenuItemInfo failed, err %u\n", GetLastError());
1380 }
1381
1382 #define TMII_INSMI( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,eret1 )\
1383 hmenu = CreateMenu();\
1384 submenu = CreateMenu();\
1385 if(ansi)strcpy( string, init );\
1386 else strcpyW( string, init );\
1387 insert_menu_item( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, eret1 )
1388
1389 /* GetMenuItemInfo + GetMenuString */
1390 #define TMII_GMII( c2,l2,\
1391 d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,\
1392 expname, eret2, eret3)\
1393 check_menu_item_info( __LINE__, hmenu, ansi, c2, d3, e3, f3, g3, h3, i3, j3, k3, l2, l3, m3, \
1394 expname, eret2, eret3 )
1395
1396 #define TMII_DONE \
1397 RemoveMenu(hmenu, 0, TRUE );\
1398 DestroyMenu( hmenu );\
1399 DestroyMenu( submenu );
1400
1401 /* modify menu */
1402 #define TMII_MODM( flags, id, data ) \
1403 modify_menu( __LINE__, hmenu, ansi, flags, id, data )
1404
1405 /* SetMenuItemInfo */
1406 #define TMII_SMII( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1 ) \
1407 set_menu_item_info( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1 )
1408
1409
1410 #define OK 1
1411 #define ER 0
1412
1413
1414 static void test_menu_iteminfo( void )
1415 {
1416 BOOL ansi = TRUE;
1417 char txtA[]="wine";
1418 char initA[]="XYZ";
1419 char emptyA[]="";
1420 WCHAR txtW[]={'W','i','n','e',0};
1421 WCHAR initW[]={'X','Y','Z',0};
1422 WCHAR emptyW[]={0};
1423 void *txt, *init, *empty, *string;
1424 HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
1425 char stringA[0x80];
1426 HMENU hmenu, submenu;
1427 HBITMAP dummy_hbm = (HBITMAP)(ULONG_PTR)0xdeadbeef;
1428
1429 do {
1430 if( ansi) {txt=txtA;init=initA;empty=emptyA;string=stringA;}
1431 else {txt=txtW;init=initW;empty=emptyW;string=stringA;}
1432 trace( "%s string %p hbm %p txt %p\n", ansi ? "ANSI tests: " : "Unicode tests:", string, hbm, txt);
1433 /* test all combinations of MFT_STRING, MFT_OWNERDRAW and MFT_BITMAP */
1434 /* (since MFT_STRING is zero, there are four of them) */
1435 TMII_INSMI( MIIM_TYPE, MFT_STRING, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1436 TMII_GMII ( MIIM_TYPE, 80,
1437 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1438 txt, OK, OK );
1439 TMII_DONE
1440 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1441 TMII_GMII ( MIIM_TYPE, 80,
1442 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1443 NULL, OK, ER );
1444 TMII_DONE
1445 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1446 TMII_GMII ( MIIM_TYPE, 80,
1447 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1448 NULL, OK, ER );
1449 TMII_DONE
1450 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1451 TMII_GMII ( MIIM_TYPE, 80,
1452 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1453 NULL, OK, ER );
1454 TMII_DONE
1455 /* not enough space for name*/
1456 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1457 TMII_GMII ( MIIM_TYPE, 0,
1458 MFT_STRING, 0, 0, 0, 0, 0, 0, NULL, 4, 0,
1459 NULL, OK, OK );
1460 TMII_DONE
1461 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1462 TMII_GMII ( MIIM_TYPE, 5,
1463 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1464 txt, OK, OK );
1465 TMII_DONE
1466 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1467 TMII_GMII ( MIIM_TYPE, 4,
1468 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 3, 0,
1469 txt, OK, OK );
1470 TMII_DONE
1471 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1472 TMII_GMII ( MIIM_TYPE, 0,
1473 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, 0,
1474 NULL, OK, ER );
1475 TMII_DONE
1476 /* cannot combine MIIM_TYPE with some other flags */
1477 TMII_INSMI( MIIM_TYPE|MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1478 TMII_DONE
1479 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1480 TMII_GMII ( MIIM_TYPE|MIIM_STRING, 80,
1481 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1482 NULL, ER, OK );
1483 TMII_DONE
1484 TMII_INSMI( MIIM_TYPE|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1485 TMII_DONE
1486 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1487 TMII_GMII ( MIIM_TYPE|MIIM_FTYPE, 80,
1488 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1489 NULL, ER, OK );
1490 TMII_DONE
1491 TMII_INSMI( MIIM_TYPE|MIIM_BITMAP, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, hbm, ER );
1492 TMII_DONE
1493 /* but succeeds with some others */
1494 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1495 TMII_GMII ( MIIM_TYPE|MIIM_SUBMENU, 80,
1496 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1497 txt, OK, OK );
1498 TMII_DONE
1499 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1500 TMII_GMII ( MIIM_TYPE|MIIM_STATE, 80,
1501 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1502 txt, OK, OK );
1503 TMII_DONE
1504 TMII_INSMI( MIIM_TYPE|MIIM_ID, MFT_STRING, -1, 888, 0, 0, 0, -1, txt, 6, 0, OK );
1505 TMII_GMII ( MIIM_TYPE|MIIM_ID, 80,
1506 MFT_STRING, 0, 888, 0, 0, 0, 0, string, 4, 0,
1507 txt, OK, OK );
1508 TMII_DONE
1509 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING, -1, -1, 0, 0, 0, 999, txt, 6, 0, OK );
1510 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1511 MFT_STRING, 0, 0, 0, 0, 0, 999, string, 4, 0,
1512 txt, OK, OK );
1513 TMII_DONE
1514 /* to be continued */
1515 /* set text with MIIM_TYPE and retrieve with MIIM_STRING */
1516 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1517 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1518 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1519 txt, OK, OK );
1520 TMII_DONE
1521 /* set text with MIIM_TYPE and retrieve with MIIM_STRING; MFT_OWNERDRAW causes an empty string */
1522 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1523 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1524 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1525 empty, OK, ER );
1526 TMII_DONE
1527 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1528 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1529 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1530 empty, OK, ER );
1531 TMII_DONE
1532 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1533 TMII_GMII ( MIIM_FTYPE, 80,
1534 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, 0,
1535 init, OK, ER );
1536 TMII_DONE
1537 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1538 TMII_GMII ( 0, 80,
1539 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1540 init, OK, OK );
1541 TMII_DONE
1542 /* contrary to MIIM_TYPE,you can set the text for an owner draw menu */
1543 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1544 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1545 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1546 txt, OK, OK );
1547 TMII_DONE
1548 /* same but retrieve with MIIM_TYPE */
1549 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1550 TMII_GMII ( MIIM_TYPE, 80,
1551 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1552 NULL, OK, OK );
1553 TMII_DONE
1554 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1555 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1556 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1557 empty, OK, ER );
1558 TMII_DONE
1559 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1560 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1561 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1562 empty, OK, ER );
1563 TMII_DONE
1564 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1565 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1566 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, 0,
1567 NULL, OK, ER );
1568 TMII_DONE
1569
1570 /* How is that with bitmaps? */
1571 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1572 TMII_GMII ( MIIM_TYPE, 80,
1573 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1574 NULL, OK, ER );
1575 TMII_DONE
1576 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1577 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1578 0, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1579 init, OK, ER );
1580 TMII_DONE
1581 /* MIIM_BITMAP does not like MFT_BITMAP */
1582 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, hbm, ER );
1583 TMII_DONE
1584 /* no problem with OWNERDRAWN */
1585 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1586 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1587 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1588 init, OK, ER );
1589 TMII_DONE
1590 /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1591 TMII_INSMI( MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER );
1592 TMII_DONE
1593
1594 /* menu with submenu */
1595 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1596 TMII_GMII ( MIIM_SUBMENU, 80,
1597 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1598 init, OK, ER );
1599 TMII_DONE
1600 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, empty, 0, 0, OK );
1601 TMII_GMII ( MIIM_SUBMENU, 80,
1602 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1603 init, OK, ER );
1604 TMII_DONE
1605 /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1606 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1607 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1608 MFT_STRING|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1609 empty, OK, ER );
1610 TMII_GMII ( MIIM_SUBMENU|MIIM_FTYPE, 80,
1611 MFT_SEPARATOR, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1612 empty, OK, ER );
1613 TMII_DONE
1614 /* menu with invalid submenu */
1615 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, (HMENU)999, 0, 0, -1, txt, 0, 0, ER );
1616 TMII_DONE
1617 /* Separator */
1618 TMII_INSMI( MIIM_TYPE, MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1619 TMII_GMII ( MIIM_TYPE, 80,
1620 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1621 NULL, OK, ER );
1622 TMII_DONE
1623 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1624 TMII_GMII ( MIIM_TYPE, 80,
1625 MFT_BITMAP|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1626 NULL, OK, ER );
1627 TMII_DONE
1628 /* SEPARATOR and STRING go well together */
1629 /* BITMAP and STRING go well together */
1630 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1631 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1632 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1633 txt, OK, OK );
1634 TMII_DONE
1635 /* BITMAP, SEPARATOR and STRING go well together */
1636 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1637 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1638 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1639 txt, OK, OK );
1640 TMII_DONE
1641 /* last two tests, but use MIIM_TYPE to retrieve info */
1642 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1643 TMII_GMII ( MIIM_TYPE, 80,
1644 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1645 NULL, OK, OK );
1646 TMII_DONE
1647 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1648 TMII_GMII ( MIIM_TYPE, 80,
1649 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1650 NULL, OK, OK );
1651 TMII_DONE
1652 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1653 TMII_GMII ( MIIM_TYPE, 80,
1654 MFT_SEPARATOR|MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1655 NULL, OK, OK );
1656 TMII_DONE
1657 /* same three with MFT_OWNERDRAW */
1658 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1659 TMII_GMII ( MIIM_TYPE, 80,
1660 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1661 NULL, OK, OK );
1662 TMII_DONE
1663 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1664 TMII_GMII ( MIIM_TYPE, 80,
1665 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1666 NULL, OK, OK );
1667 TMII_DONE
1668 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1669 TMII_GMII ( MIIM_TYPE, 80,
1670 MFT_SEPARATOR|MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1671 NULL, OK, OK );
1672 TMII_DONE
1673
1674 TMII_INSMI( MIIM_STRING|MIIM_FTYPE|MIIM_ID, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1675 TMII_GMII ( MIIM_TYPE, 80,
1676 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1677 NULL, OK, OK );
1678 TMII_DONE
1679 /* test with modifymenu: string is preserved after setting OWNERDRAW */
1680 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1681 TMII_MODM( MFT_OWNERDRAW, -1, (void*)787 );
1682 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_DATA, 80,
1683 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 787, string, 4, 0,
1684 txt, OK, OK );
1685 TMII_DONE
1686 /* same with bitmap: now the text is cleared */
1687 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1688 TMII_MODM( MFT_BITMAP, 545, hbm );
1689 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1690 MFT_BITMAP, 0, 545, 0, 0, 0, 0, string, 0, hbm,
1691 empty, OK, ER );
1692 TMII_DONE
1693 /* start with bitmap: now setting text clears it (though he flag is raised) */
1694 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1695 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1696 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 0, hbm,
1697 empty, OK, ER );
1698 TMII_MODM( MFT_STRING, 545, txt );
1699 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1700 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 4, 0,
1701 txt, OK, OK );
1702 TMII_DONE
1703 /*repeat with text NULL */
1704 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1705 TMII_MODM( MFT_STRING, 545, NULL );
1706 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1707 MFT_SEPARATOR, 0, 545, 0, 0, 0, 0, string, 0, 0,
1708 empty, OK, ER );
1709 TMII_DONE
1710 /* repeat with text "" */
1711 TMII_INSMI( MIIM_BITMAP, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1712 TMII_MODM( MFT_STRING, 545, empty );
1713 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1714 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 0, 0,
1715 empty, OK, ER );
1716 TMII_DONE
1717 /* start with bitmap: set ownerdraw */
1718 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1719 TMII_MODM( MFT_OWNERDRAW, -1, (void *)232 );
1720 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_DATA, 80,
1721 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 232, string, 0, hbm,
1722 empty, OK, ER );
1723 TMII_DONE
1724 /* ask nothing */
1725 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1726 TMII_GMII ( 0, 80,
1727 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1728 init, OK, OK );
1729 TMII_DONE
1730 /* some tests with small cbSize: the hbmpItem is to be ignored */
1731 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1732 TMII_GMII ( MIIM_TYPE, 80,
1733 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1734 NULL, OK, ER );
1735 TMII_DONE
1736 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1737 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1738 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, NULL,
1739 init, OK, ER );
1740 TMII_DONE
1741 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1742 TMII_GMII ( MIIM_TYPE, 80,
1743 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, NULL,
1744 txt, OK, OK );
1745 TMII_DONE
1746 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1747 TMII_GMII ( MIIM_TYPE, 80,
1748 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1749 NULL, OK, OK );
1750 TMII_DONE
1751 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1752 TMII_GMII ( MIIM_TYPE, 80,
1753 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1754 NULL, OK, OK );
1755 TMII_DONE
1756 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1757 TMII_GMII ( MIIM_TYPE, 80,
1758 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1759 NULL, OK, OK );
1760 TMII_DONE
1761 /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus */
1762 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1763 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1764 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1765 NULL, OK, ER );
1766 TMII_DONE
1767 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1768 TMII_GMII ( MIIM_TYPE, 80,
1769 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1770 NULL, OK, ER );
1771 TMII_DONE
1772 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1773 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1774 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1775 NULL, OK, ER );
1776 TMII_DONE
1777 /* set a string menu to ownerdraw with MIIM_TYPE */
1778 TMII_INSMI( MIIM_TYPE, MFT_STRING, -2, -2, 0, 0, 0, -2, txt, -2, 0, OK );
1779 TMII_SMII ( MIIM_TYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1780 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1781 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1782 txt, OK, OK );
1783 TMII_DONE
1784 /* test with modifymenu add submenu */
1785 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1786 TMII_MODM( MF_POPUP, (UINT_PTR)submenu, txt );
1787 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_SUBMENU, 80,
1788 MFT_STRING, 0, 0, submenu, 0, 0, 0, string, 4, 0,
1789 txt, OK, OK );
1790 TMII_GMII ( MIIM_TYPE, 80,
1791 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1792 txt, OK, OK );
1793 TMII_DONE
1794 /* MFT_SEPARATOR bit is kept when the text is added */
1795 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1796 TMII_SMII( MIIM_STRING, 0, 0, 0, 0, 0, 0, 0, txt, 0, 0 );
1797 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1798 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, 0,
1799 txt, OK, OK );
1800 TMII_DONE
1801 /* MFT_SEPARATOR bit is kept when bitmap is added */
1802 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1803 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm );
1804 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1805 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1806 init, OK, ER );
1807 TMII_DONE
1808 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1809 Only the low word of the dwTypeData is used.
1810 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1811 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1812 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1813 TMII_GMII ( MIIM_TYPE, 80,
1814 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1815 NULL, OK, OK );
1816 TMII_DONE
1817 /* Type flags */
1818 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1819 TMII_GMII ( MIIM_TYPE, 80,
1820 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1821 NULL, OK, OK );
1822 TMII_DONE
1823 /* State flags */
1824 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1825 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1826 TMII_GMII ( MIIM_STATE, 80,
1827 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1828 NULL, OK, OK );
1829 TMII_DONE
1830 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1831 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1832 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1833 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1834 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1835 NULL, OK, OK );
1836 TMII_DONE
1837 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1838 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1839 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1840 TMII_GMII ( MIIM_FTYPE, 80,
1841 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1842 NULL, OK, OK );
1843 TMII_GMII ( MIIM_TYPE, 80,
1844 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1845 NULL, OK, OK );
1846 TMII_GMII ( MIIM_FTYPE, 80,
1847 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1848 NULL, OK, OK );
1849 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1850 TMII_GMII ( MIIM_TYPE, 80,
1851 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1852 NULL, OK, OK );
1853 TMII_DONE
1854 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1855 Only the low word of the dwTypeData is used.
1856 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1857 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1858 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1859 TMII_GMII ( MIIM_TYPE, 80,
1860 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1861 NULL, OK, OK );
1862 TMII_DONE
1863 /* Type flags */
1864 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1865 TMII_GMII ( MIIM_TYPE, 80,
1866 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1867 NULL, OK, OK );
1868 TMII_DONE
1869 /* State flags */
1870 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1871 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1872 TMII_GMII ( MIIM_STATE, 80,
1873 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1874 NULL, OK, OK );
1875 TMII_DONE
1876 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1877 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1878 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1879 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1880 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1881 NULL, OK, OK );
1882 TMII_DONE
1883 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1884 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1885 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1886 TMII_GMII ( MIIM_FTYPE, 80,
1887 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1888 NULL, OK, OK );
1889 TMII_GMII ( MIIM_TYPE, 80,
1890 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1891 NULL, OK, OK );
1892 TMII_GMII ( MIIM_FTYPE, 80,
1893 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1894 NULL, OK, OK );
1895 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1896 TMII_GMII ( MIIM_TYPE, 80,
1897 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1898 NULL, OK, OK );
1899 TMII_DONE
1900 } while( !(ansi = !ansi) );
1901 DeleteObject( hbm);
1902 }
1903
1904 /*
1905 The following tests try to confirm the algorithm used to return the menu items
1906 when there is a collision between a menu item and a popup menu
1907 */
1908 static void test_menu_search_bycommand( void )
1909 {
1910 HMENU hmenu, hmenuSub, hmenuSub2;
1911 MENUITEMINFOA info;
1912 BOOL rc;
1913 UINT id;
1914 char strback[0x80];
1915 char strIn[0x80];
1916 static CHAR menuitem[] = "MenuItem",
1917 menuitem2[] = "MenuItem 2";
1918
1919 /* Case 1: Menu containing a menu item */
1920 hmenu = CreateMenu();
1921
1922 memset( &info, 0, sizeof info );
1923 info.cbSize = sizeof info;
1924 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1925 info.fType = MFT_STRING;
1926 strcpy(strIn, "Case 1 MenuItem");
1927 info.dwTypeData = strIn;
1928 info.wID = (UINT) 0x1234;
1929
1930 rc = InsertMenuItemA(hmenu, 0, TRUE, &info );
1931 ok (rc, "Inserting the menuitem failed\n");
1932
1933 id = GetMenuItemID(hmenu, 0);
1934 ok (id == 0x1234, "Getting the menuitem id failed(gave %x)\n", id);
1935
1936 /* Confirm the menuitem was given the id supplied (getting by position) */
1937 memset( &info, 0, sizeof info );
1938 strback[0] = 0x00;
1939 info.cbSize = sizeof(MENUITEMINFOA);
1940 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1941 info.dwTypeData = strback;
1942 info.cch = sizeof(strback);
1943
1944 rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info); /* Get by position */
1945 ok (rc, "Getting the menu items info failed\n");
1946 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1947 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1948
1949 /* Search by id - Should return the item */
1950 memset( &info, 0, sizeof info );
1951 strback[0] = 0x00;
1952 info.cbSize = sizeof(MENUITEMINFOA);
1953 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1954 info.dwTypeData = strback;
1955 info.cch = sizeof(strback);
1956 rc = GetMenuItemInfoA(hmenu, 0x1234, FALSE, &info); /* Get by ID */
1957
1958 ok (rc, "Getting the menu items info failed\n");
1959 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1960 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1961
1962 DestroyMenu( hmenu );
1963
1964 /* Case 2: Menu containing a popup menu */
1965 hmenu = CreateMenu();
1966 hmenuSub = CreateMenu();
1967
1968 strcpy(strIn, "Case 2 SubMenu");
1969 rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, strIn);
1970 ok (rc, "Inserting the popup menu into the main menu failed\n");
1971
1972 id = GetMenuItemID(hmenu, 0);
1973 ok (id == -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id);
1974
1975 /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
1976 memset( &info, 0, sizeof info );
1977 strback[0] = 0x00;
1978 info.cbSize = sizeof(MENUITEMINFOA);
1979 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1980 info.dwTypeData = strback;
1981 info.cch = sizeof(strback);
1982 info.wID = 0xdeadbeef;
1983
1984 rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info); /* Get by position */
1985 ok (rc, "Getting the menu items info failed\n");
1986 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the menuitem\n");
1987 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1988
1989 /* Search by id - returns the popup menu itself */
1990 memset( &info, 0, sizeof info );
1991 strback[0] = 0x00;
1992 info.cbSize = sizeof(MENUITEMINFOA);
1993 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1994 info.dwTypeData = strback;
1995 info.cch = sizeof(strback);
1996 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1997
1998 ok (rc, "Getting the menu items info failed\n");
1999 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
2000 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
2001
2002 /*
2003 Now add an item after it with the same id
2004 */
2005 memset( &info, 0, sizeof info );
2006 info.cbSize = sizeof info;
2007 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2008 info.fType = MFT_STRING;
2009 strcpy(strIn, "Case 2 MenuItem 1");
2010 info.dwTypeData = strIn;
2011 info.wID = (UINT_PTR) hmenuSub;
2012 rc = InsertMenuItemA(hmenu, -1, TRUE, &info );
2013 ok (rc, "Inserting the menuitem failed\n");
2014
2015 /* Search by id - returns the item which follows the popup menu */
2016 memset( &info, 0, sizeof info );
2017 strback[0] = 0x00;
2018 info.cbSize = sizeof(MENUITEMINFOA);
2019 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
2020 info.dwTypeData = strback;
2021 info.cch = sizeof(strback);
2022 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
2023
2024 ok (rc, "Getting the menu items info failed\n");
2025 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
2026 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2027
2028 /*
2029 Now add an item before the popup (with the same id)
2030 */
2031 memset( &info, 0, sizeof info );
2032 info.cbSize = sizeof info;
2033 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2034 info.fType = MFT_STRING;
2035 strcpy(strIn, "Case 2 MenuItem 2");
2036 info.dwTypeData = strIn;
2037 info.wID = (UINT_PTR) hmenuSub;
2038 rc = InsertMenuItemA(hmenu, 0, TRUE, &info );
2039 ok (rc, "Inserting the menuitem failed\n");
2040
2041 /* Search by id - returns the item which precedes the popup menu */
2042 memset( &info, 0, sizeof info );
2043 strback[0] = 0x00;
2044 info.cbSize = sizeof(MENUITEMINFOA);
2045 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
2046 info.dwTypeData = strback;
2047 info.cch = sizeof(strback);
2048 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
2049
2050 ok (rc, "Getting the menu items info failed\n");
2051 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
2052 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2053
2054 DestroyMenu( hmenu );
2055 DestroyMenu( hmenuSub );
2056
2057 /*
2058 Case 3: Menu containing a popup menu which in turn
2059 contains 2 items with the same id as the popup itself
2060 */
2061
2062 hmenu = CreateMenu();
2063 hmenuSub = CreateMenu();
2064
2065 memset( &info, 0, sizeof info );
2066 info.cbSize = sizeof info;
2067 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2068 info.fType = MFT_STRING;
2069 info.dwTypeData = menuitem;
2070 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2071
2072 rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
2073 ok (rc, "Inserting the popup menu into the main menu failed\n");
2074
2075 rc = InsertMenuItemA(hmenuSub, 0, TRUE, &info );
2076 ok (rc, "Inserting the sub menu menuitem failed\n");
2077
2078 memset( &info, 0, sizeof info );
2079 info.cbSize = sizeof info;
2080 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2081 info.fType = MFT_STRING;
2082 info.dwTypeData = menuitem2;
2083 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2084
2085 rc = InsertMenuItemA(hmenuSub, 1, TRUE, &info );
2086 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
2087
2088 /* Prove that you can't query the id of a popup directly (By position) */
2089 id = GetMenuItemID(hmenu, 0);
2090 ok (id == -1, "Getting the sub menu id should have failed because it's a popup (gave %x)\n", id);
2091
2092 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
2093 memset( &info, 0, sizeof info );
2094 strback[0] = 0x00;
2095 info.cbSize = sizeof(MENUITEMINFOA);
2096 info.fMask = MIIM_STRING | MIIM_ID;
2097 info.dwTypeData = strback;
2098 info.cch = sizeof(strback);
2099
2100 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
2101 ok (rc, "Getting the menus info failed\n");
2102 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
2103 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2104 DestroyMenu( hmenu );
2105 DestroyMenu( hmenuSub );
2106
2107 /*
2108 Case 4: Menu containing 2 popup menus, the second
2109 contains 2 items with the same id as the first popup menu
2110 */
2111 hmenu = CreateMenu();
2112 hmenuSub = CreateMenu();
2113 hmenuSub2 = CreateMenu();
2114
2115 rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
2116 ok (rc, "Inserting the popup menu into the main menu failed\n");
2117
2118 rc = InsertMenuA(hmenu, 1, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub2, "Submenu2");
2119 ok (rc, "Inserting the popup menu into the main menu failed\n");
2120
2121 memset( &info, 0, sizeof info );
2122 info.cbSize = sizeof info;
2123 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2124 info.fType = MFT_STRING;
2125 info.dwTypeData = menuitem;
2126 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2127
2128 rc = InsertMenuItemA(hmenuSub2, 0, TRUE, &info );
2129 ok (rc, "Inserting the sub menu menuitem failed\n");
2130
2131 memset( &info, 0, sizeof info );
2132 info.cbSize = sizeof info;
2133 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2134 info.fType = MFT_STRING;
2135 info.dwTypeData = menuitem2;
2136 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2137
2138 rc = InsertMenuItemA(hmenuSub2, 1, TRUE, &info );
2139 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
2140
2141 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
2142 memset( &info, 0, sizeof info );
2143 strback[0] = 0x00;
2144 info.cbSize = sizeof(MENUITEMINFOA);
2145 info.fMask = MIIM_STRING | MIIM_ID;
2146 info.dwTypeData = strback;
2147 info.cch = sizeof(strback);
2148
2149 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
2150 ok (rc, "Getting the menus info failed\n");
2151 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
2152 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2153
2154 memset( &info, 0, sizeof info );
2155 strback[0] = 0x00;
2156 info.cbSize = sizeof(MENUITEMINFOA);
2157 info.fMask = MIIM_STRING | MIIM_ID;
2158 info.dwTypeData = strback;
2159 info.cch = sizeof(strback);
2160
2161 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub2, FALSE, &info);
2162 ok (rc, "Getting the menus info failed\n");
2163 ok (info.wID == (UINT_PTR)hmenuSub2, "IDs differ for popup menu\n");
2164 ok (!strcmp(info.dwTypeData, "Submenu2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2165
2166 DestroyMenu( hmenu );
2167 DestroyMenu( hmenuSub );
2168 DestroyMenu( hmenuSub2 );
2169
2170
2171 /*
2172 Case 5: Menu containing a popup menu which in turn
2173 contains an item with a different id than the popup menu.
2174 This tests the fallback to a popup menu ID.
2175 */
2176
2177 hmenu = CreateMenu();
2178 hmenuSub = CreateMenu();
2179
2180 rc = AppendMenuA(hmenu, MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
2181 ok (rc, "Appending the popup menu to the main menu failed\n");
2182
2183 rc = AppendMenuA(hmenuSub, MF_STRING, 102, "Item");
2184 ok (rc, "Appending the item to the popup menu failed\n");
2185
2186 /* Set the ID for hmenuSub */
2187 info.cbSize = sizeof(info);
2188 info.fMask = MIIM_ID;
2189 info.wID = 101;
2190
2191 rc = SetMenuItemInfoA(hmenu, 0, TRUE, &info);
2192 ok(rc, "Setting the ID for the popup menu failed\n");
2193
2194 /* Check if the ID has been set */
2195 info.wID = 0;
2196 rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info);
2197 ok(rc, "Getting the ID for the popup menu failed\n");
2198 ok(info.wID == 101, "The ID for the popup menu has not been set\n");
2199
2200 /* Prove getting the item info via ID returns the popup menu */
2201 memset( &info, 0, sizeof(info));
2202 strback[0] = 0x00;
2203 info.cbSize = sizeof(MENUITEMINFOA);
2204 info.fMask = MIIM_STRING | MIIM_ID;
2205 info.dwTypeData = strback;
2206 info.cch = sizeof(strback);
2207
2208 rc = GetMenuItemInfoA(hmenu, 101, FALSE, &info);
2209 ok (rc, "Getting the menu info failed\n");
2210 ok (info.wID == 101, "IDs differ\n");
2211 ok (!strcmp(info.dwTypeData, "Submenu"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2212
2213 /* Also look for the menu item */
2214 memset( &info, 0, sizeof(info));
2215 strback[0] = 0x00;
2216 info.cbSize = sizeof(MENUITEMINFOA);
2217 info.fMask = MIIM_STRING | MIIM_ID;
2218 info.dwTypeData = strback;
2219 info.cch = sizeof(strback);
2220
2221 rc = GetMenuItemInfoA(hmenu, 102, FALSE, &info);
2222 ok (rc, "Getting the menu info failed\n");
2223 ok (info.wID == 102, "IDs differ\n");
2224 ok (!strcmp(info.dwTypeData, "Item"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2225
2226 DestroyMenu(hmenu);
2227 DestroyMenu(hmenuSub);
2228 }
2229
2230 struct menu_item_pair_s {
2231 UINT uMenu; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
2232 * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
2233 * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
2234 UINT uItem;
2235 };
2236
2237 static struct menu_mouse_tests_s {
2238 DWORD type;
2239 struct menu_item_pair_s menu_item_pairs[5]; /* for mousing */
2240 WORD wVk[5]; /* keys */
2241 BOOL bMenuVisible;
2242 BOOL _todo_wine;
2243 } menu_tests[] = {
2244 /* for each test, send keys or clicks and check for menu visibility */
2245 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE }, /* test 0 */
2246 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
2247 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
2248 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2249 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
2250 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2251 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2252 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, VK_ESCAPE, 0}, FALSE, FALSE },
2253 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', VK_ESCAPE, 0}, TRUE, FALSE },
2254 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
2255 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2256 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2257 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2258 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2259 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
2260 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2261 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
2262 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2263 { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, TRUE, FALSE },
2264 { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, FALSE, FALSE },
2265
2266 { INPUT_MOUSE, {{1, 2}, {0}}, {0}, TRUE, TRUE }, /* test 20 */
2267 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2268 { INPUT_MOUSE, {{1, 0}, {0}}, {0}, TRUE, TRUE },
2269 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2270 { INPUT_MOUSE, {{1, 0}, {2, 2}, {0}}, {0}, TRUE, TRUE },
2271 { INPUT_MOUSE, {{2, 1}, {0}}, {0}, FALSE, FALSE },
2272 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
2273 { INPUT_MOUSE, {{3, 0}, {0}}, {0}, FALSE, FALSE },
2274 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
2275 { INPUT_MOUSE, {{3, 1}, {0}}, {0}, TRUE, TRUE },
2276 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2277 { -1 }
2278 };
2279
2280 static void send_key(WORD wVk)
2281 {
2282 TEST_INPUT i[2];
2283 memset(i, 0, sizeof(i));
2284 i[0].type = i[1].type = INPUT_KEYBOARD;
2285 i[0].u.ki.wVk = i[1].u.ki.wVk = wVk;
2286 i[1].u.ki.dwFlags = KEYEVENTF_KEYUP;
2287 pSendInput(2, (INPUT *) i, sizeof(INPUT));
2288 }
2289
2290 static BOOL click_menu(HANDLE hWnd, struct menu_item_pair_s *mi)
2291 {
2292 HMENU hMenu = hMenus[mi->uMenu];
2293 TEST_INPUT i[3];
2294 MSG msg;
2295 RECT r;
2296 int screen_w = GetSystemMetrics(SM_CXSCREEN);
2297 int screen_h = GetSystemMetrics(SM_CYSCREEN);
2298 BOOL ret = GetMenuItemRect(mi->uMenu > 2 ? NULL : hWnd, hMenu, mi->uItem, &r);
2299 if(!ret) return FALSE;
2300
2301 memset(i, 0, sizeof(i));
2302 i[0].type = i[1].type = i[2].type = INPUT_MOUSE;
2303 i[0].u.mi.dx = i[1].u.mi.dx = i[2].u.mi.dx
2304 = ((r.left + 5) * 65535) / screen_w;
2305 i[0].u.mi.dy = i[1].u.mi.dy = i[2].u.mi.dy
2306 = ((r.top + 5) * 65535) / screen_h;
2307 i[0].u.mi.dwFlags = i[1].u.mi.dwFlags = i[2].u.mi.dwFlags
2308 = MOUSEEVENTF_ABSOLUTE;
2309 i[0].u.mi.dwFlags |= MOUSEEVENTF_MOVE;
2310 i[1].u.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
2311 i[2].u.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
2312 ret = pSendInput(3, (INPUT *) i, sizeof(INPUT));
2313
2314 /* hack to prevent mouse message buildup in Wine */
2315 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
2316 return ret;
2317 }
2318
2319 static DWORD WINAPI test_menu_input_thread(LPVOID lpParameter)
2320 {
2321 int i, j;
2322 HANDLE hWnd = lpParameter;
2323
2324 Sleep(500);
2325 /* mixed keyboard/mouse test */
2326 for (i = 0; menu_tests[i].type != -1; i++)
2327 {
2328 BOOL ret = TRUE;
2329 int elapsed = 0;
2330
2331 got_input = i && menu_tests[i-1].bMenuVisible;
2332
2333 if (menu_tests[i].type == INPUT_KEYBOARD)
2334 for (j = 0; menu_tests[i].wVk[j] != 0; j++)
2335 send_key(menu_tests[i].wVk[j]);
2336 else
2337 for (j = 0; menu_tests[i].menu_item_pairs[j].uMenu != 0; j++)
2338 if (!(ret = click_menu(hWnd, &menu_tests[i].menu_item_pairs[j]))) break;
2339
2340 if (!ret)
2341 {
2342 skip( "test %u: failed to send input\n", i );
2343 PostMessageA( hWnd, WM_CANCELMODE, 0, 0 );
2344 return 0;
2345 }
2346 while (menu_tests[i].bMenuVisible != bMenuVisible)
2347 {
2348 if (elapsed > 200)
2349 break;
2350 elapsed += 20;
2351 Sleep(20);
2352 }
2353
2354 if (!got_input)
2355 {
2356 skip( "test %u: didn't receive input\n", i );
2357 PostMessageA( hWnd, WM_CANCELMODE, 0, 0 );
2358 return 0;
2359 }
2360
2361 todo_wine_if (menu_tests[i]._todo_wine)
2362 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
2363 }
2364 return 0;
2365 }
2366
2367 static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam,
2368 LPARAM lParam)
2369 {
2370 switch (msg) {
2371 case WM_ENTERMENULOOP:
2372 bMenuVisible = TRUE;
2373 break;
2374 case WM_INITMENUPOPUP:
2375 case WM_UNINITMENUPOPUP:
2376 case WM_EXITMENULOOP:
2377 case WM_MENUSELECT:
2378 break;
2379
2380 case WM_KEYDOWN:
2381 case WM_SYSKEYDOWN:
2382 case WM_MOUSEMOVE:
2383 case WM_LBUTTONDOWN:
2384 case WM_LBUTTONUP:
2385 case WM_NCMOUSEMOVE:
2386 case WM_NCLBUTTONDOWN:
2387 case WM_NCLBUTTONUP:
2388 got_input = TRUE;
2389 /* fall through */
2390 default:
2391 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2392 }
2393
2394 if(pGetMenuBarInfo)
2395 {
2396 MENUBARINFO mbi;
2397 HMENU hmenu;
2398 UINT state;
2399 BOOL br;
2400
2401 mbi.cbSize = sizeof(MENUBARINFO);
2402
2403 /* get info for the menu */
2404 br = pGetMenuBarInfo(hWnd, OBJID_MENU, 0, &mbi);
2405 ok(br, "msg %x: GetMenuBarInfo failed\n", msg);
2406 hmenu = GetMenu(hWnd);
2407 ok(!mbi.hwndMenu, "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected NULL\n",
2408 msg, mbi.hwndMenu);
2409 ok(mbi.hMenu == hmenu, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2410 msg, mbi.hMenu, hmenu);
2411 ok(!bMenuVisible == !mbi.fBarFocused, "msg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2412 msg, mbi.fBarFocused != 0);
2413 ok(!bMenuVisible == !mbi.fFocused, "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n",
2414 msg, mbi.fFocused != 0);
2415
2416 /* get info for the menu's first item */
2417 br = pGetMenuBarInfo(hWnd, OBJID_MENU, 1, &mbi);
2418 ok(br, "msg %x: GetMenuBarInfo failed\n", msg);
2419 state = GetMenuState(hmenu, 0, MF_BYPOSITION);
2420 if (pGetMenuInfo) /* Skip on NT */
2421 {
2422 /* Native returns handle to destroyed window */
2423 todo_wine_if (msg==WM_UNINITMENUPOPUP && popmenu==1)
2424 ok(!mbi.hwndMenu == !popmenu,
2425 "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected %sNULL\n",
2426 msg, mbi.hwndMenu, popmenu ? "not " : "");
2427 }
2428 ok(mbi.hMenu == hmenu, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2429 msg, mbi.hMenu, hmenu);
2430 ok(!bMenuVisible == !mbi.fBarFocused, "nsg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2431 msg, mbi.fBarFocused != 0);
2432 ok(!(bMenuVisible && (state & MF_HILITE)) == !mbi.fFocused,
2433 "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n", msg, mbi.fFocused != 0);
2434 }
2435
2436 if (msg == WM_EXITMENULOOP)
2437 bMenuVisible = FALSE;
2438 else if (msg == WM_INITMENUPOPUP)
2439 popmenu++;
2440 else if (msg == WM_UNINITMENUPOPUP)
2441 popmenu--;
2442 return 0;
2443 }
2444
2445 static void test_menu_input(void) {
2446 MSG msg;
2447 WNDCLASSA wclass;
2448 HINSTANCE hInstance = GetModuleHandleA( NULL );
2449 HANDLE hThread, hWnd;
2450 DWORD tid;
2451 ATOM aclass;
2452 POINT orig_pos;
2453
2454 if (!pSendInput)
2455 {
2456 win_skip("SendInput is not available\n");
2457 return;
2458 }
2459
2460 wclass.lpszClassName = "MenuTestClass";
2461 wclass.style = CS_HREDRAW | CS_VREDRAW;
2462 wclass.lpfnWndProc = WndProc;
2463 wclass.hInstance = hInstance;
2464 wclass.hIcon = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
2465 wclass.hCursor = LoadCursorA( 0, (LPCSTR)IDC_ARROW );
2466 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2467 wclass.lpszMenuName = 0;
2468 wclass.cbClsExtra = 0;
2469 wclass.cbWndExtra = 0;
2470 aclass = RegisterClassA( &wclass );
2471 ok (aclass, "MenuTest class not created\n");
2472 if (!aclass) return;
2473 hWnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
2474 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2475 400, 200, NULL, NULL, hInstance, NULL);
2476 ok (hWnd != NULL, "MenuTest window not created\n");
2477 if (!hWnd) return;