Solved

how to capture mouse in a screenshot?

Posted on 2011-02-28
6
422 Views
Last Modified: 2012-05-11
this is what I'm using to process the screenshot into jpg, tho how to I capture mouse?
procedure ScreenShot2;
    var
      ScreenDC: HDC;
      ScreenHandle: HWnd;
      ScreenBitmap: TBitmap;
      Jpg:TJpegImage;
      filename:string;
      time:string;
    begin
      ScreenHandle := GetDeskTopWindow;
      ScreenDC := GetDC(ScreenHandle);
      time:=DateTimeToStr(Now);
      time:=StringReplace(time, ':', '-', [rfReplaceAll, rfIgnoreCase]);
      time:=StringReplace(time, '/', '-', [rfReplaceAll, rfIgnoreCase]);
     

      GetWindowText(GetForegroundWindow, Wnd2, SizeOf(Wnd2));






      filename:=extractfilepath(paramstr(0))+'\'+wnd2+' - '+time+'.jpg';
      try
        ScreenBitmap := TBitMap.Create;
        try
          ScreenBitmap.Width := Screen.Width;
          ScreenBitmap.Height := Screen.Height;
          BitBlt(ScreenBitmap.Canvas.Handle, 0, 0,
              Screen.Width, Screen.Height, ScreenDC, 0, 0, SRCCOPY);
             // Clipboard.Assign(ScreenBitmap)
             try
               jpg:=TJpegImage.Create;
               jpg.PixelFormat := jf24bit;
               Jpg.CompressionQuality:=70;
               Jpg.ProgressiveEncoding:=True;
               // Jpg.Grayscale:=
               Jpg.Assign(ScreenBitmap);
               Jpg.SaveToFile(FileName);
             finally

             end;
        finally
          ScreenBitmap.Free
        end
      finally
        ReleaseDC(ScreenHandle, ScreenDC)
      end
    end {ScreenShot};

Open in new window

0
Comment
Question by:eNarc
  • 2
  • 2
  • 2
6 Comments
 
LVL 9

Expert Comment

by:Mahdi78
ID: 35000101
0
 
LVL 5

Author Comment

by:eNarc
ID: 35000201
tho how do I put it into the function above?
0
 
LVL 3

Expert Comment

by:maosalah
ID: 35000236
for draws the current mouse cursor image ScreenShot Bitmap

0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 3

Expert Comment

by:maosalah
ID: 35000429
for draws the current mouse cursor image ScreenShot Bitmap
procedure DrawCursor(ScreenShotBitmap : TBitmap);
var
  r: TRect;
  CI: TCursorInfo;
  Icon: TIcon;
  II: TIconInfo;
begin
  r := ScreenShotBitmap.Canvas.ClipRect;
  Icon := TIcon.Create;
  try
    CI.cbSize := SizeOf(CI);
    if GetCursorInfo(CI) then
      if CI.Flags = CURSOR_SHOWING then
      begin
        Icon.Handle := CopyIcon(CI.hCursor);
        if GetIconInfo(Icon.Handle, II) then
        begin
          ScreenShotBitmap.Canvas.Draw(
                ci.ptScreenPos.x - Integer(II.xHotspot) - r.Left,
                ci.ptScreenPos.y - Integer(II.yHotspot) - r.Top,
                Icon
                );
        end;
      end;
  finally
    Icon.Free;
  end;
end;

Open in new window

0
 
LVL 9

Accepted Solution

by:
Mahdi78 earned 500 total points
ID: 35000806
Like this


procedure ScreenShotCursorJPEG;
var
  c: TCanvas;
  r: TRect;
  CI: TCursorInfo;
  Icon: TIcon;
  II: TIconInfo;
  Bild : Tbitmap;
  jpg : TJPEGImage;
begin
  c := TCanvas.Create;
  c.Handle := GetWindowDC(GetDesktopWindow);
  Icon := TIcon.Create;
  Bild := Tbitmap.Create;
  jpg:=TJpegImage.Create;
  try
    r := Rect(0, 0, Screen.Width, Screen.Height);
    Bild.Width := Screen.Width;
    Bild.Height := Screen.Height;
    Bild.Canvas.CopyRect(r, c, r);

    CI.cbSize := SizeOf(CI);
    if GetCursorInfo(CI) then
      if CI.Flags = CURSOR_SHOWING then
      begin
        Icon.Handle := CopyIcon(CI.hCursor);
        if GetIconInfo(Icon.Handle, II) then
        begin
          Bild.Canvas.Draw(
                ci.ptScreenPos.x - Integer(II.xHotspot) - r.Left,
                ci.ptScreenPos.y - Integer(II.yHotspot) - r.Top,
                Icon
                );
        end;
      end;


      jpg.PixelFormat := jf24bit;
      Jpg.CompressionQuality:=70;
      Jpg.ProgressiveEncoding:=True;
      Jpg.Assign(Bild);
      Jpg.SaveToFile(ExtractFilePath(Application.ExeName)+'MyScreenShot.jpg' );

  finally
    Icon.Free;
    Bild.Free;
    ReleaseDC(0, c.Handle);
    c.Free;
    jpg.Free;
  end;
end;

Open in new window

0
 
LVL 5

Author Closing Comment

by:eNarc
ID: 35015795
Perfect
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

13 Experts available now in Live!

Get 1:1 Help Now