コード例 #1
0
        private static bool EnumTheWindows(IntPtr hWnd, IntPtr lParam)
        {
            int windowNameSize = WindowsFunctions.GetWindowTextLength(hWnd);

            if (hWnd == WindowsFunctions.GetShellWindow())
            {
                return(true);
            }
            if (windowNameSize == 0)
            {
                return(true);
            }
            if (!WindowsFunctions.IsWindowVisible(hWnd))
            {
                return(true);
            }


            StringBuilder sb = new StringBuilder(windowNameSize + 1);

            WindowsFunctions.GetWindowText(hWnd, sb, windowNameSize + 1);

            ActiveWindows.Add(sb.ToString(), hWnd);

            return(true);
        }
コード例 #2
0
 /// <summary>
 /// Unregisters a hot key. If it fails, it will throw a <see cref="HotKeyException"/>
 /// </summary>
 /// <exception cref="HotKeyException">If hotKey removal failed</exception>
 public void UnregisterHotKey()
 {
     if (!WindowsFunctions.UnregisterHotKey(IntPtr.Zero, Id))
     {
         ErrorMsg = new Win32Exception(Marshal.GetLastWin32Error()).Message;
         throw new HotKeyException(ErrorMsg);
     }
 }
コード例 #3
0
        /// <summary>
        /// Register a hot key. If the registration was successful it will return a <see cref="HotKey" /> object.
        /// If registration was unsuccessful it will throw a <see cref="HotKeyException" />.
        /// </summary>
        /// <param name="hWnd">Window Handle.</param>
        /// <param name="key">The key.</param>
        /// <param name="modifiers">The modifiers.</param>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        /// <exception cref="HotKeyException">If hotKey registration failed</exception>
        public static HotKey RegisterHotKey(IntPtr hWnd, VirtualKeys key, Modifiers modifiers, int id)
        {
            if (!WindowsFunctions.RegisterHotKey(hWnd, id, (uint)modifiers, (uint)key))
            {
                throw new HotKeyException(new Win32Exception(Marshal.GetLastWin32Error()).Message);
            }

            return(new HotKey(key, id));
        }
コード例 #4
0
        /// <summary>
        /// Dispose unmanaged resources
        /// </summary>
        /// <param name="disposing"></param>
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                //dispose managed resources
            }

            //dispose unmanaged resources
            WindowsFunctions.UnregisterHotKey(IntPtr.Zero, Id);
            _disposed = true;
        }
コード例 #5
0
 private static void UpdateDictionary()
 {
     ActiveWindows.Clear();
     WindowsFunctions.EnumWindows(EnumTheWindows, IntPtr.Zero);
 }