在Excel VBA 2013中获取游标状态

问题描述 投票:3回答:2

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

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

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

例:

如果发生了什么事 睡2000年 万一

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

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

excel vba
2个回答
3
投票

您可以尝试使用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

0
投票

尝试检查screen.MousePointer属性,如果忙(沙漏)

While screen.MousePointer = 11
      Sleep(500)
Wend
© www.soinside.com 2019 - 2024. All rights reserved.