Skip to content

Commit

Permalink
Add UxTheme.GetCurrentThemeName
Browse files Browse the repository at this point in the history
  • Loading branch information
RussKie committed Mar 5, 2021
1 parent cb16302 commit 7292ad2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
23 changes: 23 additions & 0 deletions src/Tests/WInterop.Tests/Theming/ThemesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Jeremy W. Kuhne. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using FluentAssertions;
using WInterop.Windows;
using Xunit;

namespace WindowsTests
{
public class ThemesTests
{
[Fact]
public unsafe void GetCurrentThemeName()
{
string themeName = Themes.GetCurrentThemeName();

// Name would be something like: C:\WINDOWS\resources\themes\Aero\Aero.msstyles

themeName.Length.Should().BeGreaterThan(0);
themeName.Should().EndWith(".msstyles");
}
}
}
20 changes: 15 additions & 5 deletions src/WInterop.Desktop/Windows/Native/WindowsImports.UxTheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ namespace WInterop.Windows.Native
{
public static partial class WindowsImports
{
// https://docs.microsoft.com/windows/win32/api/uxtheme/nf-uxtheme-closethemedata
[DllImport(Libraries.UxTheme, ExactSpelling = true)]
public static extern HResult CloseThemeData(
HTHEME hTheme);

// https://docs.microsoft.com/windows/win32/api/uxtheme/nf-uxtheme-getcurrentthemename
[DllImport(Libraries.UxTheme, ExactSpelling = true)]
public static unsafe extern HResult GetCurrentThemeName(
char* pszThemeFileName,
int cchMaxNameChars,
char* pszColorBuff,
int cchMaxColorChars,
char* pszSizeBuff,
int cchMaxSizeChars);

// https://docs.microsoft.com/windows/win32/api/uxtheme/nf-uxtheme-isappthemed
[SuppressGCTransition]
[DllImport(Libraries.UxTheme, ExactSpelling = true)]
Expand Down Expand Up @@ -38,10 +53,5 @@ public static unsafe extern HTHEME OpenThemeDataEx(
HWND hwnd,
char* pszClassList,
uint dwFlags);

// https://docs.microsoft.com/windows/win32/api/uxtheme/nf-uxtheme-closethemedata
[DllImport(Libraries.UxTheme, ExactSpelling = true)]
public static extern HResult CloseThemeData(
HTHEME hTheme);
}
}
20 changes: 11 additions & 9 deletions src/WInterop.Desktop/Windows/Windows.Theming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Buffers;
using System.Drawing;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using WInterop.Errors;
using WInterop.Gdi;
using WInterop.Globalization;
using WInterop.Modules;
using WInterop.Support;
using WInterop.Support.Buffers;
using WInterop.Windows.Native;

namespace WInterop.Windows
{
public static partial class Windows
{
public static unsafe string GetCurrentThemeName()
{
Span<char> themeName = stackalloc char[Paths.MaxPath];
fixed (char* theme = themeName)
{
WindowsImports.GetCurrentThemeName(theme, Paths.MaxPath, null, 0, null, 0).ThrowIfFailed();
}

return themeName.SliceAtNull().ToString();
}

public static bool IsAppThemed() => WindowsImports.IsAppThemed();

public static bool IsCompositionActive() => WindowsImports.IsCompositionActive();
Expand Down

0 comments on commit 7292ad2

Please sign in to comment.