Example #1
0
        /// <summary>
        /// Add commands to a shortcut menu.
        /// </summary>
        /// <param name="hMenu">A handle to the shortcut menu.</param>
        /// <param name="iMenu">
        /// The zero-based position at which to insert the first new menu item.
        /// </param>
        /// <param name="idCmdFirst">
        /// The minimum value that the handler can specify for a menu item ID.
        /// </param>
        /// <param name="idCmdLast">
        /// The maximum value that the handler can specify for a menu item ID.
        /// </param>
        /// <param name="uFlags">
        /// Optional flags that specify how the shortcut menu can be changed.
        /// </param>
        /// <returns>
        /// If successful, returns an HRESULT value that has its severity value set
        /// to SEVERITY_SUCCESS and its code value set to the offset of the largest
        /// command identifier that was assigned, plus one.
        /// </returns>
        public int QueryContextMenu(
            IntPtr hMenu,
            uint iMenu,
            uint idCmdFirst,
            uint idCmdLast,
            uint uFlags)
        {
            //MessageBox.Show("QueryContextMenu");
            // If uFlags include CMF_DEFAULTONLY then we should not do anything.
            if (((uint)CMF.CMF_DEFAULTONLY & uFlags) != 0)
            {
                return(WinError.MAKE_HRESULT(WinError.SEVERITY_SUCCESS, 0, 0));
            }

            MenuManager.Instance.Register(new MenuContext {
                IdCmdFirst = idCmdFirst
            });
            List <MENUITEMINFO> menuInfos = MenuManager.Instance.GetMenuItemInfo();

            for (int index = 0; index < menuInfos.Count; index++)
            {
                var info = menuInfos[index];
                if (!NativeMethods.InsertMenuItem(hMenu, iMenu + (uint)index, true, ref info))
                {
                    return(Marshal.GetHRForLastWin32Error());
                }
            }

            // Return an HRESULT value with the severity set to SEVERITY_SUCCESS.
            // Set the code value to the offset of the largest command identifier
            // that was assigned, plus one (1).
            return(WinError.MAKE_HRESULT(WinError.SEVERITY_SUCCESS, 0, MenuManager.IDM_DISPLAY2 - MenuManager.IDM_DISPLAY + 1));
        }
Example #2
0
        /// <summary>
        /// Add commands to a shortcut menu.
        /// </summary>
        /// <param name="hMenu">A handle to the shortcut menu.</param>
        /// <param name="iMenu">
        /// The zero-based position at which to insert the first new menu item.
        /// </param>
        /// <param name="idCmdFirst">
        /// The minimum value that the handler can specify for a menu item ID.
        /// </param>
        /// <param name="idCmdLast">
        /// The maximum value that the handler can specify for a menu item ID.
        /// </param>
        /// <param name="uFlags">
        /// Optional flags that specify how the shortcut menu can be changed.
        /// </param>
        /// <returns>
        /// If successful, returns an HRESULT value that has its severity value set
        /// to SEVERITY_SUCCESS and its code value set to the offset of the largest
        /// command identifier that was assigned, plus one.
        /// </returns>
        public int QueryContextMenu(
            IntPtr hMenu,
            uint iMenu,
            uint idCmdFirst,
            uint idCmdLast,
            uint uFlags)
        {
            //System.Windows.Forms.MessageBox.Show("kero_query");
            // If uFlags include CMF_DEFAULTONLY then we should not do anything.
            if (((uint)CMF.CMF_DEFAULTONLY & uFlags) != 0)
            {
                return(WinError.MAKE_HRESULT(WinError.SEVERITY_SUCCESS, 0, 0));
            }


            IntPtr hSubMenu = NativeMethods.CreatePopupMenu();

            // PARENT!!!
            MENUITEMINFO mii2 = new MENUITEMINFO();

            mii2.cbSize = (uint)Marshal.SizeOf(mii2);
            mii2.fMask  = /*MIIM.MIIM_BITMAP | MIIM.MIIM_SUBMENU | */ MIIM.MIIM_STRING | MIIM.MIIM_FTYPE | MIIM.MIIM_ID | MIIM.MIIM_STATE;
            //mii2.hSubMenu = hSubMenu;
            mii2.wID        = idCmdFirst + itemCount++;
            mii2.fType      = MFT.MFT_STRING;
            mii2.dwTypeData = this.menuText + " (" + this.selectedFiles.Count.ToString() + " Items)";
            if (this.selectedFiles.Count == 1)
            {
                mii2.dwTypeData = this.menuText + " (1 Item)";
                return(WinError.MAKE_HRESULT(WinError.SEVERITY_SUCCESS, 0, 0));//there is no need to merge 1 folder...
            }
            if (this.selectedFiles.Count >= 16)
            {
                mii2.dwTypeData = this.menuText + " (16 or More Items)";
            }


            mii2.fState = MFS.MFS_ENABLED;

            // Adding the POPUP Menu
            if (!NativeMethods.InsertMenuItem(hMenu, iMenu + 0, true, ref mii2))
            {
                return(Marshal.GetHRForLastWin32Error());
            }

            return(WinError.MAKE_HRESULT(WinError.SEVERITY_SUCCESS, 0,
                                         IDM_DISPLAY + itemCount));
        }
        /// <summary>
        /// Add commands to a shortcut menu.
        /// </summary>
        /// <param name="hMenu">A handle to the shortcut menu.</param>
        /// <param name="iMenu">
        /// The zero-based position at which to insert the first new menu item.
        /// </param>
        /// <param name="idCmdFirst">
        /// The minimum value that the handler can specify for a menu item ID.
        /// </param>
        /// <param name="idCmdLast">
        /// The maximum value that the handler can specify for a menu item ID.
        /// </param>
        /// <param name="uFlags">
        /// Optional flags that specify how the shortcut menu can be changed.
        /// </param>
        /// <returns>
        /// If successful, returns an HRESULT value that has its severity value set
        /// to SEVERITY_SUCCESS and its code value set to the offset of the largest
        /// command identifier that was assigned, plus one.
        /// </returns>
        public int QueryContextMenu(
            IntPtr hMenu,
            uint iMenu,
            uint idCmdFirst,
            uint idCmdLast,
            uint uFlags)
        {
            // If uFlags include CMF_DEFAULTONLY then we should not do anything.
            if (((uint)CMF.CMF_DEFAULTONLY & uFlags) != 0)
            {
                return(WinError.MAKE_HRESULT(WinError.SEVERITY_SUCCESS, 0, 0));
            }

            // Use either InsertMenu or InsertMenuItem to add menu items.
            MENUITEMINFO mii = new MENUITEMINFO();

            mii.cbSize = (uint)Marshal.SizeOf(mii);
            mii.fMask  = MIIM.MIIM_BITMAP | MIIM.MIIM_STRING | MIIM.MIIM_FTYPE |
                         MIIM.MIIM_ID | MIIM.MIIM_STATE;
            mii.wID        = idCmdFirst + IDM_DISPLAY;
            mii.fType      = MFT.MFT_STRING;
            mii.dwTypeData = this.menuText;
            mii.fState     = MFS.MFS_ENABLED;
            mii.hbmpItem   = this.menuBmp;
            if (!NativeMethods.InsertMenuItem(hMenu, iMenu, true, ref mii))
            {
                return(Marshal.GetHRForLastWin32Error());
            }

            // Add a separator.
            MENUITEMINFO sep = new MENUITEMINFO();

            sep.cbSize = (uint)Marshal.SizeOf(sep);
            sep.fMask  = MIIM.MIIM_TYPE;
            sep.fType  = MFT.MFT_SEPARATOR;
            if (!NativeMethods.InsertMenuItem(hMenu, iMenu + 1, true, ref sep))
            {
                return(Marshal.GetHRForLastWin32Error());
            }

            // Return an HRESULT value with the severity set to SEVERITY_SUCCESS.
            // Set the code value to the offset of the largest command identifier
            // that was assigned, plus one (1).
            return(WinError.MAKE_HRESULT(WinError.SEVERITY_SUCCESS, 0,
                                         IDM_DISPLAY + 1));
        }
Example #4
0
        /// <summary>
        /// 将命令添加到快捷菜单.
        /// </summary>
        /// <param name="hMenu">快捷菜单的句柄.</param>
        /// <param name="iMenu">
        /// 从零位置开始插入第一个新菜单项.
        /// </param>
        /// <param name="idCmdFirst">
        /// 菜单项 ID 指定的最小值.
        /// </param>
        /// <param name="idCmdLast">
        /// 菜单项 ID 指定的最大值.
        /// </param>
        /// <param name="uFlags">
        /// 可选参数,用来标示快捷菜单如何改变.
        /// </param>
        /// <returns>
        // 如果成功返回一个HRESULT类型的值.
        // 将代码值设置为最大的命令标识符的偏移量将被分配并且加一.
        /// </returns>
        public int QueryContextMenu(
            IntPtr hMenu,
            uint iMenu,
            uint idCmdFirst,
            uint idCmdLast,
            uint uFlags)
        {
            //  如果uFlags参数包含CMF_DEFAULTONLY,我们就可以什么都不要做了.
            if (((uint)CMF.CMF_DEFAULTONLY & uFlags) != 0)
            {
                return(WinError.MAKE_HRESULT(WinError.SEVERITY_SUCCESS, 0, 0));
            }

            // 使用InsertMenu 或 InsertMenuItem添加菜单项.

            MENUITEMINFO mii = new MENUITEMINFO();

            mii.cbSize     = (uint)Marshal.SizeOf(mii);
            mii.fMask      = MIIM.MIIM_ID | MIIM.MIIM_TYPE | MIIM.MIIM_STATE;
            mii.wID        = idCmdFirst + IDM_DISPLAY;
            mii.fType      = MFT.MFT_STRING;
            mii.dwTypeData = menuText;
            mii.fState     = MFS.MFS_ENABLED;
            if (!NativeMethods.InsertMenuItem(hMenu, iMenu, true, ref mii))
            {
                return(Marshal.GetHRForLastWin32Error());
            }

            // 增加一个分隔符.
            MENUITEMINFO sep = new MENUITEMINFO();

            sep.cbSize = (uint)Marshal.SizeOf(sep);
            sep.fMask  = MIIM.MIIM_TYPE;
            sep.fType  = MFT.MFT_SEPARATOR;
            if (!NativeMethods.InsertMenuItem(hMenu, iMenu + 1, true, ref sep))
            {
                return(Marshal.GetHRForLastWin32Error());
            }

            // 如果成功返回一个HRESULT类型的值.
            // 将代码值设置为最大的命令标识符的偏移量将被分配并且加一.
            return(WinError.MAKE_HRESULT(WinError.SEVERITY_SUCCESS, 0,
                                         IDM_DISPLAY + 1));
        }
Example #5
0
        /// <summary>
        /// Add commands to a shortcut menu.
        /// </summary>
        /// <param name="hMenu">A handle to the shortcut menu.</param>
        /// <param name="iMenu">
        /// The zero-based position at which to insert the first new menu item.
        /// </param>
        /// <param name="idCmdFirst">
        /// The minimum value that the handler can specify for a menu item ID.
        /// </param>
        /// <param name="idCmdLast">
        /// The maximum value that the handler can specify for a menu item ID.
        /// </param>
        /// <param name="uFlags">
        /// Optional flags that specify how the shortcut menu can be changed.
        /// </param>
        /// <returns>
        /// If successful, returns an HRESULT value that has its severity value set
        /// to SEVERITY_SUCCESS and its code value set to the offset of the largest
        /// command identifier that was assigned, plus one.
        /// </returns>
        public int QueryContextMenu(
            IntPtr hMenu,
            uint iMenu,
            uint idCmdFirst,
            uint idCmdLast,
            uint uFlags)
        {
            // If uFlags include CMF_DEFAULTONLY then we should not do anything.
            if (((uint)CMF.CMF_DEFAULTONLY & uFlags) != 0)
            {
                return(WinError.MAKE_HRESULT(WinError.SEVERITY_SUCCESS, 0, 0));
            }


            // ORIGINAL
            // Use either InsertMenu or InsertMenuItem to add menu items.

            /*
             * MENUITEMINFO mii = new MENUITEMINFO();
             * mii.cbSize = (uint)Marshal.SizeOf(mii);
             * mii.fMask = MIIM.MIIM_BITMAP | MIIM.MIIM_STRING | MIIM.MIIM_FTYPE | MIIM.MIIM_ID | MIIM.MIIM_STATE;
             * mii.wID = idCmdFirst + itemCount++;
             * mii.fType = MFT.MFT_STRING;
             * mii.dwTypeData = this.menuText;
             * mii.fState = MFS.MFS_ENABLED;
             * mii.hbmpItem = this.menuBmp;
             * if (!NativeMethods.InsertMenuItem(hMenu, iMenu, true, ref mii))
             * {
             *  return Marshal.GetHRForLastWin32Error();
             * }
             */

            IntPtr hSubMenu = NativeMethods.CreatePopupMenu();

            // PARENT!!!
            MENUITEMINFO mii2 = new MENUITEMINFO();

            mii2.cbSize     = (uint)Marshal.SizeOf(mii2);
            mii2.fMask      = MIIM.MIIM_BITMAP | MIIM.MIIM_SUBMENU | MIIM.MIIM_STRING | MIIM.MIIM_FTYPE | MIIM.MIIM_ID | MIIM.MIIM_STATE;
            mii2.hSubMenu   = hSubMenu;
            mii2.wID        = idCmdFirst + itemCount;
            mii2.fType      = MFT.MFT_STRING;
            mii2.dwTypeData = this.menuText;
            mii2.fState     = MFS.MFS_ENABLED;
            mii2.hbmpItem   = this.menuBmp;


            uint subItemCount = 0;

            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
            string filename;

            foreach (SHDocVw.InternetExplorer ie in shellWindows)
            {
                /*
                 * string[] paths = {"path1", "path2", "path3"};
                 * foreach(string s in paths ) {
                 */

                filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();


                if (filename.Equals("explorer"))
                {
                    string ExplorerWindowPath = ie.LocationURL;
                    ExplorerWindowPath = ExplorerWindowPath.Replace("file:///", "");

                    // Filters out the current explorer window

                    // Had a file in c:\ and it matched c:\alertus-dev...
                    if (/*Path.GetDirectoryName(selectedFile) != Path.GetDirectoryName(ExplorerWindowPath) && */
                        !String.IsNullOrEmpty(ExplorerWindowPath))
                    {
                        // Subitem1
                        MENUITEMINFO mii3 = new MENUITEMINFO();
                        mii3.cbSize     = (uint)Marshal.SizeOf(mii2);
                        mii3.fMask      = MIIM.MIIM_STRING | MIIM.MIIM_FTYPE | MIIM.MIIM_ID | MIIM.MIIM_STATE;
                        mii3.wID        = idCmdFirst + itemCount;
                        mii3.fType      = MFT.MFT_STRING;
                        mii3.dwTypeData = ExplorerWindowPath;
                        mii3.fState     = MFS.MFS_ENABLED;
                        //mii3.hbmpItem = this.menuBmp;
                        if (!NativeMethods.InsertMenuItem(hSubMenu, subItemCount++, true, ref mii3))
                        {
                            return(Marshal.GetHRForLastWin32Error());
                        }

                        pathMap.Add((int)itemCount, ExplorerWindowPath);
                        itemCount++;
                    }
                }
            }



            // Adding the POPUP Menu
            if (!NativeMethods.InsertMenuItem(hMenu, iMenu + 0, true, ref mii2))
            {
                return(Marshal.GetHRForLastWin32Error());
            }



            // Return an HRESULT value with the severity set to SEVERITY_SUCCESS.
            // Set the code value to the offset of the largest command identifier
            // that was assigned, plus one (1).
            return(WinError.MAKE_HRESULT(WinError.SEVERITY_SUCCESS, 0,
                                         IDM_DISPLAY + itemCount));
        }