Skip to content

Commit

Permalink
Fix splashscreen scale calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
dotMorten committed Nov 19, 2024
1 parent 4595776 commit 29d69fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/WinUIEx/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ GdipCreateHBITMAPFromBitmap
WNDCLASSEXW
RegisterClassEx
CreateCompatibleDC
SelectObject
SelectObject
MonitorFromPoint
10 changes: 9 additions & 1 deletion src/WinUIEx/SimpleSplashScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,16 @@ public static SimpleSplashScreen ShowDefaultSplashScreen()
var manager = new Microsoft.Windows.ApplicationModel.Resources.ResourceManager();
var context = manager.CreateResourceContext();

var dpi = PInvoke.GetDpiForWindow(PInvoke.GetDesktopWindow());
uint dpi = 96;
var monitor = PInvoke.MonitorFromPoint(new System.Drawing.Point(0, 0), Windows.Win32.Graphics.Gdi.MONITOR_FROM_FLAGS.MONITOR_DEFAULTTOPRIMARY);

if(monitor != IntPtr.Zero)
{
PInvoke.GetDpiForMonitor(monitor, Windows.Win32.UI.HiDpi.MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, out var dpiX, out var dpiy);
dpi = dpiX;
}
var scale = (int)(dpi / 96d * 100);
if (scale == 0) scale = 100;
context.QualifierValues["Scale"] = scale.ToString();
var splashScreenImageResource = manager.MainResourceMap.TryGetValue("Files/" + image.Replace('\\','/'), context);
if (splashScreenImageResource is not null && splashScreenImageResource.Kind == Microsoft.Windows.ApplicationModel.Resources.ResourceCandidateKind.FilePath)
Expand Down

0 comments on commit 29d69fa

Please sign in to comment.