You need to enable JavaScript to run this app.
最新活动
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

手机存储的IContextMenu Shell扩展

要实现“手机存储的IContextMenu Shell扩展”,可以按照以下步骤进行:

  1. 创建一个新的C#类库项目。
  2. 引用Shell32.dll和System.Windows.Forms命名空间。
  3. 在项目中创建一个类,并实现IContextMenu接口。代码示例如下:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Shell32;

namespace PhoneStorageContextMenu
{
    [ComVisible(true)]
    [Guid("Your-GUID-Here")]
    [ClassInterface(ClassInterfaceType.None)]
    public class PhoneStorageContextMenu : IContextMenu
    {
        public void QueryContextMenu(IntPtr hMenu, uint indexMenu, uint idCmdFirst, uint idCmdLast, uint uFlags)
        {
            // 在上下文菜单中添加自定义项
            Shell32.Shell shell = new Shell32.Shell();
            Folder folder = shell.NameSpace("Your-Phone-Storage-Path");
            FolderItem item = folder.ParseName("Your-File-Name");
            FolderItemVerbs verbs = item.Verbs();
            for (int i = 0; i < verbs.Count; i++)
            {
                MenuItem menuItem = new MenuItem(verbs.Item(i).Name);
                menuItem.Click += MenuItem_Click;
                ContextMenu menu = new ContextMenu(new MenuItem[] { menuItem });
                MenuItem[] menuItems = { menu.MenuItems[0] };
                menu.MergeMenu(hMenu, indexMenu, idCmdFirst + (uint)i, idCmdLast, uFlags);
            }
        }

        public void InvokeCommand(IntPtr pici)
        {
            // 处理菜单项的点击事件
            uint idCmd = (uint)(Marshal.ReadInt32(pici, 0) - 1);
            Shell32.Shell shell = new Shell32.Shell();
            Folder folder = shell.NameSpace("Your-Phone-Storage-Path");
            FolderItem item = folder.ParseName("Your-File-Name");
            FolderItemVerbs verbs = item.Verbs();
            if (idCmd >= 0 && idCmd < verbs.Count)
            {
                verbs.Item(idCmd).DoIt();
            }
        }

        public void GetCommandString(uint idCmd, uint uFlags, IntPtr pReserved, IntPtr pszName, uint cchMax)
        {
            // 获取菜单项的文字描述
            if (uFlags == (uint)Shell32.GCS.VERB)
            {
                Shell32.Shell shell = new Shell32.Shell();
                Folder folder = shell.NameSpace("Your-Phone-Storage-Path");
                FolderItem item = folder.ParseName("Your-File-Name");
                FolderItemVerbs verbs = item.Verbs();
                if (idCmd >= 0 && idCmd < verbs.Count)
                {
                    string verbName = verbs.Item(idCmd).Name;
                    if (cchMax < (uint)(verbName.Length + 1))
                    {
                        Marshal.ThrowExceptionForHR((int)Shell32.HRESULT.E_FAIL);
                    }
                    else
                    {
                        Marshal.GetNativeVariantForObject(verbName, pszName);
                    }
                }
            }
        }
    }
}

请注意,上述代码中的"Your-GUID-Here"应替换为您自己的GUID,"Your-Phone-Storage-Path"和"Your-File-Name"应替换为您的手机存储路径和文件名。

  1. 在项目中添加一个名为"Registration.cs"的类,并添加以下代码:
using System;
using System.Runtime.InteropServices;

namespace PhoneStorageContextMenu
{
    public static class Registration
    {
        [DllImport("Shell32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
        public static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);

        [ComRegisterFunction]
        public static void RegisterClass(Type t)
        {
            try
            {
                Shell32.Shell shell = new Shell32.Shell();
                string className = t.FullName;
                string subKey = $"CLSID\\{{{t.GUID.ToString().ToUpper()}}}\\InProcServer32";
                using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(subKey, true))
                {
                    key.SetValue(null, System.Environment.SystemDirectory + "\\mscoree.dll", Microsoft.Win32.RegistryValueKind.String);
                }

                subKey = $"CLSID\\{{{t.GUID.ToString().ToUpper()}}}\\Implemented Categories\\{{{Shell32.CLSID.ShellContextMenu}}}"; 
                using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(subKey))
本文内容通过AI工具匹配关键字智能整合而成,仅供参考,火山引擎不对内容的真实、准确或完整作任何形式的承诺。如有任何问题或意见,您可以通过联系service@volcengine.com进行反馈,火山引擎收到您的反馈后将及时答复和处理。
展开更多
面向开发者的云福利中心,ECS 60元/年,域名1元起,助力开发者快速在云上构建可靠应用

社区干货

特惠活动

热门爆款云服务器

100%性能独享,更高内存性能更佳,学习测试、web前端、企业应用首选,每日花费低至0.55元
60.00/1212.00/年
立即购买

域名注册服务

cn/top/com等热门域名,首年低至1元,邮箱建站必选
1.00/首年起32.00/首年起
立即购买

DCDN国内流量包100G

同时抵扣CDN与DCDN两种流量消耗,加速分发更实惠
2.00/20.00/年
立即购买

手机存储的IContextMenu Shell扩展-优选内容

批量作业执行命令与实例内执行命令差异说明
Xshell等)或ECS控制台远程连接登录实例后,系统会默认进入交互式登录的Shell环境。在这个环境中,Shell解释器(如/bin/bash)会加载环境配置和初始化相关的启动文件(例如/etc/profile、~/.bash_profile、~/.bashrc等),... 按回车键保存并退出文件。 执行如下命令,重新加载systemd守护进程的配置文件。systemctl daemon-reload 执行如下命令,重启批量作业服务。systemctl restart assist-client 通过批量作业执行ulimit -n命令。登录批...

手机存储的IContextMenu Shell扩展-相关内容

特惠活动

热门爆款云服务器

100%性能独享,更高内存性能更佳,学习测试、web前端、企业应用首选,每日花费低至0.55元
60.00/1212.00/年
立即购买

域名注册服务

cn/top/com等热门域名,首年低至1元,邮箱建站必选
1.00/首年起32.00/首年起
立即购买

DCDN国内流量包100G

同时抵扣CDN与DCDN两种流量消耗,加速分发更实惠
2.00/20.00/年
立即购买

产品体验

体验中心

云服务器特惠

云服务器
云服务器ECS新人特惠
立即抢购

白皮书

一图详解大模型
浓缩大模型架构,厘清生产和应用链路关系
立即获取

最新活动

爆款1核2G共享型服务器

首年60元,每月仅需5元,限量秒杀
立即抢购

火山引擎增长体验专区

丰富能力激励企业快速增长
查看详情

数据智能VeDI

易用的高性能大数据产品家族
了解详情

一键开启云上增长新空间

立即咨询