-
Sep 1st, 2021, 12:22 AM
#1
Thread Starter
Frenzied Member
Show Hourglass - or Wait Cursor
What's the command for Hourglass on /off please?
I have Screen.MousePointer = vbHourglass
But that does nothing.
Thanks
-
Sep 1st, 2021, 01:50 AM
#2
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.
-
Sep 1st, 2021, 02:23 AM
#3
Thread Starter
Frenzied Member
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...
-
Sep 1st, 2021, 02:59 AM
#4
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?
-
Sep 1st, 2021, 03:08 AM
#5
Thread Starter
Frenzied Member
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 ?
-
Sep 1st, 2021, 04:10 AM
#6
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..
-
Sep 1st, 2021, 05:32 AM
#7
Addicted Member
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)
-
Sep 1st, 2021, 07:39 AM
#8
Re: Show Hourglass - or Wait Cursor
Originally Posted by AlexanderBB
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).
-
Sep 1st, 2021, 06:17 PM
#9
Thread Starter
Frenzied Member
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 ?
-
Sep 1st, 2021, 07:01 PM
#10
Re: Show Hourglass - or Wait Cursor
Originally Posted by dilettante
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).
-
Sep 1st, 2021, 07:46 PM
#11
Thread Starter
Frenzied Member
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!
-
Sep 1st, 2021, 08:18 PM
#12
Re: Show Hourglass - or Wait Cursor
Originally Posted by AlexanderBB
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.
Originally Posted by AlexanderBB
But I'm rapidly giving up on the idea!
???
-
Sep 1st, 2021, 08:25 PM
#13
Thread Starter
Frenzied Member
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.
-
Sep 1st, 2021, 08:59 PM
#14
Re: Show Hourglass - or Wait Cursor
Originally Posted by AlexanderBB
But it isn't changing to an hourglass is the point.
Post a sample project where it is not working.
-
Sep 1st, 2021, 09:01 PM
#15
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
-
Sep 1st, 2021, 09:16 PM
#16
Thread Starter
Frenzied Member
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 ()
-
Sep 1st, 2021, 09:24 PM
#17
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.
-
Sep 1st, 2021, 09:33 PM
#18
Thread Starter
Frenzied Member
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.
-
Sep 1st, 2021, 09:56 PM
#19
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
-
Sep 1st, 2021, 10:14 PM
#20
Thread Starter
Frenzied Member
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.
-
Sep 1st, 2021, 10:20 PM
#21
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
-
Sep 1st, 2021, 10:43 PM
#22
Thread Starter
Frenzied Member
Re: Show Hourglass - or Wait Cursor
Yes, I'm getting the same thing now. Thank you.
-
Sep 2nd, 2021, 01:05 AM
#23
Re: Show Hourglass - or Wait Cursor
Originally Posted by AlexanderBB
> 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.
-
Sep 2nd, 2021, 01:10 AM
#24
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|