IsWindowVisible() private method

private IsWindowVisible ( IntPtr hWnd ) : bool
hWnd System.IntPtr
return bool
Exemplo n.º 1
0
        /// <summary>
        /// Callback function for the enumwindows function
        /// </summary>
        /// <param name="winHandle">enumerated window handle</param>
        /// <param name="lParam">nod used </param>
        /// <returns></returns>
        private static bool enumWindowsCallback(IntPtr winHandle, int lParam)
        {
            if (!User32Interop.IsWindowVisible(winHandle))
            {
                return(true);
            }

            if (_excludeThisProcess)
            {
                uint pid = 0;
                User32Interop.GetWindowThreadProcessId(winHandle, out pid);

                if (pid == 0 || pid == _currentProcess.Id)
                {
                    return(true);
                }
            }

            if (!Windows.IsApplicationWindow(winHandle))
            {
                return(true);
            }

            if (!canBeActivated(winHandle))
            {
                return(true);
            }

            if (Windows.IsCloakedWindow(winHandle))
            {
                return(true);
            }

            var buffer = new StringBuilder(1024);

            User32Interop.GetWindowText(winHandle, buffer, buffer.Capacity);
            var windowTitle = buffer.ToString();

            // save the window only if it is visible and contains a title
            // and has an app icon (this criterium is needed to not display "Start" and "Program Manager")
            // this can be altered in the future to add other filtering criteria

            if (!string.IsNullOrEmpty(windowTitle))
            {
                Log.Debug("hWnd=" + winHandle + "  windowTitle=" + windowTitle);

                var info = new WindowInfo(winHandle, windowTitle);
                windowList.Add(info);
            }

            // return true to continue enumerating windows.
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Callback function for the enumwindows function
        /// </summary>
        /// <param name="winHandle">enumerated window handle</param>
        /// <param name="lParam">nod used </param>
        /// <returns></returns>
        private static bool enumWindowsCallback(IntPtr winHandle, int lParam)
        {
            var buffer = new StringBuilder(1024);

            User32Interop.GetWindowText(winHandle, buffer, buffer.Capacity);
            var windowTitle = buffer.ToString();

            // save the window only if it is visible and contains a title
            // and has an app icon (this criterium is needed to not display "Start" and "Program Manager")
            // this can be altered in the future to add other filtering criteria

            if (User32Interop.IsWindowVisible(winHandle) &&
                (!string.IsNullOrEmpty(windowTitle)) && (GetAppIcon(winHandle) != null))
            {
                Log.Debug("hWnd=" + winHandle + "  windowTitle=" + windowTitle);

                var info = new WindowInfo(winHandle, windowTitle);
                windowList.Add(info);
            }

            // return true to continue enumerating windows.
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the pop window (if any) of the specified window
        /// </summary>
        /// <param name="window">Window handle</param>
        /// <returns>handle if found, IntPtr.Zero else</returns>
        private static IntPtr getWindowPopup(IntPtr window)
        {
            var windowLevel  = 32;
            var targetWindow = window;

            while (windowLevel-- > 0)
            {
                IntPtr popupWindow = User32Interop.GetLastActivePopup(targetWindow);

                if (User32Interop.IsWindowVisible(popupWindow))
                {
                    return(popupWindow);
                }

                if (popupWindow == targetWindow)
                {
                    return(IntPtr.Zero);
                }

                targetWindow = popupWindow;
            }

            return(IntPtr.Zero);
        }