Results 1 to 1 of 1

Thread: VB6 - Save Mousepointer

  1. #1

    Thread Starter
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796

    VB6 - Save Mousepointer

    Just a trivial bit of code to save and restore the mousepointer.

    It's quite common to set the mousepointer to an hourglass at the start of a long procedure, then set it back to default when you exit.

    But how do you know it was in the default state when your procedure was called? It may have been called from another time-consuming procedure that had already set it to the hourglass - which will not want it sent back as the default.

    Of course you can do this:

    VB Code:
    1. Sub MySub()
    2.  
    3.   Dim iOldMousePointer As Integer
    4.  
    5.   iOldMousePointer = Screen.MousePointer
    6.  
    7.   Screen.MousePointer = vbHourglass
    8.  
    9.   'Do lots of stuff.......
    10.  
    11.   Screen.MousePointer = iOldMousePointer
    12.  
    13.  
    14. End Sub

    But it's a lot less typing to do this:

    VB Code:
    1. Sub MySub()
    2.  
    3.   PushP
    4.  
    5.   'Do lots of stuff.......
    6.  
    7.   PopP
    8.  
    9. End Sub

    Just add this to a module:

    VB Code:
    1. Option Explicit
    2.  
    3. 'Store pushed and popped mouse pointers
    4. Private ScreenMousePointers As String
    5.  
    6. Public Sub PushP()
    7.  
    8.   'Saves the screen mousepointer then sets it to an hourglass
    9.   ScreenMousePointers = Format$(Screen.MousePointer, "00") & ScreenMousePointers
    10.   Screen.MousePointer = vbHourglass
    11.  
    12. End Sub
    13.  
    14. Public Sub PopP()
    15.  
    16.   'Restores the screen mousepointer to what it was before pushp was called
    17.   Dim s As String
    18.   Screen.MousePointer = Val(Left$(ScreenMousePointers, 2))
    19.   ScreenMousePointers = Mid$(ScreenMousePointers, 3)
    20.  
    21. End Sub


    Using Exit Sub in the middle of your procedure will mess it up of course, but that's not good practice anyway and I'm sure you never do it

    The pushes and pops must be in pairs and in the right order, but if you screw up nothing dramatic happens except you get the wrong mousepointer.

    Enjoy!
    Last edited by BrianHawley; Aug 21st, 2005 at 01:26 AM.
    Brian
    (Fighting with the RightToLeft bugs in VS 2005)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width