For Newbie

Tuesday, 15 November 2011

The trick to limit the movement of a cursor on a specific window handle.



Declaration procedure:
LockCursorTo procedure (targetHwnd: hWnd);
var
   r: TRect;
begin
   if targetHwnd <> 0 then
   begin
     GetWindowRect (targetHwnd, r);
     ClipCursor (@ r);
   end
   ClipCursor else (nil);
end;

Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
begin
   LockCursorTo (Button2.Handle);
end;

To restore the cursor function kesediakala, targetHwnd parameter set to 0. example:
procedure TForm1.Button2Click (Sender: TObject);
begin
   LockCursorTo (0);
end;

Share on Facebook
Share on Twitter
Share on Google+

Related : The trick to limit the movement of a cursor on a specific window handle.