ReactOS  0.4.14-dev-41-g31d7680
menu.c
Go to the documentation of this file.
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 #ifndef __REACTOS__
23 #define _WIN32_WINNT 0x0501
24 #endif
25 
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <assert.h>
30 
31 #define OEMRESOURCE /* For OBM_MNARROW */
32 
33 #include "windef.h"
34 #include "winbase.h"
35 #include "wingdi.h"
36 #include "winuser.h"
37 
38 #include "wine/test.h"
39 
41 
42 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
43 static BOOL (WINAPI *pGetMenuBarInfo)(HWND,LONG,LONG,PMENUBARINFO);
44 static UINT (WINAPI *pSendInput)(UINT, INPUT*, size_t);
45 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
46 
47 static void init_function_pointers(void)
48 {
49  HMODULE hdll = GetModuleHandleA("user32");
50 
51 #define GET_PROC(func) \
52  p ## func = (void*)GetProcAddress(hdll, #func); \
53  if(!p ## func) \
54  trace("GetProcAddress(%s) failed\n", #func);
55 
60 
61 #undef GET_PROC
62 }
63 
64 static BOOL correct_behavior(void)
65 {
66  HMENU hmenu;
68  BOOL rc;
69 
70  hmenu = CreateMenu();
71 
72  memset(&info, 0, sizeof(MENUITEMINFOA));
73  info.cbSize= sizeof(MENUITEMINFOA);
74  SetLastError(0xdeadbeef);
75  rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info);
76  /* Win9x : 0xdeadbeef
77  * NT4 : ERROR_INVALID_PARAMETER
78  * >= W2K : ERROR_MENU_ITEM_NOT_FOUND
79  */
81  {
82  win_skip("NT4 and below can't handle a bigger MENUITEMINFO struct\n");
84  return FALSE;
85  }
86 
88  return TRUE;
89 }
90 
92 {
93  switch (msg)
94  {
95  case WM_ENTERMENULOOP:
96  /* mark window as having entered menu loop */
98  /* exit menu modal loop
99  * ( A SendMessage does not work on NT3.51 here ) */
100  return PostMessageA(hwnd, WM_CANCELMODE, 0, 0);
101  }
102  return DefWindowProcA(hwnd, msg, wparam, lparam);
103 }
104 
105 /* The MSVC headers ignore our NONAMELESSUNION requests so we have to define
106  * our own type */
107 typedef struct
108 {
109  DWORD type;
110  union
111  {
112  MOUSEINPUT mi;
113  KEYBDINPUT ki;
114  HARDWAREINPUT hi;
115  } u;
116 } TEST_INPUT;
117 
118 /* globals to communicate between test and wndproc */
119 
121 static INT popmenu;
123 static HMENU hMenus[4];
124 
125 #define MOD_SIZE 10
126 #define MOD_NRMENUS 8
127 
128  /* menu texts with their sizes */
129 static struct {
131  SIZE size; /* size of text up to any \t */
132  SIZE sc_size; /* size of the short-cut */
133 } MOD_txtsizes[] = {
134  { "Pinot &Noir" },
135  { "&Merlot\bF4" },
136  { "Shira&z\tAlt+S" },
137  { "" },
138  { NULL }
139 };
140 
141 static unsigned int MOD_maxid;
143 static int MOD_avec, MOD_hic;
144 static int MOD_odheight;
154 
155 /* wndproc used by test_menu_ownerdraw() */
158 {
159  static HMENU hmenupopup;
160  switch (msg)
161  {
162  case WM_INITMENUPOPUP:
164  hmenupopup = (HMENU) wparam;
165  break;
166  case WM_ENTERMENULOOP:
168  break;
169  case WM_INITMENU:
170  gflag_initmenu++;
171  break;
172  case WM_MEASUREITEM:
173  {
175  if (winetest_debug > 1)
176  trace("WM_MEASUREITEM received data %lx size %dx%d\n",
177  pmis->itemData, pmis->itemWidth, pmis->itemHeight);
178  ok( !wparam, "wrong wparam %lx\n", wparam );
179  ok( pmis->CtlType == ODT_MENU, "wrong type %x\n", pmis->CtlType );
180  MOD_odheight = pmis->itemHeight;
181  pmis->itemWidth = MODsizes[pmis->itemData].cx;
182  pmis->itemHeight = MODsizes[pmis->itemData].cy;
183  return TRUE;
184  }
185  case WM_DRAWITEM:
186  {
187  DRAWITEMSTRUCT * pdis;
188  TEXTMETRICA tm;
189  HPEN oldpen;
190  char chrs[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
191  SIZE sz;
192  int i;
193  pdis = (DRAWITEMSTRUCT *) lparam;
194  if (winetest_debug > 1) {
195  RECT rc;
196  GetMenuItemRect( hwnd, (HMENU)pdis->hwndItem, pdis->itemData ,&rc);
197  trace("WM_DRAWITEM received hwnd %p hmenu %p itemdata %ld item %d rc %s itemrc: %s\n",
198  hwnd, pdis->hwndItem, pdis->itemData, pdis->itemID,
200  oldpen=SelectObject( pdis->hDC, GetStockObject(
202  Rectangle( pdis->hDC, pdis->rcItem.left,pdis->rcItem.top,
203  pdis->rcItem.right,pdis->rcItem.bottom );
204  SelectObject( pdis->hDC, oldpen);
205  }
206  ok( !wparam, "wrong wparam %lx\n", wparam );
207  ok( pdis->CtlType == ODT_MENU, "wrong type %x\n", pdis->CtlType );
208  /* calculate widths of some menu texts */
209  if( ! MOD_txtsizes[0].size.cx)
210  for(i = 0; MOD_txtsizes[i].text; i++) {
211  char buf[100], *p;
212  RECT rc={0,0,0,0};
214  if( ( p = strchr( buf, '\t'))) {
215  *p = '\0';
216  DrawTextA( pdis->hDC, p + 1, -1, &rc,
218  MOD_txtsizes[i].sc_size.cx= rc.right - rc.left;
219  MOD_txtsizes[i].sc_size.cy= rc.bottom - rc.top;
220  }
221  DrawTextA( pdis->hDC, buf, -1, &rc,
223  MOD_txtsizes[i].size.cx= rc.right - rc.left;
224  MOD_txtsizes[i].size.cy= rc.bottom - rc.top;
225  }
226 
227  if( pdis->itemData > MOD_maxid) return TRUE;
228  /* store the rectangle */
229  MOD_rc[pdis->itemData] = pdis->rcItem;
230  /* calculate average character width */
231  GetTextExtentPointA( pdis->hDC, chrs, 52, &sz );
232  MOD_avec = (sz.cx + 26)/52;
233  GetTextMetricsA( pdis->hDC, &tm);
234  MOD_hic = tm.tmHeight;
236  return TRUE;
237  }
238  case WM_ENTERIDLE:
239  {
240  gflag_enteridle++;
241  ok( lparam || broken(!lparam), /* win9x, nt4 */
242  "Menu window handle is NULL!\n");
243  if( lparam) {
245  ok( hmenupopup == hmenu, "MN_GETHMENU returns %p expected %p\n",
246  hmenu, hmenupopup);
247  }
249  return TRUE;
250  }
251  case WM_MENUSELECT:
254  break;
255  }
256  return DefWindowProcA(hwnd, msg, wparam, lparam);
257 }
258 
259 static void register_menu_check_class(void)
260 {
261  WNDCLASSA wc =
262  {
263  0,
265  0,
266  0,
268  NULL,
270  (HBRUSH)(COLOR_BTNFACE+1),
271  NULL,
272  "WineMenuCheck",
273  };
274 
276 }
277 
278 static void test_getmenubarinfo(void)
279 {
280  BOOL ret;
281  HMENU hmenu;
282  MENUBARINFO mbi;
283  RECT rcw, rci;
284  HWND hwnd;
285  INT err;
286 
287  if (!pGetMenuBarInfo) {
288  win_skip("GetMenuBarInfo is not available\n");
289  return;
290  }
291 
292  mbi.cbSize = sizeof(MENUBARINFO);
293 
296  NULL, NULL, NULL, NULL);
297  ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
298 
299  /* no menu: getmenubarinfo should fail */
300  SetLastError(0xdeadbeef);
301  ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
302  err = GetLastError();
303  ok(ret == FALSE, "GetMenuBarInfo should not have been successful\n");
304  ok(err == 0xdeadbeef, "err = %d\n", err);
305 
306  /* create menubar, no items yet */
307  hmenu = CreateMenu();
308  ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
309 
310  ret = SetMenu(hwnd, hmenu);
311  ok(ret, "SetMenu failed with error %d\n", GetLastError());
312 
313  SetLastError(0xdeadbeef);
314  ret = pGetMenuBarInfo(NULL, OBJID_CLIENT, 0, &mbi);
315  err = GetLastError();
316  ok(!ret, "GetMenuBarInfo succeeded\n");
317  ok(err == ERROR_INVALID_WINDOW_HANDLE, "err = %d\n", err);
318 
319  SetLastError(0xdeadbeef);
320  ret = pGetMenuBarInfo(hwnd, OBJID_CLIENT, 0, &mbi);
321  err = GetLastError();
322  ok(!ret, "GetMenuBarInfo succeeded\n");
323  ok(err==ERROR_INVALID_MENU_HANDLE || broken(err==0xdeadbeef) /* NT, W2K, XP */, "err = %d\n", err);
324 
325  SetLastError(0xdeadbeef);
326  ret = pGetMenuBarInfo(hwnd, OBJID_MENU, -1, &mbi);
327  err = GetLastError();
328  ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
329  ok(err == 0xdeadbeef, "err = %d\n", err);
330 
331  mbi.cbSize = 1000;
332  SetLastError(0xdeadbeef);
333  ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
334  err = GetLastError();
335  ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
336  ok(err == ERROR_INVALID_PARAMETER, "err = %d\n", err);
337  mbi.cbSize = sizeof(MENUBARINFO);
338 
339  SetLastError(0xdeadbeef);
340  ret = pGetMenuBarInfo(hwnd, 123, 0, &mbi);
341  err = GetLastError();
342  ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
343  ok(err == 0xdeadbeef, "err = %d\n", err);
344 
345  ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
346  ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
347 
348  ok(mbi.rcBar.left == 0 && mbi.rcBar.top == 0 && mbi.rcBar.bottom == 0 && mbi.rcBar.right == 0,
349  "rcBar: Expected (0,0)-(0,0), got: %s\n", wine_dbgstr_rect(&mbi.rcBar));
350  ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n",
351  mbi.hMenu, hmenu);
352  ok(mbi.fBarFocused == 0, "fBarFocused: Got %d instead of 0.\n", mbi.fBarFocused);
353  ok(mbi.fFocused == 0, "fFocused: Got %d instead of 0.\n", mbi.fFocused);
354 
355  /* add some items */
356  ret = AppendMenuA(hmenu, MF_STRING , 100, "item 1");
357  ok(ret, "AppendMenu failed.\n");
358  ret = AppendMenuA(hmenu, MF_STRING , 101, "item 2");
359  ok(ret, "AppendMenu failed.\n");
360  ret = SetMenu(hwnd, hmenu);
361  ok(ret, "SetMenu failed with error %d\n", GetLastError());
362 
363  SetLastError(0xdeadbeef);
364  ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 200, &mbi);
365  err = GetLastError();
366  ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
367  ok(err == 0xdeadbeef, "err = %d\n", err);
368 
369  /* get info for the whole menu */
370  ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
371  ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
372 
373  /* calculate menu rectangle, from window rectangle and the position of the first item */
374  ret = GetWindowRect(hwnd, &rcw);
375  ok(ret, "GetWindowRect failed.\n");
376  ret = GetMenuItemRect(hwnd, hmenu, 0, &rci);
377  ok(ret, "GetMenuItemRect failed.\n");
378  todo_wine ok(mbi.rcBar.left == rci.left && mbi.rcBar.top == rci.top &&
379  mbi.rcBar.bottom == rci.bottom && mbi.rcBar.right == rcw.right - rci.left + rcw.left,
380  "rcBar: Got %s instead of (%d,%d)-(%d,%d)\n", wine_dbgstr_rect(&mbi.rcBar),
381  rci.left, rci.top, rcw.right - rci.left + rcw.left, rci.bottom);
382  ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n", mbi.hMenu, hmenu);
383  ok(mbi.fBarFocused == 0, "fBarFocused: got %d instead of 0\n", mbi.fBarFocused);
384  ok(mbi.fFocused == 0, "fFocused: got %d instead of 0\n", mbi.fFocused);
385 
386  /* get info for item nr.2 */
387  ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 2, &mbi);
388  ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
389  ret = GetMenuItemRect(hwnd, hmenu, 1, &rci);
390  ok(ret, "GetMenuItemRect failed.\n");
391  ok(EqualRect(&mbi.rcBar, &rci), "rcBar: Got %s instead of %s\n", wine_dbgstr_rect(&mbi.rcBar),
392  wine_dbgstr_rect(&rci));
393  ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n", mbi.hMenu, hmenu);
394  ok(mbi.fBarFocused == 0, "fBarFocused: got %d instead of 0\n", mbi.fBarFocused);
395  ok(mbi.fFocused == 0, "fFocused: got %d instead of 0\n", mbi.fFocused);
396 
398 }
399 
400 static void test_system_menu(void)
401 {
402  WCHAR testW[] = {'t','e','s','t',0};
403  BOOL ret;
404  HMENU menu;
405  HWND hwnd;
408  char buffer[80];
409  char found[0x200];
410  int i, res;
411 
414  NULL, NULL, NULL, NULL);
415  ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
416  menu = GetSystemMenu( hwnd, FALSE );
417  ok( menu != NULL, "no system menu\n" );
418 
419  for (i = 0xf000; i < 0xf200; i++)
420  {
421  memset( &info, 0xcc, sizeof(info) );
422  info.cbSize = sizeof(info);
423  info.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID;
424  info.dwTypeData = buffer;
425  info.cch = sizeof( buffer );
426  ret = GetMenuItemInfoA( menu, i, FALSE, &info );
427  if (ret) trace( "found %x: '%s'\n", i, buffer );
428  switch (i)
429  {
430  case SC_RESTORE:
431  case SC_SIZE:
432  case SC_MOVE:
433  case SC_MINIMIZE:
434  case SC_MAXIMIZE:
435  case SC_CLOSE:
436  ok( ret, "%x menu item not found\n", i );
437  break;
438  case SC_SCREENSAVE+1: /* used for the 'About Wine' entry, don't test */
439  break;
440  default:
441  ok( !ret, "%x menu item found\n", i );
442  break;
443  }
444  found[i - 0xf000] = ret;
445  }
446 
447  for (i = 0xf000; i < 0xf200; i++)
448  {
449  res = CheckMenuItem( menu, i, 0 );
450  if (res == -1) ok( !found[i - 0xf000], "could not check existent item %x\n", i );
451  else ok( found[i - 0xf000], "could check non-existent item %x\n", i );
452 
453  res = EnableMenuItem( menu, i, 0 );
454  if (res == -1) ok( !found[i - 0xf000], "could not enable existent item %x\n", i );
455  else ok( found[i - 0xf000], "could enable non-existent item %x\n", i );
456 
457  res = GetMenuState( menu, i, 0 );
458  if (res == -1) ok( !found[i - 0xf000], "could not get state existent item %x\n", i );
459  else ok( found[i - 0xf000], "could get state of non-existent item %x\n", i );
460 
461  if (!found[i - 0xf000]) /* don't remove the existing ones */
462  {
463  ret = RemoveMenu( menu, i, 0 );
464  ok( !ret, "could remove non-existent item %x\n", i );
465  }
466 
467  ret = ModifyMenuA( menu, i, 0, i, "test" );
468  if (i == SC_TASKLIST) ok( ret, "failed to modify SC_TASKLIST\n" );
469  else if (!ret) ok( !found[i - 0xf000], "could not modify existent item %x\n", i );
470  else ok( found[i - 0xf000], "could modify non-existent item %x\n", i );
471 
472  ret = ModifyMenuW( menu, i, 0, i, testW );
473  if (i == SC_TASKLIST) ok( ret, "failed to modify SC_TASKLIST\n" );
474  else if (!ret) ok( !found[i - 0xf000], "could not modify existent item %x\n", i );
475  else ok( found[i - 0xf000], "could modify non-existent item %x\n", i );
476 
477  ret = ModifyMenuA( menu, i, MF_BYPOSITION, i, "test" );
478  ok( !ret, "could modify non-existent item %x\n", i );
479 
480  strcpy( buffer, "test" );
481  memset( &info, 0xcc, sizeof(info) );
482  info.cbSize = sizeof(info);
483  info.fMask = MIIM_STRING | MIIM_ID;
484  info.wID = i;
485  info.dwTypeData = buffer;
486  info.cch = strlen( buffer );
487  ret = SetMenuItemInfoA( menu, i, FALSE, &info );
488  if (i == SC_TASKLIST) ok( ret, "failed to set SC_TASKLIST\n" );
489  else if (!ret) ok( !found[i - 0xf000], "could not set existent item %x\n", i );
490  else ok( found[i - 0xf000], "could set non-existent item %x\n", i );
491  ret = SetMenuItemInfoA( menu, i, TRUE, &info );
492  ok( !ret, "could modify non-existent item %x\n", i );
493 
494  memset( &infoW, 0xcc, sizeof(infoW) );
495  infoW.cbSize = sizeof(infoW);
496  infoW.fMask = MIIM_STRING | MIIM_ID;
497  infoW.wID = i;
498  infoW.dwTypeData = testW;
499  infoW.cch = lstrlenW( testW );
500  ret = SetMenuItemInfoW( menu, i, FALSE, &infoW );
501  if (i == SC_TASKLIST) ok( ret, "failed to set SC_TASKLIST\n" );
502  else if (!ret) ok( !found[i - 0xf000], "could not set existent item %x\n", i );
503  else ok( found[i - 0xf000], "could set non-existent item %x\n", i );
504  ret = SetMenuItemInfoW( menu, i, TRUE, &infoW );
505  ok( !ret, "could modify non-existent item %x\n", i );
506  }
507 
508  /* confirm that SC_TASKLIST still does not exist */
509  for (i = 0xf000; i < 0xf200; i++)
510  {
511  memset( &info, 0xcc, sizeof(info) );
512  info.cbSize = sizeof(info);
513  info.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID;
514  info.dwTypeData = buffer;
515  info.cch = sizeof( buffer );
516  ret = GetMenuItemInfoA( menu, i, FALSE, &info );
517  switch (i)
518  {
519  case SC_RESTORE:
520  case SC_SIZE:
521  case SC_MOVE:
522  case SC_MINIMIZE:
523  case SC_MAXIMIZE:
524  case SC_CLOSE:
525  ok( ret, "%x menu item not found\n", i );
526  break;
527  case SC_SCREENSAVE+1: /* used for the 'About Wine' entry, don't test */
528  break;
529  default:
530  ok( !ret, "%x menu item found\n", i );
531  break;
532  }
533  }
534 
535  /* now a normal (non-system) menu */
536 
537  menu = CreateMenu();
538  ok( menu != NULL, "CreateMenu failed with error %d\n", GetLastError() );
539 
540  res = CheckMenuItem( menu, SC_TASKLIST, 0 );
541  ok( res == -1, "CheckMenuItem succeeded\n" );
542  res = EnableMenuItem( menu, SC_TASKLIST, 0 );
543  ok( res == -1, "EnableMenuItem succeeded\n" );
544  res = GetMenuState( menu, SC_TASKLIST, 0 );
545  ok( res == -1, "GetMenuState succeeded\n" );
546  ret = RemoveMenu( menu, SC_TASKLIST, 0 );
547  ok( !ret, "RemoveMenu succeeded\n" );
548  ret = ModifyMenuA( menu, SC_TASKLIST, 0, SC_TASKLIST, "test" );
549  ok( ret, "ModifyMenuA failed err %d\n", GetLastError() );
550  ret = ModifyMenuW( menu, SC_TASKLIST, 0, SC_TASKLIST, testW );
551  ok( ret, "ModifyMenuW failed err %d\n", GetLastError() );
552  ret = ModifyMenuA( menu, SC_TASKLIST-1, 0, SC_TASKLIST, "test" );
553  ok( !ret, "ModifyMenu succeeded on SC_TASKLIST-1\n" );
554  strcpy( buffer, "test" );
555  memset( &info, 0xcc, sizeof(info) );
556  info.cbSize = sizeof(info);
557  info.fMask = MIIM_STRING | MIIM_ID;
558  info.wID = SC_TASKLIST;
559  info.dwTypeData = buffer;
560  info.cch = strlen( buffer );
561  ret = SetMenuItemInfoA( menu, SC_TASKLIST, FALSE, &info );
562  ok( ret, "failed to set SC_TASKLIST\n" );
563  ret = SetMenuItemInfoA( menu, SC_TASKLIST+1, FALSE, &info );
564  ok( !ret, "succeeded setting SC_TASKLIST+1\n" );
565  ret = SetMenuItemInfoA( menu, SC_TASKLIST, TRUE, &info );
566  ok( !ret, "succeeded setting by position\n" );
567 
568  memset( &infoW, 0xcc, sizeof(infoW) );
569  infoW.cbSize = sizeof(infoW);
570  infoW.fMask = MIIM_STRING | MIIM_ID;
571  infoW.wID = SC_TASKLIST;
572  infoW.dwTypeData = testW;
573  infoW.cch = lstrlenW( testW );
575  ok( ret, "failed to set SC_TASKLIST\n" );
576  ret = SetMenuItemInfoW( menu, SC_TASKLIST+1, FALSE, &infoW );
577  ok( !ret, "succeeded setting SC_TASKLIST+1\n" );
578  ret = SetMenuItemInfoW( menu, SC_TASKLIST, TRUE, &infoW );
579  ok( !ret, "succeeded setting by position\n" );
580 
581  DestroyMenu( menu );
582  DestroyWindow( hwnd );
583 }
584 
585 /* demonstrates that windows locks the menu object so that it is still valid
586  * even after a client calls DestroyMenu on it */
587 static void test_menu_locked_by_window(void)
588 {
589  BOOL ret;
590  HMENU hmenu;
593  NULL, NULL, NULL, NULL);
594  ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
595  hmenu = CreateMenu();
596  ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
597  ret = InsertMenuA(hmenu, 0, MF_STRING, 0, "&Test");
598  ok(ret, "InsertMenu failed with error %d\n", GetLastError());
599  ret = SetMenu(hwnd, hmenu);
600  ok(ret, "SetMenu failed with error %d\n", GetLastError());
601  ret = DestroyMenu(hmenu);
602  ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
603 
604  ret = DrawMenuBar(hwnd);
605  ok(ret, "DrawMenuBar failed with error %d\n", GetLastError());
606  ret = IsMenu(GetMenu(hwnd));
607  ok(!ret || broken(ret) /* nt4 */, "Menu handle should have been destroyed\n");
608 
610  /* did we process the WM_INITMENU message? */
612  todo_wine {
613  ok(ret, "WM_INITMENU should have been sent\n");
614  }
615 
617 }
618 
619 /* demonstrates that subpopup's are locked
620  * even after a client calls DestroyMenu on it */
622 {
623  HWND hwndmenu;
624  switch (msg)
625  {
626  case WM_ENTERIDLE:
627  hwndmenu = GetCapture();
628  if( hwndmenu) {
629  PostMessageA( hwndmenu, WM_KEYDOWN, VK_DOWN, 0);
630  PostMessageA( hwndmenu, WM_KEYDOWN, VK_RIGHT, 0);
631  PostMessageA( hwndmenu, WM_KEYDOWN, VK_RETURN, 0);
632  }
633  }
634  return DefWindowProcA(hwnd, msg, wparam, lparam);
635 }
636 
638 {
639  DWORD gle;
640  BOOL ret;
641  HMENU hmenu, hsubmenu;
642  MENUINFO mi = { sizeof( MENUINFO)};
643  MENUITEMINFOA mii = { sizeof( MENUITEMINFOA)};
644  HWND hwnd;
645  const int itemid = 0x1234567;
646  if( !pGetMenuInfo)
647  {
648  win_skip("GetMenuInfo is not available\n");
649  return;
650  }
651  /* create window, popupmenu with one subpopup */
654  NULL, NULL, NULL, NULL);
655  ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
658  ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
659  hsubmenu = CreatePopupMenu();
660  ok(hsubmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
662  "PopUpLockTest");
663  ok(ret, "InsertMenu failed with error %d\n", GetLastError());
664  ret = InsertMenuA(hsubmenu, 0, MF_BYPOSITION | MF_STRING, itemid, "PopUpMenu");
665  ok(ret, "InsertMenu failed with error %d\n", GetLastError());
666  /* first some tests that all this functions properly */
667  mii.fMask = MIIM_SUBMENU;
668  ret = GetMenuItemInfoA( hmenu, 0, TRUE, &mii);
669  ok( ret, "GetMenuItemInfo failed error %d\n", GetLastError());
670  ok( mii.hSubMenu == hsubmenu, "submenu is %p\n", mii.hSubMenu);
671  mi.fMask |= MIM_STYLE;
672  ret = pGetMenuInfo( hsubmenu, &mi);
673  ok( ret , "GetMenuInfo returned 0 with error %d\n", GetLastError());
674  ret = IsMenu( hsubmenu);
675  ok( ret , "Menu handle is not valid\n");
676  SetLastError( 0xdeadbeef);
677  ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
678  if( ret == (itemid & 0xffff)) {
679  win_skip("not on 16 bit menu subsystem\n");
680  DestroyMenu( hsubmenu);
681  } else {
682  gle = GetLastError();
683  ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, gle);
684  ok( gle == 0 ||
685  broken( gle == 0xdeadbeef), /* win2k0 */
686  "Last error is %d\n", gle);
687  /* then destroy the sub-popup */
688  ret = DestroyMenu( hsubmenu);
689  ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
690  /* and repeat the tests */
691  mii.fMask = MIIM_SUBMENU;
692  ret = GetMenuItemInfoA( hmenu, 0, TRUE, &mii);
693  ok( ret, "GetMenuItemInfo failed error %d\n", GetLastError());
694  /* GetMenuInfo fails now */
695  ok( mii.hSubMenu == hsubmenu, "submenu is %p\n", mii.hSubMenu);
696  mi.fMask |= MIM_STYLE;
697  ret = pGetMenuInfo( hsubmenu, &mi);
698  ok( !ret , "GetMenuInfo should have failed\n");
699  /* IsMenu says it is not */
700  ret = IsMenu( hsubmenu);
701  ok( !ret , "Menu handle should be invalid\n");
702  /* but TrackPopupMenu still works! */
703  SetLastError( 0xdeadbeef);
704  ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
705  gle = GetLastError();
706  todo_wine {
707  ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, gle);
708  }
709  ok( gle == 0 ||
710  broken(gle == 0xdeadbeef) || /* wow64 */
711  broken(gle == ERROR_INVALID_PARAMETER), /* win2k0 */
712  "Last error is %d\n", gle);
713  }
714  /* clean up */
715  DestroyMenu( hmenu);
717 }
718 
719 static void test_menu_ownerdraw(void)
720 {
721  int i,j,k;
722  BOOL ret;
723  HMENU hmenu;
724  MENUITEMINFOA mii;
725  LONG leftcol;
728  NULL, NULL, NULL, NULL);
729  ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
730  if( !hwnd) return;
733  ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
734  if( !hmenu) { DestroyWindow(hwnd);return;}
735  k=0;
736  for( j=0;j<2;j++) /* create columns */
737  for(i=0;i<2;i++) { /* create rows */
739  (i==0 ? MF_MENUBREAK : 0), k, (LPCSTR)MAKEINTRESOURCE(k));
740  k++;
741  ok( ret, "AppendMenu failed for %d\n", k-1);
742  }
743  MOD_maxid = k-1;
744  assert( k <= sizeof(MOD_rc)/sizeof(RECT));
745  /* display the menu */
746  TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
747 
748  /* columns have a 4 pixel gap between them */
749  ok( MOD_rc[0].right + 4 == MOD_rc[2].left,
750  "item rectangles are not separated by 4 pixels space\n");
751  /* height should be what the MEASUREITEM message has returned */
752  ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
753  "menu item has wrong height: %d should be %d\n",
754  MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
755  /* no gaps between the rows */
756  ok( MOD_rc[0].bottom - MOD_rc[1].top == 0,
757  "There should not be a space between the rows, gap is %d\n",
758  MOD_rc[0].bottom - MOD_rc[1].top);
759  /* test the correct value of the item height that was sent
760  * by the WM_MEASUREITEM message */
761  ok( MOD_odheight == HIWORD( GetDialogBaseUnits()) || /* WinNT,2k,XP */
762  MOD_odheight == MOD_hic, /* Win95,98,ME */
763  "Wrong height field in MEASUREITEMSTRUCT, expected %d or %d actual %d\n",
765  /* test what MF_MENUBREAK did at the first position. Also show
766  * that an MF_SEPARATOR is ignored in the height calculation. */
767  leftcol= MOD_rc[0].left;
769  /* display the menu */
770  TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
771  /* left should be 4 pixels less now */
772  ok( leftcol == MOD_rc[0].left + 4,
773  "columns should be 4 pixels to the left (actual %d).\n",
774  leftcol - MOD_rc[0].left);
775  /* test width */
776  ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
777  "width of owner drawn menu item is wrong. Got %d expected %d\n",
778  MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
779  /* and height */
780  ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
781  "Height is incorrect. Got %d expected %d\n",
782  MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
783 
784  /* test owner-drawn callback bitmap */
786  mii.cbSize = sizeof(mii);
788  if (GetMenuItemInfoA( hmenu, 1, TRUE, &mii ))
789  {
790  ok( mii.fType == MFT_BITMAP, "wrong type %x\n", mii.fType );
791  ok( mii.wID == 1, "wrong id %x\n", mii.wID );
792  ok( mii.hbmpItem == HBMMENU_CALLBACK, "wrong data %p\n", mii.hbmpItem );
793  }
794  TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
795 
796  /* test width/height of an ownerdraw menu bar as well */
797  ret = DestroyMenu(hmenu);
798  ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
799  hmenu = CreateMenu();
800  ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
801  if( !hmenu) { DestroyWindow(hwnd);return;}
802  MOD_maxid=1;
803  for(i=0;i<2;i++) {
804  ret = AppendMenuA( hmenu, MF_OWNERDRAW, i, 0 );
805  ok( ret, "AppendMenu failed for %d\n", i);
806  }
807  ret = SetMenu( hwnd, hmenu);
808  UpdateWindow( hwnd); /* hack for wine to draw the window + menu */
809  ok(ret, "SetMenu failed with error %d\n", GetLastError());
810  /* test width */
811  ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
812  "width of owner drawn menu item is wrong. Got %d expected %d\n",
813  MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
814  /* test height */
815  ok( MOD_rc[0].bottom - MOD_rc[0].top == GetSystemMetrics( SM_CYMENU) - 1,
816  "Height of owner drawn menu item is wrong. Got %d expected %d\n",
818 
819  /* clean up */
820  ret = DestroyMenu(hmenu);
821  ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
823 }
824 
825 /* helper for test_menu_bmp_and_string() */
826 static void test_mbs_help( int ispop, int hassub, int mnuopt,
827  HWND hwnd, int arrowwidth, int count, HBITMAP hbmp,
828  SIZE bmpsize, LPCSTR text, SIZE size, SIZE sc_size)
829 {
830  BOOL ret;
831  HMENU hmenu, submenu;
832  MENUITEMINFOA mii={ sizeof( MENUITEMINFOA )};
833  MENUINFO mi;
834  RECT rc;
835  CHAR text_copy[16];
836  int hastab, expect;
837  BOOL failed = FALSE;
838 
841  mii.fType = 0;
842  /* check the menu item unless MNS_CHECKORBMP is set */
843  mii.fState = (mnuopt != 2 ? MFS_CHECKED : MFS_UNCHECKED);
844  mii.dwItemData =0;
845  MODsizes[0] = bmpsize;
846  hastab = 0;
847  if( text ) {
848  char *p;
849  mii.fMask |= MIIM_STRING;
850  strcpy(text_copy, text);
851  mii.dwTypeData = text_copy; /* structure member declared non-const */
852  if( ( p = strchr( text, '\t'))) {
853  hastab = *(p + 1) ? 2 : 1;
854  }
855  }
856  /* tabs don't make sense in menubars */
857  if(hastab && !ispop) return;
858  if( hbmp) {
859  mii.fMask |= MIIM_BITMAP;
860  mii.hbmpItem = hbmp;
861  }
862  submenu = CreateMenu();
863  ok( submenu != 0, "CreateMenu failed with error %d\n", GetLastError());
864  if( ispop)
866  else
867  hmenu = CreateMenu();
868  ok( hmenu != 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
869  if( hassub) {
870  mii.fMask |= MIIM_SUBMENU;
871  mii.hSubMenu = submenu;
872  }
873  if( mnuopt) {
874  mi.cbSize = sizeof(mi);
875  mi.fMask = MIM_STYLE;
876  pGetMenuInfo( hmenu, &mi);
877  if( mnuopt) mi.dwStyle |= mnuopt == 1 ? MNS_NOCHECK : MNS_CHECKORBMP;
878  ret = pSetMenuInfo( hmenu, &mi);
879  ok( ret, "SetMenuInfo failed with error %d\n", GetLastError());
880  }
881  ret = InsertMenuItemA( hmenu, 0, FALSE, &mii);
882  ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
883  failed = !ret;
884  if( winetest_debug) {
885  HDC hdc=GetDC(hwnd);
886  RECT rc = {100, 50, 400, 70};
887  char buf[100];
888 
889  sprintf( buf,"%d text \"%s\" mnuopt %d", count, text ? text: "(nil)", mnuopt);
890  FillRect( hdc, &rc, (HBRUSH) COLOR_WINDOW);
891  TextOutA( hdc, 10, 50, buf, strlen( buf));
892  ReleaseDC( hwnd, hdc);
893  }
894  if(ispop)
895  TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
896  else {
897  ret = SetMenu( hwnd, hmenu);
898  ok(ret, "SetMenu failed with error %d\n", GetLastError());
899  DrawMenuBar( hwnd);
900  }
901  ret = GetMenuItemRect( hwnd, hmenu, 0, &rc);
902  ok(ret, "GetMenuItemRect failed with error %d\n", GetLastError());
903 
904  if (0) /* comment out menu size checks, behavior is different in almost every Windows version */
905  /* the tests should however succeed on win2000, XP and Wine (at least up to 1.1.15) */
906  /* with a variety of dpis and desktop font sizes */
907  {
908  /* check menu width */
909  if( ispop)
910  expect = ( text || hbmp ?
911  4 + (mnuopt != 1 ? GetSystemMetrics(SM_CXMENUCHECK) : 0)
912  : 0) +
913  arrowwidth + MOD_avec + (hbmp ?
914  ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ? bmpsize.cx + 2 : GetSystemMetrics( SM_CXMENUSIZE) + 2)
915  : 0) +
916  (text && hastab ? /* TAB space */
917  MOD_avec + ( hastab==2 ? sc_size.cx : 0) : 0) +
918  (text ? 2 + (text[0] ? size.cx :0): 0) ;
919  else
920  expect = !(text || hbmp) ? 0 :
921  ( hbmp ? (text ? 2:0) + bmpsize.cx : 0 ) +
922  (text ? 2 * MOD_avec + (text[0] ? size.cx :0): 0) ;
923  ok( rc.right - rc.left == expect,
924  "menu width wrong, got %d expected %d\n", rc.right - rc.left, expect);
925  failed = failed || !(rc.right - rc.left == expect);
926  /* check menu height */
927  if( ispop)
928  expect = max( ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 : 0),
929  max( (text ? max( 2 + size.cy, MOD_hic + 4) : 0),
930  (hbmp ?
931  ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ?
932  bmpsize.cy + 2
934  : 0)));
935  else
936  expect = ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 :
937  max( GetSystemMetrics( SM_CYMENU) - 1, (hbmp ? bmpsize.cy : 0)));
938  ok( rc.bottom - rc.top == expect,
939  "menu height wrong, got %d expected %d (%d)\n",
941  failed = failed || !(rc.bottom - rc.top == expect);
943  /* check the position of the bitmap */
944  /* horizontal */
945  if (!ispop)
946  expect = 3;
947  else if (mnuopt == 0)
949  else if (mnuopt == 1)
950  expect = 4;
951  else /* mnuopt == 2 */
952  expect = 2;
953  ok( expect == MOD_rc[0].left,
954  "bitmap left is %d expected %d\n", MOD_rc[0].left, expect);
955  failed = failed || !(expect == MOD_rc[0].left);
956  /* vertical */
957  expect = (rc.bottom - rc.top - MOD_rc[0].bottom + MOD_rc[0].top) / 2;
958  ok( expect == MOD_rc[0].top,
959  "bitmap top is %d expected %d\n", MOD_rc[0].top, expect);
960  failed = failed || !(expect == MOD_rc[0].top);
961  }
962  }
963  /* if there was a failure, report details */
964  if( failed) {
965  trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
966  count, (ispop? "POPUP": "MENUBAR"),text ? text: "(nil)", hbmp, bmpsize.cx, bmpsize.cy,
967  size.cx, size.cy, sc_size.cx, mnuopt, hastab);
968  trace(" check %d,%d arrow %d avechar %d\n",
971  if( hbmp == HBMMENU_CALLBACK)
972  trace( " rc %s bmp.rc %s\n", wine_dbgstr_rect(&rc), wine_dbgstr_rect(&MOD_rc[0]));
973  }
974  /* clean up */
975  ret = DestroyMenu(submenu);
976  ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
977  ret = DestroyMenu(hmenu);
978  ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
979 }
980 
981 
982 static void test_menu_bmp_and_string(void)
983 {
984  BYTE bmfill[300];
985  HBITMAP hbm_arrow;
986  BITMAP bm;
987  INT arrowwidth;
988  HWND hwnd;
989  HMENU hsysmenu;
990  MENUINFO mi= {sizeof(MENUINFO)};
991  MENUITEMINFOA mii= {sizeof(MENUITEMINFOA)};
992  int count, szidx, txtidx, bmpidx, hassub, mnuopt, ispop;
993  BOOL got;
994 
995  if( !pGetMenuInfo)
996  {
997  win_skip("GetMenuInfo is not available\n");
998  return;
999  }
1000 
1001  memset( bmfill, 0xcc, sizeof( bmfill));
1004  NULL, NULL, NULL, NULL);
1005  hbm_arrow = LoadBitmapA( 0, (LPCSTR)OBM_MNARROW);
1006  GetObjectA( hbm_arrow, sizeof(bm), &bm);
1007  arrowwidth = bm.bmWidth;
1008  ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
1009  if( !hwnd) return;
1010  /* test system menu */
1011  hsysmenu = GetSystemMenu( hwnd, FALSE);
1012  ok( hsysmenu != NULL, "GetSystemMenu failed with error %d\n", GetLastError());
1013  mi.fMask = MIM_STYLE;
1014  mi.dwStyle = 0;
1015  got = pGetMenuInfo( hsysmenu, &mi);
1016  ok( got, "GetMenuInfo failed gle=%d\n", GetLastError());
1017  ok( MNS_CHECKORBMP == mi.dwStyle, "System Menu Style is %08x, without the bit %08x\n",
1018  mi.dwStyle, MNS_CHECKORBMP);
1019  mii.fMask = MIIM_BITMAP;
1020  mii.hbmpItem = NULL;
1021  got = GetMenuItemInfoA( hsysmenu, SC_CLOSE, FALSE, &mii);
1022  ok( got, "GetMenuItemInfoA failed gle=%d\n", GetLastError());
1023  ok( HBMMENU_POPUP_CLOSE == mii.hbmpItem, "Item info did not get the right hbitmap: got %p expected %p\n",
1024  mii.hbmpItem, HBMMENU_POPUP_CLOSE);
1025 
1026  memset(&mii, 0x81, sizeof(mii));
1027  mii.cbSize = sizeof(mii);
1029  mii.dwTypeData = (LPSTR)bmfill;
1030  mii.cch = sizeof(bmfill);
1031  mii.dwItemData = 0x81818181;
1032  got = GetMenuItemInfoA(hsysmenu, SC_RESTORE, 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_RESTORE, "expected HBMMENU_POPUP_RESTORE, got %p\n", mii.hbmpItem);
1042 
1043  mii.cbSize = sizeof(mii);
1044  mii.fMask = MIIM_TYPE;
1045  mii.hbmpItem = (HBITMAP)0x81818181;
1046  got = GetMenuItemInfoA(hsysmenu, SC_CLOSE, FALSE, &mii);
1047  ok(got, "GetMenuItemInfo failed\n");
1048  ok((mii.fType & ~(MFT_RIGHTJUSTIFY|MFT_RIGHTORDER)) == MFT_STRING, "expected MFT_STRING, got %#x\n", mii.fType);
1049  ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
1050  ok(mii.wID == SC_RESTORE, "expected SC_RESTORE, got %#x\n", mii.wID);
1051  ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
1052  ok(mii.dwItemData == 0, "expected 0, got %#lx\n", mii.dwItemData);
1053  ok(mii.dwTypeData == (LPSTR)bmfill, "expected %p, got %p\n", bmfill, mii.dwTypeData);
1054  ok(mii.cch != 0, "cch should not be 0\n");
1055  ok(mii.hbmpItem == HBMMENU_POPUP_CLOSE, "expected HBMMENU_POPUP_CLOSE, got %p\n", mii.hbmpItem);
1056 
1058 
1059  if( winetest_debug)
1060  trace(" check %d,%d arrow %d avechar %d\n",
1062  GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
1063  count = 0;
1064  MOD_maxid = 0;
1065  for( ispop=1; ispop >= 0; ispop--){
1066  static SIZE bmsizes[]= {
1067  {10,10},{38,38},{1,30},{55,5}};
1068  for( szidx=0; szidx < sizeof( bmsizes) / sizeof( SIZE); szidx++) {
1069  HBITMAP hbm = CreateBitmap( bmsizes[szidx].cx, bmsizes[szidx].cy,1,1,bmfill);
1071  ok( hbm != 0, "CreateBitmap failed err %d\n", GetLastError());
1072  for( txtidx = 0; txtidx < sizeof(MOD_txtsizes)/sizeof(MOD_txtsizes[0]); txtidx++) {
1073  for( hassub = 0; hassub < 2 ; hassub++) { /* add submenu item */
1074  for( mnuopt = 0; mnuopt < 3 ; mnuopt++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
1075  for( bmpidx = 0; bmpidx <sizeof(bitmaps)/sizeof(HBITMAP); bmpidx++) {
1076  /* no need to test NULL bitmaps of several sizes */
1077  if( !bitmaps[bmpidx] && szidx > 0) continue;
1078  /* the HBMMENU_POPUP not to test for menu bars */
1079  if( !ispop &&
1080  bitmaps[bmpidx] >= HBMMENU_POPUP_CLOSE &&
1081  bitmaps[bmpidx] <= HBMMENU_POPUP_MINIMIZE) continue;
1082  if( !ispop && hassub) continue;
1083  test_mbs_help( ispop, hassub, mnuopt,
1084  hwnd, arrowwidth, ++count,
1085  bitmaps[bmpidx],
1086  bmsizes[szidx],
1087  MOD_txtsizes[txtidx].text,
1088  MOD_txtsizes[txtidx].size,
1089  MOD_txtsizes[txtidx].sc_size);
1090  }
1091  }
1092  }
1093  }
1094  DeleteObject( hbm);
1095  }
1096  }
1097  /* clean up */
1099 }
1100 
1101 static void test_menu_add_string( void )
1102 {
1103  HMENU hmenu;
1105  BOOL rc;
1106  int ret;
1107 
1108  char string[0x80];
1109  char string2[0x80];
1110 
1111  char strback[0x80];
1112  WCHAR strbackW[0x80];
1113  static CHAR blah[] = "blah";
1114  static const WCHAR expectedString[] = {'D','u','m','m','y',' ','s','t','r','i','n','g', 0};
1115 
1116  hmenu = CreateMenu();
1117 
1118  memset( &info, 0, sizeof info );
1119  info.cbSize = sizeof info;
1121  info.dwTypeData = blah;
1122  info.cch = 6;
1123  info.dwItemData = 0;
1124  info.wID = 1;
1125  info.fState = 0;
1126  InsertMenuItemA(hmenu, 0, TRUE, &info );
1127 
1128  memset( &info, 0, sizeof info );
1129  info.cbSize = sizeof info;
1131  info.dwTypeData = string;
1132  info.cch = sizeof string;
1133  string[0] = 0;
1134  GetMenuItemInfoA( hmenu, 0, TRUE, &info );
1135 
1136  ok( !strcmp( string, "blah" ), "menu item name differed\n");
1137 
1138  /* Test combination of ownerdraw and strings with GetMenuItemString(A/W) */
1139  strcpy(string, "Dummy string");
1140  memset(&info, 0x00, sizeof(info));
1141  info.cbSize= sizeof(MENUITEMINFOA);
1142  info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
1143  info.fType= MFT_OWNERDRAW;
1144  info.dwTypeData= string;
1145  rc = InsertMenuItemA( hmenu, 0, TRUE, &info );
1146  ok (rc, "InsertMenuItem failed\n");
1147 
1148  strcpy(string,"Garbage");
1149  ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1150  ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
1151 
1152  SetLastError(0xdeadbeef);
1153  ret = GetMenuStringW( hmenu, 0, strbackW, 99, MF_BYPOSITION );
1155  win_skip("GetMenuStringW is not implemented\n");
1156  else
1157  {
1158  ok (ret, "GetMenuStringW on ownerdraw entry failed\n");
1159  ok (!lstrcmpW( strbackW, expectedString ), "Menu text from Unicode version incorrect\n");
1160  }
1161 
1162  /* Just try some invalid parameter tests */
1163  SetLastError(0xdeadbeef);
1164  rc = SetMenuItemInfoA( hmenu, 0, TRUE, NULL );
1165  ret = GetLastError();
1166  ok (!rc, "SetMenuItemInfoA succeeded unexpectedly\n");
1167  ok (ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
1168 
1169  SetLastError(0xdeadbeef);
1170  rc = SetMenuItemInfoA( hmenu, 0, FALSE, NULL );
1171  ret = GetLastError();
1172  ok (!rc, "SetMenuItemInfoA succeeded unexpectedly\n");
1173  ok (ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
1174 
1175  /* Just change ftype to string and see what text is stored */
1176  memset(&info, 0x00, sizeof(info));
1177  info.cbSize= sizeof(MENUITEMINFOA);
1178  info.fMask= MIIM_FTYPE; /* Set string type */
1179  info.fType= MFT_STRING;
1180  info.dwTypeData= (char *)0xdeadbeef;
1181  rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1182  ok (rc, "SetMenuItemInfo failed\n");
1183 
1184  /* Did we keep the old dwTypeData? */
1185  ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1186  ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
1187 
1188  /* Ensure change to bitmap type fails */
1189  memset(&info, 0x00, sizeof(info));
1190  info.cbSize= sizeof(MENUITEMINFOA);
1191  info.fMask= MIIM_FTYPE; /* Set as bitmap type */
1192  info.fType= MFT_BITMAP;
1193  info.dwTypeData= (char *)0xdeadbee2;
1194  rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1195  ok (!rc, "SetMenuItemInfo unexpectedly worked\n");
1196 
1197  /* Just change ftype back and ensure data hasn't been freed */
1198  info.fType= MFT_OWNERDRAW; /* Set as ownerdraw type */
1199  info.dwTypeData= (char *)0xdeadbee3;
1200  rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1201  ok (rc, "SetMenuItemInfo failed\n");
1202 
1203  /* Did we keep the old dwTypeData? */
1204  ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1205  ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
1206 
1207  /* Just change string value (not type) */
1208  memset(&info, 0x00, sizeof(info));
1209  info.cbSize= sizeof(MENUITEMINFOA);
1210  info.fMask= MIIM_STRING; /* Set typeData */
1211  strcpy(string2, "string2");
1212  info.dwTypeData= string2;
1213  rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1214  ok (rc, "SetMenuItemInfo failed\n");
1215 
1216  ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1217  ok (!strcmp( strback, "string2" ), "Menu text from Ansi version incorrect\n");
1218 
1219  /* crashes with wine 0.9.5 */
1220  memset(&info, 0x00, sizeof(info));
1221  info.cbSize= sizeof(MENUITEMINFOA);
1222  info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
1223  info.fType= MFT_OWNERDRAW;
1224  rc = InsertMenuItemA( hmenu, 0, TRUE, &info );
1225  ok (rc, "InsertMenuItem failed\n");
1227  "GetMenuString on ownerdraw entry succeeded.\n");
1228  SetLastError(0xdeadbeef);
1231  win_skip("GetMenuStringW is not implemented\n");
1232  else
1233  ok (!ret, "GetMenuStringW on ownerdraw entry succeeded.\n");
1234 
1235  DestroyMenu( hmenu );
1236 }
1237 
1238 /* define building blocks for the menu item info tests */
1239 static int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
1240 {
1241  if (n <= 0) return 0;
1242  while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
1243  return *str1 - *str2;
1244 }
1245 
1246 static WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
1247 {
1248  WCHAR *p = dst;
1249  while ((*p++ = *src++));
1250  return dst;
1251 }
1252 
1254  HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
1255  void *type_data, UINT len, HBITMAP item, BOOL expect )
1256 {
1258  BOOL ret;
1259 
1260  /* magic bitmap handle to test smaller cbSize */
1261  if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
1262  info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
1263  else
1264  info.cbSize = sizeof(info);
1265  info.fMask = mask;
1266  info.fType = type;
1267  info.fState = state;
1268  info.wID = id;
1269  info.hSubMenu = submenu;
1270  info.hbmpChecked = checked;
1271  info.hbmpUnchecked = unchecked;
1272  info.dwItemData = data;
1273  info.dwTypeData = type_data;
1274  info.cch = len;
1275  info.hbmpItem = item;
1276  SetLastError( 0xdeadbeef );
1277  if (ansi) ret = InsertMenuItemA( hmenu, 0, TRUE, &info );
1278  else ret = InsertMenuItemW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
1279  if (!expect) ok_(__FILE__, line)( !ret, "InsertMenuItem should have failed.\n" );
1280  else ok_(__FILE__, line)( ret, "InsertMenuItem failed, err %u\n", GetLastError());
1281 }
1282 
1284  UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked,
1285  ULONG_PTR data, void *type_data, UINT in_len, UINT out_len,
1286  HBITMAP item, LPCSTR expname, BOOL expect, BOOL expstring )
1287 {
1289  BOOL ret;
1290  WCHAR buffer[80];
1291 
1292  SetLastError( 0xdeadbeef );
1293  memset( &info, 0xcc, sizeof(info) );
1294  info.cbSize = sizeof(info);
1295  info.fMask = mask;
1296  info.dwTypeData = type_data;
1297  info.cch = in_len;
1298 
1299  ret = ansi ? GetMenuItemInfoA( hmenu, 0, TRUE, &info ) :
1301  if (!expect)
1302  {
1303  ok_(__FILE__, line)( !ret, "GetMenuItemInfo should have failed.\n" );
1304  return;
1305  }
1306  ok_(__FILE__, line)( ret, "GetMenuItemInfo failed, err %u\n", GetLastError());
1307  if (mask & MIIM_TYPE)
1308  ok_(__FILE__, line)( info.fType == type || info.fType == LOWORD(type),
1309  "wrong type %x/%x\n", info.fType, type );
1310  if (mask & MIIM_STATE)
1311  ok_(__FILE__, line)( info.fState == state || info.fState == LOWORD(state),
1312  "wrong state %x/%x\n", info.fState, state );
1313  if (mask & MIIM_ID)
1314  ok_(__FILE__, line)( info.wID == id || info.wID == LOWORD(id),
1315  "wrong id %x/%x\n", info.wID, id );
1316  if (mask & MIIM_SUBMENU)
1317  ok_(__FILE__, line)( info.hSubMenu == submenu || (ULONG_PTR)info.hSubMenu == LOWORD(submenu),
1318  "wrong submenu %p/%p\n", info.hSubMenu, submenu );
1319  if (mask & MIIM_CHECKMARKS)
1320  {
1321  ok_(__FILE__, line)( info.hbmpChecked == checked || (ULONG_PTR)info.hbmpChecked == LOWORD(checked),
1322  "wrong bmpchecked %p/%p\n", info.hbmpChecked, checked );
1323  ok_(__FILE__, line)( info.hbmpUnchecked == unchecked || (ULONG_PTR)info.hbmpUnchecked == LOWORD(unchecked),
1324  "wrong bmpunchecked %p/%p\n", info.hbmpUnchecked, unchecked );
1325  }
1326  if (mask & MIIM_DATA)
1327  ok_(__FILE__, line)( info.dwItemData == data || info.dwItemData == LOWORD(data),
1328  "wrong item data %lx/%lx\n", info.dwItemData, data );
1329  if (mask & MIIM_BITMAP)
1330  ok_(__FILE__, line)( info.hbmpItem == item || (ULONG_PTR)info.hbmpItem == LOWORD(item),
1331  "wrong bmpitem %p/%p\n", info.hbmpItem, item );
1332  ok_(__FILE__, line)( info.dwTypeData == type_data || (ULONG_PTR)info.dwTypeData == LOWORD(type_data),
1333  "wrong type data %p/%p\n", info.dwTypeData, type_data );
1334  ok_(__FILE__, line)( info.cch == out_len ||
1335  broken(! ansi && info.cch == 2 * out_len) /* East-Asian */,
1336  "wrong len %x/%x\n", info.cch, out_len );
1337  if (expname)
1338  {
1339  if(ansi)
1340  ok_(__FILE__, line)( !strncmp( expname, info.dwTypeData, out_len ),
1341  "menu item name differed from '%s' '%s'\n", expname, info.dwTypeData );
1342  else
1343  ok_(__FILE__, line)( !strncmpW( (WCHAR *)expname, (WCHAR *)info.dwTypeData, out_len ),
1344  "menu item name wrong\n" );
1345 
1346  SetLastError( 0xdeadbeef );
1347  ret = ansi ? GetMenuStringA( hmenu, 0, (char *)buffer, 80, MF_BYPOSITION ) :
1349  if (expstring)
1350  ok_(__FILE__, line)( ret, "GetMenuString failed, err %u\n", GetLastError());
1351  else
1352  ok_(__FILE__, line)( !ret, "GetMenuString should have failed\n" );
1353  }
1354 }
1355 
1356 static void modify_menu( int line, HMENU hmenu, BOOL ansi, UINT flags, UINT_PTR id, void *data )
1357 {
1358  BOOL ret;
1359 
1360  SetLastError( 0xdeadbeef );
1361  if (ansi) ret = ModifyMenuA( hmenu, 0, flags, id, data );
1362  else ret = ModifyMenuW( hmenu, 0, flags, id, data );
1363  ok_(__FILE__,line)( ret, "ModifyMenuA failed, err %u\n", GetLastError());
1364 }
1365 
1367  UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
1368  void *type_data, UINT len, HBITMAP item )
1369 
1370 {
1372  BOOL ret;
1373 
1374  /* magic bitmap handle to test smaller cbSize */
1375  if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
1376  info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
1377  else
1378  info.cbSize = sizeof(info);
1379  info.fMask = mask;
1380  info.fType = type;
1381  info.fState = state;
1382  info.wID = id;
1383  info.hSubMenu = submenu;
1384  info.hbmpChecked = checked;
1385  info.hbmpUnchecked = unchecked;
1386  info.dwItemData = data;
1387  info.dwTypeData = type_data;
1388  info.cch = len;
1389  info.hbmpItem = item;
1390  SetLastError( 0xdeadbeef );
1391  if (ansi) ret = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1392  else ret = SetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
1393  ok_(__FILE__, line)( ret, "SetMenuItemInfo failed, err %u\n", GetLastError());
1394 }
1395 
1396 #define TMII_INSMI( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,eret1 )\
1397  hmenu = CreateMenu();\
1398  submenu = CreateMenu();\
1399  if(ansi)strcpy( string, init );\
1400  else strcpyW( string, init );\
1401  insert_menu_item( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, eret1 )
1402 
1403 /* GetMenuItemInfo + GetMenuString */
1404 #define TMII_GMII( c2,l2,\
1405  d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,\
1406  expname, eret2, eret3)\
1407  check_menu_item_info( __LINE__, hmenu, ansi, c2, d3, e3, f3, g3, h3, i3, j3, k3, l2, l3, m3, \
1408  expname, eret2, eret3 )
1409 
1410 #define TMII_DONE \
1411  RemoveMenu(hmenu, 0, TRUE );\
1412  DestroyMenu( hmenu );\
1413  DestroyMenu( submenu );
1414 
1415 /* modify menu */
1416 #define TMII_MODM( flags, id, data ) \
1417  modify_menu( __LINE__, hmenu, ansi, flags, id, data )
1418 
1419 /* SetMenuItemInfo */
1420 #define TMII_SMII( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1 ) \
1421  set_menu_item_info( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1 )
1422 
1423 
1424 #define OK 1
1425 #define ER 0
1426 
1427 
1428 static void test_menu_iteminfo( void )
1429 {
1430  BOOL ansi = TRUE;
1431  char txtA[]="wine";
1432  char initA[]="XYZ";
1433  char emptyA[]="";
1434  WCHAR txtW[]={'W','i','n','e',0};
1435  WCHAR initW[]={'X','Y','Z',0};
1436  WCHAR emptyW[]={0};
1437  void *txt, *init, *empty, *string;
1438  HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
1439  char stringA[0x80];
1440  HMENU hmenu, submenu;
1441  HBITMAP dummy_hbm = (HBITMAP)(ULONG_PTR)0xdeadbeef;
1442 
1443  do {
1444  if( ansi) {txt=txtA;init=initA;empty=emptyA;string=stringA;}
1445  else {txt=txtW;init=initW;empty=emptyW;string=stringA;}
1446  trace( "%s string %p hbm %p txt %p\n", ansi ? "ANSI tests: " : "Unicode tests:", string, hbm, txt);
1447  /* test all combinations of MFT_STRING, MFT_OWNERDRAW and MFT_BITMAP */
1448  /* (since MFT_STRING is zero, there are four of them) */
1449  TMII_INSMI( MIIM_TYPE, MFT_STRING, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1450  TMII_GMII ( MIIM_TYPE, 80,
1451  MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1452  txt, OK, OK );
1453  TMII_DONE
1454  TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1455  TMII_GMII ( MIIM_TYPE, 80,
1456  MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1457  NULL, OK, ER );
1458  TMII_DONE
1459  TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1460  TMII_GMII ( MIIM_TYPE, 80,
1461  MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1462  NULL, OK, ER );
1463  TMII_DONE
1464  TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1465  TMII_GMII ( MIIM_TYPE, 80,
1466  MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1467  NULL, OK, ER );
1468  TMII_DONE
1469  /* not enough space for name*/
1470  TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1471  TMII_GMII ( MIIM_TYPE, 0,
1472  MFT_STRING, 0, 0, 0, 0, 0, 0, NULL, 4, 0,
1473  NULL, OK, OK );
1474  TMII_DONE
1475  TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1476  TMII_GMII ( MIIM_TYPE, 5,
1477  MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1478  txt, OK, OK );
1479  TMII_DONE
1480  TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1481  TMII_GMII ( MIIM_TYPE, 4,
1482  MFT_STRING, 0, 0, 0, 0, 0, 0, string, 3, 0,
1483  txt, OK, OK );
1484  TMII_DONE
1485  TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1486  TMII_GMII ( MIIM_TYPE, 0,
1487  MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, 0,
1488  NULL, OK, ER );
1489  TMII_DONE
1490  /* cannot combine MIIM_TYPE with some other flags */
1491  TMII_INSMI( MIIM_TYPE|MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1492  TMII_DONE
1493  TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1495  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1496  NULL, ER, OK );
1497  TMII_DONE
1498  TMII_INSMI( MIIM_TYPE|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1499  TMII_DONE
1500  TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1502  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1503  NULL, ER, OK );
1504  TMII_DONE
1505  TMII_INSMI( MIIM_TYPE|MIIM_BITMAP, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, hbm, ER );
1506  TMII_DONE
1507  /* but succeeds with some others */
1508  TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1510  MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1511  txt, OK, OK );
1512  TMII_DONE
1513  TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1515  MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1516  txt, OK, OK );
1517  TMII_DONE
1518  TMII_INSMI( MIIM_TYPE|MIIM_ID, MFT_STRING, -1, 888, 0, 0, 0, -1, txt, 6, 0, OK );
1519  TMII_GMII ( MIIM_TYPE|MIIM_ID, 80,
1520  MFT_STRING, 0, 888, 0, 0, 0, 0, string, 4, 0,
1521  txt, OK, OK );
1522  TMII_DONE
1523  TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING, -1, -1, 0, 0, 0, 999, txt, 6, 0, OK );
1525  MFT_STRING, 0, 0, 0, 0, 0, 999, string, 4, 0,
1526  txt, OK, OK );
1527  TMII_DONE
1528  /* to be continued */
1529  /* set text with MIIM_TYPE and retrieve with MIIM_STRING */
1530  TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1532  MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1533  txt, OK, OK );
1534  TMII_DONE
1535  /* set text with MIIM_TYPE and retrieve with MIIM_STRING; MFT_OWNERDRAW causes an empty string */
1536  TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1538  MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1539  empty, OK, ER );
1540  TMII_DONE
1541  TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1543  MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1544  empty, OK, ER );
1545  TMII_DONE
1546  TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1547  TMII_GMII ( MIIM_FTYPE, 80,
1548  MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, 0,
1549  init, OK, ER );
1550  TMII_DONE
1551  TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1552  TMII_GMII ( 0, 80,
1553  0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1554  init, OK, OK );
1555  TMII_DONE
1556  /* contrary to MIIM_TYPE,you can set the text for an owner draw menu */
1557  TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1559  MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1560  txt, OK, OK );
1561  TMII_DONE
1562  /* same but retrieve with MIIM_TYPE */
1563  TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1564  TMII_GMII ( MIIM_TYPE, 80,
1565  MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1566  NULL, OK, OK );
1567  TMII_DONE
1568  TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1570  MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1571  empty, OK, ER );
1572  TMII_DONE
1573  TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1575  MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1576  empty, OK, ER );
1577  TMII_DONE
1578  TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1580  MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, 0,
1581  NULL, OK, ER );
1582  TMII_DONE
1583 
1584  /* How is that with bitmaps? */
1585  TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1586  TMII_GMII ( MIIM_TYPE, 80,
1587  MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1588  NULL, OK, ER );
1589  TMII_DONE
1590  TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1592  0, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1593  init, OK, ER );
1594  TMII_DONE
1595  /* MIIM_BITMAP does not like MFT_BITMAP */
1596  TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, hbm, ER );
1597  TMII_DONE
1598  /* no problem with OWNERDRAWN */
1599  TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1601  MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1602  init, OK, ER );
1603  TMII_DONE
1604  /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1605  TMII_INSMI( MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER );
1606  TMII_DONE
1607 
1608  /* menu with submenu */
1609  TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1610  TMII_GMII ( MIIM_SUBMENU, 80,
1611  0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1612  init, OK, ER );
1613  TMII_DONE
1614  TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, empty, 0, 0, OK );
1615  TMII_GMII ( MIIM_SUBMENU, 80,
1616  0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1617  init, OK, ER );
1618  TMII_DONE
1619  /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1620  TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1622  MFT_STRING|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1623  empty, OK, ER );
1625  MFT_SEPARATOR, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1626  empty, OK, ER );
1627  TMII_DONE
1628  /* menu with invalid submenu */
1629  TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, (HMENU)999, 0, 0, -1, txt, 0, 0, ER );
1630  TMII_DONE
1631  /* Separator */
1632  TMII_INSMI( MIIM_TYPE, MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1633  TMII_GMII ( MIIM_TYPE, 80,
1634  MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1635  NULL, OK, ER );
1636  TMII_DONE
1637  TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1638  TMII_GMII ( MIIM_TYPE, 80,
1639  MFT_BITMAP|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1640  NULL, OK, ER );
1641  TMII_DONE
1642  /* SEPARATOR and STRING go well together */
1643  /* BITMAP and STRING go well together */
1644  TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1646  MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1647  txt, OK, OK );
1648  TMII_DONE
1649  /* BITMAP, SEPARATOR and STRING go well together */
1650  TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1652  MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1653  txt, OK, OK );
1654  TMII_DONE
1655  /* last two tests, but use MIIM_TYPE to retrieve info */
1656  TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1657  TMII_GMII ( MIIM_TYPE, 80,
1658  MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1659  NULL, OK, OK );
1660  TMII_DONE
1661  TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1662  TMII_GMII ( MIIM_TYPE, 80,
1663  MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1664  NULL, OK, OK );
1665  TMII_DONE
1666  TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1667  TMII_GMII ( MIIM_TYPE, 80,
1668  MFT_SEPARATOR|MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1669  NULL, OK, OK );
1670  TMII_DONE
1671  /* same three with MFT_OWNERDRAW */
1672  TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1673  TMII_GMII ( MIIM_TYPE, 80,
1674  MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1675  NULL, OK, OK );
1676  TMII_DONE
1677  TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1678  TMII_GMII ( MIIM_TYPE, 80,
1679  MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1680  NULL, OK, OK );
1681  TMII_DONE
1682  TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1683  TMII_GMII ( MIIM_TYPE, 80,
1684  MFT_SEPARATOR|MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1685  NULL, OK, OK );
1686  TMII_DONE
1687 
1688  TMII_INSMI( MIIM_STRING|MIIM_FTYPE|MIIM_ID, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1689  TMII_GMII ( MIIM_TYPE, 80,
1690  MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1691  NULL, OK, OK );
1692  TMII_DONE
1693  /* test with modifymenu: string is preserved after setting OWNERDRAW */
1694  TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1695  TMII_MODM( MFT_OWNERDRAW, -1, (void*)787 );
1697  MFT_OWNERDRAW, 0, 0, 0, 0, 0, 787, string, 4, 0,
1698  txt, OK, OK );
1699  TMII_DONE
1700  /* same with bitmap: now the text is cleared */
1701  TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1702  TMII_MODM( MFT_BITMAP, 545, hbm );
1704  MFT_BITMAP, 0, 545, 0, 0, 0, 0, string, 0, hbm,
1705  empty, OK, ER );
1706  TMII_DONE
1707  /* start with bitmap: now setting text clears it (though he flag is raised) */
1708  TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1710  MFT_STRING, 0, 0, 0, 0, 0, 0, string, 0, hbm,
1711  empty, OK, ER );
1712  TMII_MODM( MFT_STRING, 545, txt );
1714  MFT_STRING, 0, 545, 0, 0, 0, 0, string, 4, 0,
1715  txt, OK, OK );
1716  TMII_DONE
1717  /*repeat with text NULL */
1718  TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1719  TMII_MODM( MFT_STRING, 545, NULL );
1721  MFT_SEPARATOR, 0, 545, 0, 0, 0, 0, string, 0, 0,
1722  empty, OK, ER );
1723  TMII_DONE
1724  /* repeat with text "" */
1725  TMII_INSMI( MIIM_BITMAP, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1726  TMII_MODM( MFT_STRING, 545, empty );
1728  MFT_STRING, 0, 545, 0, 0, 0, 0, string, 0, 0,
1729  empty, OK, ER );
1730  TMII_DONE
1731  /* start with bitmap: set ownerdraw */
1732  TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1733  TMII_MODM( MFT_OWNERDRAW, -1, (void *)232 );
1735  MFT_OWNERDRAW, 0, 0, 0, 0, 0, 232, string, 0, hbm,
1736  empty, OK, ER );
1737  TMII_DONE
1738  /* ask nothing */
1739  TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1740  TMII_GMII ( 0, 80,
1741  0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1742  init, OK, OK );
1743  TMII_DONE
1744  /* some tests with small cbSize: the hbmpItem is to be ignored */
1745  TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1746  TMII_GMII ( MIIM_TYPE, 80,
1747  MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1748  NULL, OK, ER );
1749  TMII_DONE
1750  TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1752  MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, NULL,
1753  init, OK, ER );
1754  TMII_DONE
1755  TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1756  TMII_GMII ( MIIM_TYPE, 80,
1757  MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, NULL,
1758  txt, OK, OK );
1759  TMII_DONE
1760  TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1761  TMII_GMII ( MIIM_TYPE, 80,
1762  MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1763  NULL, OK, OK );
1764  TMII_DONE
1765  TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1766  TMII_GMII ( MIIM_TYPE, 80,
1767  MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1768  NULL, OK, OK );
1769  TMII_DONE
1770  TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1771  TMII_GMII ( MIIM_TYPE, 80,
1772  MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1773  NULL, OK, OK );
1774  TMII_DONE
1775  /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus */
1776  TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1778  MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1779  NULL, OK, ER );
1780  TMII_DONE
1781  TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1782  TMII_GMII ( MIIM_TYPE, 80,
1783  MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1784  NULL, OK, ER );
1785  TMII_DONE
1786  TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1788  MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1789  NULL, OK, ER );
1790  TMII_DONE
1791  /* set a string menu to ownerdraw with MIIM_TYPE */
1792  TMII_INSMI( MIIM_TYPE, MFT_STRING, -2, -2, 0, 0, 0, -2, txt, -2, 0, OK );
1793  TMII_SMII ( MIIM_TYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1795  MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1796  txt, OK, OK );
1797  TMII_DONE
1798  /* test with modifymenu add submenu */
1799  TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1800  TMII_MODM( MF_POPUP, (UINT_PTR)submenu, txt );
1802  MFT_STRING, 0, 0, submenu, 0, 0, 0, string, 4, 0,
1803  txt, OK, OK );
1804  TMII_GMII ( MIIM_TYPE, 80,
1805  MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1806  txt, OK, OK );
1807  TMII_DONE
1808  /* MFT_SEPARATOR bit is kept when the text is added */
1809  TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1810  TMII_SMII( MIIM_STRING, 0, 0, 0, 0, 0, 0, 0, txt, 0, 0 );
1812  MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, 0,
1813  txt, OK, OK );
1814  TMII_DONE
1815  /* MFT_SEPARATOR bit is kept when bitmap is added */
1816  TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1817  TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm );
1819  MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1820  init, OK, ER );
1821  TMII_DONE
1822  /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1823  Only the low word of the dwTypeData is used.
1824  Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1825  TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1826  (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1827  TMII_GMII ( MIIM_TYPE, 80,
1829  NULL, OK, OK );
1830  TMII_DONE
1831  /* Type flags */
1833  TMII_GMII ( MIIM_TYPE, 80,
1835  NULL, OK, OK );
1836  TMII_DONE
1837  /* State flags */
1838  TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1839  TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1840  TMII_GMII ( MIIM_STATE, 80,
1841  0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1842  NULL, OK, OK );
1843  TMII_DONE
1844  /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1845  TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1846  TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1848  MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1849  NULL, OK, OK );
1850  TMII_DONE
1851  /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1852  TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1853  TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1854  TMII_GMII ( MIIM_FTYPE, 80,
1855  MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1856  NULL, OK, OK );
1857  TMII_GMII ( MIIM_TYPE, 80,
1858  MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1859  NULL, OK, OK );
1860  TMII_GMII ( MIIM_FTYPE, 80,
1861  MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1862  NULL, OK, OK );
1863  TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1864  TMII_GMII ( MIIM_TYPE, 80,
1865  MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1866  NULL, OK, OK );
1867  TMII_DONE
1868  /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1869  Only the low word of the dwTypeData is used.
1870  Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1871  TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1872  (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1873  TMII_GMII ( MIIM_TYPE, 80,
1875  NULL, OK, OK );
1876  TMII_DONE
1877  /* Type flags */
1879  TMII_GMII ( MIIM_TYPE, 80,
1881  NULL, OK, OK );
1882  TMII_DONE
1883  /* State flags */
1884  TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1885  TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1886  TMII_GMII ( MIIM_STATE, 80,
1887  0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1888  NULL, OK, OK );
1889  TMII_DONE
1890  /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1891  TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1892  TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1894  MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1895  NULL, OK, OK );
1896  TMII_DONE
1897  /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1898  TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1899  TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1900  TMII_GMII ( MIIM_FTYPE, 80,
1901  MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1902  NULL, OK, OK );
1903  TMII_GMII ( MIIM_TYPE, 80,
1904  MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1905  NULL, OK, OK );
1906  TMII_GMII ( MIIM_FTYPE, 80,
1907  MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1908  NULL, OK, OK );
1909  TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1910  TMII_GMII ( MIIM_TYPE, 80,
1911  MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1912  NULL, OK, OK );
1913  TMII_DONE
1914  } while( !(ansi = !ansi) );
1915  DeleteObject( hbm);
1916 }
1917 
1918 /*
1919  The following tests try to confirm the algorithm used to return the menu items
1920  when there is a collision between a menu item and a popup menu
1921  */
1922 static void test_menu_search_bycommand( void )
1923 {
1924  HMENU hmenu, hmenuSub, hmenuSub2;
1926  BOOL rc;
1927  UINT id;
1928  char strback[0x80];
1929  char strIn[0x80];
1930  static CHAR menuitem[] = "MenuItem",
1931  menuitem2[] = "MenuItem 2";
1932 
1933  /* Case 1: Menu containing a menu item */
1934  hmenu = CreateMenu();
1935 
1936  memset( &info, 0, sizeof info );
1937  info.cbSize = sizeof info;
1938  info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1939  info.fType = MFT_STRING;
1940  strcpy(strIn, "Case 1 MenuItem");
1941  info.dwTypeData = strIn;
1942  info.wID = (UINT) 0x1234;
1943 
1944  rc = InsertMenuItemA(hmenu, 0, TRUE, &info );
1945  ok (rc, "Inserting the menuitem failed\n");
1946 
1947  id = GetMenuItemID(hmenu, 0);
1948  ok (id == 0x1234, "Getting the menuitem id failed(gave %x)\n", id);
1949 
1950  /* Confirm the menuitem was given the id supplied (getting by position) */
1951  memset( &info, 0, sizeof info );
1952  strback[0] = 0x00;
1953  info.cbSize = sizeof(MENUITEMINFOA);
1954  info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1955  info.dwTypeData = strback;
1956  info.cch = sizeof(strback);
1957 
1958  rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info); /* Get by position */
1959  ok (rc, "Getting the menu items info failed\n");
1960  ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1961  ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1962 
1963  /* Search by id - Should return the item */
1964  memset( &info, 0, sizeof info );
1965  strback[0] = 0x00;
1966  info.cbSize = sizeof(MENUITEMINFOA);
1967  info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1968  info.dwTypeData = strback;
1969  info.cch = sizeof(strback);
1970  rc = GetMenuItemInfoA(hmenu, 0x1234, FALSE, &info); /* Get by ID */
1971 
1972  ok (rc, "Getting the menu items info failed\n");
1973  ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1974  ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1975 
1976  DestroyMenu( hmenu );
1977 
1978  /* Case 2: Menu containing a popup menu */
1979  hmenu = CreateMenu();
1980  hmenuSub = CreateMenu();
1981 
1982  strcpy(strIn, "Case 2 SubMenu");
1983  rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, strIn);
1984  ok (rc, "Inserting the popup menu into the main menu failed\n");
1985 
1986  id = GetMenuItemID(hmenu, 0);
1987  ok (id == -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id);
1988 
1989  /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
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  info.wID = 0xdeadbeef;
1997 
1998  rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info); /* Get by position */
1999  ok (rc, "Getting the menu items info failed\n");
2000  ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the menuitem\n");
2001  ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
2002 
2003  /* Search by id - returns the popup menu itself */
2004  memset( &info, 0, sizeof info );
2005  strback[0] = 0x00;
2006  info.cbSize = sizeof(MENUITEMINFOA);
2007  info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
2008  info.dwTypeData = strback;
2009  info.cch = sizeof(strback);
2010  rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
2011 
2012  ok (rc, "Getting the menu items info failed\n");
2013  ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
2014  ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
2015 
2016  /*
2017  Now add an item after it with the same id
2018  */
2019  memset( &info, 0, sizeof info );
2020  info.cbSize = sizeof info;
2021  info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2022  info.fType = MFT_STRING;
2023  strcpy(strIn, "Case 2 MenuItem 1");
2024  info.dwTypeData = strIn;
2025  info.wID = (UINT_PTR) hmenuSub;
2026  rc = InsertMenuItemA(hmenu, -1, TRUE, &info );
2027  ok (rc, "Inserting the menuitem failed\n");
2028 
2029  /* Search by id - returns the item which follows the popup menu */
2030  memset( &info, 0, sizeof info );
2031  strback[0] = 0x00;
2032  info.cbSize = sizeof(MENUITEMINFOA);
2033  info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
2034  info.dwTypeData = strback;
2035  info.cch = sizeof(strback);
2036  rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
2037 
2038  ok (rc, "Getting the menu items info failed\n");
2039  ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
2040  ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2041 
2042  /*
2043  Now add an item before the popup (with the same id)
2044  */
2045  memset( &info, 0, sizeof info );
2046  info.cbSize = sizeof info;
2047  info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2048  info.fType = MFT_STRING;
2049  strcpy(strIn, "Case 2 MenuItem 2");
2050  info.dwTypeData = strIn;
2051  info.wID = (UINT_PTR) hmenuSub;
2052  rc = InsertMenuItemA(hmenu, 0, TRUE, &info );
2053  ok (rc, "Inserting the menuitem failed\n");
2054 
2055  /* Search by id - returns the item which precedes the popup menu */
2056  memset( &info, 0, sizeof info );
2057  strback[0] = 0x00;
2058  info.cbSize = sizeof(MENUITEMINFOA);
2059  info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
2060  info.dwTypeData = strback;
2061  info.cch = sizeof(strback);
2062  rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
2063 
2064  ok (rc, "Getting the menu items info failed\n");
2065  ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
2066  ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2067 
2068  DestroyMenu( hmenu );
2069  DestroyMenu( hmenuSub );
2070 
2071  /*
2072  Case 3: Menu containing a popup menu which in turn
2073  contains 2 items with the same id as the popup itself
2074  */
2075 
2076  hmenu = CreateMenu();
2077  hmenuSub = CreateMenu();
2078 
2079  memset( &info, 0, sizeof info );
2080  info.cbSize = sizeof info;
2081  info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2082  info.fType = MFT_STRING;
2083  info.dwTypeData = menuitem;
2084  info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2085 
2086  rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
2087  ok (rc, "Inserting the popup menu into the main menu failed\n");
2088 
2089  rc = InsertMenuItemA(hmenuSub, 0, TRUE, &info );
2090  ok (rc, "Inserting the sub menu menuitem failed\n");
2091 
2092  memset( &info, 0, sizeof info );
2093  info.cbSize = sizeof info;
2094  info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2095  info.fType = MFT_STRING;
2096  info.dwTypeData = menuitem2;
2097  info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2098 
2099  rc = InsertMenuItemA(hmenuSub, 1, TRUE, &info );
2100  ok (rc, "Inserting the sub menu menuitem 2 failed\n");
2101 
2102  /* Prove that you can't query the id of a popup directly (By position) */
2103  id = GetMenuItemID(hmenu, 0);
2104  ok (id == -1, "Getting the sub menu id should have failed because it's a popup (gave %x)\n", id);
2105 
2106  /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
2107  memset( &info, 0, sizeof info );
2108  strback[0] = 0x00;
2109  info.cbSize = sizeof(MENUITEMINFOA);
2110  info.fMask = MIIM_STRING | MIIM_ID;
2111  info.dwTypeData = strback;
2112  info.cch = sizeof(strback);
2113 
2114  rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
2115  ok (rc, "Getting the menus info failed\n");
2116  ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
2117  ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2118  DestroyMenu( hmenu );
2119  DestroyMenu( hmenuSub );
2120 
2121  /*
2122  Case 4: Menu containing 2 popup menus, the second
2123  contains 2 items with the same id as the first popup menu
2124  */
2125  hmenu = CreateMenu();
2126  hmenuSub = CreateMenu();
2127  hmenuSub2 = CreateMenu();
2128 
2129  rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
2130  ok (rc, "Inserting the popup menu into the main menu failed\n");
2131 
2132  rc = InsertMenuA(hmenu, 1, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub2, "Submenu2");
2133  ok (rc, "Inserting the popup menu into the main menu failed\n");
2134 
2135  memset( &info, 0, sizeof info );
2136  info.cbSize = sizeof info;
2137  info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2138  info.fType = MFT_STRING;
2139  info.dwTypeData = menuitem;
2140  info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2141 
2142  rc = InsertMenuItemA(hmenuSub2, 0, TRUE, &info );
2143  ok (rc, "Inserting the sub menu menuitem failed\n");
2144 
2145  memset( &info, 0, sizeof info );
2146  info.cbSize = sizeof info;
2147  info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2148  info.fType = MFT_STRING;
2149  info.dwTypeData = menuitem2;
2150  info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2151 
2152  rc = InsertMenuItemA(hmenuSub2, 1, TRUE, &info );
2153  ok (rc, "Inserting the sub menu menuitem 2 failed\n");
2154 
2155  /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
2156  memset( &info, 0, sizeof info );
2157  strback[0] = 0x00;
2158  info.cbSize = sizeof(MENUITEMINFOA);
2159  info.fMask = MIIM_STRING | MIIM_ID;
2160  info.dwTypeData = strback;
2161  info.cch = sizeof(strback);
2162 
2163  rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
2164  ok (rc, "Getting the menus info failed\n");
2165  ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
2166  ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2167 
2168  memset( &info, 0, sizeof info );
2169  strback[0] = 0x00;
2170  info.cbSize = sizeof(MENUITEMINFOA);
2171  info.fMask = MIIM_STRING | MIIM_ID;
2172  info.dwTypeData = strback;
2173  info.cch = sizeof(strback);
2174 
2175  rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub2, FALSE, &info);
2176  ok (rc, "Getting the menus info failed\n");
2177  ok (info.wID == (UINT_PTR)hmenuSub2, "IDs differ for popup menu\n");
2178  ok (!strcmp(info.dwTypeData, "Submenu2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2179 
2180  DestroyMenu( hmenu );
2181  DestroyMenu( hmenuSub );
2182  DestroyMenu( hmenuSub2 );
2183 
2184 
2185  /*
2186  Case 5: Menu containing a popup menu which in turn
2187  contains an item with a different id than the popup menu.
2188  This tests the fallback to a popup menu ID.
2189  */
2190 
2191  hmenu = CreateMenu();
2192  hmenuSub = CreateMenu();
2193 
2194  rc = AppendMenuA(hmenu, MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
2195  ok (rc, "Appending the popup menu to the main menu failed\n");
2196 
2197  rc = AppendMenuA(hmenuSub, MF_STRING, 102, "Item");
2198  ok (rc, "Appending the item to the popup menu failed\n");
2199 
2200  /* Set the ID for hmenuSub */
2201  info.cbSize = sizeof(info);
2202  info.fMask = MIIM_ID;
2203  info.wID = 101;
2204 
2205  rc = SetMenuItemInfoA(hmenu, 0, TRUE, &info);
2206  ok(rc, "Setting the ID for the popup menu failed\n");
2207 
2208  /* Check if the ID has been set */
2209  info.wID = 0;
2210  rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info);
2211  ok(rc, "Getting the ID for the popup menu failed\n");
2212  ok(info.wID == 101, "The ID for the popup menu has not been set\n");
2213 
2214  /* Prove getting the item info via ID returns the popup menu */
2215  memset( &info, 0, sizeof(info));
2216  strback[0] = 0x00;
2217  info.cbSize = sizeof(MENUITEMINFOA);
2218  info.fMask = MIIM_STRING | MIIM_ID;
2219  info.dwTypeData = strback;
2220  info.cch = sizeof(strback);
2221 
2222  rc = GetMenuItemInfoA(hmenu, 101, FALSE, &info);
2223  ok (rc, "Getting the menu info failed\n");
2224  ok (info.wID == 101, "IDs differ\n");
2225  ok (!strcmp(info.dwTypeData, "Submenu"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2226 
2227  /* Also look for the menu item */
2228  memset( &info, 0, sizeof(info));
2229  strback[0] = 0x00;
2230  info.cbSize = sizeof(MENUITEMINFOA);
2231  info.fMask = MIIM_STRING | MIIM_ID;
2232  info.dwTypeData = strback;
2233  info.cch = sizeof(strback);
2234 
2235  rc = GetMenuItemInfoA(hmenu, 102, FALSE, &info);
2236  ok (rc, "Getting the menu info failed\n");
2237  ok (info.wID == 102, "IDs differ\n");
2238  ok (!strcmp(info.dwTypeData, "Item"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2239 
2240  DestroyMenu(hmenu);
2241  DestroyMenu(hmenuSub);
2242 }
2243 
2245  UINT uMenu; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
2246  * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
2247  * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
2249 };
2250 
2251 static struct menu_mouse_tests_s {
2253  struct menu_item_pair_s menu_item_pairs[5]; /* for mousing */
2254  WORD wVk[5]; /* keys */
2257 } menu_tests[] = {
2258  /* for each test, send keys or clicks and check for menu visibility */
2259  { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE }, /* test 0 */
2260  { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
2261  { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
2262  { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2263  { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
2264  { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2265  { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2266  { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, VK_ESCAPE, 0}, FALSE, FALSE },
2267  { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', VK_ESCAPE, 0}, TRUE, FALSE },
2268  { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
2269  { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2270  { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2271  { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2272  { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2273  { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
2274  { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2275  { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
2276  { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2277  { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, TRUE, FALSE },
2278  { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, FALSE, FALSE },
2279 
2280  { INPUT_MOUSE, {{1, 2}, {0}}, {0}, TRUE, TRUE }, /* test 20 */
2281  { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2282  { INPUT_MOUSE, {{1, 0}, {0}}, {0}, TRUE, TRUE },
2283  { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2284  { INPUT_MOUSE, {{1, 0}, {2, 2}, {0}}, {0}, TRUE, TRUE },
2285  { INPUT_MOUSE, {{2, 1}, {0}}, {0}, FALSE, FALSE },
2286  { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
2287  { INPUT_MOUSE, {{3, 0}, {0}}, {0}, FALSE, FALSE },
2288  { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
2289  { INPUT_MOUSE, {{3, 1}, {0}}, {0}, TRUE, TRUE },
2290  { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2291  { -1 }
2292 };
2293 
2294 static void send_key(WORD wVk)
2295 {
2296  TEST_INPUT i[2];
2297  memset(i, 0, sizeof(i));
2298  i[0].type = i[1].type = INPUT_KEYBOARD;
2299  i[0].u.ki.wVk = i[1].u.ki.wVk = wVk;
2300  i[1].u.ki.dwFlags = KEYEVENTF_KEYUP;
2301  pSendInput(2, (INPUT *) i, sizeof(INPUT));
2302 }
2303 
2305 {
2306  HMENU hMenu = hMenus[mi->uMenu];
2307  TEST_INPUT i[3];
2308  MSG msg;
2309  RECT r;
2310  int screen_w = GetSystemMetrics(SM_CXSCREEN);
2311  int screen_h = GetSystemMetrics(SM_CYSCREEN);
2312  BOOL ret = GetMenuItemRect(mi->uMenu > 2 ? NULL : hWnd, hMenu, mi->uItem, &r);
2313  if(!ret) return FALSE;
2314 
2315  memset(i, 0, sizeof(i));
2316  i[0].type = i[1].type = i[2].type = INPUT_MOUSE;
2317  i[0].u.mi.dx = i[1].u.mi.dx = i[2].u.mi.dx
2318  = ((r.left + 5) * 65535) / screen_w;
2319  i[0].u.mi.dy = i[1].u.mi.dy = i[2].u.mi.dy
2320  = ((r.top + 5) * 65535) / screen_h;
2321  i[0].u.mi.dwFlags = i[1].u.mi.dwFlags = i[2].u.mi.dwFlags
2323  i[0].u.mi.dwFlags |= MOUSEEVENTF_MOVE;
2324  i[1].u.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
2325  i[2].u.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
2326  ret = pSendInput(3, (INPUT *) i, sizeof(INPUT));
2327 
2328  /* hack to prevent mouse message buildup in Wine */
2329  while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
2330  return ret;
2331 }
2332 
2334 {
2335  int i, j;
2337 
2338  Sleep(500);
2339  /* mixed keyboard/mouse test */
2340  for (i = 0; menu_tests[i].type != -1; i++)
2341  {
2342  BOOL ret = TRUE;
2343  int elapsed = 0;
2344 
2345  got_input = i && menu_tests[i-1].bMenuVisible;
2346 
2347  if (menu_tests[i].type == INPUT_KEYBOARD)
2348  for (j = 0; menu_tests[i].wVk[j] != 0; j++)
2349  send_key(menu_tests[i].wVk[j]);
2350  else
2351  for (j = 0; menu_tests[i].menu_item_pairs[j].uMenu != 0; j++)
2352  if (!(ret = click_menu(hWnd, &menu_tests[i].menu_item_pairs[j]))) break;
2353 
2354  if (!ret)
2355  {
2356  skip( "test %u: failed to send input\n", i );
2357  PostMessageA( hWnd, WM_CANCELMODE, 0, 0 );
2358  return 0;
2359  }
2361  {
2362  if (elapsed > 200)
2363  break;
2364  elapsed += 20;
2365  Sleep(20);
2366  }
2367 
2368  if (!got_input)
2369  {
2370  skip( "test %u: didn't receive input\n", i );
2371  PostMessageA( hWnd, WM_CANCELMODE, 0, 0 );
2372  return 0;
2373  }
2374 
2375  todo_wine_if (menu_tests[i]._todo_wine)
2376  ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
2377  }
2378  return 0;
2379 }
2380 
2382  LPARAM lParam)
2383 {
2384  switch (msg) {
2385  case WM_ENTERMENULOOP:
2386  bMenuVisible = TRUE;
2387  break;
2388  case WM_INITMENUPOPUP:
2389  case WM_UNINITMENUPOPUP:
2390  case WM_EXITMENULOOP:
2391  case WM_MENUSELECT:
2392  break;
2393 
2394  case WM_KEYDOWN:
2395  case WM_SYSKEYDOWN:
2396  case WM_MOUSEMOVE:
2397  case WM_LBUTTONDOWN:
2398  case WM_LBUTTONUP:
2399  case WM_NCMOUSEMOVE:
2400  case WM_NCLBUTTONDOWN:
2401  case WM_NCLBUTTONUP:
2402  got_input = TRUE;
2403  /* fall through */
2404  default:
2405  return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2406  }
2407 
2408  if(pGetMenuBarInfo)
2409  {
2410  MENUBARINFO mbi;
2411  HMENU hmenu;
2412  UINT state;
2413  BOOL br;
2414 
2415  mbi.cbSize = sizeof(MENUBARINFO);
2416 
2417  /* get info for the menu */
2418  br = pGetMenuBarInfo(hWnd, OBJID_MENU, 0, &mbi);
2419  ok(br, "msg %x: GetMenuBarInfo failed\n", msg);
2420  hmenu = GetMenu(hWnd);
2421  ok(!mbi.hwndMenu, "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected NULL\n",
2422  msg, mbi.hwndMenu);
2423  ok(mbi.hMenu == hmenu, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2424  msg, mbi.hMenu, hmenu);
2425  ok(!bMenuVisible == !mbi.fBarFocused, "msg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2426  msg, mbi.fBarFocused != 0);
2427  ok(!bMenuVisible == !mbi.fFocused, "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n",
2428  msg, mbi.fFocused != 0);
2429 
2430  /* get info for the menu's first item */
2431  br = pGetMenuBarInfo(hWnd, OBJID_MENU, 1, &mbi);
2432  ok(br, "msg %x: GetMenuBarInfo failed\n", msg);
2434  if (pGetMenuInfo) /* Skip on NT */
2435  {
2436  /* Native returns handle to destroyed window */
2437  todo_wine_if (msg==WM_UNINITMENUPOPUP && popmenu==1)
2438  ok(!mbi.hwndMenu == !popmenu,
2439  "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected %sNULL\n",
2440  msg, mbi.hwndMenu, popmenu ? "not " : "");
2441  }
2442  ok(mbi.hMenu == hmenu, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2443  msg, mbi.hMenu, hmenu);
2444  ok(!bMenuVisible == !mbi.fBarFocused, "nsg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2445  msg, mbi.fBarFocused != 0);
2446  ok(!(bMenuVisible && (state & MF_HILITE)) == !mbi.fFocused,
2447  "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n", msg, mbi.fFocused != 0);
2448  }
2449 
2450  if (msg == WM_EXITMENULOOP)
2451  bMenuVisible = FALSE;
2452  else if (msg == WM_INITMENUPOPUP)
2453  popmenu++;
2454  else if (msg == WM_UNINITMENUPOPUP)
2455  popmenu--;
2456  return 0;
2457 }
2458 
2459 static void test_menu_input(void) {
2460  MSG msg;
2461  WNDCLASSA wclass;
2463  HANDLE hThread, hWnd;
2464  DWORD tid;
2465  ATOM aclass;
2466  POINT orig_pos;
2467 
2468  if (!pSendInput)
2469  {
2470  win_skip("SendInput is not available\n");
2471  return;
2472  }
2473 
2474  wclass.lpszClassName = "MenuTestClass";
2475  wclass.style = CS_HREDRAW | CS_VREDRAW;
2476  wclass.lpfnWndProc = WndProc;
2477  wclass.hInstance = hInstance;
2478  wclass.hIcon = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
2479  wclass.hCursor = LoadCursorA( 0, (LPCSTR)IDC_ARROW );
2480  wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2481  wclass.lpszMenuName = 0;
2482  wclass.cbClsExtra = 0;
2483  wclass.cbWndExtra = 0;
2484  aclass = RegisterClassA( &wclass );
2485  ok (aclass, "MenuTest class not created\n");
2486  if (!aclass) return;
2487  hWnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
2489  400, 200, NULL, NULL, hInstance, NULL);
2490  ok (hWnd != NULL, "MenuTest window not created\n");
2491  if (!hWnd) return;
2492  /* fixed menus */
2493  hMenus[3] = CreatePopupMenu();
2494  AppendMenuA(hMenus[3], MF_STRING, 0, "&Enabled");
2495  AppendMenuA(hMenus[3], MF_STRING|MF_DISABLED, 0, "&Disabled");
2496 
2497  hMenus[2] = CreatePopupMenu();
2498  AppendMenuA(hMenus[2], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[3], "&Popup");
2499  AppendMenuA(hMenus[2], MF_STRING, 0, "&Enabled");
2500  AppendMenuA(hMenus[2], MF_STRING|MF_DISABLED, 0, "&Disabled");
2501 
2502  hMenus[1] = CreateMenu();
2503  AppendMenuA(hMenus[1], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[2], "&Menu");
2504  AppendMenuA(hMenus[1], MF_STRING, 0, "&Enabled");
2505  AppendMenuA(hMenus[1], MF_STRING|MF_DISABLED, 0, "&Disabled");
2506 
2507  SetMenu(hWnd, hMenus[1]);
2509  UpdateWindow(hWnd);
2510 
2511  GetCursorPos(&orig_pos);
2512 
2514  while(1)
2515  {
2517  break;
2518  while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2519  }
2520  SetCursorPos(orig_pos.x, orig_pos.y);
2522 }
2523 
2524 static void test_menu_flags( void )
2525 {
2526  HMENU hMenu, hPopupMenu;
2527 
2528  hMenu = CreateMenu();
2529  hPopupMenu = CreatePopupMenu();
2530 
2531  AppendMenuA(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2532 
2533  AppendMenuA(hPopupMenu, MF_STRING | MF_HILITE | MF_DEFAULT, 101, "Item 1");
2534  InsertMenuA(hPopupMenu, 1, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 102, "Item 2");
2535  AppendMenuA(hPopupMenu, MF_STRING, 103, "Item 3");
2536  ModifyMenuA(hPopupMenu, 2, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 103, "Item 3");
2537 
2538  ok(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_HILITE,
2539  "AppendMenu should accept MF_HILITE\n");
2540  ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2541  "InsertMenu should accept MF_HILITE\n");
2542  ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2543  "ModifyMenu should accept MF_HILITE\n");
2544 
2545  ok(!(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_DEFAULT),
2546  "AppendMenu must not accept MF_DEFAULT\n");
2547  ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_DEFAULT),
2548  "InsertMenu must not accept MF_DEFAULT\n");
2549  ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_DEFAULT),
2550  "ModifyMenu must not accept MF_DEFAULT\n");
2551 
2552  DestroyMenu(hMenu);
2553 }
2554 
2555 static void test_menu_hilitemenuitem( void )
2556 {
2557  HMENU hMenu, hPopupMenu;
2558  WNDCLASSA wclass;
2559  HWND hWnd;
2560  ATOM aclass;
2561 
2562  wclass.lpszClassName = "HiliteMenuTestClass";
2563  wclass.style = CS_HREDRAW | CS_VREDRAW;
2564  wclass.lpfnWndProc = WndProc;
2565  wclass.hInstance = GetModuleHandleA( NULL );
2566  wclass.hIcon = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
2567  wclass.hCursor = LoadCursorA( 0, (LPCSTR)IDC_ARROW );
2568  wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2569  wclass.lpszMenuName = 0;
2570  wclass.cbClsExtra = 0;
2571  wclass.cbWndExtra = 0;
2572  aclass = RegisterClassA( &wclass );
2573  ok (aclass, "HiliteMenuTest class could not be created\n");
2574  if (!aclass) return;
2575  hWnd = CreateWindowA( wclass.lpszClassName, "HiliteMenuTest",
2577  400, 200, NULL, NULL, wclass.hInstance, NULL);
2578  ok (hWnd != NULL, "HiliteMenuTest window could not be created\n");
2579  if (!hWnd) return;
2580 
2581  hMenu = CreateMenu();
2582  hPopupMenu = CreatePopupMenu();
2583 
2584  AppendMenuA(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2585 
2586  AppendMenuA(hPopupMenu, MF_STRING, 101, "Item 1");
2587  AppendMenuA(hPopupMenu, MF_STRING, 102, "Item 2");
2588  AppendMenuA(hPopupMenu, MF_STRING, 103, "Item 3");
2589 
2590  SetMenu(hWnd, hMenu);
2591 
2592  /* test invalid arguments */
2593 
2594  ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2595  "HiliteMenuItem: Item 2 is hilited\n");
2596 
2597  SetLastError(0xdeadbeef);
2598  todo_wine
2599  {
2600  ok(!HiliteMenuItem(NULL, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2601  "HiliteMenuItem: call should have failed.\n");
2602  }
2603  ok(GetLastError() == 0xdeadbeef || /* 9x */
2605  "HiliteMenuItem: expected error ERROR_INVALID_WINDOW_HANDLE, got: %d\n", GetLastError());
2606 
2607  SetLastError(0xdeadbeef);
2609  "HiliteMenuItem: call should have failed.\n");
2610  ok(GetLastError() == 0xdeadbeef || /* 9x */
2612  "HiliteMenuItem: expected error ERROR_INVALID_MENU_HANDLE, got: %d\n", GetLastError());
2613 
2614  ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2615  "HiliteMenuItem: Item 2 is hilited\n");
2616 
2617  /* either MF_HILITE or MF_UNHILITE *and* MF_BYCOMMAND or MF_BYPOSITION need to be set */
2618 
2619  SetLastError(0xdeadbeef);
2620  ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_BYPOSITION),
2621  "HiliteMenuItem: call should have succeeded.\n");
2622  ok(GetLastError() == 0xdeadbeef,
2623  "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2624 
2625  ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2626  "HiliteMenuItem: Item 2 is hilited\n");
2627 
2628  SetLastError(0xdeadbeef);
2629  todo_wine
2630  {
2631  ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE),
2632  "HiliteMenuItem: call should have succeeded.\n");
2633  }
2634  ok(GetLastError() == 0xdeadbeef,
2635  "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2636 
2637  ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2638  "HiliteMenuItem: Item 2 is hilited\n");
2639 
2640  /* hilite a menu item (by position) */
2641 
2642  SetLastError(0xdeadbeef);
2643  ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2644  "HiliteMenuItem: call should not have failed.\n");
2645  ok(GetLastError() == 0xdeadbeef,
2646  "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2647 
2648  todo_wine
2649  {
2650  ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2651  "HiliteMenuItem: Item 2 is not hilited\n");
2652  }
2653 
2654  /* unhilite a menu item (by position) */
2655 
2656  SetLastError(0xdeadbeef);
2657  ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_UNHILITE | MF_BYPOSITION),
2658  "HiliteMenuItem: call should not have failed.\n");
2659  ok(GetLastError() == 0xdeadbeef,
2660  "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2661 
2662  ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2663  "HiliteMenuItem: Item 2 is hilited\n");
2664 
2665  /* hilite a menu item (by command) */
2666 
2667  SetLastError(0xdeadbeef);
2668  ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_HILITE | MF_BYCOMMAND),
2669  "HiliteMenuItem: call should not have failed.\n");
2670  ok(GetLastError() == 0xdeadbeef,
2671  "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2672 
2673  todo_wine
2674  {
2675  ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2676  "HiliteMenuItem: Item 3 is not hilited\n");
2677  }
2678 
2679  /* unhilite a menu item (by command) */
2680 
2681  SetLastError(0xdeadbeef);
2682  ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_UNHILITE | MF_BYCOMMAND),
2683  "HiliteMenuItem: call should not have failed.\n");
2684  ok(GetLastError() == 0xdeadbeef,
2685  "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2686 
2687  ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE),
2688  "HiliteMenuItem: Item 3 is hilited\n");
2689 
2691 }
2692 
2693 static void check_menu_items(HMENU hmenu, UINT checked_cmd, UINT checked_type,
2694  UINT checked_state)
2695 {
2696  INT i, count;
2697 
2699  ok (count != -1, "GetMenuItemCount returned -1\n");
2700 
2701  for (i = 0; i < count; i++)
2702  {
2703  BOOL ret;
2704  MENUITEMINFOA mii;
2705 
2706  memset(&mii, 0, sizeof(mii));
2707  mii.cbSize = sizeof(mii);
2709  ret = GetMenuItemInfoA(hmenu, i, TRUE, &mii);
2710  ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2711 
2712  if (winetest_debug > 1)
2713  trace("item #%u: fType %04x, fState %04x, wID %u, hSubMenu %p\n",
2714  i, mii.fType, mii.fState, mii.wID, mii.hSubMenu);
2715 
2716  if (mii.hSubMenu)
2717  {
2718  ok(mii.wID == (UINT_PTR)mii.hSubMenu, "id %u: wID %x should be equal to hSubMenu %p\n",
2719  checked_cmd, mii.wID, mii.hSubMenu);
2720  if (!GetMenuItemCount(mii.hSubMenu))
2721  {
2722  ok(mii.fType == checked_type, "id %u: expected fType %04x, got %04x\n", checked_cmd, checked_type, mii.fType);
2723  ok(mii.fState == checked_state, "id %u: expected fState %04x, got %04x\n", checked_cmd, checked_state, mii.fState);
2724  }
2725  check_menu_items(mii.hSubMenu, checked_cmd, checked_type, checked_state);
2726  }
2727  else
2728  {
2729  if (mii.wID == checked_cmd)
2730  {
2731  ok(mii.fType == checked_type, "id %u: expected fType %04x, got %04x\n", checked_cmd, checked_type, mii.fType);
2732  ok(mii.fState == checked_state, "id %u: expected fState %04x, got %04x\n", checked_cmd, checked_state, mii.fState);
2733  ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2734  }
2735  else
2736  {
2737  ok(mii.fType != MFT_RADIOCHECK, "id %u: not expected fType MFT_RADIOCHECK on cmd %u\n", checked_cmd, mii.wID);
2738 
2739  if (mii.fType == MFT_SEPARATOR)
2740  {
2741  ok(mii.fState == MFS_GRAYED, "id %u: expected fState MFS_GRAYED, got %04x\n", checked_cmd, mii.fState);
2742  ok(mii.wID == 0, "id %u: expected wID 0, got %u\n", checked_cmd, mii.wID);
2743  }
2744  else
2745  {
2746  ok(mii.fState == 0, "id %u: expected fState 0, got %04x\n", checked_cmd, mii.fState);
2747  ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2748  }
2749  }
2750  }
2751  }
2752 }
2753 
2755 {
2756  BOOL ret;
2757  MENUITEMINFOA mii;
2758 
2759  memset(&mii, 0, sizeof(mii));
2760  mii.cbSize = sizeof(mii);
2761  mii.fMask = MIIM_FTYPE | MIIM_STATE;
2762  ret = SetMenuItemInfoA(hmenu, id, (flags & MF_BYPOSITION) != 0, &mii);
2763  ok(ret, "SetMenuItemInfo(%u) failed\n", id);
2764 }
2765 
2766 static void test_CheckMenuRadioItem(void)
2767 {
2768  BOOL ret;
2769  HMENU hmenu;
2770 
2772  assert(hmenu != 0);
2773 
2774  check_menu_items(hmenu, -1, 0, 0);
2775 
2776  ret = CheckMenuRadioItem(hmenu, 100, 100, 100, MF_BYCOMMAND);
2777  ok(ret, "CheckMenuRadioItem failed\n");
2779 
2780  /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2781  ret = CheckMenuRadioItem(hmenu, 100, 100, -1, MF_BYCOMMAND);
2782  ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2784 
2785  /* clear check */
2787  check_menu_items(hmenu, -1, 0, 0);
2788 
2789  /* first and checked items are on different menus */
2790  ret = CheckMenuRadioItem(hmenu, 0, 300, 202, MF_BYCOMMAND);
2791  ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2792  check_menu_items(hmenu, -1, 0, 0);
2793 
2794  ret = CheckMenuRadioItem(hmenu, 200, 300, 202, MF_BYCOMMAND);
2795  ok(ret, "CheckMenuRadioItem failed\n");
2797 
2798  /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2799  ret = CheckMenuRadioItem(hmenu, 202, 202, -1, MF_BYCOMMAND);
2800  ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2802 
2803  /* clear check */
2805  check_menu_items(hmenu, -1, 0, 0);
2806 
2807  /* just for fun, try to check separator */
2808  ret = CheckMenuRadioItem(hmenu, 0, 300, 0, MF_BYCOMMAND);
2809  ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2810  check_menu_items(hmenu, -1, 0, 0);
2811 }
2812 
2813 static void test_menu_resource_layout(void)
2814 {
2815  static const struct
2816  {
2818  WORD data[14];
2819  } menu_template =
2820  {
2821  { 0, 0 }, /* versionNumber, offset */
2822  {
2823  /* mtOption, mtID, mtString[] '\0' terminated */
2824  MF_STRING, 1, 'F', 0,
2825  MF_STRING, 2, 0,
2826  MF_SEPARATOR, 3, 0,
2827  /* MF_SEPARATOR, 4, 'S', 0, FIXME: Wine ignores 'S' */
2828  MF_STRING|MF_GRAYED|MF_END, 5, 'E', 0
2829  }
2830  };
2831  static const struct
2832  {
2833  UINT type, state, id;
2834  const char *str;
2835  } menu_data[] =
2836  {
2837  { MF_STRING, MF_ENABLED, 1, "F" },
2838  { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 2, "" },
2839  { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 3, "" },
2840  /*{ MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 4, "S" }, FIXME: Wine ignores 'S'*/
2841  { MF_STRING, MF_GRAYED, 5, "E" },
2842  { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 6, "" },
2843  { MF_STRING, MF_ENABLED, 7, "" },
2844  { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 8, "" }
2845  };
2846  HMENU hmenu;
2847  INT count, i;
2848  BOOL ret;
2849 
2850  hmenu = LoadMenuIndirectA(&menu_template);
2851  ok(hmenu != 0, "LoadMenuIndirect error %u\n", GetLastError());
2852 
2854  ok(ret, "AppendMenu failed\n");
2855  ret = AppendMenuA(hmenu, MF_STRING, 7, "\0");
2856  ok(ret, "AppendMenu failed\n");
2857  ret = AppendMenuA(hmenu, MF_SEPARATOR, 8, "separator");
2858  ok(ret, "AppendMenu failed\n");
2859 
2861  ok(count == sizeof(menu_data)/sizeof(menu_data[0]),
2862  "expected %u menu items, got %u\n",
2863  (UINT)(sizeof(menu_data)/sizeof(menu_data[0])), count);
2864 
2865  for (i = 0; i < count; i++)
2866  {
2867  char buf[20];
2868  MENUITEMINFOA mii;
2869 
2870  memset(&mii, 0, sizeof(mii));
2871  mii.cbSize = sizeof(mii);
2872  mii.dwTypeData = buf;
2873  mii.cch = sizeof(buf);
2875  ret = GetMenuItemInfoA(hmenu, i, TRUE, &mii);
2876  ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2877  if (winetest_debug > 1)
2878  trace("item #%u: fType %04x, fState %04x, wID %u, dwTypeData %s\n",
2879  i, mii.fType, mii.fState, mii.wID, (LPCSTR)mii.dwTypeData);
2880 
2881  ok(mii.fType == menu_data[i].type,
2882  "%u: expected fType %04x, got %04x\n", i, menu_data[i].type, mii.fType);
2883  ok(mii.fState == menu_data[i].state,
2884  "%u: expected fState %04x, got %04x\n", i, menu_data[i].state, mii.fState);
2885  ok(mii.wID == menu_data[i].id,
2886  "%u: expected wID %04x, got %04x\n", i, menu_data[i].id, mii.wID);
2887  ok(mii.cch == strlen(menu_data[i].str),
2888  "%u: expected cch %u, got %u\n", i, (UINT)strlen(menu_data[i].str), mii.cch);
2889  ok(!strcmp(mii.dwTypeData, menu_data[i].str),
2890  "%u: expected dwTypeData %s, got %s\n", i, menu_data[i].str, (LPCSTR)mii.dwTypeData);
2891  }
2892 
2893  DestroyMenu(hmenu);
2894 }
2895 
2897 {
2899  const char *str;
2900 };
2901 
2902 static HMENU create_menu_from_data(const struct menu_data *item, INT item_count)
2903 {
2904  HMENU hmenu;
2905  INT i;
2906  BOOL ret;
2907 
2908  hmenu = CreateMenu();
2909  assert(hmenu != 0);
2910 
2911  for (i = 0; i < item_count; i++)
2912  {
2913  SetLastError(0xdeadbeef);
2914  ret = AppendMenuA(hmenu, item[i].type, item[i].id, item[i].str);
2915  ok(ret, "%d: AppendMenu(%04x, %04x, %p) error %u\n",
2916  i, item[i].type, item[i].id, item[i].str, GetLastError());
2917  }
2918  return hmenu;
2919 }
2920 
2921 /* use InsertMenuItem: does not set the MFT_BITMAP flag,
2922  * and does not accept non-magic bitmaps with invalid
2923  * bitmap handles */
2924 static HMENU create_menuitem_from_data(const struct menu_data *item, INT item_count)
2925 {
2926  HMENU hmenu;
2927  INT i;
2928  BOOL ret;
2929  MENUITEMINFOA mii = { sizeof( MENUITEMINFOA) };
2930 
2931  hmenu = CreateMenu();
2932  assert(hmenu != 0);
2933 
2934  for (i = 0; i < item_count; i++)
2935  {
2936  SetLastError(0xdeadbeef);
2937 
2938  mii.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STATE;
2939  mii.fType = 0;
2940  if( item[i].type & MFT_BITMAP)
2941  {
2942  mii.fMask |= MIIM_BITMAP;
2943  mii.hbmpItem = (HBITMAP)item[i].str;
2944  }
2945  else if( item[i].type & MFT_SEPARATOR)
2946  mii.fType = MFT_SEPARATOR;
2947  else
2948  {
2949  mii.fMask |= MIIM_STRING;
2950  mii.dwTypeData = (LPSTR)item[i].str;
2951  mii.cch = strlen( item[i].str);
2952  }
2953  mii.fState = 0;
2954  if( item[i].type & MF_HELP) mii.fType |= MF_HELP;
2955  mii.wID = item[i].id;
2956  ret = InsertMenuItemA( hmenu, -1, TRUE, &mii);
2957  ok(ret, "%d: InsertMenuItem(%04x, %04x, %p) error %u\n",
2958  i, item[i].type, item[i].id, item[i].str, GetLastError());
2959  }
2960  return hmenu;
2961 }
2962 
2963 static void compare_menu_data(HMENU hmenu, const struct menu_data *item, INT item_count)
2964 {
2965  INT count, i;
2966  BOOL ret;
2967 
2969  ok(count == item_count, "expected %d, got %d menu items\n", count, item_count);
2970 
2971  for (i = 0; i < count; i++)
2972  {
2973  char buf[20];
2974  MENUITEMINFOA mii;
2975 
2976  memset(&mii, 0, sizeof(mii));
2977  mii.cbSize = sizeof(mii);
2978  mii.dwTypeData = buf;
2979  mii.cch = sizeof(buf);
2981  ret = GetMenuItemInfoA(hmenu, i, TRUE, &mii);
2982  ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2983 
2984  if (winetest_debug > 1)
2985  trace("item #%u: fType %04x, fState %04x, wID %04x, hbmp %p\n",
2986  i, mii.fType, mii.fState, mii.wID, mii.hbmpItem);
2987 
2988  ok(mii.fType == item[i].type,
2989  "%u: expected fType %04x, got %04x\n", i, item[i].type, mii.fType);
2990  ok(mii.wID == item[i].id,
2991  "%u: expected wID %04x, got %04x\n", i, item[i].id, mii.wID);
2992  if (mii.hbmpItem || !item[i].str)
2993  /* For some reason Windows sets high word to not 0 for
2994  * not "magic" ids.
2995  */
2996  ok(LOWORD(mii.hbmpItem) == LOWORD(item[i].str),
2997  "%u: expected hbmpItem %p, got %p\n", i, item[i].str, mii.hbmpItem);
2998  else
2999  {
3000  ok(mii.cch == strlen(item[i].str),
3001  "%u: expected cch %u, got %u\n", i, (UINT)strlen(item[i].str), mii.cch);
3002  ok(!strcmp(mii.dwTypeData, item[i].str),
3003  "%u: expected dwTypeData %s, got %s\n", i, item[i].str, (LPCSTR)mii.dwTypeData);
3004  }
3005  }
3006 }
3007 
3008 static void test_InsertMenu(void)
3009 {
3010  HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
3011  /* Note: XP treats only bitmap handles 1 - 6 as "magic" ones
3012  * regardless of their id.
3013  */
3014  static const struct menu_data in1[] =
3015  {
3016  { MF_STRING, 1, "File" },
3018  { MF_STRING|MF_HELP, 2, "Help" }
3019  };
3020  static const struct menu_data out1[] =
3021  {
3022  { MF_STRING, 1, "File" },
3023  { MF_STRING|MF_HELP, 2, "Help" },
3025  };
3026  static const struct menu_data out1a[] =
3027  {
3028  { MF_STRING, 1, "File" },
3029  { MF_STRING|MF_HELP, 2, "Help" },
3031  };
3032  const struct menu_data in2[] =
3033  {
3034  { MF_STRING, 1, "File" },
3035  { MF_BITMAP|MF_HELP, SC_CLOSE, (char*)hbm },
3036  { MF_STRING|MF_HELP, 2, "Help" }
3037  };
3038  const struct menu_data out2[] =
3039  {
3040  { MF_STRING, 1, "File" },
3041  { MF_BITMAP|MF_HELP, SC_CLOSE, (char*)hbm },
3042  { MF_STRING|MF_HELP, 2, "Help" }
3043  };
3044  const struct menu_data out2a[] =
3045  {
3046  { MF_STRING, 1, "File" },
3047  { MF_HELP, SC_CLOSE, (char*)hbm },
3048  { MF_STRING|MF_HELP, 2, "Help" }
3049  };
3050  static const struct menu_data in3[] =
3051  {
3052  { MF_STRING, 1, "File" },
3054  { MF_STRING|MF_HELP, 2, "Help" }
3055  };
3056  static const struct menu_data out3[] =
3057  {
3058  { MF_STRING, 1, "File" },
3060  { MF_STRING|MF_HELP, 2, "Help" },
3061  };
3062  static const struct menu_data in4[] =
3063  {
3064  { MF_STRING, 1, "File" },
3065  { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCEA(1) },
3066  { MF_STRING|MF_HELP, 2, "Help" }
3067  };
3068  static const struct menu_data out4[] =
3069  {
3070  { MF_STRING, 1, "File" },
3071  { MF_STRING|MF_HELP, 2, "Help" },
3073  };
3074  static const struct menu_data out4a[] =
3075  {
3076  { MF_STRING, 1, "File" },
3077  { MF_STRING|MF_HELP, 2, "Help" },
3078  { MF_HELP, 1, MAKEINTRESOURCEA(1) }
3079  };
3080  HMENU hmenu;
3081 
3082 #define create_menu(a) create_menu_from_data((a), sizeof(a)/sizeof((a)[0]))
3083 #define create_menuitem(a) create_menuitem_from_data((a), sizeof(a)/sizeof((a)[0]))
3084 #define compare_menu(h, a) compare_menu_data((h), (a), sizeof(a)/sizeof((a)[0]))
3085 
3086  hmenu = create_menu(in1);
3087  compare_menu(hmenu, out1);
3088  DestroyMenu(hmenu);
3089 
3090  hmenu = create_menu(in2);
3091  compare_menu(hmenu, out2);
3092  DestroyMenu(hmenu);
3093 
3094  hmenu = create_menu(in3);
3095  compare_menu(hmenu, out3);
3096  DestroyMenu(hmenu);
3097 
3098  hmenu = create_menu(in4);
3099  compare_menu(hmenu, out4);
3100  DestroyMenu(hmenu);
3101 
3102  /* now using InsertMenuItemInfo */
3103  hmenu = create_menuitem(in1);
3104  compare_menu(hmenu, out1a);
3105  DestroyMenu(hmenu);
3106 
3107  hmenu = create_menuitem(in2);
3108  compare_menu(hmenu, out2a);
3109  DestroyMenu(hmenu);
3110 
3111  hmenu = create_menuitem(in3);
3112  compare_menu(hmenu, out3);
3113  DestroyMenu(hmenu);
3114 
3115  hmenu = create_menuitem(in4);
3116  compare_menu(hmenu, out4a);
3117  DestroyMenu(hmenu);
3118 
3119 #undef create_menu
3120 #undef create_menuitem
3121 #undef compare_menu
3122 }
3123 
3124 static void test_menu_getmenuinfo(void)
3125 {
3126  HMENU hmenu;
3127  MENUINFO mi = {0};
3128  BOOL ret;
3129  DWORD gle;
3130 
3131  if (!pGetMenuInfo)
3132  {
3133  win_skip("GetMenuInfo is not available\n");
3134  return;
3135  }
3136 
3137  /* create a menu */
3138  hmenu = CreateMenu();
3139  assert( hmenu);
3140  /* test some parameter errors */
3141  SetLastError(0xdeadbeef);
3142  ret = pGetMenuInfo( hmenu, NULL);
3143  gle= GetLastError();
3144  ok( !ret, "GetMenuInfo() should have failed\n");
3145  ok( gle == ERROR_INVALID_PARAMETER ||
3146  broken(gle == 0xdeadbeef), /* Win98, WinME */
3147  "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
3148  SetLastError(0xdeadbeef);
3149  mi.cbSize = 0;
3150  ret = pGetMenuInfo( hmenu, &mi);
3151  gle= GetLastError();
3152  ok( !ret, "GetMenuInfo() should have failed\n");
3153  ok( gle == ERROR_INVALID_PARAMETER ||
3154  broken(gle == 0xdeadbeef), /* Win98, WinME */
3155  "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
3156  SetLastError(0xdeadbeef);
3157  mi.cbSize = sizeof( MENUINFO);
3158  ret = pGetMenuInfo( hmenu, &mi);
3159  gle= GetLastError();
3160  ok( ret, "GetMenuInfo() should have succeeded\n");
3161  ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3162  SetLastError(0xdeadbeef);
3163  mi.cbSize = 0;
3164  ret = pGetMenuInfo( NULL, &mi);
3165  gle= GetLastError();
3166  ok( !ret, "GetMenuInfo() should have failed\n");
3167  ok( gle == ERROR_INVALID_PARAMETER ||
3168  broken(gle == 0xdeadbeef), /* Win98, WinME */
3169  "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
3170  /* clean up */
3171  DestroyMenu( hmenu);
3172  return;
3173 }
3174 
3175 static void test_menu_setmenuinfo(void)
3176 {
3177  HMENU hmenu, hsubmenu;
3178  MENUINFO mi = {0};
3179  MENUITEMINFOA mii = { sizeof(MENUITEMINFOA) };
3180  BOOL ret;
3181  DWORD gle;
3182  HBRUSH brush;
3183 
3184  if (!pGetMenuInfo || !pSetMenuInfo)
3185  {
3186  win_skip("Get/SetMenuInfo are not available\n");
3187  return;
3188  }
3189 
3190  /* create a menu with a submenu */
3191  hmenu = CreateMenu();
3192  hsubmenu = CreateMenu();
3193  assert( hmenu && hsubmenu);
3194  mii.fMask = MIIM_SUBMENU;
3195  mii.hSubMenu = hsubmenu;
3196  ret = InsertMenuItemA( hmenu, 0, FALSE, &mii);
3197  ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
3198  /* test some parameter errors */
3199  SetLastError(0xdeadbeef);
3200  ret = pSetMenuInfo( hmenu, NULL);
3201  gle= GetLastError();
3202  ok( !ret, "SetMenuInfo() should have failed\n");
3203  ok( gle == ERROR_INVALID_PARAMETER ||
3204  broken(gle == 0xdeadbeef), /* Win98, WinME */
3205  "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
3206  SetLastError(0xdeadbeef);
3207  mi.cbSize = 0;
3208  ret = pSetMenuInfo( hmenu, &mi);
3209  gle= GetLastError();
3210  ok( !ret, "SetMenuInfo() should have failed\n");
3211  ok( gle == ERROR_INVALID_PARAMETER ||
3212  broken(gle == 0xdeadbeef), /* Win98, WinME */
3213  "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
3214  SetLastError(0xdeadbeef);
3215  mi.cbSize = sizeof( MENUINFO);
3216  ret = pSetMenuInfo( hmenu, &mi);
3217  gle= GetLastError();
3218  ok( ret, "SetMenuInfo() should have succeeded\n");
3219  ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
3220  SetLastError(0xdeadbeef);
3221  mi.cbSize = 0;
3222  ret = pSetMenuInfo( NULL, &mi);
3223  gle= GetLastError();
3224  ok( !ret, "SetMenuInfo() should have failed\n");
3225  ok( gle == ERROR_INVALID_PARAMETER ||
3226  broken(gle == 0xdeadbeef), /* Win98, WinME */
3227  "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
3228  /* functional tests */
3229  /* menu and submenu should have the CHECKORBMP style bit cleared */
3230  SetLastError(0xdeadbeef);
3231  mi.cbSize = sizeof( MENUINFO);
3232  mi.fMask = MIM_STYLE;
3233  ret = pGetMenuInfo( hmenu, &mi);
3234  gle= GetLastError();
3235  ok( ret, "GetMenuInfo() should have succeeded\n");
3236  ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3237  ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
3238  SetLastError(0xdeadbeef);
3239  mi.cbSize = sizeof( MENUINFO);
3240  mi.fMask = MIM_STYLE;
3241  ret = pGetMenuInfo( hsubmenu, &mi);
3242  gle= GetLastError();
3243  ok( ret, "GetMenuInfo() should have succeeded\n");
3244  ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3245  ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
3246  /* SetMenuInfo() */
3247  SetLastError(0xdeadbeef);
3248  mi.cbSize = sizeof( MENUINFO);
3249  mi.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS;
3250  mi.dwStyle = MNS_CHECKORBMP;
3251  ret = pSetMenuInfo( hmenu, &mi);
3252  gle= GetLastError();
3253  ok( ret, "SetMenuInfo() should have succeeded\n");
3254  ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
3255  /* Now both menus should have the MNS_CHECKORBMP style bit set */
3256  SetLastError(0xdeadbeef);
3257  mi.cbSize = sizeof( MENUINFO);
3258  mi.fMask = MIM_STYLE;
3259  ret = pGetMenuInfo( hmenu, &mi);
3260  gle= GetLastError();
3261  ok( ret, "GetMenuInfo() should have succeeded\n");
3262  ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3263  ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
3264  SetLastError(0xdeadbeef);
3265  mi.cbSize = sizeof( MENUINFO);
3266  mi.fMask = MIM_STYLE;
3267  ret = pGetMenuInfo( hsubmenu, &mi);
3268  gle= GetLastError();
3269  ok( ret, "GetMenuInfo() should have succeeded\n");
3270  ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3271  ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
3272  /* now repeat that without the APPLYTOSUBMENUS flag and another style bit */
3273  SetLastError(0xdeadbeef);
3274  mi.cbSize = sizeof( MENUINFO);
3275  mi.fMask = MIM_STYLE ;
3276  mi.dwStyle = MNS_NOCHECK;
3277  ret = pSetMenuInfo( hmenu, &mi);
3278  gle= GetLastError();
3279  ok( ret,