[update] 已禁用管理员批准模式的警告、窗口截图支持DWM拉伸
This commit is contained in:
parent
75abf73089
commit
8a1bcc3ffa
@ -5753,6 +5753,13 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Button>
|
</Button>
|
||||||
</ui:SimpleStackPanel>
|
</ui:SimpleStackPanel>
|
||||||
|
<ui:InfoBar
|
||||||
|
IsOpen="True"
|
||||||
|
Name="CannotSwitchToUserPrivNotification"
|
||||||
|
IsClosable="False"
|
||||||
|
Severity="Warning"
|
||||||
|
Title="可能无法切换到普通用户权限"
|
||||||
|
Message="检测到您禁用了组策略项目:“用户帐户控制:以管理员批准模式运行所有管理员”,这可能会导致无法切换到普通用户权限" />
|
||||||
<Line HorizontalAlignment="Center" X1="0" Y1="0" X2="400" Y2="0" Stroke="#3f3f46"
|
<Line HorizontalAlignment="Center" X1="0" Y1="0" X2="400" Y2="0" Stroke="#3f3f46"
|
||||||
StrokeThickness="1" Margin="0,4,0,4" />
|
StrokeThickness="1" Margin="0,4,0,4" />
|
||||||
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left">
|
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left">
|
||||||
|
@ -18,6 +18,7 @@ using Encoder = System.Drawing.Imaging.Encoder;
|
|||||||
using OperatingSystem = OSVersionExtension.OperatingSystem;
|
using OperatingSystem = OSVersionExtension.OperatingSystem;
|
||||||
using PixelFormat = System.Drawing.Imaging.PixelFormat;
|
using PixelFormat = System.Drawing.Imaging.PixelFormat;
|
||||||
using System.Management;
|
using System.Management;
|
||||||
|
using System.Reflection;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using Path = System.IO.Path;
|
using Path = System.IO.Path;
|
||||||
using Rectangle = System.Drawing.Rectangle;
|
using Rectangle = System.Drawing.Rectangle;
|
||||||
@ -319,11 +320,10 @@ namespace Ink_Canvas {
|
|||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
static extern bool GetLayeredWindowAttributes(IntPtr hwnd, out uint crKey, out byte bAlpha, out uint dwFlags);
|
static extern bool GetLayeredWindowAttributes(IntPtr hwnd, out uint crKey, out byte bAlpha, out uint dwFlags);
|
||||||
public delegate bool EnumWindowsProc(IntPtr hwnd, IntPtr lParam);
|
public delegate bool EnumWindowsProc(IntPtr hwnd, IntPtr lParam);
|
||||||
[DllImport("user32.dll")]
|
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
|
||||||
public static extern bool EnumChildWindows(IntPtr hwndParent, EnumWindowsProc lpEnumFunc, IntPtr lParam);
|
|
||||||
[DllImport("user32.dll", SetLastError=true)]
|
[DllImport("user32.dll", SetLastError=true)]
|
||||||
static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId);
|
static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId);
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
internal static extern int GetDpiForWindow(IntPtr hWnd);
|
||||||
|
|
||||||
enum DwmWindowAttribute : uint {
|
enum DwmWindowAttribute : uint {
|
||||||
NCRenderingEnabled = 1,
|
NCRenderingEnabled = 1,
|
||||||
@ -382,6 +382,9 @@ namespace Ink_Canvas {
|
|||||||
public RECT RealRect { get; set; }
|
public RECT RealRect { get; set; }
|
||||||
public Rectangle ContentRect { get; set; }
|
public Rectangle ContentRect { get; set; }
|
||||||
public IntPtr Handle { get; set; }
|
public IntPtr Handle { get; set; }
|
||||||
|
public int WindowDPI { get; set; }
|
||||||
|
public int SystemDPI { get; set; }
|
||||||
|
public double DPIScale { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct WINDOWPLACEMENT {
|
public struct WINDOWPLACEMENT {
|
||||||
@ -426,6 +429,18 @@ namespace Ink_Canvas {
|
|||||||
if ((windowLong & 0x00080000) != 0 && (dwFlags & 0x00000002) != 0 && bAlpha == 0) return true; //分层窗口且全透明
|
if ((windowLong & 0x00080000) != 0 && (dwFlags & 0x00000002) != 0 && bAlpha == 0) return true; //分层窗口且全透明
|
||||||
DwmGetWindowAttribute(hwnd, (int)DwmWindowAttribute.Cloaked, out bool isCloacked, Marshal.SizeOf(typeof(bool)));
|
DwmGetWindowAttribute(hwnd, (int)DwmWindowAttribute.Cloaked, out bool isCloacked, Marshal.SizeOf(typeof(bool)));
|
||||||
DwmGetWindowAttribute(hwnd, DwmWindowAttribute.ExtendedFrameBounds, out RECT realRect, Marshal.SizeOf(typeof(RECT)));
|
DwmGetWindowAttribute(hwnd, DwmWindowAttribute.ExtendedFrameBounds, out RECT realRect, Marshal.SizeOf(typeof(RECT)));
|
||||||
|
var pidRes = GetWindowThreadProcessId(hwnd, out uint pid);
|
||||||
|
if (pid == 0 || pidRes == 0) return true;
|
||||||
|
var dpiForHwnd = GetDpiForWindow(hwnd);
|
||||||
|
var dpiXProperty = typeof(SystemParameters).GetProperty("DpiX", BindingFlags.NonPublic | BindingFlags.Static);
|
||||||
|
var dpiYProperty = typeof(SystemParameters).GetProperty("Dpi", BindingFlags.NonPublic | BindingFlags.Static);
|
||||||
|
var dpiX = (int)dpiXProperty.GetValue(null, null);
|
||||||
|
var dpiY = (int)dpiYProperty.GetValue(null, null);
|
||||||
|
var dpi = (dpiX + dpiY) / 2;
|
||||||
|
double scale = 1;
|
||||||
|
if (dpi > dpiForHwnd) { // 说明该应用是win32应用,靠DWM的拉伸放大到高DPI
|
||||||
|
scale = dpi / (double)dpiForHwnd;
|
||||||
|
}
|
||||||
if (isCloacked) return true;
|
if (isCloacked) return true;
|
||||||
var icon = GetAppIcon(hwnd);
|
var icon = GetAppIcon(hwnd);
|
||||||
var length = GetWindowTextLength(hwnd) + 1;
|
var length = GetWindowTextLength(hwnd) + 1;
|
||||||
@ -441,7 +456,6 @@ namespace Ink_Canvas {
|
|||||||
GetWindowRect(hwnd, out rect);
|
GetWindowRect(hwnd, out rect);
|
||||||
var w = rect.Width;
|
var w = rect.Width;
|
||||||
var h = rect.Height;
|
var h = rect.Height;
|
||||||
Trace.WriteLine($"x: {realRect.X - rect.X} y: {realRect.Y - rect.Y} w: {realRect.Width} h: {realRect.Height}");
|
|
||||||
if (w == 0 || h == 0) return true;
|
if (w == 0 || h == 0) return true;
|
||||||
Bitmap bmp = new Bitmap(rect.Width, rect.Height);
|
Bitmap bmp = new Bitmap(rect.Width, rect.Height);
|
||||||
Graphics memoryGraphics = Graphics.FromImage(bmp);
|
Graphics memoryGraphics = Graphics.FromImage(bmp);
|
||||||
@ -458,7 +472,11 @@ namespace Ink_Canvas {
|
|||||||
Placement = placement,
|
Placement = placement,
|
||||||
RealRect = realRect,
|
RealRect = realRect,
|
||||||
Handle = hwnd,
|
Handle = hwnd,
|
||||||
ContentRect = new Rectangle(realRect.X - rect.X, realRect.Y - rect.Y, realRect.Width, realRect.Height),
|
ContentRect = new Rectangle(realRect.X - rect.X, realRect.Y - rect.Y, (int)Math.Round(
|
||||||
|
realRect.Width / scale ,0), (int)Math.Round(realRect.Height / scale, 0)),
|
||||||
|
WindowDPI = dpiForHwnd,
|
||||||
|
SystemDPI = dpi,
|
||||||
|
DPIScale = scale
|
||||||
});
|
});
|
||||||
memoryGraphics.ReleaseHdc(hdc);
|
memoryGraphics.ReleaseHdc(hdc);
|
||||||
System.GC.Collect();
|
System.GC.Collect();
|
||||||
|
@ -14,6 +14,7 @@ using System.Windows.Ink;
|
|||||||
using System.Windows.Interop;
|
using System.Windows.Interop;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
|
using Microsoft.Win32;
|
||||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||||
using File = System.IO.File;
|
using File = System.IO.File;
|
||||||
using OperatingSystem = OSVersionExtension.OperatingSystem;
|
using OperatingSystem = OSVersionExtension.OperatingSystem;
|
||||||
@ -88,6 +89,16 @@ namespace Ink_Canvas {
|
|||||||
AdministratorPrivilegeIndicateText.Text = "icc目前以管理员身份运行";
|
AdministratorPrivilegeIndicateText.Text = "icc目前以管理员身份运行";
|
||||||
RunAsAdminButton.Visibility = Visibility.Collapsed;
|
RunAsAdminButton.Visibility = Visibility.Collapsed;
|
||||||
RunAsUserButton.Visibility = Visibility.Visible;
|
RunAsUserButton.Visibility = Visibility.Visible;
|
||||||
|
RegistryKey localKey;
|
||||||
|
if(Environment.Is64BitOperatingSystem)
|
||||||
|
localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
|
||||||
|
else
|
||||||
|
localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
|
||||||
|
|
||||||
|
int LUAValue = (int)(localKey.OpenSubKey("SOFTWARE").OpenSubKey("Microsoft").OpenSubKey("Windows")
|
||||||
|
.OpenSubKey("CurrentVersion").OpenSubKey("Policies").OpenSubKey("System")
|
||||||
|
.GetValue("EnableLUA", 1));
|
||||||
|
CannotSwitchToUserPrivNotification.IsOpen = LUAValue == 0;
|
||||||
} else {
|
} else {
|
||||||
AdministratorPrivilegeIndicateText.Text = "icc目前以非管理员身份运行";
|
AdministratorPrivilegeIndicateText.Text = "icc目前以非管理员身份运行";
|
||||||
RunAsAdminButton.Visibility = Visibility.Visible;
|
RunAsAdminButton.Visibility = Visibility.Visible;
|
||||||
|
Loading…
Reference in New Issue
Block a user