diff --git a/dlls/oledlg/oledlg_main.c b/dlls/oledlg/oledlg_main.c index 87df968516a..8ba9f17a7ae 100644 --- a/dlls/oledlg/oledlg_main.c +++ b/dlls/oledlg/oledlg_main.c @@ -184,6 +184,7 @@ BOOL WINAPI OleUIAddVerbMenuW(IOleObject *object, LPCWSTR shorttype, LoadStringW(OLEDLG_hInstance, IDS_VERBMENU_OBJECT, resstrW, sizeof(resstrW)/sizeof(WCHAR)); /* no object, or object without enumeration support */ if (!object || !enumverbs) { + RemoveMenu(hMenu, uPos, MF_BYPOSITION); InsertMenuW(hMenu, uPos, MF_BYPOSITION|MF_STRING|MF_GRAYED, idmin, resstrW); return FALSE; } diff --git a/dlls/oledlg/tests/main.c b/dlls/oledlg/tests/main.c index 9c5e4bdfa27..5d452f1b099 100644 --- a/dlls/oledlg/tests/main.c +++ b/dlls/oledlg/tests/main.c @@ -303,6 +303,7 @@ static IOleObject oleobject = { &oleobjectvtbl }; static void test_OleUIAddVerbMenu(void) { + static const WCHAR cadabraW[] = {'c','a','d','a','b','r','a',0}; HMENU hMenu, verbmenu; MENUITEMINFOW info; WCHAR buffW[50]; @@ -418,6 +419,72 @@ static void test_OleUIAddVerbMenu(void) ok(count == 5, "got %d\n", count); DestroyMenu(hMenu); + + /* try to add verb menu repeatedly, with same id */ + hMenu = CreatePopupMenu(); + + count = GetMenuItemCount(hMenu); + ok(count == 0, "got %d\n", count); + + verbmenu = NULL; + ret = OleUIAddVerbMenuW(NULL, NULL, hMenu, 0, 5, 10, TRUE, 3, &verbmenu); + ok(!ret, "got %d\n", ret); + ok(verbmenu == NULL, "got %p\n", verbmenu); + + count = GetMenuItemCount(hMenu); + ok(count == 1, "got %d\n", count); + + verbmenu = NULL; + ret = OleUIAddVerbMenuW(NULL, NULL, hMenu, 0, 5, 10, TRUE, 3, &verbmenu); + ok(!ret, "got %d\n", ret); + ok(verbmenu == NULL, "got %p\n", verbmenu); + + count = GetMenuItemCount(hMenu); + ok(count == 1, "got %d\n", count); + + /* same position, different id */ + verbmenu = NULL; + ret = OleUIAddVerbMenuW(NULL, NULL, hMenu, 0, 6, 10, TRUE, 3, &verbmenu); + ok(!ret, "got %d\n", ret); + ok(verbmenu == NULL, "got %p\n", verbmenu); + + count = GetMenuItemCount(hMenu); + ok(count == 1, "got %d\n", count); + + /* change added item string and state */ + memset(&info, 0, sizeof(info)); + info.cbSize = sizeof(info); + info.fMask = MIIM_STRING|MIIM_STATE; + info.fState = MFS_ENABLED; + info.dwTypeData = buffW; + lstrcpyW(buffW, cadabraW); + ret = SetMenuItemInfoW(hMenu, 0, TRUE, &info); + ok(ret, "got %d\n", ret); + + buffW[0] = 0; + GetMenuStringW(hMenu, 0, buffW, sizeof(buffW)/sizeof(buffW[0]), MF_BYPOSITION); + ok(!lstrcmpW(buffW, cadabraW), "got %s\n", wine_dbgstr_w(buffW)); + + verbmenu = NULL; + ret = OleUIAddVerbMenuW(NULL, NULL, hMenu, 0, 5, 10, TRUE, 3, &verbmenu); + ok(!ret, "got %d\n", ret); + ok(verbmenu == NULL, "got %p\n", verbmenu); + + memset(&info, 0, sizeof(info)); + info.cbSize = sizeof(info); + info.fMask = MIIM_STRING|MIIM_STATE; + buffW[0] = 0; + info.dwTypeData = buffW; + info.cch = sizeof(buffW)/sizeof(WCHAR); + ret = GetMenuItemInfoW(hMenu, 0, TRUE, &info); + ok(ret, "got %d\n", ret); + ok(lstrcmpW(buffW, cadabraW), "got %s\n", wine_dbgstr_w(buffW)); + ok(info.fState == MF_GRAYED, "got state 0x%08x\n", info.fState); + + count = GetMenuItemCount(hMenu); + ok(count == 1, "got %d\n", count); + + DestroyMenu(hMenu); } START_TEST(main)