Jump to content
Tuts 4 You

Kibloy's Blog

  • entries
    7
  • comments
    19
  • views
    50,805

Bool Isappthemedthistime4real(void);

Sign in to follow this  
Killboy

1,406 views

Maybe you've been trying to find out whether an application (yours, that is) is using visual styles or not before.

While you normally know if it does or not (you added the manifest, didn't you), when writing example code or libraries for GUI stuff, it sometimes turns out to be useful to know.

I ran across such a case when I dealt with tab controls. Without visual styles tab sheets have the same background as normal dialogs whereas with visual styles enabled, the bg is white...

Have you seen the gradient on tabs used by Windows settings dialogs or .NET apps ? There's a function called EnableThemeDialogTexture that applies that background to a window.

However, if you call that function on an OS supporting visual styles in an app that does not have them enabled, it will still apply the white background. Which, as you can imagine, looks kinda gay..

Now, there is another function exported by uxtheme.dll called IsAppThemed which is actually supposed to do what it says.

Funny thing is, it always returns true on XP, on Vista they seem to have fixed it though.

So, it seems like we have to do that ourselves :D

As you might know, you have to enable visual styles with a manifest. What the manifest actually does, is linking to a certain version of comctl32.dll.

This is achieved through the so called SxS (Side by Side) directory which keeps all sorts of versions of the same dll. The manifest works like some sort of import table, you tell it the name and the version(!) of the dll to load.

The trick with visual styles is that the comctl32.dll located in system32 has version 5.x which doesn't apply any visual styles.

This is the one that gets loaded when you import it via the import table.

If you add the manifest, it will require version 6 of comctl32.dll which enables visual styles.

So, this is how we're going to check for visual styles: load comctl32.dll, call DllGetVersion and check if the major version number is above 5.

If it is, the program is using visual styles, otherwise it isn't.

If comctl32 does not export DllGetVersion we're on an OS below 2000, in that case we'll just return false because it doesn't support visual styles at all.

Otherwise, we'll check if dwMajorVersion of the DLLVERSIONINFO struct is 6 or above, if it is, visual styles are enabled.

As easy as that :D

Anyway, for the lazy ones, here's a way to implement it:

bool VisualStylesEnabled(){
HMODULE hMod;
DLLGETVERSIONPROC pDllGetVersion;
DLLVERSIONINFO DllVersion;

hMod = GetModuleHandle("comctl32.dll");
if(hMod){
pDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress(hMod, "DllGetVersion");
if(pDllGetVersion){
DllVersion.cbSize = sizeof(DLLVERSIONINFO);
if(pDllGetVersion(&DllVersion) == S_OK){
return (DllVersion.dwMajorVersion >= 6);
}
}
}
return false;
}

Be sure to add:

#include <shlwapi.h>

to the beginning of your source code, this is needed for the definition of DLLGETVERSIONPROC and DLLVERSIONINFO.

Hope this helped removing some confusion on that topic, sorry if it went the other way around :wacko:

Win32 is a bitch, if you don't like it, switch to Java or .NET or use Linux ;)

But isn't the weird stuff what makes it so unique and adorable :D

Sign in to follow this  


1 Comment


Recommended Comments

Alternatively, the lazier version, you can add this to stdafx.h

#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_IA64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif

or just the one under #else would suffice.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...