コード例 #1
0
        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_ID | MIIM.MIIM_TYPE | MIIM.MIIM_STATE;
            mii.fMask = MIIM.MIIM_BITMAP | MIIM.MIIM_STRING | MIIM.MIIM_FTYPE |
                        MIIM.MIIM_ID | MIIM.MIIM_STATE;
            mii.wID        = idCmdFirst + _idmDisplay;
            mii.fType      = MFT.MFT_STRING;
            mii.dwTypeData = _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, _idmDisplay + 1));
        }
コード例 #2
0
ファイル: NativeMethods.cs プロジェクト: SupremeGenius/espUrl
 public static extern bool InsertMenuItem(
     IntPtr hMenu,
     uint uItem,
     [MarshalAs(UnmanagedType.Bool)] bool fByPosition,
     ref MENUITEMINFO mii);
コード例 #3
0
        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_ID | MIIM.MIIM_TYPE | MIIM.MIIM_STATE;
             mii.fMask = MIIM.MIIM_BITMAP | MIIM.MIIM_STRING | MIIM.MIIM_FTYPE |
                MIIM.MIIM_ID | MIIM.MIIM_STATE;
             mii.wID = idCmdFirst + _idmDisplay;
             mii.fType = MFT.MFT_STRING;
             mii.dwTypeData = _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, _idmDisplay + 1);
        }