// This file and its .h counterpart were taken from http://www.codeproject.com [DNM 4/13/06].

/////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2001-2002 by David Yuheng Zhao
//
// Distribute and change freely, except: don't remove my name from the source 
//
// No warrantee of any kind, express or implied, is included with this
// software; use at your own risk, responsibility for damages (if any) to
// anyone resulting from the use of this software rests entirely with the
// user.
//
// Partly based on the _ThemeHelper struct in MFC7.0 source code (winctrl3.cpp), 
// and the difference is that this implementation wraps the full set of 
// visual style APIs from the platform SDK August 2001
//
// If you have any questions, I can be reached as follows:
//	yuheng_zhao@yahoo.com
//
//
// How to use:
// Instead of calling the API directly, 
//    OpenThemeData(...);
// use the global variable
//    g_xpStyle.OpenThemeData(...);
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "WindowsUtilities.h"
#include "visualstylesxp.h"


CVisualStylesXP g_xpStyle;

CVisualStylesXP::CVisualStylesXP(void)
{
	if (RunningWinXPOrVista()) {
		m_hThemeDll = LoadLibrary(_T("UxTheme.dll"));
	}
}

CVisualStylesXP::~CVisualStylesXP(void)
{
	if (RunningWinXPOrVista()) {
		if (m_hThemeDll!=NULL)
			FreeLibrary(m_hThemeDll);
		m_hThemeDll = NULL;
	}
}

BOOL CVisualStylesXP::RunningWinXPOrVista()
//
// Description:
//   Determines if we are running under Windows XP.
//	 Note this function is a duplicate of GetWindowsSystemType in GSWin.cpp.
//	 I was getting link errors from the Workspace Editor when trying to use
//	 GetWindowsSystemType because it could not include GSWin.h from the 
//	 Workspace Editor Plug-In.  Revisit for 13.
//
//	 [DNM VW 13 Revisit 6/16/06].
//
// Parameters:
//   None
//
// Returns:
//	 BOOL	- TRUE  -	if we are running Windows XP.
//			- FASLE -	otherwise.
//
// Created by Donne Martin  6/16/2006
//
{
	static ESystemType		senumSystemType		= eSysUnknown;
	static EPlatformType	senumPlatformType;

	if (senumSystemType == eSysUnknown) {

		// Set defaults.
		senumPlatformType = eWindows;
		senumSystemType = eSysWin95;
		
		OSVERSIONINFO os;
		os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
		GetVersionEx(&os);

		// get the first digit of the minor version value
		// i.e., if minor version is 10, get the value 1

		char minorVerStr[10];
		sprintf(minorVerStr, "%d", os.dwMinorVersion);
		short minorVer = minorVerStr[0] - '0';


		switch (os.dwPlatformId) {
			case VER_PLATFORM_WIN32s: {
				senumPlatformType = eWindows;
				senumSystemType = eSysWin32s;
				break;
			}
			case VER_PLATFORM_WIN32_WINDOWS: {
				senumPlatformType = eWindows;

				ASSERTN(kLewis, os.dwMajorVersion == 4);

				

				switch (minorVer) {
					case 0:
						senumSystemType = eSysWin95;
						break;
					case 1:
						senumSystemType = eSysWin98;
						break;
					case 9:
						senumSystemType = eSysWinMe;
						break;
					default:
						DSTOP((kDave, "Unknown version of Windows: %d.%d", os.dwMajorVersion, os.dwMinorVersion));
						senumSystemType = eSysWinMe;		// assume a newer version
				}
				break;
			}
			case VER_PLATFORM_WIN32_NT: {
				senumPlatformType = eWindowsNT;

				// can ignore minor version
				switch (os.dwMajorVersion) {
					case 3:
						// Not supported as of version 8
						DSTOP((kLewis, "Windows NT 3 no longer supported!\n"));
						senumSystemType = eSysWinNT3;
						break;
					case 4:
						DSTOP((kLewis, "Windows NT 4 no longer supported!\n"));
						senumSystemType = eSysWinNT4;
						break;
					case 5:
						// all flavors of Windows 2000 and XP
						switch (minorVer) {
							case 0:
								DSTOP((kLewis, "Windows 2000 no longer supported!\n"));
								senumSystemType = eSysWinNT2000;						
								break;
							case 1:
								senumSystemType = eSysWinXP;						
								break;
							case 2:
								// 64 bit XP
								senumSystemType = eSysWinXP;						
								break;
							default:
								DSTOP((kDave, "Unknown version of Windows NT: %d.%d", os.dwMajorVersion, os.dwMinorVersion));
								senumSystemType = eSysWinXP;	// assume the latest OS
						}
						break;
					case 6:
						senumSystemType = eSysWinVista;
						break;
					default:
						DSTOP((kDave, "Unknown version of Windows NT: %d.%d", os.dwMajorVersion, os.dwMinorVersion));
						senumSystemType = eSysWinVista;	// assume the latest OS
				}
				break;
			}
			default:
				DSTOP((kDave, "Encountered an unknown system type: %lu", os.dwPlatformId));
		}
	}

	return senumSystemType == eSysWinXP || senumSystemType == eSysWinVista;
}

void* CVisualStylesXP::GetProc(LPCSTR szProc, void* pfnFail)
{
	if (RunningWinXPOrVista()) {
		void* pRet = pfnFail;
		if (m_hThemeDll != NULL)
			pRet = GetProcAddress(m_hThemeDll, szProc);
		return pRet;
	}
	else {
		return pfnFail;
	}
}

HTHEME CVisualStylesXP::OpenThemeData(HWND hwnd, LPCWSTR pszClassList)
{
	if (RunningWinXPOrVista()) {
		PFNOPENTHEMEDATA pfnOpenThemeData = (PFNOPENTHEMEDATA)GetProc("OpenThemeData", (void*)OpenThemeDataFail);
		return (*pfnOpenThemeData)(hwnd, pszClassList);
	}
	else {
		return NULL;
	}
}

HRESULT CVisualStylesXP::CloseThemeData(HTHEME hTheme)
{
	if (RunningWinXPOrVista()) {
		PFNCLOSETHEMEDATA pfnCloseThemeData = (PFNCLOSETHEMEDATA)GetProc("CloseThemeData", (void*)CloseThemeDataFail);
		return (*pfnCloseThemeData)(hTheme);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::DrawThemeBackground(HTHEME hTheme, HDC hdc, 
											 int iPartId, int iStateId, const RECT *pRect, const RECT *pClipRect)
{
	if (RunningWinXPOrVista()) {
		PFNDRAWTHEMEBACKGROUND pfnDrawThemeBackground = 
			(PFNDRAWTHEMEBACKGROUND)GetProc("DrawThemeBackground", (void*)DrawThemeBackgroundFail);
		return (*pfnDrawThemeBackground)(hTheme, hdc, iPartId, iStateId, pRect, pClipRect);
	}
	else {
		return E_FAIL;
	}
}


HRESULT CVisualStylesXP::DrawThemeText(HTHEME hTheme, HDC hdc, int iPartId, 
									   int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags, 
									   DWORD dwTextFlags2, const RECT *pRect)
{
	if (RunningWinXPOrVista()) {
		PFNDRAWTHEMETEXT pfn = (PFNDRAWTHEMETEXT)GetProc("DrawThemeText", (void*)DrawThemeTextFail);
		return (*pfn)(hTheme, hdc, iPartId, iStateId, pszText, iCharCount, dwTextFlags, dwTextFlags2, pRect);
	}
	else {
		return E_FAIL;
	}
}
HRESULT CVisualStylesXP::GetThemeBackgroundContentRect(HTHEME hTheme,  HDC hdc, 
													   int iPartId, int iStateId,  const RECT *pBoundingRect, 
													   RECT *pContentRect)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMEBACKGROUNDCONTENTRECT pfn = (PFNGETTHEMEBACKGROUNDCONTENTRECT)GetProc("GetThemeBackgroundContentRect", (void*)GetThemeBackgroundContentRectFail);
		return (*pfn)(hTheme,  hdc, iPartId, iStateId,  pBoundingRect, pContentRect);
	}
	else {
		return E_FAIL;
	}
}
HRESULT CVisualStylesXP::GetThemeBackgroundExtent(HTHEME hTheme,  HDC hdc,
												  int iPartId, int iStateId, const RECT *pContentRect, 
												  RECT *pExtentRect)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMEBACKGROUNDEXTENT pfn = (PFNGETTHEMEBACKGROUNDEXTENT)GetProc("GetThemeBackgroundExtent", (void*)GetThemeBackgroundExtentFail);
		return (*pfn)(hTheme, hdc, iPartId, iStateId, pContentRect, pExtentRect);
	}
	else {
		return E_FAIL;
	}
}
HRESULT CVisualStylesXP::GetThemePartSize(HTHEME hTheme, HDC hdc, 
										  int iPartId, int iStateId, RECT * pRect, enum THEMESIZE eSize, SIZE *psz)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMEPARTSIZE pfnGetThemePartSize = 
			(PFNGETTHEMEPARTSIZE)GetProc("GetThemePartSize", (void*)GetThemePartSizeFail);
		return (*pfnGetThemePartSize)(hTheme, hdc, iPartId, iStateId, pRect, eSize, psz);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::GetThemeTextExtent(HTHEME hTheme, HDC hdc, 
											int iPartId, int iStateId, LPCWSTR pszText, int iCharCount, 
											DWORD dwTextFlags,  const RECT *pBoundingRect, 
											RECT *pExtentRect)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMETEXTEXTENT pfn = (PFNGETTHEMETEXTEXTENT)GetProc("GetThemeTextExtent", (void*)GetThemeTextExtentFail);
		return (*pfn)(hTheme, hdc, iPartId, iStateId, pszText, iCharCount, dwTextFlags,  pBoundingRect, pExtentRect);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::GetThemeTextMetrics(HTHEME hTheme,  HDC hdc, 
											 int iPartId, int iStateId,  TEXTMETRIC* ptm)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMETEXTMETRICS pfn = (PFNGETTHEMETEXTMETRICS)GetProc("GetThemeTextMetrics", (void*)GetThemeTextMetricsFail);
		return (*pfn)(hTheme, hdc, iPartId, iStateId,  ptm);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::GetThemeBackgroundRegion(HTHEME hTheme,  HDC hdc,  
												  int iPartId, int iStateId, const RECT *pRect,  HRGN *pRegion)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMEBACKGROUNDREGION pfn = (PFNGETTHEMEBACKGROUNDREGION)GetProc("GetThemeBackgroundRegion", (void*)GetThemeBackgroundRegionFail);
		return (*pfn)(hTheme, hdc, iPartId, iStateId, pRect, pRegion);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::HitTestThemeBackground(HTHEME hTheme,  HDC hdc, int iPartId, 
												int iStateId, DWORD dwOptions, const RECT *pRect,  HRGN hrgn, 
												POINT ptTest,  WORD *pwHitTestCode)
{
	if (RunningWinXPOrVista()) {
		PFNHITTESTTHEMEBACKGROUND pfn = (PFNHITTESTTHEMEBACKGROUND)GetProc("HitTestThemeBackground", (void*)HitTestThemeBackgroundFail);
		return (*pfn)(hTheme, hdc, iPartId, iStateId, dwOptions, pRect, hrgn, ptTest, pwHitTestCode);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::DrawThemeEdge(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, 
									   const RECT *pDestRect, UINT uEdge, UINT uFlags,   RECT *pContentRect)
{
	if (RunningWinXPOrVista()) {
		PFNDRAWTHEMEEDGE pfn = (PFNDRAWTHEMEEDGE)GetProc("DrawThemeEdge", (void*)DrawThemeEdgeFail);
		return (*pfn)(hTheme, hdc, iPartId, iStateId, pDestRect, uEdge, uFlags, pContentRect);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::DrawThemeIcon(HTHEME hTheme, HDC hdc, int iPartId, 
									   int iStateId, const RECT *pRect, HIMAGELIST himl, int iImageIndex)
{
	if (RunningWinXPOrVista()) {
		PFNDRAWTHEMEICON pfn = (PFNDRAWTHEMEICON)GetProc("DrawThemeIcon", (void*)DrawThemeIconFail);
		return (*pfn)(hTheme, hdc, iPartId, iStateId, pRect, himl, iImageIndex);
	}
	else {
		return E_FAIL;
	}
}

BOOL CVisualStylesXP::IsThemePartDefined(HTHEME hTheme, int iPartId, 
										 int iStateId)
{
	if (RunningWinXPOrVista()) {
		PFNISTHEMEPARTDEFINED pfn = (PFNISTHEMEPARTDEFINED)GetProc("IsThemePartDefined", (void*)IsThemePartDefinedFail);
		return (*pfn)(hTheme, iPartId, iStateId);
	}
	else {
		return FALSE;
	}
}

BOOL CVisualStylesXP::IsThemeBackgroundPartiallyTransparent(HTHEME hTheme, 
															int iPartId, int iStateId)
{
	if (RunningWinXPOrVista()) {
		PFNISTHEMEBACKGROUNDPARTIALLYTRANSPARENT pfn = (PFNISTHEMEBACKGROUNDPARTIALLYTRANSPARENT)GetProc("IsThemeBackgroundPartiallyTransparent", (void*)IsThemeBackgroundPartiallyTransparentFail);
		return (*pfn)(hTheme, iPartId, iStateId);
	}
	else {
		return FALSE;
	}
}

HRESULT CVisualStylesXP::GetThemeColor(HTHEME hTheme, int iPartId, 
									   int iStateId, int iPropId,  COLORREF *pColor)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMECOLOR pfn = (PFNGETTHEMECOLOR)GetProc("GetThemeColor", (void*)GetThemeColorFail);
		return (*pfn)(hTheme, iPartId, iStateId, iPropId, pColor);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::GetThemeMetric(HTHEME hTheme,  HDC hdc, int iPartId, 
										int iStateId, int iPropId,  int *piVal)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMEMETRIC pfn = (PFNGETTHEMEMETRIC)GetProc("GetThemeMetric", (void*)GetThemeMetricFail);
		return (*pfn)(hTheme, hdc, iPartId, iStateId, iPropId, piVal);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::GetThemeString(HTHEME hTheme, int iPartId, 
										int iStateId, int iPropId,  LPWSTR pszBuff, int cchMaxBuffChars)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMESTRING pfn = (PFNGETTHEMESTRING)GetProc("GetThemeString", (void*)GetThemeStringFail);
		return (*pfn)(hTheme, iPartId, iStateId, iPropId, pszBuff, cchMaxBuffChars);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::GetThemeBool(HTHEME hTheme, int iPartId, 
									  int iStateId, int iPropId,  BOOL *pfVal)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMEBOOL pfn = (PFNGETTHEMEBOOL)GetProc("GetThemeBool", (void*)GetThemeBoolFail);
		return (*pfn)(hTheme, iPartId, iStateId, iPropId, pfVal);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::GetThemeInt(HTHEME hTheme, int iPartId, 
									 int iStateId, int iPropId,  int *piVal)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMEINT pfn = (PFNGETTHEMEINT)GetProc("GetThemeInt", (void*)GetThemeIntFail);
		return (*pfn)(hTheme, iPartId, iStateId, iPropId, piVal);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::GetThemeEnumValue(HTHEME hTheme, int iPartId, 
										   int iStateId, int iPropId,  int *piVal)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMEENUMVALUE pfn = (PFNGETTHEMEENUMVALUE)GetProc("GetThemeEnumValue", (void*)GetThemeEnumValueFail);
		return (*pfn)(hTheme, iPartId, iStateId, iPropId, piVal);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::GetThemePosition(HTHEME hTheme, int iPartId, 
										  int iStateId, int iPropId,  POINT *pPoint)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMEPOSITION pfn = (PFNGETTHEMEPOSITION)GetProc("GetThemePosition", (void*)GetThemePositionFail);
		return (*pfn)(hTheme, iPartId, iStateId, iPropId, pPoint);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::GetThemeFont(HTHEME hTheme,  HDC hdc, int iPartId, 
									  int iStateId, int iPropId,  LOGFONT *pFont)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMEFONT pfn = (PFNGETTHEMEFONT)GetProc("GetThemeFont", (void*)GetThemeFontFail);
		return (*pfn)(hTheme, hdc, iPartId, iStateId, iPropId, pFont);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::GetThemeRect(HTHEME hTheme, int iPartId, 
									  int iStateId, int iPropId,  RECT *pRect)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMERECT pfn = (PFNGETTHEMERECT)GetProc("GetThemeRect", (void*)GetThemeRectFail);
		return (*pfn)(hTheme, iPartId, iStateId, iPropId, pRect);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::GetThemeMargins(HTHEME hTheme,  HDC hdc, int iPartId, 
										 int iStateId, int iPropId,  RECT *prc,  MARGINS *pMargins)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMEMARGINS pfn = (PFNGETTHEMEMARGINS)GetProc("GetThemeMargins", (void*)GetThemeMarginsFail);
		return (*pfn)(hTheme, hdc, iPartId, iStateId, iPropId, prc, pMargins);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::GetThemeIntList(HTHEME hTheme, int iPartId, 
										 int iStateId, int iPropId,  INTLIST *pIntList)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMEINTLIST pfn = (PFNGETTHEMEINTLIST)GetProc("GetThemeIntList", (void*)GetThemeIntListFail);
		return (*pfn)(hTheme, iPartId, iStateId, iPropId, pIntList);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::GetThemePropertyOrigin(HTHEME hTheme, int iPartId, 
												int iStateId, int iPropId,  enum PROPERTYORIGIN *pOrigin)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMEPROPERTYORIGIN pfn = (PFNGETTHEMEPROPERTYORIGIN)GetProc("GetThemePropertyOrigin", (void*)GetThemePropertyOriginFail);
		return (*pfn)(hTheme, iPartId, iStateId, iPropId, pOrigin);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::SetWindowTheme(HWND hwnd, LPCWSTR pszSubAppName, 
										LPCWSTR pszSubIdList)
{
	if (RunningWinXPOrVista()) {
		PFNSETWINDOWTHEME pfn = (PFNSETWINDOWTHEME)GetProc("SetWindowTheme", (void*)SetWindowThemeFail);
		return (*pfn)(hwnd, pszSubAppName, pszSubIdList);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::GetThemeFilename(HTHEME hTheme, int iPartId, 
										  int iStateId, int iPropId,  LPWSTR pszThemeFileName, int cchMaxBuffChars)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMEFILENAME pfn = (PFNGETTHEMEFILENAME)GetProc("GetThemeFilename", (void*)GetThemeFilenameFail);
		return (*pfn)(hTheme, iPartId, iStateId, iPropId,  pszThemeFileName, cchMaxBuffChars);
	}
	else {
		return E_FAIL;
	}
}

COLORREF CVisualStylesXP::GetThemeSysColor(HTHEME hTheme, int iColorId)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMESYSCOLOR pfn = (PFNGETTHEMESYSCOLOR)GetProc("GetThemeSysColor", (void*)GetThemeSysColorFail);
		return (*pfn)(hTheme, iColorId);
	}
	else {
		return 0;
	}
}

HBRUSH CVisualStylesXP::GetThemeSysColorBrush(HTHEME hTheme, int iColorId)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMESYSCOLORBRUSH pfn = (PFNGETTHEMESYSCOLORBRUSH)GetProc("GetThemeSysColorBrush", (void*)GetThemeSysColorBrushFail);
		return (*pfn)(hTheme, iColorId);
	}
	else {
		return NULL;
	}
}

BOOL CVisualStylesXP::GetThemeSysBool(HTHEME hTheme, int iBoolId)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMESYSBOOL pfn = (PFNGETTHEMESYSBOOL)GetProc("GetThemeSysBool", (void*)GetThemeSysBoolFail);
		return (*pfn)(hTheme, iBoolId);
	}
	else {
		return FALSE;
	}
}

int CVisualStylesXP::GetThemeSysSize(HTHEME hTheme, int iSizeId)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMESYSSIZE pfn = (PFNGETTHEMESYSSIZE)GetProc("GetThemeSysSize", (void*)GetThemeSysSizeFail);
		return (*pfn)(hTheme, iSizeId);
	}
	else {
		return 0;
	}
}

HRESULT CVisualStylesXP::GetThemeSysFont(HTHEME hTheme, int iFontId,  LOGFONT *plf)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMESYSFONT pfn = (PFNGETTHEMESYSFONT)GetProc("GetThemeSysFont", (void*)GetThemeSysFontFail);
		return (*pfn)(hTheme, iFontId, plf);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::GetThemeSysString(HTHEME hTheme, int iStringId, 
										   LPWSTR pszStringBuff, int cchMaxStringChars)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMESYSSTRING pfn = (PFNGETTHEMESYSSTRING)GetProc("GetThemeSysString", (void*)GetThemeSysStringFail);
		return (*pfn)(hTheme, iStringId, pszStringBuff, cchMaxStringChars);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::GetThemeSysInt(HTHEME hTheme, int iIntId, int *piValue)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMESYSINT pfn = (PFNGETTHEMESYSINT)GetProc("GetThemeSysInt", (void*)GetThemeSysIntFail);
		return (*pfn)(hTheme, iIntId, piValue);
	}
	else {
		return E_FAIL;
	}
}

BOOL CVisualStylesXP::IsThemeActive()
{
	if (RunningWinXPOrVista()) {
		PFNISTHEMEACTIVE pfn = (PFNISTHEMEACTIVE)GetProc("IsThemeActive", (void*)IsThemeActiveFail);
		return (*pfn)();
	}
	else {
		return FALSE;
	}
}

BOOL CVisualStylesXP::IsAppThemed()
{
	if (RunningWinXPOrVista()) {
		PFNISAPPTHEMED pfnIsAppThemed = (PFNISAPPTHEMED)GetProc("IsAppThemed", (void*)IsAppThemedFail);
		return (*pfnIsAppThemed)();
	}
	else {
		return FALSE;
	}
}

HTHEME CVisualStylesXP::GetWindowTheme(HWND hwnd)
{
	if (RunningWinXPOrVista()) {
		PFNGETWINDOWTHEME pfn = (PFNGETWINDOWTHEME)GetProc("GetWindowTheme", (void*)GetWindowThemeFail);
		return (*pfn)(hwnd);
	}
	else {
		return NULL;
	}
}

HRESULT CVisualStylesXP::EnableThemeDialogTexture(HWND hwnd, DWORD dwFlags)
{
	if (RunningWinXPOrVista()) {
		PFNENABLETHEMEDIALOGTEXTURE pfn = (PFNENABLETHEMEDIALOGTEXTURE)GetProc("EnableThemeDialogTexture", (void*)EnableThemeDialogTextureFail);
		return (*pfn)(hwnd, dwFlags);
	}
	else {
		return E_FAIL;
	}
}

BOOL CVisualStylesXP::IsThemeDialogTextureEnabled(HWND hwnd)
{
	if (RunningWinXPOrVista()) {
		PFNISTHEMEDIALOGTEXTUREENABLED pfn = (PFNISTHEMEDIALOGTEXTUREENABLED)GetProc("IsThemeDialogTextureEnabled", (void*)IsThemeDialogTextureEnabledFail);
		return (*pfn)(hwnd);
	}
	else {
		return FALSE;
	}
}

DWORD CVisualStylesXP::GetThemeAppProperties()
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMEAPPPROPERTIES pfn = (PFNGETTHEMEAPPPROPERTIES)GetProc("GetThemeAppProperties", (void*)GetThemeAppPropertiesFail);
		return (*pfn)();
	}
	else {
		return 0;
	}
}

void CVisualStylesXP::SetThemeAppProperties(DWORD dwFlags)
{
	if (RunningWinXPOrVista()) {
		PFNSETTHEMEAPPPROPERTIES pfn = (PFNSETTHEMEAPPPROPERTIES)GetProc("SetThemeAppProperties", (void*)SetThemeAppPropertiesFail);
		(*pfn)(dwFlags);
	}
}

HRESULT CVisualStylesXP::GetCurrentThemeName(
	LPWSTR pszThemeFileName, int cchMaxNameChars, 
	LPWSTR pszColorBuff, int cchMaxColorChars,
	LPWSTR pszSizeBuff, int cchMaxSizeChars)
{
	if (RunningWinXPOrVista()) {
		PFNGETCURRENTTHEMENAME pfn = (PFNGETCURRENTTHEMENAME)GetProc("GetCurrentThemeName", (void*)GetCurrentThemeNameFail);
		return (*pfn)(pszThemeFileName, cchMaxNameChars, pszColorBuff, cchMaxColorChars, pszSizeBuff, cchMaxSizeChars);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::GetThemeDocumentationProperty(LPCWSTR pszThemeName,
													   LPCWSTR pszPropertyName,  LPWSTR pszValueBuff, int cchMaxValChars)
{
	if (RunningWinXPOrVista()) {
		PFNGETTHEMEDOCUMENTATIONPROPERTY pfn = (PFNGETTHEMEDOCUMENTATIONPROPERTY)GetProc("GetThemeDocumentationProperty", (void*)GetThemeDocumentationPropertyFail);
		return (*pfn)(pszThemeName, pszPropertyName, pszValueBuff, cchMaxValChars);
	}
	else {
		return E_FAIL;
	}
}


HRESULT CVisualStylesXP::DrawThemeParentBackground(HWND hwnd, HDC hdc,  RECT* prc)
{
	if (RunningWinXPOrVista()) {
		PFNDRAWTHEMEPARENTBACKGROUND pfn = (PFNDRAWTHEMEPARENTBACKGROUND)GetProc("DrawThemeParentBackground", (void*)DrawThemeParentBackgroundFail);
		return (*pfn)(hwnd, hdc, prc);
	}
	else {
		return E_FAIL;
	}
}

HRESULT CVisualStylesXP::EnableTheming(BOOL fEnable)
{
	if (RunningWinXPOrVista()) {
		PFNENABLETHEMING pfn = (PFNENABLETHEMING)GetProc("EnableTheming", (void*)EnableThemingFail);
		return (*pfn)(fEnable);
	}
	else {
		return E_FAIL;
	}
}
