i am parse any char for the correctly width like this.
function TSkinListView.CalculateCharWith(DC: HDC; const C: Char): Integer;
var
Fam: GpFontFamily;
TempFont: GpFont;
zdW: integer;
Graphics: cardinal;
begin
zdW := 0;
GdipCreateFontFamilyFromName(FFontName, nil, Fam);
if Assigned(Fam) then
begin
GdipCreateFont(Fam, FPointSize, FFontStyle, 2, TempFont);
if Assigned(TempFont) then
begin
GdipCreateStringFormat(0, 0, strFormat);
GdipCreateFromHDC(DC, Graphics);
GdipMeasureString(Graphics, C, length(C), TempFont, @layoutRect, strFormat,
@boundingBox, nil, nil);
if Assigned(strFormat) then
GdipDeleteStringFormat(strFormat);
zdW := round(boundingBox.Width);
end;
GdipDeleteGraphics(Graphics);
GdipDeleteFont(TempFont);
end;
GdipDeleteFontFamily(Fam);
Result := zdW;
end;
for HeaderItem := 0 to HeaderItemCount - 1 do
begin
ZeroMemory(@buf, sizeof(buf));
ListView_GetItemText(WinHandle, Item, HeaderItem, buf, sizeof(buf));
Header_GetItemRect(HeaderHandle, HeaderItem, @rcHeader);
MaxLength := (rcHeader.Right + rc.Left) - rcHeader.Left;
ItemText := PWideChar(ShortenText(hTempDC, buf, MaxLength, CalculateCharWith));
DrawItem(WinHandle, hTempDC, Item, HeaderItem, rc, ItemText, nSelected);
end;
OffsetRect(rc, 0, ItemHeight);
the Trouble is now the text is smaler then the Max Rect as shown.
I want to cut the text if longer than the maximum rect and added ELLIPSIS
any help?
EDIT:
I think this is not possible without DrawText and DT_END_ELLIPSIS
greets
Render the text into a bitmap then BitBlt to the final DC using a croped section
Quote from: Patrice Terrier on February 12, 2017, 07:28:57 PM
Render the text into a bitmap then BitBlt to the final DC using a croped section
i do it..
the Problem is not the render part the Trouble is the width of any Char with GdipMeasureString.
It works as it should, with DrawText and DT_END_ELLIPSIS see shot
the Problem then the text is wrong with BlurEffect.
greets