| unit sBcForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
DsgnIntF;
type
TBcForm = class(TForm)
private
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 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);
function GetCaptionRect : TRect;
procedure SetCaption(const Value: TCaption);
protected
public
constructor Create(AOwner: TComponent);
override;
published
property Caption : TCaption read FCaption write SetCaption;
end;
procedure register;
implementation
procedure register;
begin
RegisterCustomModule(TBcForm, TCustomModule)
end;
constructor TBcForm.Create(AOwner: TComponent);
begin
inherited;
inherited Caption := ''
end;
function TBcForm.GetCaptionRect : TRect;
var
iRect: TRect;
begin
with iRect do
if (csDesigning in ComponentState) then
begin
Top := GetSystemMetrics(SM_CYSIZEFRAME);
Bottom := Top;
Left := GetSystemMetrics(SM_CXBORDER) + GetSystemMetrics(SM_CXSIZEFRAME);
Right := 2 * Left + GetSystemMetrics(SM_CXSIZEFRAME) +
3 * GetSystemMetrics(SM_CXSIZE);
Bottom := Bottom + GetSystemMetrics(SM_CYSIZE);
Left := Left + GetSystemMetrics(SM_CXSIZE)
end
else
begin
if (BorderStyle in [bsSizeable, bsSizeToolWin]) then
begin
Top := GetSystemMetrics(SM_CYSIZEFRAME);
Bottom := Top;
Left := GetSystemMetrics(SM_CXBORDER) + GetSystemMetrics(SM_CXSIZEFRAME);
Right := 2 * Left + GetSystemMetrics(SM_CXSIZEFRAME)
end
else
begin
Top := GetSystemMetrics(SM_CYFIXEDFRAME);
Bottom := Top;
Left := GetSystemMetrics(SM_CXBORDER) + GetSystemMetrics(SM_CXFIXEDFRAME);
Right := 2 * Left + GetSystemMetrics(SM_CXFIXEDFRAME)
end;
if (BorderStyle in [bsToolWindow, bsSizeToolWin]) then
begin
Bottom := Bottom + GetSystemMetrics(SM_CYSMSIZE)
end
else
begin
Bottom := Bottom + GetSystemMetrics(SM_CYSIZE);
if (BorderStyle<>bsDialog)
and
(biSystemMenu in BorderIcons) then
Left := Left + GetSystemMetrics(SM_CXSIZE)
end;
if (BorderStyle in [bsToolWindow, bsSizeToolWin, bsDialog]) then
begin
if (biSystemMenu in BorderIcons) then
begin
Right := Right + GetSystemMetrics(SM_CXSIZE);
if (biHelp in BorderIcons) then
Right := Right + GetSystemMetrics(SM_CXSIZE)
end;
end
else
if (biSystemMenu in BorderIcons) then
begin
Right := Right + GetSystemMetrics(SM_CXSIZE);
if (biMinimize in BorderIcons)
or
(biMaximize in BorderIcons) then
Right := Right + 2 * GetSystemMetrics(SM_CXSIZE)
else
if (biHelp in BorderIcons) then
Right := Right + GetSystemMetrics(SM_CXSIZE)
end;
end;
GetWindowRect(Handle, Result);
Result.Right := Result.Right - Result.Left - iRect.Right;
Result.Left := iRect.Left;
Result.Top := iRect.Top;
Result.Bottom := iRect.Bottom
end;
procedure TBcForm.DrawCaption(AActive: boolean);
var
iNCM: TNonClientMetrics;
iRect: TRect;
iCanvas: TCanvas;
iFlags: integer;
begin
if (BorderStyle<>bsNone) then
begin
iRect := GetCaptionRect;
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];
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(Caption), -1, iRect, iFlags);
OffsetRect(iRect, -1, -1);
Font.Color := GetSysColor(COLOR_CAPTIONTEXT)
end
else
Font.Color := GetSysColor(COLOR_INACTIVECAPTIONTEXT);
DrawText(Handle, PChar(Caption), -1, iRect, iFlags)
finally
ReleaseDC(Self.Handle, Handle);
iCanvas.Free
end;
end;
end;
procedure TBcForm.WMNCActivate(var Msg: TWMNCActivate);
begin
inherited;
DrawCaption(Msg.Active)
end;
procedure TBcForm.WMNCPaint(var Msg: TWMNCPaint);
begin
inherited;
DrawCaption(Active)
end;
procedure TBcForm.WMSetText(var Msg: TWMSetText);
begin
inherited;
DrawCaption(Active)
end;
procedure TBcForm.WMSysCommand(var Msg: TWMSysCommand);
begin
inherited;
DrawCaption(Active)
end;
procedure TBcForm.WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo);
begin
inherited
end;
procedure TBcForm.SetCaption(const Value: TCaption);
begin
if (FCaption<>Value) then
begin
FCaption := Value;
Perform(WM_NCPAINT, 0, 0)
end;
end;
procedure TBcForm.CMFontChanged(var Msg: TMessage);
begin
inherited;
Perform(WM_NCPAINT, 0, 0)
end;
procedure TBcForm.WMWinIniChange(var Msg: TWMWinIniChange);
begin
inherited;
Perform(WM_NCPAINT, 0, 0)
end;
end. | |