[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Capture screen with cursor ?

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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

649 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