Drawing in a Form's Caption Area

The Canvas property of TForm does not include the caption area, so you are limited to drawing in the client area of the Form.  Fortunately, the Windows API function GetWindowDC will give us access to the entire Form's device context, which we can assign to our own TCanvas.  The following example draws a bitmap in the Form's caption area... 

KEYWORDS:  GetWindowDC, ReleaseHandle 


 

  // in Form's header...
  TCanvas *FullCanvas;
 

 
 

//---------------------------------------------------------------------------
//in Form's source...

__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    FullCanvas = new TCanvas();
}

void __fastcall TForm1::FormPaint(TObject *Sender) 

    // GetWindowDC returns a handle to the entire 
    // Form's device context, including the caption area
    FullCanvas->Handle = GetWindowDC(Handle); 
    FullCanvas->Draw(100, 5, Image1->Picture->Graphic); 
    ReleaseDC(Handle, FullCanvas->Handle); 

__fastcall TForm1::~TForm()

    delete FullCanvas;