Title: Getting access to Windows Desktop with canvas (for beginners)
Question: How I can get access to the Windows Desktop Canvas and draw on it?
Answer:
// retrieves a new TCanvas object with Handle to control Windows Desktop
function WindowsDesktopCanvas: TCanvas;
var
DC: HDC;
Canvas: TCanvas;
begin
DC := GetWindowDC(GetDesktopWindow);
// creates a new TCanvas
Canvas := TCanvas.Create;
Canvas.Handle := DC;
// sets the result with the new canvas
result := Canvas;
end;
When you use the WindowsDesktopCanvas, remember to destroy the Canvas object returned by the function to prevent memory leak.