zoukankan      html  css  js  c++  java
  • [摘]给窗体添加快捷键

    [System.Runtime.InteropServices.DllImport("user32.dll")] //申明API函数
          public static extern bool RegisterHotKey(
             IntPtr hWnd, // handle to window 
             int id, // hot key identifier 
             uint fsModifiers, // key-modifier options 
             Keys vk // virtual-key code 
            );
            [System.Runtime.InteropServices.DllImport("user32.dll")] //申明API函数
            public static extern bool UnregisterHotKey(
             IntPtr hWnd, // handle to window 
             int id // hot key identifier 
            );
    
    
            protected override void WndProc(ref Message m)
            {
                const int WM_HOTKEY = 0x0312;
    
                if (WM_HOTKEY == m.Msg)
                {
                    if (m.WParam.ToInt32() == 101)
                    { 
                        hidWindows(); 
                    }
                }
                base.WndProc(ref m);
            }
    
    
         //显示 or 隐藏
         private void hidWindows()
            {
                if (this.Visible == false)
                {
                    this.Visible = true;
                    this.TopMost = true;
                }
                else
                {
                    this.Visible = false;
                }
            }
    
    注册快捷键:
    /*        None = 0,   
                Alt = 1,   
                Ctrl = 2,   
                Shift = 4,   
                WindowsKey = 8  */
           RegisterHotKey(Handle, 101, 2, Keys.Q);
  • 相关阅读:
    1004 Counting Leaves
    1003 Emergency (25分)
    1002 A+B for Polynomials (25分)
    1001 A+B Format
    Weekly Contest 139
    491. Increasing Subsequences
    488. Zuma Game
    servlet总结
    firefox插件Firebug的使用教程
    KMP---POJ 3461 Oulipo
  • 原文地址:https://www.cnblogs.com/qq1223558/p/3227128.html
Copyright © 2011-2022 走看看