vb.net findwindowex无法按标题查找子项

时间:2015-05-07 08:18:29

标签: vb.net pinvoke

我知道我的代码不是那么优雅,但它应该有用,但事实并非如此。只是为了抬起头来,我将我的数组添加到一个列表框中,这样我就可以在我得到代码的时候看到它们。

   cb = New CallBack(AddressOf MyCallBack)
    EnumWindows(cb, 0)

    Dim CadTITLE As String = ""
    For Each item As String In ListBox1.Items
        If item.Contains("Program Name") Then
            CadTITLE = item

        End If
    Next

    ListBox1.Items.Clear()

    Dim Hwnd As IntPtr = FindWindow(Nothing, CadTITLE)

    Dim hndls() As IntPtr = GetChildWindows(Hwnd)

    Dim CallTITLE As String = ""

    For Each hnd In hndls
        If Len(GetText(hnd)) > 0 Then
            ListBox1.Items.Add(GetText(hnd))
        End If
    Next

    For Each item As String In ListBox1.Items
        If item.Contains("Call No") Then
            CallTITLE = item
        End If
    Next



    Dim hwnd2 As IntPtr = FindWindowEx(Hwnd, IntPtr.Zero, nothing, CallTITLE)
            If hwnd2.Equals(IntPtr.Zero) Then
        MsgBox("Not Found")
    Else
        MsgBox("Found")
    End If

根据MSDN,我应该能够通过窗口的标题找到窗口,我在变量CallTITLE中找到了它(用msgbox(CallTITLE)确认),但它仍然没有找到子窗口。应该返回一个msgbox(“找到”)然后我可以继续找到我需要的文本框。

1 个答案:

答案 0 :(得分:0)

总是,我可以用几个小时的东西打架,一旦我问这个问题,我就弄明白了。我错过了一个级别。 MDIClient,应该早点抓住它。

 Dim hwnd2 As IntPtr = FindWindowEx(Hwnd, Nothing, "MDIClient", Nothing)
    Dim hwnd3 As IntPtr = FindWindowEx(hwnd2, Nothing, Nothing, CallTITLE)




    If hwnd3.Equals(IntPtr.Zero) Then
        MsgBox("Not Found")
    Else
        MsgBox("Found")
    End If