// 1. Get the handle to the current mouse-cursor and its position
function GetCursorInfo2: TCursorInfo;
var
hWindow: HWND;
pt: TPoint;
pIconInfo: TIconInfo;
dwThreadID, dwCurrentThreadID: DWORD;
begin
try
Result.hCursor := 0;
ZeroMemory(@Result, SizeOf(Result));
// Find out which window owns the cursor
if GetCursorPos(pt)
then
begin
Result.ptScreenPos := pt;
hWindow := WindowFromPoint(pt);
if IsWindow(hWindow)
then
begin
// 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.hCursor := GetCursor;
AttachThreadInput(dwCurrentThreadID, dwThreadID, False);
end;
end
else
begin
Result.hCursor := GetCursor;
end;
end;
end;
except on e:
exception do addline('
Fehler getcursorinfo2:'+e.
Message);
end;
end;
// 2. Capture the screen
procedure CaptureScreen (ImageKomp: TBitmap);
var
DC: HDC;
ABitmap: TBitmap;
MyCursor: TIcon;
CursorInfo: TCursorInfo;
IconInfo: TIconInfo;
MausPos: TPoint;
begin
try
// Capture the Desktop screen
DC := GetDC(GetDesktopWindow);
ABitmap := TBitmap.Create;
try
ABitmap.Width := 25;
// GetDeviceCaps(DC, HORZRES);
ABitmap.Height := 25;
// GetDeviceCaps(DC, VERTRES);
// BitBlt on our bitmap
GetCursorPos(MausPos);
BitBlt(ABitmap.Canvas.Handle,
0,
0,
ABitmap.Width,
ABitmap.Height,
DC,
MausPos.x - form1.Image_maus.Width
div 2,
//left
MausPos.y - form1.Image_maus.height
div 2,
//top
SRCCOPY);
// Create temp. Icon
MyCursor := TIcon.Create;
try
// Retrieve Cursor info
CursorInfo := GetCursorInfo2;
if CursorInfo.hCursor <> 0
then
begin
MyCursor.Handle := CursorInfo.hCursor;
// Get Hotspot information
GetIconInfo(CursorInfo.hCursor, IconInfo);
// Draw the Cursor on our bitmap
ABitmap.Canvas.Draw( -20-IconInfo.xHotspot,
-15-IconInfo.yHotspot, MyCursor);
end;
finally
// Clean up
MyCursor.ReleaseHandle;
MyCursor.Free;
end;
form1.image_maus.picture.bitmap:=abitmap;
finally
ReleaseDC(GetDesktopWindow,
DC);
abitmap.Free;
end;
except on e:
exception do addline('
Maus Fehler: '+e.
Message);
end;
end;