屏幕截图,为什么截不到鼠标指针(小箭头)?

regft 2006-02-21 12:36:26
procedure TForm1.Timer1Timer(Sender: TObject);

var
Fullscreen:Tbitmap;
FullscreenCanvas:TCanvas;
dc:HDC;

begin
Fullscreen := TBitmap.Create; // 创建一个 BITMAP 来存放图象
Fullscreen.Width := screen.width;
Fullscreen.Height := screen.Height;
DC := GetDC (0); // 取得屏幕的 DC,参数 0 指的是屏幕
FullscreenCanvas := TCanvas.Create; // 创建一个 CANVAS 对象
FullscreenCanvas.Handle := DC;
Fullscreen.Canvas.CopyRect(Rect (0, 0, screen.Width, screen.Height),
fullscreenCanvas,Rect (0, 0, Screen.Width, Screen.Height));// 把整个屏幕复制到 BITMAP 中

FullscreenCanvas.Free; // 释放 CANVAS 对象

ReleaseDC (0, DC); // 释放 DC

//*******************************

image1.picture.Bitmap:=fullscreen;// 拷贝下的图象赋给 IMAGE 对象
image1.Width:=fullscreen.Width;
image1.Height:=fullscreen.Height;

fullscreen.free; // 释放 bitmap

end;

屏幕截图,为什么截不到鼠标指针(小箭头)?
...全文
1296 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ly_liuyang 2006-02-22
  • 打赏
  • 举报
回复
不用我在多说了
呵呵
constantine 2006-02-21
  • 打赏
  • 举报
回复
这样抓取当前鼠标形状:

先定义一个cursor变量:
var GlobalCur:TIcon;
windowhld:hwnd;
threadld:dword;
begin
windowhld:=GetForegroundWindow;
threadld:=GetWindowThreadProcessId(Windowhld,nil);
AttachThreadInput(GetCurrentThreadId,threadld,true);
GlobalCur:=TIcon.Create;
GlobalCur.handle:=GetCursor;
AttachThreadInput(GetCurrentThreadId,threadld,false);
然后
bitmap.canvas.brush.Style:=bsclear;
bitmap.canvas.draw(x,y,GlobalCur); //x,y的值可以通过GetCursorPos得到
****************************
下面是两个演示:
{
The GetCursor() API is limited in that it does not, by default, return a handle to the current
cursor when that cursor is owned by another thread. This article demonstrates a way to retrieve
the current cursor regardless of what thread owns it.
For example, when you wish to include the image of the cursor in a screen capture.
}
function GetCursorHandle: HCURSOR;
var
hWindow : HWND;
pt : TPoint;
pIconInfo : TIconInfo;
dwThreadID, dwCurrentThreadID: DWORD;
begin
// Find out which window owns the cursor
GetCursorPos(pt);
hWindow := WindowFromPoint(pt);

// Get the thread ID for the cursor owner.
dwThreadID := GetWindowThreadProcessId(hWindow, nil);

// Get the thread ID for the current thread
dwCurrentThreadID := GetCurrentThreadId;

// If the cursor owner is not us then we must attach to
// the other thread in so that we can use GetCursor() to
// return the correct hCursor
if (dwCurrentThreadID <> dwThreadID) then
begin
if AttachThreadInput(dwCurrentThreadID, dwThreadID, True) then
begin
// Get the handle to the cursor
Result := GetCursor;
AttachThreadInput(dwCurrentThreadID, dwThreadID, False);
end;
end
else
begin
Result := GetCursor;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
CurPosX, CurPoxY : Integer;
MyCursor : TIcon;
pIconInfo : TIconInfo;
begin
MyCursor := TIcon.Create;
try
MyCursor.Handle := GetCursorHandle;
// Retrieves information about the specified cursor.
GetIconInfo(MyCursor.Handle, pIconInfo);
CurPosX := pIconInfo.xHotspot;
CurPoxY := pIconInfo.yHotspot;
// Draw the Cursor on the form
Canvas.Draw(CurPoxY, CurPoxY, MyCursor);
finally
MyCursor.ReleaseHandle;
MyCursor.Free;
end;
end;

// Another Solution:

procedure TForm1.Timer1Timer(Sender: TObject);
var
CI : TCursorInfo;
begin
CI.cbSize := SizeOf(CI);
GetCursorInfo(CI);
Image1.Picture.Icon.Handle := CI.hCursor;
end;
王集鹄 2006-02-21
  • 打赏
  • 举报
回复
//参考如下api,具体调用方法和参数说明请自己搜索

GetCursorInfo(vCursorInfo) //得到鼠标的信息
GetIcon(vCursorInfo.hCursor, vIconInfo) //得到图标信息
DrawIcon() //绘制图标到画布中

vCursorInfo.ptScreenPos //鼠标位置
vIconInfo.xHotspot\vIconInfo.yHotspot //热点坐标
cuteant 2006-02-21
  • 打赏
  • 举报
回复
是截不到鼠标,如果有需要,得自己绘制一个。

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧