Beispiel #1
0
        /// <summary>
        /// Disable mouse input transparency for the given window.
        /// </summary>
        /// <remarks>
        /// Returns true if input transparency is already disabled or if window isn't layered.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// If input window is null.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// If input window handle is equal to IntPtr.Zero.
        /// </exception>
        /// <SecurityNote>
        /// This method isn't security critical, because work with window handle going on internally.
        /// </SecurityNote>
        public static bool TryDisableInputTransparency(Window window)
        {
            if (window is null)
            {
                throw new ArgumentNullException(nameof(window));
            }

            IntPtr handle = InternalWindowsHelper.GetWindowHandle(window);

            if (handle == IntPtr.Zero)
            {
                throw new ArgumentException(InputWindowHasInvalidHandle);
            }

            WindowStylesEx windowStyles = InternalWindowsHelper.GetWindowsExtendedStyle(handle);

            if (!windowStyles.HasFlag(WindowStylesEx.WS_EX_LAYERED))
            {
                return(false);
            }

            if (windowStyles.HasFlag(WindowStylesEx.WS_EX_TRANSPARENT))
            {
                WindowStylesEx newStyle = windowStyles & ~WindowStylesEx.WS_EX_TRANSPARENT;

                return(InternalWindowsHelper.TrySetWindowsExtendedStyle(handle, newStyle));
            }
            else
            {
                return(true);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Checks that input window is transparency for the mouse input.
        /// </summary>
        /// <exception cref="ArgumentNullException">
        /// If input window is null.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// If input window handle is equal to IntPtr.Zero.
        /// </exception>
        /// <SecurityNote>
        /// This method isn't security critical, because work with window handle going on internally.
        /// </SecurityNote>
        public static bool HasInputTransparency(Window window)
        {
            if (window is null)
            {
                throw new ArgumentNullException(nameof(window));
            }

            IntPtr handle = InternalWindowsHelper.GetWindowHandle(window);

            if (handle == IntPtr.Zero)
            {
                throw new ArgumentException(InputWindowHasInvalidHandle);
            }

            return(InternalWindowsHelper.IsContainExtendedStyle(handle, WindowStylesEx.WS_EX_TRANSPARENT));
        }