Notice Of Closure

Please note that this website is due to close down on 15th June 2020.

In the interim I will try to move as much content as possible over to my GitHub account. Thanks to everyone who has supported the site over the years.

» Help

How to draw on the Windows desktop


Need to draw text or graphic on screen?

Here's how to do it:

  1. File -> New -> Application
  2. Put a button anywhere on the form
  3. Double-click the button and Copy / Paste this code
procedure TForm1.Button1Click(Sender: TObject);
  (* our text *)
  CTHE_TEXT = 'I Love Delphigeist';
  (* we need a canvas object *)
  theCanvas: TCanvas;
  (* create theCanvas *)
  theCanvas := TCanvas.Create;
  (* get Desktop canvas handle *)
  theCanvas.Handle := GetWindowDC(0);
  (* we don't want a rectangle behind our text this is optional you can comment
  next line with "//" and see how it looks *)
  theCanvas.Brush.Style := bsClear;
  (* set the font name *)
  theCanvas.Font.Name := 'Courier New';
  (* we want it bold *)
  theCanvas.Font.Style := [fsBold];
  (* set the size *)
  theCanvas.Font.Size := 60;
  (* lime looks good if your wallpaper has dark colors *)
  theCanvas.Font.Color := clLime;
  (* draw the text *)
  theCanvas.TextOut(50, 50, CTHE_TEXT);
  (* clear allocated memory to our theCanvas object *)
  (* that's it *)

Now if you want to draw a TBitmap or TJPEGImage on the desktop then replace

  theCanvas.TextOut(50, 50, CTHE_TEXT);


  (* create a TBitmap named thisBitmap and load image into it *)
  (* now do the drawing *)
  theCanvas.Draw(50, 50, thisBitmap);

To use a TJPEGImage is similar, just replace thisBitmap with some suitable TJPEGImage variable.

This tip lightly modified by DelphiDabbler.

Author: Dorin Duminica
Contributor: topellina
Added: 2012-09-17
Last updated: 2012-09-17

« Return to contents »