Solved

how to capture mouse in a screenshot?

Posted on 2011-02-28
6
435 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
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…

786 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