Link to home
Start Free TrialLog in
Avatar of eNarc
eNarcFlag for United Kingdom of Great Britain and Northern Ireland

asked on

how to capture mouse in a screenshot?

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

Avatar of Mahdi78
Mahdi78
Flag of Algeria image

Avatar of eNarc

ASKER

tho how do I put it into the function above?
for draws the current mouse cursor image ScreenShot Bitmap

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

ASKER CERTIFIED SOLUTION
Avatar of Mahdi78
Mahdi78
Flag of Algeria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eNarc

ASKER

Perfect