Evo da bi se odrzao 'Caption', bilo je potrebno
malo znati i WinApi
Code:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, WinSkinData;
type
TForm1 = class(TForm)
SkinData1: TSkinData;
procedure FormPaint(Sender: TObject);
private
{ private declarations }
FCaption: TCaption;
procedure CMFontChanged(var Msg: TMessage);
message CM_FONTCHANGED;
procedure WMWinIniChange(var Msg: TWMWinIniChange);
message WM_WININICHANGE;
procedure WMNCPaint(var Msg: TWMNCPaint);
message WM_NCPAINT;
procedure WMNCActivate(var Msg: TWMNCActivate);
message WM_NCACTIVATE;
procedure WMActivate(var Msg: TWMNCActivate);
message WM_ACTIVATE;
procedure WMSetText(var Msg: TWMSetText);
message WM_SETTEXT;
procedure WMSysCommand(var Msg: TWMSysCommand);
message WM_SYSCOMMAND;
procedure WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo);
message WM_GETMINMAXINFO;
procedure DrawCaption(AActive: Boolean);
procedure SetCaption(const Value: TCaption);
protected
{ protected declarations }
public
{ public declarations }
published
{ published declarations }
property Caption: TCaption read FCaption write SetCaption;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.DrawCaption(AActive: Boolean);
var
iNCM: TNonClientMetrics;
iRect: TRect;
iCanvas: TCanvas;
iFlags: Integer;
Natpis: string;
begin
Natpis := 'Milan';
if (BorderStyle <> bsNone) then
begin
iRect.Left := 30;
iRect.Top := 9;
iRect.Bottom := 25;
iRect.Right := 200;
iCanvas := TCanvas.Create;
iCanvas.Handle := GetWindowDC(Handle);
with iCanvas do
try
Font := Self.Font;
iNCM.cbSize := SizeOf(iNCM);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, SizeOf(iNCM), @iNCM,
0);
if (BorderStyle in [bsToolWindow, bsSizeToolWin]) then
Font.Height := ((iNCM.lfCaptionFont.lfHeight * 7) div 8)
else
Font.Height := iNCM.lfCaptionFont.lfHeight;
if (iNCM.lfCaptionFont.lfWeight < 700) then
Font.Style := []
else
Font.Style := [fsBold];
Font.Size := 12;
Brush.Style := bsClear;
iFlags := DT_EXPANDTABS or DT_LEFT or DT_VCENTER or
DT_SINGLELINE or DT_END_ELLIPSIS;
iFlags := DrawTextBiDiModeFlags(iFlags);
if (AActive) then
begin
Font.Color := GetSysColor(COLOR_BACKGROUND);
OffsetRect(iRect, + 1, + 1);
DrawText(Handle, PChar(Natpis), - 1, iRect, iFlags);
OffsetRect(iRect, - 1, - 1);
Font.Color := GetSysColor(COLOR_CAPTIONTEXT)
end
else
Font.Color := GetSysColor(COLOR_GRAYTEXT);
DrawText(Handle, PChar(Natpis), - 1, iRect, iFlags)
finally
ReleaseDC(Self.Handle, Handle);
iCanvas.Free
end;
end;
end;
procedure TForm1.WMNCActivate(var Msg: TWMNCActivate);
begin
inherited;
DrawCaption(Msg.Active)
end;
procedure TForm1.WMActivate(var Msg: TWMNCActivate);
begin
inherited;
DrawCaption(Msg.Active)
end;
procedure TForm1.WMNCPaint(var Msg: TWMNCPaint);
begin
inherited;
DrawCaption(Active)
end;
procedure TForm1.WMSetText(var Msg: TWMSetText);
begin
inherited;
DrawCaption(Active)
end;
procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
begin
inherited;
DrawCaption(Active)
end;
procedure TForm1.WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo);
begin { TForm1.WMGetMinMaxInfo }
inherited;
DrawCaption(Active)
end;
procedure TForm1.SetCaption(const Value: TCaption);
begin
if (FCaption <> Value) then
begin
FCaption := Value;
Perform(WM_NCPAINT, 0, 0)
end;
end;
procedure TForm1.CMFontChanged(var Msg: TMessage);
begin
inherited;
Perform(WM_NCPAINT, 0, 0)
end;
procedure TForm1.WMWinIniChange(var Msg: TWMWinIniChange);
begin
inherited;
Perform(WM_NCPAINT, 0, 0)
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
inherited;
DrawCaption(Active)
end;
end.
Pozdrav.
p.s.
Prilozen je i primer.