《VB》API如何获取窗口内控件的句柄?

 我来答
hejian511
2018-02-01 · TA获得超过846个赞
知道大有可为答主
回答量:1559
采纳率:0%
帮助的人:1474万
展开全部
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) 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
Dim n As POINTAPI
Dim a As Long
Private Sub Form_Load()
Timer1.Interval = 100
Label1.Caption = "移动鼠标指针"
End Sub

Private Sub Timer1_Timer()
GetCursorPos n
a = WindowFromPoint(n.x, n.y)
If a <> 0 Then
Dim s As String
s = String(100, Chr(0))
GetWindowText a, s, 100
Label1.Caption = "目标标题或文本: " & Trim(s)
Label2.Caption = "目标句柄为 " & a
End If
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式