1. Home
  2. Computing & Technology
  3. Delphi Programming

Hiding the cursor from the screen

By Zarko Gajic, About.com

The API ShowCursor can be used to hide/show the mouse cursor, but this only affects our application. If we want to hide the cursor for all applications, one way of doing it is confining the cursor to a position outside the limits of the screen with the API ClipCursor:

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure rShowCursor(bShow: BOOL) ;
var
   r: trect;
begin
   if not bShow then begin // Hide
     r.Top := 0;
     r.Left := GetSystemMetrics(SM_CXSCREEN)
             + GetSystemMetrics(SM_CXCURSOR) ;
     r.Right := r.Left;
     r.Bottom := 0;
     ClipCursor(@r) ;
     SetCursorPos(0,0) ;
   end else begin // Restore
     ClipCursor(nil) ;
     SetCursorPos(GetSystemMetrics(SM_CXSCREEN) div 2,
                  GetSystemMetrics(SM_CYSCREEN) div 2) ;
   end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» How to merge strings in two TStringList's
« How to determine the path to the users Application Data

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2003 Delphi Tips
  7. Hiding the cursor from the screen

©2009 About.com, a part of The New York Times Company.

All rights reserved.