When the cursor is grasped by another thread, the cursor handle cannot be obtained using the getCursor () application interface. This article describes how to get the cursor handle when you master the cursor in any thread.
============================================================================================================================================================================================================= =======
{When the cursor is grasped by another thread, it cannot be used to obtain the cursor handle with the getCursor () application interface. This article describes how to get the cursor handle when you master the cursor in any thread. For example, what to do when you want to place the cursor in the screen intercept program. }
function GetCursorHandle: HCURSOR; var hWindow: HWND; pt: TPoint; pIconInfo: TIconInfo; dwThreadID, dwCurrentThreadID: DWORD; begin // check which forms a cursor control GetCursorPos (pt); hWindow: = WindowFromPoint (pt);
// Get the thread ID DWTHREADID: = getWindowThreadProcessId (Hwindow, NIL);
// Get the ID dwcurrentthreadidIdIdIDIDID: = getCurrentThreadId;
// If the thread of the cursor owner is not current thread, you have to match the thread of the cursor owner to the current thread. / / Then call GetCursor () to get the correct cursor handle (HCURSOR).
if (dwCurrentThreadID <> dwThreadID) then begin if AttachThreadInput (dwCurrentThreadID, dwThreadID, True) then begin // get cursor handle Result: = GetCursor; AttachThreadInput (dwCurrentThreadID, dwThreadID, False); end; end else begin Result: = GetCursor; end ;
procedure TForm1.Button1Click (Sender: TObject); var CurPosX, CurPoxY: Integer; MyCursor: TIcon; pIconInfo: TIconInfo; begin MyCursor: = TIcon.Create; try MyCursor.Handle: = GetCursorHandle; // get the cursor position GetIconInfo (MyCursor. Handle, PiconInfo; curposx: = piconinfo.xhotspot; curpoxy: = piconinfo.yhotspot; // Draw curst canvas.draw (curpoxy, curpoxy, mycursor) on the form; finally mycursor.releaseHandle; Mycursor.Free; end; END;
// Another solution: