Skip to content

Commit

Permalink
Enable High DPI support (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
JDDKCN authored Jun 23, 2024
1 parent 3d160f9 commit c62b468
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions Source/GrasscutterTools/GrasscutterTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@
<Compile Include="Utils\ArtifactUtils.cs" />
<Compile Include="Utils\Common.cs" />
<Compile Include="Utils\GuiRedirect.cs" />
<Compile Include="Utils\HighDPIUtil.cs" />
<Compile Include="Utils\KeyGo.cs" />
<Compile Include="Utils\HotKeyItem.cs" />
<Compile Include="Utils\HttpHelper.cs" />
Expand Down
6 changes: 6 additions & 0 deletions Source/GrasscutterTools/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ private static int Main(string[] args)
if (result != -1)
return result;

// 开启高DPI支持
if (Environment.OSVersion.Version.Major >= 6) // 至少需要Vista系统
{
HighDPIUtil.SetDpiAwareness();
}

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

Expand Down
32 changes: 32 additions & 0 deletions Source/GrasscutterTools/Utils/HighDPIUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace GrasscutterTools.Utils
{
internal class HighDPIUtil
{
public static void SetDpiAwareness()
{
var dpiAwareness = ProcessDpiAwareness.PerMonitorDpiAware;
var hresult = SetProcessDpiAwareness(dpiAwareness);
if (hresult != 0)
{
throw new System.ComponentModel.Win32Exception(hresult);
}
}

[DllImport("shcore.dll")]
private static extern int SetProcessDpiAwareness(ProcessDpiAwareness value);

private enum ProcessDpiAwareness
{
DpiUnaware = 0,
SystemDpiAware = 1,
PerMonitorDpiAware = 2
}
}
}

0 comments on commit c62b468

Please sign in to comment.