这个很简单啊 Private Declare Function GetParent Lib "user32" Alias "GetParent" (ByVal hwnd As Long) As Long Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Type POINTAPI x As Long y As Long End Type Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long Private Const cch = 255 Private lpString As String * 256Private Sub Timer1_Timer() Dim PP As POINTAPI Dim myhwnd As Long myhwnd = GetCursorPos(PP) myhwnd = WindowFromPoint(PP.x, PP.y) Label1.Caption = "鼠标所在控件的句柄是:" & myhwnd Label2.Caption = "鼠标所在控件的文字是:" & Left(lpString, GetWindowText(myhwnd, lpString, cch)) Label3.Caption = "鼠标所在控件的父控件的句柄是:" & GetParent(myhwnd) Label4.Caption = "鼠标所在控件的父控件的文字是:" & Left(lpString, GetWindowText(GetParent(myhwnd), lpString, cch)) Label5.Caption = "鼠标所在控件的祖控件的句柄是:" & GetParent(GetParent(myhwnd)) Label6.Caption = "鼠标所在控件的祖控件的文字是:" & Left(lpString, GetWindowText(GetParent(GetParent(myhwnd)), lpString, cch)) End Sub
Private Declare Function GetParent Lib "user32" Alias "GetParent" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Const cch = 255
Private lpString As String * 256Private Sub Timer1_Timer()
Dim PP As POINTAPI
Dim myhwnd As Long
myhwnd = GetCursorPos(PP)
myhwnd = WindowFromPoint(PP.x, PP.y)
Label1.Caption = "鼠标所在控件的句柄是:" & myhwnd
Label2.Caption = "鼠标所在控件的文字是:" & Left(lpString, GetWindowText(myhwnd, lpString, cch))
Label3.Caption = "鼠标所在控件的父控件的句柄是:" & GetParent(myhwnd)
Label4.Caption = "鼠标所在控件的父控件的文字是:" & Left(lpString, GetWindowText(GetParent(myhwnd), lpString, cch))
Label5.Caption = "鼠标所在控件的祖控件的句柄是:" & GetParent(GetParent(myhwnd))
Label6.Caption = "鼠标所在控件的祖控件的文字是:" & Left(lpString, GetWindowText(GetParent(GetParent(myhwnd)), lpString, cch))
End Sub