1

I got all Child Windows of handle,
Now I want to get the caption of every Child Window by handle.
my code:

 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

                 '  i want to do something like: MsgBox(getCaption(hh))

            Next
        Next

How can I do it?

4

2 回答 2

1

Source : #1 & #2


By caption i hope you mean "The window Title text"

you have already created a list of window handle of child windows

for rest will be easy

    <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

Usage :

 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
于 2013-01-23T15:29:35.787 回答
1

GetWindowText您可以使用该函数获取窗口的标题。你需要 p/invoke 到它。您可以在pinvoke.net找到示例代码。

于 2013-01-23T15:27:12.860 回答