加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

用delphi在屏幕截图中显示鼠标光标

发布时间:2020-12-15 09:36:57 所属栏目:大数据 来源:网络整理
导读:嗨,我正在制作一个delphi xe函数,功能是截取屏幕,一切顺利,但问题是我没有看到任何图像上的鼠标光标. 代码如下: procedure capturar_pantalla(nombre: string);// Credits :// Based on : http://www.delphibasics.info/home/delphibasicssnippets/screenca
嗨,我正在制作一个delphi xe函数,功能是截取屏幕,一切顺利,但问题是我没有看到任何图像上的鼠标光标.

代码如下:

procedure capturar_pantalla(nombre: string);

// Credits :
// Based on : http://www.delphibasics.info/home/delphibasicssnippets/screencapturewithpurewindowsapi
// Thanks to  www.delphibasics.info and n0v4

var

  uno: integer;
  dos: integer;
  cre: hDC;
  cre2: hDC;
  im: hBitmap;
  archivo: file of byte;
  parriba: TBITMAPFILEHEADER;
  cantidad: pointer;
  data: TBITMAPINFO;

begin


  // Start

  cre := getDC(getDeskTopWindow);
  cre2 := createCompatibleDC(cre);
  uno := getDeviceCaps(cre,HORZRES);
  dos := getDeviceCaps(cre,VERTRES);
  zeromemory(@data,sizeOf(data));


  // Config

  with data.bmiHeader do
  begin
    biSize := sizeOf(TBITMAPINFOHEADER);
    biWidth := uno;
    biheight := dos;
    biplanes := 1;
    biBitCount := 24;

  end;

  with parriba do
  begin
    bfType := ord('B') + (ord('M') shl 8);
    bfSize := sizeOf(TBITMAPFILEHEADER) + sizeOf(TBITMAPINFOHEADER)
      + uno * dos * 3;
    bfOffBits := sizeOf(TBITMAPINFOHEADER);
  end;

  //

  im := createDIBSection(cre2,data,DIB_RGB_COLORS,cantidad,0);
  selectObject(cre2,im);

  bitblt(cre2,uno,dos,cre,SRCCOPY);

  releaseDC(getDeskTopWindow,cre);

  // Make Photo

  AssignFile(archivo,nombre);
  Rewrite(archivo);

  blockWrite(archivo,parriba,sizeOf(TBITMAPFILEHEADER));
  blockWrite(archivo,data.bmiHeader,sizeOf(TBITMAPINFOHEADER));
  blockWrite(archivo,cantidad^,uno * dos * 3);

end;

当我在屏幕截图中显示鼠标光标时,有人可以解释一下吗?

解决方法

这是一个更清晰的实现,你正在尝试做什么,以及一个演示如何使用它的控制台应用程序. (由于捕获屏幕的时间,它会抓取“应用程序忙”光标,因为在应用程序仍在加载时进行调用.)您可以在需要时找出如何调用它以获得正确的光标.

将鼠标光标捕获到Zarko(Tony的链接).我在这里找到的屏幕捕获代码一段时间(并且有给作者的信用,但它在不同的机器上) – 我明天将更新这篇文章,当我回到那个系统.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils,Windows,Graphics;

procedure DrawCursor (ACanvas:TCanvas; Position:TPoint) ;
var
  HCursor : THandle;
begin
  HCursor := GetCursor;
  DrawIconEx(ACanvas.Handle,Position.X,Position.Y,HCursor,32,DI_NORMAL) ;
end;

function CaptureWindow(const WindowHandle: HWnd): TBitmap;
var
  DC: HDC;
  wRect: TRect;
  CurPos: TPoint;
begin
  DC := GetWindowDC(WindowHandle);
  Result := TBitmap.Create;
  try
    GetWindowRect(WindowHandle,wRect);
    Result.Width := wRect.Right - wRect.Left;
    Result.Height := wRect.Bottom - wRect.Top;
    BitBlt(Result.Canvas.Handle,Result.Width,Result.Height,DC,SRCCOPY);
    GetCursorPos(CurPos);
    DrawCursor(Result.Canvas,CurPos);
  finally
    ReleaseDC(WindowHandle,DC);
  end;
end;

// Sample usage starts here
var
  Bmp: TBitmap;

begin
  Bmp := CaptureWindow(GetDesktopWindow);
  Bmp.SaveToFile('D:TempFilesFullScreenCap.bmp');
  Bmp.Free;
  WriteLn('Screen captured.');
  ReadLn;
end.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读