Enumerate all windows + children
Using straight up API's
VB Code:
Option Strict On
Option Explicit On
Public Class Form1
Delegate Function EnumWindProc( _
ByVal hWnd As Int32, _
ByVal lParam As Int32) As Boolean
Delegate Function EnumChildWindProc( _
ByVal hWnd As Int32, _
ByVal lParam As Int32) As Boolean
Declare Function EnumWindows Lib "user32.dll" ( _
ByVal lpEnumProc As EnumWindProc, _
ByVal lParam As Int32) As Boolean
Declare Function EnumChildWindows Lib "user32" ( _
ByVal hWnd As IntPtr, _
ByVal lpEnumFunc As EnumWindProc, _
ByRef lParam As IntPtr) As Int32
Dim Children As String
Private Function EnumChild( _
ByVal hWnd As Int32, _
ByVal lParam As Int32) As Boolean
Children = Children & "," & hWnd.ToString
EnumChild = True
End Function
Private Function EnumWins(ByVal hwnd As Int32, ByVal lParam As Int32) As Boolean
Dim proc As New EnumWindProc(AddressOf EnumChild)
Children = String.Empty
EnumChildWindows(CType(hwnd, IntPtr), proc, IntPtr.Zero)
MessageBox.Show(hwnd & Convert.ToChar(Keys.Return) & Children)
EnumWins = True
End Function
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim proc As New EnumWindProc(AddressOf EnumWins)
EnumWindows(proc, 0)
End Sub
End Class
Using process class
VB Code:
Option Strict On
Option Explicit On
Public Class Form1
Delegate Function EnumWindProc( _
ByVal hWnd As Int32, _
ByVal lParam As Int32) As Boolean
Delegate Function EnumChildWindProc( _
ByVal hWnd As Int32, _
ByVal lParam As Int32) As Boolean
Declare Function EnumChildWindows Lib "user32" ( _
ByVal hWnd As IntPtr, _
ByVal lpEnumFunc As EnumWindProc, _
ByRef lParam As IntPtr) As Int32
Dim Children As String
Private Function EnumChild( _
ByVal hWnd As Int32, _
ByVal lParam As Int32) As Boolean
If Children.Length <> 0 Then
Children = Children & "," & hWnd.ToString
Else
Children = hWnd.ToString
End If
EnumChild = True
End Function
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
For i = 0 To hwnd.GetUpperBound(0)
Children = String.Empty
EnumChildWindows(hwnd(i).MainWindowHandle, proc, IntPtr.Zero)
MessageBox.Show(hwnd(i).ToString & Convert.ToChar(Keys.Return) & Children)
Next i
End Sub
End Class
Please, if i have done anything wrong, correct me! :wave:
Re: Enumerate all windows + children
Why not use the Children property of a Form?
Re: Enumerate all windows + children
Can you explain what you mean? I am a vb.net noobie :)
Re: Enumerate all windows + children
Every System.Windows.Forms.Form has an MdiChildren property that returns an array of all of the MdiChildren that the current form is a Parent of.
Just simply cycle through those to access them.
Re: Enumerate all windows + children
the code posted here enumerates through all windows running, not just the child forms of the current MDI client.
Re: Enumerate all windows + children
Getting error in vb.net 2003
Quote:
CType(hwnd, IntPtr)
Quote:
Value of type 'Integer' cannot be converted to 'System.IntPtr'.