Ejemplo n.º 1
0
        void InvokeCommand(int index)
        {
            const int SW_SHOWNORMAL            = 1;
            CMINVOKECOMMANDINFO_ByIndex invoke = new CMINVOKECOMMANDINFO_ByIndex();

            invoke.cbSize = Marshal.SizeOf(invoke);
            invoke.iVerb  = index;
            invoke.nShow  = SW_SHOWNORMAL;
            m_ComInterface2.InvokeCommand(ref invoke);
        }
Ejemplo n.º 2
0
        private void InvokeCommand(int index)
        {
            const int swShownormal = 1;
            var       invoke       = new CMINVOKECOMMANDINFO_ByIndex();

            invoke.cbSize = Marshal.SizeOf(invoke);
            invoke.iVerb  = index;
            invoke.nShow  = swShownormal;
            _mComInterface2.InvokeCommand(ref invoke);
        }
        public void InvokeCommand(int index)
        {
            const int SW_SHOWNORMAL = 1;
            var       invoke        = new CMINVOKECOMMANDINFO_ByIndex
            {
                iVerb = index,
                nShow = SW_SHOWNORMAL
            };

            invoke.cbSize = Marshal.SizeOf(invoke);
            _contextMenu2.InvokeCommand(ref invoke);
        }
Ejemplo n.º 4
0
        public void InvokeCommand(int index)
        {
            const int SW_SHOWNORMAL            = 1;
            CMINVOKECOMMANDINFO_ByIndex invoke = new CMINVOKECOMMANDINFO_ByIndex();

            invoke.cbSize = Marshal.SizeOf(invoke);
            invoke.iVerb  = index;
            invoke.nShow  = SW_SHOWNORMAL;

            try
            {
                m_ComInterface2.InvokeCommand(ref invoke);
            }
            catch (Exception ex)
            {
                Console.Write("\n" + ex.Message);
            }
        }
Ejemplo n.º 5
0
        public override async Task <string> Handle(string data)
        {
            var item = JsonConvert.DeserializeObject <ContextMenuAction>(data);
            var path = item.Path;

            using var shellItem =
                      new ComObjDisposable <IShellItem>(
                          Shell32.SHCreateItemFromParsingName(path, IntPtr.Zero, typeof(IShellItem).GUID));
            using var iContextMenuPtr =
                      shellItem.Instance.BindToHandler(IntPtr.Zero, BHID.SFUIObject, typeof(IContextMenu).GUID);
            using var contextMenu = new ComObjDisposable <IContextMenu>(
                      Marshal.GetTypedObjectForIUnknown(iContextMenuPtr.DangerousGetHandle(), typeof(IContextMenu)) as
                      IContextMenu);
            using var menu = User32.CreatePopupMenu();
            contextMenu.Instance.QueryContextMenu(menu.DangerousGetHandle(), 0, 0, int.MaxValue,
                                                  CMF.NORMAL);
            Marshal.QueryInterface(iContextMenuPtr.DangerousGetHandle(), ref IID_IContextMenu2,
                                   out var iContextMenuPtr2);
            Marshal.QueryInterface(iContextMenuPtr.DangerousGetHandle(), ref IID_IContextMenu3,
                                   out var iContextMenuPtr3);
            using var contextMenuPtr2 = new IntPtrSafeHandle(iContextMenuPtr2, true);
            using var contextMenuPtr3 = new IntPtrSafeHandle(iContextMenuPtr3, true);
            using var contextMenu3    = new ComObjDisposable <IContextMenu3>(Marshal.GetTypedObjectForIUnknown(
                                                                                 contextMenuPtr3.DangerousGetHandle(),
                                                                                 typeof(IContextMenu3)) as IContextMenu3);
            using var contextMenu2 = new ComObjDisposable <IContextMenu2>(
                      Marshal.GetTypedObjectForIUnknown(contextMenuPtr2.DangerousGetHandle(), typeof(IContextMenu2)) as
                      IContextMenu2);
            switch (item.Type)
            {
            case ContextMenuAction.ActionType.ShowMenu:
            {
                Console.WriteLine(DateTime.Now.TimeOfDay + "\tShow menu request");
                var res = GenerateMenuInfo(menu.DangerousGetHandle(), contextMenu.Instance,
                                           contextMenu3.Instance);
                return(JsonConvert.SerializeObject(res));
            }

            case ContextMenuAction.ActionType.InvokeCommand:
            {
                Console.WriteLine(DateTime.Now.TimeOfDay + "\tIncoke command request");
                var       id            = item.MenuId;
                const int SW_SHOWNORMAL = 1;
                var       invoke        = new CMINVOKECOMMANDINFO_ByIndex();
                invoke.cbSize = Marshal.SizeOf(invoke);
                invoke.iVerb  = id;
                invoke.nShow  = SW_SHOWNORMAL;
                try
                {
                    contextMenu2.Instance.InvokeCommand(ref invoke);
                }
                catch (COMException)
                {
                    Console.WriteLine(DateTime.Now.TimeOfDay + "\tA COMException was thrown from invoke command");
                    // Do nothing
                }
                return(string.Empty);
            }

            default:
                break;
            }

            return(string.Empty);
        }