Вот тебе пример:
Код:
type
TShadowPosition = (spNone, spLeftTop, spLeftBottom, spRightBottom, spRightTop);
TFontStyle = (fsNone, fsBold, fsItalic, fsUnderline, fsStrikeOut);
TFontStyles = set of TFontStyle;
TTextStyle = (tsLeft, tsCenter, tsVCenter, tsRight, tsTop, tsBottom, tsSingle, tsBreak, tsCalc, tsOpaque);
TTextStyles = set of TTextStyle;
//----------------------------------------------------------
function GetNewFont(DC : HDC; FntName : String; FontSize : Integer; Style : TFontStyles): hFont;
var
Fnt : hFont;
Bold : Integer;
Name : String;
begin
if fsBold in Style then
Bold := FW_BOLD
else
Bold := FW_NORMAL;
Name := 'MS Sans Serif';
if Length(FntName) <> 0 then
Name := FntName;
Fnt := CreateFont(-MulDiv(FontSize, GetDeviceCaps(DC, LOGPIXELSY),
72), 0, 0, 0,
Bold,
Byte(fsItalic in Style),
Byte(fsUnderline in Style),
Byte(fsStrikeOut in Style),
ANSI_CHARSET or RUSSIAN_CHARSET,
OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
DEFAULT_PITCH or FF_MODERN,
PChar(Name));
Result := Fnt;
end;
//----------------------------------------------------------
function DrawShadowText(DC : HDC; S: PChar;
var aRect: TRect;
ShadowSize: Byte;
TextColor,
ShadowColor: TColorRef;
ShadowPos: TShadowPosition;
SelFont : Boolean;
FntName : String;
SizeFont : Integer;
FontStyle : TFontStyles;
TextStyle : TTextStyles) : Integer;
var
RText,
RShadow : TRect;
TxtStyle : Integer;
BkMode : Integer;
begin
RText := aRect;
RShadow := aRect;
TxtStyle := 0;
BkMode := TRANSPARENT;
if tsLeft in TextStyle then TxtStyle := TxtStyle or DT_LEFT;
if tsCenter in TextStyle then TxtStyle := TxtStyle or DT_CENTER;
if tsVCenter in TextStyle then TxtStyle := TxtStyle or DT_VCENTER;
if tsRight in TextStyle then TxtStyle := TxtStyle or DT_RIGHT;
if tsTop in TextStyle then TxtStyle := TxtStyle or DT_TOP;
if tsBottom in TextStyle then TxtStyle := TxtStyle or DT_BOTTOM;
if tsSingle in TextStyle then TxtStyle := TxtStyle or DT_SINGLELINE;
if tsBreak in TextStyle then TxtStyle := TxtStyle or DT_WORDBREAK;
if tsCalc in TextStyle then TxtStyle := TxtStyle or DT_CALCRECT;
if tsOpaque in TextStyle then BkMode := OPAQUE;
case ShadowPos of
spNone : OffsetRect(RShadow, 0, 0);
spLeftTop : OffsetRect(RShadow, -ShadowSize, -ShadowSize);
spRightBottom : OffsetRect(RShadow, ShadowSize, ShadowSize);
spLeftBottom : OffsetRect(RShadow, -ShadowSize, ShadowSize);
spRightTop : OffsetRect(RShadow, ShadowSize, -ShadowSize);
end; { case }
if SelFont then
begin
hfntNew := GetNewFont(DC, FntName, SizeFont, FontStyle);
if hfntNew <> 0 then
hfntDefault := SelectObject(DC, hfntNew);
end;
try
SetBkMode(DC, BkMode);
SetTextColor(DC, ShadowColor);
DrawText(DC, S, -1, RShadow, {DT_VCENTER or} TxtStyle);
SetTextColor(DC, TextColor);
Result := DrawText(DC, S, -1, RText, {DT_VCENTER or} TxtStyle);
if tsCalc in TextStyle then
begin
if tsCenter in TextStyle then
begin
OffsetRect(RText, ((aRect.Right - aRect.Left) - (RText.Right - RText.Left)) div 2, 0);
OffsetRect(RShadow, ((aRect.Right - aRect.Left) - (RShadow.Right - RShadow.Left)) div 2, 0);
end;
UnionRect(aRect, RText, RShadow);
end;
finally
if SelFont then
begin
if hfntNew <> 0 then
DeleteObject(SelectObject(DC, hfntDefault));
end;
end;
end;
пример использования:
Код:
var
aRect : TRect;
begin
SetTect(aRect, 0, 0, 800, 600);
DrawShadowText(GetDC(0), 'Дельфи - это круто', aRect, 1, $FF, $0000FF, spRightBottom, True, 'Tahoma', 8, [fsBold], [tsCenter, tsVCenter, tsSingle]);
end;

__________________
Je venus de nulle part
55.026263 с.ш., 73.397636 в.д.
|