Example #1
0
        internal int RegHotKey(ShellNotifyIcon.MOD mods, Keys key)
        {
            int id = 0xA000 | (((int)mods & 0xF) << 8) | (int)key;

            ShellNotifyIcon.RegisterHotKey(this.Handle, id, mods, key);
            return(id);
        }
Example #2
0
 protected override void WndProc(ref Message m)
 {
     base.WndProc(ref m);
     if (m.Msg == (int)WM.WM_HOTKEY)
     {
         var    id  = m.WParam.ToInt32();
         var    key = (Keys)ShlUtil.HIWORD(m.LParam);
         var    mod = (ShellNotifyIcon.MOD)ShlUtil.LOWORD(m.LParam);
         HotKey hotkey;
         if (HotKeyActionMap.TryGetValue(id, out hotkey) && hotkey != null)
         {
             if (hotkey.Action == null)
             {
                 return;
             }
             var str = hotkey.Action.ToString().Trim();
             if (str.Length == 0)
             {
                 return;
             }
             if (System.IO.File.Exists(str))
             {
                 if (str.Length > 4 && System.IO.Path.GetExtension(str).ToLower() == ".exe")
                 {
                     Process.Start(str);
                 }
                 else
                 {
                     ShellNotifyIcon.ShellExecute(IntPtr.Zero, "open", str, null, null, 10);
                 }
             }
             else if (System.IO.Directory.Exists(str))
             {
                 ShellNotifyIcon.ShellExecute(IntPtr.Zero, "explore", str, null, null, 10);
             }
             MessageBox.Show(hotkey.Display);
         }
     }
 }
Example #3
0
 internal void UnregHotKey(int id)
 {
     ShellNotifyIcon.UnregisterHotKey(this.Handle, id);
 }