Last active
April 23, 2023 05:27
-
-
Save Trumeet/e5c4f35267464366aa6cd98b24e61346 to your computer and use it in GitHub Desktop.
Enable Aero style on Windows 10.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Windows.Forms; | |
using System.Runtime.InteropServices; | |
using System.Drawing; | |
/// <summary> | |
/// Enable Aero style on Windows 10. | |
/// Refrences: | |
/// https://gist.github.com/ysc3839/b08d2bff1c7dacde529bed1d37e85ccf, | |
/// https://gist.github.com/riverar/fd6525579d6bbafc6e48, | |
/// https://www.kechuang.org/t/79675 | |
/// http://msdn.microsoft.com/en-us/library/ms748975.aspx | |
/// http://www.codeproject.com/KB/vista/AeroGlassForms.aspx | |
/// StackOverflow | |
/// Don't ask me ANY questions about this because I do NOT understand C#, lol. | |
/// </summary> | |
namespace AeroDemo | |
{ | |
class MainForm : Form | |
{ | |
[STAThread] | |
static void Main() | |
{ | |
Application.EnableVisualStyles(); | |
Application.SetCompatibleTextRenderingDefault(false); | |
Application.Run(new MainForm()); | |
} | |
public MainForm() | |
{ | |
// this.ShowIcon = false; | |
// SetStyle(ControlStyles.SupportsTransparentBackColor, true); | |
this.BackColor = Color.Black; | |
// this.TransparencyKey = Color.LimeGreen; | |
this.MaximizeBox = false; | |
this.FormBorderStyle = FormBorderStyle.FixedDialog; | |
} | |
protected override void OnLoad(EventArgs e) | |
{ | |
base.OnLoad(e); | |
MARGINS margins = new MARGINS(); | |
margins.Top = Height; | |
margins.Left = Left; | |
Console.WriteLine("SetAero: 7 = {0}, 10 = {1}", | |
DllHelper.SetAero7(this.Handle, margins), | |
DllHelper.SetAero10(this.Handle)); | |
} | |
} | |
public static class DllHelper | |
{ | |
[DllImport("user32.dll")] | |
internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data); | |
[DllImport("DwmApi.dll")] | |
public static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS pMarInset); | |
public static int SetAero10(IntPtr hwnd) | |
{ | |
AccentPolicy accentPolicy = new AccentPolicy | |
{ | |
AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND, | |
AccentFlags = 0, | |
GradientColor = 0, | |
AnimationId = 0 | |
}; | |
WindowCompositionAttributeData data = new WindowCompositionAttributeData | |
{ | |
Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY | |
}; | |
int accentSize = Marshal.SizeOf(accentPolicy); | |
IntPtr accentPtr = Marshal.AllocHGlobal(accentSize); | |
Marshal.StructureToPtr(accentPolicy, accentPtr, false); | |
data.Data = accentPtr; | |
data.SizeOfData = accentSize; | |
int result = SetWindowCompositionAttribute(hwnd, ref data); | |
Marshal.FreeHGlobal(accentPtr); | |
return result; | |
} | |
public static int SetAero7(IntPtr mainWindowPtr, MARGINS margins) | |
{ | |
return DwmExtendFrameIntoClientArea(mainWindowPtr, ref margins); | |
} | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
internal struct WindowCompositionAttributeData | |
{ | |
public WindowCompositionAttribute Attribute; | |
public IntPtr Data; | |
public int SizeOfData; | |
} | |
internal enum WindowCompositionAttribute | |
{ | |
WCA_UNDEFINED = 0, | |
WCA_NCRENDERING_ENABLED = 1, | |
WCA_NCRENDERING_POLICY = 2, | |
WCA_TRANSITIONS_FORCEDISABLED = 3, | |
WCA_ALLOW_NCPAINT = 4, | |
WCA_CAPTION_BUTTON_BOUNDS = 5, | |
WCA_NONCLIENT_RTL_LAYOUT = 6, | |
WCA_FORCE_ICONIC_REPRESENTATION = 7, | |
WCA_EXTENDED_FRAME_BOUNDS = 8, | |
WCA_HAS_ICONIC_BITMAP = 9, | |
WCA_THEME_ATTRIBUTES = 10, | |
WCA_NCRENDERING_EXILED = 11, | |
WCA_NCADORNMENTINFO = 12, | |
WCA_EXCLUDED_FROM_LIVEPREVIEW = 13, | |
WCA_VIDEO_OVERLAY_ACTIVE = 14, | |
WCA_FORCE_ACTIVEWINDOW_APPEARANCE = 15, | |
WCA_DISALLOW_PEEK = 16, | |
WCA_CLOAK = 17, | |
WCA_CLOAKED = 18, | |
WCA_ACCENT_POLICY = 19, | |
WCA_FREEZE_REPRESENTATION = 20, | |
WCA_EVER_UNCLOAKED = 21, | |
WCA_VISUAL_OWNER = 22, | |
WCA_HOLOGRAPHIC = 23, | |
WCA_EXCLUDED_FROM_DDA = 24, | |
WCA_PASSIVEUPDATEMODE = 25, | |
WCA_LAST = 26 | |
} | |
internal enum AccentState | |
{ | |
ACCENT_DISABLED = 0, | |
ACCENT_ENABLE_GRADIENT = 1, | |
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2, | |
ACCENT_ENABLE_BLURBEHIND = 3, | |
ACCENT_ENABLE_ACRYLICBLURBEHIND = 4, // RS4 1803 | |
ACCENT_ENABLE_HOSTBACKDROP = 5, // RS5 1809 | |
ACCENT_INVALID_STATE = 6 | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
internal struct AccentPolicy | |
{ | |
public AccentState AccentState; | |
public int AccentFlags; | |
public int GradientColor; | |
public int AnimationId; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
public struct MARGINS | |
{ | |
public int Left; | |
public int Right; | |
public int Top; | |
public int Bottom; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment