Create a gist now

Instantly share code, notes, and snippets.

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
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 commented Nov 1, 2013

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

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