gpt4 book ai didi

excel - 让我的代码等到光标加载 MS Excel 2016

转载 作者:行者123 更新时间:2023-12-04 20:10:04 24 4
gpt4 key购买 nike

我正在做一些自动化工作来重复复制粘贴工作。有时服务器会很慢。那时我将使用下面的代码等到光标等待恢复正常

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

上面的代码在 MS Excel 2013 32 位中对我来说很好。但现在我使用的是 MS Excel 64 位,上面的代码不起作用。有人请告诉我需要做什么

最佳答案

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

上面的代码对我有用。我更改了 数据类型为 长指针

关于excel - 让我的代码等到光标加载 MS Excel 2016,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52834470/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com