7,785
社区成员




Public Function GetCursorShape() As Long
Dim Pt As POINTAPI
Call GetCursorPos(Pt)
Dim hWindow As Long
hWindow = WindowFromPoint(Pt.x, Pt.y)
Dim name As String * 256
Call GetWindowText(hWindow, name, 256)
Dim dwThreadID As Long
dwThreadID = GetWindowThreadProcessId(hWindow, 0)
Dim dwCurrentThreadID As Long
dwCurrentThreadID = GetCurrentThreadId
Dim hc As Long
If dwCurrentThreadID <> dwThreadID Then
If AttachThreadInput(dwCurrentThreadID, dwThreadID, True) Then
hc = GetCursor
Call AttachThreadInput(dwCurrentThreadID, dwThreadID, False)
End If
Else
hc = GetCursor
End If
Dim ii As ICONINFO
Call GetIconInfo(hc, ii)
Dim L As Long
L = 1024
Static bytes() As Byte
ReDim bytes(1 To L)
Dim length As Long
length = GetBitmapBits(ii.hbmColor, L, bytes(1))
Debug.Assert length < L
Dim arr(0 To 1) As Long
Dim i As Long
For i = LBound(arr) To UBound(arr)
arr(i) = 0
Next
For i = 1 To length
Dim j As Long
j = bytes(i)
Dim m As Long
For m = 1 To 8
Dim k As Long
k = j Mod 2
arr(k) = arr(k) + 1
j = j \ 2
Next
Next
Dim result As String
result = ""
For i = LBound(arr) To UBound(arr)
result = result & arr(i)
Next
Debug.Print Pt.x, Pt.y, result, Now, name
GetCursorShape = CLng(result)
End Function
这是我获取鼠标形状的代码,其中hc就是HCURSOR,这样获得的hc和GetCursorInfo获得的hc应该一样吧?
我跟踪过,发现每次程序启动后这个hc都不一样。。Option Explicit
Private Sub Command1_Click()
Me.MousePointer = vbUpArrow '向上的箭头
Debug.Print Me.MousePointer
End Sub