-
Jun 27th, 2021, 08:12 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Hourglass - again
Is there an issue running the following
Code:
Me.MousePointer = vbHourglass
or
Code:
Me.MosePointer = vbDefault
on Windows 10.
I tried in a test program, when it didn't work in my real program. The cursor never changed. I know my long routine takes between 5 to 10 seconds depending on the input.
Thanks
-
Jun 27th, 2021, 08:25 AM
#2
Thread Starter
Fanatic Member
Re: Hourglass - again
Follow up. I tried this in the IDE, and in an .exe. Still no change
-
Jun 27th, 2021, 11:37 AM
#3
Re: Hourglass - again
No issue here.
(apart from a TYPo you've written/pasted)
Code:
Me.MoUsePointer = vbDefault
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.
-
Jun 27th, 2021, 11:40 AM
#4
Thread Starter
Fanatic Member
Re: Hourglass - again
That's what I thought. But it does not work for me.
-
Jun 27th, 2021, 11:41 AM
#5
Re: Hourglass - again
Your subject says "again" Is this some ongoing issue that you've posted about before? If so, can you link to any previous thread(s) where this has been discussed?
-
Jun 27th, 2021, 12:03 PM
#6
Thread Starter
Fanatic Member
Re: Hourglass - again
No. I seen other posts referring to the mouse pointer being changed. That was what the 'again' referred to.
-
Jun 27th, 2021, 12:11 PM
#7
Thread Starter
Fanatic Member
Re: Hourglass - again
However, I think I know what the problem is.
I set the pointer to hourglass for form2 from form1.
In form 1
set form1 = nothing
unload form1
set the mp for form2 to hourglass
show form2
In form 2 all before the form_load completes
do all my calcs, etc
set the mp for form2 to to default
Oh, I think I just found the answer. Do the calcs in form 1, with he mp set for form1, then switch to form2. I'll try that
AND yes I do know that when in Windows 10, the "hourglass" displays as a rotating circle.
-
Jun 27th, 2021, 02:04 PM
#8
Hyperactive Member
Re: Hourglass - again
I copied the file from: \ WINDOWS \ Cursors \ hourglas.ani WindowsXP to the application folder. And I wrote the following code to change the cursor. When the application starts, the cursor changes to an animated hourglass and after the program finishes, the cursor changes back.
Code:
Option Explicit
Private Declare Function CopyCursor Lib "user32" Alias "CopyIcon" (ByVal hcur As Integer) As Integer
Private Declare Function GetCursor Lib "user32" () As Integer
Private Declare Function LoadCursorFromFile Lib "user32" Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As Integer
Private Declare Function SetSystemCursor Lib "user32" (ByVal hcur As Integer, ByVal id As Integer) As Integer
Private Const OCR_NORMAL = 32512
Dim hCursor As Long, hOldCursor As Long
Dim lRet As Long
Private Sub Form_Load()
Dim lRet As Long
hCursor = LoadCursorFromFile(App.Path & "\hourglas.ani")
If hCursor Then
lRet = GetCursor()
hOldCursor = CopyCursor(lRet)
lRet = SetSystemCursor(hCursor, OCR_NORMAL)
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
lRet = SetSystemCursor(hOldCursor, OCR_NORMAL)
End Sub
-
Jun 27th, 2021, 02:53 PM
#9
Thread Starter
Fanatic Member
Re: Hourglass - again
Argus19 Thanks. Please explain to me what happened? Is it Windows 10?
I tried the old fashioned way "Me.MousePointer = VB[ANYTHING ELSE|. from 1 to 10. Same results - no change. Your method worked as needed. I think you treated the pointer I needed as a user defined one?
-
Jun 27th, 2021, 03:01 PM
#10
Hyperactive Member
Re: Hourglass - again
Originally Posted by AccessShell
I think you treated the pointer I needed as a user defined one?
Yes. I used for Win 7. The cursor file is loaded and installed as a system file. I don't know if Win 10 has an hourglass cursor.
https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx
-
Jun 27th, 2021, 03:17 PM
#11
Thread Starter
Fanatic Member
Re: Hourglass - again
I guess I'm not done. The cursor changes to an hourglass with the code you gave me. It does not however change back. I also think, when it is an hourglass, I have do disable all buttons, and minimize and X-out.
I also noticed, while I was trying to fix the problem, I placed a label box on the form. I was originally set to visible = false. Just before your code, I tried to make the box visible, is never would become visible.
-
Jun 27th, 2021, 03:21 PM
#12
Thread Starter
Fanatic Member
Re: Hourglass - again
OK, when I walk through the program, on the line of code that should make it the default (OCR_NORMAL), it becomes an I-beam.
If I let it go, with walking through it, it stays an hourglass.
-
Jun 27th, 2021, 03:31 PM
#13
Hyperactive Member
Re: Hourglass - again
When you need to change the system cursor, you can use the existing cursors.
When you exit the program or after the hourglass is no longer needed, you can do the same:
Code:
hCursor = LoadCursorFromFile("c:\Windows\Cursors\arrow_rm.cur")
lRet = SetSystemCursor(hCursor, OCR_NORMAL)
In Win 7, the cursor becomes a black arrow.
-
Jun 27th, 2021, 03:46 PM
#14
Thread Starter
Fanatic Member
Re: Hourglass - again
Win 7 may have been black, But mine in WIN 10 was white.
-
Jun 27th, 2021, 04:27 PM
#15
Re: Hourglass - again
I'm not sure what sort of pachinko machine you have created, but this demo maintains order and seems to work just fine.
Normally dialog Forms should be opened modally. But here I added the plumbing to do it modelessly to allow the hourglass cursor to show... but safely as well.
Code:
Option Explicit
'Just one control: Command1
Private MyEnabled As Boolean
Private MyLevel As Integer
Private MyOwner As MyForm
Public Sub CloseDialog()
MousePointer = vbDefault
ControlsEnabled = True
End Sub
Public Sub OpenDialog(ByVal Owner As MyForm, ByVal Level As Integer)
MyLevel = Level
Set MyOwner = Owner
Show vbModeless, Owner 'Triggers our Load event.
End Sub
Private Property Let ControlsEnabled(ByVal RHS As Boolean)
'Don't disable the Form itself as we'd typically do, because we want to
'see the hourglass cursor.
Dim Control As Control
For Each Control In Controls
Control.Enabled = RHS
Next
MyEnabled = RHS
End Property
Private Sub Command1_Click()
ControlsEnabled = False
MousePointer = vbHourglass
With New MyForm
.OpenDialog Me, MyLevel + 1
End With
Debug.Print "Command1_Click of " & Caption
End Sub
Private Sub Form_Initialize()
MyEnabled = True
End Sub
Private Sub Form_Load()
Caption = Caption & " Level " & CStr(MyLevel)
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = vbFormControlMenu Then
Cancel = Not MyEnabled
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Not MyOwner Is Nothing Then MyOwner.CloseDialog
End Sub
Here we have just one Form named MyForm that spawns nested instances of itself on demand at deeper and deeper levels. Cursor seems to appear just as expected on Windows 10.
-
Jun 27th, 2021, 05:47 PM
#16
Thread Starter
Fanatic Member
Re: Hourglass - again
Somehow, putting the mouse pointer change code into a dedicated function, I can not change between the default and the hourglass pointer. the code is simple Me.MousePointer = vbHourglass (or vbDefault). I don't understand what that would make it work.
I am also not sure if I now have the default cursor I had before I used the used the API calls suggested by Argus19.
-
Jun 28th, 2021, 02:41 AM
#17
Re: Hourglass - again
Can you post a (minimal) sample project that reproduces the problem with Me.MousePointer?
Here is one which show the problem with setting Screen.MousePointer in a VB6 application: HourglassProblem.zip
1. Open and start the project in VBIDE
2. Minimize everything (incl. VBIDE) but Form1
3. Move mouse to upper left corner
4. Press the button with keyboard (spacebar or Enter)
5. Notice that mouse pointer does not become hourglass until you move it over Form1 or Form2
This is a normal behavior/shortcoming on the VB6 Forms subsystem -- the "global" cursor shape changes only when being hovered over hwnds of the current application.
cheers,
</wqw>
-
Jun 28th, 2021, 04:25 AM
#18
Re: Hourglass - again
Screen.MousePointer is for system-wide indication. Most applications should not use it.
-
Jun 28th, 2021, 07:51 AM
#19
Thread Starter
Fanatic Member
Re: Hourglass - again
I don't recall using screen.mousepointer.. I am now using me.mousepointer. WHy it didn't work before and does now, I do not know. All I know, now, is that the mouse pointer changes to hourglass (yes, a real hourglass, rather and the rotating circle for WIN 19), and then changes back to the pointer.
-
Jul 2nd, 2021, 11:45 PM
#20
Fanatic Member
Re: Hourglass - again
Originally Posted by Argus19
When you need to change the system cursor, you can use the existing cursors.
When you exit the program or after the hourglass is no longer needed, you can do the same:
Code:
hCursor = LoadCursorFromFile("c:\Windows\Cursors\arrow_rm.cur")
lRet = SetSystemCursor(hCursor, OCR_NORMAL)
In Win 7, the cursor becomes a black arrow.
The only difference between cur and ico is the mark bit on the file. The third byte of ico is 1, and the third byte of cur is 2.
Open "xxx.cur" For Binary As #1
Put #1, 3, 1 '
Close #1 '
After this operation, the cur format file becomes the ico format file (note that the file format has nothing to do with the extension, the extension is only the suffix part of the file name, and the internal recognition of the file format in VB is based on the header file identification, not the extension), At this time, import the xxx.cur file into the custom cursor of VB and it will not turn black anymore
can fixed becomes a black
-
Jul 3rd, 2021, 07:24 AM
#21
Thread Starter
Fanatic Member
Re: [RESOLVED] Hourglass - again
Thanks ccdoc123, I'll check it out.
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
|