Scalabium Software |
|
| Knowledge for your independence'. | |
#59: How can I draw in the form caption? |
|
If you want to draw a something in the title bar of the form,
you must handle the WM_NCPAINT message. For example in the next
code I show how you can output the form caption with italic font
style: type
TForm1 = class(TForm)
private
procedure WMNCPaint(var Msg: TWMNCPaint); message WM_NCPAINT;
end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.WMNCPaint(var Msg: TWMNCPaint);
var ACanvas: TCanvas;
intLeftShift, intTopShift: Integer;
begin
inherited;
ACanvas := TCanvas.Create;
try
{to retrieve the device context for the Form1 window}
ACanvas.Handle := GetWindowDC(Form1.Handle);
with ACanvas do
begin
Brush.Color := clActiveCaption;
Font.Style := [fsItalic];
{calculate the left coordinate for caption drawing}
intLeftShift := GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CXBORDER);
{calculate the top coordinate for caption drawing}
intTopShift := (GetSystemMetrics(SM_CYCAPTION) - Abs(Font.Height)) div 2 + 1;
{output the caption string}
TextOut(intLeftShift, intTopShift, Caption)
end;
finally
{to release the device context}
ReleaseDC(Form1.Handle, ACanvas.Handle);
ACanvas.Free
end;
end;
|
|
|
Copyright© 1998-2025, Scalabium
Software. All rights reserved. |