Solved

Capture screen with cursor ?

Posted on 2001-09-14
5
448 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 89
Delphi IDE crash without error message ... 7 133
Find and Replace Stream with 0s 8 82
firemonkey keyboard covers the controls 1 76
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

740 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