Exemplo n.º 1
0
        /// <summary>
        /// Gets a value indicating whether is the window cloaked. To detect UWP apps in background or win32 apps running in another virtual desktop
        /// </summary>
        public bool IsWindowCloaked()
        {
            int       isCloaked     = 0;
            const int DWMWA_CLOAKED = 14;

            InteropAndHelpers.DwmGetWindowAttribute(hwnd, DWMWA_CLOAKED, out isCloaked, sizeof(int));
            return(isCloaked != 0);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Deactivates the live preview
 /// </summary>
 public static void DeactivateLivePreview()
 {
     InteropAndHelpers.DwmpActivateLivePreview(
         false,
         IntPtr.Zero,
         IntPtr.Zero,
         InteropAndHelpers.LivePreviewTrigger.AltTab,
         IntPtr.Zero);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Activates the live preview
 /// </summary>
 /// <param name="targetWindow">the window to show by making all other windows transparent</param>
 /// <param name="windowToSpare">the window which should not be transparent but is not the target window</param>
 public static void ActivateLivePreview(IntPtr targetWindow, IntPtr windowToSpare)
 {
     InteropAndHelpers.DwmpActivateLivePreview(
         true,
         targetWindow,
         windowToSpare,
         InteropAndHelpers.LivePreviewTrigger.Superbar,
         IntPtr.Zero);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Updates the list of open windows
        /// </summary>
        public void UpdateOpenWindowsList()
        {
            windows.Clear();

            new Task(() =>
            {
                InteropAndHelpers.CallBackPtr callbackptr = new InteropAndHelpers.CallBackPtr(WindowEnumerationCallBack);
                InteropAndHelpers.EnumWindows(callbackptr, 0);
            }).Start();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Makes sure that a window is excluded from the live preview
        /// </summary>
        /// <param name="hwnd">handle to the window to exclude</param>
        public static void SetWindowExlusionFromLivePreview(IntPtr hwnd)
        {
            int renderPolicy = (int)InteropAndHelpers.DwmNCRenderingPolicy.Enabled;

            InteropAndHelpers.DwmSetWindowAttribute(
                hwnd,
                12,
                ref renderPolicy,
                sizeof(int));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the name of the process using the window handle
        /// </summary>
        /// <param name="hwnd">The handle to the window</param>
        /// <returns>A string representing the process name or an empty string if the function fails</returns>
        private string GetProcessNameFromWindowHandle(IntPtr hwnd)
        {
            uint processId = GetProcessIDFromWindowHandle(hwnd);

            ProcessID = processId;
            IntPtr        processHandle = InteropAndHelpers.OpenProcess(InteropAndHelpers.ProcessAccessFlags.AllAccess, true, (int)processId);
            StringBuilder processName   = new StringBuilder(MaximumFileNameLength);

            if (InteropAndHelpers.GetProcessImageFileName(processHandle, processName, MaximumFileNameLength) != 0)
            {
                return(processName.ToString().Split('\\').Reverse().ToArray()[0]);
            }
            else
            {
                return(string.Empty);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Switches dekstop focus to the window
        /// </summary>
        public void SwitchToWindow()
        {
            // The following block is necessary because
            // 1) There is a weird flashing behaviour when trying
            //    to use ShowWindow for switching tabs in IE
            // 2) SetForegroundWindow fails on minimized windows
            if (ProcessName.ToLower().Equals("iexplore.exe") || !Minimized)
            {
                InteropAndHelpers.SetForegroundWindow(Hwnd);
            }
            else
            {
                InteropAndHelpers.ShowWindow(Hwnd, InteropAndHelpers.ShowWindowCommands.Restore);
            }

            InteropAndHelpers.FlashWindow(Hwnd, true);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Returns what the window size is
        /// </summary>
        /// <returns>The state (minimized, maximized, etc..) of the window</returns>
        public WindowSizeState GetWindowSizeState()
        {
            InteropAndHelpers.GetWindowPlacement(Hwnd, out InteropAndHelpers.WINDOWPLACEMENT placement);

            switch (placement.ShowCmd)
            {
            case InteropAndHelpers.ShowWindowCommands.Normal:
                return(WindowSizeState.Normal);

            case InteropAndHelpers.ShowWindowCommands.Minimize:
            case InteropAndHelpers.ShowWindowCommands.ShowMinimized:
                return(WindowSizeState.Minimized);

            case InteropAndHelpers.ShowWindowCommands.Maximize:     // No need for ShowMaximized here since its also of value 3
                return(WindowSizeState.Maximized);

            default:
                // throw new Exception("Don't know how to handle window state = " + placement.ShowCmd);
                return(WindowSizeState.Unknown);
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Gets the process ID for the Window handle
 /// </summary>
 /// <param name="hwnd">The handle to the window</param>
 /// <returns>The process ID</returns>
 private uint GetProcessIDFromWindowHandle(IntPtr hwnd)
 {
     InteropAndHelpers.GetWindowThreadProcessId(hwnd, out uint processId);
     return(processId);
 }