Skip to content

Instantly share code, notes, and snippets.

@thomaslevesque
Created September 6, 2012 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomaslevesque/3653097 to your computer and use it in GitHub Desktop.
Save thomaslevesque/3653097 to your computer and use it in GitHub Desktop.
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
);
}
@peter13th
Copy link

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

@EdwinHauspie
Copy link

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