Results 1 to 21 of 21

Thread: [RESOLVED] Hourglass - again

  1. #1

    Thread Starter
    Hyperactive Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    464

    Resolved [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

  2. #2

    Thread Starter
    Hyperactive Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    464

    Re: Hourglass - again

    Follow up. I tried this in the IDE, and in an .exe. Still no change

  3. #3
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,575

    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.



  4. #4

    Thread Starter
    Hyperactive Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    464

    Re: Hourglass - again

    That's what I thought. But it does not work for me.

  5. #5
    Frenzied Member
    Join Date
    Nov 2017
    Posts
    1,657

    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?

  6. #6

    Thread Starter
    Hyperactive Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    464

    Re: Hourglass - again

    No. I seen other posts referring to the mouse pointer being changed. That was what the 'again' referred to.

  7. #7

    Thread Starter
    Hyperactive Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    464

    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.

  8. #8
    Hyperactive Member
    Join Date
    Jul 2020
    Posts
    283

    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

  9. #9

    Thread Starter
    Hyperactive Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    464

    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?

  10. #10
    Hyperactive Member
    Join Date
    Jul 2020
    Posts
    283

    Re: Hourglass - again

    Quote Originally Posted by AccessShell View Post
    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

  11. #11

    Thread Starter
    Hyperactive Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    464

    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.

  12. #12

    Thread Starter
    Hyperactive Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    464

    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.

  13. #13
    Hyperactive Member
    Join Date
    Jul 2020
    Posts
    283

    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.

  14. #14

    Thread Starter
    Hyperactive Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    464

    Re: Hourglass - again

    Win 7 may have been black, But mine in WIN 10 was white.

  15. #15
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,825

    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.

  16. #16

    Thread Starter
    Hyperactive Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    464

    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.

  17. #17
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,281

    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>

  18. #18
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,825

    Re: Hourglass - again

    Screen.MousePointer is for system-wide indication. Most applications should not use it.

  19. #19

    Thread Starter
    Hyperactive Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    464

    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.

  20. #20
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    531

    Re: Hourglass - again

    Quote Originally Posted by Argus19 View Post
    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

  21. #21

    Thread Starter
    Hyperactive Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    464

    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
  •  



Click Here to Expand Forum to Full Width