Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get information about current Windows theme in C#
public class ThemeInfo
{
private readonly string _themeName;
private readonly string _themeColor;
private readonly string _themeSize;
private readonly string _themeFileName;
public ThemeInfo(string name, string fileName, string color, string size)
{
_themeName = name;
_themeFileName = fileName;
_themeColor = color;
_themeSize = size;
}
public string ThemeFileName
{
get { return _themeFileName; }
}
public string ThemeName
{
get { return _themeName; }
}
public string ThemeColor
{
get { return _themeColor; }
}
public string ThemeSize
{
get { return _themeSize; }
}
public static ThemeInfo Current
{
get
{
var fileName = new StringBuilder(260);
var color = new StringBuilder(260);
var size = new StringBuilder(260);
int hresult = GetCurrentThemeName(fileName, fileName.Capacity, color, color.Capacity, size, size.Capacity);
if (hresult < 0)
throw Marshal.GetExceptionForHR(hresult);
string themeName = Path.GetFileNameWithoutExtension(fileName.ToString());
return new ThemeInfo(themeName, fileName.ToString(), color.ToString(), size.ToString());
}
}
[DllImport("uxtheme", CharSet = CharSet.Auto)]
private static extern int GetCurrentThemeName(
StringBuilder pszThemeFileName,
int dwMaxNameChars,
StringBuilder pszColorBuff,
int cchMaxColorChars,
StringBuilder pszSizeBuff,
int cchMaxSizeChars
);
}
@piotrby

This comment has been minimized.

Show comment
Hide comment
@piotrby

piotrby Nov 1, 2013

Exception! When current Classic Windows Theme! (windows 7 sp1 x64)

piotrby commented Nov 1, 2013

Exception! When current Classic Windows Theme! (windows 7 sp1 x64)

@EdwinHauspie

This comment has been minimized.

Show comment
Hide comment
@EdwinHauspie

EdwinHauspie Feb 28, 2017

ThemeColor is "NormalColor" .. what would you do with that? It's useless

ThemeColor is "NormalColor" .. what would you do with that? It's useless

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment