Article View: borland.public.cppbuilder.nativeapi
Article #5430Re: XP Theming
From: JD
Date: Wed, 24 Aug 2005 21:08
Date: Wed, 24 Aug 2005 21:08
117 lines
6105 bytes
6105 bytes
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>> if it is, then why would it accept the handle from AllocateHWnd?
> I cannot answer that because you have yet to show your
> actual code like I asked you to.
I thought you wanted to see what code didn't work.
In the main form's ctor:
TMyComponent *pComponent = new TMyComponent( this );
if( pComponent->Succeeded ) ShowMessage("Determing Theming Succeeded.");
else ShowMessage(pComponent->ThemeError);
//-------------------------------------------------------------
#ifndef Unit2H
#define Unit2H
//-------------------------------------------------------------
#include <Classes.hpp>
#include <shlwapi.h>
//-------------------------------------------------------------
class TMyComponent : public TComponent
{
protected:
virtual void __fastcall WndProc( TMessage &Message );
private:
HWND FHandle;
bool FSucceeded;
AnsiString FThemeError;
public:
__fastcall TMyComponent(TComponent* Owner);
__fastcall ~TMyComponent();
__property bool Succeeded = { read = FSucceeded };
__property AnsiString ThemeError = { read = FThemeError };
};
//-------------------------------------------------------------
#endif
//-------------------------------------------------------------
#include <basepch.h>
#pragma hdrstop
#include "Unit2.h"
#pragma package(smart_init)
//-------------------------------------------------------------
__fastcall TMyComponent::TMyComponent(TComponent* Owner) : TComponent(Owner)
{
FSucceeded = false;
FThemeError = "";
FHandle = NULL;
if( !ComponentState.Contains(csDesigning) )
{
FHandle = AllocateHWnd( WndProc );
WORD MajorVersion = 0;
HINSTANCE hComCtl32 = ::LoadLibrary( "ComCtl32.dll" );
if( hComCtl32 )
{
DLLGETVERSIONPROC lpDllGetVersion = (DLLGETVERSIONPROC) ::GetProcAddress( hComCtl32, "DllGetVersion" );
if( lpDllGetVersion )
{
DLLVERSIONINFO dvi = { sizeof(DLLVERSIONINFO), 0 };
if( SUCCEEDED(lpDllGetVersion(&dvi)) ) MajorVersion = dvi.dwMajorVersion;
}
::FreeLibrary( hComCtl32 );
}
else FThemeError = "LoadLibrary::ComCtl32 Failed.";
if( MajorVersion > 5 )
{
HINSTANCE hUxTheme = ::LoadLibrary( "UxTheme.dll" );
if( hUxTheme )
{
typedef BOOL WINAPI (*DLLISTHEMEACTIVE)();
DLLISTHEMEACTIVE IsThemeActive = (DLLISTHEMEACTIVE) ::GetProcAddress( hUxTheme, "IsThemeActive" );
if( IsThemeActive )
{
if( IsThemeActive() )
{
typedef HANDLE HTHEME; typedef HTHEME WINAPI (*DLLOPENTHEMEDATA)(HWND, LPCWSTR ); DLLOPENTHEMEDATA OpenThemeData = (DLLOPENTHEMEDATA) ::GetProcAddress( hUxTheme, "OpenThemeData" );
if( OpenThemeData )
{
HTHEME hTheme = OpenThemeData(FHandle, L"Button");
if( hTheme )
{
typedef HRESULT WINAPI (*DLLCLOSETHEMEDATA)( HTHEME ); DLLCLOSETHEMEDATA CloseThemeData = (DLLCLOSETHEMEDATA) ::GetProcAddress( hUxTheme, "CloseThemeData" );
if( CloseThemeData ) { CloseThemeData( hTheme ); FSucceeded = true; } else FThemeError = "GetProcAddress::CloseThemeData failed.";
}
else FThemeError.sprintf("Call to OpenThemeData failed.\nGetLastError : %u\n\t\t\t0x%08X\nSysErrorMessage : %s", ::GetLastError(), ::GetLastError(), SysErrorMessage(::GetLastError()) );
}
else FThemeError = "GetProcAddress::OpenThemeData failed.";
}
else FThemeError = "Theming is not active.";
}
else FThemeError = "GetProcAddress::IsThemeActive failed.";
::FreeLibrary( hUxTheme );
}
else FThemeError = "LoadLibrary::UxTheme failed.";
}
else FThemeError.sprintf("ComCtl32 Major Version too small : %d.", MajorVersion);
}
}
//-------------------------------------------------------------
__fastcall TMyComponent::~TMyComponent()
{
if( FHandle ) DeallocateHWnd( FHandle );
}
//-------------------------------------------------------------
void __fastcall TMyComponent::WndProc( TMessage &Message )
{
Message.Result = DefWindowProc( FHandle, Message.Msg, Message.WParam, Message.LParam );
}
//-------------------------------------------------------------
~ JD
Technical Details
Message-ID:
<430ce1b2$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!newsread.com!news-xfer.newsread.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<430cb5d9$1@newsgroups.borland.com> <430cc947$1@newsgroups.borland.com> <430cd1e4$1@newsgroups.borland.com> <430cda41$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,155e299ff335af68 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "JD" <nospam@nospam.com> Sender: "JD" <nospam@nospam.com> Reply-To: "JD" <nospam@nospam.com> Subject: Re: XP Theming Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 64.12.117.6 X-Forwarded-For: 172.175.236.167 References: <430cb5d9$1@newsgroups.borland.com> <430cc947$1@newsgroups.borland.com> <430cd1e4$1@newsgroups.borland.com> <430cda41$1@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <430ce1b2$1@newsgroups.borland.com> Date: 24 Aug 2005 14:08:02 -0700 X-Trace: newsgroups.borland.com 1124917682 207.105.83.66 (24 Aug 2005 14:08:02 -0700) Lines: 118 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!newsread.com!news-xfer.newsread.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail