Exemple #1
0
        /// <summary>
        /// Bind a hotkey to a method.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="method">The method.</param>
        /// <param name="id">The bind ID.</param>
        /// <param name="handle">The handle.</param>
        public static bool RegisterHotKey(Keys key, Action method, int id, IntPtr handle)
        {
            var hotKeyWnd = new HotKeyWndProc();

            if (!RegisterHotKey(handle, id, 0, key))
            {
                HandleError(new Win32Exception(string.Format(Resources.RegisterHotKeyFailed, key)), Resources.RegisterHotKey);
                return(false);
            }

            try
            {
                hotKeyWnd.HotKeyPass = new HotKeyPass(method);
                hotKeyWnd.WParam     = id;
                hotKeyWnd.AssignHandle(handle);
                return(true);
            }
            catch
            {
                hotKeyWnd.ReleaseHandle();
                return(false);
            }
        }