Vb.net 获取句柄的标题
我得到了所有Vb.net 获取句柄的标题,vb.net,winforms,pinvoke,Vb.net,Winforms,Pinvoke,我得到了所有子窗口的句柄, 现在我想通过句柄获取每个子窗口的标题。 我的代码: 如何操作?您可以使用该函数获取窗口的标题。您需要对其进行p/invoke。您可以在以下位置找到此示例代码。源代码:& 我希望你说的标题是“窗口标题文本” 您已经创建了子窗口的窗口句柄列表 休息很容易 <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ Private Shared Function Ge
子窗口的句柄,
现在我想通过句柄获取每个子窗口的标题。
我的代码:
如何操作?您可以使用该函数获取窗口的标题。您需要对其进行p/invoke。您可以在以下位置找到此示例代码。源代码:&
我希望你说的标题是“窗口标题文本”
您已经创建了子窗口的窗口句柄列表
休息很容易
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function GetWindowText(ByVal hwnd As IntPtr, ByVal lpString As StringBuilder, ByVal cch As Integer) As Integer
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function GetWindowTextLength(ByVal hwnd As IntPtr) As Integer
End Function
Public Function GetText(ByVal hWnd As IntPtr) As String
Dim length As Integer
If hWnd.ToInt32 <= 0 Then
Return Nothing
End If
length = GetWindowTextLength(hWnd)
If length = 0 Then
Return Nothing
End If
Dim sb As New System.Text.StringBuilder("", length + 1)
GetWindowText(hWnd, sb, sb.Capacity)
Return sb.ToString()
End Function
你看过这个网站吗?你的意思是想FindWindow
Caption吗?@WraithNath我当然看到了这个网站。@spajce我的意思是通过句柄查找句柄的标题。如果子窗口不是MDI客户端窗口,则没有标题。请不要从其他源复制没有属性的代码。那确实是非常糟糕的形式。对不起谢谢提醒!
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function GetWindowText(ByVal hwnd As IntPtr, ByVal lpString As StringBuilder, ByVal cch As Integer) As Integer
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function GetWindowTextLength(ByVal hwnd As IntPtr) As Integer
End Function
Public Function GetText(ByVal hWnd As IntPtr) As String
Dim length As Integer
If hWnd.ToInt32 <= 0 Then
Return Nothing
End If
length = GetWindowTextLength(hWnd)
If length = 0 Then
Return Nothing
End If
Dim sb As New System.Text.StringBuilder("", length + 1)
GetWindowText(hWnd, sb, sb.Capacity)
Return sb.ToString()
End Function
For Each p As Process In Process.GetProcessesByName("MyProccess")
Dim ChildrenList As New List(Of IntPtr)
ChildrenList = GetChildWindows(p.MainWindowHandle)
MsgBox(ChildrenList.Count) ' = 343
For Each hh As IntPtr In ChildrenList
Dim caption As String = GetText(hh)
' use the caption the way u want
Next
Next