XP主题是否启用!

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

Using the code

if(IsThemed())
    m_bThemed = true;
else
    m_bThemed = false;

你可能感兴趣的:(XP主题是否启用!)