Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I get the canvas handle of a extended screen

Status
Not open for further replies.

klindal

Programmer
Jan 1, 2011
3
IS
I want to draw the extended monitor(2) to a bitmap.
how can I get the canvas handle of the second screen.
 
I've been using this to get a screen shot of my monitor (in .jpg format), so you should be able to modify it to capture a secondary monitor.

Code:
procedure TForm1.CaptureScreenShot(acapture: TBitMap);
var
   c: TCanvas;
   r: TRect;
begin
   c:= TCanvas.Create;
   c.Handle:= GetWindowDC (GetDesktopWindow);
   try
     r:= Rect(0,0,screen.width,screen.height);
     acapture.Width:=screen.Width;
     acapture.Height:=screen.Height;
     acapture.Canvas.CopyRect(r, c, r);
 finally
     ReleaseDC(0, c.handle);
     c.Free;
 end;
end;

procedure TForm1.CaptureScreenShotJPEG(ajpeg:TJPEGImage);
var
   abmp:TBitmap;
begin
   abmp:=TBitmap.Create;
   try
      CaptureScreenShot(abmp);
      ajpeg.Assign(abmp);
   finally
      abmp.Free;
   end;
end;

procedure TForm1.btnStartCaptureClick(Sender: TObject);
var 
   ajpeg:TJPEGImage;
begin
   ajpeg:=TJPEGImage.Create;
   try
      CaptureScreenShotJPEG(ajpeg);
      if SavePictureDialog1.Execute then
         ajpeg.SaveToFile(SavePictureDialog1.Filename);
   finally
      ajpeg.Free;
   end;
end;

You need to add JPEG to the uses clause, and the line you need to modify is probably:

Code:
r:= Rect(0,0,screen.width,screen.height);

Rect(Left, Top, Right, Bottom) so you'll have to play with it, I don't have a second monitor to test it with.

Something like
Code:
r := Rect(screen.monitors[0].width+1, 
          0,
          screen.monitors[0].width+screen.monitors[1].width,
          // screen.width may work for 'Right'?
          screen.monitors[1].height);
 
Hi majlumbo.
Thanks for your reply.
This is not quite what I ‘am looking for.
The monitors can be 4 or 5, what I want is the canvas handle for number 3 or 5, not one large canvas for all 5 as your code returns.
Something like (canvas. Handle := GetDC(0);) this is a function that gives you the main monitor.
Any ideas.
Thanks.
 
is there nobody who knows how to snapshot other screens than the entry screen?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top