Skip to content

Commit c62b468

Browse files
authored
Enable High DPI support (#231)
1 parent 3d160f9 commit c62b468

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

Source/GrasscutterTools/GrasscutterTools.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@
352352
<Compile Include="Utils\ArtifactUtils.cs" />
353353
<Compile Include="Utils\Common.cs" />
354354
<Compile Include="Utils\GuiRedirect.cs" />
355+
<Compile Include="Utils\HighDPIUtil.cs" />
355356
<Compile Include="Utils\KeyGo.cs" />
356357
<Compile Include="Utils\HotKeyItem.cs" />
357358
<Compile Include="Utils\HttpHelper.cs" />

Source/GrasscutterTools/Program.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ private static int Main(string[] args)
7171
if (result != -1)
7272
return result;
7373

74+
// 开启高DPI支持
75+
if (Environment.OSVersion.Version.Major >= 6) // 至少需要Vista系统
76+
{
77+
HighDPIUtil.SetDpiAwareness();
78+
}
79+
7480
Application.EnableVisualStyles();
7581
Application.SetCompatibleTextRenderingDefault(false);
7682

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Runtime.InteropServices;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace GrasscutterTools.Utils
9+
{
10+
internal class HighDPIUtil
11+
{
12+
public static void SetDpiAwareness()
13+
{
14+
var dpiAwareness = ProcessDpiAwareness.PerMonitorDpiAware;
15+
var hresult = SetProcessDpiAwareness(dpiAwareness);
16+
if (hresult != 0)
17+
{
18+
throw new System.ComponentModel.Win32Exception(hresult);
19+
}
20+
}
21+
22+
[DllImport("shcore.dll")]
23+
private static extern int SetProcessDpiAwareness(ProcessDpiAwareness value);
24+
25+
private enum ProcessDpiAwareness
26+
{
27+
DpiUnaware = 0,
28+
SystemDpiAware = 1,
29+
PerMonitorDpiAware = 2
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)