Solved

how to capture mouse in a screenshot?

Posted on 2011-02-28
6
430 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

863 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

22 Experts available now in Live!

Get 1:1 Help Now