Skip to content

Commit

Permalink
win32
Browse files Browse the repository at this point in the history
  • Loading branch information
rounk-ctrl committed Sep 18, 2023
1 parent 5832f80 commit d96fae1
Show file tree
Hide file tree
Showing 9 changed files with 1,487 additions and 1,749 deletions.
5 changes: 0 additions & 5 deletions Rectify11Installer/Core/TreeViewExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ namespace Rectify11Installer.Core
{
public static class TreeViewExtension
{
public static List<TreeNode> Descendants(this TreeView tree)
{
var nodes = tree.Nodes.Cast<TreeNode>();
return nodes.SelectMany(x => x.Descendants()).Concat(nodes).ToList();
}
public static List<TreeNode> Descendants(this TreeNode node)
{
var nodes = node.Nodes.Cast<TreeNode>().ToList();
Expand Down
22 changes: 9 additions & 13 deletions Rectify11Installer/Rectify11Installer.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Resource.Embedder.2.2.0\build\Resource.Embedder.props" Condition="Exists('..\packages\Resource.Embedder.2.2.0\build\Resource.Embedder.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -101,9 +100,6 @@
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="TaskDialog, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\KPreisser.UI.TaskDialog.1.0.0\lib\net472\TaskDialog.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Controls\DarkAwareControls.cs">
Expand Down Expand Up @@ -239,13 +235,12 @@
<Compile Include="Win32\DarkMode.cs" />
<Compile Include="Win32\NativeMethods.cs" />
<Compile Include="Win32\RECT.cs" />
<Compile Include="Win32\SafeHGlobalHandle.cs" />
<Compile Include="Win32\Vanara\DesktopWindowManager\DesktopWindowManager.cs" />
<Compile Include="Win32\Vanara\DesktopWindowManager\GlassExtenderProvider.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Win32\Vanara\NativeMethodsVan.cs" />
<Compile Include="Win32\VisualStylesRendererExtension.cs" />
<Compile Include="Win32\Vanara\VisualStylesRendererExtension.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -316,7 +311,6 @@
<LastGenOutput>Rectify11.zh-TW.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="app.manifest" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down Expand Up @@ -383,13 +377,15 @@
<Content Include="r11.ico" />
<None Include="Resources\7za.exe" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="KPreisser.UI.TaskDialog">
<Version>1.0.0</Version>
</PackageReference>
<PackageReference Include="Resource.Embedder">
<Version>2.2.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Resource.Embedder.2.2.0\build\Resource.Embedder.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Resource.Embedder.2.2.0\build\Resource.Embedder.props'))" />
</Target>
<Target Name="FixAL1703Warning" BeforeTargets="GenerateSatelliteAssemblies" Condition="'$(PlatformTarget)' == 'x64'">
<Message Text="Adjusting SDK tools directory to use x64 version of AL.EXE" />
<PropertyGroup>
Expand Down
254 changes: 127 additions & 127 deletions Rectify11Installer/Win32/DarkMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,134 +4,134 @@

namespace Rectify11Installer.Win32
{
public class DarkMode
{
#region P/Invoke
[DllImport("uxtheme.dll", EntryPoint = "#135")]
internal static extern int SetPreferredAppMode(PreferredAppMode appMode);
[DllImport("uxtheme.dll", EntryPoint = "#135")]
internal static extern int AllowDarkModeForApp(bool allow);
[DllImport("uxtheme.dll", EntryPoint = "#133")]
internal static extern int AllowDarkModeForWindow(IntPtr handle, bool allow);
[DllImport("user32.dll")]
public static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WINDOWCOMPOSITIONATTRIBDATA data);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool SetProp(IntPtr hWnd, string lpString, IntPtr hData);
[DllImport("dwmapi.dll")]
internal static extern int DwmSetWindowAttribute(IntPtr hwnd, DWMATTRIB dwAttribute, ref int pvAttribute, int cbAttribute);
#endregion
#region Flags
internal enum PreferredAppMode
{
Default,
AllowDark,
ForceDark,
ForceLight,
Max
}
public enum WINDOWCOMPOSITIONATTRIB
{
// ...
WCA_USEDARKMODECOLORS = 26,
// ...
};
public enum DWMATTRIB
{
DWMWA_SYSTEMBACKDROP_TYPE = 38,
DWMWA_MICA_EFFECT = 1029
}
[StructLayout(LayoutKind.Sequential)]
public struct WINDOWCOMPOSITIONATTRIBDATA
{
public WINDOWCOMPOSITIONATTRIB Attrib;
public IntPtr pvData;
public int cbData;
};
#endregion
#region Public Methods
public static void RefreshTitleBarColor(IntPtr hWnd)
{
if (Environment.OSVersion.Version.Build < 18362)
{
SetProp(hWnd, "UseImmersiveDarkModeColors", new IntPtr(Theme.IsUsingDarkMode ? 1 : 0));
}
else
{
var size = Marshal.SizeOf(Theme.IsUsingDarkMode);
var ptr = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(Theme.IsUsingDarkMode, ptr, false);
var data = new WINDOWCOMPOSITIONATTRIBDATA
{
Attrib = WINDOWCOMPOSITIONATTRIB.WCA_USEDARKMODECOLORS,
pvData = ptr,
cbData = size
};
SetWindowCompositionAttribute(hWnd, ref data);
}
}
public static void UpdateFrame(FrmWizard frm, bool yes)
{
var extend = Theme.IsUsingDarkMode;
public class DarkMode
{
#region P/Invoke
[DllImport("uxtheme.dll", EntryPoint = "#135")]
internal static extern int SetPreferredAppMode(PreferredAppMode appMode);
[DllImport("uxtheme.dll", EntryPoint = "#135")]
internal static extern int AllowDarkModeForApp(bool allow);
[DllImport("uxtheme.dll", EntryPoint = "#133")]
internal static extern int AllowDarkModeForWindow(IntPtr handle, bool allow);
[DllImport("user32.dll")]
public static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WINDOWCOMPOSITIONATTRIBDATA data);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool SetProp(IntPtr hWnd, string lpString, IntPtr hData);
[DllImport("dwmapi.dll")]
internal static extern int DwmSetWindowAttribute(IntPtr hwnd, DWMATTRIB dwAttribute, ref int pvAttribute, int cbAttribute);
#endregion
#region Flags
internal enum PreferredAppMode
{
Default,
AllowDark,
ForceDark,
ForceLight,
Max
}
public enum WINDOWCOMPOSITIONATTRIB
{
// ...
WCA_USEDARKMODECOLORS = 26,
// ...
};
public enum DWMATTRIB
{
DWMWA_SYSTEMBACKDROP_TYPE = 38,
DWMWA_MICA_EFFECT = 1029
}
[StructLayout(LayoutKind.Sequential)]
public struct WINDOWCOMPOSITIONATTRIBDATA
{
public WINDOWCOMPOSITIONATTRIB Attrib;
public IntPtr pvData;
public int cbData;
};
#endregion
#region Public Methods
public static void RefreshTitleBarColor(IntPtr hWnd)
{
if (Environment.OSVersion.Version.Build < 18362)
{
SetProp(hWnd, "UseImmersiveDarkModeColors", new IntPtr(Theme.IsUsingDarkMode ? 1 : 0));
}
else
{
var size = Marshal.SizeOf(Theme.IsUsingDarkMode);
var ptr = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(Theme.IsUsingDarkMode, ptr, false);
var data = new WINDOWCOMPOSITIONATTRIBDATA
{
Attrib = WINDOWCOMPOSITIONATTRIB.WCA_USEDARKMODECOLORS,
pvData = ptr,
cbData = size
};
SetWindowCompositionAttribute(hWnd, ref data);
}
}
public static void UpdateFrame(FrmWizard frm, bool yes)
{
var extend = Theme.IsUsingDarkMode;

if (Environment.OSVersion.Version.Build >= 22523)
{
var micaValue = 0x02;
var tabbedvalue = 0x04;
if (extend)
{
DwmSetWindowAttribute(frm.Handle, DWMATTRIB.DWMWA_SYSTEMBACKDROP_TYPE, ref micaValue, Marshal.SizeOf(typeof(int)));
}
else
{
DwmSetWindowAttribute(frm.Handle, DWMATTRIB.DWMWA_SYSTEMBACKDROP_TYPE, ref tabbedvalue, Marshal.SizeOf(typeof(int)));
}
}
if (Environment.OSVersion.Version.Build >= 22523)
{
var micaValue = 0x02;
var tabbedvalue = 0x04;
if (extend)
{
DwmSetWindowAttribute(frm.Handle, DWMATTRIB.DWMWA_SYSTEMBACKDROP_TYPE, ref micaValue, Marshal.SizeOf(typeof(int)));
}
else
{
DwmSetWindowAttribute(frm.Handle, DWMATTRIB.DWMWA_SYSTEMBACKDROP_TYPE, ref tabbedvalue, Marshal.SizeOf(typeof(int)));
}
}

else
{
var trueValue = 0x01;
DwmSetWindowAttribute(frm.Handle, DWMATTRIB.DWMWA_MICA_EFFECT, ref trueValue, Marshal.SizeOf(typeof(int)));
}
var DarkMode = Theme.IsUsingDarkMode;
var m = new NativeMethods.MARGINS();
else
{
var trueValue = 0x01;
DwmSetWindowAttribute(frm.Handle, DWMATTRIB.DWMWA_MICA_EFFECT, ref trueValue, Marshal.SizeOf(typeof(int)));
}
var DarkMode = Theme.IsUsingDarkMode;
var m = new NativeMethods.MARGINS();

if (DarkMode)
{
m.cyTopHeight = frm.Height;
}
else
{
m.cyTopHeight = frm.tableLayoutPanel1.Height + 1;
m.cyBottomHeight = frm.tableLayoutPanel2.Height + 5;
}
if (yes)
{
if ((NativeMethods.GetUbr() != -1
&& NativeMethods.GetUbr() >= 51
&& Environment.OSVersion.Version.Build == 22000)
|| Environment.OSVersion.Version.Build is > 22000 or < 21996)
{
NativeMethods.DwmExtendFrameIntoClientArea(frm.Handle, ref m);
}
}
else
{
NativeMethods.MARGINS mar = new()
{
cxLeftWidth = 0,
cxRightWidth = 0,
cyBottomHeight = 0,
cyTopHeight = 0
};
if ((NativeMethods.GetUbr() != -1
&& NativeMethods.GetUbr() >= 51
&& Environment.OSVersion.Version.Build == 22000)
|| Environment.OSVersion.Version.Build is > 22000 or < 21996)
{
NativeMethods.DwmExtendFrameIntoClientArea(frm.Handle, ref mar);
}
}
}
#endregion
}
if (DarkMode)
{
m.cyTopHeight = frm.Height;
}
else
{
m.cyTopHeight = frm.tableLayoutPanel1.Height + 1;
m.cyBottomHeight = frm.tableLayoutPanel2.Height + 5;
}
if (yes)
{
if ((NativeMethods.GetUbr() != -1
&& NativeMethods.GetUbr() >= 51
&& Environment.OSVersion.Version.Build == 22000)
|| Environment.OSVersion.Version.Build is > 22000 or < 21996)
{
NativeMethods.DwmExtendFrameIntoClientArea(frm.Handle, ref m);
}
}
else
{
NativeMethods.MARGINS mar = new()
{
cxLeftWidth = 0,
cxRightWidth = 0,
cyBottomHeight = 0,
cyTopHeight = 0
};
if ((NativeMethods.GetUbr() != -1
&& NativeMethods.GetUbr() >= 51
&& Environment.OSVersion.Version.Build == 22000)
|| Environment.OSVersion.Version.Build is > 22000 or < 21996)
{
NativeMethods.DwmExtendFrameIntoClientArea(frm.Handle, ref mar);
}
}
}
#endregion
}
}
Loading

0 comments on commit d96fae1

Please sign in to comment.