关于怎么在winform中屏蔽复制,粘贴,剪切的.

public partial class 捷通客户添加 : Form
    {
        static int cishu = 0;
        public enum KeyModifiers //组合键枚举
        {
            None = 0,
            Alt = 1,
            Control = 2,
            Shift = 4,
            Windows = 8
        }
        [System.Runtime.InteropServices.DllImport("user32.dll")] //申明API函数
        public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, Keys vk);

        [System.Runtime.InteropServices.DllImport("user32.dll")] //申明API函数
        public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
        private void ProcessHotkey(Message m) //按下设定的键时调用该函数
        {
            IntPtr id = m.WParam; //IntPtr用于表示指针或句柄的平台特定类型

            string sid = id.ToString();
            switch (sid)
            {
                case "100":
                    {
                        MessageBox.Show("复制无效请勿尝试复制");
                        cishu = cishu + 1;
                        if (cishu > 4)
                        {
                            Application.Exit();
                        }
                    }
                    break;
                case "200":
                    {
                        MessageBox.Show("剪切无效请勿尝试剪切");
                        cishu = cishu + 1;
                        if (cishu > 4)
                        {
                            Application.Exit();
                        }
                    }
                    break;

            }
        }


   首先,这个代码拿过来就可以用,至于怎么分析我希望一起研究!

private void 捷通客户添加_Load(object sender, EventArgs e)
        {
            RegisterHotKey(Handle, 100, 2, Keys.C);
            RegisterHotKey(Handle, 200, 2, Keys.X);
}


 

protected override void WndProc(ref Message m)//监视Windows消息
        {
            const int WM_HOTKEY = 0x0312;//如果m.Msg的值为0x0312那么表示用户按下了热键
            switch (m.Msg)
            {
                case WM_HOTKEY:
                    ProcessHotkey(m);//按下热键时调用ProcessHotkey()函数
                    break;
            }
            base.WndProc(ref m); //将系统消息传递自父类的WndProc
        }


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值