Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to screen capture of the desktop when multiple monitors are present Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Screen capture of the desktop when multiple monitors are pr 25-Aug-03
Category
System
Language
Delphi 2.x
Views
173
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			 Author: Lou Adler

I currently use DC := GetDC(GetDesktopWindow) to get a screen capture. What do I 
need to do do to capture the desktop when multiple monitors are present instead of 
just the primary monitor?

Answer:

Solve 1:

On multi-monitor systems the desktop is one big bitmap. On my dual-monitor system 
the following captures both desktops into one big bitmap. If you just wanted the 
second monitor you could adjust the left setting of the TRect to be captured. Keep 
in mind, however, that some people might arrange monitors other than side by side 
with monitor 1 on the left and monitor 2 on the right.
1   
2   procedure GrabScreen(const SourceRect: TRect; Bitmap: TBitmap);
3   var
4     ScreenCanvas: TCanvas;
5   begin
6     ScreenCanvas := TCanvas.Create;
7     try
8       ScreenCanvas.Handle := GetDC(0);
9       try
10        Bitmap.Width := SourceRect.Right - SourceRect.Left;
11        Bitmap.Height := SourceRect.Bottom - SourceRect.Top;
12        Bitmap.Canvas.CopyRect(Rect(0, 0, Bitmap.Width, Bitmap.Height), ScreenCanvas,
13          SourceRect);
14      finally
15        ReleaseDC(0, ScreenCanvas.Handle);
16        ScreenCanvas.Handle := 0;
17      end;
18    finally
19      ScreenCanvas.Free;
20    end;
21  end;
22  
23  procedure TForm1.Button1Click(Sender: TObject);
24  begin
25    GrabScreen(Rect(0, 0, Screen.Monitors[0].Width + Screen.Monitors[1].Width,
26      Screen.Height),
27      Image1.Picture.Bitmap);
28    Caption := Format('Width %d Height %d', [Image1.Width, Image1.Height]);
29  end;



Solve 2:

Referring to Answer 1: Finally, I went through and used the debugger to check out 
all of the Screen variable fields at runtime and found what I needed:

30  { ... }
31  DC := GetDC(GetDesktopWindow);
32  BMPImage := TBitmap.Create;
33  try
34    BMPImage.Width := Screen.DesktopWidth;
35    BMPImage.Height := Screen.DesktopHeight;
36    BitBlt(BMPImage.Canvas.Handle, 0, 0, BMPImage.Width, BMPImage.Height,
37      DC, Screen.DesktopLeft, Screen.DesktopTop, SRCCOPY);
38  finally
39    ReleaseDC(GetDesktopWindow, DC);
40  end;
41  { ... }


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC