Topic "Minor Bug+Patch: Themed Groupbox captions incorrectly drawn"

Author Message
[View user's profile]
Joined: 2006-03-16
Posts: 1
I already reported this to Mike Lischke (ThemeManager) some time ago:
ThemeManager (and therefore your XPGroupbox code) makes use of GetTextExtent32 instead of GetThemeTextExtent.
This causes incorrect GroupBox caption-drawing if your theme does not use standard font, eg. when the font style is bold.

Screen of Problem:
<invalid link removed>
<invalid link removed>
(Theme: ClearLoks/Human)

Patch (Function define according to source/win32/rtl/win/UxTheme.pas)
--- E:\misc\winscp380source-orig\packages\my\XPThemes.pas   Sat Oct 16 19:11:14 2004
+++ E:\misc\winscp380source\packages\my\XPThemes.pas   Thu Mar 16 22:24:10 2006
@@ -31,6 +31,8 @@
     FCloseThemeData: function(hTheme: THandle): HRESULT; stdcall;
     FDrawThemeText: function(hTheme: THandle; hdc: HDC; iPartId, iStateId: Integer; pszText: LPCWSTR; iCharCount: Integer;
       dwTextFlags, dwTextFlags2: DWORD; const pRect: TRect): HRESULT; stdcall;
+    FGetThemeTextExtent: function(hTheme: THandle; hdc: HDC; iPartId, iStateId: Integer; pszText: LPCWSTR; iCharCount: Integer;
+      dwTextFlags: DWORD; pBoundingRect: PRECT; var pExtentRect: TRect): HRESULT; stdcall;
     FIsThemeBackgroundPartiallyTransparent: function(hTheme: THandle; iPartId, iStateId: Integer): BOOL; stdcall;
     FDrawThemeParentBackground: function(hwnd: HWND; hdc: HDC; prc: PRECT): HRESULT; stdcall;
     FGetThemeAppProperties: function: DWORD; stdcall;
@@ -78,6 +80,7 @@
     FOpenThemeData := GetProcAddress(FThemeLib, 'OpenThemeData');
     FCloseThemeData := GetProcAddress(FThemeLib, 'CloseThemeData');
     FDrawThemeText := GetProcAddress(FThemeLib, 'DrawThemeText');
+    FGetThemeTextExtent := GetProcAddress(FThemeLib, 'GetThemeTextExtent');
     FIsThemeBackgroundPartiallyTransparent := GetProcAddress(FThemeLib, 'IsThemeBackgroundPartiallyTransparent');
     FDrawThemeParentBackground := GetProcAddress(FThemeLib, 'DrawThemeParentBackground');
     FGetThemeAppProperties := GetProcAddress(FThemeLib, 'GetThemeAppProperties');
@@ -161,8 +164,9 @@
     if Text <> '' then
       SetTextColor(DC, Graphics.ColorToRGB(Font.Color));
-      GetTextExtentPoint32(DC, PChar(Text), Length(Text), Size);
-      TextR := Rect(0, 0,,;
+      WText := Text;
+      XPTheme.FGetThemeTextExtent(GetButtonThemeData, DC, BP_GROUPBOX, StateID,
+        PWideChar(WText), Length(WText), DT_LEFT, nil, TextR);
       if not UseRightToLeftAlignment then
         OffsetRect(TextR, 8, 0)
@@ -185,7 +189,6 @@
     SelectClipRgn(DC, 0);
     if Text <> '' then
-      WText := Text;
       XPTheme.FDrawThemeText(GetButtonThemeData, DC, BP_GROUPBOX, StateID,
         PWideChar(WText), Length(WText), DT_LEFT, 0, TextR);
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26911
Location: Prague, Czechia
Thanks! I'll apply the patch into the next version.
Martin Prikryl

You can post new topics in this forum


What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License