PDA手持终端 C#热键例子代码

来源:互联网 发布:顶尖数据恢复破解版 编辑:程序博客网 时间:2024/05/01 18:06

using System; 
using System.Collections.Generic; 
using Microsoft.WindowsCE.Forms; 
using System.Runtime.InteropServices; 
using System.Text;

namespace APPButton_CSharp 
{

    public struct HotKeyEventArgs 
    { 
        public int identifer; 
    } 
    public delegate void HotkeyDelegate(object sender, HotKeyEventArgs e);

    class AppButton : MessageWindow 
    { 
        protected const int WM_HOTKEY = 0x0312; 
        private readonly uint F1KEY_VK = 0xC1;//APP4   F1 key 
        private readonly uint F2KEY_VK = 0xC2;//APP5   F2 key. 
        private readonly uint F3KEY_VK = 0xC3;//APP4   F1 key 
        private readonly uint F4KEY_VK = 0xC4;//APP5   F2 key. 
        private readonly uint F5KEY_VK = 0xC5;//APP6   F3 key. 
        private readonly uint F6KEY_VK = 0xC6;//APP6   F3 key 
        public readonly int keyindentifier1 = 991; 
        public readonly int keyindentifier2 = 992; 
        public readonly int keyindentifier3 = 993; 
        public readonly int keyindentifier4 = 994; 
        public readonly int keyindentifier5 = 995; 
        public readonly int keyindentifier6 = 996;

 

        private HotKeyEventArgs pea;

        [DllImport("coredll.dll")] 
        protected static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);

        [DllImport("coredll.dll")] 
        protected static extern bool UnregisterHotKey(IntPtr hWnd, int id);

        protected override void WndProc(ref Message msg) 
        { 
            object l = new object(); 
            lock (l) 
            { 
                if (msg.Msg == WM_HOTKEY) 
                { 
                    HotKeyEvent((int)msg.WParam); 
                } 
                base.WndProc(ref msg); 
            } 
        }

        public void RegisterHotKey(uint vk,uint modifer) 
        { 
            RegisterHotKey(this.Hwnd, (int)vk + 10000, modifer, vk); 
            
        }

        public void UnRegisterHotKey(int id) 
        { 
            UnregisterHotKey(this.Hwnd, id+10000); 
           
        }

        public void HotKeyEvent(int identifer) 
        { 
            pea = new HotKeyEventArgs(); 
            pea.identifer = identifer; 
            Process(this, pea); 
        }

        public event HotkeyDelegate Process;

    } 
}

0 0
原创粉丝点击