From b2ab7769f929f832e61d6f5f90d66bc0696a0738 Mon Sep 17 00:00:00 2001 From: David Hall Date: Tue, 28 May 2024 13:31:27 -0600 Subject: [PATCH] Added advanced ctor for CMINVOKECOMMANDINFOEX --- PInvoke/Shell32/ShObjIdl.IContextMenu.cs | 78 ++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/PInvoke/Shell32/ShObjIdl.IContextMenu.cs b/PInvoke/Shell32/ShObjIdl.IContextMenu.cs index eafabf23..c50227d7 100644 --- a/PInvoke/Shell32/ShObjIdl.IContextMenu.cs +++ b/PInvoke/Shell32/ShObjIdl.IContextMenu.cs @@ -775,5 +775,83 @@ public static partial class Shell32 cbSize = (uint)Marshal.SizeOf(this); lpVerb = commandId; } + + /// Initializes a new instance of the struct with its fields. + /// + /// The address of a null-terminated string that specifies the language-independent name of the command to carry out. This member is + /// typically a string when a command is being activated by an application. The system provides predefined constant values for the + /// following command strings. + /// + /// If a canonical verb exists and a menu handler does not implement the canonical verb, it must return a failure code to enable the + /// next handler to be able to handle this verb.Failing to do this will break functionality in the system including ShellExecute. + /// + /// + /// Alternatively, rather than a pointer, this parameter can be MAKEINTRESOURCE(offset) where offset is the menu-identifier offset of + /// the command to carry out. Implementations can use the IS_INTRESOURCE macro to detect that this alternative is being employed. The + /// Shell uses this alternative when the user chooses a menu command. + /// + /// + /// A set of values to pass to the ShowWindow function if the command displays a window or starts an application. + /// + /// A handle to the window that is the owner of the shortcut menu. An extension can also use this handle as the owner of any message + /// boxes or dialog boxes it displays. Callers must specify a legitimate HWND that can be used as the owner window for any UI that + /// may be displayed. Failing to specify an HWND when calling from a UI thread (one with windows already created) will result in + /// reentrancy and possible bugs in the implementation of this call. + /// + /// If supplied, the point where the command is invoked. + /// + /// The implementation can spin off a new thread or process to handle the call and does not need to block on completion of the + /// function being invoked. For example, if the verb is "delete" the call may return before all of the items have been deleted. Since + /// this is advisory, calling applications that specify this flag cannot guarantee that this request will be honored if they are not + /// familiar with the implementation of the verb that they are invoking. + /// + /// + /// If , the SHIFT key is pressed. Use this instead of polling the current state of the keyboard that may have + /// changed since the verb was invoked. + /// + /// + /// If , the CTRL key is pressed. Use this instead of polling the current state of the keyboard that may have + /// changed since the verb was invoked.. + /// + /// An optional keyboard shortcut to assign to any application activated by the command. + /// + /// If , indicates that the method might want to keep track of the item being invoked for features like the + /// "Recent documents" menu. + /// + /// + /// Do not perform a zone check. This flag allows ShellExecuteEx to bypass zone checking put into place by IAttachmentExecute. + /// + /// Optional parameters. + public CMINVOKECOMMANDINFOEX(ResourceId verb, ShowWindowCommand show = ShowWindowCommand.SW_SHOWNORMAL, HWND parent = default, + POINT? location = default, bool allowAsync = false, bool shiftDown = false, bool ctrlDown = false, uint hotkey = 0, + bool logUsage = false, bool noZoneChecks = false, string? parameters = null) + { + cbSize = (uint)Marshal.SizeOf(typeof(CMINVOKECOMMANDINFOEX)); + hwnd = parent; + fMask = (parent.IsNull ? CMIC.CMIC_MASK_FLAG_NO_UI : 0) | (hotkey != 0 ? CMIC.CMIC_MASK_HOTKEY : 0); + lpVerb = verb; + nShow = show; + dwHotKey = hotkey; + if (allowAsync) fMask |= CMIC.CMIC_MASK_ASYNCOK; + if (shiftDown) fMask |= CMIC.CMIC_MASK_SHIFT_DOWN; + if (ctrlDown) fMask |= CMIC.CMIC_MASK_CONTROL_DOWN; + if (logUsage) fMask |= CMIC.CMIC_MASK_FLAG_LOG_USAGE; + if (noZoneChecks) fMask |= CMIC.CMIC_MASK_NOZONECHECKS; + if (location.HasValue) + { + ptInvoke = location.Value; + fMask |= CMIC.CMIC_MASK_PTINVOKE; + } + if (!verb.IsIntResource) + { + lpVerbW = (string)verb; + fMask |= CMIC.CMIC_MASK_UNICODE; + } + if (parameters != null) + { + lpParameters = lpParametersW = parameters; + fMask |= CMIC.CMIC_MASK_UNICODE; + } + } } } \ No newline at end of file