function TSkinListView.DrawEllipsisText(
DC: Hdc; UseText: WideString; rec: TRect;
ColrARGB: COLORREF; UseFont: WideString; UseSize: Single; FontStyle: TFontStyle;
ShadowOffset: Single; UseStrFormat: Integer; WordWrap: Bool = False): GpStatus;
var
Width: Integer;
Fam: GpFontFamily;
TempFont: GpFont;
Graphics: Cardinal;
rectF: TGPRectF;
Rect, rc, rc2: TRect;
strFormat: Pointer;
begin
Result := GenericError;
Graphics := 0;
strFormat :=
nil;
TempFont :=
nil;
Fam :=
nil;
try
GdipCheck(GdipCreateFromHDC(
DC, Graphics));
GdipCheck(GdipCreateFontFamilyFromName(UseFont,
nil, Fam));
if assigned(Fam)
then
begin
GdipCheck(GdipCreateFont(Fam, UseSize, FontStyle, 2, TempFont));
if assigned(TempFont)
then
begin
GdipCheck(GdipCreateStringFormat(0, 0, strFormat));
GdipCheck(GdipMeasureString(Graphics, UseText, length(UseText), TempFont, @layoutRect, strFormat,
@boundingBox,
nil,
nil));
GetWindowRect(HeaderHandle, rc);
GetWindowRect(
Handle, rc2);
Width := (rec.Right - rec.Left) + ((rc.Left - rc2.Left) - 1);
if boundingBox.Width > Width
then
begin
rectF := MakeRect(rec.Left, rec.Top, Width, rec.Bottom);
Rect.Left := round(rectF.x);
Rect.Top := round(rectF.y);
Rect.Bottom := round(rectF.Height);
Rect.Right := round(rectF.Width);
UseStrFormat := ZD_Ellipsis;
Result := DrawTextToDC(
DC, UseText, Rect, ColrARGB, UseFont, UseSize, FontStyle, ShadowOffset,
UseStrFormat, True);
end
else
Result := DrawTextToDC(
DC, UseText, rec, ColrARGB, UseFont, UseSize, FontStyle, ShadowOffset,
UseStrFormat, WordWrap);
end;
end;
finally
if Graphics <> 0
then
GdipCheck(GdipDeleteGraphics(Graphics));
if assigned(TempFont)
then
GdipCheck(GdipDeleteFont(TempFont));
if assigned(Fam)
then
GdipCheck(GdipDeleteFontFamily(Fam));
if assigned(strFormat)
then
GdipCheck(GdipDeleteStringFormat(strFormat));
end;
end;