File tree Expand file tree Collapse file tree 2 files changed +9
-14
lines changed Expand file tree Collapse file tree 2 files changed +9
-14
lines changed Original file line number Diff line number Diff line change @@ -292,8 +292,8 @@ private void NotifyIcon_MouseClick(object sender, MouseEventArgs e)
292
292
_allowVisible = true ;
293
293
_keepOpen = e . Button == MouseButtons . Right && Visible == false ;
294
294
295
- //get Windows screen scale factor (system -> display -> scale):
296
- //to get real resolution from virtual one, we need to multiply with scale factor: virtual resolution * scale = native unscaled resolution
295
+ // get Windows screen scale factor (system -> display -> scale):
296
+ // to get real resolution from virtual one, we need to multiply with scale factor: virtual resolution * scale = native unscaled resolution
297
297
float scale = ScreenScaling . GetScreenScalingFactor ( ) ;
298
298
299
299
bool IsVisible ( Point p )
Original file line number Diff line number Diff line change 1
- using System ;
2
- using System . Collections . Generic ;
3
- using System . Linq ;
4
- using System . Text ;
5
- using System . Threading . Tasks ;
1
+ namespace GW_Launcher . Utilities ;
6
2
7
- namespace GW_Launcher . Utilities ;
8
3
internal static class ScreenScaling
9
4
{
10
5
[ DllImport ( "gdi32.dll" ) ]
11
6
static extern int GetDeviceCaps ( IntPtr hdc , int nIndex ) ;
12
7
8
+ // https://www.pinvoke.net/default.aspx/gdi32.getdevicecaps
13
9
private enum DeviceCap
14
10
{
15
11
VERTRES = 10 ,
16
- DESKTOPVERTRES = 117 ,
17
- //... http://pinvoke.net/default.aspx/gdi32/GetDeviceCaps.html
12
+ DESKTOPVERTRES = 117
18
13
}
19
14
20
- //get screen scaling factor set under settings -> system -> screen: scaling (e.g. 225%)
15
+ // get screen scaling factor set under settings -> system -> screen: scaling (e.g. 225%)
21
16
public static float GetScreenScalingFactor ( )
22
17
{
23
18
using Graphics g = Graphics . FromHwnd ( IntPtr . Zero ) ;
24
19
IntPtr desktop = g . GetHdc ( ) ;
25
20
26
- int logicalScreenHeight = GetDeviceCaps ( desktop , ( int ) DeviceCap . VERTRES ) ; //virtual screen resolution scaled down for DPI-unaware app
27
- int physicalScreenHeight = GetDeviceCaps ( desktop , ( int ) DeviceCap . DESKTOPVERTRES ) ; //actual screen resolution, e.g. 3840 x 2160
21
+ var logicalScreenHeight = GetDeviceCaps ( desktop , ( int ) DeviceCap . VERTRES ) ; // virtual screen resolution scaled down for DPI-unaware app
22
+ var physicalScreenHeight = GetDeviceCaps ( desktop , ( int ) DeviceCap . DESKTOPVERTRES ) ; // actual screen resolution, e.g. 3840 x 2160
28
23
29
24
g . ReleaseHdc ( desktop ) ;
30
25
31
- float screenScalingFactor = physicalScreenHeight / ( float ) logicalScreenHeight ;
26
+ var screenScalingFactor = physicalScreenHeight / ( float ) logicalScreenHeight ;
32
27
return screenScalingFactor ; // e.g. 1.25 = 125%
33
28
}
34
29
}
You can’t perform that action at this time.
0 commit comments