8 Replies Latest reply on Oct 3, 2017 8:35 AM by Matt Bieringer

    Set Wait Cursor with VBA

    Andrea Orlando

      Hi

       

      I want to set cursor to "wait"  when my VBA MACRO run (SolidWorks 2013); I have tried this code:

       

      Private Const IDC_WAIT As Long = 32512&
      Private Const IDC_ARROW As Long = 32514&
      Private Declare PtrSafe Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
      Private Declare PtrSafe Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
      Public Function SetCursorToWait(bWait As Boolean)
          If bWait = False Then
              SetCursor LoadCursor(0&, IDC_WAIT)
          Else
              SetCursor LoadCursor(0&, IDC_ARROW)
          End If
      End Function
      
      
      

       

      but don't work

       

      Any suggestion ? thanks

        • Re: Set Wait Cursor with VBA
          Amen Allah Jlili

          Are you running on a 64 or 32 bits system?

          • Re: Set Wait Cursor with VBA
            Andrea Orlando

            But at least is there a way to set the cursor to solidworks (even in the recent version) ?

              • Re: Set Wait Cursor with VBA
                Matt Bieringer

                Andrea, are you getting any errors when you run the code? I just tried it in multiple macros and it works perfectly for me. I even made a quick macro to just pause for 10 seconds and was able to turn the wait cursor off (normally would have been on).

                 

                edit: I am using solidworks 2017 on a Windows 7 64-Bit system.

                I have even made a few changes, so I can test out different styles of cursor and all of those seem to be working as well.

                Private Const IDC_WAIT As Long = 32514&         'HOURGLASS
                Private Const IDC_ARROW As Long = 32512&        'STD ARROW
                Private Const IDC_HAND As Long = 32649&         'HAND
                Private Const IDC_ARROWQMARK As Long = 32651&   'ARROW W/ QUESTION MARK
                Private Const IDC_ARROWWAIT As Long = 32650&    'ARROW W/ HOURGLASS
                Private Const IDC_CROSS As Long = 32515&        'CROSS
                Private Const IDC_IBEAM As Long = 32513&        'I-BEAM
                Private Const IDC_NOALLOW As Long = 32648&      'SLASHED CIRCLE
                Private Declare PtrSafe Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
                Private Declare PtrSafe Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
                Public Function SetCursorTo(cType As Long)
                Select Case cType
                    Case Is = 1
                        SetCursor LoadCursor(0&, IDC_ARROW)
                    Case Is = 2
                        SetCursor LoadCursor(0&, IDC_WAIT)
                    Case Is = 3
                        SetCursor LoadCursor(0&, IDC_HAND)
                    Case Is = 4
                        SetCursor LoadCursor(0&, IDC_ARROWQMARK)
                    Case Is = 5
                        SetCursor LoadCursor(0&, IDC_ARROWWAIT)
                    Case Is = 6
                        SetCursor LoadCursor(0&, IDC_CROSS)
                    Case Is = 7
                        SetCursor LoadCursor(0&, IDC_IBEAM)
                    Case Is = 8
                        SetCursor LoadCursor(0&, IDC_NOALLOW)
                End Select
                End Function
                
                
                  • Re: Set Wait Cursor with VBA
                    Andrea Orlando

                    I don't have any error.

                     

                    I have tryed the code in standalone format and don't work:

                     

                    Dim swApp As Object
                    
                    
                    Private Const IDC_WAIT As Long = 32512&
                    Private Const IDC_ARROW As Long = 32514&
                    Private Declare PtrSafe Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
                    Private Declare PtrSafe Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
                    Public Function SetCursorToWait(bWait As Boolean)
                        If bWait = False Then
                            SetCursor LoadCursor(0&, IDC_WAIT)
                        Else
                            SetCursor LoadCursor(0&, IDC_ARROW)
                        End If
                    End Function
                    
                    
                    Sub main()
                    
                    
                        Set swApp = Application.SldWorks
                        
                        SetCursorToWait False
                        'SetCursorToWait True
                    End Sub
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                      • Re: Set Wait Cursor with VBA
                        Matt Bieringer

                        The problem is the cursor is only visible when the macro is being run, as soon as it hits the end sub line it will change to whatever solidworks is using by default. Try adding a simple timer in and you should see the wait cursor.

                         

                        Dim time1, time2
                        time1 = Now
                        time2 = Now + TimeValue("0:00:05")
                            SetCursorTo (False)
                            Do Until time1 >= time2
                                time1 = Now()
                            Loop
                        

                        By the way you have the arrow and wait cursor codes mixed up.

                         

                        Wait is 32514 and the arrow is 32512.

                          • Re: Set Wait Cursor with VBA
                            Andrea Orlando

                            I have tryed this:

                             

                            Private Const IDC_WAIT As Long = 32514&         'HOURGLASS
                            Private Const IDC_ARROW As Long = 32512&        'STD ARROW
                            Private Const IDC_HAND As Long = 32649&         'HAND
                            Private Const IDC_ARROWQMARK As Long = 32651&   'ARROW W/ QUESTION MARK
                            Private Const IDC_ARROWWAIT As Long = 32650&    'ARROW W/ HOURGLASS
                            Private Const IDC_CROSS As Long = 32515&        'CROSS
                            Private Const IDC_IBEAM As Long = 32513&        'I-BEAM
                            Private Const IDC_NOALLOW As Long = 32648&      'SLASHED CIRCLE
                            Private Declare PtrSafe Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
                            Private Declare PtrSafe Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
                            Public Function SetCursorTo(cType As Long)
                            Select Case cType
                                Case Is = 1
                                    SetCursor LoadCursor(0&, IDC_ARROW)
                                Case Is = 2
                                    SetCursor LoadCursor(0&, IDC_WAIT)
                                Case Is = 3
                                    SetCursor LoadCursor(0&, IDC_HAND)
                                Case Is = 4
                                    SetCursor LoadCursor(0&, IDC_ARROWQMARK)
                                Case Is = 5
                                    SetCursor LoadCursor(0&, IDC_ARROWWAIT)
                                Case Is = 6
                                    SetCursor LoadCursor(0&, IDC_CROSS)
                                Case Is = 7
                                    SetCursor LoadCursor(0&, IDC_IBEAM)
                                Case Is = 8
                                    SetCursor LoadCursor(0&, IDC_NOALLOW)
                            End Select
                            End Function
                            
                            
                            Sub main()
                            
                            
                                Set swApp = Application.SldWorks
                                Dim time1, time2
                                time1 = Now
                                time2 = Now + TimeValue("0:00:05")
                                SetCursorTo (False)
                                Do Until time1 >= time2
                                    time1 = Now()
                                Loop
                            End Sub
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            

                            but don't work.

                             

                            I suppose that the problem is solidworks 2013 ...

                             

                            Thanks alot for your help Matt, I appreciated it.