Solved

Capture screen with cursor ?

Posted on 2001-09-14
5
423 Views
Last Modified: 2010-04-06
As title, How can i capture the screen (like print screen) -  It has to go very fast.

Thanks
Dennis
0
Comment
Question by:Dennis9
5 Comments
 
LVL 3

Expert Comment

by:hagur
ID: 6484112
Here is a procedure I use to do this.  Try it, it's quite simple.

**************************************************

procedure TForm1.TakeScreenShot;
var
  DC: HDC;
  Canvas: TCanvas;
  MyBitmap: TBitmap;
  aJPEGImage: TJPEGImage;
  filename: string;
begin
  try
    //Specify a filename

    filename := 'c:\image.jpg';

    //Takes the screenshot:
    Canvas := TCanvas.Create;
    MyBitmap := TBitmap.Create;
    aJPEGImage := TJPEGImage.Create;
    DC := GetDC(0);
    try
      Canvas.Handle := DC;
      with Screen do
        begin
          MyBitmap.Width := Width;
          MyBitmap.Height := Height;
          MyBitmap.Canvas.CopyRect(Rect(0, 0, Width, Height), Canvas,Rect(0, 0, Width, Height));
          //Safe the image in a jpeg format:
          try
            aJPEGImage.Assign(MyBitmap);
            aJPEGImage.SaveToFile(filename);
          finally
            aJPEGImage.Free;
          end
        end;
    finally
      ReleaseDC(0, DC);
      MyBitmap.Free;
      Canvas.Free
    end;
  except
  end;
end;

**************************************************

Just copy it to your program and don't forget to declare it at the top of the unit like this:

procedure TakeScreenShot;


To use it, simply place a button on your form and add this to the button's onclick event:

TakeScreenShot;

By default, it will save the image to c:\image.jpg , you can change that easily.

Finally, make sure that you add 'jpeg' to the uses clause of the unit.

Regards,
Hagur
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6484338
Does this catch the cursor also as requested?
If not it should be possible to get the current cursor (and its position), assign it to a TBitmap and pait it on the captured TBitmap at the correct position.
0
 
LVL 1

Author Comment

by:Dennis9
ID: 6484487
hagur -> it does not capture the cursor, but thanks for the code anyway.

robert_marquardt -> Good idea it might be the only way else i should use code to press the print screen while the other key i can't remember should be down, then it catch the cursor too. But i will try your idea since i already had code to take the shot with.


Thanks
Dennis
0
 
LVL 5

Accepted Solution

by:
alanwhincup earned 16 total points
ID: 6484542
This should do it:

The below example uses a TImage (Image1) and a TButton (Button1) with the button's OnClick event code as the below code.

procedure TForm1.Button1Click(Sender: TObject);
var
  Desktop : HDC;
  Point : TPoint;
begin
  GetCursorPos(Point);
  Desktop := GetDC(0);
  try
    with Image1.Picture.Bitmap do
    begin
      PixelFormat:=pf32bit;
      Width := Screen.Width;
      Height := Screen.Height;
      BitBlt(Canvas.Handle, 0, 0, Width, Height, Desktop, 0, 0, SRCCOPY);
      DrawIcon(Canvas.Handle, Point.X, Point.Y, GetCursor);
    end;
  finally
    ReleaseDC(0, Desktop);
  end;
end;

Cheers,

Alan
0
 
LVL 1

Author Comment

by:Dennis9
ID: 6484575
Thanks alanwhincup it worked great :>

Dennis
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now