2

I am doing some automation work to do repeated copy paste work. Sometimes the server will be so slow. In that time i would be using the below code to wait until the cursor wait goes to normal

Option Explicit

Private Const IDC_WAIT As Long = 32514

Private Type POINT
x As Long
y As Long
End Type

Private Type CURSORINFO
cbSize As Long
flags As Long
hCursor As Long
ptScreenPos As POINT
End Type

Private Declare Function GetCursorInfo _
Lib "user32" (ByRef pci As CURSORINFO) As Boolean
Private Declare Function LoadCursor _
Lib "user32" Alias "LoadCursorA" _
(ByVal hInstance As Long, ByVal lpCursorName As Long) As Long

Public Function IsWaitCursor() As Boolean

' Get handle to wait cursor
Dim handleWaitCursor As Long
handleWaitCursor = LoadCursor(ByVal 0&, IDC_WAIT)

Dim pci As CURSORINFO
pci.cbSize = Len(pci)

' Retrieve information about the current cursor
Dim ret As Boolean
ret = GetCursorInfo(pci)

If ret = False Then
    MsgBox "GetCursorInfo failed", vbCritical
    Exit Function
End If

' Returns true when current cursor equals to wait cursor
IsWaitCursor = (pci.hCursor = handleWaitCursor)

End Function

The above code worked fine for me in MS Excel 2013 32-bit. But now I am using MS Excel 64-bit and the above code is not working. Someone please tell me what needs to be done

braX
  • 11,506
  • 5
  • 20
  • 33
Varadharajan
  • 78
  • 1
  • 8
  • 1
    When you say: **code is not working**, is it throwing an error? or is it not waiting? – Zac Oct 16 '18 at 11:36
  • 3
    See here https://stackoverflow.com/a/5514745/7599798 – FunThomas Oct 16 '18 at 11:40
  • 1
    Possible helpful, too - citation: *"LongPtr is the perfect type for any pointer or handle in your Declare Statement. ... Do not forget a very important detail: Not only your `Declare` statement should be written with the `LongPtr` data type, your procedures calling the external API function must, in fact, use the `LongPtr` type as well "* - see [Windows API declaration VBA 64 bit](https://codekabinett.com/rdumps.php?Lang=2&targetDoc=windows-api-declaration-vba-64-bit). – T.M. Oct 17 '18 at 16:59

1 Answers1

2
Private Const IDC_WAIT As Long = 32514
Private Type POINT
X As Long
Y As Long
End Type

Private Type CURSORINFO
cbSize As Long
flags As Long
hCursor As LongPtr
ptScreenPos As POINT
End Type

Private Declare PtrSafe Function GetCursorInfo _
Lib "User32" (ByRef pci As CURSORINFO) As Boolean
Private Declare PtrSafe Function LoadCursor Lib "User32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As LongPtr

Public Function IsWaitCursor() As Boolean

' Get handle to wait cursor
Dim handleWaitCursor As LongPtr
handleWaitCursor = LoadCursor(ByVal 0&, IDC_WAIT)

Dim pci As CURSORINFO
pci.cbSize = Len(pci)

' Retrieve information about the current cursor
Dim ret As Boolean
ret = GetCursorInfo(pci)

If ret = False Then
    MsgBox "GetCursorInfo failed", vbCritical
    Exit Function
End If

' Returns true when current cursor equals to wait cursor
IsWaitCursor = (pci.hCursor = handleWaitCursor)

End Function

The above code worked for me. I changed the Long datatype to LongPtr

Varadharajan
  • 78
  • 1
  • 8