Results 1 to 24 of 24

Thread: Show Hourglass - or Wait Cursor

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,297

    Show Hourglass - or Wait Cursor

    What's the command for Hourglass on /off please?

    I have Screen.MousePointer = vbHourglass

    But that does nothing.

    Thanks

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,839

    Re: Show Hourglass - or Wait Cursor

    I'm not sure why you want to imply that Windows is busy. Assign to the active Form's MousePointer property instead.

    And yes, for that to take effect you must return from the current event handler. Avoid calling the DoEvents() function if at all possible.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,297

    Re: Show Hourglass - or Wait Cursor

    Must be something odd about Vb6 Hourglass. No one (not even Google) seem to want to tell you how it's turned of of off. Sigh...

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    4,702

    Re: Show Hourglass - or Wait Cursor

    There is nothing odd.

    In a form the code I would use and it just works
    Code:
    ' Show hourglass
    Me.MousePointer = vbHourglass
    ' Back to normal
    Me.MousePointer = vbNormal
    The same for turning the changing the global mousepointer
    Code:
    ' Show hourglass
    Screen.MousePointer = vbHourglass
    ' Back to normal
    Screen.MousePointer = vbNormal
    What doesn't work for you?

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,297

    Re: Show Hourglass - or Wait Cursor

    That's weird, I have exactly that but it does nothing.
    Or - does it only work at runtime when compiled ?

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    4,702

    Re: Show Hourglass - or Wait Cursor

    The most basic sample using a form with 2 commandbuttons:
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
      Me.MousePointer = vbHourglass
    End Sub
    
    Private Sub Command2_Click()
      Me.MousePointer = vbNormal
    End Sub
    Does for me what it should do..

  7. #7
    Lively Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    83

    Re: Show Hourglass - or Wait Cursor

    Yes, just tested it in the IDE and also as Compiled, it's working as it should.
    (VB6 SP6 on Windows 7 64-bit)

  8. #8
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    8,025

    Re: Show Hourglass - or Wait Cursor

    Quote Originally Posted by AlexanderBB View Post
    That's weird, I have exactly that but it does nothing.
    Or - does it only work at runtime when compiled ?

    If you have nothing IN BETWEEN those lines, then NO, you won't see it change.

    put some code after the first line to DO SOMETHING that may take a second or more, then add the second line.

    Do a search in MSDN on vbHourGlass
    Sam I am (as well as Confused at times).

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,297

    Re: Show Hourglass - or Wait Cursor

    I spent a long time Googling VB6 Hourglass but didn't find what I wanted.
    Here is it working in vba Excel

    Sub showHourglass()
    Stop
    Application.Cursor = xlWait
    Stop
    Application.Cursor = xlDefault

    End Sub

    But in VB6

    Sub showHourglass()
    Stop
    Screen.MousePointer = vbHourglass
    Stop
    Screen.MousePointer = vbHourglass
    End Sub

    Stepping through this here in Excel shows the cursor changing but it does absolutely nothing in Vb6.
    Does it work for you guys ?

  10. #10
    PowerPoster
    Join Date
    Feb 2017
    Posts
    3,403

    Re: Show Hourglass - or Wait Cursor

    Quote Originally Posted by dilettante View Post
    I'm not sure why you want to imply that Windows is busy. Assign to the active Form's MousePointer property instead.

    And yes, for that to take effect you must return from the current event handler. Avoid calling the DoEvents() function if at all possible.
    Screen.MousePointer is not applied to Windows but just to your program, what is usually what the programmer wants since VB6 is single threaded (and cannot do anything with any form while it is busy).

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,297

    Re: Show Hourglass - or Wait Cursor

    What do you mean - is not applied to Windows but just to your program ? I want to change the cursor when the VB6 program is running - and doing a task where showing the hourglass would be appropriate.
    But I'm rapidly giving up on the idea!

  12. #12
    PowerPoster
    Join Date
    Feb 2017
    Posts
    3,403

    Re: Show Hourglass - or Wait Cursor

    Quote Originally Posted by AlexanderBB View Post
    What do you mean - is not applied to Windows but just to your program ?
    That if the user changes to another program (for example with Alt+Tab) the MousePointer is not what you have set.
    What you have set with Screen.MousePointer only applies to your program.

    Quote Originally Posted by AlexanderBB View Post
    But I'm rapidly giving up on the idea!
    ???

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,297

    Re: Show Hourglass - or Wait Cursor

    > What you have set with Screen.MousePointer only applies to your program.
    That's what is wanted.
    But it isn't changing to an hourglass is the point.

  14. #14
    PowerPoster
    Join Date
    Feb 2017
    Posts
    3,403

    Re: Show Hourglass - or Wait Cursor

    Quote Originally Posted by AlexanderBB View Post
    But it isn't changing to an hourglass is the point.
    Post a sample project where it is not working.

  15. #15
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,704

    Re: Show Hourglass - or Wait Cursor

    Yeah, I'm not sure what you are seeing, where you are calling it from or why you have the stops in there but the code does show the wait cursor. On this Windows 10 system it is the spinning circle that gets shown a bit hard to see with those stops in there as it throws up the IDE on each of them but once you go back to the form it is showing the wait cursor.

    Get rid of the stops, place a call to set the hourglass under one button and back to default under another button and you will be able to see it work with ease.

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Screen.MousePointer = vbHourglass
    End Sub
    
    Private Sub Command2_Click()
    Screen.MousePointer = vbDefault
    End Sub

  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,297

    Re: Show Hourglass - or Wait Cursor

    The stops were just to enable stepping with F8. In Excel you see the hourglass appear then revert back to the default.
    In VB6 nothing happens.. but I'm just wondering does it only work in code behind a Form?
    In my project I have no Form and the code (in msg #9) is called from Sub Main ()

  17. #17
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,704

    Re: Show Hourglass - or Wait Cursor

    No the code does not need to be part of the form but if there is no form loaded you may not see anything.
    In a module
    Code:
    Option Explicit
    
    Sub Showhourglass()
    Screen.MousePointer = vbHourglass
    End Sub
    Sub HideHourglass()
    Screen.MousePointer = vbDefault
    End Sub
    In a form
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Showhourglass
    End Sub
    
    Private Sub Command2_Click()
    HideHourglass
    End Sub
    Works the same as if it were behind the form.
    If you are trying to get it to display an hourglass before you first form is loaded then you should probably rethink what you are doing and allow the form (or a form) to display right away then do whatever process requires the wait cursor.

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,297

    Re: Show Hourglass - or Wait Cursor

    > if there is no form loaded you may not see anything.

    That probably explains it. I have no Form, as none is needed.
    In Excel you don't need a form, the hourglass just works so I was looking for the same functionality.
    No major... will just have to do without it.

  19. #19
    PowerPoster
    Join Date
    Feb 2017
    Posts
    3,403

    Re: Show Hourglass - or Wait Cursor

    OK, then try this:
    Code:
    Private Declare Function SetCursor Lib "user32.dll" (Optional ByVal hCursor As Long) As Long
    Private Declare Function LoadCursorW Lib "user32.dll" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
    Private Const IDC_WAIT As Long = 32514
    
    Public Sub Main()
        SetCursor LoadCursorW(0&, IDC_WAIT) ' instead of Screen.MousePointer
        ' .....
    
    End Sub

  20. #20

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,297

    Re: Show Hourglass - or Wait Cursor

    Should that work at design time ?
    I've put the declarations in and running this from Sub Main
    Code:
    Sub Main()
    showHourglass
    Exit Sub
    
    Sub showHourglass()
    Stop
     SetCursor LoadCursorW(0&, IDC_WAIT) ' instead of Screen.MousePointer
    
        Stop
      Screen.MousePointer = vbHourglass
    End Sub
    I get to the stop and press F8 but the cursor doesn't change from 'I' .
    No errors are generated.

  21. #21
    PowerPoster
    Join Date
    Feb 2017
    Posts
    3,403

    Re: Show Hourglass - or Wait Cursor

    It will restore the mouse pointer when goes to break mode.

    Code:
    Private Declare Function SetCursor Lib "user32.dll" (Optional ByVal hCursor As Long) As Long
    Private Declare Function LoadCursorW Lib "user32.dll" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
    Private Const IDC_WAIT As Long = 32514
    
    Sub Main()
        showHourglass
    End Sub
    
    Sub showHourglass()
        Stop
        SetCursor LoadCursorW(0&, IDC_WAIT) ' instead of Screen.MousePointer
        
        Dim c
        For c = 1 To 1000000000
        Next
        
        Stop
    End Sub

  22. #22

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,297

    Re: Show Hourglass - or Wait Cursor

    Yes, I'm getting the same thing now. Thank you.

  23. #23
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,704

    Re: Show Hourglass - or Wait Cursor

    Quote Originally Posted by AlexanderBB View Post
    > if there is no form loaded you may not see anything.

    That probably explains it. I have no Form, as none is needed.
    In Excel you don't need a form, the hourglass just works so I was looking for the same functionality.
    No major... will just have to do without it.
    I would assume that in Excel it is setting the cursor for the excel application which does have stuff displayed. In the case of a VB app if you have not loaded a form then there is no visual aspect there. Keep in mind that when you are running VBA code in Excel or other product you are running that product with your addon code but when you are running a VB app you are running just the code you added.

  24. #24

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,297

    Re: Show Hourglass - or Wait Cursor

    Yes, thanks understood now. Initially I couldn't understand why Hourglass wasn't coming on.

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