Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VBScript: How to hide the mouse-Cursor

1,682 views
Skip to first unread message

Rupert Hildenbrand

unread,
Oct 29, 2004, 8:34:25 AM10/29/04
to
Hi

excuse me, probably a very simple thing, but I am new to VBScript:

During a Script-controlled presentation I'd like to hide the mouse cursor.
Which is the sacred command?

Thanks
Rupert


Ulf Dornheck Busscher

unread,
Oct 29, 2004, 8:49:37 AM10/29/04
to
Rupert Hildenbrand wrote:
> During a Script-controlled presentation I'd like to hide the mouse
> cursor. Which is the sacred command?

Hi Rupert,

What is a script controlled presentation?

Ulf


Rupert Hildenbrand

unread,
Oct 29, 2004, 9:34:36 AM10/29/04
to
"Ulf Dornheck Busscher" <ul...@web.de> schrieb im Newsbeitrag
news:uKUxvWbv...@TK2MSFTNGP12.phx.gbl...

The script opens and closes documents step by step

Rupert

mayayana

unread,
Oct 29, 2004, 10:14:58 AM10/29/04
to
I think Ulf is asking what it is that you're trying to
do. There's no VBS method to hide the screen cursor,
so you want to try to hide the cursor in the window
of whatever program is opening the "documents".
If that can be done it will depend on what the program
is.
_____________________________

mayayX...@mindYYspring.com
For return email remove XX and YY.
_____________________________
Rupert Hildenbrand <hilde...@t-online.de> wrote in message
news:cltgu6$dcd$02$1...@news.t-online.com...

mr unreliable

unread,
Oct 29, 2004, 1:37:10 PM10/29/04
to
servus Rupert,

There is no way to do this using "pure" script.

However, it is quite easy to do if you are willing to call api's from script
(gasp!).

If you are willing to call api's, then you will have to either: write an
actX object "wrapping" the api calls, _OR_ use some utility which is able to
define-and-call an api at "run time". Such a utility (DynaWrap, a.k.a.
DynaCall) may be found on Guenter Born's website.

http://www.borncity.com/WSHBazaar/WSHBazaar.htm

What you do (with the api's) is to re-set the system cursor to a cursor
which is completely transparent (I call it a "null" cursor).

Here is a snippet of code that does that:

--- <snip> ---
' use DynaWrap to change the system cursor, jw 24Apr00

Option Explicit

Dim oDW ' as object (Dynawrap)
Dim hNullCursor, hCurHourGlass, hCurArrow ' as long (cursor handle)
Dim bAns ' as long (success/fail)

Const IDC_ARROW = 32512 ' standard cursors
Const IDC_IBEAM = 32513
Const IDC_WAIT = 32514

Const OCR_NORMAL = 32512 ' system cursor ID's
Const OCR_IBEAM = 32513
Const OCR_WAIT = 32514

Const sNullCurFileSpec = "c:\windows\temp\null.cur"


MsgBox("Clear the decks!, your cursor is about to be changed")

' this code will load the hourglass cursor...
' Call DeclareAPI("USER32.DLL", "LoadCursorA", "i=ll", "f=s", "r=h")
' hCurHourGlass = oDW.LoadCursorA(0, CLng(IDC_WAIT)) ' load hourglass
' bAns = oDW.SetSystemCursor(CLng(hCurHourGlass), CLng(OCR_NORMAL))

' this code loads a "null cursor" (from a file)...
Call DeclareAPI("USER32.DLL", "LoadCursorFromFileA", "i=r", "f=s", "r=h")
hNullCursor = oDW.LoadCursorA(CStr(sNullCurFileSpec)) ' load null cursor

Call DeclareAPI("USER32.DLL", "SetSystemCursor", "i=ll", "f=s", "r=l")
bAns = oDW.SetSystemCursor(CLng(hNullCursor), CLng(OCR_NORMAL))


MsgBox("If all went well, you should be seeing an _NO_ cursor" & vbCrLf &
vbCrLf _
& " Now click OK to change it back to the normal arrow")

' this code will re-load the arrow cursor...
Call DeclareAPI("USER32.DLL", "LoadCursorA", "i=ll", "f=s", "r=h")
hCurArrow = oDW.LoadCursorA(0, CLng(IDC_ARROW))
Call DeclareAPI("USER32.DLL", "SetSystemCursor", "i=ll", "f=s", "r=l")
bAns = oDW.SetSystemCursor(Clng(hCurArrow), CLng(OCR_NORMAL))

' no cleanup required if you loaded a system standard cursor,
' (it's not considered "cricket" to delete the standard cursors)

' er wait. The "null" cursor was was not a standard cursor,
' so it must be cleaned up...
Call DeclareAPI("USER32.DLL", "DestroyCursor", "i=l", "f=s", "r=l")
bAns = oDW.DestroyCursor(Clng(hNullCursor))

WScript.Quit


' ================================================
' === SUBROUTINES FOLLOW =========================
' ================================================

Sub DeclareAPI(sDLL, sAPI, sInput, sType, sResult)

' the DynaWrap doc is rather inscrutable, but as best I can make out,
' DynaWrap can only accomodate ONE api at a time. (If I'm wrong,
' maybe you experts can straighten me out on this).

' Assuming that my one-at-a-time hypothesis is correct,
' then one has two choices:
' - you need to set up a separate obj for EVERY api (ugh!), or
' - declare the api's to be used (one-at-a-time),
' which is what you see here (yes, it's "ugly")...

Set oDW = nothing ' clear any previous instance
Set oDW = CreateObject("DynamicWrapper") ' start over...
oDW.Register CStr(sDLL),CStr(sAPI),CStr(sInput),CStr(sType),CStr(sResult)

End Sub
--- </snip> ---

o.k. now for the caveats. You must store the null cursor somewhere handy,
and then modify the script to point to the cursor's location.

Also, after the system cursor is set to the null cursor, then you are not
going to have a pointer to click on anything. When that message box appears
saying "click OK to restore the arrow cursor" appears, you won't be able to
click. I suggest using the "enter" key to dismiss the msgbox.

Finally, it was previously pointed out to me that not everybody uses the
"standard" arrow as a cursor, and so setting the cursor "back" to the arrow
is not strictly kosher. If you want to be politically correct about this,
you have to call the "SystemParametersInfo" api (with an appropriate
constant) to get the handle of the "real" system cursor.

mfg, jw
"Rupert Hildenbrand" <franzr...@gmx.net> wrote in message
news:cltdd4$51h$02$1...@news.t-online.com...

null.cur

mr unreliable

unread,
Oct 29, 2004, 2:52:52 PM10/29/04
to
uh-oh. Forget that "null cursor" suggestion.

There is a much more simple and direct way to hide the system cursor,
i.e., use the "Show Cursor" api.

--- <snip> ---
' use DynaWrap to show/hide the system cursor, jw 29Oct04

Option Explicit

Dim oDW ' as object (Dynawrap)

Dim nRtn ' as long (api return value)

MsgBox("Achtung, Vorsicht!, your cursor is about to be HIDDEN (gasp!)...
")

Call DeclareAPI("USER32.DLL", "ShowCursor", "i=l", "f=s", "r=l")
nRtn = oDW.ShowCursor(CLng(False)) ' hide the system cursor

MsgBox("If all went well, you should be seeing _NO_ cursor" & vbCrLf &
vbCrLf _
& " Now click OK (by pressing the enter key) to see system cursor
again... ")

nRtn = oDW.ShowCursor(CLng(True)) ' (hopefully) show the system cursor
again

WScript.Quit


' ================================================
' === SUBROUTINES FOLLOW =========================
' ================================================

Sub DeclareAPI(sDLL, sAPI, sInput, sType, sResult)

' the DynaWrap doc is rather inscrutable, but as best I can make out,
' DynaWrap can only accomodate ONE api at a time. (If I'm wrong,
' maybe you experts can straighten me out on this).

' Assuming that my one-at-a-time hypothesis is correct,
' then one has two choices:
' - you need to set up a separate obj for EVERY api (ugh!), or
' - declare the api's to be used (one-at-a-time),
' which is what you see here (yes, it's "ugly")...

Set oDW = nothing ' clear any previous instance
Set oDW = CreateObject("DynamicWrapper") ' start over...
oDW.Register CStr(sDLL),CStr(sAPI),CStr(sInput),CStr(sType),CStr(sResult)

End Sub


--- </snip> ---

Caveat Emptor. Calling api's from script is risky business, and should only
be attempted by those who are willing to suffer extreme dis-respect from
professional scripters...

mit groß Verlegenheit, jw


mr unreliable

unread,
Oct 29, 2004, 3:12:35 PM10/29/04
to
Upon further consideration, I can name-that-tune,
er, write-that-script in 7 lines of code:

--- <snip> ---
' use DynaWrap to show/hide the system cursor (take III), jw 29Oct04

Option Explicit

Dim oDW : Set oDW = CreateObject("DynamicWrapper")
oDW.Register "USER32.DLL", "ShowCursor", "i=l", "f=s", "r=l" ' declare
api

MsgBox("Achtung, Vorsicht!, your cursor is about to be HIDDEN (gasp!)...
")

Call oDW.ShowCursor(CLng(False)) ' hide the system cursor

MsgBox("If all went well, you should be seeing _NO_ cursor" & vbCrLf &
vbCrLf _
& " Now click OK (by pressing the enter key) to see system cursor
again... ")

Call oDW.ShowCursor(CLng(True)) ' (hopefully) show the system cursor
again

WScript.Quit
--- </snip> ---

mfg, jw


Rupert Hildenbrand

unread,
Nov 2, 2004, 9:11:34 AM11/2/04
to
if I run Take III, I get an error in line 2: Dim oDW: Set oDW =
CreateObject("DynamicWrapper")

the message is: ActiveX cannot create object

Thanks for your great effort
Rupert

"mr unreliable" <ReplyToN...@notmail.com> schrieb im Newsbeitrag
news:eCZSypev...@TK2MSFTNGP14.phx.gbl...

0 new messages