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的标题栏绘制自界说文字