-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Drawing; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace HsrGraphicsTool.Models; | ||
|
||
/// <summary> | ||
/// Utilities for capturing Windows display information using the Windows GDI API. | ||
/// Adapted from this S/O answer: https://stackoverflow.com/a/76670176 | ||
/// </summary> | ||
public static class DisplayUtils | ||
{ | ||
[DllImport("gdi32.dll")] | ||
private static extern int GetDeviceCaps(nint hdc, int nIndex); | ||
|
||
private enum DeviceCap | ||
{ | ||
Desktopvertres = 117, | ||
Desktophorzres = 118 | ||
} | ||
|
||
public static Size GetPhysicalDisplaySize() | ||
{ | ||
var g = Graphics.FromHwnd(nint.Zero); | ||
var desktop = g.GetHdc(); | ||
|
||
var physicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.Desktopvertres); | ||
var physicalScreenWidth = GetDeviceCaps(desktop, (int)DeviceCap.Desktophorzres); | ||
|
||
return new Size(physicalScreenWidth, physicalScreenHeight); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters