Solved

how to capture mouse in a screenshot?

Posted on 2011-02-28
6
447 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
[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
  • 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
Independent Software Vendors: 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!

 
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

Industry Leaders: 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
Delphi XE10 Round Image 2 232
Why can't I create any project with my delphi EXE file? 6 59
how to change, disabled button color FMX ? 1 66
Browsing a TTreeView in Delphi 5 50
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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

710 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