Painting on another application canvas.

Code snippet that shows how to paint in another application's window or on the screen itself.

Ever wished to paint in the window of Word, or on the desktop? Have a look at this:



procedure TForm1.Button1Click(Sender: TObject);

var thehandle:thandle;

   thecanvas:tcanvas;

begin

thecanvas:=tcanvas.create;

winexec('notepad.exe',sw_normal);

thehandle:=findwindow('notepad',nil);

thecanvas.handle:=getdc(thehandle);

thecanvas.rectangle(0,0,100,100);

thecanvas.free;

end;



For painting the screen itself, use:



thecanvas.handle:=createdc('DISPLAY',Nil,Nil,Nil);

 

Share this article!

Follow us!

Find more helpful articles: