Delphi如何在Form的標題列繪製自訂文字

來源:互聯網
上載者:User

標籤:text   win   ons   特定   get   改變   如何   bsp   需要   

 

Delphi中Form表單的標題被設計成繪製在系統功能表的旁邊,如果你想要在標題列繪製自訂文本又不想改變Caption屬性,你需要處理特定的Windows訊息:WM_NCPAINT.。

WM_NCPAINT訊息在需要重繪邊框時發送到視窗,應用程式可以利用該訊息繪製自己的視窗邊框。

注意,同時你也要處理視窗啟用或失去焦點的WM_NCACTIVATE訊息,如果不處理,當視窗失去焦點時,自訂繪製的文本會消失。

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;

Delphi如何在Form的標題列繪製自訂文字

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.