?
Solved

Capture screen with cursor ?

Posted on 2001-09-14
5
Medium Priority
?
511 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 64 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

850 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