public
Last active

Get information about current Windows theme in C#

  • Download Gist
ThemeInfo.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
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
);
}

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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.