Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Disabling theming for VCL's

14 views
Skip to first unread message

Mike Collins

unread,
Aug 2, 2008, 6:34:43 PM8/2/08
to
Hay guys, I've got a little problem that i thought i had fixed but it's
coming back to kick me.

I have a GUI that is built along the lines of MS OneCare / WinDefender. We
use a TImage streatched across the main form and load a JPEG background to
create a graphical backdrop.

At the top of the form i have a toolbar that is created with a transparent
background, using the TCoolBar. This system all works ok on < XP i.e. my
toolbar appears transparent over the image.

However, on XP, when theming is enabled, my toolbar looks crap i.e. when the
user mouses-over, the buttons are painted with a gray background instead of
the image background. I tried to resolve this by disabling theming for the
TToolbar / TCoolbar using some code that i *found*, and it seemed to work.
However, the system frequently falls over and the toolbar reverts to being
painted as is. The code i'm using looks like this,

void TUtilities::DisableXPTheme(HWND p_hWindow)
{
bool bFreeLib = false;
HINSTANCE hUxThemeDLL = NULL;

// See if UxTheme.dll is already loaded, it it is, use it's handle
hUxThemeDLL = GetModuleHandle("UxTheme.dll");
if (!hUxThemeDLL)
{
// If it's not loaded, call LoadLibrary() - must unload the dll once
it is finished
hUxThemeDLL = LoadLibrary("UxTheme.dll");
bFreeLib = true;
}

if (hUxThemeDLL)
{
TSetWindowTheme SetWindowTheme = NULL;
SetWindowTheme = (TSetWindowTheme)GetProcAddress(hUxThemeDLL,
"SetWindowTheme");
if (SetWindowTheme)
{
(SetWindowTheme)(p_hWindow, (wchar_t *)" ", (wchar_t *)" ");
}

//Free the library:
if (bFreeLib)
{
FreeLibrary(hUxThemeDLL);
hUxThemeDLL = NULL;
}
}
}

and i'm calling it from the OnShow like this:

Utils->DisableXPTheme(clbCoolBar->Handle);
Utils->DisableXPTheme(tlbMain->Handle);


has anyone got any suggestions?

Best regards

Mike


Remy Lebeau (TeamB)

unread,
Aug 4, 2008, 1:11:15 PM8/4/08
to

"Mike Collins" <its@TheBottomOfThePost> wrote in message
news:4894...@newsgroups.borland.com...

> We use a TImage streatched across the main form and load
> a JPEG background to create a graphical backdrop.

I would suggest using the form's OnPaint event for that instead.

> However, the system frequently falls over and the toolbar reverts
> to being painted as is.

The toolbar's HWND is likely be recreated in response to some action. Every
time a new HWND is created, you will have to call SetWindowTheme() again.

> // See if UxTheme.dll is already loaded, it it is, use it's handle

That is redundant. LoadLibrary() already does that for you. DLLs are
reference counted. If the DLL is already loaded, LoadLibrary() will simply
increment its reference count, not reload it anew. The DLL is not freed
until its reference count falls to 0.

> (SetWindowTheme)(p_hWindow, (wchar_t *)" ", (wchar_t *)" ");

You can't cast a char* to a wchar_t* like that. If you need to use a
wchar_t* literal, then prefix it with an 'L' instead:

(SetWindowTheme)(p_hWindow, L" ", L" ");

BTW, you did not say which version of BCB you are using? If BCB2006 or
later, then the VCL has native support for UxTheme.dll, so you don't have to
access it manually. It also has ways of controlling when theming should be
active or not for any given control.


Gambit


mikecol...@googlemail.com

unread,
Aug 12, 2008, 11:11:40 AM8/12/08
to
where have all the news groups gone?

I've been away for a week and everyone has disapeared.

Anyway - thats for the reply remy (not sure if this post will appear)
- any suggestions on how i can detect when the ttoolbar's WHND is
created / recreated?

Many thanks,

Mike

0 new messages