'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/
|