Scalabium Software

SMReport Autogenerated

Knowledge for your independence'.
Home Delphi and C++Builder tips


#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;


Published: January 17, 2000

See also
 
Paradox ActiveX
ExcelFile Viewer
Clarion Viewer
SMMsg suite
DBISAM Password Recovery
MAPIMail
Metafile Convert
SMReport
DBLoad
Protected Storage Viewer
 
 
Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2015, Scalabium Software. All rights reserved.
webmaster@scalabium.com

SMExport advertising