获取窗口的标题

时间:2012-06-19 05:30:57

标签: vb.net-2010

这是我的代码:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim proc As New EnumWindProc(AddressOf EnumChild), i As Int32
    Dim hwnd() As Process = Process.GetProcesses
    Dim FormTitle As String
    Dim RetVal As Integer
    For i = 0 To hwnd.GetUpperBound(0)
        Children = String.Empty
        EnumChildWindows(hwnd(i).MainWindowHandle, proc, IntPtr.Zero)
        RetVal = GetWindowText(hwnd(i).Handle, FormTitle, Int16.MaxValue)
        ListBox1.Items.Add(FormTitle & " " & hwnd(i).ToString & Convert.ToChar(Keys.Return) & Children)
    Next i
End Sub

出于某种原因,我只获得前两行窗口。如果我删除GetWindowTest代码行,我会获得所有窗口,但没有标题。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

为什么不尝试使用进程,这是一个获取当前打开的Windows标题的示例:

    For Each P As Process In (From item In Process.GetProcesses Where item.MainWindowTitle.Trim <> vbNullString)
        Me.ListBox1.Items.Add(P.MainWindowTitle)
    Next