抓 圖 實 際 上 是 位 圖 的 復 制 , Windows在 復 制 位 圖 時 是 不 會 受 鼠 標
光 標 的 影 響 的 。 可 以 先 抓 圖 , 然 后 在 使 用 DrawIcon將 鼠 標 光 標 畫 上 去 。
procedure TForm1.FormClick(Sender: TObject);
var
winHWND, hCur: integer;
winDC: integer;
rect: TRect;
pt: TPoint;
fBitmap: TBitmap;
begin
hCur := GetCursor(); // 取得光標句柄
GetCursorPos(pt); // 取得光標位置
winHWND := GetDesktopWindow();
winDC := GetDC(winHWND);
GetWindowRect(winHWND, rect);
fBitmap := TBitmap.create;
try
fBitmap.width := rect.right - rect.left;
fBitmap.height := rect.bottom - rect.top;
BitBlt(fBitmap.canvas.handle, 0, 0, fBitmap.width, fBitmap.height, winDC, 0, 0, SRCCOPY);
DrawIcon(fBitmap.canvas.handle, pt.x, pt.y, hCur); // 畫光標
ReleaseDC(winHWND, winDC);
Image1.Picture.Bitmap.Assign(fBitmap);
finally
fBitmap.Free;
end;
end;