[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How do I list the id and title of all the child windows?

Posted on 2004-11-01
4
Medium Priority
?
205 Views
Last Modified: 2008-01-09
I would like to list out all of the id's and titles of child windows.

Here's what I do:

Close all the IEXPLORE browsers.

Start a new IEXPLORE.

Then go to File -> New Window
-- I believe this spawns a child window

-- Continue for additional windows # Then go to File -> New Window

Currently when I run below code; it only displays information for the actively window.

I would like to display the information for all windows not just the active or focuesed one.


        Dim process As Process
        Dim p2 As Process() = process.GetProcessesByName("IEXPLORE")

        Command1.Enabled = False
        ListView1.BeginUpdate()
        ListView1.Items.Clear()
        For Each p In p2
            items(0) = p.ProcessName
            items(1) = p.Id.ToString
            If Not IntPtr.Zero.Equals(p.MainWindowHandle) Then
                items(2) = p.MainWindowHandle.ToString
                If GetWindowRect(p.MainWindowHandle, r) <> 0 Then
                    If IsIconic(p.MainWindowHandle) = 0 Then
                        items(3) = "(" & r.Left.ToString & ", " & r.Top.ToString & ")"
                        items(4) = (r.Right - r.Left).ToString & "x" & (r.Bottom - r.Top).ToString
                    Else
                        items(3) = "[Minimized]"
                        items(4) = "[Minimized]"
                    End If
                Else
                    items(3) = "[Error]"
                    items(4) = "[Error]"
                End If
                items(5) = p.MainWindowTitle
            Else
                items(2) = ""
                items(3) = ""
                items(4) = ""
                items(5) = ""
            End If

            ListView1.Items.Add(New ListViewItem(items))
        Next
0
Comment
Question by:vaultworld
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
iboutchkine earned 750 total points
ID: 12466312
try this

Dim Child as Form
      For Each Child in Me.MdiChildren
            msgbox(Child.Text)
      Next
0
 
LVL 1

Author Comment

by:vaultworld
ID: 12480732
Admin please close this question because its not possible using Process.
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 12482541
>>Admin please close this question because its not possible using Process.

The original question was :
How do I list the id and title of all the child windows?

Proces was never mentioned anywhere
0
 
LVL 1

Author Comment

by:vaultworld
ID: 12493626
Here's the final solution;

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ListBox1 = New System.Windows.Forms.ListBox()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'ListBox1
        '
        Me.ListBox1.Location = New System.Drawing.Point(32, 16)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(240, 147)
        Me.ListBox1.TabIndex = 0
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(32, 200)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(240, 64)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Button1"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.ListBox1})
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Lst = ListBox1
        EnumWindows(AddressOf EnumWindowsCallBack, 0)
    End Sub

End Class


Module Module1

    Public Lst As ListBox

    Public Delegate Function EnumWindowsProc(ByVal hwnd As IntPtr, ByVal lParam As Int32) As Int32

    Public Declare Function EnumWindows Lib "user32.dll" _
            (ByVal lpEnumFunc As EnumWindowsProc, ByVal lParam As Int32) As Int32

    Public Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" _
        (ByVal hwnd As IntPtr) As Int32

    Public Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" _
        (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch As Int32) As Int32

    'Callback function to enum windows
    Public Function EnumWindowsCallBack(ByVal hwnd As IntPtr, ByVal lParam As Int32) As Int32
        Dim sSave As String

        'Get the windowtext length
        sSave = Space(GetWindowTextLength(hwnd) + 1)

        'get the window text
        GetWindowText(hwnd, sSave, Len(sSave))

        'remove the last Chr(0)
        sSave = Microsoft.VisualBasic.Left(sSave, Len(sSave) - 1)

        'Error below: Reference to a non-shared member requires an Object Reference
        Lst.Items.Add(sSave)


        If sSave.Trim <> "" Then
            Debug.WriteLine(sSave)
        End If

        Return 1 'continue enumeration        
    End Function

End Module
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question