https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0ae6a509b0057d91c7ac67149025a1dd3ecc5d30
commit 0ae6a509b0057d91c7ac67149025a1dd3ecc5d30 Author: Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com> AuthorDate: Sun Nov 5 21:45:08 2023 +0900 Commit: GitHub <nore...@github.com> CommitDate: Sun Nov 5 21:45:08 2023 +0900 [SHLWAPI][SDK] Implement IContextMenu_Invoke (#5856) - Modify shlwapi.spec. - Add dll/win32/shlwapi/utils.cpp. - Implement IContextMenu_Invoke function. - Add it to <shlwapi_undoc.h>. CORE-19278 --- dll/win32/shlwapi/CMakeLists.txt | 1 + dll/win32/shlwapi/shlwapi.spec | 2 +- dll/win32/shlwapi/utils.cpp | 79 +++++++++++++++++++++++++++++++++++++ sdk/include/reactos/shlwapi_undoc.h | 7 ++++ 4 files changed, 88 insertions(+), 1 deletion(-) diff --git a/dll/win32/shlwapi/CMakeLists.txt b/dll/win32/shlwapi/CMakeLists.txt index 87551cd21c5..80e14eecc7e 100644 --- a/dll/win32/shlwapi/CMakeLists.txt +++ b/dll/win32/shlwapi/CMakeLists.txt @@ -25,6 +25,7 @@ list(APPEND SOURCE list(APPEND PCH_SKIP_SOURCE assoc.c propbag.cpp + utils.cpp wsprintf.c ${CMAKE_CURRENT_BINARY_DIR}/shlwapi_stubs.c) diff --git a/dll/win32/shlwapi/shlwapi.spec b/dll/win32/shlwapi/shlwapi.spec index c7618d58fa9..53e67a7800e 100644 --- a/dll/win32/shlwapi/shlwapi.spec +++ b/dll/win32/shlwapi/shlwapi.spec @@ -204,7 +204,7 @@ 204 stdcall -noname SHIsChildOrSelf(long long) 205 stdcall -noname SHGetValueGoodBootA(long str str ptr ptr ptr) 206 stdcall -noname SHGetValueGoodBootW(long wstr wstr ptr ptr ptr) -207 stub -noname IContextMenu_Invoke +207 stdcall -noname IContextMenu_Invoke(ptr ptr str long) 208 stdcall -noname FDSA_Initialize(long long ptr ptr long) 209 stdcall -noname FDSA_Destroy(ptr) 210 stdcall -noname FDSA_InsertItem(ptr long ptr) diff --git a/dll/win32/shlwapi/utils.cpp b/dll/win32/shlwapi/utils.cpp new file mode 100644 index 00000000000..a27bcd90f94 --- /dev/null +++ b/dll/win32/shlwapi/utils.cpp @@ -0,0 +1,79 @@ +/* + * PROJECT: ReactOS Shell + * LICENSE: LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later) + * PURPOSE: Implement shell light-weight utility functions + * COPYRIGHT: Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com> + */ + +#define _ATL_NO_EXCEPTIONS +#include "precomp.h" +#include <shellapi.h> +#include <shlwapi.h> +#include <shlwapi_undoc.h> +#include <shlobj_undoc.h> +#include <shlguid_undoc.h> +#include <atlstr.h> +#include <strsafe.h> + +WINE_DEFAULT_DEBUG_CHANNEL(shell); + +/************************************************************************* + * IContextMenu_Invoke [SHLWAPI.207] + * + * Used by Win:SHELL32!CISFBand::_TrySimpleInvoke. + */ +EXTERN_C +BOOL WINAPI +IContextMenu_Invoke( + _In_ IContextMenu *pContextMenu, + _In_ HWND hwnd, + _In_ LPCSTR lpVerb, + _In_ UINT uFlags) +{ + CMINVOKECOMMANDINFO info; + BOOL ret = FALSE; + INT iDefItem = 0; + HMENU hMenu = NULL; + HCURSOR hOldCursor; + + TRACE("(%p, %p, %s, %u)\n", pContextMenu, hwnd, debugstr_a(lpVerb), uFlags); + + if (!pContextMenu) + return FALSE; + + hOldCursor = SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_WAIT)); + + ZeroMemory(&info, sizeof(info)); + info.cbSize = sizeof(info); + info.hwnd = hwnd; + info.nShow = SW_NORMAL; + info.lpVerb = lpVerb; + + if (IS_INTRESOURCE(lpVerb)) + { + hMenu = CreatePopupMenu(); + if (hMenu) + { + pContextMenu->QueryContextMenu(hMenu, 0, 1, MAXSHORT, uFlags | CMF_DEFAULTONLY); + iDefItem = GetMenuDefaultItem(hMenu, 0, 0); + if (iDefItem != -1) + info.lpVerb = MAKEINTRESOURCEA(iDefItem - 1); + } + } + + if (iDefItem != -1 || info.lpVerb) + { + if (!hwnd) + info.fMask |= CMIC_MASK_FLAG_NO_UI; + ret = SUCCEEDED(pContextMenu->InvokeCommand(&info)); + } + + /* Invoking itself doesn't need the menu object, but getting the command info + needs the menu. */ + if (hMenu) + DestroyMenu(hMenu); + + SetCursor(hOldCursor); + + return ret; +} diff --git a/sdk/include/reactos/shlwapi_undoc.h b/sdk/include/reactos/shlwapi_undoc.h index 1cb5a064631..1a46c7b7438 100644 --- a/sdk/include/reactos/shlwapi_undoc.h +++ b/sdk/include/reactos/shlwapi_undoc.h @@ -278,6 +278,13 @@ VOID WINAPI FixSlashesAndColonW(LPWSTR); BOOL WINAPI PathIsValidCharW(WCHAR c, DWORD dwClass); BOOL WINAPI SHGetPathFromIDListWrapW(LPCITEMIDLIST pidl, LPWSTR pszPath); +BOOL WINAPI +IContextMenu_Invoke( + _In_ IContextMenu *pContextMenu, + _In_ HWND hwnd, + _In_ LPCSTR lpVerb, + _In_ UINT uFlags); + #ifdef __cplusplus } /* extern "C" */ #endif /* defined(__cplusplus) */