vb.net遍历查找标题,一运行就出错退出,不知道原因
Dim lngDeskTopHandle As Integer
Dim strName As String = Space(255)
Dim a As Integer
Dim n As Integer
Dim hw7 As Integer
lngDeskTopHandle = GetDesktopWindow() 'Ok
hw7 = GetWindow(lngDeskTopHandle, GW_CHILD)
n = 0
Do While hw7 <> 0
n = n + 1
GetWindowText(hw7, strName, 255)
hw7 = GetWindow(hw7, GW_HWNDNEXT)
Debug.Print("n=" & n & " " & "hw7=" & Hex(hw7))
On Error Resume Next
If Microsoft.VisualBasic.Left(strName, 1) <> "" Then
If InStr(strName, "光纤") Then
a = FindWindow(vbNullString, strName) '此处a即所需句柄,您可以在此处中断并获取该句柄,或将句柄数据写入数组以获取所有包含"xxx"的窗口句柄
End If
End If
Loop