1,486
社区成员
发帖
与我相关
我的任务
分享
'basAPI
'****for nodeclick
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long '这个是设置鼠标的位置!
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) '定义鼠标事件
Public Const MOUSEEVENTF_LEFTDOWN As Long = &H2
Public Const MOUSEEVENTF_LEFTUP As Long = &H4
'for get treeitem position
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
'for test
Public Property Get Left() As Long
Left = Forms(m_strTreeWnd).WindowLeft + Forms(m_strTreeWnd).Controls(m_strTreCtl).Left
End Property
'for test
Public Property Get Top() As Long
Top = Forms(m_strTreeWnd).WindowTop + Forms(m_strTreeWnd).Controls(m_strTreCtl).Top
End Property
Public Sub NodeClick(ByVal nodX As MSComctlLib.Node, trcX As CTreeCtl)
Dim rc As RECT
rc.Left = GetHTreeItem(nodX, trcX)
Call SendMessage(trcX.HTvw, TVM_GETITEMRECT, True, rc)
' Call SetCursorPos(trcX.Left + rc.Left, trcX.Top + rc.Top)
Call SetCursorPos(147 + rc.Left, 191 + rc.Top + 12) '现在只好这样写,晕死了
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub
Private Function GetHTreeItem(ByVal nodX As MSComctlLib.Node, trcX As CTreeCtl) As Long
nodX.Selected = True
GetHTreeItem = SendMessage(trcX.HTvw, TVM_GETNEXTITEM, TVGN_CARET, 0)
End Function
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long '这个是设置鼠标的位置!
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) '定义鼠标事件
Dim i As Long
'vb模拟鼠标在屏幕的x = 10 : y = 20 的位置上点击一下左键
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 2000 '2秒
End Sub
Private Sub Timer1_Timer()
Call SetCursorPos(10, 20) '让鼠标移动到(10,20)
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '模拟鼠标的左键单击!
i = i + 1
Print "点击屏幕" & i
End Sub