• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 503
  • Last Modified:

How can I hide or change mouse cursor in VB6?

I have a theater PC using ZoomPlayer.  Every time someone bumps the mouse the cursor appears for a second.  I want to make a program that hides the mouse until the program is called again with the unhide parameter.  I'm using VB6, I was wondering if anyone knew how to do that.  I tried the common example I found while Googling where you call the ShowCursor function.  It works when I run it in the VB6 GUI editor but when I save and compile it, it doesn't work.

Any ideas?  I also tried making a blank mouse cursor and found in the registry where to change it but even when I change the reg, it doesn't update the cursor in realtime so that's a no-go too.
0
MOITExperts
Asked:
MOITExperts
1 Solution
 
DarkoLordCommented:
To hide it, try this (and ShowCursor(1) to display it):

While ShowCursor(0) >= 0: Wend

Every time it is shown, the "display counter" is increased, and vice versa. That means sometimes you have to execute it more than once until it actually gets hidden
0
 
Mark_FreeSoftwareCommented:

another solution would be to set up a mouse hook, and cancel all mouse move messages
0
 
Frosty555Commented:
ShowCursor is a WinAPI function, so you'll need to declare it first.
      Declare Function ShowCursor& Lib "user32" (ByVal bShow As Long)
Then in a function or a button call it like DarkoLord suggested:
      ShowCursor(0) to hide
      ShowCursor(1) to show again.

Two things to keep in mind:

1) This call is system-wide. If you never call showcursor(1), the cursor will remain invisible even after you exit VB.

2) The visibility of the cursor is based on a COUNTER, not just a true/false flag. When you call ShowCursor(), it returns a number which represents the current state of the cursor visibility counter. If it is less than zero, the cursor is invisible. Greater than or equal to zero and the cursor is visible.

Example:

? ShowCursor(0)
returns -1, cursor disappears
? ShowCursor(0)
returns -2, cursor stays invisible
? ShowCursor(0)
returns -3, cursor stays invisible
? ShowCursor(1)
returns -2, cursor is *still* invisible
? ShowCursor(1)
returns -1, cursor is *still* invisible
? ShowCursor(1)
returns 0, cursor is visible again.

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Frosty555Commented:
http://www.gpwiki.org/index.php/Files:VB_ToggleCursor.zip

Is an example project that does pretty much exactly what you wanted. Toggles the mouse cursor on and off with a button.
0
 
Frosty555Commented:
Hmmm... reading DarkoLord's post more carefully, he covered everything I covered above.

So if it works for you, kindly award the points to DarkoLord.
0
 
MOITExpertsAuthor Commented:
Hmm didn't seem to make a difference.  The project has just one module with this in it:

Private Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long

Sub Main()
  If Command$ = "hide" Then
    While ShowCursor(0) >= 0: Wend
  Else
    ShowCursor (1)
  End If
End Sub

When I set the command line in the proj props to "hide" and run it, the mouse disappears like it is supposed to.  I remove the hide and run it, and it comes back.  I compile it then run the .EXE and pass "hide" and it doesn't do anything.  I've found an alternate solution since then to my general problem; I just swap the active cursor for blank cursors heh.  Doesn't really explain why this isn't working though.  

-shrug-
0
 
Mark_FreeSoftwareCommented:

you can try to insert a messagebox, maybe ther is something wrong with the command line test?
0
 
Frosty555Commented:
No, ShowCursor() is only valid for the current process.

You can test this by running your project from VB, and then ALT+Tabbing over to a new window, like IE. The cursor comes back. So, when a cursor is hidden, it *isn't* quite system global. That's odd, it used to be that way in Win98 if I recall correctly.
0
 
Frosty555Commented:
Is there a reason why you can't, perhaps, just have the program run and set the cursor's position to be on the right edge of the screen every half a second?

E.g:

Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Sub Timer1_Timer()
    SetCursorPos 99999, 300
End Sub

The cursor would be set to the right edge of the desktop, showing only a few black pixels on the edge of the mouse cursor. If the user bumps the mouse, it will appear briefly and then disappear half a second later when it's position is reset.

I was thinking you could put the cursor in the bottom right (call SetCursorPos with 99999,99999), but maybe that causes a menu in ZoomPlayer to pop up. The rightmost edge of the screen shouldn't cause any problems though.

When you're done watching your movie, you exit the program.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now