Article View: borland.public.cppbuilder.nativeapi
Article #3843Re: XP Style close button on Form
From: JD
Date: Thu, 20 Apr 2006 21:36
Date: Thu, 20 Apr 2006 21:36
180 lines
8214 bytes
8214 bytes
"George P Boutwell" <lewtuobg.reverse-for-email@valleyhope.com> wrote:
>
Please wrap your lines when you post. Your editor may visually
wrap them for you but you need to enter a hard retuen at the
end of each line. If you're using a reader, look for an option
to set it's line width.
> I'm trying to manually paint an XP style close button
//-------------------------------------------------------------
#ifndef Unit2H
#define Unit2H
//-------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//-------------------------------------------------------------
#include <tmschema.h>
//-------------------------------------------------------------
typedef HANDLE HTHEME;
typedef BOOL WINAPI (*DLLISTHEMEACTIVE)();
typedef HTHEME WINAPI (*DLLOPENTHEMEDATA)( HWND, LPCWSTR );
typedef HRESULT WINAPI (*DLLDRAWTHEMEBACKGROUND)( HTHEME, HDC, int, int, const RECT*, OPTIONAL const RECT* );
typedef HRESULT WINAPI (*DLLCLOSETHEMEDATA)( HTHEME );
//-------------------------------------------------------------
class TForm2 : public TForm
{
private:
bool FCanTheme;
HINSTANCE hUxTheme;
DLLISTHEMEACTIVE IsThemeActive;
DLLOPENTHEMEDATA OpenThemeData;
DLLDRAWTHEMEBACKGROUND DrawThemeBackground;
DLLCLOSETHEMEDATA CloseThemeData;
bool __fastcall InitializeTheming();
public:
__fastcall TForm2(TComponent* Owner);
__fastcall ~TForm2();
};
//-------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
//-------------------------------------------------------------
#endif
//-------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
//-------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//-------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner) : TForm(Owner)
{
hUxTheme = NULL;
IsThemeActive = NULL;
OpenThemeData = NULL;
DrawThemeBackground = NULL;
CloseThemeData = NULL;
FCanTheme = InitializeTheming();
}
//-------------------------------------------------------------
__fastcall TForm2::~TForm2()
{
if( hUxTheme ) ::FreeLibrary( hUxTheme );
}
//-------------------------------------------------------------
bool __fastcall TForm2::InitializeTheming()
{
bool Result = false;
if( !hUxTheme )
{
hUxTheme = ::LoadLibrary( "UxTheme.dll" );
if( hUxTheme )
{
IsThemeActive = reinterpret_cast<DLLISTHEMEACTIVE>( ::GetProcAddress(hUxTheme, "IsThemeActive") );
if( IsThemeActive )
{
if( IsThemeActive() )
{
OpenThemeData = reinterpret_cast<DLLOPENTHEMEDATA> ( ::GetProcAddress(hUxTheme, "OpenThemeData" ));
DrawThemeBackground = reinterpret_cast<DLLDRAWTHEMEBACKGROUND> ( ::GetProcAddress(hUxTheme, "DrawThemeBackground" ));
CloseThemeData = reinterpret_cast<DLLCLOSETHEMEDATA> ( ::GetProcAddress(hUxTheme, "CloseThemeData" ));
if( OpenThemeData && DrawThemeBackground && CloseThemeData ) Result = true;
}
}
}
}
return Result;
}
//-------------------------------------------------------------
An example of drawing a ThemePart (small themed close button):
if( FCanTheme )
{
HTHEME hTheme = OpenThemeData( Handle, L"WINDOW" );
if( hTheme )
{
TRect R = Rect( 0, 0, ::GetSystemMetrics(SM_CXMENUSIZE), ::GetSystemMetrics(SM_CYMENUSIZE) );
// use win32 API OffsetRect to position the TRect accordlingly
DrawThemeBackground( hTheme, Canvas->Handle, WP_CLOSEBUTTON, CBS_NORMAL, &R, NULL );
CloseThemeData( hTheme );
}
else
{
// draw it un-themed
}
}
else
{
// draw it un-themed
}
If you want a normal close button, use SM_CXSIZE and SM_CYSIZE
with the calls to GetSystemMetrics when sizing the TRect. If
you want to clip the extra pixels that surround the button,
the last parameter in the call to DrawThemeBackground is a
clipping rect.
Here's a list of parts and their states for the WINDOW class.
Where no states are listed, use a one (1) for the state.:
WP_CAPTION CS_ACTIVE, CS_DISABLED, CS_INACTIVE
WP_CAPTIONSIZINGTEMPLATE
WP_CLOSEBUTTON CBS_DISABLED, CBS_HOT, CBS_NORMAL, CBS_PUSHED
WP_DIALOG
WP_FRAMEBOTTOM FS_ACTIVE, FS_INACTIVE
WP_FRAMEBOTTOMSIZINGTEMPLATE
WP_FRAMELEFT FS_ACTIVE, FS_INACTIVE
WP_FRAMELEFTSIZINGTEMPLATE
WP_FRAMERIGHT FS_ACTIVE, FS_INACTIVE
WP_FRAMERIGHTSIZINGTEMPLATE
WP_HELPBUTTON HBS_DISABLED, HBS_HOT, HBS_NORMAL, HBS_PUSHED
WP_HORZSCROLL HSS_DISABLED, HSS_HOT, HSS_NORMAL, HSS_PUSHED
WP_HORZTHUMB HTS_DISABLED, HTS_HOT, HTS_NORMAL, HTS_PUSHED
WP_MAX_BUTTON MAXBS_DISABLED, MAXBS_HOT, MAXBS_NORMAL, MAXBS_PUSHED
WP_MAXCAPTION MXCS_ACTIVE, MXCS_DISABLED, MXCS_INACTIVE
WP_MDICLOSEBUTTON CBS_DISABLED, CBS_HOT, CBS_NORMAL, CBS_PUSHED
WP_MDIHELPBUTTON HBS_DISABLED, HBS_HOT, HBS_NORMAL, HBS_PUSHED
WP_MDIMINBUTTON MINBS_DISABLED, MINBS_HOT, MINBS_NORMAL, MINBS_PUSHED
WP_MDIRESTOREBUTTON RBS_DISABLED, RBS_HOT, RBS_NORMAL, RBS_PUSHED
WP_MDISYSBUTTON SBS_DISABLED, SBS_HOT, SBS_NORMAL, SBS_PUSHED
WP_MINBUTTON MINBS_DISABLED, MINBS_HOT, MINBS_NORMAL, MINBS_PUSHED
WP_MINCAPTION MNCS_ACTIVE, MNCS_DISABLED, MNCS_INACTIVE
WP_RESTOREBUTTON RBS_DISABLED, RBS_HOT, RBS_NORMAL, RBS_PUSHED
WP_SMALLCAPTION CS_ACTIVE, CS_DISABLED, CS_INACTIVE
WP_SMALLCAPTIONSIZINGTEMPLATE
WP_SMALLCLOSEBUTTON CBS_DISABLED, CBS_HOT, CBS_NORMAL, CBS_PUSHED
WP_SMALLFRAMEBOTTOM FS_ACTIVE, FS_INACTIVE
WP_SMALLFRAMEBOTTOMSIZINGTEMPLATE
WP_SMALLFRAMELEFT FS_ACTIVE, FS_INACTIVE
WP_SMALLFRAMELEFTSIZINGTEMPLATE
WP_SMALLFRAMERIGHT FS_ACTIVE, FS_INACTIVE
WP_SMALLFRAMERIGHTSIZINGTEMPLATE
WP_SMALLHELPBUTTON HBS_DISABLED, HBS_HOT, HBS_NORMAL, HBS_PUSHED
WP_SMALLMAXBUTTON MAXBS_DISABLED, MAXBS_HOT, MAXBS_NORMAL, MAXBS_PUSHED
WP_SMALLMAXCAPTION MXCS_ACTIVE, MXCS_DISABLED, MXCS_INACTIVE
WP_SMALLMINCAPTION MNCS_ACTIVE, MNCS_DISABLED, MNCS_INACTIVE
WP_SMALLRESTOREBUTTON RBS_DISABLED, RBS_HOT, RBS_NORMAL, RBS_PUSHED
WP_SMALLSYSBUTTON SBS_DISABLED, SBS_HOT, SBS_NORMAL, SBS_PUSHED
WP_SYSBUTTON SBS_DISABLED, SBS_HOT, SBS_NORMAL, SBS_PUSHED
WP_VERTSCROLL VSS_DISABLED, VSS_HOT, VSS_NORMAL, VSS_PUSHED
WP_VERTTHUMB VTS_DISABLED, VTS_HOT, VTS_NORMAL, VTS_PUSHED
For a complete list of theme Classes, their parts and their
states, examine tmschema.h.
For a complete list of theming functions, examine uxtheme.h.
~ JD
Technical Details
Message-ID:
<4447fece$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<444789e5$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,272f8fb8ead3e236 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 Style close button on Form Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 205.188.116.136 X-Forwarded-For: 172.136.42.33 References: <444789e5$1@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <4447fece$1@newsgroups.borland.com> Date: 20 Apr 2006 14:36:14 -0700 X-Trace: newsgroups.borland.com 1145568974 207.105.83.66 (20 Apr 2006 14:36:14 -0700) Lines: 181 Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail