Delphi中在窗体标题栏画自定义文字

来源:互联网 发布:博奥计价软件 编辑:程序博客网 时间:2024/05/17 02:38
 

type
   TCustomCaptionForm = class(TForm)
   private
     procedure WMNCPaint(var Msg: TWMNCPaint) ; message WM_NCPAINT;
     procedure WMNCACTIVATE(var Msg: TWMNCActivate) ; message WM_NCACTIVATE;
     procedure DrawCaptionText() ;
   end;

...

implementation


procedure TCustomCaptionForm .DrawCaptionText;
const
   captionText = 'delphi.about.com';
var
   canvas: TCanvas;
begin
   canvas := TCanvas.Create;
   try
     canvas.Handle := GetWindowDC(Self.Handle) ;
     with canvas do
     begin
       Brush.Style := bsClear;
       Font.Color := clMaroon;
       TextOut(Self.Width - 110, 6, captionText) ;
     end;
   finally
     ReleaseDC(Self.Handle, canvas.Handle) ;
     canvas.Free;
   end;
end;

procedure TCustomCaptionForm.WMNCACTIVATE(var Msg: TWMNCActivate) ;
begin
   inherited;
   DrawCaptionText;
end;

procedure TCustomCaptionForm.WMNCPaint(var Msg: TWMNCPaint) ;
begin
   inherited;
   DrawCaptionText;
end;

原创粉丝点击