Board index » cppbuilder » TThemeManager

TThemeManager


2004-02-27 06:24:07 PM
cppbuilder18
Hi,
I'm using TThemeManager from Mike Lischke. What I want is the Captionfont in
WinXP when a Theme in XP is selected.
I'm using the function :
NONCLIENTMETRICS theMetrics;
theMetrics.cbSize = sizeof(NONCLIENTMETRICS);
if
(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,sizeof(NONCLIENTMETRICS),&th
eMetrics,0))
fntCaption->Handle=CreateFontIndirect(&theMetrics.lfCaptionFont);
But it don't look like the Caption font. Can someone tell me how to get the
right font.
Regards,
Bart
 
 

Re:TThemeManager

Hi,
I'm using TThemeManager from Mike Lischke. What I want is the Captionfont in
WinXP when a Theme in XP is selected.
I'm using the function :
NONCLIENTMETRICS theMetrics;
theMetrics.cbSize = sizeof(NONCLIENTMETRICS);
if
(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,sizeof(NONCLIENTMETRICS),&th
eMetrics,0))
fntCaption->Handle=CreateFontIndirect(&theMetrics.lfCaptionFont);
But it don't look like the Caption font. Can someone tell me how to get the
right font.
Regards,
Bart
 

Re:TThemeManager

On 27/02/2004 12:24:07, Bart Huls wrote:
Quote
I'm using TThemeManager from Mike Lischke. What I want is the
Captionfont in WinXP when a Theme in XP is selected.
I'm using the function :

(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,sizeof(NONCLIENTMETR
ICS),&th eMetrics,0))
Works for me. However, you can use the theme functions to get the
caption font. Call the GetThemeSysFont, passing 0 for the theme
handle and TMT_CAPTIONFONT for the font ID.
Note that the function may be incorrectly defined to expect a LOGFONT
struct. It actually expects a LOGFONTW struct. You can then create
the font handle using CreateFontIndirectW.
The following Delphi code demostrates this:
function CreateCaptionFont: TFont;
var
NCMetrics: TNonClientMetrics;
LFont: TLogFontW;
begin
Result := nil;
if ThemeServices.ThemesEnabled then
begin
if GetThemeSysFont(0, TMT_CAPTIONFONT,
PLogFont(@LFont)^) = S_OK then
begin
Result := TFont.Create;
Result.Handle := CreateFontIndirectW(LFont);
end;
end else
begin
FillChar(NCMetrics, SizeOf(NCMetrics), 0);
NCMetrics.cbSize := SizeOf(NCMetrics);
if SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
SizeOf(NCMetrics), @NCMetrics, 0) then
begin
Result := TFont.Create;
Result.Handle := CreateFontIndirect(NCMetrics.lfCaptionFont);
end;
end;
end;
--
Yorai Aminov (TeamB)
(TeamB cannot answer questions received via email.)
Shorter Path - www.shorterpath.com
Yorai's Page - www.yoraispage.com
 

{smallsort}

Re:TThemeManager

"Bart Huls" < XXXX@XXXXX.COM >wrote in message
Quote
Can someone tell me how to get the right font.
If XP Themes are enabled, try calling GetThemeFont() instead of
SystemParameterInfo().
Gambit
 

Re:TThemeManager

Hi Yorai,
I'm using Borland C++ Builder 5 with Mike Lischke Theme Components.
When I'm tryuing to use the GetThemeSysFont function it gives me an
unresolved external Linker error
Bart
 

Re:TThemeManager

Bart Huls wrote:
Quote
Hi Yorai,

I'm using Borland C++ Builder 5 with Mike Lischke Theme Components.
When I'm tryuing to use the GetThemeSysFont function it gives me an
unresolved external Linker error
Does it have a const argument ?
If yes, and if you have the sources for ThemeManager, remove the const
specifier, recompile the packages, and everything should work again.
 

Re:TThemeManager

Hi Remy,
I have tried to use the GetThemeFont or the GetThemeSysFont functions only
the compiler gives me unresolved external errors on both funtcions.
Bart
 

Re:TThemeManager

"Bart Huls" < XXXX@XXXXX.COM >wrote in message
Quote
I have tried to use the GetThemeFont or the GetThemeSysFont
functions only the compiler gives me unresolved external errors
on both funtcions.
If you intend for your program to run on systems other than XP, then you
will have to obtain pointers to the functions dynamically at runtime using
LoadLibrary() and GetProcAddress(). They are available from UxTheme.dll.
If you are targetting XP solely, then simply add UxTheme.lib to your project
instead. You can use Borland's IMPLIB utility to generate UxTheme.lib from
UxTheme.dll.
Gambit
 

Re:TThemeManager

Hi Remy,
The problem is that I'm developing On Windows 2000 with Borland C++ Builder
5.
An UxTheme.dll or UxTheme.lib is not available for me. I tried to use the
UxTheme.pas from Mike Lischke but there must be something wrong with the
source that it does not export correctly the functions. (Notice: Pascal is
not my best language...)
Bart
 

Re:TThemeManager

"Bart Huls" < XXXX@XXXXX.COM >wrote in message
Quote
The problem is that I'm developing On Windows
2000 with Borland C++ Builder 5.
That doesn't really answer my original question. Are you targetting XP
specifically, or multiple Windows version in general? You could be
developing under 2K and yet still target XP only.
Worse case, just dynamically load the functions at runtime like I suggested
earlier. For example:
typedef HRESULT WINAPI (*GETTHEMEFONTPTR)(HTHEME, HDC, int, int, int,
LOGFONT*);
HINSTANCE hDll = LoadLibrary("UxTheme.dll");
if( hDll )
{
GETTHEMEFONTPTR lpGetThemeFont =
(GETTHEMEFONTPTR)GetProcAddress(hDll, "GetThemeFont");
if( lpGetThemeFont )
// call lpGetThemeFont as needed...
FreeLibrary(hDll);
}
Gambit
 

Re:TThemeManager

Hi Remy
Quote
That doesn't really answer my original question. Are you targetting XP
specifically, or multiple Windows version in general? You could be
developing under 2K and yet still target XP only.
No I'm not specifically targetting for XP (Application must also run on
Win98 etc...)
I made a test and come with the function below.
ftSysCaption containts the system font (It looks like) only when I draw it
near to the caption it don't look like the same font. Why?
Bart
void TXpThemeManager::ThemeSysFont(HWND hwnd)
{
typedef HRESULT WINAPI (*MyGetThemeSysFont)(HTHEME, int, LOGFONT*);
typedef HRESULT WINAPI (*MyGetThemeFont)(HTHEME,HDC, int, int, int,
LOGFONT*);
typedef HTHEME WINAPI (*MyOpenThemeData)(HWND,LPCWSTR);
typedef HTHEME WINAPI (*MyCloseThemeData)(HTHEME hTheme);
HTHEME hTheme=0;
HINSTANCE hDll = LoadLibrary("UxTheme.dll");
if (hDll)
{
MyOpenThemeData fpOpenThemeData =
MyOpenThemeData )GetProcAddress(hDll,"OpenThemeData");
MyCloseThemeData fpCloseThemeData =
(MyCloseThemeData )GetProcAddress(hDll,"CloseThemeData");
MyGetThemeSysFont fpGetThemeSysFont =
(MyGetThemeSysFont)GetProcAddress(hDll,"GetThemeSysFont");
MyGetThemeFont fpGetThemeFont =
yGetThemeFont )GetProcAddress(hDll,"GetThemeFont");
if (fpOpenThemeData && fpCloseThemeData && fpGetThemeSysFont &&
fpGetThemeFont)
{
if (ftSysCaption) delete ftSysCaption;
hTheme=(*fpOpenThemeData)(hwnd,L"window");
if (hTheme)
{
LOGFONTW lf;
if ((*fpGetThemeSysFont)(hTheme,::TMT_CAPTIONFONT,(LOGFONT*)&lf) ==
S_OK)
{
ftSysCaption = new TFont();
ftSysCaption->Handle = CreateFontIndirectW(&lf);
}
// if
((*fpGetThemeFont)(hTheme,NULL,::WP_CAPTION,::CS_ACTIVE,::TMT_FONT,(LOGFONT*
)&lf) == S_OK)
// {
// ftSysCaption = new TFont();
// ftSysCaption->Handle = CreateFontIndirectW(&lf);
// }
(*fpCloseThemeData)(hTheme);
}
}
FreeLibrary(hDll);
}
}
//--------------------------------------------------------------------------
-
 

Re:TThemeManager

"Bart Huls" < XXXX@XXXXX.COM >wrote in message
Quote
No I'm not specifically targetting for XP (Application must
also run on Win98 etc...)
Ok. Then dynamic loading the DLL at runtime is your only option.
Quote
ftSysCaption containts the system font (It looks like)
only when I draw it near to the caption it don't look like
the same font. Why?
I do not understand what you are referring to. Can you please show a screen
shot of what you are expecting to see and what you are actually seeing
instead?
Why are you trying to access the Theme API directly anyway? What exactly is
wrong with using TThemeManager that does not work for you?
Gambit
 

Re:TThemeManager

Hi Remy,
Quote
Why are you trying to access the Theme API directly anyway? What exactly
is
wrong with using TThemeManager that does not work for you?
My Application is writing into the caption of a form. Therefore I have
written some classes. During introduction of Win XP this extra caption
doesn't look the same as the font of the normal caption. It is the font
which is selected in Windows (NONCLIENTMETRICS lfCaptionFont etc..) but it
don't look the same
because is has some shadow on it.
I found the Lib of Mike but the GetThemeSysFont and OpenThemeData are
resulting in a external linker error.
What I only want is to write into the caption (Rect etc...) with the same
font.
I Managed to get DrawThemeText to get to work
((*fpDrawThemeText)(hTheme,hdc,::WP_CAPTION,::CS_ACTIVE,WideString(asStr.c_s
tr()),-1,DT_SINGLELINE|DT_VCENTER,0,r));
But it give me a black text, but it looks like that it has the same outlook
as the real caption.
Regards,
Bart
 

Re:TThemeManager

"Bart Huls" < XXXX@XXXXX.COM >wrote in message
Quote
My Application is writing into the caption of a form.
Are you trying to custom-draw the Caption? Otherwise, why can't you use the
default themed caption font?
Quote
During introduction of Win XP this extra caption doesn't
look the same as the font of the normal caption.
What "extra" caption are you referring to? There is only one caption on a
window.
Quote
I found the Lib of Mike but the GetThemeSysFont and
OpenThemeData are resulting in a external linker error.
You need to be more specific. What are the EXACT errors?
Quote
What I only want is to write into the caption (Rect etc...)
with the same font.
Why are you trying to draw the caption manually? What EXACTLY are you
trying to accomplish?
Quote
((*fpDrawThemeText)(hTheme,hdc,::WP_CAPTION,
::CS_ACTIVE,WideString(asStr.c_s tr()),-1,DT_SINGLELINE|DT_VCENTER,0,r));
Assuming asStr is an AnsiString, you don't need to call c_str() at all.
WideString has a constructor that accepts an AnsiString directly.
Quote
But it give me a black text, but it looks like that it has the same
outlook
as the real caption.
Again, I have to ask you for screenshots. You are asking for something that
is visual, which is not something that is easily described in writing.
Gambit
 

Re:TThemeManager

Hi Remy,
Quote
Are you trying to custom-draw the Caption? Otherwise, why can't you use
the
default themed caption font?
My Application is a MDI application. I'm using the original Caption to make
it possible for the users to select a window (normal MDI beheauviour).
A MDI child is a presentation of data in a map or displays images. These
map-data or images are reflecting a time or time period. This time or time
period String is printed next to the Caption (see attached image -low res-)
When running on Xp the font of the String is not the same as the default
caption font.
Quote
>((*fpDrawThemeText)(hTheme,hdc,::WP_CAPTION,
>::CS_ACTIVE,WideString(asStr.c_s
tr()),-1,DT_SINGLELINE|DT_VCENTER,0,r));
DrawThemeText gives me a String as in the example the only thing is: It is
black on not white or the color of the active acption font.
The unresolved external error:
[Linker Error] Unresolved external 'OpenThemeData' referenced from
C:\SOURCE\UTILCLASSES\TXPTHEMEMANAGER\TXPTHEMEMANAGER.OBJ
Since I cannot post any images you will find the images in the attachments
group
Bart