ReactOS 0.4.15-dev-7693-gd0e2924
utils.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Shell
3 * LICENSE: LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
4 * PURPOSE: Implement shell light-weight utility functions
5 * COPYRIGHT: Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7
8#define _ATL_NO_EXCEPTIONS
9#include "precomp.h"
10#include <shellapi.h>
11#include <shlwapi.h>
12#include <shlwapi_undoc.h>
13#include <shlobj_undoc.h>
14#include <shlguid_undoc.h>
15#include <atlstr.h>
16#include <strsafe.h>
17
19
20/*************************************************************************
21 * IContextMenu_Invoke [SHLWAPI.207]
22 *
23 * Used by Win:SHELL32!CISFBand::_TrySimpleInvoke.
24 */
28 _In_ IContextMenu *pContextMenu,
30 _In_ LPCSTR lpVerb,
32{
33 CMINVOKECOMMANDINFO info;
34 BOOL ret = FALSE;
35 INT iDefItem = 0;
36 HMENU hMenu = NULL;
37 HCURSOR hOldCursor;
38
39 TRACE("(%p, %p, %s, %u)\n", pContextMenu, hwnd, debugstr_a(lpVerb), uFlags);
40
41 if (!pContextMenu)
42 return FALSE;
43
44 hOldCursor = SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_WAIT));
45
46 ZeroMemory(&info, sizeof(info));
47 info.cbSize = sizeof(info);
48 info.hwnd = hwnd;
49 info.nShow = SW_NORMAL;
50 info.lpVerb = lpVerb;
51
52 if (IS_INTRESOURCE(lpVerb))
53 {
54 hMenu = CreatePopupMenu();
55 if (hMenu)
56 {
57 pContextMenu->QueryContextMenu(hMenu, 0, 1, MAXSHORT, uFlags | CMF_DEFAULTONLY);
58 iDefItem = GetMenuDefaultItem(hMenu, 0, 0);
59 if (iDefItem != -1)
60 info.lpVerb = MAKEINTRESOURCEA(iDefItem - 1);
61 }
62 }
63
64 if (iDefItem != -1 || info.lpVerb)
65 {
66 if (!hwnd)
67 info.fMask |= CMIC_MASK_FLAG_NO_UI;
68 ret = SUCCEEDED(pContextMenu->InvokeCommand(&info));
69 }
70
71 /* Invoking itself doesn't need the menu object, but getting the command info
72 needs the menu. */
73 if (hMenu)
74 DestroyMenu(hMenu);
75
76 SetCursor(hOldCursor);
77
78 return ret;
79}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
void shell(int argc, const char *argv[])
Definition: cmds.c:1231
#define EXTERN_C
Definition: basetyps.h:12
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
UINT uFlags
Definition: api.c:59
EXTERN_C BOOL WINAPI IContextMenu_Invoke(_In_ IContextMenu *pContextMenu, _In_ HWND hwnd, _In_ LPCSTR lpVerb, _In_ UINT uFlags)
Definition: utils.cpp:27
unsigned int BOOL
Definition: ntddk_ex.h:94
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define debugstr_a
Definition: kernel32.h:31
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
#define _In_
Definition: ms_sal.h:308
unsigned int UINT
Definition: ndis.h:50
#define TRACE(s)
Definition: solgame.cpp:4
int32_t INT
Definition: typedefs.h:58
#define MAXSHORT
Definition: umtypes.h:114
int ret
#define ZeroMemory
Definition: winbase.h:1712
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
HICON HCURSOR
Definition: windef.h:299
#define WINAPI
Definition: msvc.h:6
HMENU WINAPI CreatePopupMenu(void)
Definition: menu.c:838
UINT WINAPI GetMenuDefaultItem(_In_ HMENU hMenu, _In_ UINT fByPos, _In_ UINT gmdiFlags)
#define IS_INTRESOURCE(i)
Definition: winuser.h:580
HCURSOR WINAPI SetCursor(_In_opt_ HCURSOR)
HCURSOR WINAPI LoadCursorW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2088
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
BOOL WINAPI DestroyMenu(_In_ HMENU)
#define IDC_WAIT
Definition: winuser.h:689
#define SW_NORMAL
Definition: winuser.h:768
const char * LPCSTR
Definition: xmlstorage.h:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185