1c2c66affSColin Finck /*
2c2c66affSColin Finck  * Unit tests for menus
3c2c66affSColin Finck  *
4c2c66affSColin Finck  * Copyright 2005 Robert Shearman
5c2c66affSColin Finck  * Copyright 2007 Dmitry Timoshkov
6c2c66affSColin Finck  *
7c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
8c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
9c2c66affSColin Finck  * License as published by the Free Software Foundation; either
10c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
11c2c66affSColin Finck  *
12c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
13c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15c2c66affSColin Finck  * Lesser General Public License for more details.
16c2c66affSColin Finck  *
17c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
18c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
19c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20c2c66affSColin Finck  */
21c2c66affSColin Finck 
22d558fc75SAmine Khaldi #include <stdarg.h>
23d558fc75SAmine Khaldi #include <stdio.h>
24d558fc75SAmine Khaldi #include <string.h>
25d558fc75SAmine Khaldi #include <assert.h>
26d558fc75SAmine Khaldi 
27d558fc75SAmine Khaldi #define OEMRESOURCE         /* For OBM_MNARROW */
28d558fc75SAmine Khaldi 
29d558fc75SAmine Khaldi #include "windef.h"
30d558fc75SAmine Khaldi #include "winbase.h"
31d558fc75SAmine Khaldi #include "wingdi.h"
32d558fc75SAmine Khaldi #include "winuser.h"
33d558fc75SAmine Khaldi 
34d558fc75SAmine Khaldi #include "wine/test.h"
35c2c66affSColin Finck 
36c2c66affSColin Finck static ATOM atomMenuCheckClass;
37c2c66affSColin Finck 
menu_check_wnd_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)38c2c66affSColin Finck static LRESULT WINAPI menu_check_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
39c2c66affSColin Finck {
40c2c66affSColin Finck     switch (msg)
41c2c66affSColin Finck     {
42c2c66affSColin Finck     case WM_ENTERMENULOOP:
43c2c66affSColin Finck         /* mark window as having entered menu loop */
44c2c66affSColin Finck         SetWindowLongPtrA(hwnd, GWLP_USERDATA, TRUE);
45c2c66affSColin Finck         /* exit menu modal loop
46c2c66affSColin Finck          * ( A SendMessage does not work on NT3.51 here ) */
47c2c66affSColin Finck         return PostMessageA(hwnd, WM_CANCELMODE, 0, 0);
48c2c66affSColin Finck     }
49c2c66affSColin Finck     return DefWindowProcA(hwnd, msg, wparam, lparam);
50c2c66affSColin Finck }
51c2c66affSColin Finck 
52c2c66affSColin Finck /* The MSVC headers ignore our NONAMELESSUNION requests so we have to define
53c2c66affSColin Finck  * our own type */
54c2c66affSColin Finck typedef struct
55c2c66affSColin Finck {
56c2c66affSColin Finck     DWORD type;
57c2c66affSColin Finck     union
58c2c66affSColin Finck     {
59c2c66affSColin Finck         MOUSEINPUT      mi;
60c2c66affSColin Finck         KEYBDINPUT      ki;
61c2c66affSColin Finck         HARDWAREINPUT   hi;
62c2c66affSColin Finck     } u;
63c2c66affSColin Finck } TEST_INPUT;
64c2c66affSColin Finck 
65c2c66affSColin Finck /* globals to communicate between test and wndproc */
66c2c66affSColin Finck 
67c2c66affSColin Finck static BOOL bMenuVisible;
68c2c66affSColin Finck static INT popmenu;
69c2c66affSColin Finck static BOOL got_input;
70c2c66affSColin Finck static HMENU hMenus[4];
71c2c66affSColin Finck 
72c2c66affSColin Finck #define MOD_SIZE 10
73c2c66affSColin Finck #define MOD_NRMENUS 8
74c2c66affSColin Finck 
75c2c66affSColin Finck  /* menu texts with their sizes */
76c2c66affSColin Finck static struct {
77c2c66affSColin Finck     LPCSTR text;
78c2c66affSColin Finck     SIZE size; /* size of text up to any \t */
79c2c66affSColin Finck     SIZE sc_size; /* size of the short-cut */
80c2c66affSColin Finck } MOD_txtsizes[] = {
81c2c66affSColin Finck         { "Pinot &Noir" },
82c2c66affSColin Finck         { "&Merlot\bF4" },
83c2c66affSColin Finck         { "Shira&z\tAlt+S" },
84c2c66affSColin Finck         { "" },
85c2c66affSColin Finck         { NULL }
86c2c66affSColin Finck };
87c2c66affSColin Finck 
88c2c66affSColin Finck static unsigned int MOD_maxid;
89c2c66affSColin Finck static RECT MOD_rc[MOD_NRMENUS];
90c2c66affSColin Finck static int MOD_avec, MOD_hic;
91c2c66affSColin Finck static int MOD_odheight;
92c2c66affSColin Finck static SIZE MODsizes[MOD_NRMENUS]= { {MOD_SIZE, MOD_SIZE},{MOD_SIZE, MOD_SIZE},
93c2c66affSColin Finck     {MOD_SIZE, MOD_SIZE},{MOD_SIZE, MOD_SIZE}};
94c2c66affSColin Finck static BOOL MOD_GotDrawItemMsg = FALSE;
95c2c66affSColin Finck static int  gflag_initmenupopup,
96c2c66affSColin Finck             gflag_entermenuloop,
97c2c66affSColin Finck             gflag_initmenu,
98c2c66affSColin Finck             gflag_enteridle;
99c2c66affSColin Finck static WPARAM selectitem_wp;
100c2c66affSColin Finck static LPARAM selectitem_lp;
101c2c66affSColin Finck 
102c2c66affSColin Finck /* wndproc used by test_menu_ownerdraw() */
menu_ownerdraw_wnd_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)103c2c66affSColin Finck static LRESULT WINAPI menu_ownerdraw_wnd_proc(HWND hwnd, UINT msg,
104c2c66affSColin Finck         WPARAM wparam, LPARAM lparam)
105c2c66affSColin Finck {
106c2c66affSColin Finck     static HMENU hmenupopup;
107c2c66affSColin Finck     switch (msg)
108c2c66affSColin Finck     {
109c2c66affSColin Finck         case WM_INITMENUPOPUP:
110c2c66affSColin Finck             gflag_initmenupopup++;
111c2c66affSColin Finck             hmenupopup = (HMENU) wparam;
112c2c66affSColin Finck             break;
113c2c66affSColin Finck         case WM_ENTERMENULOOP:
114c2c66affSColin Finck             gflag_entermenuloop++;
115c2c66affSColin Finck             break;
116c2c66affSColin Finck         case WM_INITMENU:
117c2c66affSColin Finck             gflag_initmenu++;
118c2c66affSColin Finck             break;
119c2c66affSColin Finck         case WM_MEASUREITEM:
120c2c66affSColin Finck             {
121c2c66affSColin Finck                 MEASUREITEMSTRUCT* pmis = (MEASUREITEMSTRUCT*)lparam;
122c2c66affSColin Finck                 if (winetest_debug > 1)
123c2c66affSColin Finck                     trace("WM_MEASUREITEM received data %lx size %dx%d\n",
124c2c66affSColin Finck                             pmis->itemData, pmis->itemWidth, pmis->itemHeight);
125c2c66affSColin Finck                 ok( !wparam, "wrong wparam %lx\n", wparam );
126c2c66affSColin Finck                 ok( pmis->CtlType == ODT_MENU, "wrong type %x\n", pmis->CtlType );
127c2c66affSColin Finck                 MOD_odheight = pmis->itemHeight;
128c2c66affSColin Finck                 pmis->itemWidth = MODsizes[pmis->itemData].cx;
129c2c66affSColin Finck                 pmis->itemHeight = MODsizes[pmis->itemData].cy;
130c2c66affSColin Finck                 return TRUE;
131c2c66affSColin Finck             }
132c2c66affSColin Finck         case WM_DRAWITEM:
133c2c66affSColin Finck             {
134c2c66affSColin Finck                 DRAWITEMSTRUCT * pdis;
135c2c66affSColin Finck                 TEXTMETRICA tm;
136c2c66affSColin Finck                 HPEN oldpen;
137c2c66affSColin Finck                 char chrs[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
138c2c66affSColin Finck                 SIZE sz;
139c2c66affSColin Finck                 int i;
140c2c66affSColin Finck                 pdis = (DRAWITEMSTRUCT *) lparam;
141c2c66affSColin Finck                 if (winetest_debug > 1) {
142c2c66affSColin Finck                     RECT rc;
143c2c66affSColin Finck                     GetMenuItemRect( hwnd, (HMENU)pdis->hwndItem, pdis->itemData ,&rc);
144c2c66affSColin Finck                     trace("WM_DRAWITEM received hwnd %p hmenu %p itemdata %ld item %d rc %s itemrc:  %s\n",
145c2c66affSColin Finck                             hwnd, pdis->hwndItem, pdis->itemData, pdis->itemID,
146c2c66affSColin Finck                             wine_dbgstr_rect(&pdis->rcItem), wine_dbgstr_rect(&rc));
147c2c66affSColin Finck                     oldpen=SelectObject( pdis->hDC, GetStockObject(
148c2c66affSColin Finck                                 pdis->itemState & ODS_SELECTED ? WHITE_PEN :BLACK_PEN));
149c2c66affSColin Finck                     Rectangle( pdis->hDC, pdis->rcItem.left,pdis->rcItem.top,
150c2c66affSColin Finck                             pdis->rcItem.right,pdis->rcItem.bottom );
151c2c66affSColin Finck                     SelectObject( pdis->hDC, oldpen);
152c2c66affSColin Finck                 }
153c2c66affSColin Finck                 ok( !wparam, "wrong wparam %lx\n", wparam );
154c2c66affSColin Finck                 ok( pdis->CtlType == ODT_MENU, "wrong type %x\n", pdis->CtlType );
155c2c66affSColin Finck                 /* calculate widths of some menu texts */
156c2c66affSColin Finck                 if( ! MOD_txtsizes[0].size.cx)
157c2c66affSColin Finck                     for(i = 0; MOD_txtsizes[i].text; i++) {
158c2c66affSColin Finck                         char buf[100], *p;
159c2c66affSColin Finck                         RECT rc={0,0,0,0};
160c2c66affSColin Finck                         strcpy( buf, MOD_txtsizes[i].text);
161c2c66affSColin Finck                         if( ( p = strchr( buf, '\t'))) {
162c2c66affSColin Finck                             *p = '\0';
163c2c66affSColin Finck                             DrawTextA( pdis->hDC, p + 1, -1, &rc,
164c2c66affSColin Finck                                     DT_SINGLELINE|DT_CALCRECT);
165c2c66affSColin Finck                             MOD_txtsizes[i].sc_size.cx= rc.right - rc.left;
166c2c66affSColin Finck                             MOD_txtsizes[i].sc_size.cy= rc.bottom - rc.top;
167c2c66affSColin Finck                         }
168c2c66affSColin Finck                         DrawTextA( pdis->hDC, buf, -1, &rc,
169c2c66affSColin Finck                                 DT_SINGLELINE|DT_CALCRECT);
170c2c66affSColin Finck                         MOD_txtsizes[i].size.cx= rc.right - rc.left;
171c2c66affSColin Finck                         MOD_txtsizes[i].size.cy= rc.bottom - rc.top;
172c2c66affSColin Finck                     }
173c2c66affSColin Finck 
174c2c66affSColin Finck                 if( pdis->itemData > MOD_maxid) return TRUE;
175c2c66affSColin Finck                 /* store the rectangle */
176c2c66affSColin Finck                 MOD_rc[pdis->itemData] = pdis->rcItem;
177c2c66affSColin Finck                 /* calculate average character width */
178c2c66affSColin Finck                 GetTextExtentPointA( pdis->hDC, chrs, 52, &sz );
179c2c66affSColin Finck                 MOD_avec = (sz.cx + 26)/52;
180c2c66affSColin Finck                 GetTextMetricsA( pdis->hDC, &tm);
181c2c66affSColin Finck                 MOD_hic = tm.tmHeight;
182c2c66affSColin Finck                 MOD_GotDrawItemMsg = TRUE;
183c2c66affSColin Finck                 return TRUE;
184c2c66affSColin Finck             }
185c2c66affSColin Finck         case WM_ENTERIDLE:
186c2c66affSColin Finck             {
187c2c66affSColin Finck                 gflag_enteridle++;
188c2c66affSColin Finck                 ok( lparam || broken(!lparam), /* win9x, nt4 */
189c2c66affSColin Finck                     "Menu window handle is NULL!\n");
190c2c66affSColin Finck                 if( lparam) {
191c2c66affSColin Finck                     HMENU hmenu = (HMENU)SendMessageA( (HWND)lparam, MN_GETHMENU, 0, 0);
192c2c66affSColin Finck                     ok( hmenupopup == hmenu, "MN_GETHMENU returns %p expected %p\n",
193c2c66affSColin Finck                         hmenu, hmenupopup);
194c2c66affSColin Finck                 }
195c2c66affSColin Finck                 PostMessageA(hwnd, WM_CANCELMODE, 0, 0);
196c2c66affSColin Finck                 return TRUE;
197c2c66affSColin Finck             }
198c2c66affSColin Finck         case WM_MENUSELECT:
199c2c66affSColin Finck             selectitem_wp = wparam;
200c2c66affSColin Finck             selectitem_lp = lparam;
201c2c66affSColin Finck             break;
202c2c66affSColin Finck     }
203c2c66affSColin Finck     return DefWindowProcA(hwnd, msg, wparam, lparam);
204c2c66affSColin Finck }
205c2c66affSColin Finck 
register_menu_check_class(void)206c2c66affSColin Finck static void register_menu_check_class(void)
207c2c66affSColin Finck {
208c2c66affSColin Finck     WNDCLASSA wc =
209c2c66affSColin Finck     {
210c2c66affSColin Finck         0,
211c2c66affSColin Finck         menu_check_wnd_proc,
212c2c66affSColin Finck         0,
213c2c66affSColin Finck         0,
214c2c66affSColin Finck         GetModuleHandleA(NULL),
215c2c66affSColin Finck         NULL,
216c2c66affSColin Finck         LoadCursorA(NULL, (LPCSTR)IDC_ARROW),
217c2c66affSColin Finck         (HBRUSH)(COLOR_BTNFACE+1),
218c2c66affSColin Finck         NULL,
219c2c66affSColin Finck         "WineMenuCheck",
220c2c66affSColin Finck     };
221c2c66affSColin Finck 
222c2c66affSColin Finck     atomMenuCheckClass = RegisterClassA(&wc);
223c2c66affSColin Finck }
224c2c66affSColin Finck 
test_getmenubarinfo(void)225c2c66affSColin Finck static void test_getmenubarinfo(void)
226c2c66affSColin Finck {
227c2c66affSColin Finck     BOOL ret;
228c2c66affSColin Finck     HMENU hmenu;
229c2c66affSColin Finck     MENUBARINFO mbi;
230c2c66affSColin Finck     RECT rcw, rci;
231c2c66affSColin Finck     HWND hwnd;
232c2c66affSColin Finck     INT err;
233c2c66affSColin Finck 
234c2c66affSColin Finck     mbi.cbSize = sizeof(MENUBARINFO);
235c2c66affSColin Finck 
236c2c66affSColin Finck     hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
237c2c66affSColin Finck             WS_SYSMENU | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
238c2c66affSColin Finck             NULL, NULL, NULL, NULL);
239c2c66affSColin Finck     ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
240c2c66affSColin Finck 
241c2c66affSColin Finck     /* no menu: getmenubarinfo should fail */
242c2c66affSColin Finck     SetLastError(0xdeadbeef);
243*7a62c32bSAmine Khaldi     ret = GetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
244c2c66affSColin Finck     err = GetLastError();
245c2c66affSColin Finck     ok(ret == FALSE, "GetMenuBarInfo should not have been successful\n");
246c2c66affSColin Finck     ok(err == 0xdeadbeef, "err = %d\n", err);
247c2c66affSColin Finck 
248c2c66affSColin Finck     /* create menubar, no items yet */
249c2c66affSColin Finck     hmenu = CreateMenu();
250c2c66affSColin Finck     ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
251c2c66affSColin Finck 
252c2c66affSColin Finck     ret = SetMenu(hwnd, hmenu);
253c2c66affSColin Finck     ok(ret, "SetMenu failed with error %d\n", GetLastError());
254c2c66affSColin Finck 
255c2c66affSColin Finck     SetLastError(0xdeadbeef);
256*7a62c32bSAmine Khaldi     ret = GetMenuBarInfo(NULL, OBJID_CLIENT, 0, &mbi);
257c2c66affSColin Finck     err = GetLastError();
258c2c66affSColin Finck     ok(!ret, "GetMenuBarInfo succeeded\n");
259c2c66affSColin Finck     ok(err == ERROR_INVALID_WINDOW_HANDLE, "err = %d\n", err);
260c2c66affSColin Finck 
261c2c66affSColin Finck     SetLastError(0xdeadbeef);
262*7a62c32bSAmine Khaldi     ret = GetMenuBarInfo(hwnd, OBJID_CLIENT, 0, &mbi);
263c2c66affSColin Finck     err = GetLastError();
264c2c66affSColin Finck     ok(!ret, "GetMenuBarInfo succeeded\n");
265c2c66affSColin Finck     ok(err==ERROR_INVALID_MENU_HANDLE || broken(err==0xdeadbeef) /* NT, W2K, XP */, "err = %d\n", err);
266c2c66affSColin Finck 
267c2c66affSColin Finck     SetLastError(0xdeadbeef);
268*7a62c32bSAmine Khaldi     ret = GetMenuBarInfo(hwnd, OBJID_MENU, -1, &mbi);
269c2c66affSColin Finck     err = GetLastError();
270c2c66affSColin Finck     ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
271c2c66affSColin Finck     ok(err == 0xdeadbeef, "err = %d\n", err);
272c2c66affSColin Finck 
273c2c66affSColin Finck     mbi.cbSize = 1000;
274c2c66affSColin Finck     SetLastError(0xdeadbeef);
275*7a62c32bSAmine Khaldi     ret = GetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
276c2c66affSColin Finck     err = GetLastError();
277c2c66affSColin Finck     ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
278c2c66affSColin Finck     ok(err == ERROR_INVALID_PARAMETER, "err = %d\n", err);
279c2c66affSColin Finck     mbi.cbSize = sizeof(MENUBARINFO);
280c2c66affSColin Finck 
281c2c66affSColin Finck     SetLastError(0xdeadbeef);
282*7a62c32bSAmine Khaldi     ret = GetMenuBarInfo(hwnd, 123, 0, &mbi);
283c2c66affSColin Finck     err = GetLastError();
284c2c66affSColin Finck     ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
285c2c66affSColin Finck     ok(err == 0xdeadbeef, "err = %d\n", err);
286c2c66affSColin Finck 
287*7a62c32bSAmine Khaldi     ret = GetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
288c2c66affSColin Finck     ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
289c2c66affSColin Finck 
290c2c66affSColin Finck     ok(mbi.rcBar.left == 0 && mbi.rcBar.top == 0 && mbi.rcBar.bottom == 0 && mbi.rcBar.right == 0,
291c2c66affSColin Finck             "rcBar: Expected (0,0)-(0,0), got: %s\n", wine_dbgstr_rect(&mbi.rcBar));
292c2c66affSColin Finck     ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n",
293c2c66affSColin Finck             mbi.hMenu, hmenu);
294c2c66affSColin Finck     ok(mbi.fBarFocused == 0, "fBarFocused: Got %d instead of 0.\n", mbi.fBarFocused);
295c2c66affSColin Finck     ok(mbi.fFocused == 0, "fFocused: Got %d instead of 0.\n", mbi.fFocused);
296c2c66affSColin Finck 
297c2c66affSColin Finck     /* add some items */
298c2c66affSColin Finck     ret = AppendMenuA(hmenu, MF_STRING , 100, "item 1");
299c2c66affSColin Finck     ok(ret, "AppendMenu failed.\n");
300c2c66affSColin Finck     ret = AppendMenuA(hmenu, MF_STRING , 101, "item 2");
301c2c66affSColin Finck     ok(ret, "AppendMenu failed.\n");
302c2c66affSColin Finck     ret = SetMenu(hwnd, hmenu);
303c2c66affSColin Finck     ok(ret, "SetMenu failed with error %d\n", GetLastError());
304c2c66affSColin Finck 
305c2c66affSColin Finck     SetLastError(0xdeadbeef);
306*7a62c32bSAmine Khaldi     ret = GetMenuBarInfo(hwnd, OBJID_MENU, 200, &mbi);
307c2c66affSColin Finck     err = GetLastError();
308c2c66affSColin Finck     ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
309c2c66affSColin Finck     ok(err == 0xdeadbeef, "err = %d\n", err);
310c2c66affSColin Finck 
311c2c66affSColin Finck     /* get info for the whole menu */
312*7a62c32bSAmine Khaldi     ret = GetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
313c2c66affSColin Finck     ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
314c2c66affSColin Finck 
315c2c66affSColin Finck     /* calculate menu rectangle, from window rectangle and the position of the first item  */
316c2c66affSColin Finck     ret = GetWindowRect(hwnd, &rcw);
317c2c66affSColin Finck     ok(ret, "GetWindowRect failed.\n");
318c2c66affSColin Finck     ret = GetMenuItemRect(hwnd, hmenu, 0, &rci);
319c2c66affSColin Finck     ok(ret, "GetMenuItemRect failed.\n");
320c2c66affSColin Finck     todo_wine ok(mbi.rcBar.left == rci.left && mbi.rcBar.top == rci.top &&
321c2c66affSColin Finck             mbi.rcBar.bottom == rci.bottom && mbi.rcBar.right == rcw.right - rci.left + rcw.left,
322c2c66affSColin Finck             "rcBar: Got %s instead of (%d,%d)-(%d,%d)\n", wine_dbgstr_rect(&mbi.rcBar),
323c2c66affSColin Finck             rci.left, rci.top, rcw.right - rci.left + rcw.left, rci.bottom);
324c2c66affSColin Finck     ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n", mbi.hMenu, hmenu);
325c2c66affSColin Finck     ok(mbi.fBarFocused == 0, "fBarFocused: got %d instead of 0\n", mbi.fBarFocused);
326c2c66affSColin Finck     ok(mbi.fFocused == 0, "fFocused: got %d instead of 0\n", mbi.fFocused);
327c2c66affSColin Finck 
328c2c66affSColin Finck     /* get info for item nr.2 */
329*7a62c32bSAmine Khaldi     ret = GetMenuBarInfo(hwnd, OBJID_MENU, 2, &mbi);
330c2c66affSColin Finck     ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
331c2c66affSColin Finck     ret = GetMenuItemRect(hwnd, hmenu, 1, &rci);
332c2c66affSColin Finck     ok(ret, "GetMenuItemRect failed.\n");
333c2c66affSColin Finck     ok(EqualRect(&mbi.rcBar, &rci), "rcBar: Got %s instead of %s\n", wine_dbgstr_rect(&mbi.rcBar),
334c2c66affSColin Finck             wine_dbgstr_rect(&rci));
335c2c66affSColin Finck     ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n", mbi.hMenu, hmenu);
336c2c66affSColin Finck     ok(mbi.fBarFocused == 0, "fBarFocused: got %d instead of 0\n", mbi.fBarFocused);
337c2c66affSColin Finck     ok(mbi.fFocused == 0, "fFocused: got %d instead of 0\n", mbi.fFocused);
338c2c66affSColin Finck 
339c2c66affSColin Finck     DestroyWindow(hwnd);
340c2c66affSColin Finck }
341c2c66affSColin Finck 
test_GetMenuItemRect(void)342*7a62c32bSAmine Khaldi static void test_GetMenuItemRect(void)
343*7a62c32bSAmine Khaldi {
344*7a62c32bSAmine Khaldi     HWND hwnd;
345*7a62c32bSAmine Khaldi     HMENU hmenu;
346*7a62c32bSAmine Khaldi     HMENU popup_hmenu;
347*7a62c32bSAmine Khaldi     RECT window_rect;
348*7a62c32bSAmine Khaldi     RECT item_rect;
349*7a62c32bSAmine Khaldi     POINT client_top_left;
350*7a62c32bSAmine Khaldi     INT caption_height;
351*7a62c32bSAmine Khaldi     BOOL ret;
352*7a62c32bSAmine Khaldi 
353*7a62c32bSAmine Khaldi     hwnd = CreateWindowW((LPCWSTR)MAKEINTATOM(atomMenuCheckClass), NULL, WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, NULL,
354*7a62c32bSAmine Khaldi                          NULL, NULL, NULL);
355*7a62c32bSAmine Khaldi     ok(hwnd != NULL, "CreateWindow failed with error %d\n", GetLastError());
356*7a62c32bSAmine Khaldi     hmenu = CreateMenu();
357*7a62c32bSAmine Khaldi     ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
358*7a62c32bSAmine Khaldi     popup_hmenu = CreatePopupMenu();
359*7a62c32bSAmine Khaldi     ok(popup_hmenu != NULL, "CreatePopupMenu failed with error %d\n", GetLastError());
360*7a62c32bSAmine Khaldi     ret = AppendMenuA(popup_hmenu, MF_STRING, 0, "Popup");
361*7a62c32bSAmine Khaldi     ok(ret, "AppendMenu failed with error %d\n", GetLastError());
362*7a62c32bSAmine Khaldi     ret = AppendMenuA(hmenu, MF_STRING | MF_POPUP, (UINT_PTR)popup_hmenu, "Menu");
363*7a62c32bSAmine Khaldi     ok(ret, "AppendMenu failed with error %d\n", GetLastError());
364*7a62c32bSAmine Khaldi     ret = SetMenu(hwnd, hmenu);
365*7a62c32bSAmine Khaldi     ok(ret, "SetMenu failed with error %d\n", GetLastError());
366*7a62c32bSAmine Khaldi 
367*7a62c32bSAmine Khaldi     /* Get the menu item rectangle of the displayed sysmenu item */
368*7a62c32bSAmine Khaldi     ret = GetMenuItemRect(hwnd, hmenu, 0, &item_rect);
369*7a62c32bSAmine Khaldi     ok(ret, "GetMenuItemRect failed with error %d\n", GetLastError());
370*7a62c32bSAmine Khaldi     GetWindowRect(hwnd, &window_rect);
371*7a62c32bSAmine Khaldi     /* Get the screen coordinate of the left top corner of the client rectangle */
372*7a62c32bSAmine Khaldi     client_top_left.x = 0;
373*7a62c32bSAmine Khaldi     client_top_left.y = 0;
374*7a62c32bSAmine Khaldi     MapWindowPoints(hwnd, 0, &client_top_left, 1);
375*7a62c32bSAmine Khaldi     caption_height = GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION);
376*7a62c32bSAmine Khaldi 
377*7a62c32bSAmine Khaldi     ok(item_rect.left == client_top_left.x, "Expect item_rect.left %d == %d\n", item_rect.left, client_top_left.x);
378*7a62c32bSAmine Khaldi     ok(item_rect.right <= window_rect.right, "Expect item_rect.right %d <= %d\n", item_rect.right, window_rect.right);
379*7a62c32bSAmine Khaldi     /* A gap of 1 pixel is added deliberately in commit 75f9e64, so using equal operator would fail on Wine.
380*7a62c32bSAmine Khaldi      * Check that top and bottom are correct with 1 pixel margin tolerance */
381*7a62c32bSAmine Khaldi     ok(item_rect.top - (window_rect.top + caption_height) <= 1, "Expect item_rect.top %d - %d <= 1\n", item_rect.top,
382*7a62c32bSAmine Khaldi        window_rect.top + caption_height);
383*7a62c32bSAmine Khaldi     ok(item_rect.bottom - (client_top_left.y - 1) <= 1, "Expect item_rect.bottom %d - %d <= 1\n", item_rect.bottom,
384*7a62c32bSAmine Khaldi        client_top_left.y - 1);
385*7a62c32bSAmine Khaldi 
386*7a62c32bSAmine Khaldi     /* Get the item rectangle of the not yet displayed popup menu item. */
387*7a62c32bSAmine Khaldi     ret = GetMenuItemRect(hwnd, popup_hmenu, 0, &item_rect);
388*7a62c32bSAmine Khaldi     ok(ret, "GetMenuItemRect failed with error %d\n", GetLastError());
389*7a62c32bSAmine Khaldi     ok(item_rect.left == client_top_left.x, "Expect item_rect.left %d == %d\n", item_rect.left, client_top_left.x);
390*7a62c32bSAmine Khaldi     ok(item_rect.right == client_top_left.x, "Expect item_rect.right %d == %d\n", item_rect.right, client_top_left.x);
391*7a62c32bSAmine Khaldi     ok(item_rect.top == client_top_left.y, "Expect item_rect.top %d == %d\n", item_rect.top, client_top_left.y);
392*7a62c32bSAmine Khaldi     ok(item_rect.bottom == client_top_left.y, "Expect item_rect.bottom %d == %d\n", item_rect.bottom,
393*7a62c32bSAmine Khaldi        client_top_left.y);
394*7a62c32bSAmine Khaldi 
395*7a62c32bSAmine Khaldi     DestroyWindow(hwnd);
396*7a62c32bSAmine Khaldi }
397*7a62c32bSAmine Khaldi 
test_system_menu(void)398c2c66affSColin Finck static void test_system_menu(void)
399c2c66affSColin Finck {
400c2c66affSColin Finck     WCHAR testW[] = {'t','e','s','t',0};
401c2c66affSColin Finck     BOOL ret;
402c2c66affSColin Finck     HMENU menu;
403c2c66affSColin Finck     HWND hwnd;
404c2c66affSColin Finck     MENUITEMINFOA info;
405c2c66affSColin Finck     MENUITEMINFOW infoW;
406c2c66affSColin Finck     char buffer[80];
407c2c66affSColin Finck     char found[0x200];
408c2c66affSColin Finck     int i, res;
409c2c66affSColin Finck 
410c2c66affSColin Finck     hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
411c2c66affSColin Finck                            WS_SYSMENU | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
412c2c66affSColin Finck                            NULL, NULL, NULL, NULL);
413c2c66affSColin Finck     ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
414c2c66affSColin Finck     menu = GetSystemMenu( hwnd, FALSE );
415c2c66affSColin Finck     ok( menu != NULL, "no system menu\n" );
416c2c66affSColin Finck 
417c2c66affSColin Finck     for (i = 0xf000; i < 0xf200; i++)
418c2c66affSColin Finck     {
419c2c66affSColin Finck         memset( &info, 0xcc, sizeof(info) );
420c2c66affSColin Finck         info.cbSize = sizeof(info);
421c2c66affSColin Finck         info.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID;
422c2c66affSColin Finck         info.dwTypeData = buffer;
423c2c66affSColin Finck         info.cch = sizeof( buffer );
424c2c66affSColin Finck         ret = GetMenuItemInfoA( menu, i, FALSE, &info );
425c2c66affSColin Finck         if (ret) trace( "found %x: '%s'\n", i, buffer );
426c2c66affSColin Finck         switch (i)
427c2c66affSColin Finck         {
428c2c66affSColin Finck         case SC_RESTORE:
429c2c66affSColin Finck         case SC_SIZE:
430c2c66affSColin Finck         case SC_MOVE:
431c2c66affSColin Finck         case SC_MINIMIZE:
432c2c66affSColin Finck         case SC_MAXIMIZE:
433c2c66affSColin Finck         case SC_CLOSE:
434c2c66affSColin Finck             ok( ret, "%x menu item not found\n", i );
435c2c66affSColin Finck             break;
436c2c66affSColin Finck         case SC_SCREENSAVE+1:  /* used for the 'About Wine' entry, don't test */
437c2c66affSColin Finck             break;
438c2c66affSColin Finck         default:
439c2c66affSColin Finck             ok( !ret, "%x menu item found\n", i );
440c2c66affSColin Finck             break;
441c2c66affSColin Finck         }
442c2c66affSColin Finck         found[i - 0xf000] = ret;
443c2c66affSColin Finck     }
444c2c66affSColin Finck 
445c2c66affSColin Finck     for (i = 0xf000; i < 0xf200; i++)
446c2c66affSColin Finck     {
447c2c66affSColin Finck         res = CheckMenuItem( menu, i, 0 );
448c2c66affSColin Finck         if (res == -1) ok( !found[i - 0xf000], "could not check existent item %x\n", i );
449c2c66affSColin Finck         else ok( found[i - 0xf000], "could check non-existent item %x\n", i );
450c2c66affSColin Finck 
451c2c66affSColin Finck         res = EnableMenuItem( menu, i, 0 );
452c2c66affSColin Finck         if (res == -1) ok( !found[i - 0xf000], "could not enable existent item %x\n", i );
453c2c66affSColin Finck         else ok( found[i - 0xf000], "could enable non-existent item %x\n", i );
454c2c66affSColin Finck 
455c2c66affSColin Finck         res = GetMenuState( menu, i, 0 );
456c2c66affSColin Finck         if (res == -1) ok( !found[i - 0xf000], "could not get state existent item %x\n", i );
457c2c66affSColin Finck         else ok( found[i - 0xf000], "could get state of non-existent item %x\n", i );
458c2c66affSColin Finck 
459c2c66affSColin Finck         if (!found[i - 0xf000])  /* don't remove the existing ones */
460c2c66affSColin Finck         {
461c2c66affSColin Finck             ret = RemoveMenu( menu, i, 0 );
462c2c66affSColin Finck             ok( !ret, "could remove non-existent item %x\n", i );
463c2c66affSColin Finck         }
464c2c66affSColin Finck 
465c2c66affSColin Finck         ret = ModifyMenuA( menu, i, 0, i, "test" );
466c2c66affSColin Finck         if (i == SC_TASKLIST) ok( ret, "failed to modify SC_TASKLIST\n" );
467c2c66affSColin Finck         else if (!ret) ok( !found[i - 0xf000], "could not modify existent item %x\n", i );
468c2c66affSColin Finck         else ok( found[i - 0xf000], "could modify non-existent item %x\n", i );
469c2c66affSColin Finck 
470c2c66affSColin Finck         ret = ModifyMenuW( menu, i, 0, i, testW );
471c2c66affSColin Finck         if (i == SC_TASKLIST) ok( ret, "failed to modify SC_TASKLIST\n" );
472c2c66affSColin Finck         else if (!ret) ok( !found[i - 0xf000], "could not modify existent item %x\n", i );
473c2c66affSColin Finck         else ok( found[i - 0xf000], "could modify non-existent item %x\n", i );
474c2c66affSColin Finck 
475c2c66affSColin Finck         ret = ModifyMenuA( menu, i, MF_BYPOSITION, i, "test" );
476c2c66affSColin Finck         ok( !ret, "could modify non-existent item %x\n", i );
477c2c66affSColin Finck 
478c2c66affSColin Finck         strcpy( buffer, "test" );
479c2c66affSColin Finck         memset( &info, 0xcc, sizeof(info) );
480c2c66affSColin Finck         info.cbSize = sizeof(info);
481c2c66affSColin Finck         info.fMask = MIIM_STRING | MIIM_ID;
482c2c66affSColin Finck         info.wID = i;
483c2c66affSColin Finck         info.dwTypeData = buffer;
484c2c66affSColin Finck         info.cch = strlen( buffer );
485c2c66affSColin Finck         ret = SetMenuItemInfoA( menu, i, FALSE, &info );
486c2c66affSColin Finck         if (i == SC_TASKLIST) ok( ret, "failed to set SC_TASKLIST\n" );
487c2c66affSColin Finck         else if (!ret) ok( !found[i - 0xf000], "could not set existent item %x\n", i );
488c2c66affSColin Finck         else ok( found[i - 0xf000], "could set non-existent item %x\n", i );
489c2c66affSColin Finck         ret = SetMenuItemInfoA( menu, i, TRUE, &info );
490c2c66affSColin Finck         ok( !ret, "could modify non-existent item %x\n", i );
491c2c66affSColin Finck 
492c2c66affSColin Finck         memset( &infoW, 0xcc, sizeof(infoW) );
493c2c66affSColin Finck         infoW.cbSize = sizeof(infoW);
494c2c66affSColin Finck         infoW.fMask = MIIM_STRING | MIIM_ID;
495c2c66affSColin Finck         infoW.wID = i;
496c2c66affSColin Finck         infoW.dwTypeData = testW;
497c2c66affSColin Finck         infoW.cch = lstrlenW( testW );
498c2c66affSColin Finck         ret = SetMenuItemInfoW( menu, i, FALSE, &infoW );
499c2c66affSColin Finck         if (i == SC_TASKLIST) ok( ret, "failed to set SC_TASKLIST\n" );
500c2c66affSColin Finck         else if (!ret) ok( !found[i - 0xf000], "could not set existent item %x\n", i );
501c2c66affSColin Finck         else ok( found[i - 0xf000], "could set non-existent item %x\n", i );
502c2c66affSColin Finck         ret = SetMenuItemInfoW( menu, i, TRUE, &infoW );
503c2c66affSColin Finck         ok( !ret, "could modify non-existent item %x\n", i );
504c2c66affSColin Finck     }
505c2c66affSColin Finck 
506c2c66affSColin Finck     /* confirm that SC_TASKLIST still does not exist */
507c2c66affSColin Finck     for (i = 0xf000; i < 0xf200; i++)
508c2c66affSColin Finck     {
509c2c66affSColin Finck         memset( &info, 0xcc, sizeof(info) );
510c2c66affSColin Finck         info.cbSize = sizeof(info);
511c2c66affSColin Finck         info.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID;
512c2c66affSColin Finck         info.dwTypeData = buffer;
513c2c66affSColin Finck         info.cch = sizeof( buffer );
514c2c66affSColin Finck         ret = GetMenuItemInfoA( menu, i, FALSE, &info );
515c2c66affSColin Finck         switch (i)
516c2c66affSColin Finck         {
517c2c66affSColin Finck         case SC_RESTORE:
518c2c66affSColin Finck         case SC_SIZE:
519c2c66affSColin Finck         case SC_MOVE:
520c2c66affSColin Finck         case SC_MINIMIZE:
521c2c66affSColin Finck         case SC_MAXIMIZE:
522c2c66affSColin Finck         case SC_CLOSE:
523c2c66affSColin Finck             ok( ret, "%x menu item not found\n", i );
524c2c66affSColin Finck             break;
525c2c66affSColin Finck         case SC_SCREENSAVE+1:  /* used for the 'About Wine' entry, don't test */
526c2c66affSColin Finck             break;
527c2c66affSColin Finck         default:
528c2c66affSColin Finck             ok( !ret, "%x menu item found\n", i );
529c2c66affSColin Finck             break;
530c2c66affSColin Finck         }
531c2c66affSColin Finck     }
532c2c66affSColin Finck 
533c2c66affSColin Finck     /* now a normal (non-system) menu */
534c2c66affSColin Finck 
535c2c66affSColin Finck     menu = CreateMenu();
536c2c66affSColin Finck     ok( menu != NULL, "CreateMenu failed with error %d\n", GetLastError() );
537c2c66affSColin Finck 
538c2c66affSColin Finck     res = CheckMenuItem( menu, SC_TASKLIST, 0 );
539c2c66affSColin Finck     ok( res == -1, "CheckMenuItem succeeded\n" );
540c2c66affSColin Finck     res = EnableMenuItem( menu, SC_TASKLIST, 0 );
541c2c66affSColin Finck     ok( res == -1, "EnableMenuItem succeeded\n" );
542c2c66affSColin Finck     res = GetMenuState( menu, SC_TASKLIST, 0 );
543c2c66affSColin Finck     ok( res == -1, "GetMenuState succeeded\n" );
544c2c66affSColin Finck     ret = RemoveMenu( menu, SC_TASKLIST, 0 );
545c2c66affSColin Finck     ok( !ret, "RemoveMenu succeeded\n" );
546c2c66affSColin Finck     ret = ModifyMenuA( menu, SC_TASKLIST, 0, SC_TASKLIST, "test" );
547c2c66affSColin Finck     ok( ret, "ModifyMenuA failed err %d\n", GetLastError() );
548c2c66affSColin Finck     ret = ModifyMenuW( menu, SC_TASKLIST, 0, SC_TASKLIST, testW );
549c2c66affSColin Finck     ok( ret, "ModifyMenuW failed err %d\n", GetLastError() );
550c2c66affSColin Finck     ret = ModifyMenuA( menu, SC_TASKLIST-1, 0, SC_TASKLIST, "test" );
551c2c66affSColin Finck     ok( !ret, "ModifyMenu succeeded on SC_TASKLIST-1\n" );
552c2c66affSColin Finck     strcpy( buffer, "test" );
553c2c66affSColin Finck     memset( &info, 0xcc, sizeof(info) );
554c2c66affSColin Finck     info.cbSize = sizeof(info);
555c2c66affSColin Finck     info.fMask = MIIM_STRING | MIIM_ID;
556c2c66affSColin Finck     info.wID = SC_TASKLIST;
557c2c66affSColin Finck     info.dwTypeData = buffer;
558c2c66affSColin Finck     info.cch = strlen( buffer );
559c2c66affSColin Finck     ret = SetMenuItemInfoA( menu, SC_TASKLIST, FALSE, &info );
560c2c66affSColin Finck     ok( ret, "failed to set SC_TASKLIST\n" );
561c2c66affSColin Finck     ret = SetMenuItemInfoA( menu, SC_TASKLIST+1, FALSE, &info );
562c2c66affSColin Finck     ok( !ret, "succeeded setting SC_TASKLIST+1\n" );
563c2c66affSColin Finck     ret = SetMenuItemInfoA( menu, SC_TASKLIST, TRUE, &info );
564c2c66affSColin Finck     ok( !ret, "succeeded setting by position\n" );
565c2c66affSColin Finck 
566c2c66affSColin Finck     memset( &infoW, 0xcc, sizeof(infoW) );
567c2c66affSColin Finck     infoW.cbSize = sizeof(infoW);
568c2c66affSColin Finck     infoW.fMask = MIIM_STRING | MIIM_ID;
569c2c66affSColin Finck     infoW.wID = SC_TASKLIST;
570c2c66affSColin Finck     infoW.dwTypeData = testW;
571c2c66affSColin Finck     infoW.cch = lstrlenW( testW );
572c2c66affSColin Finck     ret = SetMenuItemInfoW( menu, SC_TASKLIST, FALSE, &infoW );
573c2c66affSColin Finck     ok( ret, "failed to set SC_TASKLIST\n" );
574c2c66affSColin Finck     ret = SetMenuItemInfoW( menu, SC_TASKLIST+1, FALSE, &infoW );
575c2c66affSColin Finck     ok( !ret, "succeeded setting SC_TASKLIST+1\n" );
576c2c66affSColin Finck     ret = SetMenuItemInfoW( menu, SC_TASKLIST, TRUE, &infoW );
577c2c66affSColin Finck     ok( !ret, "succeeded setting by position\n" );
578c2c66affSColin Finck 
579c2c66affSColin Finck     DestroyMenu( menu );
580c2c66affSColin Finck     DestroyWindow( hwnd );
581c2c66affSColin Finck }
582c2c66affSColin Finck 
583c2c66affSColin Finck /* demonstrates that windows locks the menu object so that it is still valid
584c2c66affSColin Finck  * even after a client calls DestroyMenu on it */
test_menu_locked_by_window(void)585c2c66affSColin Finck static void test_menu_locked_by_window(void)
586c2c66affSColin Finck {
587c2c66affSColin Finck     BOOL ret;
588c2c66affSColin Finck     HMENU hmenu;
589c2c66affSColin Finck     HWND hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
590c2c66affSColin Finck                                WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
591c2c66affSColin Finck                                NULL, NULL, NULL, NULL);
592c2c66affSColin Finck     ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
593c2c66affSColin Finck     hmenu = CreateMenu();
594c2c66affSColin Finck     ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
595c2c66affSColin Finck     ret = InsertMenuA(hmenu, 0, MF_STRING, 0, "&Test");
596c2c66affSColin Finck     ok(ret, "InsertMenu failed with error %d\n", GetLastError());
597c2c66affSColin Finck     ret = SetMenu(hwnd, hmenu);
598c2c66affSColin Finck     ok(ret, "SetMenu failed with error %d\n", GetLastError());
599c2c66affSColin Finck     ret = DestroyMenu(hmenu);
600c2c66affSColin Finck     ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
601c2c66affSColin Finck 
602c2c66affSColin Finck     ret = DrawMenuBar(hwnd);
603c2c66affSColin Finck     ok(ret, "DrawMenuBar failed with error %d\n", GetLastError());
604c2c66affSColin Finck     ret = IsMenu(GetMenu(hwnd));
605c2c66affSColin Finck     ok(!ret || broken(ret) /* nt4 */, "Menu handle should have been destroyed\n");
606c2c66affSColin Finck 
607c2c66affSColin Finck     SendMessageA(hwnd, WM_SYSCOMMAND, SC_KEYMENU, 0);
608c2c66affSColin Finck     /* did we process the WM_INITMENU message? */
609c2c66affSColin Finck     ret = GetWindowLongPtrA(hwnd, GWLP_USERDATA);
610c2c66affSColin Finck     todo_wine {
611c2c66affSColin Finck     ok(ret, "WM_INITMENU should have been sent\n");
612c2c66affSColin Finck     }
613c2c66affSColin Finck 
614c2c66affSColin Finck     DestroyWindow(hwnd);
615c2c66affSColin Finck }
616c2c66affSColin Finck 
617c2c66affSColin Finck /* demonstrates that subpopup's are locked
618c2c66affSColin Finck  * even after a client calls DestroyMenu on it */
subpopuplocked_wnd_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)619c2c66affSColin Finck static LRESULT WINAPI subpopuplocked_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
620c2c66affSColin Finck {
621c2c66affSColin Finck     HWND hwndmenu;
622c2c66affSColin Finck     switch (msg)
623c2c66affSColin Finck     {
624c2c66affSColin Finck     case WM_ENTERIDLE:
625c2c66affSColin Finck         hwndmenu = GetCapture();
626c2c66affSColin Finck         if( hwndmenu) {
627c2c66affSColin Finck             PostMessageA( hwndmenu, WM_KEYDOWN, VK_DOWN, 0);
628c2c66affSColin Finck             PostMessageA( hwndmenu, WM_KEYDOWN, VK_RIGHT, 0);
629c2c66affSColin Finck             PostMessageA( hwndmenu, WM_KEYDOWN, VK_RETURN, 0);
630c2c66affSColin Finck         }
631c2c66affSColin Finck     }
632c2c66affSColin Finck     return DefWindowProcA(hwnd, msg, wparam, lparam);
633c2c66affSColin Finck }
634c2c66affSColin Finck 
test_subpopup_locked_by_menu(void)635c2c66affSColin Finck static void test_subpopup_locked_by_menu(void)
636c2c66affSColin Finck {
637c2c66affSColin Finck     BOOL ret;
638c2c66affSColin Finck     HMENU hmenu, hsubmenu;
639c2c66affSColin Finck     MENUINFO mi = { sizeof( MENUINFO)};
640c2c66affSColin Finck     MENUITEMINFOA mii = { sizeof( MENUITEMINFOA)};
641c2c66affSColin Finck     HWND hwnd;
642c2c66affSColin Finck     const int itemid = 0x1234567;
643*7a62c32bSAmine Khaldi 
644c2c66affSColin Finck     /* create window, popupmenu with one subpopup */
645c2c66affSColin Finck     hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
646c2c66affSColin Finck             WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
647c2c66affSColin Finck             NULL, NULL, NULL, NULL);
648c2c66affSColin Finck     ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
649c2c66affSColin Finck     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR) subpopuplocked_wnd_proc);
650c2c66affSColin Finck     hmenu = CreatePopupMenu();
651c2c66affSColin Finck     ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
652c2c66affSColin Finck     hsubmenu = CreatePopupMenu();
653c2c66affSColin Finck     ok(hsubmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
654c2c66affSColin Finck     ret = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hsubmenu,
655c2c66affSColin Finck             "PopUpLockTest");
656c2c66affSColin Finck     ok(ret, "InsertMenu failed with error %d\n", GetLastError());
657c2c66affSColin Finck     ret = InsertMenuA(hsubmenu, 0, MF_BYPOSITION | MF_STRING, itemid, "PopUpMenu");
658c2c66affSColin Finck     ok(ret, "InsertMenu failed with error %d\n", GetLastError());
659c2c66affSColin Finck     /* first some tests that all this functions properly */
660c2c66affSColin Finck     mii.fMask = MIIM_SUBMENU;
661c2c66affSColin Finck     ret = GetMenuItemInfoA( hmenu, 0, TRUE, &mii);
662c2c66affSColin Finck     ok( ret, "GetMenuItemInfo failed error %d\n", GetLastError());
663c2c66affSColin Finck     ok( mii.hSubMenu == hsubmenu, "submenu is %p\n", mii.hSubMenu);
664c2c66affSColin Finck     mi.fMask |= MIM_STYLE;
665*7a62c32bSAmine Khaldi     ret = GetMenuInfo( hsubmenu, &mi);
666c2c66affSColin Finck     ok( ret , "GetMenuInfo returned 0 with error %d\n", GetLastError());
667c2c66affSColin Finck     ret = IsMenu( hsubmenu);
668c2c66affSColin Finck     ok( ret , "Menu handle is not valid\n");
669*7a62c32bSAmine Khaldi 
670c2c66affSColin Finck     ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
671*7a62c32bSAmine Khaldi     ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, GetLastError());
672*7a62c32bSAmine Khaldi 
673c2c66affSColin Finck     /* then destroy the sub-popup */
674c2c66affSColin Finck     ret = DestroyMenu( hsubmenu);
675c2c66affSColin Finck     ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
676c2c66affSColin Finck     /* and repeat the tests */
677c2c66affSColin Finck     mii.fMask = MIIM_SUBMENU;
678c2c66affSColin Finck     ret = GetMenuItemInfoA( hmenu, 0, TRUE, &mii);
679c2c66affSColin Finck     ok( ret, "GetMenuItemInfo failed error %d\n", GetLastError());
680c2c66affSColin Finck     /* GetMenuInfo fails now */
681c2c66affSColin Finck     ok( mii.hSubMenu == hsubmenu, "submenu is %p\n", mii.hSubMenu);
682c2c66affSColin Finck     mi.fMask |= MIM_STYLE;
683*7a62c32bSAmine Khaldi     ret = GetMenuInfo( hsubmenu, &mi);
684c2c66affSColin Finck     ok( !ret , "GetMenuInfo should have failed\n");
685c2c66affSColin Finck     /* IsMenu says it is not */
686c2c66affSColin Finck     ret = IsMenu( hsubmenu);
687c2c66affSColin Finck     ok( !ret , "Menu handle should be invalid\n");
688*7a62c32bSAmine Khaldi 
689c2c66affSColin Finck     /* but TrackPopupMenu still works! */
690c2c66affSColin Finck     ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
691c2c66affSColin Finck     todo_wine {
692*7a62c32bSAmine Khaldi         ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, GetLastError());
693c2c66affSColin Finck     }
694*7a62c32bSAmine Khaldi 
695c2c66affSColin Finck     /* clean up */
696c2c66affSColin Finck     DestroyMenu( hmenu);
697c2c66affSColin Finck     DestroyWindow(hwnd);
698c2c66affSColin Finck }
699c2c66affSColin Finck 
test_menu_ownerdraw(void)700c2c66affSColin Finck static void test_menu_ownerdraw(void)
701c2c66affSColin Finck {
702c2c66affSColin Finck     int i,j,k;
703c2c66affSColin Finck     BOOL ret;
704c2c66affSColin Finck     HMENU hmenu;
705c2c66affSColin Finck     MENUITEMINFOA mii;
706c2c66affSColin Finck     LONG leftcol;
707c2c66affSColin Finck     HWND hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
708c2c66affSColin Finck                                WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
709c2c66affSColin Finck                                NULL, NULL, NULL, NULL);
710c2c66affSColin Finck     ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
711c2c66affSColin Finck     if( !hwnd) return;
712c2c66affSColin Finck     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
713c2c66affSColin Finck     hmenu = CreatePopupMenu();
714c2c66affSColin Finck     ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
715c2c66affSColin Finck     if( !hmenu) { DestroyWindow(hwnd);return;}
716c2c66affSColin Finck     k=0;
717c2c66affSColin Finck     for( j=0;j<2;j++) /* create columns */
718c2c66affSColin Finck         for(i=0;i<2;i++) { /* create rows */
719c2c66affSColin Finck             ret = AppendMenuA( hmenu, MF_OWNERDRAW |
720c2c66affSColin Finck                               (i==0 ? MF_MENUBREAK : 0), k, (LPCSTR)MAKEINTRESOURCE(k));
721c2c66affSColin Finck             k++;
722c2c66affSColin Finck             ok( ret, "AppendMenu failed for %d\n", k-1);
723c2c66affSColin Finck         }
724c2c66affSColin Finck     MOD_maxid = k-1;
725*7a62c32bSAmine Khaldi     assert( k <= ARRAY_SIZE(MOD_rc));
726c2c66affSColin Finck     /* display the menu */
727c2c66affSColin Finck     TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
728c2c66affSColin Finck 
729c2c66affSColin Finck     /* columns have a 4 pixel gap between them */
730c2c66affSColin Finck     ok( MOD_rc[0].right + 4 ==  MOD_rc[2].left,
731c2c66affSColin Finck             "item rectangles are not separated by 4 pixels space\n");
732c2c66affSColin Finck     /* height should be what the MEASUREITEM message has returned */
733c2c66affSColin Finck     ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
734c2c66affSColin Finck             "menu item has wrong height: %d should be %d\n",
735c2c66affSColin Finck             MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
736c2c66affSColin Finck     /* no gaps between the rows */
737c2c66affSColin Finck     ok( MOD_rc[0].bottom - MOD_rc[1].top == 0,
738c2c66affSColin Finck             "There should not be a space between the rows, gap is %d\n",
739c2c66affSColin Finck             MOD_rc[0].bottom - MOD_rc[1].top);
740c2c66affSColin Finck     /* test the correct value of the item height that was sent
741c2c66affSColin Finck      * by the WM_MEASUREITEM message */
742c2c66affSColin Finck     ok( MOD_odheight == HIWORD( GetDialogBaseUnits()) || /* WinNT,2k,XP */
743c2c66affSColin Finck             MOD_odheight == MOD_hic,                     /* Win95,98,ME */
744c2c66affSColin Finck             "Wrong height field in MEASUREITEMSTRUCT, expected %d or %d actual %d\n",
745c2c66affSColin Finck             HIWORD( GetDialogBaseUnits()), MOD_hic, MOD_odheight);
746c2c66affSColin Finck     /* test what MF_MENUBREAK did at the first position. Also show
747c2c66affSColin Finck      * that an MF_SEPARATOR is ignored in the height calculation. */
748c2c66affSColin Finck     leftcol= MOD_rc[0].left;
749c2c66affSColin Finck     ModifyMenuA( hmenu, 0, MF_BYCOMMAND| MF_OWNERDRAW| MF_SEPARATOR, 0, 0);
750c2c66affSColin Finck     /* display the menu */
751c2c66affSColin Finck     TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
752c2c66affSColin Finck     /* left should be 4 pixels less now */
753c2c66affSColin Finck     ok( leftcol == MOD_rc[0].left + 4,
754c2c66affSColin Finck             "columns should be 4 pixels to the left (actual %d).\n",
755c2c66affSColin Finck             leftcol - MOD_rc[0].left);
756c2c66affSColin Finck     /* test width */
757c2c66affSColin Finck     ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
758c2c66affSColin Finck             "width of owner drawn menu item is wrong. Got %d expected %d\n",
759c2c66affSColin Finck             MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
760c2c66affSColin Finck     /* and height */
761c2c66affSColin Finck     ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
762c2c66affSColin Finck             "Height is incorrect. Got %d expected %d\n",
763c2c66affSColin Finck             MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
764c2c66affSColin Finck 
765c2c66affSColin Finck     /* test owner-drawn callback bitmap */
766c2c66affSColin Finck     ModifyMenuA( hmenu, 1, MF_BYPOSITION | MFT_BITMAP, 1, (LPCSTR)HBMMENU_CALLBACK );
767c2c66affSColin Finck     mii.cbSize = sizeof(mii);
768c2c66affSColin Finck     mii.fMask = MIIM_BITMAP | MIIM_FTYPE | MIIM_ID;
769c2c66affSColin Finck     if (GetMenuItemInfoA( hmenu, 1, TRUE, &mii ))
770c2c66affSColin Finck     {
771c2c66affSColin Finck         ok( mii.fType == MFT_BITMAP, "wrong type %x\n", mii.fType );
772c2c66affSColin Finck         ok( mii.wID == 1, "wrong id %x\n", mii.wID );
773c2c66affSColin Finck         ok( mii.hbmpItem == HBMMENU_CALLBACK, "wrong data %p\n", mii.hbmpItem );
774c2c66affSColin Finck     }
775c2c66affSColin Finck     TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
776c2c66affSColin Finck 
777c2c66affSColin Finck     /* test width/height of an ownerdraw menu bar as well */
778c2c66affSColin Finck     ret = DestroyMenu(hmenu);
779c2c66affSColin Finck     ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
780c2c66affSColin Finck     hmenu = CreateMenu();
781c2c66affSColin Finck     ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
782c2c66affSColin Finck     if( !hmenu) { DestroyWindow(hwnd);return;}
783c2c66affSColin Finck     MOD_maxid=1;
784c2c66affSColin Finck     for(i=0;i<2;i++) {
785c2c66affSColin Finck         ret = AppendMenuA( hmenu, MF_OWNERDRAW, i, 0 );
786c2c66affSColin Finck         ok( ret, "AppendMenu failed for %d\n", i);
787c2c66affSColin Finck     }
788c2c66affSColin Finck     ret = SetMenu( hwnd, hmenu);
789c2c66affSColin Finck     UpdateWindow( hwnd); /* hack for wine to draw the window + menu */
790c2c66affSColin Finck     ok(ret, "SetMenu failed with error %d\n", GetLastError());
791c2c66affSColin Finck     /* test width */
792c2c66affSColin Finck     ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
793c2c66affSColin Finck             "width of owner drawn menu item is wrong. Got %d expected %d\n",
794c2c66affSColin Finck             MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
795c2c66affSColin Finck     /* test height */
796c2c66affSColin Finck     ok( MOD_rc[0].bottom - MOD_rc[0].top == GetSystemMetrics( SM_CYMENU) - 1,
797c2c66affSColin Finck             "Height of owner drawn menu item is wrong. Got %d expected %d\n",
798c2c66affSColin Finck             MOD_rc[0].bottom - MOD_rc[0].top, GetSystemMetrics( SM_CYMENU) - 1);
799c2c66affSColin Finck 
800c2c66affSColin Finck     /* clean up */
801c2c66affSColin Finck     ret = DestroyMenu(hmenu);
802c2c66affSColin Finck     ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
803c2c66affSColin Finck     DestroyWindow(hwnd);
804c2c66affSColin Finck }
805c2c66affSColin Finck 
806c2c66affSColin Finck /* helper for test_menu_bmp_and_string() */
test_mbs_help(int ispop,int hassub,int mnuopt,HWND hwnd,int arrowwidth,int count,HBITMAP hbmp,SIZE bmpsize,LPCSTR text,SIZE size,SIZE sc_size)807c2c66affSColin Finck static void test_mbs_help( int ispop, int hassub, int mnuopt,
808c2c66affSColin Finck         HWND hwnd, int arrowwidth, int count, HBITMAP hbmp,
809c2c66affSColin Finck         SIZE bmpsize, LPCSTR text, SIZE size, SIZE sc_size)
810c2c66affSColin Finck {
811c2c66affSColin Finck     BOOL ret;
812c2c66affSColin Finck     HMENU hmenu, submenu;
813c2c66affSColin Finck     MENUITEMINFOA mii={ sizeof( MENUITEMINFOA )};
814c2c66affSColin Finck     MENUINFO mi;
815c2c66affSColin Finck     RECT rc;
816c2c66affSColin Finck     CHAR text_copy[16];
817c2c66affSColin Finck     int hastab,  expect;
818c2c66affSColin Finck     BOOL failed = FALSE;
819c2c66affSColin Finck 
820c2c66affSColin Finck     MOD_GotDrawItemMsg = FALSE;
821c2c66affSColin Finck     mii.fMask = MIIM_FTYPE | MIIM_DATA | MIIM_STATE;
822c2c66affSColin Finck     mii.fType = 0;
823c2c66affSColin Finck     /* check the menu item unless MNS_CHECKORBMP is set */
824c2c66affSColin Finck     mii.fState = (mnuopt != 2 ? MFS_CHECKED : MFS_UNCHECKED);
825c2c66affSColin Finck     mii.dwItemData =0;
826c2c66affSColin Finck     MODsizes[0] = bmpsize;
827c2c66affSColin Finck     hastab = 0;
828c2c66affSColin Finck     if( text ) {
829c2c66affSColin Finck         char *p;
830c2c66affSColin Finck         mii.fMask |= MIIM_STRING;
831c2c66affSColin Finck         strcpy(text_copy, text);
832c2c66affSColin Finck         mii.dwTypeData = text_copy; /* structure member declared non-const */
833c2c66affSColin Finck         if( ( p = strchr( text, '\t'))) {
834c2c66affSColin Finck             hastab = *(p + 1) ? 2 : 1;
835c2c66affSColin Finck         }
836c2c66affSColin Finck     }
837c2c66affSColin Finck     /* tabs don't make sense in menubars */
838c2c66affSColin Finck     if(hastab && !ispop) return;
839c2c66affSColin Finck     if( hbmp) {
840c2c66affSColin Finck         mii.fMask |= MIIM_BITMAP;
841c2c66affSColin Finck         mii.hbmpItem = hbmp;
842c2c66affSColin Finck     }
843c2c66affSColin Finck     submenu = CreateMenu();
844c2c66affSColin Finck     ok( submenu != 0, "CreateMenu failed with error %d\n", GetLastError());
845c2c66affSColin Finck     if( ispop)
846c2c66affSColin Finck         hmenu = CreatePopupMenu();
847c2c66affSColin Finck     else
848c2c66affSColin Finck         hmenu = CreateMenu();
849c2c66affSColin Finck     ok( hmenu != 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
850c2c66affSColin Finck     if( hassub) {
851c2c66affSColin Finck         mii.fMask |= MIIM_SUBMENU;
852c2c66affSColin Finck         mii.hSubMenu = submenu;
853c2c66affSColin Finck     }
854c2c66affSColin Finck     if( mnuopt) {
855c2c66affSColin Finck         mi.cbSize = sizeof(mi);
856c2c66affSColin Finck         mi.fMask = MIM_STYLE;
857*7a62c32bSAmine Khaldi         GetMenuInfo( hmenu, &mi);
858c2c66affSColin Finck         if( mnuopt) mi.dwStyle |= mnuopt == 1 ? MNS_NOCHECK : MNS_CHECKORBMP;
859*7a62c32bSAmine Khaldi         ret = SetMenuInfo( hmenu, &mi);
860c2c66affSColin Finck         ok( ret, "SetMenuInfo failed with error %d\n", GetLastError());
861c2c66affSColin Finck     }
862c2c66affSColin Finck     ret = InsertMenuItemA( hmenu, 0, FALSE, &mii);
863c2c66affSColin Finck     ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
864c2c66affSColin Finck     failed = !ret;
865c2c66affSColin Finck     if( winetest_debug) {
866c2c66affSColin Finck         HDC hdc=GetDC(hwnd);
867c2c66affSColin Finck         RECT rc = {100, 50, 400, 70};
868c2c66affSColin Finck         char buf[100];
869c2c66affSColin Finck 
870c2c66affSColin Finck         sprintf( buf,"%d text \"%s\" mnuopt %d", count, text ? text: "(nil)", mnuopt);
871c2c66affSColin Finck         FillRect( hdc, &rc, (HBRUSH) COLOR_WINDOW);
872c2c66affSColin Finck         TextOutA( hdc, 10, 50, buf, strlen( buf));
873c2c66affSColin Finck         ReleaseDC( hwnd, hdc);
874c2c66affSColin Finck     }
875c2c66affSColin Finck     if(ispop)
876c2c66affSColin Finck         TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
877c2c66affSColin Finck     else {
878c2c66affSColin Finck         ret = SetMenu( hwnd, hmenu);
879c2c66affSColin Finck         ok(ret, "SetMenu failed with error %d\n", GetLastError());
880c2c66affSColin Finck         DrawMenuBar( hwnd);
881c2c66affSColin Finck     }
882c2c66affSColin Finck     ret = GetMenuItemRect( hwnd, hmenu, 0, &rc);
883c2c66affSColin Finck     ok(ret, "GetMenuItemRect failed with error %d\n", GetLastError());
884c2c66affSColin Finck 
885c2c66affSColin Finck     if (0)  /* comment out menu size checks, behavior is different in almost every Windows version */
886c2c66affSColin Finck             /* the tests should however succeed on win2000, XP and Wine (at least up to 1.1.15) */
887c2c66affSColin Finck             /* with a variety of dpis and desktop font sizes */
888c2c66affSColin Finck     {
889c2c66affSColin Finck         /* check menu width */
890c2c66affSColin Finck         if( ispop)
891c2c66affSColin Finck             expect = ( text || hbmp ?
892c2c66affSColin Finck                        4 + (mnuopt != 1 ? GetSystemMetrics(SM_CXMENUCHECK) : 0)
893c2c66affSColin Finck                        : 0) +
894c2c66affSColin Finck                        arrowwidth  + MOD_avec + (hbmp ?
895c2c66affSColin Finck                                     ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ? bmpsize.cx + 2 : GetSystemMetrics( SM_CXMENUSIZE) + 2)
896c2c66affSColin Finck                                     : 0) +
897c2c66affSColin Finck                 (text && hastab ? /* TAB space */
898c2c66affSColin Finck                  MOD_avec + ( hastab==2 ? sc_size.cx : 0) : 0) +
899c2c66affSColin Finck                 (text ?  2 + (text[0] ? size.cx :0): 0) ;
900c2c66affSColin Finck         else
901c2c66affSColin Finck             expect = !(text || hbmp) ? 0 :
902c2c66affSColin Finck                 ( hbmp ? (text ? 2:0) + bmpsize.cx  : 0 ) +
903c2c66affSColin Finck                 (text ? 2 * MOD_avec + (text[0] ? size.cx :0): 0) ;
904c2c66affSColin Finck         ok( rc.right - rc.left == expect,
905c2c66affSColin Finck             "menu width wrong, got %d expected %d\n", rc.right - rc.left, expect);
906c2c66affSColin Finck         failed = failed || !(rc.right - rc.left == expect);
907c2c66affSColin Finck         /* check menu height */
908c2c66affSColin Finck         if( ispop)
909c2c66affSColin Finck             expect = max( ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 : 0),
910c2c66affSColin Finck                           max( (text ? max( 2 + size.cy, MOD_hic + 4) : 0),
911c2c66affSColin Finck                                (hbmp ?
912c2c66affSColin Finck                                    ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ?
913c2c66affSColin Finck                                        bmpsize.cy + 2
914c2c66affSColin Finck                                      : GetSystemMetrics( SM_CYMENUSIZE) + 2)
915c2c66affSColin Finck                                  : 0)));
916c2c66affSColin Finck         else
917c2c66affSColin Finck             expect = ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 :
918c2c66affSColin Finck                        max( GetSystemMetrics( SM_CYMENU) - 1, (hbmp ? bmpsize.cy : 0)));
919c2c66affSColin Finck         ok( rc.bottom - rc.top == expect,
920c2c66affSColin Finck             "menu height wrong, got %d expected %d (%d)\n",
921c2c66affSColin Finck             rc.bottom - rc.top, expect, GetSystemMetrics( SM_CYMENU));
922c2c66affSColin Finck         failed = failed || !(rc.bottom - rc.top == expect);
923c2c66affSColin Finck         if( hbmp == HBMMENU_CALLBACK && MOD_GotDrawItemMsg) {
924c2c66affSColin Finck             /* check the position of the bitmap */
925c2c66affSColin Finck             /* horizontal */
926c2c66affSColin Finck             if (!ispop)
927c2c66affSColin Finck                 expect = 3;
928c2c66affSColin Finck             else if (mnuopt == 0)
929c2c66affSColin Finck                 expect = 4 + GetSystemMetrics(SM_CXMENUCHECK);
930c2c66affSColin Finck             else if (mnuopt == 1)
931c2c66affSColin Finck                 expect = 4;
932c2c66affSColin Finck             else /* mnuopt == 2 */
933c2c66affSColin Finck                 expect = 2;
934c2c66affSColin Finck             ok( expect == MOD_rc[0].left,
935c2c66affSColin Finck                 "bitmap left is %d expected %d\n", MOD_rc[0].left, expect);
936c2c66affSColin Finck             failed = failed || !(expect == MOD_rc[0].left);
937c2c66affSColin Finck             /* vertical */
938c2c66affSColin Finck             expect = (rc.bottom - rc.top - MOD_rc[0].bottom + MOD_rc[0].top) / 2;
939c2c66affSColin Finck             ok( expect == MOD_rc[0].top,
940c2c66affSColin Finck                 "bitmap top is %d expected %d\n", MOD_rc[0].top, expect);
941c2c66affSColin Finck             failed = failed || !(expect == MOD_rc[0].top);
942c2c66affSColin Finck         }
943c2c66affSColin Finck     }
944c2c66affSColin Finck     /* if there was a failure, report details */
945c2c66affSColin Finck     if( failed) {
946c2c66affSColin Finck         trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
947c2c66affSColin Finck                 count, (ispop? "POPUP": "MENUBAR"),text ? text: "(nil)", hbmp, bmpsize.cx, bmpsize.cy,
948c2c66affSColin Finck                 size.cx, size.cy, sc_size.cx, mnuopt, hastab);
949c2c66affSColin Finck         trace("    check %d,%d arrow %d avechar %d\n",
950c2c66affSColin Finck                 GetSystemMetrics(SM_CXMENUCHECK ),
951c2c66affSColin Finck                 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
952c2c66affSColin Finck         if( hbmp == HBMMENU_CALLBACK)
953c2c66affSColin Finck             trace( "    rc %s bmp.rc %s\n", wine_dbgstr_rect(&rc), wine_dbgstr_rect(&MOD_rc[0]));
954c2c66affSColin Finck     }
955c2c66affSColin Finck     /* clean up */
956c2c66affSColin Finck     ret = DestroyMenu(submenu);
957c2c66affSColin Finck     ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
958c2c66affSColin Finck     ret = DestroyMenu(hmenu);
959c2c66affSColin Finck     ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
960c2c66affSColin Finck }
961c2c66affSColin Finck 
962c2c66affSColin Finck 
test_menu_bmp_and_string(void)963c2c66affSColin Finck static void test_menu_bmp_and_string(void)
964c2c66affSColin Finck {
965c2c66affSColin Finck     BYTE bmfill[300];
966c2c66affSColin Finck     HBITMAP hbm_arrow;
967c2c66affSColin Finck     BITMAP bm;
968c2c66affSColin Finck     INT arrowwidth;
969c2c66affSColin Finck     HWND hwnd;
970c2c66affSColin Finck     HMENU hsysmenu;
971c2c66affSColin Finck     MENUINFO mi= {sizeof(MENUINFO)};
972c2c66affSColin Finck     MENUITEMINFOA mii= {sizeof(MENUITEMINFOA)};
973c2c66affSColin Finck     int count, szidx, txtidx, bmpidx, hassub, mnuopt, ispop;
974c2c66affSColin Finck     BOOL got;
975c2c66affSColin Finck 
976c2c66affSColin Finck     memset( bmfill, 0xcc, sizeof( bmfill));
977c2c66affSColin Finck     hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL, WS_SYSMENU |
978c2c66affSColin Finck                           WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
979c2c66affSColin Finck                           NULL, NULL, NULL, NULL);
980c2c66affSColin Finck     hbm_arrow = LoadBitmapA( 0, (LPCSTR)OBM_MNARROW);
981c2c66affSColin Finck     GetObjectA( hbm_arrow, sizeof(bm), &bm);
982c2c66affSColin Finck     arrowwidth = bm.bmWidth;
983c2c66affSColin Finck     ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
984c2c66affSColin Finck     if( !hwnd) return;
985c2c66affSColin Finck     /* test system menu */
986c2c66affSColin Finck     hsysmenu = GetSystemMenu( hwnd, FALSE);
987c2c66affSColin Finck     ok( hsysmenu != NULL, "GetSystemMenu failed with error %d\n", GetLastError());
988c2c66affSColin Finck     mi.fMask = MIM_STYLE;
989c2c66affSColin Finck     mi.dwStyle = 0;
990*7a62c32bSAmine Khaldi     got = GetMenuInfo( hsysmenu, &mi);
991c2c66affSColin Finck     ok( got, "GetMenuInfo failed gle=%d\n", GetLastError());
992c2c66affSColin Finck     ok( MNS_CHECKORBMP == mi.dwStyle, "System Menu Style is %08x, without the bit %08x\n",
993c2c66affSColin Finck         mi.dwStyle, MNS_CHECKORBMP);
994c2c66affSColin Finck     mii.fMask = MIIM_BITMAP;
995c2c66affSColin Finck     mii.hbmpItem = NULL;
996c2c66affSColin Finck     got = GetMenuItemInfoA( hsysmenu, SC_CLOSE, FALSE, &mii);
997c2c66affSColin Finck     ok( got, "GetMenuItemInfoA failed gle=%d\n", GetLastError());
998c2c66affSColin Finck     ok( HBMMENU_POPUP_CLOSE == mii.hbmpItem, "Item info did not get the right hbitmap: got %p  expected %p\n",
999c2c66affSColin Finck         mii.hbmpItem, HBMMENU_POPUP_CLOSE);
1000c2c66affSColin Finck 
1001c2c66affSColin Finck     memset(&mii, 0x81, sizeof(mii));
1002c2c66affSColin Finck     mii.cbSize = sizeof(mii);
1003c2c66affSColin Finck     mii.fMask  = MIIM_STATE | MIIM_ID | MIIM_TYPE | MIIM_DATA;
1004c2c66affSColin Finck     mii.dwTypeData = (LPSTR)bmfill;
1005c2c66affSColin Finck     mii.cch = sizeof(bmfill);
1006c2c66affSColin Finck     mii.dwItemData = 0x81818181;
1007c2c66affSColin Finck     got = GetMenuItemInfoA(hsysmenu, SC_RESTORE, FALSE, &mii);
1008c2c66affSColin Finck     ok(got, "GetMenuItemInfo failed\n");
1009c2c66affSColin Finck     ok((mii.fType & ~(MFT_RIGHTJUSTIFY|MFT_RIGHTORDER)) == MFT_STRING, "expected MFT_STRING, got %#x\n", mii.fType);
1010c2c66affSColin Finck     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
1011c2c66affSColin Finck     ok(mii.wID == SC_RESTORE, "expected SC_RESTORE, got %#x\n", mii.wID);
1012c2c66affSColin Finck     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
1013c2c66affSColin Finck     ok(mii.dwItemData == 0, "expected 0, got %#lx\n", mii.dwItemData);
1014c2c66affSColin Finck     ok(mii.dwTypeData == (LPSTR)bmfill, "expected %p, got %p\n", bmfill, mii.dwTypeData);
1015c2c66affSColin Finck     ok(mii.cch != 0, "cch should not be 0\n");
1016c2c66affSColin Finck     ok(mii.hbmpItem == HBMMENU_POPUP_RESTORE, "expected HBMMENU_POPUP_RESTORE, got %p\n", mii.hbmpItem);
1017c2c66affSColin Finck 
1018c2c66affSColin Finck     mii.cbSize = sizeof(mii);
1019c2c66affSColin Finck     mii.fMask = MIIM_TYPE;
1020c2c66affSColin Finck     mii.hbmpItem = (HBITMAP)0x81818181;
1021c2c66affSColin Finck     got = GetMenuItemInfoA(hsysmenu, SC_CLOSE, FALSE, &mii);
1022c2c66affSColin Finck     ok(got, "GetMenuItemInfo failed\n");
1023c2c66affSColin Finck     ok((mii.fType & ~(MFT_RIGHTJUSTIFY|MFT_RIGHTORDER)) == MFT_STRING, "expected MFT_STRING, got %#x\n", mii.fType);
1024c2c66affSColin Finck     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
1025c2c66affSColin Finck     ok(mii.wID == SC_RESTORE, "expected SC_RESTORE, got %#x\n", mii.wID);
1026c2c66affSColin Finck     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
1027c2c66affSColin Finck     ok(mii.dwItemData == 0, "expected 0, got %#lx\n", mii.dwItemData);
1028c2c66affSColin Finck     ok(mii.dwTypeData == (LPSTR)bmfill, "expected %p, got %p\n", bmfill, mii.dwTypeData);
1029c2c66affSColin Finck     ok(mii.cch != 0, "cch should not be 0\n");
1030c2c66affSColin Finck     ok(mii.hbmpItem == HBMMENU_POPUP_CLOSE, "expected HBMMENU_POPUP_CLOSE, got %p\n", mii.hbmpItem);
1031c2c66affSColin Finck 
1032c2c66affSColin Finck     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
1033c2c66affSColin Finck 
1034c2c66affSColin Finck     if( winetest_debug)
1035c2c66affSColin Finck         trace("    check %d,%d arrow %d avechar %d\n",
1036c2c66affSColin Finck                 GetSystemMetrics(SM_CXMENUCHECK ),
1037c2c66affSColin Finck                 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
1038c2c66affSColin Finck     count = 0;
1039c2c66affSColin Finck     MOD_maxid = 0;
1040c2c66affSColin Finck     for( ispop=1; ispop >= 0; ispop--){
1041c2c66affSColin Finck         static SIZE bmsizes[]= {
1042c2c66affSColin Finck             {10,10},{38,38},{1,30},{55,5}};
1043*7a62c32bSAmine Khaldi         for( szidx=0; szidx < ARRAY_SIZE(bmsizes); szidx++) {
1044c2c66affSColin Finck             HBITMAP hbm = CreateBitmap( bmsizes[szidx].cx, bmsizes[szidx].cy,1,1,bmfill);
1045c2c66affSColin Finck             HBITMAP bitmaps[] = { HBMMENU_CALLBACK, hbm, HBMMENU_POPUP_CLOSE, NULL  };
1046c2c66affSColin Finck             ok( hbm != 0, "CreateBitmap failed err %d\n", GetLastError());
1047*7a62c32bSAmine Khaldi             for( txtidx = 0; txtidx < ARRAY_SIZE(MOD_txtsizes); txtidx++) {
1048c2c66affSColin Finck                 for( hassub = 0; hassub < 2 ; hassub++) { /* add submenu item */
1049c2c66affSColin Finck                     for( mnuopt = 0; mnuopt < 3 ; mnuopt++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
1050*7a62c32bSAmine Khaldi                         for( bmpidx = 0; bmpidx <ARRAY_SIZE(bitmaps); bmpidx++) {
1051c2c66affSColin Finck                             /* no need to test NULL bitmaps of several sizes */
1052c2c66affSColin Finck                             if( !bitmaps[bmpidx] && szidx > 0) continue;
1053c2c66affSColin Finck                             /* the HBMMENU_POPUP not to test for menu bars */
1054c2c66affSColin Finck                             if( !ispop &&
1055c2c66affSColin Finck                                 bitmaps[bmpidx] >= HBMMENU_POPUP_CLOSE &&
1056c2c66affSColin Finck                                 bitmaps[bmpidx] <= HBMMENU_POPUP_MINIMIZE) continue;
1057c2c66affSColin Finck                             if( !ispop && hassub) continue;
1058c2c66affSColin Finck                             test_mbs_help( ispop, hassub, mnuopt,
1059c2c66affSColin Finck                                     hwnd, arrowwidth, ++count,
1060c2c66affSColin Finck                                     bitmaps[bmpidx],
1061c2c66affSColin Finck                                     bmsizes[szidx],
1062c2c66affSColin Finck                                     MOD_txtsizes[txtidx].text,
1063c2c66affSColin Finck                                     MOD_txtsizes[txtidx].size,
1064c2c66affSColin Finck                                     MOD_txtsizes[txtidx].sc_size);
1065c2c66affSColin Finck                         }
1066c2c66affSColin Finck                     }
1067c2c66affSColin Finck                 }
1068c2c66affSColin Finck             }
1069c2c66affSColin Finck             DeleteObject( hbm);
1070c2c66affSColin Finck         }
1071c2c66affSColin Finck     }
1072c2c66affSColin Finck     /* clean up */
1073c2c66affSColin Finck     DestroyWindow(hwnd);
1074c2c66affSColin Finck }
1075c2c66affSColin Finck 
test_menu_add_string(void)1076c2c66affSColin Finck static void test_menu_add_string( void )
1077c2c66affSColin Finck {
1078c2c66affSColin Finck     HMENU hmenu;
1079c2c66affSColin Finck     MENUITEMINFOA info;
1080c2c66affSColin Finck     BOOL rc;
1081c2c66affSColin Finck     int ret;
1082c2c66affSColin Finck 
1083c2c66affSColin Finck     char string[0x80];
1084c2c66affSColin Finck     char string2[0x80];
1085c2c66affSColin Finck 
1086c2c66affSColin Finck     char strback[0x80];
1087c2c66affSColin Finck     WCHAR strbackW[0x80];
1088c2c66affSColin Finck     static CHAR blah[] = "blah";
1089c2c66affSColin Finck     static const WCHAR expectedString[] = {'D','u','m','m','y',' ','s','t','r','i','n','g', 0};
1090c2c66affSColin Finck 
1091c2c66affSColin Finck     hmenu = CreateMenu();
1092c2c66affSColin Finck 
1093c2c66affSColin Finck     memset( &info, 0, sizeof info );
1094c2c66affSColin Finck     info.cbSize = sizeof info;
1095c2c66affSColin Finck     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_ID;
1096c2c66affSColin Finck     info.dwTypeData = blah;
1097c2c66affSColin Finck     info.cch = 6;
1098c2c66affSColin Finck     info.dwItemData = 0;
1099c2c66affSColin Finck     info.wID = 1;
1100c2c66affSColin Finck     info.fState = 0;
1101c2c66affSColin Finck     InsertMenuItemA(hmenu, 0, TRUE, &info );
1102c2c66affSColin Finck 
1103c2c66affSColin Finck     memset( &info, 0, sizeof info );
1104c2c66affSColin Finck     info.cbSize = sizeof info;
1105c2c66affSColin Finck     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_DATA | MIIM_ID;
1106c2c66affSColin Finck     info.dwTypeData = string;
1107c2c66affSColin Finck     info.cch = sizeof string;
1108c2c66affSColin Finck     string[0] = 0;
1109c2c66affSColin Finck     GetMenuItemInfoA( hmenu, 0, TRUE, &info );
1110c2c66affSColin Finck 
1111c2c66affSColin Finck     ok( !strcmp( string, "blah" ), "menu item name differed\n");
1112c2c66affSColin Finck 
1113c2c66affSColin Finck     /* Test combination of ownerdraw and strings with GetMenuItemString(A/W) */
1114c2c66affSColin Finck     strcpy(string, "Dummy string");
1115c2c66affSColin Finck     memset(&info, 0x00, sizeof(info));
1116c2c66affSColin Finck     info.cbSize= sizeof(MENUITEMINFOA);
1117c2c66affSColin Finck     info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
1118c2c66affSColin Finck     info.fType= MFT_OWNERDRAW;
1119c2c66affSColin Finck     info.dwTypeData= string;
1120c2c66affSColin Finck     rc = InsertMenuItemA( hmenu, 0, TRUE, &info );
1121c2c66affSColin Finck     ok (rc, "InsertMenuItem failed\n");
1122c2c66affSColin Finck 
1123c2c66affSColin Finck     strcpy(string,"Garbage");
1124c2c66affSColin Finck     ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1125c2c66affSColin Finck     ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
1126c2c66affSColin Finck 
1127c2c66affSColin Finck     ret = GetMenuStringW( hmenu, 0, strbackW, 99, MF_BYPOSITION );
1128c2c66affSColin Finck     ok (ret, "GetMenuStringW on ownerdraw entry failed\n");
1129c2c66affSColin Finck     ok (!lstrcmpW( strbackW, expectedString ), "Menu text from Unicode version incorrect\n");
1130c2c66affSColin Finck 
1131c2c66affSColin Finck     /* Just try some invalid parameter tests */
1132c2c66affSColin Finck     SetLastError(0xdeadbeef);
1133c2c66affSColin Finck     rc = SetMenuItemInfoA( hmenu, 0, TRUE, NULL );
1134c2c66affSColin Finck     ret = GetLastError();
1135c2c66affSColin Finck     ok (!rc, "SetMenuItemInfoA succeeded unexpectedly\n");
1136c2c66affSColin Finck     ok (ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
1137c2c66affSColin Finck 
1138c2c66affSColin Finck     SetLastError(0xdeadbeef);
1139c2c66affSColin Finck     rc = SetMenuItemInfoA( hmenu, 0, FALSE, NULL );
1140c2c66affSColin Finck     ret = GetLastError();
1141c2c66affSColin Finck     ok (!rc, "SetMenuItemInfoA succeeded unexpectedly\n");
1142c2c66affSColin Finck     ok (ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
1143c2c66affSColin Finck 
1144c2c66affSColin Finck     /* Just change ftype to string and see what text is stored */
1145c2c66affSColin Finck     memset(&info, 0x00, sizeof(info));
1146c2c66affSColin Finck     info.cbSize= sizeof(MENUITEMINFOA);
1147c2c66affSColin Finck     info.fMask= MIIM_FTYPE; /* Set string type */
1148c2c66affSColin Finck     info.fType= MFT_STRING;
1149c2c66affSColin Finck     info.dwTypeData= (char *)0xdeadbeef;
1150c2c66affSColin Finck     rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1151c2c66affSColin Finck     ok (rc, "SetMenuItemInfo failed\n");
1152c2c66affSColin Finck 
1153c2c66affSColin Finck     /* Did we keep the old dwTypeData? */
1154c2c66affSColin Finck     ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1155c2c66affSColin Finck     ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
1156c2c66affSColin Finck 
1157c2c66affSColin Finck     /* Ensure change to bitmap type fails */
1158c2c66affSColin Finck     memset(&info, 0x00, sizeof(info));
1159c2c66affSColin Finck     info.cbSize= sizeof(MENUITEMINFOA);
1160c2c66affSColin Finck     info.fMask= MIIM_FTYPE; /* Set as bitmap type */
1161c2c66affSColin Finck     info.fType= MFT_BITMAP;
1162c2c66affSColin Finck     info.dwTypeData= (char *)0xdeadbee2;
1163c2c66affSColin Finck     rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1164c2c66affSColin Finck     ok (!rc, "SetMenuItemInfo unexpectedly worked\n");
1165c2c66affSColin Finck 
1166c2c66affSColin Finck     /* Just change ftype back and ensure data hasn't been freed */
1167c2c66affSColin Finck     info.fType= MFT_OWNERDRAW; /* Set as ownerdraw type */
1168c2c66affSColin Finck     info.dwTypeData= (char *)0xdeadbee3;
1169c2c66affSColin Finck     rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1170c2c66affSColin Finck     ok (rc, "SetMenuItemInfo failed\n");
1171c2c66affSColin Finck 
1172c2c66affSColin Finck     /* Did we keep the old dwTypeData? */
1173c2c66affSColin Finck     ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1174c2c66affSColin Finck     ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
1175c2c66affSColin Finck 
1176c2c66affSColin Finck     /* Just change string value (not type) */
1177c2c66affSColin Finck     memset(&info, 0x00, sizeof(info));
1178c2c66affSColin Finck     info.cbSize= sizeof(MENUITEMINFOA);
1179c2c66affSColin Finck     info.fMask= MIIM_STRING; /* Set typeData */
1180c2c66affSColin Finck     strcpy(string2, "string2");
1181c2c66affSColin Finck     info.dwTypeData= string2;
1182c2c66affSColin Finck     rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1183c2c66affSColin Finck     ok (rc, "SetMenuItemInfo failed\n");
1184c2c66affSColin Finck 
1185c2c66affSColin Finck     ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1186c2c66affSColin Finck     ok (!strcmp( strback, "string2" ), "Menu text from Ansi version incorrect\n");
1187c2c66affSColin Finck 
1188c2c66affSColin Finck     /*  crashes with wine 0.9.5 */
1189c2c66affSColin Finck     memset(&info, 0x00, sizeof(info));
1190c2c66affSColin Finck     info.cbSize= sizeof(MENUITEMINFOA);
1191c2c66affSColin Finck     info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
1192c2c66affSColin Finck     info.fType= MFT_OWNERDRAW;
1193c2c66affSColin Finck     rc = InsertMenuItemA( hmenu, 0, TRUE, &info );
1194c2c66affSColin Finck     ok (rc, "InsertMenuItem failed\n");
1195c2c66affSColin Finck     ok (!GetMenuStringA( hmenu, 0, NULL, 0, MF_BYPOSITION),
1196c2c66affSColin Finck             "GetMenuString on ownerdraw entry succeeded.\n");
1197c2c66affSColin Finck     ret = GetMenuStringW( hmenu, 0, NULL, 0, MF_BYPOSITION);
1198c2c66affSColin Finck     ok (!ret, "GetMenuStringW on ownerdraw entry succeeded.\n");
1199c2c66affSColin Finck 
1200c2c66affSColin Finck     DestroyMenu( hmenu );
1201c2c66affSColin Finck }
1202c2c66affSColin Finck 
1203c2c66affSColin Finck /* define building blocks for the menu item info tests */
strncmpW(const WCHAR * str1,const WCHAR * str2,int n)1204c2c66affSColin Finck static int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
1205c2c66affSColin Finck {
1206c2c66affSColin Finck     if (n <= 0) return 0;
1207c2c66affSColin Finck     while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
1208c2c66affSColin Finck     return *str1 - *str2;
1209c2c66affSColin Finck }
1210c2c66affSColin Finck 
strcpyW(WCHAR * dst,const WCHAR * src)1211c2c66affSColin Finck static  WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
1212c2c66affSColin Finck {
1213c2c66affSColin Finck     WCHAR *p = dst;
1214c2c66affSColin Finck     while ((*p++ = *src++));
1215c2c66affSColin Finck     return dst;
1216c2c66affSColin Finck }
1217c2c66affSColin Finck 
insert_menu_item(int line,HMENU hmenu,BOOL ansi,UINT mask,UINT type,UINT state,UINT id,HMENU submenu,HBITMAP checked,HBITMAP unchecked,ULONG_PTR data,void * type_data,UINT len,HBITMAP item,BOOL expect)1218c2c66affSColin Finck static void insert_menu_item( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state, UINT id,
1219c2c66affSColin Finck                               HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
1220c2c66affSColin Finck                               void *type_data, UINT len, HBITMAP item, BOOL expect )
1221c2c66affSColin Finck {
1222c2c66affSColin Finck     MENUITEMINFOA info;
1223c2c66affSColin Finck     BOOL ret;
1224c2c66affSColin Finck 
1225c2c66affSColin Finck     /* magic bitmap handle to test smaller cbSize */
1226c2c66affSColin Finck     if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
1227c2c66affSColin Finck         info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
1228c2c66affSColin Finck     else
1229c2c66affSColin Finck         info.cbSize = sizeof(info);
1230c2c66affSColin Finck     info.fMask = mask;
1231c2c66affSColin Finck     info.fType = type;
1232c2c66affSColin Finck     info.fState = state;
1233c2c66affSColin Finck     info.wID = id;
1234c2c66affSColin Finck     info.hSubMenu = submenu;
1235c2c66affSColin Finck     info.hbmpChecked = checked;
1236c2c66affSColin Finck     info.hbmpUnchecked = unchecked;
1237c2c66affSColin Finck     info.dwItemData = data;
1238c2c66affSColin Finck     info.dwTypeData = type_data;
1239c2c66affSColin Finck     info.cch = len;
1240c2c66affSColin Finck     info.hbmpItem = item;
1241c2c66affSColin Finck     SetLastError( 0xdeadbeef );
1242c2c66affSColin Finck     if (ansi) ret = InsertMenuItemA( hmenu, 0, TRUE, &info );
1243c2c66affSColin Finck     else ret = InsertMenuItemW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
1244c2c66affSColin Finck     if (!expect) ok_(__FILE__, line)( !ret, "InsertMenuItem should have failed.\n" );
1245c2c66affSColin Finck     else ok_(__FILE__, line)( ret, "InsertMenuItem failed, err %u\n", GetLastError());
1246c2c66affSColin Finck }
1247c2c66affSColin Finck 
check_menu_item_info(int line,HMENU hmenu,BOOL ansi,UINT mask,UINT type,UINT state,UINT id,HMENU submenu,HBITMAP checked,HBITMAP unchecked,ULONG_PTR data,void * type_data,UINT in_len,UINT out_len,HBITMAP item,LPCSTR expname,BOOL expect,BOOL expstring)1248c2c66affSColin Finck static void check_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
1249c2c66affSColin Finck                                   UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked,
1250c2c66affSColin Finck                                   ULONG_PTR data, void *type_data, UINT in_len, UINT out_len,
1251c2c66affSColin Finck                                   HBITMAP item, LPCSTR expname, BOOL expect, BOOL expstring )
1252c2c66affSColin Finck {
1253c2c66affSColin Finck     MENUITEMINFOA info;
1254c2c66affSColin Finck     BOOL ret;
1255c2c66affSColin Finck     WCHAR buffer[80];
1256c2c66affSColin Finck 
1257c2c66affSColin Finck     SetLastError( 0xdeadbeef );
1258c2c66affSColin Finck     memset( &info, 0xcc, sizeof(info) );
1259c2c66affSColin Finck     info.cbSize = sizeof(info);
1260c2c66affSColin Finck     info.fMask = mask;
1261c2c66affSColin Finck     info.dwTypeData = type_data;
1262c2c66affSColin Finck     info.cch = in_len;
1263c2c66affSColin Finck 
1264c2c66affSColin Finck     ret = ansi ? GetMenuItemInfoA( hmenu, 0, TRUE, &info ) :
1265c2c66affSColin Finck                  GetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW *)&info );
1266c2c66affSColin Finck     if (!expect)
1267c2c66affSColin Finck     {
1268c2c66affSColin Finck         ok_(__FILE__, line)( !ret, "GetMenuItemInfo should have failed.\n" );
1269c2c66affSColin Finck         return;
1270c2c66affSColin Finck     }
1271c2c66affSColin Finck     ok_(__FILE__, line)( ret, "GetMenuItemInfo failed, err %u\n", GetLastError());
1272c2c66affSColin Finck     if (mask & MIIM_TYPE)
1273c2c66affSColin Finck         ok_(__FILE__, line)( info.fType == type || info.fType == LOWORD(type),
1274c2c66affSColin Finck                              "wrong type %x/%x\n", info.fType, type );
1275c2c66affSColin Finck     if (mask & MIIM_STATE)
1276c2c66affSColin Finck         ok_(__FILE__, line)( info.fState == state || info.fState == LOWORD(state),
1277c2c66affSColin Finck                              "wrong state %x/%x\n", info.fState, state );
1278c2c66affSColin Finck     if (mask & MIIM_ID)
1279c2c66affSColin Finck         ok_(__FILE__, line)( info.wID == id || info.wID == LOWORD(id),
1280c2c66affSColin Finck                              "wrong id %x/%x\n", info.wID, id );
1281c2c66affSColin Finck     if (mask & MIIM_SUBMENU)
1282c2c66affSColin Finck         ok_(__FILE__, line)( info.hSubMenu == submenu || (ULONG_PTR)info.hSubMenu == LOWORD(submenu),
1283c2c66affSColin Finck                              "wrong submenu %p/%p\n", info.hSubMenu, submenu );
1284c2c66affSColin Finck     if (mask & MIIM_CHECKMARKS)
1285c2c66affSColin Finck     {
1286c2c66affSColin Finck         ok_(__FILE__, line)( info.hbmpChecked == checked || (ULONG_PTR)info.hbmpChecked == LOWORD(checked),
1287c2c66affSColin Finck                              "wrong bmpchecked %p/%p\n", info.hbmpChecked, checked );
1288c2c66affSColin Finck         ok_(__FILE__, line)( info.hbmpUnchecked == unchecked || (ULONG_PTR)info.hbmpUnchecked == LOWORD(unchecked),
1289c2c66affSColin Finck                              "wrong bmpunchecked %p/%p\n", info.hbmpUnchecked, unchecked );
1290c2c66affSColin Finck     }
1291c2c66affSColin Finck     if (mask & MIIM_DATA)
1292c2c66affSColin Finck         ok_(__FILE__, line)( info.dwItemData == data || info.dwItemData == LOWORD(data),
1293c2c66affSColin Finck                              "wrong item data %lx/%lx\n", info.dwItemData, data );
1294c2c66affSColin Finck     if (mask & MIIM_BITMAP)
1295c2c66affSColin Finck         ok_(__FILE__, line)( info.hbmpItem == item || (ULONG_PTR)info.hbmpItem == LOWORD(item),
1296c2c66affSColin Finck                              "wrong bmpitem %p/%p\n", info.hbmpItem, item );
1297c2c66affSColin Finck     ok_(__FILE__, line)( info.dwTypeData == type_data || (ULONG_PTR)info.dwTypeData == LOWORD(type_data),
1298c2c66affSColin Finck                          "wrong type data %p/%p\n", info.dwTypeData, type_data );
1299c2c66affSColin Finck     ok_(__FILE__, line)( info.cch == out_len ||
1300c2c66affSColin Finck                          broken(! ansi && info.cch == 2 * out_len) /* East-Asian */,
1301c2c66affSColin Finck                          "wrong len %x/%x\n", info.cch, out_len );
1302c2c66affSColin Finck     if (expname)
1303c2c66affSColin Finck     {
1304c2c66affSColin Finck         if(ansi)
1305c2c66affSColin Finck             ok_(__FILE__, line)( !strncmp( expname, info.dwTypeData, out_len ),
1306c2c66affSColin Finck                                  "menu item name differed from '%s' '%s'\n", expname, info.dwTypeData );
1307c2c66affSColin Finck         else
1308c2c66affSColin Finck             ok_(__FILE__, line)( !strncmpW( (WCHAR *)expname, (WCHAR *)info.dwTypeData, out_len ),
1309c2c66affSColin Finck                                  "menu item name wrong\n" );
1310c2c66affSColin Finck 
1311c2c66affSColin Finck         SetLastError( 0xdeadbeef );
1312c2c66affSColin Finck         ret = ansi ? GetMenuStringA( hmenu, 0, (char *)buffer, 80, MF_BYPOSITION ) :
1313c2c66affSColin Finck             GetMenuStringW( hmenu, 0, buffer, 80, MF_BYPOSITION );
1314c2c66affSColin Finck         if (expstring)
1315c2c66affSColin Finck             ok_(__FILE__, line)( ret, "GetMenuString failed, err %u\n", GetLastError());
1316c2c66affSColin Finck         else
1317c2c66affSColin Finck             ok_(__FILE__, line)( !ret, "GetMenuString should have failed\n" );
1318c2c66affSColin Finck     }
1319c2c66affSColin Finck }
1320c2c66affSColin Finck 
modify_menu(int line,HMENU hmenu,BOOL ansi,UINT flags,UINT_PTR id,void * data)1321c2c66affSColin Finck static void modify_menu( int line, HMENU hmenu, BOOL ansi, UINT flags, UINT_PTR id, void *data )
1322c2c66affSColin Finck {
1323c2c66affSColin Finck     BOOL ret;
1324c2c66affSColin Finck 
1325c2c66affSColin Finck     SetLastError( 0xdeadbeef );
1326c2c66affSColin Finck     if (ansi) ret = ModifyMenuA( hmenu, 0, flags, id, data );
1327c2c66affSColin Finck     else ret = ModifyMenuW( hmenu, 0, flags, id, data );
1328c2c66affSColin Finck     ok_(__FILE__,line)( ret, "ModifyMenuA failed, err %u\n", GetLastError());
1329c2c66affSColin Finck }
1330c2c66affSColin Finck 
set_menu_item_info(int line,HMENU hmenu,BOOL ansi,UINT mask,UINT type,UINT state,UINT id,HMENU submenu,HBITMAP checked,HBITMAP unchecked,ULONG_PTR data,void * type_data,UINT len,HBITMAP item)1331c2c66affSColin Finck static void set_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
1332c2c66affSColin Finck                                 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
1333c2c66affSColin Finck                                 void *type_data, UINT len, HBITMAP item )
1334c2c66affSColin Finck 
1335c2c66affSColin Finck {
1336c2c66affSColin Finck     MENUITEMINFOA info;
1337c2c66affSColin Finck     BOOL ret;
1338c2c66affSColin Finck 
1339c2c66affSColin Finck     /* magic bitmap handle to test smaller cbSize */
1340c2c66affSColin Finck     if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
1341c2c66affSColin Finck         info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
1342c2c66affSColin Finck     else
1343c2c66affSColin Finck         info.cbSize = sizeof(info);
1344c2c66affSColin Finck     info.fMask = mask;
1345c2c66affSColin Finck     info.fType = type;
1346c2c66affSColin Finck     info.fState = state;
1347c2c66affSColin Finck     info.wID = id;
1348c2c66affSColin Finck     info.hSubMenu = submenu;
1349c2c66affSColin Finck     info.hbmpChecked = checked;
1350c2c66affSColin Finck     info.hbmpUnchecked = unchecked;
1351c2c66affSColin Finck     info.dwItemData = data;
1352c2c66affSColin Finck     info.dwTypeData = type_data;
1353c2c66affSColin Finck     info.cch = len;
1354c2c66affSColin Finck     info.hbmpItem = item;
1355c2c66affSColin Finck     SetLastError( 0xdeadbeef );
1356c2c66affSColin Finck     if (ansi) ret = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1357c2c66affSColin Finck     else ret = SetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
1358c2c66affSColin Finck     ok_(__FILE__, line)( ret, "SetMenuItemInfo failed, err %u\n", GetLastError());
1359c2c66affSColin Finck }
1360c2c66affSColin Finck 
1361c2c66affSColin Finck #define TMII_INSMI( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,eret1 )\
1362c2c66affSColin Finck     hmenu = CreateMenu();\
1363c2c66affSColin Finck     submenu = CreateMenu();\
1364c2c66affSColin Finck     if(ansi)strcpy( string, init );\
1365c2c66affSColin Finck     else strcpyW( string, init );\
1366c2c66affSColin Finck     insert_menu_item( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, eret1 )
1367c2c66affSColin Finck 
1368c2c66affSColin Finck /* GetMenuItemInfo + GetMenuString  */
1369c2c66affSColin Finck #define TMII_GMII( c2,l2,\
1370c2c66affSColin Finck     d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,\
1371c2c66affSColin Finck     expname, eret2, eret3)\
1372c2c66affSColin Finck     check_menu_item_info( __LINE__, hmenu, ansi, c2, d3, e3, f3, g3, h3, i3, j3, k3, l2, l3, m3, \
1373c2c66affSColin Finck                           expname, eret2, eret3 )
1374c2c66affSColin Finck 
1375c2c66affSColin Finck #define TMII_DONE \
1376c2c66affSColin Finck     RemoveMenu(hmenu, 0, TRUE );\
1377c2c66affSColin Finck     DestroyMenu( hmenu );\
1378c2c66affSColin Finck     DestroyMenu( submenu );
1379c2c66affSColin Finck 
1380c2c66affSColin Finck /* modify menu */
1381c2c66affSColin Finck #define TMII_MODM( flags, id, data ) \
1382c2c66affSColin Finck     modify_menu( __LINE__, hmenu, ansi, flags, id, data )
1383c2c66affSColin Finck 
1384c2c66affSColin Finck /* SetMenuItemInfo */
1385c2c66affSColin Finck #define TMII_SMII( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1 ) \
1386c2c66affSColin Finck     set_menu_item_info( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1 )
1387c2c66affSColin Finck 
1388c2c66affSColin Finck 
1389c2c66affSColin Finck #define OK 1
1390c2c66affSColin Finck #define ER 0
1391c2c66affSColin Finck 
1392c2c66affSColin Finck 
test_menu_iteminfo(void)1393c2c66affSColin Finck static void test_menu_iteminfo( void )
1394c2c66affSColin Finck {
1395c2c66affSColin Finck   BOOL ansi = TRUE;
1396c2c66affSColin Finck   char txtA[]="wine";
1397c2c66affSColin Finck   char initA[]="XYZ";
1398c2c66affSColin Finck   char emptyA[]="";
1399c2c66affSColin Finck   WCHAR txtW[]={'W','i','n','e',0};
1400c2c66affSColin Finck   WCHAR initW[]={'X','Y','Z',0};
1401c2c66affSColin Finck   WCHAR emptyW[]={0};
1402c2c66affSColin Finck   void *txt, *init, *empty, *string;
1403c2c66affSColin Finck   HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
1404c2c66affSColin Finck   char stringA[0x80];
1405c2c66affSColin Finck   HMENU hmenu, submenu;
1406c2c66affSColin Finck   HBITMAP dummy_hbm = (HBITMAP)(ULONG_PTR)0xdeadbeef;
1407c2c66affSColin Finck 
1408c2c66affSColin Finck   do {
1409c2c66affSColin Finck     if( ansi) {txt=txtA;init=initA;empty=emptyA;string=stringA;}
1410c2c66affSColin Finck     else {txt=txtW;init=initW;empty=emptyW;string=stringA;}
1411c2c66affSColin Finck     trace( "%s string %p hbm %p txt %p\n", ansi ?  "ANSI tests:   " : "Unicode tests:", string, hbm, txt);
1412c2c66affSColin Finck     /* test all combinations of MFT_STRING, MFT_OWNERDRAW and MFT_BITMAP */
1413c2c66affSColin Finck     /* (since MFT_STRING is zero, there are four of them) */
1414c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_STRING, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1415c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1416c2c66affSColin Finck         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1417c2c66affSColin Finck         txt, OK, OK );
1418c2c66affSColin Finck     TMII_DONE
1419c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1420c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1421c2c66affSColin Finck         MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1422c2c66affSColin Finck         NULL, OK, ER );
1423c2c66affSColin Finck     TMII_DONE
1424c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1425c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1426c2c66affSColin Finck         MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1427c2c66affSColin Finck         NULL, OK, ER );
1428c2c66affSColin Finck     TMII_DONE
1429c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1430c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1431c2c66affSColin Finck         MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1432c2c66affSColin Finck         NULL, OK, ER );
1433c2c66affSColin Finck     TMII_DONE
1434c2c66affSColin Finck     /* not enough space for name*/
1435c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1436c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 0,
1437c2c66affSColin Finck         MFT_STRING, 0, 0, 0, 0, 0, 0, NULL, 4, 0,
1438c2c66affSColin Finck         NULL, OK, OK );
1439c2c66affSColin Finck     TMII_DONE
1440c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1441c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 5,
1442c2c66affSColin Finck         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1443c2c66affSColin Finck         txt, OK, OK );
1444c2c66affSColin Finck     TMII_DONE
1445c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1446c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 4,
1447c2c66affSColin Finck         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 3, 0,
1448c2c66affSColin Finck         txt, OK, OK );
1449c2c66affSColin Finck     TMII_DONE
1450c2c66affSColin Finck     TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1451c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 0,
1452c2c66affSColin Finck         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, 0,
1453c2c66affSColin Finck         NULL, OK, ER );
1454c2c66affSColin Finck     TMII_DONE
1455c2c66affSColin Finck     /* cannot combine MIIM_TYPE with some other flags */
1456c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE|MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1457c2c66affSColin Finck     TMII_DONE
1458c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1459c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE|MIIM_STRING, 80,
1460c2c66affSColin Finck         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1461c2c66affSColin Finck         NULL, ER, OK );
1462c2c66affSColin Finck     TMII_DONE
1463c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1464c2c66affSColin Finck     TMII_DONE
1465c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1466c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE|MIIM_FTYPE, 80,
1467c2c66affSColin Finck         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1468c2c66affSColin Finck         NULL, ER, OK );
1469c2c66affSColin Finck     TMII_DONE
1470c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE|MIIM_BITMAP, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, hbm, ER );
1471c2c66affSColin Finck     TMII_DONE
1472c2c66affSColin Finck         /* but succeeds with some others */
1473c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1474c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE|MIIM_SUBMENU, 80,
1475c2c66affSColin Finck         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1476c2c66affSColin Finck         txt, OK, OK );
1477c2c66affSColin Finck     TMII_DONE
1478c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1479c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE|MIIM_STATE, 80,
1480c2c66affSColin Finck         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1481c2c66affSColin Finck         txt, OK, OK );
1482c2c66affSColin Finck     TMII_DONE
1483c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE|MIIM_ID, MFT_STRING, -1, 888, 0, 0, 0, -1, txt, 6, 0, OK );
1484c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE|MIIM_ID, 80,
1485c2c66affSColin Finck         MFT_STRING, 0, 888, 0, 0, 0, 0, string, 4, 0,
1486c2c66affSColin Finck         txt, OK, OK );
1487c2c66affSColin Finck     TMII_DONE
1488c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING, -1, -1, 0, 0, 0, 999, txt, 6, 0, OK );
1489c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1490c2c66affSColin Finck         MFT_STRING, 0, 0, 0, 0, 0, 999, string, 4, 0,
1491c2c66affSColin Finck         txt, OK, OK );
1492c2c66affSColin Finck     TMII_DONE
1493c2c66affSColin Finck     /* to be continued */
1494c2c66affSColin Finck     /* set text with MIIM_TYPE and retrieve with MIIM_STRING */
1495c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1496c2c66affSColin Finck     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1497c2c66affSColin Finck         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1498c2c66affSColin Finck         txt, OK, OK );
1499c2c66affSColin Finck     TMII_DONE
1500c2c66affSColin Finck     /* set text with MIIM_TYPE and retrieve with MIIM_STRING; MFT_OWNERDRAW causes an empty string */
1501c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1502c2c66affSColin Finck     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1503c2c66affSColin Finck         MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1504c2c66affSColin Finck         empty, OK, ER );
1505c2c66affSColin Finck     TMII_DONE
1506c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1507c2c66affSColin Finck     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1508c2c66affSColin Finck         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1509c2c66affSColin Finck         empty, OK, ER );
1510c2c66affSColin Finck     TMII_DONE
1511c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1512c2c66affSColin Finck     TMII_GMII ( MIIM_FTYPE, 80,
1513c2c66affSColin Finck         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, 0,
1514c2c66affSColin Finck         init, OK, ER );
1515c2c66affSColin Finck     TMII_DONE
1516c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1517c2c66affSColin Finck     TMII_GMII ( 0, 80,
1518c2c66affSColin Finck         0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1519c2c66affSColin Finck         init, OK, OK );
1520c2c66affSColin Finck     TMII_DONE
1521c2c66affSColin Finck     /* contrary to MIIM_TYPE,you can set the text for an owner draw menu */
1522c2c66affSColin Finck     TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1523c2c66affSColin Finck     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1524c2c66affSColin Finck         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1525c2c66affSColin Finck         txt, OK, OK );
1526c2c66affSColin Finck     TMII_DONE
1527c2c66affSColin Finck     /* same but retrieve with MIIM_TYPE */
1528c2c66affSColin Finck     TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1529c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1530c2c66affSColin Finck         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1531c2c66affSColin Finck         NULL, OK, OK );
1532c2c66affSColin Finck     TMII_DONE
1533c2c66affSColin Finck     TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1534c2c66affSColin Finck     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1535c2c66affSColin Finck         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1536c2c66affSColin Finck         empty, OK, ER );
1537c2c66affSColin Finck     TMII_DONE
1538c2c66affSColin Finck     TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1539c2c66affSColin Finck     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1540c2c66affSColin Finck         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1541c2c66affSColin Finck         empty, OK, ER );
1542c2c66affSColin Finck     TMII_DONE
1543c2c66affSColin Finck     TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1544c2c66affSColin Finck     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1545c2c66affSColin Finck         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, 0,
1546c2c66affSColin Finck         NULL, OK, ER );
1547c2c66affSColin Finck     TMII_DONE
1548c2c66affSColin Finck 
1549c2c66affSColin Finck     /* How is that with bitmaps? */
1550c2c66affSColin Finck     TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1551c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1552c2c66affSColin Finck         MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1553c2c66affSColin Finck         NULL, OK, ER );
1554c2c66affSColin Finck     TMII_DONE
1555c2c66affSColin Finck     TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1556c2c66affSColin Finck     TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1557c2c66affSColin Finck         0, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1558c2c66affSColin Finck         init, OK, ER );
1559c2c66affSColin Finck     TMII_DONE
1560c2c66affSColin Finck         /* MIIM_BITMAP does not like MFT_BITMAP */
1561c2c66affSColin Finck     TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, hbm, ER );
1562c2c66affSColin Finck     TMII_DONE
1563c2c66affSColin Finck         /* no problem with OWNERDRAWN */
1564c2c66affSColin Finck     TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1565c2c66affSColin Finck     TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1566c2c66affSColin Finck         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1567c2c66affSColin Finck         init, OK, ER );
1568c2c66affSColin Finck     TMII_DONE
1569c2c66affSColin Finck         /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1570c2c66affSColin Finck     TMII_INSMI( MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER );
1571c2c66affSColin Finck     TMII_DONE
1572c2c66affSColin Finck 
1573c2c66affSColin Finck     /* menu with submenu */
1574c2c66affSColin Finck     TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1575c2c66affSColin Finck     TMII_GMII ( MIIM_SUBMENU, 80,
1576c2c66affSColin Finck         0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1577c2c66affSColin Finck         init, OK, ER );
1578c2c66affSColin Finck     TMII_DONE
1579c2c66affSColin Finck     TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, empty, 0, 0, OK );
1580c2c66affSColin Finck     TMII_GMII ( MIIM_SUBMENU, 80,
1581c2c66affSColin Finck         0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1582c2c66affSColin Finck         init, OK, ER );
1583c2c66affSColin Finck     TMII_DONE
1584c2c66affSColin Finck     /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1585c2c66affSColin Finck     TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1586c2c66affSColin Finck     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1587c2c66affSColin Finck         MFT_STRING|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1588c2c66affSColin Finck         empty, OK, ER );
1589c2c66affSColin Finck     TMII_GMII ( MIIM_SUBMENU|MIIM_FTYPE, 80,
1590c2c66affSColin Finck         MFT_SEPARATOR, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1591c2c66affSColin Finck         empty, OK, ER );
1592c2c66affSColin Finck     TMII_DONE
1593c2c66affSColin Finck     /* menu with invalid submenu */
1594c2c66affSColin Finck     TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, (HMENU)999, 0, 0, -1, txt, 0, 0, ER );
1595c2c66affSColin Finck     TMII_DONE
1596c2c66affSColin Finck     /* Separator */
1597c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1598c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1599c2c66affSColin Finck         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1600c2c66affSColin Finck         NULL, OK, ER );
1601c2c66affSColin Finck     TMII_DONE
1602c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1603c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1604c2c66affSColin Finck         MFT_BITMAP|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1605c2c66affSColin Finck         NULL, OK, ER );
1606c2c66affSColin Finck     TMII_DONE
1607c2c66affSColin Finck      /* SEPARATOR and STRING go well together */
1608c2c66affSColin Finck     /* BITMAP and STRING go well together */
1609c2c66affSColin Finck     TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1610c2c66affSColin Finck     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1611c2c66affSColin Finck         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1612c2c66affSColin Finck         txt, OK, OK );
1613c2c66affSColin Finck     TMII_DONE
1614c2c66affSColin Finck      /* BITMAP, SEPARATOR and STRING go well together */
1615c2c66affSColin Finck     TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1616c2c66affSColin Finck     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1617c2c66affSColin Finck         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1618c2c66affSColin Finck         txt, OK, OK );
1619c2c66affSColin Finck     TMII_DONE
1620c2c66affSColin Finck      /* last two tests, but use MIIM_TYPE to retrieve info */
1621c2c66affSColin Finck     TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1622c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1623c2c66affSColin Finck         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1624c2c66affSColin Finck         NULL, OK, OK );
1625c2c66affSColin Finck     TMII_DONE
1626c2c66affSColin Finck     TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1627c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1628c2c66affSColin Finck         MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1629c2c66affSColin Finck         NULL, OK, OK );
1630c2c66affSColin Finck     TMII_DONE
1631c2c66affSColin Finck     TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1632c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1633c2c66affSColin Finck         MFT_SEPARATOR|MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1634c2c66affSColin Finck         NULL, OK, OK );
1635c2c66affSColin Finck     TMII_DONE
1636c2c66affSColin Finck      /* same three with MFT_OWNERDRAW */
1637c2c66affSColin Finck     TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1638c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1639c2c66affSColin Finck         MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1640c2c66affSColin Finck         NULL, OK, OK );
1641c2c66affSColin Finck     TMII_DONE
1642c2c66affSColin Finck     TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1643c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1644c2c66affSColin Finck         MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1645c2c66affSColin Finck         NULL, OK, OK );
1646c2c66affSColin Finck     TMII_DONE
1647c2c66affSColin Finck     TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1648c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1649c2c66affSColin Finck         MFT_SEPARATOR|MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1650c2c66affSColin Finck         NULL, OK, OK );
1651c2c66affSColin Finck     TMII_DONE
1652c2c66affSColin Finck 
1653c2c66affSColin Finck     TMII_INSMI( MIIM_STRING|MIIM_FTYPE|MIIM_ID, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1654c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1655c2c66affSColin Finck         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1656c2c66affSColin Finck         NULL,  OK, OK );
1657c2c66affSColin Finck     TMII_DONE
1658c2c66affSColin Finck     /* test with modifymenu: string is preserved after setting OWNERDRAW */
1659c2c66affSColin Finck     TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1660c2c66affSColin Finck     TMII_MODM( MFT_OWNERDRAW, -1, (void*)787 );
1661c2c66affSColin Finck     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_DATA, 80,
1662c2c66affSColin Finck         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 787, string, 4, 0,
1663c2c66affSColin Finck         txt,  OK, OK );
1664c2c66affSColin Finck     TMII_DONE
1665c2c66affSColin Finck     /* same with bitmap: now the text is cleared */
1666c2c66affSColin Finck     TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1667c2c66affSColin Finck     TMII_MODM( MFT_BITMAP, 545, hbm );
1668c2c66affSColin Finck     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1669c2c66affSColin Finck         MFT_BITMAP, 0, 545, 0, 0, 0, 0, string, 0, hbm,
1670c2c66affSColin Finck         empty,  OK, ER );
1671c2c66affSColin Finck     TMII_DONE
1672c2c66affSColin Finck     /* start with bitmap: now setting text clears it (though he flag is raised) */
1673c2c66affSColin Finck     TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1674c2c66affSColin Finck     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1675c2c66affSColin Finck         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 0, hbm,
1676c2c66affSColin Finck         empty,  OK, ER );
1677c2c66affSColin Finck     TMII_MODM( MFT_STRING, 545, txt );
1678c2c66affSColin Finck     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1679c2c66affSColin Finck         MFT_STRING, 0, 545, 0, 0, 0, 0, string, 4, 0,
1680c2c66affSColin Finck         txt,  OK, OK );
1681c2c66affSColin Finck     TMII_DONE
1682c2c66affSColin Finck     /*repeat with text NULL */
1683c2c66affSColin Finck     TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1684c2c66affSColin Finck     TMII_MODM( MFT_STRING, 545, NULL );
1685c2c66affSColin Finck     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1686c2c66affSColin Finck         MFT_SEPARATOR, 0, 545, 0, 0, 0, 0, string, 0, 0,
1687c2c66affSColin Finck         empty,  OK, ER );
1688c2c66affSColin Finck     TMII_DONE
1689c2c66affSColin Finck     /* repeat with text "" */
1690c2c66affSColin Finck     TMII_INSMI( MIIM_BITMAP, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1691c2c66affSColin Finck     TMII_MODM( MFT_STRING, 545, empty );
1692c2c66affSColin Finck     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1693c2c66affSColin Finck         MFT_STRING, 0, 545, 0, 0, 0, 0, string, 0, 0,
1694c2c66affSColin Finck         empty,  OK, ER );
1695c2c66affSColin Finck     TMII_DONE
1696c2c66affSColin Finck     /* start with bitmap: set ownerdraw */
1697c2c66affSColin Finck     TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1698c2c66affSColin Finck     TMII_MODM( MFT_OWNERDRAW, -1, (void *)232 );
1699c2c66affSColin Finck     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_DATA, 80,
1700c2c66affSColin Finck         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 232, string, 0, hbm,
1701c2c66affSColin Finck         empty,  OK, ER );
1702c2c66affSColin Finck     TMII_DONE
1703c2c66affSColin Finck     /* ask nothing */
1704c2c66affSColin Finck     TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1705c2c66affSColin Finck     TMII_GMII ( 0, 80,
1706c2c66affSColin Finck                 0, 0, 0,  0, 0, 0, 0, string, 80, 0,
1707c2c66affSColin Finck         init, OK, OK );
1708c2c66affSColin Finck     TMII_DONE
1709c2c66affSColin Finck     /* some tests with small cbSize: the hbmpItem is to be ignored */
1710c2c66affSColin Finck     TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1711c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1712c2c66affSColin Finck         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1713c2c66affSColin Finck         NULL, OK, ER );
1714c2c66affSColin Finck     TMII_DONE
1715c2c66affSColin Finck     TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1716c2c66affSColin Finck     TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1717c2c66affSColin Finck         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, NULL,
1718c2c66affSColin Finck         init, OK, ER );
1719c2c66affSColin Finck     TMII_DONE
1720c2c66affSColin Finck     TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1721c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1722c2c66affSColin Finck         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, NULL,
1723c2c66affSColin Finck         txt, OK, OK );
1724c2c66affSColin Finck     TMII_DONE
1725c2c66affSColin Finck     TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1726c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1727c2c66affSColin Finck         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1728c2c66affSColin Finck         NULL, OK, OK );
1729c2c66affSColin Finck     TMII_DONE
1730c2c66affSColin Finck     TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1731c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1732c2c66affSColin Finck         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1733c2c66affSColin Finck         NULL, OK, OK );
1734c2c66affSColin Finck     TMII_DONE
1735c2c66affSColin Finck     TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1736c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1737c2c66affSColin Finck         MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1738c2c66affSColin Finck         NULL, OK, OK );
1739c2c66affSColin Finck     TMII_DONE
1740c2c66affSColin Finck     /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus  */
1741c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1742c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1743c2c66affSColin Finck         MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1744c2c66affSColin Finck         NULL, OK, ER );
1745c2c66affSColin Finck     TMII_DONE
1746c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1747c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1748c2c66affSColin Finck         MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1749c2c66affSColin Finck         NULL, OK, ER );
1750c2c66affSColin Finck     TMII_DONE
1751c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1752c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1753c2c66affSColin Finck         MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1754c2c66affSColin Finck         NULL, OK, ER );
1755c2c66affSColin Finck     TMII_DONE
1756c2c66affSColin Finck     /* set a string menu to ownerdraw with MIIM_TYPE */
1757c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_STRING, -2, -2, 0, 0, 0, -2, txt, -2, 0, OK );
1758c2c66affSColin Finck     TMII_SMII ( MIIM_TYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1759c2c66affSColin Finck     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1760c2c66affSColin Finck         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1761c2c66affSColin Finck         txt, OK, OK );
1762c2c66affSColin Finck     TMII_DONE
1763c2c66affSColin Finck     /* test with modifymenu add submenu */
1764c2c66affSColin Finck     TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1765c2c66affSColin Finck     TMII_MODM( MF_POPUP, (UINT_PTR)submenu, txt );
1766c2c66affSColin Finck     TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_SUBMENU, 80,
1767c2c66affSColin Finck         MFT_STRING, 0, 0, submenu, 0, 0, 0, string, 4, 0,
1768c2c66affSColin Finck         txt,  OK, OK );
1769c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1770c2c66affSColin Finck         MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1771c2c66affSColin Finck         txt,  OK, OK );
1772c2c66affSColin Finck     TMII_DONE
1773c2c66affSColin Finck     /* MFT_SEPARATOR bit is kept when the text is added */
1774c2c66affSColin Finck     TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1775c2c66affSColin Finck     TMII_SMII( MIIM_STRING, 0, 0, 0, 0, 0, 0, 0, txt, 0, 0 );
1776c2c66affSColin Finck     TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1777c2c66affSColin Finck         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, 0,
1778c2c66affSColin Finck         txt, OK, OK );
1779c2c66affSColin Finck     TMII_DONE
1780c2c66affSColin Finck     /* MFT_SEPARATOR bit is kept when bitmap is added */
1781c2c66affSColin Finck     TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1782c2c66affSColin Finck     TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm );
1783c2c66affSColin Finck     TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1784c2c66affSColin Finck         MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1785c2c66affSColin Finck         init, OK, ER );
1786c2c66affSColin Finck     TMII_DONE
1787c2c66affSColin Finck     /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1788c2c66affSColin Finck        Only the low word of the dwTypeData is used.
1789c2c66affSColin Finck        Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1790c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1791*7a62c32bSAmine Khaldi                 (HMENU)MAKELPARAM(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1792c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1793c2c66affSColin Finck         MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1794c2c66affSColin Finck         NULL, OK, OK );
1795c2c66affSColin Finck     TMII_DONE
1796c2c66affSColin Finck     /* Type flags */
1797c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1798c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1799c2c66affSColin Finck         MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1800c2c66affSColin Finck         NULL, OK, OK );
1801c2c66affSColin Finck     TMII_DONE
1802c2c66affSColin Finck     /* State flags */
1803c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1804c2c66affSColin Finck     TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1805c2c66affSColin Finck     TMII_GMII ( MIIM_STATE, 80,
1806c2c66affSColin Finck         0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1807c2c66affSColin Finck         NULL, OK, OK );
1808c2c66affSColin Finck     TMII_DONE
1809c2c66affSColin Finck     /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1810c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1811c2c66affSColin Finck     TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1812c2c66affSColin Finck     TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1813c2c66affSColin Finck         MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1814c2c66affSColin Finck         NULL, OK, OK );
1815c2c66affSColin Finck     TMII_DONE
1816c2c66affSColin Finck     /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1817c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1818c2c66affSColin Finck     TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1819c2c66affSColin Finck     TMII_GMII ( MIIM_FTYPE, 80,
1820c2c66affSColin Finck         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1821c2c66affSColin Finck         NULL, OK, OK );
1822c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1823c2c66affSColin Finck         MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1824c2c66affSColin Finck         NULL, OK, OK );
1825c2c66affSColin Finck     TMII_GMII ( MIIM_FTYPE, 80,
1826c2c66affSColin Finck         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1827c2c66affSColin Finck         NULL, OK, OK );
1828c2c66affSColin Finck     TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1829c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1830c2c66affSColin Finck         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1831c2c66affSColin Finck         NULL, OK, OK );
1832c2c66affSColin Finck     TMII_DONE
1833c2c66affSColin Finck     /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1834c2c66affSColin Finck        Only the low word of the dwTypeData is used.
1835c2c66affSColin Finck        Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1836c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1837*7a62c32bSAmine Khaldi                 (HMENU)MAKELPARAM(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1838c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1839c2c66affSColin Finck         MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1840c2c66affSColin Finck         NULL, OK, OK );
1841c2c66affSColin Finck     TMII_DONE
1842c2c66affSColin Finck     /* Type flags */
1843c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1844c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1845c2c66affSColin Finck         MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1846c2c66affSColin Finck         NULL, OK, OK );
1847c2c66affSColin Finck     TMII_DONE
1848c2c66affSColin Finck     /* State flags */
1849c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1850c2c66affSColin Finck     TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1851c2c66affSColin Finck     TMII_GMII ( MIIM_STATE, 80,
1852c2c66affSColin Finck         0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1853c2c66affSColin Finck         NULL, OK, OK );
1854c2c66affSColin Finck     TMII_DONE
1855c2c66affSColin Finck     /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1856c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1857c2c66affSColin Finck     TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1858c2c66affSColin Finck     TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1859c2c66affSColin Finck         MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1860c2c66affSColin Finck         NULL, OK, OK );
1861c2c66affSColin Finck     TMII_DONE
1862c2c66affSColin Finck     /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1863c2c66affSColin Finck     TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1864c2c66affSColin Finck     TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1865c2c66affSColin Finck     TMII_GMII ( MIIM_FTYPE, 80,
1866c2c66affSColin Finck         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1867c2c66affSColin Finck         NULL, OK, OK );
1868c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1869c2c66affSColin Finck         MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1870c2c66affSColin Finck         NULL, OK, OK );
1871c2c66affSColin Finck     TMII_GMII ( MIIM_FTYPE, 80,
1872c2c66affSColin Finck         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1873c2c66affSColin Finck         NULL, OK, OK );
1874c2c66affSColin Finck     TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1875c2c66affSColin Finck     TMII_GMII ( MIIM_TYPE, 80,
1876c2c66affSColin Finck         MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1877c2c66affSColin Finck         NULL, OK, OK );
1878c2c66affSColin Finck     TMII_DONE
1879c2c66affSColin Finck   } while( !(ansi = !ansi) );
1880c2c66affSColin Finck   DeleteObject( hbm);
1881c2c66affSColin Finck }
1882c2c66affSColin Finck 
1883c2c66affSColin Finck /*
1884c2c66affSColin Finck    The following tests try to confirm the algorithm used to return the menu items
1885c2c66affSColin Finck    when there is a collision between a menu item and a popup menu
1886c2c66affSColin Finck  */
test_menu_search_bycommand(void)1887c2c66affSColin Finck static void test_menu_search_bycommand( void )
1888c2c66affSColin Finck {
1889c2c66affSColin Finck     HMENU        hmenu, hmenuSub, hmenuSub2;
1890c2c66affSColin Finck     MENUITEMINFOA info;
1891c2c66affSColin Finck     BOOL         rc;
1892c2c66affSColin Finck     UINT         id;
1893c2c66affSColin Finck     char         strback[0x80];
1894c2c66affSColin Finck     char         strIn[0x80];
1895c2c66affSColin Finck     static CHAR menuitem[]  = "MenuItem",
1896c2c66affSColin Finck                 menuitem2[] = "MenuItem 2";
1897c2c66affSColin Finck 
1898c2c66affSColin Finck     /* Case 1: Menu containing a menu item */
1899c2c66affSColin Finck     hmenu = CreateMenu();
1900c2c66affSColin Finck 
1901c2c66affSColin Finck     memset( &info, 0, sizeof info );
1902c2c66affSColin Finck     info.cbSize = sizeof info;
1903c2c66affSColin Finck     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1904c2c66affSColin Finck     info.fType = MFT_STRING;
1905c2c66affSColin Finck     strcpy(strIn, "Case 1 MenuItem");
1906c2c66affSColin Finck     info.dwTypeData = strIn;
1907c2c66affSColin Finck     info.wID = (UINT) 0x1234;
1908c2c66affSColin Finck 
1909c2c66affSColin Finck     rc = InsertMenuItemA(hmenu, 0, TRUE, &info );
1910c2c66affSColin Finck     ok (rc, "Inserting the menuitem failed\n");
1911c2c66affSColin Finck 
1912c2c66affSColin Finck     id = GetMenuItemID(hmenu, 0);
1913c2c66affSColin Finck     ok (id == 0x1234, "Getting the menuitem id failed(gave %x)\n", id);
1914c2c66affSColin Finck 
1915c2c66affSColin Finck     /* Confirm the menuitem was given the id supplied (getting by position) */
1916c2c66affSColin Finck     memset( &info, 0, sizeof info );
1917c2c66affSColin Finck     strback[0] = 0x00;
1918c2c66affSColin Finck     info.cbSize = sizeof(MENUITEMINFOA);
1919c2c66affSColin Finck     info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1920c2c66affSColin Finck     info.dwTypeData = strback;
1921c2c66affSColin Finck     info.cch = sizeof(strback);
1922c2c66affSColin Finck 
1923c2c66affSColin Finck     rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info); /* Get by position */
1924c2c66affSColin Finck     ok (rc, "Getting the menu items info failed\n");
1925c2c66affSColin Finck     ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1926c2c66affSColin Finck     ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1927c2c66affSColin Finck 
1928c2c66affSColin Finck     /* Search by id - Should return the item */
1929c2c66affSColin Finck     memset( &info, 0, sizeof info );
1930c2c66affSColin Finck     strback[0] = 0x00;
1931c2c66affSColin Finck     info.cbSize = sizeof(MENUITEMINFOA);
1932c2c66affSColin Finck     info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1933c2c66affSColin Finck     info.dwTypeData = strback;
1934c2c66affSColin Finck     info.cch = sizeof(strback);
1935c2c66affSColin Finck     rc = GetMenuItemInfoA(hmenu, 0x1234, FALSE, &info); /* Get by ID */
1936c2c66affSColin Finck 
1937c2c66affSColin Finck     ok (rc, "Getting the menu items info failed\n");
1938c2c66affSColin Finck     ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1939c2c66affSColin Finck     ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1940c2c66affSColin Finck 
1941c2c66affSColin Finck     DestroyMenu( hmenu );
1942c2c66affSColin Finck 
1943c2c66affSColin Finck     /* Case 2: Menu containing a popup menu */
1944c2c66affSColin Finck     hmenu = CreateMenu();
1945c2c66affSColin Finck     hmenuSub = CreateMenu();
1946c2c66affSColin Finck 
1947c2c66affSColin Finck     strcpy(strIn, "Case 2 SubMenu");
1948c2c66affSColin Finck     rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, strIn);
1949c2c66affSColin Finck     ok (rc, "Inserting the popup menu into the main menu failed\n");
1950c2c66affSColin Finck 
1951c2c66affSColin Finck     id = GetMenuItemID(hmenu, 0);
1952c2c66affSColin Finck     ok (id == -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id);
1953c2c66affSColin Finck 
1954c2c66affSColin Finck     /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
1955c2c66affSColin Finck     memset( &info, 0, sizeof info );
1956c2c66affSColin Finck     strback[0] = 0x00;
1957c2c66affSColin Finck     info.cbSize = sizeof(MENUITEMINFOA);
1958c2c66affSColin Finck     info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1959c2c66affSColin Finck     info.dwTypeData = strback;
1960c2c66affSColin Finck     info.cch = sizeof(strback);
1961c2c66affSColin Finck     info.wID = 0xdeadbeef;
1962c2c66affSColin Finck 
1963c2c66affSColin Finck     rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info); /* Get by position */
1964c2c66affSColin Finck     ok (rc, "Getting the menu items info failed\n");
1965c2c66affSColin Finck     ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the menuitem\n");
1966c2c66affSColin Finck     ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1967c2c66affSColin Finck 
1968c2c66affSColin Finck     /* Search by id - returns the popup menu itself */
1969c2c66affSColin Finck     memset( &info, 0, sizeof info );
1970c2c66affSColin Finck     strback[0] = 0x00;
1971c2c66affSColin Finck     info.cbSize = sizeof(MENUITEMINFOA);
1972c2c66affSColin Finck     info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1973c2c66affSColin Finck     info.dwTypeData = strback;
1974c2c66affSColin Finck     info.cch = sizeof(strback);
1975c2c66affSColin Finck     rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
1976c2c66affSColin Finck 
1977c2c66affSColin Finck     ok (rc, "Getting the menu items info failed\n");
1978c2c66affSColin Finck     ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
1979c2c66affSColin Finck     ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
1980c2c66affSColin Finck 
1981c2c66affSColin Finck     /*
1982c2c66affSColin Finck         Now add an item after it with the same id
1983c2c66affSColin Finck      */
1984c2c66affSColin Finck     memset( &info, 0, sizeof info );
1985c2c66affSColin Finck     info.cbSize = sizeof info;
1986c2c66affSColin Finck     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1987c2c66affSColin Finck     info.fType = MFT_STRING;
1988c2c66affSColin Finck     strcpy(strIn, "Case 2 MenuItem 1");
1989c2c66affSColin Finck     info.dwTypeData = strIn;
1990c2c66affSColin Finck     info.wID = (UINT_PTR) hmenuSub;
1991c2c66affSColin Finck     rc = InsertMenuItemA(hmenu, -1, TRUE, &info );
1992c2c66affSColin Finck     ok (rc, "Inserting the menuitem failed\n");
1993c2c66affSColin Finck 
1994c2c66affSColin Finck     /* Search by id - returns the item which follows the popup menu */
1995c2c66affSColin Finck     memset( &info, 0, sizeof info );
1996c2c66affSColin Finck     strback[0] = 0x00;
1997c2c66affSColin Finck     info.cbSize = sizeof(MENUITEMINFOA);
1998c2c66affSColin Finck     info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1999c2c66affSColin Finck     info.dwTypeData = strback;
2000c2c66affSColin Finck     info.cch = sizeof(strback);
2001c2c66affSColin Finck     rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
2002c2c66affSColin Finck 
2003c2c66affSColin Finck     ok (rc, "Getting the menu items info failed\n");
2004c2c66affSColin Finck     ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
2005c2c66affSColin Finck     ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2006c2c66affSColin Finck 
2007c2c66affSColin Finck     /*
2008c2c66affSColin Finck         Now add an item before the popup (with the same id)
2009c2c66affSColin Finck      */
2010c2c66affSColin Finck     memset( &info, 0, sizeof info );
2011c2c66affSColin Finck     info.cbSize = sizeof info;
2012c2c66affSColin Finck     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2013c2c66affSColin Finck     info.fType = MFT_STRING;
2014c2c66affSColin Finck     strcpy(strIn, "Case 2 MenuItem 2");
2015c2c66affSColin Finck     info.dwTypeData = strIn;
2016c2c66affSColin Finck     info.wID = (UINT_PTR) hmenuSub;
2017c2c66affSColin Finck     rc = InsertMenuItemA(hmenu, 0, TRUE, &info );
2018c2c66affSColin Finck     ok (rc, "Inserting the menuitem failed\n");
2019c2c66affSColin Finck 
2020c2c66affSColin Finck     /* Search by id - returns the item which precedes the popup menu */
2021c2c66affSColin Finck     memset( &info, 0, sizeof info );
2022c2c66affSColin Finck     strback[0] = 0x00;
2023c2c66affSColin Finck     info.cbSize = sizeof(MENUITEMINFOA);
2024c2c66affSColin Finck     info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
2025c2c66affSColin Finck     info.dwTypeData = strback;
2026c2c66affSColin Finck     info.cch = sizeof(strback);
2027c2c66affSColin Finck     rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
2028c2c66affSColin Finck 
2029c2c66affSColin Finck     ok (rc, "Getting the menu items info failed\n");
2030c2c66affSColin Finck     ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
2031c2c66affSColin Finck     ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2032c2c66affSColin Finck 
2033c2c66affSColin Finck     DestroyMenu( hmenu );
2034c2c66affSColin Finck     DestroyMenu( hmenuSub );
2035c2c66affSColin Finck 
2036c2c66affSColin Finck     /*
2037c2c66affSColin Finck         Case 3: Menu containing a popup menu which in turn
2038c2c66affSColin Finck            contains 2 items with the same id as the popup itself
2039c2c66affSColin Finck      */
2040c2c66affSColin Finck 
2041c2c66affSColin Finck     hmenu = CreateMenu();
2042c2c66affSColin Finck     hmenuSub = CreateMenu();
2043c2c66affSColin Finck 
2044c2c66affSColin Finck     memset( &info, 0, sizeof info );
2045c2c66affSColin Finck     info.cbSize = sizeof info;
2046c2c66affSColin Finck     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2047c2c66affSColin Finck     info.fType = MFT_STRING;
2048c2c66affSColin Finck     info.dwTypeData = menuitem;
2049c2c66affSColin Finck     info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2050c2c66affSColin Finck 
2051c2c66affSColin Finck     rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
2052c2c66affSColin Finck     ok (rc, "Inserting the popup menu into the main menu failed\n");
2053c2c66affSColin Finck 
2054c2c66affSColin Finck     rc = InsertMenuItemA(hmenuSub, 0, TRUE, &info );
2055c2c66affSColin Finck     ok (rc, "Inserting the sub menu menuitem failed\n");
2056c2c66affSColin Finck 
2057c2c66affSColin Finck     memset( &info, 0, sizeof info );
2058c2c66affSColin Finck     info.cbSize = sizeof info;
2059c2c66affSColin Finck     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2060c2c66affSColin Finck     info.fType = MFT_STRING;
2061c2c66affSColin Finck     info.dwTypeData = menuitem2;
2062c2c66affSColin Finck     info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2063c2c66affSColin Finck 
2064c2c66affSColin Finck     rc = InsertMenuItemA(hmenuSub, 1, TRUE, &info );
2065c2c66affSColin Finck     ok (rc, "Inserting the sub menu menuitem 2 failed\n");
2066c2c66affSColin Finck 
2067c2c66affSColin Finck     /* Prove that you can't query the id of a popup directly (By position) */
2068c2c66affSColin Finck     id = GetMenuItemID(hmenu, 0);
2069c2c66affSColin Finck     ok (id == -1, "Getting the sub menu id should have failed because it's a popup (gave %x)\n", id);
2070c2c66affSColin Finck 
2071c2c66affSColin Finck     /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
2072c2c66affSColin Finck     memset( &info, 0, sizeof info );
2073c2c66affSColin Finck     strback[0] = 0x00;
2074c2c66affSColin Finck     info.cbSize = sizeof(MENUITEMINFOA);
2075c2c66affSColin Finck     info.fMask = MIIM_STRING | MIIM_ID;
2076c2c66affSColin Finck     info.dwTypeData = strback;
2077c2c66affSColin Finck     info.cch = sizeof(strback);
2078c2c66affSColin Finck 
2079c2c66affSColin Finck     rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
2080c2c66affSColin Finck     ok (rc, "Getting the menus info failed\n");
2081c2c66affSColin Finck     ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
2082c2c66affSColin Finck     ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2083c2c66affSColin Finck     DestroyMenu( hmenu );
2084c2c66affSColin Finck     DestroyMenu( hmenuSub );
2085c2c66affSColin Finck 
2086c2c66affSColin Finck     /*
2087c2c66affSColin Finck         Case 4: Menu containing 2 popup menus, the second
2088c2c66affSColin Finck            contains 2 items with the same id as the first popup menu
2089c2c66affSColin Finck      */
2090c2c66affSColin Finck     hmenu = CreateMenu();
2091c2c66affSColin Finck     hmenuSub = CreateMenu();
2092c2c66affSColin Finck     hmenuSub2 = CreateMenu();
2093c2c66affSColin Finck 
2094c2c66affSColin Finck     rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
2095c2c66affSColin Finck     ok (rc, "Inserting the popup menu into the main menu failed\n");
2096c2c66affSColin Finck 
2097c2c66affSColin Finck     rc = InsertMenuA(hmenu, 1, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub2, "Submenu2");
2098c2c66affSColin Finck     ok (rc, "Inserting the popup menu into the main menu failed\n");
2099c2c66affSColin Finck 
2100c2c66affSColin Finck     memset( &info, 0, sizeof info );
2101c2c66affSColin Finck     info.cbSize = sizeof info;
2102c2c66affSColin Finck     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2103c2c66affSColin Finck     info.fType = MFT_STRING;
2104c2c66affSColin Finck     info.dwTypeData = menuitem;
2105c2c66affSColin Finck     info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2106c2c66affSColin Finck 
2107c2c66affSColin Finck     rc = InsertMenuItemA(hmenuSub2, 0, TRUE, &info );
2108c2c66affSColin Finck     ok (rc, "Inserting the sub menu menuitem failed\n");
2109c2c66affSColin Finck 
2110c2c66affSColin Finck     memset( &info, 0, sizeof info );
2111c2c66affSColin Finck     info.cbSize = sizeof info;
2112c2c66affSColin Finck     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2113c2c66affSColin Finck     info.fType = MFT_STRING;
2114c2c66affSColin Finck     info.dwTypeData = menuitem2;
2115c2c66affSColin Finck     info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2116c2c66affSColin Finck 
2117c2c66affSColin Finck     rc = InsertMenuItemA(hmenuSub2, 1, TRUE, &info );
2118c2c66affSColin Finck     ok (rc, "Inserting the sub menu menuitem 2 failed\n");
2119c2c66affSColin Finck 
2120c2c66affSColin Finck     /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
2121c2c66affSColin Finck     memset( &info, 0, sizeof info );
2122c2c66affSColin Finck     strback[0] = 0x00;
2123c2c66affSColin Finck     info.cbSize = sizeof(MENUITEMINFOA);
2124c2c66affSColin Finck     info.fMask = MIIM_STRING | MIIM_ID;
2125c2c66affSColin Finck     info.dwTypeData = strback;
2126c2c66affSColin Finck     info.cch = sizeof(strback);
2127c2c66affSColin Finck 
2128c2c66affSColin Finck     rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
2129c2c66affSColin Finck     ok (rc, "Getting the menus info failed\n");
2130c2c66affSColin Finck     ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
2131c2c66affSColin Finck     ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2132c2c66affSColin Finck 
2133c2c66affSColin Finck     memset( &info, 0, sizeof info );
2134c2c66affSColin Finck     strback[0] = 0x00;
2135c2c66affSColin Finck     info.cbSize = sizeof(MENUITEMINFOA);
2136c2c66affSColin Finck     info.fMask = MIIM_STRING | MIIM_ID;
2137c2c66affSColin Finck     info.dwTypeData = strback;
2138c2c66affSColin Finck     info.cch = sizeof(strback);
2139c2c66affSColin Finck 
2140c2c66affSColin Finck     rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub2, FALSE, &info);
2141c2c66affSColin Finck     ok (rc, "Getting the menus info failed\n");
2142c2c66affSColin Finck     ok (info.wID == (UINT_PTR)hmenuSub2, "IDs differ for popup menu\n");
2143c2c66affSColin Finck     ok (!strcmp(info.dwTypeData, "Submenu2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2144c2c66affSColin Finck 
2145c2c66affSColin Finck     DestroyMenu( hmenu );
2146c2c66affSColin Finck     DestroyMenu( hmenuSub );
2147c2c66affSColin Finck     DestroyMenu( hmenuSub2 );
2148c2c66affSColin Finck 
2149c2c66affSColin Finck 
2150c2c66affSColin Finck     /*
2151c2c66affSColin Finck         Case 5: Menu containing a popup menu which in turn
2152c2c66affSColin Finck            contains an item with a different id than the popup menu.
2153c2c66affSColin Finck            This tests the fallback to a popup menu ID.
2154c2c66affSColin Finck      */
2155c2c66affSColin Finck 
2156c2c66affSColin Finck     hmenu = CreateMenu();
2157c2c66affSColin Finck     hmenuSub = CreateMenu();
2158c2c66affSColin Finck 
2159c2c66affSColin Finck     rc = AppendMenuA(hmenu, MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
2160c2c66affSColin Finck     ok (rc, "Appending the popup menu to the main menu failed\n");
2161c2c66affSColin Finck 
2162c2c66affSColin Finck     rc = AppendMenuA(hmenuSub, MF_STRING, 102, "Item");
2163c2c66affSColin Finck     ok (rc, "Appending the item to the popup menu failed\n");
2164c2c66affSColin Finck 
2165c2c66affSColin Finck     /* Set the ID for hmenuSub */
2166c2c66affSColin Finck     info.cbSize = sizeof(info);
2167c2c66affSColin Finck     info.fMask = MIIM_ID;
2168c2c66affSColin Finck     info.wID = 101;
2169c2c66affSColin Finck 
2170c2c66affSColin Finck     rc = SetMenuItemInfoA(hmenu, 0, TRUE, &info);
2171c2c66affSColin Finck     ok(rc, "Setting the ID for the popup menu failed\n");
2172c2c66affSColin Finck 
2173c2c66affSColin Finck     /* Check if the ID has been set */
2174c2c66affSColin Finck     info.wID = 0;
2175c2c66affSColin Finck     rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info);
2176c2c66affSColin Finck     ok(rc, "Getting the ID for the popup menu failed\n");
2177c2c66affSColin Finck     ok(info.wID == 101, "The ID for the popup menu has not been set\n");
2178c2c66affSColin Finck 
2179c2c66affSColin Finck     /* Prove getting the item info via ID returns the popup menu */
2180c2c66affSColin Finck     memset( &info, 0, sizeof(info));
2181c2c66affSColin Finck     strback[0] = 0x00;
2182c2c66affSColin Finck     info.cbSize = sizeof(MENUITEMINFOA);
2183c2c66affSColin Finck     info.fMask = MIIM_STRING | MIIM_ID;
2184c2c66affSColin Finck     info.dwTypeData = strback;
2185c2c66affSColin Finck     info.cch = sizeof(strback);
2186c2c66affSColin Finck 
2187c2c66affSColin Finck     rc = GetMenuItemInfoA(hmenu, 101, FALSE, &info);
2188c2c66affSColin Finck     ok (rc, "Getting the menu info failed\n");
2189c2c66affSColin Finck     ok (info.wID == 101, "IDs differ\n");
2190c2c66affSColin Finck     ok (!strcmp(info.dwTypeData, "Submenu"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2191c2c66affSColin Finck 
2192c2c66affSColin Finck     /* Also look for the menu item  */
2193c2c66affSColin Finck     memset( &info, 0, sizeof(info));
2194c2c66affSColin Finck     strback[0] = 0x00;
2195c2c66affSColin Finck     info.cbSize = sizeof(MENUITEMINFOA);
2196c2c66affSColin Finck     info.fMask = MIIM_STRING | MIIM_ID;
2197c2c66affSColin Finck     info.dwTypeData = strback;
2198c2c66affSColin Finck     info.cch = sizeof(strback);
2199c2c66affSColin Finck 
2200c2c66affSColin Finck     rc = GetMenuItemInfoA(hmenu, 102, FALSE, &info);
2201c2c66affSColin Finck     ok (rc, "Getting the menu info failed\n");
2202c2c66affSColin Finck     ok (info.wID == 102, "IDs differ\n");
2203c2c66affSColin Finck     ok (!strcmp(info.dwTypeData, "Item"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2204c2c66affSColin Finck 
2205c2c66affSColin Finck     DestroyMenu(hmenu);
2206c2c66affSColin Finck     DestroyMenu(hmenuSub);
2207c2c66affSColin Finck }
2208c2c66affSColin Finck 
2209c2c66affSColin Finck struct menu_item_pair_s {
2210c2c66affSColin Finck     UINT uMenu; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
2211c2c66affSColin Finck                  * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
2212c2c66affSColin Finck                  * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
2213c2c66affSColin Finck     UINT uItem;
2214c2c66affSColin Finck };
2215c2c66affSColin Finck 
2216c2c66affSColin Finck static struct menu_mouse_tests_s {
2217c2c66affSColin Finck     DWORD type;
2218c2c66affSColin Finck     struct menu_item_pair_s menu_item_pairs[5]; /* for mousing */
2219c2c66affSColin Finck     WORD wVk[5]; /* keys */
2220c2c66affSColin Finck     BOOL bMenuVisible;
2221c2c66affSColin Finck     BOOL _todo_wine;
2222c2c66affSColin Finck } menu_tests[] = {
2223c2c66affSColin Finck     /* for each test, send keys or clicks and check for menu visibility */
2224c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE }, /* test 0 */
2225c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
2226c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
2227c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2228c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
2229c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2230c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2231c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, VK_ESCAPE, 0}, FALSE, FALSE },
2232c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', VK_ESCAPE, 0}, TRUE, FALSE },
2233c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
2234c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2235c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2236c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2237c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2238c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
2239c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2240c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
2241c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2242c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, TRUE, FALSE },
2243c2c66affSColin Finck     { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, FALSE, FALSE },
2244c2c66affSColin Finck 
2245*7a62c32bSAmine Khaldi     { INPUT_MOUSE, {{1, 2}, {0}}, {0}, TRUE, FALSE }, /* test 20 */
2246c2c66affSColin Finck     { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2247*7a62c32bSAmine Khaldi     { INPUT_MOUSE, {{1, 0}, {0}}, {0}, TRUE, FALSE },
2248c2c66affSColin Finck     { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2249*7a62c32bSAmine Khaldi     { INPUT_MOUSE, {{1, 0}, {2, 2}, {0}}, {0}, TRUE, FALSE },
2250c2c66affSColin Finck     { INPUT_MOUSE, {{2, 1}, {0}}, {0}, FALSE, FALSE },
2251*7a62c32bSAmine Khaldi     { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, FALSE },
2252c2c66affSColin Finck     { INPUT_MOUSE, {{3, 0}, {0}}, {0}, FALSE, FALSE },
2253*7a62c32bSAmine Khaldi     { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, FALSE },
2254*7a62c32bSAmine Khaldi     { INPUT_MOUSE, {{3, 1}, {0}}, {0}, TRUE, FALSE },
2255c2c66affSColin Finck     { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2256c2c66affSColin Finck     { -1 }
2257c2c66affSColin Finck };
2258c2c66affSColin Finck 
send_key(WORD wVk)2259c2c66affSColin Finck static void send_key(WORD wVk)
2260c2c66affSColin Finck {
2261c2c66affSColin Finck     TEST_INPUT i[2];
2262c2c66affSColin Finck     memset(i, 0, sizeof(i));
2263c2c66affSColin Finck     i[0].type = i[1].type = INPUT_KEYBOARD;
2264c2c66affSColin Finck     i[0].u.ki.wVk = i[1].u.ki.wVk = wVk;
2265c2c66affSColin Finck     i[1].u.ki.dwFlags = KEYEVENTF_KEYUP;
2266*7a62c32bSAmine Khaldi     SendInput(2, (INPUT *) i, sizeof(INPUT));
2267c2c66affSColin Finck }
2268c2c66affSColin Finck 
click_menu(HANDLE hWnd,struct menu_item_pair_s * mi)2269c2c66affSColin Finck static BOOL click_menu(HANDLE hWnd, struct menu_item_pair_s *mi)
2270c2c66affSColin Finck {
2271c2c66affSColin Finck     HMENU hMenu = hMenus[mi->uMenu];
2272c2c66affSColin Finck     TEST_INPUT i[3];
2273c2c66affSColin Finck     MSG msg;
2274c2c66affSColin Finck     RECT r;
2275c2c66affSColin Finck     int screen_w = GetSystemMetrics(SM_CXSCREEN);
2276c2c66affSColin Finck     int screen_h = GetSystemMetrics(SM_CYSCREEN);
2277c2c66affSColin Finck     BOOL ret = GetMenuItemRect(mi->uMenu > 2 ? NULL : hWnd, hMenu, mi->uItem, &r);
2278c2c66affSColin Finck     if(!ret) return FALSE;
2279c2c66affSColin Finck 
2280c2c66affSColin Finck     memset(i, 0, sizeof(i));
2281c2c66affSColin Finck     i[0].type = i[1].type = i[2].type = INPUT_MOUSE;
2282c2c66affSColin Finck     i[0].u.mi.dx = i[1].u.mi.dx = i[2].u.mi.dx
2283c2c66affSColin Finck             = ((r.left + 5) * 65535) / screen_w;
2284c2c66affSColin Finck     i[0].u.mi.dy = i[1].u.mi.dy = i[2].u.mi.dy
2285c2c66affSColin Finck             = ((r.top + 5) * 65535) / screen_h;
2286c2c66affSColin Finck     i[0].u.mi.dwFlags = i[1].u.mi.dwFlags = i[2].u.mi.dwFlags
2287c2c66affSColin Finck             = MOUSEEVENTF_ABSOLUTE;
2288c2c66affSColin Finck     i[0].u.mi.dwFlags |= MOUSEEVENTF_MOVE;
2289c2c66affSColin Finck     i[1].u.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
2290c2c66affSColin Finck     i[2].u.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
2291*7a62c32bSAmine Khaldi     ret = SendInput(3, (INPUT *) i, sizeof(INPUT));
2292c2c66affSColin Finck 
2293c2c66affSColin Finck     /* hack to prevent mouse message buildup in Wine */
2294c2c66affSColin Finck     while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
2295c2c66affSColin Finck     return ret;
2296c2c66affSColin Finck }
2297c2c66affSColin Finck 
test_menu_input_thread(LPVOID lpParameter)2298c2c66affSColin Finck static DWORD WINAPI test_menu_input_thread(LPVOID lpParameter)
2299c2c66affSColin Finck {
2300c2c66affSColin Finck     int i, j;
2301c2c66affSColin Finck     HANDLE hWnd = lpParameter;
2302c2c66affSColin Finck 
2303c2c66affSColin Finck     Sleep(500);
2304c2c66affSColin Finck     /* mixed keyboard/mouse test */
2305c2c66affSColin Finck     for (i = 0; menu_tests[i].type != -1; i++)
2306c2c66affSColin Finck     {
2307c2c66affSColin Finck         BOOL ret = TRUE;
2308*7a62c32bSAmine Khaldi         int elapsed;
2309c2c66affSColin Finck 
2310c2c66affSColin Finck         got_input = i && menu_tests[i-1].bMenuVisible;
2311c2c66affSColin Finck 
2312c2c66affSColin Finck         if (menu_tests[i].type == INPUT_KEYBOARD)
2313c2c66affSColin Finck             for (j = 0; menu_tests[i].wVk[j] != 0; j++)
2314c2c66affSColin Finck                 send_key(menu_tests[i].wVk[j]);
2315c2c66affSColin Finck         else
2316c2c66affSColin Finck             for (j = 0; menu_tests[i].menu_item_pairs[j].uMenu != 0; j++)
2317*7a62c32bSAmine Khaldi             {
2318*7a62c32bSAmine Khaldi                 /* Maybe clicking too fast before menu is initialized. Sleep 100 ms and retry */
2319*7a62c32bSAmine Khaldi                 elapsed = 0;
2320*7a62c32bSAmine Khaldi                 while (!(ret = click_menu(hWnd, &menu_tests[i].menu_item_pairs[j])))
2321*7a62c32bSAmine Khaldi                 {
2322*7a62c32bSAmine Khaldi                     if (elapsed > 1000) break;
2323*7a62c32bSAmine Khaldi                     elapsed += 100;
2324*7a62c32bSAmine Khaldi                     Sleep(100);
2325*7a62c32bSAmine Khaldi                 }
2326*7a62c32bSAmine Khaldi             }
2327c2c66affSColin Finck 
2328c2c66affSColin Finck         if (!ret)
2329c2c66affSColin Finck         {
2330c2c66affSColin Finck             skip( "test %u: failed to send input\n", i );
2331c2c66affSColin Finck             PostMessageA( hWnd, WM_CANCELMODE, 0, 0 );
2332c2c66affSColin Finck             return 0;
2333c2c66affSColin Finck         }
2334*7a62c32bSAmine Khaldi 
2335*7a62c32bSAmine Khaldi         elapsed = 0;
2336c2c66affSColin Finck         while (menu_tests[i].bMenuVisible != bMenuVisible)
2337c2c66affSColin Finck         {
2338c2c66affSColin Finck             if (elapsed > 200)
2339c2c66affSColin Finck                 break;
2340c2c66affSColin Finck             elapsed += 20;
2341c2c66affSColin Finck             Sleep(20);
2342c2c66affSColin Finck         }
2343c2c66affSColin Finck 
2344c2c66affSColin Finck         if (!got_input)
2345c2c66affSColin Finck         {
2346c2c66affSColin Finck             skip( "test %u: didn't receive input\n", i );
2347c2c66affSColin Finck             PostMessageA( hWnd, WM_CANCELMODE, 0, 0 );
2348c2c66affSColin Finck             return 0;
2349c2c66affSColin Finck         }
2350c2c66affSColin Finck 
2351c2c66affSColin Finck         todo_wine_if (menu_tests[i]._todo_wine)
2352c2c66affSColin Finck             ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
2353c2c66affSColin Finck     }
2354c2c66affSColin Finck     return 0;
2355c2c66affSColin Finck }
2356c2c66affSColin Finck 
WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)2357c2c66affSColin Finck static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam,
2358c2c66affSColin Finck         LPARAM lParam)
2359c2c66affSColin Finck {
2360*7a62c32bSAmine Khaldi     MENUBARINFO mbi;
2361*7a62c32bSAmine Khaldi     HMENU hmenu;
2362*7a62c32bSAmine Khaldi     UINT state;
2363*7a62c32bSAmine Khaldi     BOOL br;
2364*7a62c32bSAmine Khaldi 
2365c2c66affSColin Finck     switch (msg) {
2366c2c66affSColin Finck         case WM_ENTERMENULOOP:
2367c2c66affSColin Finck             bMenuVisible = TRUE;
2368c2c66affSColin Finck             break;
2369c2c66affSColin Finck         case WM_INITMENUPOPUP:
2370c2c66affSColin Finck         case WM_UNINITMENUPOPUP:
2371c2c66affSColin Finck         case WM_EXITMENULOOP:
2372c2c66affSColin Finck         case WM_MENUSELECT:
2373c2c66affSColin Finck             break;
2374c2c66affSColin Finck 
2375c2c66affSColin Finck         case WM_KEYDOWN:
2376c2c66affSColin Finck         case WM_SYSKEYDOWN:
2377c2c66affSColin Finck         case WM_MOUSEMOVE:
2378c2c66affSColin Finck         case WM_LBUTTONDOWN:
2379c2c66affSColin Finck         case WM_LBUTTONUP:
2380c2c66affSColin Finck         case WM_NCMOUSEMOVE:
2381c2c66affSColin Finck         case WM_NCLBUTTONDOWN:
2382c2c66affSColin Finck         case WM_NCLBUTTONUP:
2383c2c66affSColin Finck             got_input = TRUE;
2384c2c66affSColin Finck             /* fall through */
2385c2c66affSColin Finck         default:
2386c2c66affSColin Finck             return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2387c2c66affSColin Finck     }
2388c2c66affSColin Finck 
2389c2c66affSColin Finck     mbi.cbSize = sizeof(MENUBARINFO);
2390c2c66affSColin Finck 
2391c2c66affSColin Finck     /* get info for the menu */
2392*7a62c32bSAmine Khaldi     br = GetMenuBarInfo(hWnd, OBJID_MENU, 0, &mbi);
2393c2c66affSColin Finck     ok(br, "msg %x: GetMenuBarInfo failed\n", msg);
2394c2c66affSColin Finck     hmenu = GetMenu(hWnd);
2395c2c66affSColin Finck     ok(!mbi.hwndMenu, "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected NULL\n",
2396c2c66affSColin Finck             msg, mbi.hwndMenu);
2397c2c66affSColin Finck     ok(mbi.hMenu == hmenu, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2398c2c66affSColin Finck             msg, mbi.hMenu, hmenu);
2399c2c66affSColin Finck     ok(!bMenuVisible == !mbi.fBarFocused, "msg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2400c2c66affSColin Finck             msg, mbi.fBarFocused != 0);
2401c2c66affSColin Finck     ok(!bMenuVisible == !mbi.fFocused, "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n",
2402c2c66affSColin Finck             msg, mbi.fFocused != 0);
2403c2c66affSColin Finck 
2404c2c66affSColin Finck     /* get info for the menu's first item */
2405*7a62c32bSAmine Khaldi     br = GetMenuBarInfo(hWnd, OBJID_MENU, 1, &mbi);
2406c2c66affSColin Finck     ok(br, "msg %x: GetMenuBarInfo failed\n", msg);
2407c2c66affSColin Finck     state = GetMenuState(hmenu, 0, MF_BYPOSITION);
2408c2c66affSColin Finck     /* Native returns handle to destroyed window */
2409c2c66affSColin Finck     todo_wine_if (msg==WM_UNINITMENUPOPUP && popmenu==1)
2410c2c66affSColin Finck         ok(!mbi.hwndMenu == !popmenu,
2411c2c66affSColin Finck             "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected %sNULL\n",
2412c2c66affSColin Finck             msg, mbi.hwndMenu, popmenu ? "not " : "");
2413c2c66affSColin Finck     ok(mbi.hMenu == hmenu, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2414c2c66affSColin Finck             msg, mbi.hMenu, hmenu);
2415c2c66affSColin Finck     ok(!bMenuVisible == !mbi.fBarFocused, "nsg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2416c2c66affSColin Finck             msg, mbi.fBarFocused != 0);
2417c2c66affSColin Finck     ok(!(bMenuVisible && (state & MF_HILITE)) == !mbi.fFocused,
2418c2c66affSColin Finck             "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n", msg, mbi.fFocused != 0);
2419c2c66affSColin Finck 
2420c2c66affSColin Finck     if (msg == WM_EXITMENULOOP)
2421c2c66affSColin Finck         bMenuVisible = FALSE;
2422c2c66affSColin Finck     else if (msg == WM_INITMENUPOPUP)
2423c2c66affSColin Finck         popmenu++;
2424c2c66affSColin Finck     else if (msg == WM_UNINITMENUPOPUP)
2425c2c66affSColin Finck         popmenu--;
2426c2c66affSColin Finck     return 0;
2427c2c66affSColin Finck }
2428c2c66affSColin Finck 
test_menu_input(void)2429c2c66affSColin Finck static void test_menu_input(void) {
2430c2c66affSColin Finck     MSG msg;
2431c2c66affSColin Finck     WNDCLASSA  wclass;
2432c2c66affSColin Finck     HINSTANCE hInstance = GetModuleHandleA( NULL );
2433c2c66affSColin Finck     HANDLE hThread, hWnd;
2434c2c66affSColin Finck     DWORD tid;
2435c2c66affSColin Finck     ATOM aclass;
2436c2c66affSColin Finck     POINT orig_pos;
2437c2c66affSColin Finck 
2438c2c66affSColin Finck     wclass.lpszClassName = "MenuTestClass";
2439c2c66affSColin Finck     wclass.style         = CS_HREDRAW | CS_VREDRAW;
2440c2c66affSColin Finck     wclass.lpfnWndProc   = WndProc;
2441c2c66affSColin Finck     wclass.hInstance     = hInstance;
2442c2c66affSColin Finck     wclass.hIcon         = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
2443c2c66affSColin Finck     wclass.hCursor       = LoadCursorA( 0, (LPCSTR)IDC_ARROW );
2444c2c66affSColin Finck     wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2445c2c66affSColin Finck     wclass.lpszMenuName  = 0;
2446c2c66affSColin Finck     wclass.cbClsExtra    = 0;
2447c2c66affSColin Finck     wclass.cbWndExtra    = 0;
2448c2c66affSColin Finck     aclass = RegisterClassA( &wclass );
2449c2c66affSColin Finck     ok (aclass, "MenuTest class not created\n");
2450c2c66affSColin Finck     if (!aclass) return;
2451c2c66affSColin Finck     hWnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
2452c2c66affSColin Finck                           WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2453c2c66affSColin Finck                           400, 200, NULL, NULL, hInstance, NULL);
2454c2c66affSColin Finck     ok (hWnd != NULL, "MenuTest window not created\n");
2455c2c66affSColin Finck     if (!hWnd) return;
2456c2c66affSColin Finck     /* fixed menus */
2457c2c66affSColin Finck     hMenus[3] = CreatePopupMenu();
2458c2c66affSColin Finck     AppendMenuA(hMenus[3], MF_STRING, 0, "&Enabled");
2459c2c66affSColin Finck     AppendMenuA(hMenus[3], MF_STRING|MF_DISABLED, 0, "&Disabled");
2460c2c66affSColin Finck 
2461c2c66affSColin Finck     hMenus[2] = CreatePopupMenu();
2462c2c66affSColin Finck     AppendMenuA(hMenus[2], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[3], "&Popup");
2463c2c66affSColin Finck     AppendMenuA(hMenus[2], MF_STRING, 0, "&Enabled");
2464c2c66affSColin Finck     AppendMenuA(hMenus[2], MF_STRING|MF_DISABLED, 0, "&Disabled");
2465c2c66affSColin Finck 
2466c2c66affSColin Finck     hMenus[1] = CreateMenu();
2467c2c66affSColin Finck     AppendMenuA(hMenus[1], MF_STRING|MF_POPUP, (UINT_PTR) hMenus[2], "&Menu");
2468c2c66affSColin Finck     AppendMenuA(hMenus[1], MF_STRING, 0, "&Enabled");
2469c2c66affSColin Finck     AppendMenuA(hMenus[1], MF_STRING|MF_DISABLED, 0, "&Disabled");
2470c2c66affSColin Finck 
2471c2c66affSColin Finck     SetMenu(hWnd, hMenus[1]);
2472c2c66affSColin Finck     ShowWindow(hWnd, SW_SHOW);
2473c2c66affSColin Finck     UpdateWindow(hWnd);
2474c2c66affSColin Finck 
2475c2c66affSColin Finck     GetCursorPos(&orig_pos);
2476c2c66affSColin Finck 
2477c2c66affSColin Finck     hThread = CreateThread(NULL, 0, test_menu_input_thread, hWnd, 0, &tid);
2478c2c66affSColin Finck     while(1)
2479c2c66affSColin Finck     {
2480c2c66affSColin Finck         if (WAIT_TIMEOUT != WaitForSingleObject(hThread, 50))
2481c2c66affSColin Finck             break;
2482c2c66affSColin Finck         while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2483c2c66affSColin Finck     }
2484c2c66affSColin Finck     SetCursorPos(orig_pos.x, orig_pos.y);
2485c2c66affSColin Finck     DestroyWindow(hWnd);
2486c2c66affSColin Finck }
2487c2c66affSColin Finck 
test_menu_flags(void)2488c2c66affSColin Finck static void test_menu_flags( void )
2489c2c66affSColin Finck {
2490c2c66affSColin Finck     HMENU hMenu, hPopupMenu;
2491c2c66affSColin Finck 
2492c2c66affSColin Finck     hMenu = CreateMenu();
2493c2c66affSColin Finck     hPopupMenu = CreatePopupMenu();
2494c2c66affSColin Finck 
2495c2c66affSColin Finck     AppendMenuA(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2496c2c66affSColin Finck 
2497c2c66affSColin Finck     AppendMenuA(hPopupMenu, MF_STRING | MF_HILITE | MF_DEFAULT, 101, "Item 1");
2498c2c66affSColin Finck     InsertMenuA(hPopupMenu, 1, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 102, "Item 2");
2499c2c66affSColin Finck     AppendMenuA(hPopupMenu, MF_STRING, 103, "Item 3");
2500c2c66affSColin Finck     ModifyMenuA(hPopupMenu, 2, MF_BYPOSITION | MF_STRING | MF_HILITE | MF_DEFAULT, 103, "Item 3");
2501c2c66affSColin Finck 
2502c2c66affSColin Finck     ok(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_HILITE,
2503c2c66affSColin Finck       "AppendMenu should accept MF_HILITE\n");
2504c2c66affSColin Finck     ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2505c2c66affSColin Finck       "InsertMenu should accept MF_HILITE\n");
2506c2c66affSColin Finck     ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2507c2c66affSColin Finck       "ModifyMenu should accept MF_HILITE\n");
2508c2c66affSColin Finck 
2509c2c66affSColin Finck     ok(!(GetMenuState(hPopupMenu, 0, MF_BYPOSITION) & MF_DEFAULT),
2510c2c66affSColin Finck       "AppendMenu must not accept MF_DEFAULT\n");
2511c2c66affSColin Finck     ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_DEFAULT),
2512c2c66affSColin Finck       "InsertMenu must not accept MF_DEFAULT\n");
2513c2c66affSColin Finck     ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_DEFAULT),
2514c2c66affSColin Finck       "ModifyMenu must not accept MF_DEFAULT\n");
2515c2c66affSColin Finck 
2516c2c66affSColin Finck     DestroyMenu(hMenu);
2517c2c66affSColin Finck }
2518c2c66affSColin Finck 
test_menu_hilitemenuitem(void)2519c2c66affSColin Finck static void test_menu_hilitemenuitem( void )
2520c2c66affSColin Finck {
2521c2c66affSColin Finck     HMENU hMenu, hPopupMenu;
2522c2c66affSColin Finck     WNDCLASSA wclass;
2523c2c66affSColin Finck     HWND hWnd;
2524c2c66affSColin Finck     ATOM aclass;
2525c2c66affSColin Finck 
2526c2c66affSColin Finck     wclass.lpszClassName = "HiliteMenuTestClass";
2527c2c66affSColin Finck     wclass.style         = CS_HREDRAW | CS_VREDRAW;
2528c2c66affSColin Finck     wclass.lpfnWndProc   = WndProc;
2529c2c66affSColin Finck     wclass.hInstance     = GetModuleHandleA( NULL );
2530c2c66affSColin Finck     wclass.hIcon         = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
2531c2c66affSColin Finck     wclass.hCursor       = LoadCursorA( 0, (LPCSTR)IDC_ARROW );
2532c2c66affSColin Finck     wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2533c2c66affSColin Finck     wclass.lpszMenuName  = 0;
2534c2c66affSColin Finck     wclass.cbClsExtra    = 0;
2535c2c66affSColin Finck     wclass.cbWndExtra    = 0;
2536c2c66affSColin Finck     aclass = RegisterClassA( &wclass );
2537c2c66affSColin Finck     ok (aclass, "HiliteMenuTest class could not be created\n");
2538c2c66affSColin Finck     if (!aclass) return;
2539c2c66affSColin Finck     hWnd = CreateWindowA( wclass.lpszClassName, "HiliteMenuTest",
2540c2c66affSColin Finck                           WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2541c2c66affSColin Finck                           400, 200, NULL, NULL, wclass.hInstance, NULL);
2542c2c66affSColin Finck     ok (hWnd != NULL, "HiliteMenuTest window could not be created\n");
2543c2c66affSColin Finck     if (!hWnd) return;
2544c2c66affSColin Finck 
2545c2c66affSColin Finck     hMenu = CreateMenu();
2546c2c66affSColin Finck     hPopupMenu = CreatePopupMenu();
2547c2c66affSColin Finck 
2548c2c66affSColin Finck     AppendMenuA(hMenu, MF_POPUP | MF_STRING, (UINT_PTR)hPopupMenu, "Popup");
2549c2c66affSColin Finck 
2550c2c66affSColin Finck     AppendMenuA(hPopupMenu, MF_STRING, 101, "Item 1");
2551c2c66affSColin Finck     AppendMenuA(hPopupMenu, MF_STRING, 102, "Item 2");
2552c2c66affSColin Finck     AppendMenuA(hPopupMenu, MF_STRING, 103, "Item 3");
2553c2c66affSColin Finck 
2554c2c66affSColin Finck     SetMenu(hWnd, hMenu);
2555c2c66affSColin Finck 
2556c2c66affSColin Finck     /* test invalid arguments */
2557c2c66affSColin Finck 
2558c2c66affSColin Finck     ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2559c2c66affSColin Finck       "HiliteMenuItem: Item 2 is hilited\n");
2560c2c66affSColin Finck 
2561c2c66affSColin Finck     SetLastError(0xdeadbeef);
2562c2c66affSColin Finck     todo_wine
2563c2c66affSColin Finck     {
2564c2c66affSColin Finck     ok(!HiliteMenuItem(NULL, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2565c2c66affSColin Finck       "HiliteMenuItem: call should have failed.\n");
2566c2c66affSColin Finck     }
2567c2c66affSColin Finck     ok(GetLastError() == 0xdeadbeef || /* 9x */
2568c2c66affSColin Finck        GetLastError() == ERROR_INVALID_WINDOW_HANDLE /* NT */,
2569c2c66affSColin Finck       "HiliteMenuItem: expected error ERROR_INVALID_WINDOW_HANDLE, got: %d\n", GetLastError());
2570c2c66affSColin Finck 
2571c2c66affSColin Finck     SetLastError(0xdeadbeef);
2572c2c66affSColin Finck     ok(!HiliteMenuItem(hWnd, NULL, 1, MF_HILITE | MF_BYPOSITION),
2573c2c66affSColin Finck       "HiliteMenuItem: call should have failed.\n");
2574c2c66affSColin Finck     ok(GetLastError() == 0xdeadbeef || /* 9x */
2575c2c66affSColin Finck        GetLastError() == ERROR_INVALID_MENU_HANDLE /* NT */,
2576c2c66affSColin Finck       "HiliteMenuItem: expected error ERROR_INVALID_MENU_HANDLE, got: %d\n", GetLastError());
2577c2c66affSColin Finck 
2578c2c66affSColin Finck     ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2579c2c66affSColin Finck       "HiliteMenuItem: Item 2 is hilited\n");
2580c2c66affSColin Finck 
2581c2c66affSColin Finck     /* either MF_HILITE or MF_UNHILITE *and* MF_BYCOMMAND or MF_BYPOSITION need to be set */
2582c2c66affSColin Finck 
2583c2c66affSColin Finck     SetLastError(0xdeadbeef);
2584c2c66affSColin Finck     ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_BYPOSITION),
2585c2c66affSColin Finck       "HiliteMenuItem: call should have succeeded.\n");
2586c2c66affSColin Finck     ok(GetLastError() == 0xdeadbeef,
2587c2c66affSColin Finck       "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2588c2c66affSColin Finck 
2589c2c66affSColin Finck     ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2590c2c66affSColin Finck       "HiliteMenuItem: Item 2 is hilited\n");
2591c2c66affSColin Finck 
2592c2c66affSColin Finck     SetLastError(0xdeadbeef);
2593c2c66affSColin Finck     todo_wine
2594c2c66affSColin Finck     {
2595c2c66affSColin Finck     ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE),
2596c2c66affSColin Finck       "HiliteMenuItem: call should have succeeded.\n");
2597c2c66affSColin Finck     }
2598c2c66affSColin Finck     ok(GetLastError() == 0xdeadbeef,
2599c2c66affSColin Finck       "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2600c2c66affSColin Finck 
2601c2c66affSColin Finck     ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2602c2c66affSColin Finck       "HiliteMenuItem: Item 2 is hilited\n");
2603c2c66affSColin Finck 
2604c2c66affSColin Finck     /* hilite a menu item (by position) */
2605c2c66affSColin Finck 
2606c2c66affSColin Finck     SetLastError(0xdeadbeef);
2607c2c66affSColin Finck     ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_HILITE | MF_BYPOSITION),
2608c2c66affSColin Finck       "HiliteMenuItem: call should not have failed.\n");
2609c2c66affSColin Finck     ok(GetLastError() == 0xdeadbeef,
2610c2c66affSColin Finck       "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2611c2c66affSColin Finck 
2612c2c66affSColin Finck     todo_wine
2613c2c66affSColin Finck     {
2614c2c66affSColin Finck     ok(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE,
2615c2c66affSColin Finck       "HiliteMenuItem: Item 2 is not hilited\n");
2616c2c66affSColin Finck     }
2617c2c66affSColin Finck 
2618c2c66affSColin Finck     /* unhilite a menu item (by position) */
2619c2c66affSColin Finck 
2620c2c66affSColin Finck     SetLastError(0xdeadbeef);
2621c2c66affSColin Finck     ok(HiliteMenuItem(hWnd, hPopupMenu, 1, MF_UNHILITE | MF_BYPOSITION),
2622c2c66affSColin Finck       "HiliteMenuItem: call should not have failed.\n");
2623c2c66affSColin Finck     ok(GetLastError() == 0xdeadbeef,
2624c2c66affSColin Finck       "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2625c2c66affSColin Finck 
2626c2c66affSColin Finck     ok(!(GetMenuState(hPopupMenu, 1, MF_BYPOSITION) & MF_HILITE),
2627c2c66affSColin Finck       "HiliteMenuItem: Item 2 is hilited\n");
2628c2c66affSColin Finck 
2629c2c66affSColin Finck     /* hilite a menu item (by command) */
2630c2c66affSColin Finck 
2631c2c66affSColin Finck     SetLastError(0xdeadbeef);
2632c2c66affSColin Finck     ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_HILITE | MF_BYCOMMAND),
2633c2c66affSColin Finck       "HiliteMenuItem: call should not have failed.\n");
2634c2c66affSColin Finck     ok(GetLastError() == 0xdeadbeef,
2635c2c66affSColin Finck       "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2636c2c66affSColin Finck 
2637c2c66affSColin Finck     todo_wine
2638c2c66affSColin Finck     {
2639c2c66affSColin Finck     ok(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE,
2640c2c66affSColin Finck       "HiliteMenuItem: Item 3 is not hilited\n");
2641c2c66affSColin Finck     }
2642c2c66affSColin Finck 
2643c2c66affSColin Finck     /* unhilite a menu item (by command) */
2644c2c66affSColin Finck 
2645c2c66affSColin Finck     SetLastError(0xdeadbeef);
2646c2c66affSColin Finck     ok(HiliteMenuItem(hWnd, hPopupMenu, 103, MF_UNHILITE | MF_BYCOMMAND),
2647c2c66affSColin Finck       "HiliteMenuItem: call should not have failed.\n");
2648c2c66affSColin Finck     ok(GetLastError() == 0xdeadbeef,
2649c2c66affSColin Finck       "HiliteMenuItem: expected error 0xdeadbeef, got: %d\n", GetLastError());
2650c2c66affSColin Finck 
2651c2c66affSColin Finck     ok(!(GetMenuState(hPopupMenu, 2, MF_BYPOSITION) & MF_HILITE),
2652c2c66affSColin Finck       "HiliteMenuItem: Item 3 is hilited\n");
2653c2c66affSColin Finck 
2654c2c66affSColin Finck     DestroyWindow(hWnd);
2655c2c66affSColin Finck }
2656c2c66affSColin Finck 
check_menu_items(HMENU hmenu,UINT checked_cmd,UINT checked_type,UINT checked_state)2657c2c66affSColin Finck static void check_menu_items(HMENU hmenu, UINT checked_cmd, UINT checked_type,
2658c2c66affSColin Finck                              UINT checked_state)
2659c2c66affSColin Finck {
2660c2c66affSColin Finck     INT i, count;
2661c2c66affSColin Finck 
2662c2c66affSColin Finck     count = GetMenuItemCount(hmenu);
2663c2c66affSColin Finck     ok (count != -1, "GetMenuItemCount returned -1\n");
2664c2c66affSColin Finck 
2665c2c66affSColin Finck     for (i = 0; i < count; i++)
2666c2c66affSColin Finck     {
2667c2c66affSColin Finck         BOOL ret;
2668c2c66affSColin Finck         MENUITEMINFOA mii;
2669c2c66affSColin Finck 
2670c2c66affSColin Finck         memset(&mii, 0, sizeof(mii));
2671c2c66affSColin Finck         mii.cbSize = sizeof(mii);
2672c2c66affSColin Finck         mii.fMask  = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU;
2673c2c66affSColin Finck         ret = GetMenuItemInfoA(hmenu, i, TRUE, &mii);
2674c2c66affSColin Finck         ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2675c2c66affSColin Finck 
2676c2c66affSColin Finck         if (winetest_debug > 1)
2677c2c66affSColin Finck             trace("item #%u: fType %04x, fState %04x, wID %u, hSubMenu %p\n",
2678c2c66affSColin Finck                   i, mii.fType, mii.fState, mii.wID, mii.hSubMenu);
2679c2c66affSColin Finck 
2680c2c66affSColin Finck         if (mii.hSubMenu)
2681c2c66affSColin Finck         {
2682c2c66affSColin Finck             ok(mii.wID == (UINT_PTR)mii.hSubMenu, "id %u: wID %x should be equal to hSubMenu %p\n",
2683c2c66affSColin Finck                checked_cmd, mii.wID, mii.hSubMenu);
2684c2c66affSColin Finck             if (!GetMenuItemCount(mii.hSubMenu))
2685c2c66affSColin Finck             {
2686c2c66affSColin Finck                 ok(mii.fType == checked_type, "id %u: expected fType %04x, got %04x\n", checked_cmd, checked_type, mii.fType);
2687c2c66affSColin Finck                 ok(mii.fState == checked_state, "id %u: expected fState %04x, got %04x\n", checked_cmd, checked_state, mii.fState);
2688c2c66affSColin Finck             }
2689c2c66affSColin Finck             check_menu_items(mii.hSubMenu, checked_cmd, checked_type, checked_state);
2690c2c66affSColin Finck         }
2691c2c66affSColin Finck         else
2692c2c66affSColin Finck         {
2693c2c66affSColin Finck             if (mii.wID == checked_cmd)
2694c2c66affSColin Finck             {
2695c2c66affSColin Finck                 ok(mii.fType == checked_type, "id %u: expected fType %04x, got %04x\n", checked_cmd, checked_type, mii.fType);
2696c2c66affSColin Finck                 ok(mii.fState == checked_state, "id %u: expected fState %04x, got %04x\n", checked_cmd, checked_state, mii.fState);
2697c2c66affSColin Finck                 ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2698c2c66affSColin Finck             }
2699c2c66affSColin Finck             else
2700c2c66affSColin Finck             {
2701c2c66affSColin Finck                 ok(mii.fType != MFT_RADIOCHECK, "id %u: not expected fType MFT_RADIOCHECK on cmd %u\n", checked_cmd, mii.wID);
2702c2c66affSColin Finck 
2703c2c66affSColin Finck                 if (mii.fType == MFT_SEPARATOR)
2704c2c66affSColin Finck                 {
2705c2c66affSColin Finck                     ok(mii.fState == MFS_GRAYED, "id %u: expected fState MFS_GRAYED, got %04x\n", checked_cmd, mii.fState);
2706c2c66affSColin Finck                     ok(mii.wID == 0, "id %u: expected wID 0, got %u\n", checked_cmd, mii.wID);
2707c2c66affSColin Finck                 }
2708c2c66affSColin Finck                 else
2709c2c66affSColin Finck                 {
2710c2c66affSColin Finck                     ok(mii.fState == 0, "id %u: expected fState 0, got %04x\n", checked_cmd, mii.fState);
2711c2c66affSColin Finck                     ok(mii.wID != 0, "id %u: not expected wID 0\n", checked_cmd);
2712c2c66affSColin Finck                 }
2713c2c66affSColin Finck             }
2714c2c66affSColin Finck         }
2715c2c66affSColin Finck     }
2716c2c66affSColin Finck }
2717c2c66affSColin Finck 
clear_ftype_and_state(HMENU hmenu,UINT id,UINT flags)2718c2c66affSColin Finck static void clear_ftype_and_state(HMENU hmenu, UINT id, UINT flags)
2719c2c66affSColin Finck {
2720c2c66affSColin Finck     BOOL ret;
2721c2c66affSColin Finck     MENUITEMINFOA mii;
2722c2c66affSColin Finck 
2723c2c66affSColin Finck     memset(&mii, 0, sizeof(mii));
2724c2c66affSColin Finck     mii.cbSize = sizeof(mii);
2725c2c66affSColin Finck     mii.fMask  = MIIM_FTYPE | MIIM_STATE;
2726c2c66affSColin Finck     ret = SetMenuItemInfoA(hmenu, id, (flags & MF_BYPOSITION) != 0, &mii);
2727c2c66affSColin Finck     ok(ret, "SetMenuItemInfo(%u) failed\n", id);
2728c2c66affSColin Finck }
2729c2c66affSColin Finck 
test_CheckMenuRadioItem(void)2730c2c66affSColin Finck static void test_CheckMenuRadioItem(void)
2731c2c66affSColin Finck {
2732c2c66affSColin Finck     BOOL ret;
2733c2c66affSColin Finck     HMENU hmenu;
2734c2c66affSColin Finck 
2735c2c66affSColin Finck     hmenu = LoadMenuA(GetModuleHandleA(NULL), MAKEINTRESOURCEA(1));
2736c2c66affSColin Finck     assert(hmenu != 0);
2737c2c66affSColin Finck 
2738c2c66affSColin Finck     check_menu_items(hmenu, -1, 0, 0);
2739c2c66affSColin Finck 
2740c2c66affSColin Finck     ret = CheckMenuRadioItem(hmenu, 100, 100, 100, MF_BYCOMMAND);
2741c2c66affSColin Finck     ok(ret, "CheckMenuRadioItem failed\n");
2742c2c66affSColin Finck     check_menu_items(hmenu, 100, MFT_RADIOCHECK, MFS_CHECKED);
2743c2c66affSColin Finck 
2744c2c66affSColin Finck     /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2745c2c66affSColin Finck     ret = CheckMenuRadioItem(hmenu, 100, 100, -1, MF_BYCOMMAND);
2746c2c66affSColin Finck     ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2747c2c66affSColin Finck     check_menu_items(hmenu, 100, MFT_RADIOCHECK, 0);
2748c2c66affSColin Finck 
2749c2c66affSColin Finck     /* clear check */
2750c2c66affSColin Finck     clear_ftype_and_state(hmenu, 100, MF_BYCOMMAND);
2751c2c66affSColin Finck     check_menu_items(hmenu, -1, 0, 0);
2752c2c66affSColin Finck 
2753c2c66affSColin Finck     /* first and checked items are on different menus */
2754c2c66affSColin Finck     ret = CheckMenuRadioItem(hmenu, 0, 300, 202, MF_BYCOMMAND);
2755c2c66affSColin Finck     ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2756c2c66affSColin Finck     check_menu_items(hmenu, -1, 0, 0);
2757c2c66affSColin Finck 
2758c2c66affSColin Finck     ret = CheckMenuRadioItem(hmenu, 200, 300, 202, MF_BYCOMMAND);
2759c2c66affSColin Finck     ok(ret, "CheckMenuRadioItem failed\n");
2760c2c66affSColin Finck     check_menu_items(hmenu, 202, MFT_RADIOCHECK, MFS_CHECKED);
2761c2c66affSColin Finck 
2762c2c66affSColin Finck     /* MSDN is wrong, Windows does not remove MFT_RADIOCHECK */
2763c2c66affSColin Finck     ret = CheckMenuRadioItem(hmenu, 202, 202, -1, MF_BYCOMMAND);
2764c2c66affSColin Finck     ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2765c2c66affSColin Finck     check_menu_items(hmenu, 202, MFT_RADIOCHECK, 0);
2766c2c66affSColin Finck 
2767c2c66affSColin Finck     /* clear check */
2768c2c66affSColin Finck     clear_ftype_and_state(hmenu, 202, MF_BYCOMMAND);
2769c2c66affSColin Finck     check_menu_items(hmenu, -1, 0, 0);
2770c2c66affSColin Finck 
2771c2c66affSColin Finck     /* just for fun, try to check separator */
2772c2c66affSColin Finck     ret = CheckMenuRadioItem(hmenu, 0, 300, 0, MF_BYCOMMAND);
2773c2c66affSColin Finck     ok(!ret, "CheckMenuRadioItem should return FALSE\n");
2774c2c66affSColin Finck     check_menu_items(hmenu, -1, 0, 0);
2775c2c66affSColin Finck }
2776c2c66affSColin Finck 
test_menu_resource_layout(void)2777c2c66affSColin Finck static void test_menu_resource_layout(void)
2778c2c66affSColin Finck {
2779c2c66affSColin Finck     static const struct
2780c2c66affSColin Finck     {
2781c2c66affSColin Finck         MENUITEMTEMPLATEHEADER mith;
2782c2c66affSColin Finck         WORD data[14];
2783c2c66affSColin Finck     } menu_template =
2784c2c66affSColin Finck     {
2785c2c66affSColin Finck         { 0, 0 }, /* versionNumber, offset */
2786c2c66affSColin Finck         {
2787c2c66affSColin Finck             /* mtOption, mtID, mtString[] '\0' terminated */
2788c2c66affSColin Finck             MF_STRING, 1, 'F', 0,
2789c2c66affSColin Finck             MF_STRING, 2, 0,
2790c2c66affSColin Finck             MF_SEPARATOR, 3, 0,
2791c2c66affSColin Finck             /* MF_SEPARATOR, 4, 'S', 0, FIXME: Wine ignores 'S' */
2792c2c66affSColin Finck             MF_STRING|MF_GRAYED|MF_END, 5, 'E', 0
2793c2c66affSColin Finck         }
2794c2c66affSColin Finck     };
2795c2c66affSColin Finck     static const struct
2796c2c66affSColin Finck     {
2797c2c66affSColin Finck         UINT type, state, id;
2798c2c66affSColin Finck         const char *str;
2799c2c66affSColin Finck     } menu_data[] =
2800c2c66affSColin Finck     {
2801c2c66affSColin Finck         { MF_STRING, MF_ENABLED, 1, "F" },
2802c2c66affSColin Finck         { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 2, "" },
2803c2c66affSColin Finck         { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 3, "" },
2804c2c66affSColin Finck         /*{ MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 4, "S" }, FIXME: Wine ignores 'S'*/
2805c2c66affSColin Finck         { MF_STRING, MF_GRAYED, 5, "E" },
2806c2c66affSColin Finck         { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 6, "" },
2807c2c66affSColin Finck         { MF_STRING, MF_ENABLED, 7, "" },
2808c2c66affSColin Finck         { MF_SEPARATOR, MF_GRAYED|MF_DISABLED, 8, "" }
2809c2c66affSColin Finck     };
2810c2c66affSColin Finck     HMENU hmenu;
2811c2c66affSColin Finck     INT count, i;
2812c2c66affSColin Finck     BOOL ret;
2813c2c66affSColin Finck 
2814c2c66affSColin Finck     hmenu = LoadMenuIndirectA(&menu_template);
2815c2c66affSColin Finck     ok(hmenu != 0, "LoadMenuIndirect error %u\n", GetLastError());
2816c2c66affSColin Finck 
2817c2c66affSColin Finck     ret = AppendMenuA(hmenu, MF_STRING, 6, NULL);
2818c2c66affSColin Finck     ok(ret, "AppendMenu failed\n");
2819c2c66affSColin Finck     ret = AppendMenuA(hmenu, MF_STRING, 7, "\0");
2820c2c66affSColin Finck     ok(ret, "AppendMenu failed\n");
2821c2c66affSColin Finck     ret = AppendMenuA(hmenu, MF_SEPARATOR, 8, "separator");
2822c2c66affSColin Finck     ok(ret, "AppendMenu failed\n");
2823c2c66affSColin Finck 
2824c2c66affSColin Finck     count = GetMenuItemCount(hmenu);
2825*7a62c32bSAmine Khaldi     ok(count == ARRAY_SIZE(menu_data), "expected %u menu items, got %u\n",
2826*7a62c32bSAmine Khaldi        (UINT) ARRAY_SIZE(menu_data), count);
2827c2c66affSColin Finck 
2828c2c66affSColin Finck     for (i = 0; i < count; i++)
2829c2c66affSColin Finck     {
2830c2c66affSColin Finck         char buf[20];
2831c2c66affSColin Finck         MENUITEMINFOA mii;
2832c2c66affSColin Finck 
2833c2c66affSColin Finck         memset(&mii, 0, sizeof(mii));
2834c2c66affSColin Finck         mii.cbSize = sizeof(mii);
2835c2c66affSColin Finck         mii.dwTypeData = buf;
2836c2c66affSColin Finck         mii.cch = sizeof(buf);
2837c2c66affSColin Finck         mii.fMask  = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_STRING;
2838c2c66affSColin Finck         ret = GetMenuItemInfoA(hmenu, i, TRUE, &mii);
2839c2c66affSColin Finck         ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2840c2c66affSColin Finck         if (winetest_debug > 1)
2841c2c66affSColin Finck             trace("item #%u: fType %04x, fState %04x, wID %u, dwTypeData %s\n",
2842c2c66affSColin Finck                   i, mii.fType, mii.fState, mii.wID, (LPCSTR)mii.dwTypeData);
2843c2c66affSColin Finck 
2844c2c66affSColin Finck         ok(mii.fType == menu_data[i].type,
2845c2c66affSColin Finck            "%u: expected fType %04x, got %04x\n", i, menu_data[i].type, mii.fType);
2846c2c66affSColin Finck         ok(mii.fState == menu_data[i].state,
2847c2c66affSColin Finck            "%u: expected fState %04x, got %04x\n", i, menu_data[i].state, mii.fState);
2848c2c66affSColin Finck         ok(mii.wID == menu_data[i].id,
2849c2c66affSColin Finck            "%u: expected wID %04x, got %04x\n", i, menu_data[i].id, mii.wID);
2850c2c66affSColin Finck         ok(mii.cch == strlen(menu_data[i].str),
2851c2c66affSColin Finck            "%u: expected cch %u, got %u\n", i, (UINT)strlen(menu_data[i].str), mii.cch);
2852c2c66affSColin Finck         ok(!strcmp(mii.dwTypeData, menu_data[i].str),
2853c2c66affSColin Finck            "%u: expected dwTypeData %s, got %s\n", i, menu_data[i].str, (LPCSTR)mii.dwTypeData);
2854c2c66affSColin Finck     }
2855c2c66affSColin Finck 
2856c2c66affSColin Finck     DestroyMenu(hmenu);
2857c2c66affSColin Finck }
2858c2c66affSColin Finck 
2859c2c66affSColin Finck struct menu_data
2860c2c66affSColin Finck {
2861c2c66affSColin Finck     UINT type, id;
2862c2c66affSColin Finck     const char *str;
2863c2c66affSColin Finck };
2864c2c66affSColin Finck 
create_menu_from_data(const struct menu_data * item,INT item_count)2865c2c66affSColin Finck static HMENU create_menu_from_data(const struct menu_data *item, INT item_count)
2866c2c66affSColin Finck {
2867c2c66affSColin Finck     HMENU hmenu;
2868c2c66affSColin Finck     INT i;
2869c2c66affSColin Finck     BOOL ret;
2870c2c66affSColin Finck 
2871c2c66affSColin Finck     hmenu = CreateMenu();
2872c2c66affSColin Finck     assert(hmenu != 0);
2873c2c66affSColin Finck 
2874c2c66affSColin Finck     for (i = 0; i < item_count; i++)
2875c2c66affSColin Finck     {
2876c2c66affSColin Finck         SetLastError(0xdeadbeef);
2877c2c66affSColin Finck         ret = AppendMenuA(hmenu, item[i].type, item[i].id, item[i].str);
2878c2c66affSColin Finck         ok(ret, "%d: AppendMenu(%04x, %04x, %p) error %u\n",
2879c2c66affSColin Finck            i, item[i].type, item[i].id, item[i].str, GetLastError());
2880c2c66affSColin Finck     }
2881c2c66affSColin Finck     return hmenu;
2882c2c66affSColin Finck }
2883c2c66affSColin Finck 
2884c2c66affSColin Finck /* use InsertMenuItem: does not set the MFT_BITMAP flag,
2885c2c66affSColin Finck  * and does not accept non-magic bitmaps with invalid
2886c2c66affSColin Finck  * bitmap handles */
create_menuitem_from_data(const struct menu_data * item,INT item_count)2887c2c66affSColin Finck static HMENU create_menuitem_from_data(const struct menu_data *item, INT item_count)
2888c2c66affSColin Finck {
2889c2c66affSColin Finck     HMENU hmenu;
2890c2c66affSColin Finck     INT i;
2891c2c66affSColin Finck     BOOL ret;
2892c2c66affSColin Finck     MENUITEMINFOA mii = { sizeof( MENUITEMINFOA) };
2893c2c66affSColin Finck 
2894c2c66affSColin Finck     hmenu = CreateMenu();
2895c2c66affSColin Finck     assert(hmenu != 0);
2896c2c66affSColin Finck 
2897c2c66affSColin Finck     for (i = 0; i < item_count; i++)
2898c2c66affSColin Finck     {
2899c2c66affSColin Finck         SetLastError(0xdeadbeef);
2900c2c66affSColin Finck 
2901c2c66affSColin Finck         mii.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STATE;
2902c2c66affSColin Finck         mii.fType = 0;
2903c2c66affSColin Finck         if(  item[i].type & MFT_BITMAP)
2904c2c66affSColin Finck         {
2905c2c66affSColin Finck             mii.fMask |= MIIM_BITMAP;
2906c2c66affSColin Finck             mii.hbmpItem =  (HBITMAP)item[i].str;
2907c2c66affSColin Finck         }
2908c2c66affSColin Finck         else if(  item[i].type & MFT_SEPARATOR)
2909c2c66affSColin Finck             mii.fType = MFT_SEPARATOR;
2910c2c66affSColin Finck         else
2911c2c66affSColin Finck         {
2912c2c66affSColin Finck             mii.fMask |= MIIM_STRING;
2913c2c66affSColin Finck             mii.dwTypeData =  (LPSTR)item[i].str;
2914c2c66affSColin Finck             mii.cch = strlen(  item[i].str);
2915c2c66affSColin Finck         }
2916c2c66affSColin Finck         mii.fState = 0;
2917c2c66affSColin Finck         if(  item[i].type & MF_HELP) mii.fType |= MF_HELP;
2918c2c66affSColin Finck         mii.wID = item[i].id;
2919c2c66affSColin Finck         ret = InsertMenuItemA( hmenu, -1, TRUE, &mii);
2920c2c66affSColin Finck         ok(ret, "%d: InsertMenuItem(%04x, %04x, %p) error %u\n",
2921c2c66affSColin Finck            i, item[i].type, item[i].id, item[i].str, GetLastError());
2922c2c66affSColin Finck     }
2923c2c66affSColin Finck     return hmenu;
2924c2c66affSColin Finck }
2925c2c66affSColin Finck 
compare_menu_data(HMENU hmenu,const struct menu_data * item,INT item_count)2926c2c66affSColin Finck static void compare_menu_data(HMENU hmenu, const struct menu_data *item, INT item_count)
2927c2c66affSColin Finck {
2928c2c66affSColin Finck     INT count, i;
2929c2c66affSColin Finck     BOOL ret;
2930c2c66affSColin Finck 
2931c2c66affSColin Finck     count = GetMenuItemCount(hmenu);
2932c2c66affSColin Finck     ok(count == item_count, "expected %d, got %d menu items\n", count, item_count);
2933c2c66affSColin Finck 
2934c2c66affSColin Finck     for (i = 0; i < count; i++)
2935c2c66affSColin Finck     {
2936c2c66affSColin Finck         char buf[20];
2937c2c66affSColin Finck         MENUITEMINFOA mii;
2938c2c66affSColin Finck 
2939c2c66affSColin Finck         memset(&mii, 0, sizeof(mii));
2940c2c66affSColin Finck         mii.cbSize = sizeof(mii);
2941c2c66affSColin Finck         mii.dwTypeData = buf;
2942c2c66affSColin Finck         mii.cch = sizeof(buf);
2943c2c66affSColin Finck         mii.fMask  = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_BITMAP;
2944c2c66affSColin Finck         ret = GetMenuItemInfoA(hmenu, i, TRUE, &mii);
2945c2c66affSColin Finck         ok(ret, "GetMenuItemInfo(%u) failed\n", i);
2946c2c66affSColin Finck 
2947c2c66affSColin Finck         if (winetest_debug > 1)
2948c2c66affSColin Finck             trace("item #%u: fType %04x, fState %04x, wID %04x, hbmp %p\n",
2949c2c66affSColin Finck                   i, mii.fType, mii.fState, mii.wID, mii.hbmpItem);
2950c2c66affSColin Finck 
2951c2c66affSColin Finck         ok(mii.fType == item[i].type,
2952c2c66affSColin Finck            "%u: expected fType %04x, got %04x\n", i, item[i].type, mii.fType);
2953c2c66affSColin Finck         ok(mii.wID == item[i].id,
2954c2c66affSColin Finck            "%u: expected wID %04x, got %04x\n", i, item[i].id, mii.wID);
2955c2c66affSColin Finck         if (mii.hbmpItem || !item[i].str)
2956c2c66affSColin Finck             /* For some reason Windows sets high word to not 0 for
2957c2c66affSColin Finck              * not "magic" ids.
2958c2c66affSColin Finck              */
2959c2c66affSColin Finck             ok(LOWORD(mii.hbmpItem) == LOWORD(item[i].str),
2960c2c66affSColin Finck                "%u: expected hbmpItem %p, got %p\n", i, item[i].str, mii.hbmpItem);
2961c2c66affSColin Finck         else
2962c2c66affSColin Finck         {
2963c2c66affSColin Finck             ok(mii.cch == strlen(item[i].str),
2964c2c66affSColin Finck                "%u: expected cch %u, got %u\n", i, (UINT)strlen(item[i].str), mii.cch);
2965c2c66affSColin Finck             ok(!strcmp(mii.dwTypeData, item[i].str),
2966c2c66affSColin Finck                "%u: expected dwTypeData %s, got %s\n", i, item[i].str, (LPCSTR)mii.dwTypeData);
2967c2c66affSColin Finck         }
2968c2c66affSColin Finck     }
2969c2c66affSColin Finck }
2970c2c66affSColin Finck 
test_InsertMenu(void)2971c2c66affSColin Finck static void test_InsertMenu(void)
2972c2c66affSColin Finck {
2973c2c66affSColin Finck     HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
2974c2c66affSColin Finck     /* Note: XP treats only bitmap handles 1 - 6 as "magic" ones
2975c2c66affSColin Finck      * regardless of their id.
2976c2c66affSColin Finck      */
2977c2c66affSColin Finck     static const struct menu_data in1[] =
2978c2c66affSColin Finck     {
2979c2c66affSColin Finck         { MF_STRING, 1, "File" },
2980c2c66affSColin Finck         { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCEA(1) },
2981c2c66affSColin Finck         { MF_STRING|MF_HELP, 2, "Help" }
2982c2c66affSColin Finck     };
2983c2c66affSColin Finck     static const struct menu_data out1[] =
2984c2c66affSColin Finck     {
2985c2c66affSColin Finck         { MF_STRING, 1, "File" },
2986c2c66affSColin Finck         { MF_STRING|MF_HELP, 2, "Help" },
2987c2c66affSColin Finck         { MF_BITMAP|MF_HELP, SC_CLOSE, MAKEINTRESOURCEA(1) }
2988c2c66affSColin Finck     };
2989c2c66affSColin Finck     static const struct menu_data out1a[] =
2990c2c66affSColin Finck     {
2991c2c66affSColin Finck         { MF_STRING, 1, "File" },
2992c2c66affSColin Finck         { MF_STRING|MF_HELP, 2, "Help" },
2993c2c66affSColin Finck         { MF_HELP, SC_CLOSE, MAKEINTRESOURCEA(1) }
2994c2c66affSColin Finck     };
2995c2c66affSColin Finck     const struct menu_data in2[] =
2996c2c66affSColin Finck     {
2997c2c66affSColin Finck         { MF_STRING, 1, "File" },
2998c2c66affSColin Finck         { MF_BITMAP|MF_HELP, SC_CLOSE, (char*)hbm },
2999c2c66affSColin Finck         { MF_STRING|MF_HELP, 2, "Help" }
3000c2c66affSColin Finck     };
3001c2c66affSColin Finck     const struct menu_data out2[] =
3002c2c66affSColin Finck     {
3003c2c66affSColin Finck         { MF_STRING, 1, "File" },
3004c2c66affSColin Finck         { MF_BITMAP|MF_HELP, SC_CLOSE, (char*)hbm },
3005c2c66affSColin Finck         { MF_STRING|MF_HELP, 2, "Help" }
3006c2c66affSColin Finck     };
3007c2c66affSColin Finck     const struct menu_data out2a[] =
3008c2c66affSColin Finck     {
3009c2c66affSColin Finck         { MF_STRING, 1, "File" },
3010c2c66affSColin Finck         { MF_HELP, SC_CLOSE, (char*)hbm },
3011c2c66affSColin Finck         { MF_STRING|MF_HELP, 2, "Help" }
3012c2c66affSColin Finck     };
3013c2c66affSColin Finck     static const struct menu_data in3[] =
3014c2c66affSColin Finck     {
3015c2c66affSColin Finck         { MF_STRING, 1, "File" },
3016c2c66affSColin Finck         { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCEA(1) },
3017c2c66affSColin Finck         { MF_STRING|MF_HELP, 2, "Help" }
3018c2c66affSColin Finck     };
3019c2c66affSColin Finck     static const struct menu_data out3[] =
3020c2c66affSColin Finck     {
3021c2c66affSColin Finck         { MF_STRING, 1, "File" },
3022c2c66affSColin Finck         { MF_SEPARATOR|MF_HELP, SC_CLOSE, MAKEINTRESOURCEA(0) },
3023c2c66affSColin Finck         { MF_STRING|MF_HELP, 2, "Help" },
3024c2c66affSColin Finck     };
3025c2c66affSColin Finck     static const struct menu_data in4[] =
3026c2c66affSColin Finck     {
3027c2c66affSColin Finck         { MF_STRING, 1, "File" },
3028c2c66affSColin Finck         { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCEA(1) },
3029c2c66affSColin Finck         { MF_STRING|MF_HELP, 2, "Help" }
3030c2c66affSColin Finck     };
3031c2c66affSColin Finck     static const struct menu_data out4[] =
3032c2c66affSColin Finck     {
3033c2c66affSColin Finck         { MF_STRING, 1, "File" },
3034c2c66affSColin Finck         { MF_STRING|MF_HELP, 2, "Help" },
3035c2c66affSColin Finck         { MF_BITMAP|MF_HELP, 1, MAKEINTRESOURCEA(1) }
3036c2c66affSColin Finck     };
3037c2c66affSColin Finck     static const struct menu_data out4a[] =
3038c2c66affSColin Finck     {
3039c2c66affSColin Finck         { MF_STRING, 1, "File" },
3040c2c66affSColin Finck         { MF_STRING|MF_HELP, 2, "Help" },
3041c2c66affSColin Finck         { MF_HELP, 1, MAKEINTRESOURCEA(1) }
3042c2c66affSColin Finck     };
3043c2c66affSColin Finck     HMENU hmenu;
3044c2c66affSColin Finck 
3045*7a62c32bSAmine Khaldi #define create_menu(a) create_menu_from_data((a), ARRAY_SIZE(a))
3046*7a62c32bSAmine Khaldi #define create_menuitem(a) create_menuitem_from_data((a), ARRAY_SIZE(a))
3047*7a62c32bSAmine Khaldi #define compare_menu(h, a) compare_menu_data((h), (a), ARRAY_SIZE(a))
3048c2c66affSColin Finck 
3049c2c66affSColin Finck     hmenu = create_menu(in1);
3050c2c66affSColin Finck     compare_menu(hmenu, out1);
3051c2c66affSColin Finck     DestroyMenu(hmenu);
3052c2c66affSColin Finck 
3053c2c66affSColin Finck     hmenu = create_menu(in2);
3054c2c66affSColin Finck     compare_menu(hmenu, out2);
3055c2c66affSColin Finck     DestroyMenu(hmenu);
3056c2c66affSColin Finck 
3057c2c66affSColin Finck     hmenu = create_menu(in3);
3058c2c66affSColin Finck     compare_menu(hmenu, out3);
3059c2c66affSColin Finck     DestroyMenu(hmenu);
3060c2c66affSColin Finck 
3061c2c66affSColin Finck     hmenu = create_menu(in4);
3062c2c66affSColin Finck     compare_menu(hmenu, out4);
3063c2c66affSColin Finck     DestroyMenu(hmenu);
3064c2c66affSColin Finck 
3065c2c66affSColin Finck     /* now using InsertMenuItemInfo */
3066c2c66affSColin Finck     hmenu = create_menuitem(in1);
3067c2c66affSColin Finck     compare_menu(hmenu, out1a);
3068c2c66affSColin Finck     DestroyMenu(hmenu);
3069c2c66affSColin Finck 
3070c2c66affSColin Finck     hmenu = create_menuitem(in2);
3071c2c66affSColin Finck     compare_menu(hmenu, out2a);
3072c2c66affSColin Finck     DestroyMenu(hmenu);
3073c2c66affSColin Finck 
3074c2c66affSColin Finck     hmenu = create_menuitem(in3);
3075c2c66affSColin Finck     compare_menu(hmenu, out3);
3076c2c66affSColin Finck     DestroyMenu(hmenu);
3077c2c66affSColin Finck 
3078c2c66affSColin Finck     hmenu = create_menuitem(in4);
3079c2c66affSColin Finck     compare_menu(hmenu, out4a);
3080c2c66affSColin Finck     DestroyMenu(hmenu);
3081c2c66affSColin Finck 
3082c2c66affSColin Finck #undef create_menu
3083c2c66affSColin Finck #undef create_menuitem
3084c2c66affSColin Finck #undef compare_menu
3085c2c66affSColin Finck }
3086c2c66affSColin Finck 
test_menu_getmenuinfo(void)3087c2c66affSColin Finck static void test_menu_getmenuinfo(void)
3088c2c66affSColin Finck {
3089c2c66affSColin Finck     HMENU hmenu;
3090c2c66affSColin Finck     MENUINFO mi = {0};
3091c2c66affSColin Finck     BOOL ret;
3092c2c66affSColin Finck     DWORD gle;
3093c2c66affSColin Finck 
3094c2c66affSColin Finck     /* create a menu */
3095c2c66affSColin Finck     hmenu = CreateMenu();
3096c2c66affSColin Finck     assert( hmenu);
3097c2c66affSColin Finck     /* test some parameter errors */
3098c2c66affSColin Finck     SetLastError(0xdeadbeef);
3099*7a62c32bSAmine Khaldi     ret = GetMenuInfo( hmenu, NULL);
3100c2c66affSColin Finck     gle= GetLastError();
3101c2c66affSColin Finck     ok( !ret, "GetMenuInfo() should have failed\n");
3102c2c66affSColin Finck     ok( gle == ERROR_INVALID_PARAMETER ||
3103c2c66affSColin Finck         broken(gle == 0xdeadbeef), /* Win98, WinME */
3104c2c66affSColin Finck         "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
3105c2c66affSColin Finck     SetLastError(0xdeadbeef);
3106c2c66affSColin Finck     mi.cbSize = 0;
3107*7a62c32bSAmine Khaldi     ret = GetMenuInfo( hmenu, &mi);
3108c2c66affSColin Finck     gle= GetLastError();
3109c2c66affSColin Finck     ok( !ret, "GetMenuInfo() should have failed\n");
3110c2c66affSColin Finck     ok( gle == ERROR_INVALID_PARAMETER ||
3111c2c66affSColin Finck         broken(gle == 0xdeadbeef), /* Win98, WinME */
3112c2c66affSColin Finck         "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
3113c2c66affSColin Finck     SetLastError(0xdeadbeef);
3114c2c66affSColin Finck     mi.cbSize = sizeof( MENUINFO);
3115*7a62c32bSAmine Khaldi     ret = GetMenuInfo( hmenu, &mi);
3116c2c66affSColin Finck     gle= GetLastError();
3117c2c66affSColin Finck     ok( ret, "GetMenuInfo() should have succeeded\n");
3118c2c66affSColin Finck     ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3119c2c66affSColin Finck     SetLastError(0xdeadbeef);
3120c2c66affSColin Finck     mi.cbSize = 0;
3121*7a62c32bSAmine Khaldi     ret = GetMenuInfo( NULL, &mi);
3122c2c66affSColin Finck     gle= GetLastError();
3123c2c66affSColin Finck     ok( !ret, "GetMenuInfo() should have failed\n");
3124c2c66affSColin Finck     ok( gle == ERROR_INVALID_PARAMETER ||
3125c2c66affSColin Finck         broken(gle == 0xdeadbeef), /* Win98, WinME */
3126c2c66affSColin Finck         "GetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
3127c2c66affSColin Finck     /* clean up */
3128c2c66affSColin Finck     DestroyMenu( hmenu);
3129c2c66affSColin Finck     return;
3130c2c66affSColin Finck }
3131c2c66affSColin Finck 
test_menu_setmenuinfo(void)3132c2c66affSColin Finck static void test_menu_setmenuinfo(void)
3133c2c66affSColin Finck {
3134c2c66affSColin Finck     HMENU hmenu, hsubmenu;
3135c2c66affSColin Finck     MENUINFO mi = {0};
3136c2c66affSColin Finck     MENUITEMINFOA mii = { sizeof(MENUITEMINFOA) };
3137c2c66affSColin Finck     BOOL ret;
3138c2c66affSColin Finck     DWORD gle;
3139c2c66affSColin Finck     HBRUSH brush;
3140c2c66affSColin Finck 
3141c2c66affSColin Finck     /* create a menu with a submenu */
3142c2c66affSColin Finck     hmenu = CreateMenu();
3143c2c66affSColin Finck     hsubmenu = CreateMenu();
3144c2c66affSColin Finck     assert( hmenu && hsubmenu);
3145c2c66affSColin Finck     mii.fMask = MIIM_SUBMENU;
3146c2c66affSColin Finck     mii.hSubMenu = hsubmenu;
3147c2c66affSColin Finck     ret = InsertMenuItemA( hmenu, 0, FALSE, &mii);
3148c2c66affSColin Finck     ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
3149c2c66affSColin Finck     /* test some parameter errors */
3150c2c66affSColin Finck     SetLastError(0xdeadbeef);
3151*7a62c32bSAmine Khaldi     ret = SetMenuInfo( hmenu, NULL);
3152c2c66affSColin Finck     gle= GetLastError();
3153c2c66affSColin Finck     ok( !ret, "SetMenuInfo() should have failed\n");
3154c2c66affSColin Finck     ok( gle == ERROR_INVALID_PARAMETER ||
3155c2c66affSColin Finck         broken(gle == 0xdeadbeef), /* Win98, WinME */
3156c2c66affSColin Finck         "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
3157c2c66affSColin Finck     SetLastError(0xdeadbeef);
3158c2c66affSColin Finck     mi.cbSize = 0;
3159*7a62c32bSAmine Khaldi     ret = SetMenuInfo( hmenu, &mi);
3160c2c66affSColin Finck     gle= GetLastError();
3161c2c66affSColin Finck     ok( !ret, "SetMenuInfo() should have failed\n");
3162c2c66affSColin Finck     ok( gle == ERROR_INVALID_PARAMETER ||
3163c2c66affSColin Finck         broken(gle == 0xdeadbeef), /* Win98, WinME */
3164c2c66affSColin Finck         "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
3165c2c66affSColin Finck     SetLastError(0xdeadbeef);
3166c2c66affSColin Finck     mi.cbSize = sizeof( MENUINFO);
3167*7a62c32bSAmine Khaldi     ret = SetMenuInfo( hmenu, &mi);
3168c2c66affSColin Finck     gle= GetLastError();
3169c2c66affSColin Finck     ok( ret, "SetMenuInfo() should have succeeded\n");
3170c2c66affSColin Finck     ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
3171c2c66affSColin Finck     SetLastError(0xdeadbeef);
3172c2c66affSColin Finck     mi.cbSize = 0;
3173*7a62c32bSAmine Khaldi     ret = SetMenuInfo( NULL, &mi);
3174c2c66affSColin Finck     gle= GetLastError();
3175c2c66affSColin Finck     ok( !ret, "SetMenuInfo() should have failed\n");
3176c2c66affSColin Finck     ok( gle == ERROR_INVALID_PARAMETER ||
3177c2c66affSColin Finck         broken(gle == 0xdeadbeef), /* Win98, WinME */
3178c2c66affSColin Finck         "SetMenuInfo() error got %u expected %u\n", gle, ERROR_INVALID_PARAMETER);
3179c2c66affSColin Finck     /* functional tests */
3180c2c66affSColin Finck     /* menu and submenu should have the CHECKORBMP style bit cleared */
3181c2c66affSColin Finck     SetLastError(0xdeadbeef);
3182c2c66affSColin Finck     mi.cbSize = sizeof( MENUINFO);
3183c2c66affSColin Finck     mi.fMask = MIM_STYLE;
3184*7a62c32bSAmine Khaldi     ret = GetMenuInfo( hmenu, &mi);
3185c2c66affSColin Finck     gle= GetLastError();
3186c2c66affSColin Finck     ok( ret, "GetMenuInfo() should have succeeded\n");
3187c2c66affSColin Finck     ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3188c2c66affSColin Finck     ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
3189c2c66affSColin Finck     SetLastError(0xdeadbeef);
3190c2c66affSColin Finck     mi.cbSize = sizeof( MENUINFO);
3191c2c66affSColin Finck     mi.fMask = MIM_STYLE;
3192*7a62c32bSAmine Khaldi     ret = GetMenuInfo( hsubmenu, &mi);
3193c2c66affSColin Finck     gle= GetLastError();
3194c2c66affSColin Finck     ok( ret, "GetMenuInfo() should have succeeded\n");
3195c2c66affSColin Finck     ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3196c2c66affSColin Finck     ok( !(mi.dwStyle & MNS_CHECKORBMP), "menustyle was not expected to have the MNS_CHECKORBMP flag\n");
3197c2c66affSColin Finck     /* SetMenuInfo() */
3198c2c66affSColin Finck     SetLastError(0xdeadbeef);
3199c2c66affSColin Finck     mi.cbSize = sizeof( MENUINFO);
3200c2c66affSColin Finck     mi.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS;
3201c2c66affSColin Finck     mi.dwStyle = MNS_CHECKORBMP;
3202*7a62c32bSAmine Khaldi     ret = SetMenuInfo( hmenu, &mi);
3203c2c66affSColin Finck     gle= GetLastError();
3204c2c66affSColin Finck     ok( ret, "SetMenuInfo() should have succeeded\n");
3205c2c66affSColin Finck     ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
3206c2c66affSColin Finck     /* Now both menus should have the MNS_CHECKORBMP style bit set */
3207c2c66affSColin Finck     SetLastError(0xdeadbeef);
3208c2c66affSColin Finck     mi.cbSize = sizeof( MENUINFO);
3209c2c66affSColin Finck     mi.fMask = MIM_STYLE;
3210*7a62c32bSAmine Khaldi     ret = GetMenuInfo( hmenu, &mi);
3211c2c66affSColin Finck     gle= GetLastError();
3212c2c66affSColin Finck     ok( ret, "GetMenuInfo() should have succeeded\n");
3213c2c66affSColin Finck     ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3214c2c66affSColin Finck     ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
3215c2c66affSColin Finck     SetLastError(0xdeadbeef);
3216c2c66affSColin Finck     mi.cbSize = sizeof( MENUINFO);
3217c2c66affSColin Finck     mi.fMask = MIM_STYLE;
3218*7a62c32bSAmine Khaldi     ret = GetMenuInfo( hsubmenu, &mi);
3219c2c66affSColin Finck     gle= GetLastError();
3220c2c66affSColin Finck     ok( ret, "GetMenuInfo() should have succeeded\n");
3221c2c66affSColin Finck     ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3222c2c66affSColin Finck     ok( mi.dwStyle & MNS_CHECKORBMP, "menustyle was expected to have the MNS_CHECKORBMP flag\n");
3223c2c66affSColin Finck     /* now repeat that without the APPLYTOSUBMENUS flag and another style bit */
3224c2c66affSColin Finck     SetLastError(0xdeadbeef);
3225c2c66affSColin Finck     mi.cbSize = sizeof( MENUINFO);
3226c2c66affSColin Finck     mi.fMask = MIM_STYLE ;
3227c2c66affSColin Finck     mi.dwStyle = MNS_NOCHECK;
3228*7a62c32bSAmine Khaldi     ret = SetMenuInfo( hmenu, &mi);
3229c2c66affSColin Finck     gle= GetLastError();
3230c2c66affSColin Finck     ok( ret, "SetMenuInfo() should have succeeded\n");
3231c2c66affSColin Finck     ok( gle == 0xdeadbeef, "SetMenuInfo() error got %u\n", gle);
3232c2c66affSColin Finck     /* Now only the top menu should have the MNS_NOCHECK style bit set */
3233c2c66affSColin Finck     SetLastError(0xdeadbeef);
3234c2c66affSColin Finck     mi.cbSize = sizeof( MENUINFO);
3235c2c66affSColin Finck     mi.fMask = MIM_STYLE;
3236*7a62c32bSAmine Khaldi     ret = GetMenuInfo( hmenu, &mi);
3237c2c66affSColin Finck     gle= GetLastError();
3238c2c66affSColin Finck     ok( ret, "GetMenuInfo() should have succeeded\n");
3239c2c66affSColin Finck     ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3240c2c66affSColin Finck     ok( mi.dwStyle & MNS_NOCHECK, "menustyle was expected to have the MNS_NOCHECK flag\n");
3241c2c66affSColin Finck     SetLastError(0xdeadbeef);
3242c2c66affSColin Finck     mi.cbSize = sizeof( MENUINFO);
3243c2c66affSColin Finck     mi.fMask = MIM_STYLE;
3244*7a62c32bSAmine Khaldi     ret = GetMenuInfo( hsubmenu, &mi);
3245c2c66affSColin Finck     gle= GetLastError();
3246c2c66affSColin Finck     ok( ret, "GetMenuInfo() should have succeeded\n");
3247c2c66affSColin Finck     ok( gle == 0xdeadbeef, "GetMenuInfo() error got %u\n", gle);
3248c2c66affSColin Finck     ok( !(mi.dwStyle & MNS_NOCHECK), "menustyle was not expected to have the MNS_NOCHECK flag\n");
3249c2c66affSColin Finck 
3250c2c66affSColin Finck     /* test background brush */
3251c2c66affSColin Finck     mi.cbSize = sizeof(mi);
3252c2c66affSColin Finck     mi.fMask = MIM_BACKGROUND;
3253*7a62c32bSAmine Khaldi     ret = GetMenuInfo( hmenu, &mi );
3254c2c66affSColin Finck     ok( ret, "GetMenuInfo() should have succeeded\n" );
3255c2c66affSColin Finck     ok( mi.hbrBack == NULL, "got %p\n", mi.hbrBack );
3256c2c66affSColin Finck 
3257c2c66affSColin Finck     brush = CreateSolidBrush( RGB(0xff, 0, 0) );
3258c2c66affSColin Finck     mi.hbrBack = brush;
3259*7a62c32bSAmine Khaldi     ret = SetMenuInfo( hmenu, &mi );
3260c2c66affSColin Finck     ok( ret, "SetMenuInfo() should have succeeded\n" );
3261c2c66affSColin Finck     mi.hbrBack = NULL;
3262*7a62c32bSAmine Khaldi     ret = GetMenuInfo( hmenu, &mi );
3263c2c66affSColin Finck     ok( ret, "GetMenuInfo() should have succeeded\n" );
3264c2c66affSColin Finck     ok( mi.hbrBack == brush, "got %p original %p\n", mi.hbrBack, brush );
3265c2c66affSColin Finck 
3266c2c66affSColin Finck     mi.hbrBack = NULL;
3267*7a62c32bSAmine Khaldi     ret = SetMenuInfo( hmenu, &mi );
3268c2c66affSColin Finck     ok( ret, "SetMenuInfo() should have succeeded\n" );
3269*7a62c32bSAmine Khaldi     ret = GetMenuInfo( hmenu, &mi );
3270c2c66affSColin Finck     ok( ret, "GetMenuInfo() should have succeeded\n" );
3271c2c66affSColin Finck     ok( mi.hbrBack == NULL, "got %p\n", mi.hbrBack );
3272c2c66affSColin Finck     DeleteObject( brush );
3273c2c66affSColin Finck 
3274c2c66affSColin Finck     /* clean up */
3275c2c66affSColin Finck     DestroyMenu( hsubmenu);
3276c2c66affSColin Finck     DestroyMenu( hmenu);
3277c2c66affSColin Finck     return;
3278c2c66affSColin Finck }
3279c2c66affSColin Finck 
3280c2c66affSColin Finck /* little func to easy switch either TrackPopupMenu() or TrackPopupMenuEx() */
MyTrackPopupMenu(int ex,HMENU hmenu,UINT flags,INT x,INT y,HWND hwnd,LPTPMPARAMS ptpm)3281c2c66affSColin Finck static DWORD MyTrackPopupMenu( int ex, HMENU hmenu, UINT flags, INT x, INT y, HWND hwnd, LPTPMPARAMS ptpm)
3282c2c66affSColin Finck {
3283c2c66affSColin Finck     return ex
3284c2c66affSColin Finck         ? TrackPopupMenuEx( hmenu, flags, x, y, hwnd, ptpm)
3285c2c66affSColin Finck         : TrackPopupMenu( hmenu, flags, x, y, 0, hwnd, NULL);
3286c2c66affSColin Finck }
3287c2c66affSColin Finck 
3288c2c66affSColin Finck /* some TrackPopupMenu and TrackPopupMenuEx tests */
3289c2c66affSColin Finck /* the LastError values differ between NO_ERROR and invalid handle */
3290c2c66affSColin Finck /* between all windows versions tested. The first value is that valid on XP  */
3291c2c66affSColin Finck /* Vista was the only that made returned different error values */
3292c2c66affSColin Finck /* between the TrackPopupMenu and TrackPopupMenuEx functions */
test_menu_trackpopupmenu(void)3293c2c66affSColin Finck static void test_menu_trackpopupmenu(void)
3294c2c66affSColin Finck {
3295c2c66affSColin Finck     BOOL ret;
3296c2c66affSColin Finck     HMENU hmenu;
3297c2c66affSColin Finck     DWORD gle;
3298c2c66affSColin Finck     int Ex;
3299c2c66affSColin Finck     HWND hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
3300c2c66affSColin Finck             WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
3301c2c66affSColin Finck             NULL, NULL, NULL, NULL);
3302c2c66affSColin Finck     ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
3303c2c66affSColin Finck     if (!hwnd) return;
3304c2c66affSColin Finck     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
3305c2c66affSColin Finck     for( Ex = 0; Ex < 2; Ex++)
3306c2c66affSColin Finck     {
3307c2c66affSColin Finck         hmenu = CreatePopupMenu();
3308c2c66affSColin Finck         ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
3309c2c66affSColin Finck         if (!hmenu)
3310c2c66affSColin Finck         {
3311c2c66affSColin Finck             DestroyWindow(hwnd);
3312c2c66affSColin Finck             return;
3313c2c66affSColin Finck         }
3314c2c66affSColin Finck         /* display the menu */
3315c2c66affSColin Finck         /* start with an invalid menu handle */
3316c2c66affSColin Finck         SetLastError(0xdeadbeef);
3317c2c66affSColin Finck 
3318c2c66affSColin Finck         gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
3319c2c66affSColin Finck         ret = MyTrackPopupMenu( Ex, NULL, TPM_RETURNCMD, 100,100, hwnd, NULL);
3320c2c66affSColin Finck         gle = GetLastError();
3321c2c66affSColin Finck         ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
3322c2c66affSColin Finck         ok( gle == ERROR_INVALID_MENU_HANDLE
3323c2c66affSColin Finck             || broken (gle == 0xdeadbeef) /* win95 */
3324c2c66affSColin Finck             || broken (gle == NO_ERROR) /* win98/ME */
3325c2c66affSColin Finck             ,"TrackPopupMenu%s error got %u expected %u\n",
3326c2c66affSColin Finck             Ex ? "Ex" : "", gle, ERROR_INVALID_MENU_HANDLE);
3327c2c66affSColin Finck         ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
3328c2c66affSColin Finck                 "got unexpected message(s)%s%s%s\n",
3329c2c66affSColin Finck                 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
3330c2c66affSColin Finck                 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
3331c2c66affSColin Finck                 gflag_initmenu ? "WM_INITMENU": "");
3332c2c66affSColin Finck         /* another one but not NULL */
3333c2c66affSColin Finck         SetLastError(0xdeadbeef);
3334c2c66affSColin Finck         gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
3335c2c66affSColin Finck         ret = MyTrackPopupMenu( Ex, (HMENU)hwnd, TPM_RETURNCMD, 100,100, hwnd, NULL);
3336c2c66affSColin Finck         gle = GetLastError();
3337c2c66affSColin Finck         ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
3338c2c66affSColin Finck         ok( gle == ERROR_INVALID_MENU_HANDLE
3339c2c66affSColin Finck             || broken (gle == 0xdeadbeef) /* win95 */
3340c2c66affSColin Finck             || broken (gle == NO_ERROR) /* win98/ME */
3341c2c66affSColin Finck             ,"TrackPopupMenu%s error got %u expected %u\n",
3342c2c66affSColin Finck             Ex ? "Ex" : "", gle, ERROR_INVALID_MENU_HANDLE);
3343c2c66affSColin Finck         ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
3344c2c66affSColin Finck                 "got unexpected message(s)%s%s%s\n",
3345c2c66affSColin Finck                 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
3346c2c66affSColin Finck                 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
3347c2c66affSColin Finck                 gflag_initmenu ? "WM_INITMENU": "");
3348c2c66affSColin Finck 
3349c2c66affSColin Finck         /* invalid window */
3350c2c66affSColin Finck         SetLastError(0xdeadbeef);
3351c2c66affSColin Finck         gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
3352c2c66affSColin Finck         ret = MyTrackPopupMenu( Ex, hmenu, TPM_RETURNCMD, 100,100, 0, NULL);
3353c2c66affSColin Finck         gle = GetLastError();
3354c2c66affSColin Finck         ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
3355c2c66affSColin Finck         ok( gle == ERROR_INVALID_WINDOW_HANDLE, "TrackPopupMenu%s error got %u\n", Ex ? "Ex" : "", gle );
3356c2c66affSColin Finck         ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
3357c2c66affSColin Finck                 "got unexpected message(s)%s%s%s\n",
3358c2c66affSColin Finck                 gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
3359c2c66affSColin Finck                 gflag_entermenuloop ? "WM_INITMENULOOP ": "",
3360c2c66affSColin Finck                 gflag_initmenu ? "WM_INITMENU": "");
3361c2c66affSColin Finck 
3362c2c66affSColin Finck         /* now a somewhat successful call */
3363c2c66affSColin Finck         SetLastError(0xdeadbeef);
3364c2c66affSColin Finck         gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
3365c2c66affSColin Finck         ret = MyTrackPopupMenu( Ex, hmenu, TPM_RETURNCMD, 100,100, hwnd, NULL);
3366c2c66affSColin Finck         gle = GetLastError();
3367c2c66affSColin Finck         ok( ret == 0, "TrackPopupMenu%s returned %d expected zero\n", Ex ? "Ex" : "", ret);
3368c2c66affSColin Finck         ok( gle == NO_ERROR
3369c2c66affSColin Finck             || gle == ERROR_INVALID_MENU_HANDLE /* NT4, win2k */
3370c2c66affSColin Finck             || broken (gle == 0xdeadbeef) /* win95 */
3371c2c66affSColin Finck             ,"TrackPopupMenu%s error got %u expected %u or %u\n",
3372c2c66affSColin Finck             Ex ? "Ex" : "", gle, NO_ERROR, ERROR_INVALID_MENU_HANDLE);
3373c2c66affSColin Finck         ok( gflag_initmenupopup && gflag_entermenuloop && gflag_initmenu,
3374c2c66affSColin Finck                 "missed expected message(s)%s%s%s\n",
3375c2c66affSColin Finck                 !gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
3376c2c66affSColin Finck                 !gflag_entermenuloop ? "WM_INITMENULOOP ": "",
3377c2c66affSColin Finck                 !gflag_initmenu ? "WM_INITMENU": "");
3378c2c66affSColin Finck         /* and another */
3379c2c66affSColin Finck         ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest");
3380c2c66affSColin Finck         ok( ret, "AppendMenA has failed!\n");
3381c2c66affSColin Finck         SetLastError(0xdeadbeef);
3382c2c66affSColin Finck         gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
3383c2c66affSColin Finck         ret = MyTrackPopupMenu( Ex, hmenu, TPM_RETURNCMD, 100,100, hwnd, NULL);
3384c2c66affSColin Finck         gle = GetLastError();
3385c2c66affSColin Finck         ok( ret == 0, "TrackPopupMenu%s returned %d expected zero\n", Ex ? "Ex" : "", ret);
3386c2c66affSColin Finck         ok( gle == NO_ERROR
3387c2c66affSColin Finck             || gle == ERROR_INVALID_MENU_HANDLE /* NT4, win2k and Vista in the TrackPopupMenuEx case */
3388c2c66affSColin Finck             || broken (gle == 0xdeadbeef) /* win95 */
3389c2c66affSColin Finck             ,"TrackPopupMenu%s error got %u expected %u or %u\n",
3390c2c66affSColin Finck             Ex ? "Ex" : "", gle, NO_ERROR, ERROR_INVALID_MENU_HANDLE);
3391c2c66affSColin Finck         ok( gflag_initmenupopup && gflag_entermenuloop && gflag_initmenu,
3392c2c66affSColin Finck                 "missed expected message(s)%s%s%s\n",
3393c2c66affSColin Finck                 !gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
3394c2c66affSColin Finck                 !gflag_entermenuloop ? "WM_INITMENULOOP ": "",
3395c2c66affSColin Finck                 !gflag_initmenu ? "WM_INITMENU": "");
3396c2c66affSColin Finck         DestroyMenu(hmenu);
3397c2c66affSColin Finck     }
3398c2c66affSColin Finck     /* clean up */
3399c2c66affSColin Finck     DestroyWindow(hwnd);
3400c2c66affSColin Finck }
3401c2c66affSColin Finck 
3402c2c66affSColin Finck static HMENU g_hmenu;
3403c2c66affSColin Finck 
menu_track_again_wnd_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)3404c2c66affSColin Finck static LRESULT WINAPI menu_track_again_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3405c2c66affSColin Finck {
3406c2c66affSColin Finck     switch (msg)
3407c2c66affSColin Finck     {
3408c2c66affSColin Finck     case WM_ENTERMENULOOP:
3409c2c66affSColin Finck     {
3410c2c66affSColin Finck         BOOL ret;
3411c2c66affSColin Finck 
3412c2c66affSColin Finck         /* try a recursive call */
3413c2c66affSColin Finck         SetLastError(0xdeadbeef);
3414c2c66affSColin Finck         ret = TrackPopupMenu(g_hmenu, 0, 100, 100, 0, hwnd, NULL);
3415c2c66affSColin Finck         ok(ret == FALSE, "got %d\n", ret);
3416c2c66affSColin Finck         ok(GetLastError() == ERROR_POPUP_ALREADY_ACTIVE ||
3417c2c66affSColin Finck            broken(GetLastError() == 0xdeadbeef) /* W9x */, "got %d\n", GetLastError());
3418c2c66affSColin Finck 
3419c2c66affSColin Finck         /* exit menu modal loop
3420c2c66affSColin Finck          * ( A SendMessage does not work on NT3.51 here ) */
3421c2c66affSColin Finck         return PostMessageA(hwnd, WM_CANCELMODE, 0, 0);
3422c2c66affSColin Finck     }
3423c2c66affSColin Finck     }
3424c2c66affSColin Finck     return DefWindowProcA(hwnd, msg, wparam, lparam);
3425c2c66affSColin Finck }
3426c2c66affSColin Finck 
test_menu_trackagain(void)3427c2c66affSColin Finck static void test_menu_trackagain(void)
3428c2c66affSColin Finck {
3429c2c66affSColin Finck     HWND hwnd;
3430c2c66affSColin Finck     BOOL ret;
3431c2c66affSColin Finck 
3432c2c66affSColin Finck     hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
3433c2c66affSColin Finck             WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
3434c2c66affSColin Finck             NULL, NULL, NULL, NULL);
3435c2c66affSColin Finck     ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
3436c2c66affSColin Finck     if (!hwnd) return;
3437c2c66affSColin Finck     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_track_again_wnd_proc);
3438c2c66affSColin Finck 
3439c2c66affSColin Finck     g_hmenu = CreatePopupMenu();
3440c2c66affSColin Finck     ok(g_hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
3441c2c66affSColin Finck 
3442c2c66affSColin Finck     ret = AppendMenuA(g_hmenu, MF_STRING , 100, "item 1");
3443c2c66affSColin Finck     ok(ret, "AppendMenu failed.\n");
3444c2c66affSColin Finck     ret = AppendMenuA(g_hmenu, MF_STRING , 101, "item 2");
3445c2c66affSColin Finck     ok(ret, "AppendMenu failed.\n");
3446c2c66affSColin Finck 
3447c2c66affSColin Finck     ret = TrackPopupMenu( g_hmenu, 0, 100, 100, 0, hwnd, NULL);
3448c2c66affSColin Finck     ok(ret == TRUE, "got %d\n", ret);
3449c2c66affSColin Finck 
3450c2c66affSColin Finck     DestroyMenu(g_hmenu);
3451c2c66affSColin Finck     DestroyWindow(hwnd);
3452c2c66affSColin Finck }
3453c2c66affSColin Finck 
3454c2c66affSColin Finck /* test handling of WM_CANCELMODE messages */
3455c2c66affSColin Finck static int g_got_enteridle;
3456c2c66affSColin Finck static HWND g_hwndtosend;
menu_cancelmode_wnd_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)3457c2c66affSColin Finck static LRESULT WINAPI menu_cancelmode_wnd_proc(HWND hwnd, UINT msg,
3458c2c66affSColin Finck         WPARAM wparam, LPARAM lparam)
3459c2c66affSColin Finck {
3460c2c66affSColin Finck     switch (msg)
3461c2c66affSColin Finck     {
3462c2c66affSColin Finck         case WM_ENTERMENULOOP:
3463c2c66affSColin Finck             g_got_enteridle = 0;
3464c2c66affSColin Finck             return SendMessageA( g_hwndtosend, WM_CANCELMODE, 0, 0);
3465c2c66affSColin Finck         case WM_ENTERIDLE:
3466c2c66affSColin Finck             {
3467c2c66affSColin Finck                 if( g_got_enteridle++ == 0) {
3468c2c66affSColin Finck                     /* little hack to get another WM_ENTERIDLE message */
3469c2c66affSColin Finck                     PostMessageA( hwnd, WM_MOUSEMOVE, 0, 0);
3470c2c66affSColin Finck                     return SendMessageA( g_hwndtosend, WM_CANCELMODE, 0, 0);
3471c2c66affSColin Finck                 }
3472d558fc75SAmine Khaldi                 EndMenu();
3473c2c66affSColin Finck                 return TRUE;
3474c2c66affSColin Finck             }
3475c2c66affSColin Finck     }
3476c2c66affSColin Finck     return DefWindowProcA( hwnd, msg, wparam, lparam);
3477c2c66affSColin Finck }
3478c2c66affSColin Finck 
test_menu_cancelmode(void)3479c2c66affSColin Finck static void test_menu_cancelmode(void)
3480c2c66affSColin Finck {
3481c2c66affSColin Finck     DWORD ret;
3482c2c66affSColin Finck     HWND hwnd, hwndchild;
3483c2c66affSColin Finck     HMENU menu, menubar;
3484c2c66affSColin Finck     MSG msg;
3485d558fc75SAmine Khaldi 
3486c2c66affSColin Finck     hwnd = CreateWindowExA( 0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
3487c2c66affSColin Finck             WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
3488c2c66affSColin Finck             NULL, NULL, NULL, NULL);
3489c2c66affSColin Finck     hwndchild = CreateWindowExA( 0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
3490c2c66affSColin Finck             WS_VISIBLE | WS_CHILD, 10, 10, 20, 20,
3491c2c66affSColin Finck             hwnd, NULL, NULL, NULL);
3492c2c66affSColin Finck     ok( hwnd != NULL && hwndchild != NULL,
3493c2c66affSColin Finck             "CreateWindowEx failed with error %d\n", GetLastError());
3494c2c66affSColin Finck     g_hwndtosend = hwnd;
3495c2c66affSColin Finck     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_cancelmode_wnd_proc);
3496c2c66affSColin Finck     SetWindowLongPtrA( hwndchild, GWLP_WNDPROC, (LONG_PTR)menu_cancelmode_wnd_proc);
3497c2c66affSColin Finck     menu = CreatePopupMenu();
3498c2c66affSColin Finck     ok( menu != NULL, "CreatePopupMenu failed with error %d\n", GetLastError());
3499c2c66affSColin Finck     ret = AppendMenuA( menu, MF_STRING, 1, "winetest");
3500c2c66affSColin Finck     ok( ret, "Functie failed lasterror is %u\n", GetLastError());
3501c2c66affSColin Finck     /* seems to be needed only on wine :( */
3502c2c66affSColin Finck     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
3503c2c66affSColin Finck         DispatchMessageA(&msg);
3504c2c66affSColin Finck     /* test the effect of sending a WM_CANCELMODE message in the WM_INITMENULOOP
3505c2c66affSColin Finck      * handler of the menu owner */
3506c2c66affSColin Finck     /* test results is extracted from variable g_got_enteridle. Possible values:
3507c2c66affSColin Finck      * 0 : complete conformance. Sending WM_CANCELMODE cancels a menu initializing tracking
3508c2c66affSColin Finck      * 1 : Sending WM_CANCELMODE cancels a menu that is in tracking state
3509c2c66affSColin Finck      * 2 : Sending WM_CANCELMODE does not work
3510c2c66affSColin Finck      */
3511c2c66affSColin Finck     /* menu owner is top level window */
3512c2c66affSColin Finck     g_hwndtosend = hwnd;
3513c2c66affSColin Finck     TrackPopupMenu( menu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
3514c2c66affSColin Finck     ok( g_got_enteridle == 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle);
3515c2c66affSColin Finck     /* menu owner is child window */
3516c2c66affSColin Finck     g_hwndtosend = hwndchild;
3517c2c66affSColin Finck     TrackPopupMenu( menu, TPM_RETURNCMD, 100,100, 0, hwndchild, NULL);
3518c2c66affSColin Finck     ok(g_got_enteridle == 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle);
3519c2c66affSColin Finck     /* now send the WM_CANCELMODE messages to the WRONG window */
3520c2c66affSColin Finck     /* those should fail ( to have any effect) */
3521c2c66affSColin Finck     g_hwndtosend = hwnd;
3522c2c66affSColin Finck     TrackPopupMenu( menu, TPM_RETURNCMD, 100,100, 0, hwndchild, NULL);
3523c2c66affSColin Finck     ok( g_got_enteridle == 2, "received %d WM_ENTERIDLE messages, should be 2\n", g_got_enteridle);
3524c2c66affSColin Finck 
3525c2c66affSColin Finck     /* test canceling tracking in a window's menu bar */
3526c2c66affSColin Finck     menubar = CreateMenu();
3527c2c66affSColin Finck     ok( menubar != NULL, "CreateMenu failed with error %d\n", GetLastError());
3528c2c66affSColin Finck     ret = AppendMenuA( menubar, MF_POPUP|MF_STRING, (UINT_PTR)menu, "winetest");
3529c2c66affSColin Finck     ok( ret, "AppendMenuA failed lasterror is %u\n", GetLastError());
3530c2c66affSColin Finck     ret = SetMenu( hwnd, menubar );
3531c2c66affSColin Finck     ok( ret, "SetMenu failed lasterror is %u\n", GetLastError());
3532c2c66affSColin Finck     /* initiate tracking */
3533c2c66affSColin Finck     g_hwndtosend = hwnd;
3534c2c66affSColin Finck     ret = SendMessageA( hwnd, WM_SYSCOMMAND, SC_KEYMENU, 0 );
3535c2c66affSColin Finck     ok( ret == 0, "Sending WM_SYSCOMMAND/SC_KEYMENU failed lasterror is %u\n", GetLastError());
3536c2c66affSColin Finck     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
3537c2c66affSColin Finck         DispatchMessageA(&msg);
3538c2c66affSColin Finck     ok(g_got_enteridle == 0, "received %d WM_ENTERIDLE messages, none expected\n", g_got_enteridle);
3539c2c66affSColin Finck 
3540c2c66affSColin Finck     /* cleanup */
3541c2c66affSColin Finck     DestroyMenu( menubar );
3542c2c66affSColin Finck     DestroyMenu( menu);
3543c2c66affSColin Finck     DestroyWindow( hwndchild);
3544c2c66affSColin Finck     DestroyWindow( hwnd);
3545c2c66affSColin Finck }
3546c2c66affSColin Finck 
3547c2c66affSColin Finck /* show menu trees have a maximum depth */
test_menu_maxdepth(void)3548c2c66affSColin Finck static void test_menu_maxdepth(void)
3549c2c66affSColin Finck {
3550c2c66affSColin Finck #define NR_MENUS 100
3551c2c66affSColin Finck     HMENU hmenus[ NR_MENUS];
3552c2c66affSColin Finck     int i;
3553c2c66affSColin Finck     DWORD ret;
3554c2c66affSColin Finck 
3555c2c66affSColin Finck     SetLastError(12345678);
3556c2c66affSColin Finck     for( i = 0; i < NR_MENUS; i++) {
3557c2c66affSColin Finck         hmenus[i] = CreatePopupMenu();
3558c2c66affSColin Finck         if( !hmenus[i]) break;
3559c2c66affSColin Finck     }
3560c2c66affSColin Finck     ok( i == NR_MENUS, "could not create more than %d menu's\n", i);
3561c2c66affSColin Finck     for( i = 1; i < NR_MENUS; i++) {
3562c2c66affSColin Finck         ret = AppendMenuA( hmenus[i], MF_POPUP, (UINT_PTR)hmenus[i-1],"test");
3563c2c66affSColin Finck         if( !ret) break;
3564c2c66affSColin Finck     }
3565c2c66affSColin Finck     trace("Maximum depth is %d\n", i);
3566c2c66affSColin Finck     ok( GetLastError() == 12345678, "unexpected error %d\n",  GetLastError());
3567c2c66affSColin Finck     ok( i < NR_MENUS ||
3568c2c66affSColin Finck            broken( i == NR_MENUS), /* win98, NT */
3569c2c66affSColin Finck            "no ( or very large) limit on menu depth!\n");
3570c2c66affSColin Finck 
3571c2c66affSColin Finck     for( i = 0; i < NR_MENUS; i++)
3572c2c66affSColin Finck         DestroyMenu( hmenus[i]);
3573c2c66affSColin Finck }
3574c2c66affSColin Finck 
3575c2c66affSColin Finck /* bug #12171 */
test_menu_circref(void)3576c2c66affSColin Finck static void test_menu_circref(void)
3577c2c66affSColin Finck {
3578c2c66affSColin Finck     HMENU menu1, menu2;
3579c2c66affSColin Finck     DWORD ret;
3580c2c66affSColin Finck 
3581c2c66affSColin Finck     menu1 = CreatePopupMenu();
3582c2c66affSColin Finck     menu2 = CreatePopupMenu();
3583c2c66affSColin Finck     ok( menu1 && menu2, "error creating menus.\n");
3584c2c66affSColin Finck     ret = AppendMenuA( menu1, MF_POPUP, (UINT_PTR)menu2, "winetest");
3585c2c66affSColin Finck     ok( ret, "AppendMenu failed, error is %d\n", GetLastError());
3586c2c66affSColin Finck     ret = AppendMenuA( menu1, MF_STRING | MF_HILITE, 123, "winetest");
3587c2c66affSColin Finck     ok( ret, "AppendMenu failed, error is %d\n", GetLastError());
3588c2c66affSColin Finck     /* app chooses an id that happens to clash with its own hmenu */
3589c2c66affSColin Finck     ret = AppendMenuA( menu2, MF_STRING, (UINT_PTR)menu2, "winetest");
3590c2c66affSColin Finck     ok( ret, "AppendMenu failed, error is %d\n", GetLastError());
3591c2c66affSColin Finck     /* now attempt to change the string of the first item of menu1 */
3592c2c66affSColin Finck     ret = ModifyMenuA( menu1, (UINT_PTR)menu2, MF_POPUP, (UINT_PTR)menu2, "menu 2");
3593c2c66affSColin Finck     ok( !ret ||
3594c2c66affSColin Finck             broken( ret), /* win98, NT */
3595c2c66affSColin Finck             "ModifyMenu should have failed.\n");
3596c2c66affSColin Finck     if( !ret) { /* will probably stack fault if the ModifyMenu succeeded */
3597c2c66affSColin Finck         ret = GetMenuState( menu1, 123, 0);
3598c2c66affSColin Finck         ok( ret == MF_HILITE, "GetMenuState returned %x\n",ret);
3599c2c66affSColin Finck     }
3600c2c66affSColin Finck     DestroyMenu( menu2);
3601c2c66affSColin Finck     DestroyMenu( menu1);
3602c2c66affSColin Finck }
3603c2c66affSColin Finck 
3604c2c66affSColin Finck /* test how the menu texts are aligned when the menu items have
3605c2c66affSColin Finck  * different combinations of text and bitmaps (bug #13350) */
test_menualign(void)3606c2c66affSColin Finck static void test_menualign(void)
3607c2c66affSColin Finck {
3608c2c66affSColin Finck     BYTE bmfill[300];
3609c2c66affSColin Finck     HMENU menu;
3610c2c66affSColin Finck     HBITMAP hbm1, hbm2, hbm3;
3611c2c66affSColin Finck     MENUITEMINFOA mii = { sizeof(MENUITEMINFOA) };
3612c2c66affSColin Finck     DWORD ret;
3613c2c66affSColin Finck     HWND hwnd;
3614c2c66affSColin Finck     MENUINFO mi = { sizeof( MENUINFO)};
3615c2c66affSColin Finck 
3616c2c66affSColin Finck     if( !winetest_interactive) {
3617c2c66affSColin Finck         skip( "interactive alignment tests.\n");
3618c2c66affSColin Finck         return;
3619c2c66affSColin Finck     }
3620c2c66affSColin Finck     hwnd = CreateWindowExA(0,
3621c2c66affSColin Finck             "STATIC",
3622c2c66affSColin Finck             "Menu text alignment Test\nPlease make a selection.",
3623c2c66affSColin Finck             WS_OVERLAPPEDWINDOW,
3624c2c66affSColin Finck             100, 100,
3625c2c66affSColin Finck             300, 300,
3626c2c66affSColin Finck             NULL, NULL, 0, NULL);
3627c2c66affSColin Finck     ShowWindow( hwnd, SW_SHOW);
3628c2c66affSColin Finck     /* create bitmaps */
3629c2c66affSColin Finck     memset( bmfill, 0xcc, sizeof( bmfill));
3630c2c66affSColin Finck     hbm1 = CreateBitmap( 10,10,1,1,bmfill);
3631c2c66affSColin Finck     hbm2 = CreateBitmap( 20,20,1,1,bmfill);
3632c2c66affSColin Finck     hbm3 = CreateBitmap( 50,6,1,1,bmfill);
3633c2c66affSColin Finck     ok( hbm1 && hbm2 && hbm3, "Creating bitmaps failed\n");
3634c2c66affSColin Finck     menu = CreatePopupMenu();
3635c2c66affSColin Finck     ok( menu != NULL, "CreatePopupMenu() failed\n");
3636*7a62c32bSAmine Khaldi 
3637c2c66affSColin Finck     mi.fMask = MIM_STYLE;
3638*7a62c32bSAmine Khaldi     ret = GetMenuInfo( menu, &mi);
3639c2c66affSColin Finck     ok( ret, "GetMenuInfo failed: %d\n", GetLastError());
3640c2c66affSColin Finck     ok( menu != NULL, "GetMenuInfo() failed\n");
3641c2c66affSColin Finck     ok( 0 == mi.dwStyle, "menuinfo style is %x\n", mi.dwStyle);
3642*7a62c32bSAmine Khaldi 
3643c2c66affSColin Finck     /* test 1 */
3644c2c66affSColin Finck     mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3645c2c66affSColin Finck     mii.wID = 1;
3646c2c66affSColin Finck     mii.hbmpItem = hbm1;
3647c2c66affSColin Finck     mii.dwTypeData = (LPSTR) " OK: menu texts are correctly left-aligned.";
3648c2c66affSColin Finck     ret = InsertMenuItemA( menu, -1, TRUE, &mii);
3649c2c66affSColin Finck     ok( ret, "InsertMenuItem() failed\n");
3650c2c66affSColin Finck     mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID ;
3651c2c66affSColin Finck     mii.wID = 2;
3652c2c66affSColin Finck     mii.hbmpItem = hbm2;
3653c2c66affSColin Finck     mii.dwTypeData = (LPSTR) " FAIL: menu texts are NOT left-aligned.";
3654c2c66affSColin Finck     ret = InsertMenuItemA( menu, -1, TRUE, &mii);
3655c2c66affSColin Finck     ok( ret, "InsertMenuItem() failed\n");
3656c2c66affSColin Finck     ret = TrackPopupMenu( menu, TPM_RETURNCMD, 110, 200, 0, hwnd, NULL);
3657c2c66affSColin Finck     ok( ret != 2, "User indicated that menu text alignment test 1 failed %d\n", ret);
3658c2c66affSColin Finck     /* test 2*/
3659c2c66affSColin Finck     mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3660c2c66affSColin Finck     mii.wID = 3;
3661c2c66affSColin Finck     mii.hbmpItem = hbm3;
3662c2c66affSColin Finck     mii.dwTypeData = NULL;
3663c2c66affSColin Finck     ret = InsertMenuItemA( menu, 0, TRUE, &mii);
3664c2c66affSColin Finck     ok( ret, "InsertMenuItem() failed\n");
3665c2c66affSColin Finck     mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3666c2c66affSColin Finck     mii.wID = 1;
3667c2c66affSColin Finck     mii.hbmpItem = hbm1;
3668c2c66affSColin Finck     /* make the text a bit longer, to keep it readable */
3669c2c66affSColin Finck     /* this bug is on winXP and reproduced on wine */
3670c2c66affSColin Finck     mii.dwTypeData = (LPSTR) " OK: menu texts are to the right of the bitmaps........";
3671c2c66affSColin Finck     ret = SetMenuItemInfoA( menu, 1, TRUE, &mii);
3672c2c66affSColin Finck     ok( ret, "SetMenuItemInfo() failed\n");
3673c2c66affSColin Finck     mii.wID = 2;
3674c2c66affSColin Finck     mii.hbmpItem = hbm2;
3675c2c66affSColin Finck     mii.dwTypeData = (LPSTR) " FAIL: menu texts are below the first bitmap.  ";
3676c2c66affSColin Finck     ret = SetMenuItemInfoA( menu, 2, TRUE, &mii);
3677c2c66affSColin Finck     ok( ret, "SetMenuItemInfo() failed\n");
3678c2c66affSColin Finck     ret = TrackPopupMenu( menu, TPM_RETURNCMD, 110, 200, 0, hwnd, NULL);
3679c2c66affSColin Finck     ok( ret != 2, "User indicated that menu text alignment test 2 failed %d\n", ret);
3680c2c66affSColin Finck     /* test 3 */
3681c2c66affSColin Finck     mii.fMask = MIIM_TYPE | MIIM_ID;
3682c2c66affSColin Finck     mii.wID = 3;
3683c2c66affSColin Finck     mii.fType = MFT_BITMAP;
3684c2c66affSColin Finck     mii.dwTypeData = (LPSTR) hbm3;
3685c2c66affSColin Finck     ret = SetMenuItemInfoA( menu, 0, TRUE, &mii);
3686c2c66affSColin Finck     ok( ret, "SetMenuItemInfo() failed\n");
3687c2c66affSColin Finck     mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
3688c2c66affSColin Finck     mii.wID = 1;
3689c2c66affSColin Finck     mii.hbmpItem = NULL;
3690c2c66affSColin Finck     mii.dwTypeData = (LPSTR) " OK: menu texts are below the bitmap.";
3691c2c66affSColin Finck     ret = SetMenuItemInfoA( menu, 1, TRUE, &mii);
3692c2c66affSColin Finck     ok( ret, "SetMenuItemInfo() failed\n");
3693c2c66affSColin Finck     mii.wID = 2;
3694c2c66affSColin Finck     mii.hbmpItem = NULL;
3695c2c66affSColin Finck     mii.dwTypeData = (LPSTR) " FAIL: menu texts are NOT below the bitmap.";
3696c2c66affSColin Finck     ret = SetMenuItemInfoA( menu, 2, TRUE, &mii);
3697c2c66affSColin Finck     ok( ret, "SetMenuItemInfo() failed\n");
3698c2c66affSColin Finck     ret = TrackPopupMenu( menu, TPM_RETURNCMD, 110, 200, 0, hwnd, NULL);
3699c2c66affSColin Finck     ok( ret != 2, "User indicated that menu text alignment test 3 failed %d\n", ret);
3700c2c66affSColin Finck     /* cleanup */
3701c2c66affSColin Finck     DeleteObject( hbm1);
3702c2c66affSColin Finck     DeleteObject( hbm2);
3703c2c66affSColin Finck     DeleteObject( hbm3);
3704c2c66affSColin Finck     DestroyMenu( menu);
3705c2c66affSColin Finck     DestroyWindow( hwnd);
3706c2c66affSColin Finck }
3707c2c66affSColin Finck 
menu_fill_in_init(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)3708c2c66affSColin Finck static LRESULT WINAPI menu_fill_in_init(HWND hwnd, UINT msg,
3709c2c66affSColin Finck         WPARAM wparam, LPARAM lparam)
3710c2c66affSColin Finck {
3711c2c66affSColin Finck     HMENU hmenupopup;
3712c2c66affSColin Finck     BOOL ret;
3713c2c66affSColin Finck     switch (msg)
3714c2c66affSColin Finck     {
3715c2c66affSColin Finck         case WM_INITMENUPOPUP:
3716c2c66affSColin Finck             gflag_initmenupopup++;
3717c2c66affSColin Finck             hmenupopup = (HMENU) wparam;
3718c2c66affSColin Finck             ret = AppendMenuA(hmenupopup, MF_STRING , 100, "item 1");
3719c2c66affSColin Finck             ok(ret, "AppendMenu failed.\n");
3720c2c66affSColin Finck             ret = AppendMenuA(hmenupopup, MF_STRING , 101, "item 2");
3721c2c66affSColin Finck             ok(ret, "AppendMenu failed.\n");
3722c2c66affSColin Finck             break;
3723c2c66affSColin Finck         case WM_ENTERMENULOOP:
3724c2c66affSColin Finck             gflag_entermenuloop++;
3725c2c66affSColin Finck             break;
3726c2c66affSColin Finck         case WM_INITMENU:
3727c2c66affSColin Finck             gflag_initmenu++;
3728c2c66affSColin Finck             break;
3729c2c66affSColin Finck         case WM_ENTERIDLE:
3730c2c66affSColin Finck             gflag_enteridle++;
3731c2c66affSColin Finck             PostMessageA(hwnd, WM_CANCELMODE, 0, 0);
3732c2c66affSColin Finck             return TRUE;
3733c2c66affSColin Finck         case WM_MENUSELECT:
3734c2c66affSColin Finck             selectitem_wp = wparam;
3735c2c66affSColin Finck             selectitem_lp = lparam;
3736c2c66affSColin Finck             break;
3737c2c66affSColin Finck     }
3738c2c66affSColin Finck     return DefWindowProcA(hwnd, msg, wparam, lparam);
3739c2c66affSColin Finck }
3740c2c66affSColin Finck 
test_emptypopup(void)3741c2c66affSColin Finck static void test_emptypopup(void)
3742c2c66affSColin Finck {
3743c2c66affSColin Finck     BOOL ret;
3744c2c66affSColin Finck     HMENU hmenu;
3745c2c66affSColin Finck 
3746c2c66affSColin Finck     HWND hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
3747c2c66affSColin Finck                                WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
3748c2c66affSColin Finck                                NULL, NULL, NULL, NULL);
3749c2c66affSColin Finck     ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
3750c2c66affSColin Finck     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
3751c2c66affSColin Finck 
3752c2c66affSColin Finck     hmenu = CreatePopupMenu();
3753c2c66affSColin Finck     ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
3754c2c66affSColin Finck 
3755c2c66affSColin Finck     gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = gflag_enteridle = 0;
3756c2c66affSColin Finck     selectitem_wp = 0xdeadbeef;
3757c2c66affSColin Finck     selectitem_lp = 0xdeadbeef;
3758c2c66affSColin Finck 
3759c2c66affSColin Finck     ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
3760c2c66affSColin Finck     ok(ret == 0, "got %i\n", ret);
3761c2c66affSColin Finck 
3762c2c66affSColin Finck     ok(gflag_initmenupopup == 1, "got %i\n", gflag_initmenupopup);
3763c2c66affSColin Finck     ok(gflag_entermenuloop == 1, "got %i\n", gflag_entermenuloop);
3764c2c66affSColin Finck     ok(gflag_initmenu == 1, "got %i\n", gflag_initmenu);
3765c2c66affSColin Finck     ok(gflag_enteridle == 0, "got %i\n", gflag_initmenu);
3766c2c66affSColin Finck 
3767c2c66affSColin Finck     ok(selectitem_wp == 0xdeadbeef, "got %lx\n", selectitem_wp);
3768c2c66affSColin Finck     ok(selectitem_lp == 0xdeadbeef, "got %lx\n", selectitem_lp);
3769c2c66affSColin Finck 
3770c2c66affSColin Finck     gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = gflag_enteridle = 0;
3771c2c66affSColin Finck     selectitem_wp = 0xdeadbeef;
3772c2c66affSColin Finck     selectitem_lp = 0xdeadbeef;
3773c2c66affSColin Finck 
3774c2c66affSColin Finck     ret = TrackPopupMenu( hmenu, 0, 100,100, 0, hwnd, NULL);
3775c2c66affSColin Finck     ok(ret == 0, "got %i\n", ret);
3776c2c66affSColin Finck 
3777c2c66affSColin Finck     ok(gflag_initmenupopup == 1, "got %i\n", gflag_initmenupopup);
3778c2c66affSColin Finck     ok(gflag_entermenuloop == 1, "got %i\n", gflag_entermenuloop);
3779c2c66affSColin Finck     ok(gflag_initmenu == 1, "got %i\n", gflag_initmenu);
3780c2c66affSColin Finck     ok(gflag_enteridle == 0, "got %i\n", gflag_initmenu);
3781c2c66affSColin Finck 
3782c2c66affSColin Finck     ok(selectitem_wp == 0xdeadbeef, "got %lx\n", selectitem_wp);
3783c2c66affSColin Finck     ok(selectitem_lp == 0xdeadbeef, "got %lx\n", selectitem_lp);
3784c2c66affSColin Finck 
3785c2c66affSColin Finck     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_fill_in_init);
3786c2c66affSColin Finck 
3787c2c66affSColin Finck     gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = gflag_enteridle = 0;
3788c2c66affSColin Finck     selectitem_wp = 0xdeadbeef;
3789c2c66affSColin Finck     selectitem_lp = 0xdeadbeef;
3790c2c66affSColin Finck 
3791c2c66affSColin Finck     ret = TrackPopupMenu( hmenu, 0, 100,100, 0, hwnd, NULL);
3792c2c66affSColin Finck     ok(ret == 1, "got %i\n", ret);
3793c2c66affSColin Finck 
3794c2c66affSColin Finck     ok(gflag_initmenupopup == 1, "got %i\n", gflag_initmenupopup);
3795c2c66affSColin Finck     ok(gflag_entermenuloop == 1, "got %i\n", gflag_entermenuloop);
3796c2c66affSColin Finck     ok(gflag_initmenu == 1, "got %i\n", gflag_initmenu);
3797c2c66affSColin Finck     ok(gflag_enteridle == 1, "got %i\n", gflag_initmenu);
3798c2c66affSColin Finck 
3799c2c66affSColin Finck     ok(selectitem_wp == 0xffff0000, "got %lx\n", selectitem_wp);
3800c2c66affSColin Finck     ok(selectitem_lp == 0, "got %lx\n", selectitem_lp);
3801c2c66affSColin Finck 
3802c2c66affSColin Finck     DestroyWindow(hwnd);
3803c2c66affSColin Finck 
3804c2c66affSColin Finck     ret = DestroyMenu(hmenu);
3805c2c66affSColin Finck     ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
3806c2c66affSColin Finck }
3807c2c66affSColin Finck 
get_bad_hmenu(UINT_PTR id)3808c2c66affSColin Finck static HMENU get_bad_hmenu( UINT_PTR id )
3809c2c66affSColin Finck {
3810c2c66affSColin Finck     while (IsMenu( (HMENU)id )) id++;
3811c2c66affSColin Finck     return (HMENU)id;
3812c2c66affSColin Finck }
3813c2c66affSColin Finck 
test_AppendMenu(void)3814c2c66affSColin Finck static void test_AppendMenu(void)
3815c2c66affSColin Finck {
3816c2c66affSColin Finck     static char string[] = "string";
3817c2c66affSColin Finck     MENUITEMINFOA mii;
3818c2c66affSColin Finck     HMENU hmenu, hsubmenu;
3819c2c66affSColin Finck     HBITMAP hbmp;
3820c2c66affSColin Finck     char buf[16];
3821c2c66affSColin Finck     BOOL ret;
3822c2c66affSColin Finck 
3823c2c66affSColin Finck     hmenu = CreateMenu();
3824c2c66affSColin Finck     ok(hmenu != 0, "CreateMenu failed\n");
3825c2c66affSColin Finck     ret = AppendMenuA(hmenu, MF_OWNERDRAW, 201, "item 1");
3826c2c66affSColin Finck     ok(ret, "AppendMenu failed\n");
3827c2c66affSColin Finck     check_menu_items(hmenu, 201, MF_OWNERDRAW, 0);
3828c2c66affSColin Finck     DestroyMenu(hmenu);
3829c2c66affSColin Finck 
3830c2c66affSColin Finck     hmenu = CreateMenu();
3831c2c66affSColin Finck     ok(hmenu != 0, "CreateMenu failed\n");
3832c2c66affSColin Finck     hsubmenu = get_bad_hmenu( 202 );
3833c2c66affSColin Finck     ret = AppendMenuA(hmenu, MF_POPUP, (UINT_PTR)hsubmenu, "item 1");
3834c2c66affSColin Finck     ok(ret, "AppendMenu failed\n");
3835c2c66affSColin Finck     check_menu_items(hmenu, (UINT_PTR)hsubmenu, MF_STRING, 0);
3836c2c66affSColin Finck     DestroyMenu(hmenu);
3837c2c66affSColin Finck 
3838c2c66affSColin Finck     hmenu = CreateMenu();
3839c2c66affSColin Finck     ok(hmenu != 0, "CreateMenu failed\n");
3840c2c66affSColin Finck     hsubmenu = get_bad_hmenu( 203 );
3841c2c66affSColin Finck     ret = AppendMenuA(hmenu, MF_OWNERDRAW | MF_POPUP, (UINT_PTR)hsubmenu, "item 1");
3842c2c66affSColin Finck     ok(ret, "AppendMenu failed\n");
3843c2c66affSColin Finck     check_menu_items(hmenu, (UINT_PTR)hsubmenu, MF_OWNERDRAW, 0);
3844c2c66affSColin Finck     DestroyMenu(hmenu);
3845c2c66affSColin Finck 
3846c2c66affSColin Finck     hmenu = CreateMenu();
3847c2c66affSColin Finck     ok(hmenu != 0, "CreateMenu failed\n");
3848c2c66affSColin Finck     hsubmenu = CreateMenu();
3849c2c66affSColin Finck     ok(hsubmenu != 0, "CreateMenu failed\n");
3850c2c66affSColin Finck     ret = AppendMenuA(hmenu, MF_OWNERDRAW, (UINT_PTR)hsubmenu, "item 1");
3851c2c66affSColin Finck     ok(ret, "AppendMenu failed\n");
3852c2c66affSColin Finck     check_menu_items(hmenu, (UINT_PTR)hsubmenu, MF_OWNERDRAW, 0);
3853c2c66affSColin Finck     DestroyMenu(hmenu);
3854c2c66affSColin Finck     DestroyMenu(hsubmenu);
3855c2c66affSColin Finck 
3856c2c66affSColin Finck     hmenu = CreateMenu();
3857c2c66affSColin Finck     ok(hmenu != 0, "CreateMenu failed\n");
3858c2c66affSColin Finck     hsubmenu = CreateMenu();
3859c2c66affSColin Finck     ok(hsubmenu != 0, "CreateMenu failed\n");
3860c2c66affSColin Finck     ret = AppendMenuA(hmenu, MF_POPUP, (UINT_PTR)hsubmenu, "item 1");
3861c2c66affSColin Finck     ok(ret, "AppendMenu failed\n");
3862c2c66affSColin Finck     check_menu_items(hmenu, (UINT_PTR)hsubmenu, MF_STRING, 0);
3863c2c66affSColin Finck     DestroyMenu(hmenu);
3864c2c66affSColin Finck     DestroyMenu(hsubmenu);
3865c2c66affSColin Finck 
3866c2c66affSColin Finck     hmenu = CreateMenu();
3867c2c66affSColin Finck     ok(hmenu != 0, "CreateMenu failed\n");
3868c2c66affSColin Finck     hsubmenu = CreateMenu();
3869c2c66affSColin Finck     ok(hsubmenu != 0, "CreateMenu failed\n");
3870c2c66affSColin Finck     ret = AppendMenuA(hmenu, MF_OWNERDRAW | MF_POPUP, (UINT_PTR)hsubmenu, "item 1");
3871c2c66affSColin Finck     ok(ret, "AppendMenu failed\n");
3872c2c66affSColin Finck     check_menu_items(hmenu, (UINT_PTR)hsubmenu, MF_OWNERDRAW, 0);
3873c2c66affSColin Finck     DestroyMenu(hmenu);
3874c2c66affSColin Finck     DestroyMenu(hsubmenu);
3875c2c66affSColin Finck 
3876c2c66affSColin Finck     hmenu = CreateMenu();
3877c2c66affSColin Finck     ok(hmenu != 0, "CreateMenu failed\n");
3878c2c66affSColin Finck     hsubmenu = CreatePopupMenu();
3879c2c66affSColin Finck     ok(hsubmenu != 0, "CreatePopupMenu failed\n");
3880c2c66affSColin Finck     ret = AppendMenuA(hmenu, MF_OWNERDRAW, (UINT_PTR)hsubmenu, "item 1");
3881c2c66affSColin Finck     ok(ret, "AppendMenu failed\n");
3882c2c66affSColin Finck     check_menu_items(hmenu, (UINT_PTR)hsubmenu, MF_OWNERDRAW, 0);
3883c2c66affSColin Finck     DestroyMenu(hmenu);
3884c2c66affSColin Finck     DestroyMenu(hsubmenu);
3885c2c66affSColin Finck 
3886c2c66affSColin Finck     hmenu = CreateMenu();
3887c2c66affSColin Finck     ok(hmenu != 0, "CreateMenu failed\n");
3888c2c66affSColin Finck     hsubmenu = CreatePopupMenu();
3889c2c66affSColin Finck     ok(hsubmenu != 0, "CreatePopupMenu failed\n");
3890c2c66affSColin Finck     ret = AppendMenuA(hmenu, MF_POPUP, (UINT_PTR)hsubmenu, "item 1");
3891c2c66affSColin Finck     ok(ret, "AppendMenu failed\n");
3892c2c66affSColin Finck     check_menu_items(hmenu, (UINT_PTR)hsubmenu, MF_STRING, 0);
3893c2c66affSColin Finck     DestroyMenu(hmenu);
3894c2c66affSColin Finck     DestroyMenu(hsubmenu);
3895c2c66affSColin Finck 
3896c2c66affSColin Finck     hmenu = CreateMenu();
3897c2c66affSColin Finck     ok(hmenu != 0, "CreateMenu failed\n");
3898c2c66affSColin Finck     hsubmenu = CreatePopupMenu();
3899c2c66affSColin Finck     ok(hsubmenu != 0, "CreatePopupMenu failed\n");
3900c2c66affSColin Finck     ret = AppendMenuA(hmenu, MF_OWNERDRAW | MF_POPUP, (UINT_PTR)hsubmenu, "item 1");
3901c2c66affSColin Finck     ok(ret, "AppendMenu failed\n");
3902c2c66affSColin Finck     check_menu_items(hmenu, (UINT_PTR)hsubmenu, MF_OWNERDRAW, 0);
3903c2c66affSColin Finck     DestroyMenu(hmenu);
3904c2c66affSColin Finck     DestroyMenu(hsubmenu);
3905c2c66affSColin Finck 
3906c2c66affSColin Finck     hmenu = CreateMenu();
3907c2c66affSColin Finck     ok(hmenu != 0, "CreateMenu failed\n");
3908c2c66affSColin Finck     ret = AppendMenuA(hmenu, MF_STRING, 204, "item 1");
3909c2c66affSColin Finck     ok(ret, "AppendMenu failed\n");
3910c2c66affSColin Finck     check_menu_items(hmenu, 204, MF_STRING, 0);
3911c2c66affSColin Finck     hsubmenu = get_bad_hmenu( 205 );
3912c2c66affSColin Finck     ret = ModifyMenuA(hmenu, 0, MF_POPUP | MF_BYPOSITION, (UINT_PTR)hsubmenu, "item 2");
3913c2c66affSColin Finck     ok(ret, "ModifyMenu failed\n");
3914c2c66affSColin Finck     check_menu_items(hmenu, (UINT_PTR)hsubmenu, MF_STRING, 0);
3915c2c66affSColin Finck     memset(&mii, 0, sizeof(mii));
3916c2c66affSColin Finck     mii.cbSize = sizeof(mii);
3917c2c66affSColin Finck     mii.fMask = MIIM_SUBMENU;
3918c2c66affSColin Finck     mii.hSubMenu = get_bad_hmenu( 204 );
3919c2c66affSColin Finck     ret = InsertMenuItemA(hmenu, 0, TRUE, &mii);
3920c2c66affSColin Finck     ok(!ret, "InsertMenuItem should fail\n");
3921c2c66affSColin Finck     ret = SetMenuItemInfoA(hmenu, 0, TRUE, &mii);
3922c2c66affSColin Finck     ok(!ret, "SetMenuItemInfo should fail\n");
3923c2c66affSColin Finck     mii.fMask = MIIM_ID;
3924c2c66affSColin Finck     mii.wID = 206;
3925c2c66affSColin Finck     ret = InsertMenuItemA(hmenu, 0, TRUE, &mii);
3926c2c66affSColin Finck     ok(ret, "InsertMenuItem failed\n");
3927c2c66affSColin Finck if (0) /* FIXME: uncomment once Wine is fixed */ {
3928c2c66affSColin Finck     check_menu_items(hmenu, 206, MF_SEPARATOR, MFS_GRAYED);
3929c2c66affSColin Finck }
3930c2c66affSColin Finck     mii.wID = 207;
3931c2c66affSColin Finck     ret = SetMenuItemInfoA(hmenu, 0, TRUE, &mii);
3932c2c66affSColin Finck     ok(ret, "SetMenuItemInfo failed\n");
3933c2c66affSColin Finck if (0) /* FIXME: uncomment once Wine is fixed */ {
3934c2c66affSColin Finck     check_menu_items(hmenu, 207, MF_SEPARATOR, MFS_GRAYED);
3935c2c66affSColin Finck }
3936c2c66affSColin Finck     DestroyMenu(hmenu);
3937c2c66affSColin Finck 
3938c2c66affSColin Finck     hbmp = CreateBitmap(1, 1, 1, 1, NULL);
3939c2c66affSColin Finck     hmenu = CreateMenu();
3940c2c66affSColin Finck     ok(hmenu != 0, "CreateMenu failed\n");
3941c2c66affSColin Finck 
3942c2c66affSColin Finck     /* menu item with a string and a bitmap */
3943c2c66affSColin Finck     memset(&mii, 0, sizeof(mii));
3944c2c66affSColin Finck     mii.cbSize = sizeof(mii);
3945c2c66affSColin Finck     mii.fMask = MIIM_STRING | MIIM_BITMAP;
3946c2c66affSColin Finck     mii.dwTypeData = string;
3947c2c66affSColin Finck     mii.cch = strlen(string);
3948c2c66affSColin Finck     mii.hbmpItem = hbmp;
3949c2c66affSColin Finck     ret = InsertMenuItemA(hmenu, 0, TRUE, &mii);
3950c2c66affSColin Finck     ok(ret, "InsertMenuItem failed\n");
3951c2c66affSColin Finck     memset(&mii, 0x81, sizeof(mii));
3952c2c66affSColin Finck     memset(buf, 0x81, sizeof(buf));
3953c2c66affSColin Finck     mii.cbSize = sizeof(mii);
3954c2c66affSColin Finck     mii.fMask  = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_STRING | MIIM_BITMAP;
3955c2c66affSColin Finck     mii.dwTypeData = buf;
3956c2c66affSColin Finck     mii.cch = sizeof(buf);
3957c2c66affSColin Finck     mii.dwItemData = 0x81818181;
3958c2c66affSColin Finck     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
3959c2c66affSColin Finck     ok(ret, "GetMenuItemInfo failed\n");
3960c2c66affSColin Finck     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
3961c2c66affSColin Finck     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
3962c2c66affSColin Finck     ok(mii.wID == 0, "expected 0, got %#x\n", mii.wID);
3963c2c66affSColin Finck     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
3964c2c66affSColin Finck     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
3965c2c66affSColin Finck     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
3966c2c66affSColin Finck     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
3967c2c66affSColin Finck     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
3968c2c66affSColin Finck     ok(mii.hbmpItem == hbmp, "expected %p, got %p\n", hbmp, mii.hbmpItem);
3969c2c66affSColin Finck 
3970c2c66affSColin Finck     memset(&mii, 0x81, sizeof(mii));
3971c2c66affSColin Finck     mii.cbSize = sizeof(mii);
3972c2c66affSColin Finck     mii.fMask  = MIIM_TYPE;
3973c2c66affSColin Finck     mii.dwItemData = 0x81818181;
3974c2c66affSColin Finck     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
3975c2c66affSColin Finck     ok(ret, "GetMenuItemInfo failed\n");
3976c2c66affSColin Finck     ok(mii.fType == MF_BITMAP, "expected MF_BITMAP, got %#x\n", mii.fType);
3977c2c66affSColin Finck     ok(mii.fState == 0x81818181, "expected 0x81818181, got %#x\n", mii.fState);
3978c2c66affSColin Finck     ok(mii.wID == 0x81818181, "expected 0x81818181, got %#x\n", mii.wID);
3979c2c66affSColin Finck     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
3980c2c66affSColin Finck     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
3981c2c66affSColin Finck     ok(mii.dwTypeData == (LPSTR)hbmp, "expected %p, got %p\n", hbmp, mii.dwTypeData);
3982c2c66affSColin Finck     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
3983c2c66affSColin Finck     ok(mii.hbmpItem == hbmp, "expected %p, got %p\n", hbmp, mii.hbmpItem);
3984c2c66affSColin Finck 
3985c2c66affSColin Finck     memset(&mii, 0x81, sizeof(mii));
3986c2c66affSColin Finck     memset(buf, 0x81, sizeof(buf));
3987c2c66affSColin Finck     mii.cbSize = sizeof(mii);
3988c2c66affSColin Finck     mii.fMask  = MIIM_STATE | MIIM_ID | MIIM_TYPE | MIIM_DATA;
3989c2c66affSColin Finck     mii.dwTypeData = buf;
3990c2c66affSColin Finck     mii.cch = sizeof(buf);
3991c2c66affSColin Finck     mii.dwItemData = 0x81818181;
3992c2c66affSColin Finck     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
3993c2c66affSColin Finck     ok(ret, "GetMenuItemInfo failed\n");
3994c2c66affSColin Finck     ok(mii.fType == MF_BITMAP, "expected MF_BITMAP, got %#x\n", mii.fType);
3995c2c66affSColin Finck     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
3996c2c66affSColin Finck     ok(mii.wID == 0, "expected 0, got %#x\n", mii.wID);
3997c2c66affSColin Finck     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
3998c2c66affSColin Finck     ok(mii.dwItemData == 0, "expected 0, got %#lx\n", mii.dwItemData);
3999c2c66affSColin Finck     ok(mii.dwTypeData == (LPSTR)hbmp, "expected %p, got %p\n", hbmp, mii.dwTypeData);
4000c2c66affSColin Finck     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4001c2c66affSColin Finck     ok(mii.hbmpItem == hbmp, "expected %p, got %p\n", hbmp, mii.hbmpItem);
4002c2c66affSColin Finck 
4003c2c66affSColin Finck     DestroyMenu(hmenu);
4004c2c66affSColin Finck     DeleteObject(hbmp);
4005c2c66affSColin Finck 
4006c2c66affSColin Finck     hmenu = CreateMenu();
4007c2c66affSColin Finck     ok(hmenu != 0, "CreateMenu failed\n");
4008c2c66affSColin Finck 
4009c2c66affSColin Finck     /* menu item with a string and a "magic" bitmap */
4010c2c66affSColin Finck     memset(&mii, 0, sizeof(mii));
4011c2c66affSColin Finck     mii.cbSize = sizeof(mii);
4012c2c66affSColin Finck     mii.fMask = MIIM_STRING | MIIM_BITMAP;
4013c2c66affSColin Finck     mii.dwTypeData = string;
4014c2c66affSColin Finck     mii.cch = strlen(string);
4015c2c66affSColin Finck     mii.hbmpItem = HBMMENU_POPUP_RESTORE;
4016c2c66affSColin Finck     ret = InsertMenuItemA(hmenu, 0, TRUE, &mii);
4017c2c66affSColin Finck     ok(ret, "InsertMenuItem failed\n");
4018c2c66affSColin Finck     memset(&mii, 0x81, sizeof(mii));
4019c2c66affSColin Finck     memset(buf, 0x81, sizeof(buf));
4020c2c66affSColin Finck     mii.cbSize = sizeof(mii);
4021c2c66affSColin Finck     mii.fMask  = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_STRING | MIIM_BITMAP;
4022c2c66affSColin Finck     mii.dwTypeData = buf;
4023c2c66affSColin Finck     mii.cch = sizeof(buf);
4024c2c66affSColin Finck     mii.dwItemData = 0x81818181;
4025c2c66affSColin Finck     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4026c2c66affSColin Finck     ok(ret, "GetMenuItemInfo failed\n");
4027c2c66affSColin Finck     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4028c2c66affSColin Finck     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
4029c2c66affSColin Finck     ok(mii.wID == 0, "expected 0, got %#x\n", mii.wID);
4030c2c66affSColin Finck     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4031c2c66affSColin Finck     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
4032c2c66affSColin Finck     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4033c2c66affSColin Finck     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4034c2c66affSColin Finck     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4035c2c66affSColin Finck     ok(mii.hbmpItem == HBMMENU_POPUP_RESTORE, "expected HBMMENU_POPUP_RESTORE, got %p\n", mii.hbmpItem);
4036c2c66affSColin Finck 
4037c2c66affSColin Finck     memset(&mii, 0x81, sizeof(mii));
4038c2c66affSColin Finck     mii.cbSize = sizeof(mii);
4039c2c66affSColin Finck     mii.fMask  = MIIM_TYPE;
4040c2c66affSColin Finck     mii.dwTypeData = buf;
4041c2c66affSColin Finck     mii.cch = sizeof(buf);
4042c2c66affSColin Finck     mii.dwItemData = 0x81818181;
4043c2c66affSColin Finck     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4044c2c66affSColin Finck     ok(ret, "GetMenuItemInfo failed\n");
4045c2c66affSColin Finck     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4046c2c66affSColin Finck     ok(mii.fState == 0x81818181, "expected 0x81818181, got %#x\n", mii.fState);
4047c2c66affSColin Finck     ok(mii.wID == 0x81818181, "expected 0x81818181, got %#x\n", mii.wID);
4048c2c66affSColin Finck     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4049c2c66affSColin Finck     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
4050c2c66affSColin Finck     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4051c2c66affSColin Finck     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4052c2c66affSColin Finck     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4053c2c66affSColin Finck     ok(mii.hbmpItem == HBMMENU_POPUP_RESTORE, "expected HBMMENU_POPUP_RESTORE, got %p\n", mii.hbmpItem);
4054c2c66affSColin Finck 
4055c2c66affSColin Finck     memset(&mii, 0x81, sizeof(mii));
4056c2c66affSColin Finck     memset(buf, 0x81, sizeof(buf));
4057c2c66affSColin Finck     mii.cbSize = sizeof(mii);
4058c2c66affSColin Finck     mii.fMask  = MIIM_STATE | MIIM_ID | MIIM_TYPE | MIIM_DATA;
4059c2c66affSColin Finck     mii.dwTypeData = buf;
4060c2c66affSColin Finck     mii.cch = sizeof(buf);
4061c2c66affSColin Finck     mii.dwItemData = 0x81818181;
4062c2c66affSColin Finck     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4063c2c66affSColin Finck     ok(ret, "GetMenuItemInfo failed\n");
4064c2c66affSColin Finck     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4065c2c66affSColin Finck     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
4066c2c66affSColin Finck     ok(mii.wID == 0, "expected 0, got %#x\n", mii.wID);
4067c2c66affSColin Finck     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4068c2c66affSColin Finck     ok(mii.dwItemData == 0, "expected 0, got %#lx\n", mii.dwItemData);
4069c2c66affSColin Finck     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4070c2c66affSColin Finck     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4071c2c66affSColin Finck     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4072c2c66affSColin Finck     ok(mii.hbmpItem == HBMMENU_POPUP_RESTORE, "expected HBMMENU_POPUP_RESTORE, got %p\n", mii.hbmpItem);
4073c2c66affSColin Finck 
4074c2c66affSColin Finck     DestroyMenu(hmenu);
4075c2c66affSColin Finck 
4076c2c66affSColin Finck     hbmp = CreateBitmap(1, 1, 1, 1, NULL);
4077c2c66affSColin Finck     hmenu = CreateMenu();
4078c2c66affSColin Finck     ok(hmenu != 0, "CreateMenu failed\n");
4079c2c66affSColin Finck 
4080c2c66affSColin Finck     /* menu item with a string */
4081c2c66affSColin Finck     memset(&mii, 0, sizeof(mii));
4082c2c66affSColin Finck     mii.cbSize = sizeof(mii);
4083c2c66affSColin Finck     mii.fMask  = MIIM_STATE | MIIM_ID | MIIM_TYPE | MIIM_DATA;
4084c2c66affSColin Finck     mii.dwItemData = (ULONG_PTR)hbmp;
4085c2c66affSColin Finck     mii.dwTypeData = string;
4086c2c66affSColin Finck     mii.cch = strlen(string);
4087c2c66affSColin Finck     mii.hbmpItem = hbmp;
4088c2c66affSColin Finck     ret = InsertMenuItemA(hmenu, 0, TRUE, &mii);
4089c2c66affSColin Finck     ok(ret, "InsertMenuItem failed\n");
4090c2c66affSColin Finck     memset(&mii, 0x81, sizeof(mii));
4091c2c66affSColin Finck     memset(buf, 0x81, sizeof(buf));
4092c2c66affSColin Finck     mii.cbSize = sizeof(mii);
4093c2c66affSColin Finck     mii.fMask  = MIIM_STATE | MIIM_ID | MIIM_TYPE | MIIM_DATA;
4094c2c66affSColin Finck     mii.dwTypeData = buf;
4095c2c66affSColin Finck     mii.cch = sizeof(buf);
4096c2c66affSColin Finck     mii.dwItemData = 0x81818181;
4097c2c66affSColin Finck     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4098c2c66affSColin Finck     ok(ret, "GetMenuItemInfo failed\n");
4099c2c66affSColin Finck     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4100c2c66affSColin Finck     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
4101c2c66affSColin Finck     ok(mii.wID == 0, "expected 0, got %#x\n", mii.wID);
4102c2c66affSColin Finck     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4103c2c66affSColin Finck     ok(mii.dwItemData == (ULONG_PTR)hbmp, "expected %p, got %#lx\n", hbmp, mii.dwItemData);
4104c2c66affSColin Finck     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4105c2c66affSColin Finck     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4106c2c66affSColin Finck     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4107c2c66affSColin Finck     ok(mii.hbmpItem == 0, "expected 0, got %p\n", mii.hbmpItem);
4108c2c66affSColin Finck 
4109c2c66affSColin Finck     memset(&mii, 0x81, sizeof(mii));
4110c2c66affSColin Finck     memset(buf, 0x81, sizeof(buf));
4111c2c66affSColin Finck     mii.cbSize = sizeof(mii);
4112c2c66affSColin Finck     mii.fMask  = MIIM_TYPE;
4113c2c66affSColin Finck     mii.dwTypeData = buf;
4114c2c66affSColin Finck     mii.cch = sizeof(buf);
4115c2c66affSColin Finck     mii.dwItemData = 0x81818181;
4116c2c66affSColin Finck     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4117c2c66affSColin Finck     ok(ret, "GetMenuItemInfo failed\n");
4118c2c66affSColin Finck     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4119c2c66affSColin Finck     ok(mii.fState == 0x81818181, "expected 0x81818181, got %#x\n", mii.fState);
4120c2c66affSColin Finck     ok(mii.wID == 0x81818181, "expected 0x81818181, got %#x\n", mii.wID);
4121c2c66affSColin Finck     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4122c2c66affSColin Finck     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
4123c2c66affSColin Finck     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4124c2c66affSColin Finck     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4125c2c66affSColin Finck     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4126c2c66affSColin Finck     ok(mii.hbmpItem == 0, "expected 0, got %p\n", mii.hbmpItem);
4127c2c66affSColin Finck 
4128c2c66affSColin Finck     DestroyMenu(hmenu);
4129c2c66affSColin Finck     DeleteObject(hbmp);
4130c2c66affSColin Finck 
4131c2c66affSColin Finck     /* menu item with a string */
4132c2c66affSColin Finck     hbmp = CreateBitmap(1, 1, 1, 1, NULL);
4133c2c66affSColin Finck     hmenu = CreateMenu();
4134c2c66affSColin Finck     ok(hmenu != 0, "CreateMenu failed\n");
4135c2c66affSColin Finck     memset(&mii, 0, sizeof(mii));
4136c2c66affSColin Finck     mii.cbSize = sizeof(mii);
4137c2c66affSColin Finck     mii.fMask = MIIM_STRING;
4138c2c66affSColin Finck     mii.dwTypeData = string;
4139c2c66affSColin Finck     mii.cch = strlen(string);
4140c2c66affSColin Finck     ret = InsertMenuItemA(hmenu, 0, TRUE, &mii);
4141c2c66affSColin Finck     ok(ret, "InsertMenuItem failed\n");
4142c2c66affSColin Finck     memset(&mii, 0x81, sizeof(mii));
4143c2c66affSColin Finck     memset(buf, 0x81, sizeof(buf));
4144c2c66affSColin Finck     mii.cbSize = sizeof(mii);
4145c2c66affSColin Finck     mii.fMask  = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_STRING | MIIM_BITMAP;
4146c2c66affSColin Finck     mii.dwTypeData = buf;
4147c2c66affSColin Finck     mii.cch = sizeof(buf);
4148c2c66affSColin Finck     mii.dwItemData = 0x81818181;
4149c2c66affSColin Finck     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4150c2c66affSColin Finck     ok(ret, "GetMenuItemInfo failed\n");
4151c2c66affSColin Finck     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4152c2c66affSColin Finck     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
4153c2c66affSColin Finck     ok(mii.wID == 0, "expected 0, got %#x\n", mii.wID);
4154c2c66affSColin Finck     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4155c2c66affSColin Finck     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
4156c2c66affSColin Finck     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4157c2c66affSColin Finck     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4158c2c66affSColin Finck     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4159c2c66affSColin Finck     ok(mii.hbmpItem == 0, "expected 0, got %p\n", mii.hbmpItem);
4160c2c66affSColin Finck 
4161c2c66affSColin Finck     /* add "magic" bitmap to a menu item */
4162c2c66affSColin Finck     mii.fMask = MIIM_BITMAP;
4163c2c66affSColin Finck     mii.hbmpItem = HBMMENU_POPUP_RESTORE;
4164c2c66affSColin Finck     ret = SetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4165c2c66affSColin Finck     ok(ret, "SetMenuItemInfo failed\n");
4166c2c66affSColin Finck     memset(&mii, 0x81, sizeof(mii));
4167c2c66affSColin Finck     memset(buf, 0x81, sizeof(buf));
4168c2c66affSColin Finck     mii.cbSize = sizeof(mii);
4169c2c66affSColin Finck     mii.fMask  = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_STRING | MIIM_BITMAP;
4170c2c66affSColin Finck     mii.dwTypeData = buf;
4171c2c66affSColin Finck     mii.cch = sizeof(buf);
4172c2c66affSColin Finck     mii.dwItemData = 0x81818181;
4173c2c66affSColin Finck     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4174c2c66affSColin Finck     ok(ret, "GetMenuItemInfo failed\n");
4175c2c66affSColin Finck     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4176c2c66affSColin Finck     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
4177c2c66affSColin Finck     ok(mii.wID == 0, "expected 0, got %#x\n", mii.wID);
4178c2c66affSColin Finck     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4179c2c66affSColin Finck     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
4180c2c66affSColin Finck     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4181c2c66affSColin Finck     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4182c2c66affSColin Finck     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4183c2c66affSColin Finck     ok(mii.hbmpItem == HBMMENU_POPUP_RESTORE, "expected HBMMENU_POPUP_RESTORE, got %p\n", mii.hbmpItem);
4184c2c66affSColin Finck 
4185c2c66affSColin Finck     memset(&mii, 0x81, sizeof(mii));
4186c2c66affSColin Finck     memset(buf, 0x81, sizeof(buf));
4187c2c66affSColin Finck     mii.cbSize = sizeof(mii);
4188c2c66affSColin Finck     mii.fMask  = MIIM_TYPE;
4189c2c66affSColin Finck     mii.dwTypeData = buf;
4190c2c66affSColin Finck     mii.cch = sizeof(buf);
4191c2c66affSColin Finck     mii.dwItemData = 0x81818181;
4192c2c66affSColin Finck     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4193c2c66affSColin Finck     ok(ret, "GetMenuItemInfo failed\n");
4194c2c66affSColin Finck     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4195c2c66affSColin Finck     ok(mii.fState == 0x81818181, "expected 0x81818181, got %#x\n", mii.fState);
4196c2c66affSColin Finck     ok(mii.wID == 0x81818181, "expected 0x81818181, got %#x\n", mii.wID);
4197c2c66affSColin Finck     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4198c2c66affSColin Finck     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
4199c2c66affSColin Finck     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4200c2c66affSColin Finck     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4201c2c66affSColin Finck     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4202c2c66affSColin Finck     ok(mii.hbmpItem == HBMMENU_POPUP_RESTORE, "expected HBMMENU_POPUP_RESTORE, got %p\n", mii.hbmpItem);
4203c2c66affSColin Finck 
4204c2c66affSColin Finck     /* replace "magic" bitmap by a normal one */
4205c2c66affSColin Finck     mii.fMask = MIIM_BITMAP;
4206c2c66affSColin Finck     mii.hbmpItem = hbmp;
4207c2c66affSColin Finck     ret = SetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4208c2c66affSColin Finck     ok(ret, "SetMenuItemInfo failed\n");
4209c2c66affSColin Finck     memset(&mii, 0x81, sizeof(mii));
4210c2c66affSColin Finck     memset(buf, 0x81, sizeof(buf));
4211c2c66affSColin Finck     mii.cbSize = sizeof(mii);
4212c2c66affSColin Finck     mii.fMask  = MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_STRING | MIIM_BITMAP;
4213c2c66affSColin Finck     mii.dwTypeData = buf;
4214c2c66affSColin Finck     mii.cch = sizeof(buf);
4215c2c66affSColin Finck     mii.dwItemData = 0x81818181;
4216c2c66affSColin Finck     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4217c2c66affSColin Finck     ok(ret, "GetMenuItemInfo failed\n");
4218c2c66affSColin Finck     ok(mii.fType == MF_STRING, "expected MF_STRING, got %#x\n", mii.fType);
4219c2c66affSColin Finck     ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
4220c2c66affSColin Finck     ok(mii.wID == 0, "expected 0, got %#x\n", mii.wID);
4221c2c66affSColin Finck     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4222c2c66affSColin Finck     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
4223c2c66affSColin Finck     ok(mii.dwTypeData == buf, "expected %p, got %p\n", buf, mii.dwTypeData);
4224c2c66affSColin Finck     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4225c2c66affSColin Finck     ok(!strcmp(buf, string), "expected %s, got %s\n", string, buf);
4226c2c66affSColin Finck     ok(mii.hbmpItem == hbmp, "expected %p, got %p\n", hbmp, mii.hbmpItem);
4227c2c66affSColin Finck 
4228c2c66affSColin Finck     memset(&mii, 0x81, sizeof(mii));
4229c2c66affSColin Finck     memset(buf, 0x81, sizeof(buf));
4230c2c66affSColin Finck     mii.cbSize = sizeof(mii);
4231c2c66affSColin Finck     mii.fMask  = MIIM_TYPE;
4232c2c66affSColin Finck     mii.dwTypeData = buf;
4233c2c66affSColin Finck     mii.cch = sizeof(buf);
4234c2c66affSColin Finck     mii.dwItemData = 0x81818181;
4235c2c66affSColin Finck     ret = GetMenuItemInfoA(hmenu, 0, TRUE, &mii);
4236c2c66affSColin Finck     ok(ret, "GetMenuItemInfo failed\n");
4237c2c66affSColin Finck     ok(mii.fType == MF_BITMAP, "expected MF_BITMAP, got %#x\n", mii.fType);
4238c2c66affSColin Finck     ok(mii.fState == 0x81818181, "expected 0x81818181, got %#x\n", mii.fState);
4239c2c66affSColin Finck     ok(mii.wID == 0x81818181, "expected 0x81818181, got %#x\n", mii.wID);
4240c2c66affSColin Finck     ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
4241c2c66affSColin Finck     ok(mii.dwItemData == 0x81818181, "expected 0x81818181, got %#lx\n", mii.dwItemData);
4242c2c66affSColin Finck     ok(mii.dwTypeData == (LPSTR)hbmp, "expected %p, got %p\n", hbmp, mii.dwTypeData);
4243c2c66affSColin Finck     ok(mii.cch == 6, "expected 6, got %u\n", mii.cch);
4244c2c66affSColin Finck     ok(mii.hbmpItem == hbmp, "expected %p, got %p\n", hbmp, mii.hbmpItem);
4245c2c66affSColin Finck 
4246c2c66affSColin Finck     DestroyMenu(hmenu);
4247c2c66affSColin Finck     DeleteObject(hbmp);
4248c2c66affSColin Finck }
4249c2c66affSColin Finck 
START_TEST(menu)4250c2c66affSColin Finck START_TEST(menu)
4251c2c66affSColin Finck {
4252c2c66affSColin Finck     register_menu_check_class();
4253c2c66affSColin Finck 
4254c2c66affSColin Finck     test_menu_add_string();
4255c2c66affSColin Finck     test_menu_iteminfo();
4256c2c66affSColin Finck     test_menu_search_bycommand();
4257c2c66affSColin Finck     test_CheckMenuRadioItem();
4258c2c66affSColin Finck     test_menu_resource_layout();
4259c2c66affSColin Finck     test_InsertMenu();
4260c2c66affSColin Finck     test_menualign();
4261c2c66affSColin Finck     test_system_menu();
4262c2c66affSColin Finck 
4263c2c66affSColin Finck     test_menu_locked_by_window();
4264c2c66affSColin Finck     test_subpopup_locked_by_menu();
4265c2c66affSColin Finck     test_menu_ownerdraw();
4266c2c66affSColin Finck     test_getmenubarinfo();
4267*7a62c32bSAmine Khaldi     test_GetMenuItemRect();
4268c2c66affSColin Finck     test_menu_bmp_and_string();
4269c2c66affSColin Finck     test_menu_getmenuinfo();
4270c2c66affSColin Finck     test_menu_setmenuinfo();
4271c2c66affSColin Finck     test_menu_input();
4272c2c66affSColin Finck     test_menu_flags();
4273c2c66affSColin Finck 
4274c2c66affSColin Finck     test_menu_hilitemenuitem();
4275c2c66affSColin Finck     test_menu_trackpopupmenu();
4276c2c66affSColin Finck     test_menu_trackagain();
4277c2c66affSColin Finck     test_menu_cancelmode();
4278c2c66affSColin Finck     test_menu_maxdepth();
4279c2c66affSColin Finck     test_menu_circref();
4280c2c66affSColin Finck     test_emptypopup();
4281c2c66affSColin Finck     test_AppendMenu();
4282c2c66affSColin Finck }
4283