vb实现输入窗口句柄就能找到指定窗口并显示窗口信息的程序
1个回答
推荐于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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询