[c++] vb 鼠标光标

[复制链接]
梅雷工具箱发表于 2015-6-25 13:21:53 | 显示全部楼层 |阅读模式
'VB获取窗口下,鼠标光标位置所在的控件句柄 声明
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorpos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type



'根据句柄取窗口标题 声明
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
                                                     (ByVal hwnd As Long, _
                                                     ByVal lpString As String, _
                                                     ByVal cch As Long) As Long


Private Sub Form_Load()


'VB获取窗口下,鼠标光标位置所在的控件句柄

Dim a As POINTAPI 'VB获取窗口下,鼠标光标位置所在的控件句柄
GetCursorpos a
  HwndVal = WindowFromPoint(a.X, a.Y)

  Dim MyStr As String '根据句柄取窗口标题
    MyStr = String(255, Chr$(0))
    GetWindowText HwndVal, MyStr, 255
    MyStr = Left$(MyStr, InStr(MyStr, Chr$(0)) - 1)

MsgBox  “窗口标题 ---> " & MyStr

End Sub



_____________________________________________________________________________ _

中磊UG二次开发教程 梅雷著 qq1821117007
学UG就上UG网 http://www.9sug.com/
就上UG网淘宝直营店
您需要登录后才可以回帖 登录 | 注册UG网 用百度帐号登录

本版积分规则