vb实现输入窗口句柄就能找到指定窗口并显示窗口信息的程序

 我来答
匿名用户
推荐于2016-02-15
展开全部
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 GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Command1_Click()
Dim n As Long
Dim str1 As String
Dim h As Long, h1 As String
Dim p As RECT
h1 = InputBox("请输入窗口句柄", , Me.hwnd)
If IsNumeric(h1) Then
If Int(h1) = Val(h1) Then
h = h1
Else
MsgBox "非整数"
Exit Sub
End If
Else
MsgBox "非整数"
Exit Sub
End If
str1 = String(255, 0)
n = GetWindowText(h, str1, 255)
If n <> 0 Then
MsgBox "窗口标题:" & Left(str1, InStr(str1, Chr(0)) - 1)
Else
MsgBox "错误"
End If

GetWindowRect h, p
MsgBox "窗口位置:Left=" & p.Left & " Top=" & p.Top & vbCrLf & "大小是:" & p.Right - p.Left & "X" & p.Bottom - p.Top
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式