2

这是我的代码:

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 代码行,我会得到所有窗口,但没有标题。

我怎样才能解决这个问题?

4

1 回答 1

0

为什么不尝试使用Process,这里是获取当前打开的窗口标题的示例:

    For Each P As Process In (From item In Process.GetProcesses Where item.MainWindowTitle.Trim <> vbNullString)
        Me.ListBox1.Items.Add(P.MainWindowTitle)
    Next
于 2012-08-15T03:50:13.780 回答