You are here: Home » Builder » C++ » [ En ] » Disable XP Theme…

Disable XP Theme…

13 January |

  So, you want to disable XP Theme applied on the entirely window or maybe just on a button? or any other control?

Well… say thank you to Microsoft for providing us an easy way to do that: just by calling SetWindowTheme with an empty string your control (button/checkbox/combo etc) will not be painted with the XP Theme. That is easy enough! You will find the SetWindowTheme function in UxTheme.dll which ships starting with Windows XP. So, this function will not be available in Windows 2000 (or 98), obviously you don’t even need it on win98 or win2k since windows themes was introduced starting with Windows XP. Linking statically to UxTheme.dll will make your application useless on those windows so we have to do a check for UxTheme.dll and dynamically linking if it is found:
[cpp]
void DisableXPTheme(HWND hWindow)
{

HMODULE HModUXT = NULL;
HModUXT = LoadLibrary(“UxTheme.DLL”);

if ( NULL != HModUXT ) //module not found, maybe we are not on xp or newer windows…
{
typedef HRESULT (*SetWindowThemeFunc)(HWND hwnd,LPCWSTR pszSubAppName,LPCWSTR pszSubIdList);
BOOL freeResult, runTimeLinkSuccess = FALSE;
SetWindowThemeFunc SetThemePtr = NULL;
//Get pointer to our function using GetProcAddress:
SetThemePtr = (SetWindowThemeFunc)GetProcAddress(HModUXT, “SetWindowTheme”);
// If the function address is valid, call the function.
if (runTimeLinkSuccess = (NULL != SetThemePtr))
{
(SetThemePtr)(hWindow,(wchar_t *)” “,(wchar_t *)” “);
}
//Free the library:
freeResult = FreeLibrary(HModUXT);
}
}
[/cpp]

Use the above function like this:
[cpp]

DisableXPTheme(Button1->Handle);

[/cpp]
MSDN: Using Windows XP Visual Styles

You like this post? Be the first of my friends to give me a beer! click here. Thanks!
Filed under

Builder, C++, [ En ]

| Tags:

2 Comments.

  1. Replace the (wchar_t *)” ” with NULL:
    [cpp]
    //——
    if (runTimeLinkSuccess = (NULL != SetThemePtr))
    (SetThemePtr)(hWindow,NULL,NULL);
    //——
    [/cpp]

  2. Cum mai fac sa se si revina la skin-ul de XP ? In timpul executiei programului ?