I was most annoyed when I found that IsAppThemed and IsThemeActive do not work as expected. Instead of returning the themed status of the running application, both functions return the themed status of the system (pretty much useless for my specific requirement). After some googling, I found a posting from a fellow-MVP, Jeff Partch, who suggested calling GetModuleHandle on comctl32.dll and comparing this module handle with the handle returned by calling GetClassLongPtr on a known control handle with the GCLP_HMODULE flag. While I didn’t actually try that out, I thought it’d be easier to call DllGetVersion on comctl32.dll and check if the version is 6 or greater.
I ended up writing my IsThemed function which I have sumitted to The Code Project. Here’s the article link (with screen shots and history) :-
How to accurately detect if an application is theme-enabled?
And here’s the full function listing :-
(You’ll be wondering why I profusely used LoadLibrary/GetProcAddress. Well, I wanted to support VC++ 6 and the code now compiles on the default installation of VC++ 6, without the Platform SDK)
IsThemed
#pragma once
#include "stdafx.h"
#include <Shlwapi.h>
BOOL IsThemed()
{
BOOL ret = FALSE;
OSVERSIONINFO ovi = {0};
ovi.dwOSVersionInfoSize = sizeof ovi;
GetVersionEx(&ovi);
if(ovi.dwMajorVersion==5 && ovi.dwMinorVersion==1)
{
//Windows XP detected
typedef BOOL WINAPI ISAPPTHEMED();
typedef BOOL WINAPI ISTHEMEACTIVE();
ISAPPTHEMED* pISAPPTHEMED = NULL;
ISTHEMEACTIVE* pISTHEMEACTIVE = NULL;
HMODULE hMod = LoadLibrary(_T("uxtheme.dll"));
if(hMod)
{
pISAPPTHEMED = reinterpret_cast<ISAPPTHEMED*>(
GetProcAddress(hMod,_T("IsAppThemed")));
pISTHEMEACTIVE = reinterpret_cast<ISTHEMEACTIVE*>(
GetProcAddress(hMod,_T("IsThemeActive")));
if(pISAPPTHEMED && pISTHEMEACTIVE)
{
if(pISAPPTHEMED() && pISTHEMEACTIVE())
{
typedef HRESULT CALLBACK DLLGETVERSION(DLLVERSIONINFO*);
DLLGETVERSION* pDLLGETVERSION = NULL;
HMODULE hModComCtl = LoadLibrary(_T("comctl32.dll"));
if(hModComCtl)
{
pDLLGETVERSION = reinterpret_cast<DLLGETVERSION*>(
GetProcAddress(hModComCtl,_T("DllGetVersion")));
if(pDLLGETVERSION)
{
DLLVERSIONINFO dvi = {0};
dvi.cbSize = sizeof dvi;
if(pDLLGETVERSION(&dvi) == NOERROR )
{
ret = dvi.dwMajorVersion >= 6;
}
}
FreeLibrary(hModComCtl);
}
}
}
FreeLibrary(hMod);
}
}
return ret;
}
Read Full Post »