標籤: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的標題列繪製自訂文字