Task manager.



Windows XP.
Visual studio 2010.
Visual Basic.net


Can anyone help me please,

I am writing a task manager program.
I use the following routine to list the processes and handles.

Code:
   Public Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
    'ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_fxmancli/html/6abcb67e-3766-4af2-9590-bf5dabd17e41.htm

     Declare Auto Function SetForegroundWindow Lib "USER32.DLL" _
        (ByVal hWnd As IntPtr) As Boolean



    Sub ListAllApplications()

        Dim p As New Process()
        Dim rw(2) As String
        Me.dgv.Rows.Clear()
        Dim r As Int16 = 0 'was 97
        For Each p In Process.GetProcesses(".")
            Try

                If p.MainWindowTitle.Length > 0 Then
                    rw(0) = Chr(r + 97)
                    rw(1) = p.MainWindowTitle

                    rw(2) = p.MainWindowHandle 'works with SetForegroundWindow(target_handle)
                    r = r + 1
                    Me.dgv.Rows.Add(rw)
                End If

            Catch
                MessageBox.Show("error")
            End Try


        Next
        rw(0) = ""
        rw(1) = "Target not found"
        rw(2) = ""
        Me.dgv.Rows.Add(rw)

    End Sub
I can then switch to the desired program using-

Code:
    SetForegroundWindow(target_handle)
     ShowWindow(target_handle, SW_RESTORE)

this works fine with most applications, however, with Firefox and Google Chrome, when multiple windows are open only one of them is located. Only one instance seems to have a p.MainWindowHandle.

It must be possible as Windows taskmanager shows all instances.

Any help gratefully accepted stop.
Thanks,
Steve