IsAppThemed and IsThemeActive just don't work

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;
}
Advertisements

3 thoughts on “IsAppThemed and IsThemeActive just don't work

  1. Great code! It works. Here is a Delphi version that I made up based on your code and a general dllget version post by Jamie Frater that I found somewhere.

    function isApplicationThemed: boolean;
    var
    IEHandle : THandle;
    DllGetVersion: function(dvi: PDLLVerInfo): PDLLVerInfo; stdcall;
    p:pDLLVerInfo;
    begin
    result := isAppThemed and isthemeactive;
    if not result then
    exit;
    IEHandle := LoadLibrary(‘comctl32.dll’);
    if IEHandle = 0 then // shdocvw doesn’t exist
    begin
    result := false;
    end
    else
    begin // shdocvw exists
    try
    new(p);
    ZeroMemory(p, sizeof(p^));
    p^.cbSize := sizeof(p^);
    @DllGetVersion := GetProcAddress(IEHandle,’DllGetVersion’);
    DllGetVersion(p);
    if p^.dwMajorVersion

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s