Solved

Capture screen with cursor ?

Posted on 2001-09-14
5
420 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks alanwhincup it worked great :>

Dennis
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

10 Experts available now in Live!

Get 1:1 Help Now