excel - 在 Excel VBA 2013 中获取光标状态

标签 excel vba

我创建了一个宏来执行一系列鼠标单击和鼠标移动(击键宏),以将重复数据输入 Oracle(程序/数据库)。

我以前使用Dataload Classic或Dataloader Classic(按键程序)将数据输入到Oracle中,但它缺乏“Smarts”,所以我创建了自己的带有一些“Smarts”的按键程序。

我使用 SLEEP 命令/函数在每次鼠标移动和单击鼠标后等待几秒/毫秒。有时Oracle会很慢并且“暂停”/“加载”/或“卡住”,并且卡住时间可能会超过SLEEP命令的初始等待时间并继续执行程序,从而搞乱一切。

示例:

如果某事发生,那么
sleep 2000
结束如果

在 DataLoad classic/Dataloader Classic 中,有一些选项可以更改每次鼠标单击或鼠标移动等可以等待/暂停的时间。有一个“沙漏检查”。这表示如果鼠标处于沙漏状态,您可以设置程序等待的时间,并且用户可以输入毫秒或秒。

是否有 Excel VBA 代码来检查鼠标的 HOURGLASS 状态?

最佳答案

您可以尝试以下使用win api函数的函数LoadCursor GetCursorInfo确定当前光标是否等于等待光标。

该函数首先加载win预定义的等待光标,然后获取当前光标并检查它们是否相同。 HTH

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

关于excel - 在 Excel VBA 2013 中获取光标状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34799287/

相关文章:

excel - 删除从 Excel 工作表中的任何数字开始的任何内容

Excel 2007 - 1004 运行时错误刷新查询表

VBA - 如何将新行命令 (\n) 或制表符命令 (\t) 发送到 PowerPointS 形状的 textbox.textrange.text

json - 网页抓取的内循环设计

python - 如何将空可选参数从 Python 传递到 Excel VBA 宏

vba - 参数数量错误或属性分配集合添加无效

vba - Outlook 2007 中的 ItemSend 事件中的密件抄送不再有效

vba - 优化 VBA 文本搜索

excel - 使用 VBA 自动调整行

vba - 用于复制单元格并将其粘贴到接下来的 2 个单元格的宏代码