Older Version Newer Version

Alyce Alyce Dec 14, 2011

**ShowCursor**
[[toc|flat]]

//Some text below is copied from the Microsoft Developers Network Library.//

For an eBook or printed book on using the API with Liberty BASIC, see:
[[http://alycesrestaurant.com/apilb/index.htm|APIs for Liberty BASIC]]

=Show or Hide the Cursor= 
The ShowCursor function is part of user32 DLL and it sets an internal display counter that determines whether the cursor should be displayed. The cursor is displayed only if the display count is greater than or equal to 0. If a mouse is installed, the initial display count is 0. If no mouse is installed, the display count is –1.

=Syntax=
The syntax for the ShowCursor function is as follows.
[[code format="lb"]]
    calldll #user32, "ShowCursor",_
    bShow as long,_   '0 decrements count, 1 increments count
    displayCount as long   'returns new display count
[[code]]

The bShow parameter tells the function whether to increment or decrement the display count. The return from this function is the new display count. The display count must be greater than or equal to zero for the cursor to be displayed.

=Assuring Cursor Display=
To assure that the cursor is displayed after a program hides the cursor, call the ShowCursor function until it returns a counter value of 0 or greater. The API ShowCursor function is wrapped in a Liberty BASIC function in the code below.

[[code format="lb"]]
while count<0
    count=ShowCursor(1)
wend

wait

function ShowCursor( bShow )
'bShow =0 decrements count, =1 increments count
    calldll #user32, "ShowCursor",_
    bShow as long, _
    ShowCursor as long   'returns new display count
    end function
[[code]]

=Demo=
Here is a sample program. The buttons allow the user to increment or decrement the cursor count. The count is displayed in the statictext control. When the program closes, the function is called to increment the display count until the cursor is displayed.

[[code format="lb"]]
nomainwin
button #1.show, "Show Cursor",[show],UL,10,10,100,30
button #1.hide, "Hide Cursor",[hide],UL,10,50,100,30
statictext #1.s, "Cursor Count",130, 10, 300, 100
open "Cursor Display Demo" for window as #1
#1 "trapclose [quit]"
wait
[quit]
'assure that cursor is displayed
'cursor count must be >=0
while count<0
    count=ShowCursor(1)
wend
close #1:end

[show]
count=ShowCursor(1)
#1.s "Cursor Count is ";count
wait

[hide]
count=ShowCursor(0)
#1.s "Cursor Count is ";count
wait

function ShowCursor( bShow )
'bShow =0 decrements count, =1 increments count
    calldll #user32, "ShowCursor",_
    bShow as long, _
    ShowCursor as long   'returns new display count
    end function
[[code]]