Skip to content

Commit d092412

Browse files
committed
Implemented immersive dark mode
1 parent 952a909 commit d092412

12 files changed

Lines changed: 164 additions & 1 deletion

Sonic-06-Mod-Manager/Sonic-06-Mod-Manager.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
<PropertyGroup>
4242
<ApplicationIcon>res\Icons\logo_main_icon.ico</ApplicationIcon>
4343
</PropertyGroup>
44+
<PropertyGroup>
45+
<ApplicationManifest>app.manifest</ApplicationManifest>
46+
</PropertyGroup>
4447
<ItemGroup>
4548
<Reference Include="Marathon.Helpers, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
4649
<SpecificVersion>False</SpecificVersion>
@@ -77,6 +80,7 @@
7780
<DesignTime>True</DesignTime>
7881
<DependentUpon>Resources.resx</DependentUpon>
7982
</Compile>
83+
<Compile Include="src\Environment3\Interop\ImmersiveDarkMode.cs" />
8084
<Compile Include="src\Environment3\PatchCreator.cs">
8185
<SubType>Form</SubType>
8286
</Compile>
@@ -299,6 +303,7 @@
299303
<DependentUpon>ProgressDialog.cs</DependentUpon>
300304
</EmbeddedResource>
301305
<None Include="app.config" />
306+
<None Include="app.manifest" />
302307
<None Include="Properties\Settings.settings">
303308
<Generator>SettingsSingleFileGenerator</Generator>
304309
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

Sonic-06-Mod-Manager/app.manifest

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
3+
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
4+
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
5+
<security>
6+
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
7+
<!-- UAC Manifest Options
8+
If you want to change the Windows User Account Control level replace the
9+
requestedExecutionLevel node with one of the following.
10+
11+
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
12+
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
13+
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
14+
15+
Specifying requestedExecutionLevel element will disable file and registry virtualization.
16+
Remove this element if your application requires this virtualization for backwards
17+
compatibility.
18+
-->
19+
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
20+
</requestedPrivileges>
21+
</security>
22+
</trustInfo>
23+
24+
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
25+
<application>
26+
<!-- A list of the Windows versions that this application has been tested on
27+
and is designed to work with. Uncomment the appropriate elements
28+
and Windows will automatically select the most compatible environment. -->
29+
30+
<!-- Windows Vista -->
31+
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
32+
33+
<!-- Windows 7 -->
34+
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
35+
36+
<!-- Windows 8 -->
37+
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
38+
39+
<!-- Windows 8.1 -->
40+
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
41+
42+
<!-- Windows 10 -->
43+
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
44+
45+
</application>
46+
</compatibility>
47+
48+
<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
49+
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
50+
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
51+
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config.
52+
53+
Makes the application long-path aware. See https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation -->
54+
<!--
55+
<application xmlns="urn:schemas-microsoft-com:asm.v3">
56+
<windowsSettings>
57+
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
58+
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
59+
</windowsSettings>
60+
</application>
61+
-->
62+
63+
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
64+
<!--
65+
<dependency>
66+
<dependentAssembly>
67+
<assemblyIdentity
68+
type="win32"
69+
name="Microsoft.Windows.Common-Controls"
70+
version="6.0.0.0"
71+
processorArchitecture="*"
72+
publicKeyToken="6595b64144ccf1df"
73+
language="*"
74+
/>
75+
</dependentAssembly>
76+
</dependency>
77+
-->
78+
79+
</assembly>

Sonic-06-Mod-Manager/src/Environment3/Controls/UnifyMessenger.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,20 @@ internal partial class UnifyMessenger : Form
3939
public static string Accept = string.Empty;
4040
public static int TextHeight = 0;
4141

42-
public UnifyMessenger() { InitializeComponent(); }
42+
public UnifyMessenger()
43+
{
44+
InitializeComponent();
45+
46+
// Initialise immersive dark mode.
47+
ImmersiveDarkMode.Initialise(Handle, true);
48+
}
4349

4450
public UnifyMessenger(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon) {
4551
InitializeComponent();
4652

53+
// Initialise immersive dark mode.
54+
ImmersiveDarkMode.Initialise(Handle, true);
55+
4756
Text = caption;
4857
rtb_Message.Text = text;
4958

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace Unify.Environment3
5+
{
6+
public static class ImmersiveDarkMode
7+
{
8+
[DllImport("dwmapi.dll")]
9+
private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
10+
11+
private const int DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19;
12+
private const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
13+
14+
/// <summary>
15+
/// Initialises immersive dark mode for the input handle in Desktop Window Manager.
16+
/// <para>This requires an application manifest that supports Windows 10 for OSVersion to return the correct build numbers.</para>
17+
/// </summary>
18+
/// <param name="handle">Window handle to apply immersive dark mode to.</param>
19+
/// <param name="enabled">Whether or not immersive dark mode should be enabled.</param>
20+
public static bool Initialise(IntPtr handle, bool enabled)
21+
{
22+
int useImmersiveDarkMode = enabled ? 1 : 0;
23+
24+
if (IsW10OrGreater(17763))
25+
{
26+
var attribute = DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1;
27+
28+
if (IsW10OrGreater(18985))
29+
attribute = DWMWA_USE_IMMERSIVE_DARK_MODE;
30+
31+
return DwmSetWindowAttribute(handle, attribute, ref useImmersiveDarkMode, sizeof(int)) == 0;
32+
}
33+
34+
return false;
35+
}
36+
37+
/// <summary>
38+
/// Checks if the returned OSVersion is greater than Windows 10.
39+
/// </summary>
40+
/// <param name="build">Windows 10 build number to check.</param>
41+
private static bool IsW10OrGreater(int build)
42+
=> Environment.OSVersion.Version.Major >= 10 && Environment.OSVersion.Version.Build >= build;
43+
}
44+
}

Sonic-06-Mod-Manager/src/Environment3/ModCreator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public ModCreator(string mod, bool edit)
5151
this.mod = mod;
5252
this.edit = edit;
5353

54+
// Initialise immersive dark mode.
55+
ImmersiveDarkMode.Initialise(Handle, true);
56+
5457
if (!this.edit) {
5558
text_Version.Text = "1.0";
5659
text_Date.Text = DateTime.Now.ToString("dd/MM/yyyy");

Sonic-06-Mod-Manager/src/Environment3/ModInfo.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public partial class ModInfo : Form
4646
public ModInfo(string mod) {
4747
InitializeComponent();
4848

49+
// Initialise immersive dark mode.
50+
ImmersiveDarkMode.Initialise(Handle, true);
51+
4952
modDirectory = Path.GetDirectoryName(mod);
5053

5154
string[] getThumbnail = Directory.GetFiles(modDirectory, "thumbnail*", SearchOption.TopDirectoryOnly);

Sonic-06-Mod-Manager/src/Environment3/ModOneClickInstall.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public partial class ModOneClickInstall : Form
5252
public ModOneClickInstall(GBAPIItemDataBasic item, string url, int downloadID, int modID) {
5353
InitializeComponent();
5454

55+
// Initialise immersive dark mode.
56+
ImmersiveDarkMode.Initialise(Handle, true);
57+
5558
this.url = url;
5659
this.item = item;
5760
this.modID = modID;

Sonic-06-Mod-Manager/src/Environment3/PatchCreator.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public partial class PatchCreator : Form
4747
public PatchCreator(string patch, bool edit)
4848
{
4949
InitializeComponent();
50+
51+
// Initialise immersive dark mode.
52+
ImmersiveDarkMode.Initialise(Handle, true);
53+
5054
this.patch = patch;
5155
this.edit = edit;
5256
if (!this.edit) {

Sonic-06-Mod-Manager/src/Environment3/ProfileCreator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public ProfileCreator(ListView modsList, ListView patchesList)
3636
{
3737
InitializeComponent();
3838

39+
// Initialise immersive dark mode.
40+
ImmersiveDarkMode.Initialise(Handle, true);
41+
3942
// Set theme colours
4043
unifytb_ProfileCreator.ActiveColor =
4144
unifytb_ProfileCreator.HorizontalLineColor =

Sonic-06-Mod-Manager/src/Environment3/ProfileSelect.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public ProfileSelect()
3939
{
4040
InitializeComponent();
4141

42+
// Initialise immersive dark mode.
43+
ImmersiveDarkMode.Initialise(Handle, true);
44+
4245
// Set theme colours
4346
unifytb_Profiles.ActiveColor =
4447
unifytb_Profiles.HorizontalLineColor =

0 commit comments

Comments
 (0)