mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-19 06:53:26 +08:00
parent
688d37fe76
commit
d235bf9822
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Windows.Interop;
|
using System.Windows.Interop;
|
||||||
@ -51,18 +52,60 @@ namespace Wox.Helper
|
|||||||
[DllImport("user32.dll", SetLastError = true)]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
private static extern int GetWindowRect(IntPtr hwnd, out RECT rc);
|
private static extern int GetWindowRect(IntPtr hwnd, out RECT rc);
|
||||||
|
|
||||||
|
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||||
|
private static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
|
||||||
|
|
||||||
|
[DllImport("user32.DLL")]
|
||||||
|
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
|
||||||
|
|
||||||
|
|
||||||
|
const string WINDOW_CLASS_CONSOLE = "ConsoleWindowClass";
|
||||||
|
const string WINDOW_CLASS_WINTAB = "Flip3D";
|
||||||
|
const string WINDOW_CLASS_PROGMAN = "Progman";
|
||||||
|
const string WINDOW_CLASS_WORKERW = "WorkerW";
|
||||||
|
|
||||||
public static bool IsWindowFullscreen()
|
public static bool IsWindowFullscreen()
|
||||||
{
|
{
|
||||||
RECT foreWinBounds;
|
//get current active window
|
||||||
Rectangle screenBounds;
|
IntPtr hWnd = GetForegroundWindow();
|
||||||
var hWnd = GetForegroundWindow();
|
|
||||||
if (!hWnd.Equals(IntPtr.Zero))
|
if (hWnd != null && !hWnd.Equals(IntPtr.Zero))
|
||||||
{
|
{
|
||||||
|
//if current active window is NOT desktop or shell
|
||||||
if (!(hWnd.Equals(HWND_DESKTOP) || hWnd.Equals(HWND_SHELL)))
|
if (!(hWnd.Equals(HWND_DESKTOP) || hWnd.Equals(HWND_SHELL)))
|
||||||
{
|
{
|
||||||
GetWindowRect(hWnd, out foreWinBounds);
|
StringBuilder sb = new StringBuilder(256);
|
||||||
screenBounds = Screen.FromHandle(hWnd).Bounds;
|
GetClassName(hWnd, sb, sb.Capacity);
|
||||||
if ((foreWinBounds.Bottom - foreWinBounds.Top) == screenBounds.Height && (foreWinBounds.Right - foreWinBounds.Left) == screenBounds.Width)
|
string windowClass = sb.ToString();
|
||||||
|
|
||||||
|
//for Win+Tab (Flip3D)
|
||||||
|
if (windowClass == WINDOW_CLASS_WINTAB)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
RECT appBounds;
|
||||||
|
GetWindowRect(hWnd, out appBounds);
|
||||||
|
|
||||||
|
//for console (ConsoleWindowClass), we have to check for negative dimensions
|
||||||
|
if (windowClass == WINDOW_CLASS_CONSOLE)
|
||||||
|
{
|
||||||
|
return appBounds.Top < 0 && appBounds.Bottom < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//for desktop (Progman or WorkerW, depends on the system), we have to check
|
||||||
|
if (windowClass == WINDOW_CLASS_PROGMAN || windowClass == WINDOW_CLASS_WORKERW)
|
||||||
|
{
|
||||||
|
IntPtr hWndDesktop = FindWindowEx(hWnd, IntPtr.Zero, "SHELLDLL_DefView", null);
|
||||||
|
hWndDesktop = FindWindowEx(hWndDesktop, IntPtr.Zero, "SysListView32", "FolderView");
|
||||||
|
if (hWndDesktop != null && !hWndDesktop.Equals(IntPtr.Zero))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle screenBounds = Screen.FromHandle(hWnd).Bounds;
|
||||||
|
if ((appBounds.Bottom - appBounds.Top) == screenBounds.Height && (appBounds.Right - appBounds.Left) == screenBounds.Width)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -104,7 +147,7 @@ namespace Wox.Helper
|
|||||||
matrix = src.CompositionTarget.TransformFromDevice;
|
matrix = src.CompositionTarget.TransformFromDevice;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Point((int) (matrix.M11*unitX), (int) (matrix.M22*unitY));
|
return new Point((int)(matrix.M11 * unitX), (int)(matrix.M22 * unitY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user