Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on windows 7 #158

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion FluentWPF/AcrylicWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,34 @@ protected static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lPar
var monitorRectangle = monitorInfo.rcMonitor;

var win = (Window)HwndSource.FromHwnd(hwnd).RootVisual;
GetDpiForMonitor(hMonitor, MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, out var dpiX, out var dpiY);
uint dpiX = 96, dpiY = 96;
if (Environment.OSVersion.Version.Major >= 10 || (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 3))
{
GetDpiForMonitor(hMonitor, MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, out dpiX, out dpiY);
}
else
{
// must be an old version of Windows (7 or 8)
// an old version of Windows (7 or 8)
// Get scale of main window and assume scale is the same for all monitors
using (ManagementClass mc = new ManagementClass("Win32_DesktopMonitor"))
{
using (ManagementObjectCollection moc = mc.GetInstances())
{

uint PixelsPerXLogicalInch = 0; // dpi for x
uint PixelsPerYLogicalInch = 0; // dpi for y

foreach (ManagementObject each in moc)
{
PixelsPerXLogicalInch = uint.Parse((each.Properties["PixelsPerXLogicalInch"].Value.ToString()));
PixelsPerYLogicalInch = uint.Parse((each.Properties["PixelsPerYLogicalInch"].Value.ToString()));
}
dpiX = PixelsPerXLogicalInch;
dpiY = PixelsPerYLogicalInch;
}
}
}
var maxWidth = win.MaxWidth / 96.0 * dpiX;
var maxHeight = win.MaxHeight / 96.0 * dpiY;
var minWidth = win.MinWidth / 96.0 * dpiX;
Expand Down