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
Please, if i have done anything wrong, correct me!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![]()





Reply With Quote