Results 1 to 6 of 6

Thread: Enumerate all windows + children

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Enumerate all windows + children

    Using straight up API's
    VB Code:
    1. Option Strict On
    2. Option Explicit On
    3.  
    4. Public Class Form1
    5.     Delegate Function EnumWindProc( _
    6.             ByVal hWnd As Int32, _
    7.             ByVal lParam As Int32) As Boolean
    8.  
    9.     Delegate Function EnumChildWindProc( _
    10.             ByVal hWnd As Int32, _
    11.             ByVal lParam As Int32) As Boolean
    12.  
    13.     Declare Function EnumWindows Lib "user32.dll" ( _
    14.             ByVal lpEnumProc As EnumWindProc, _
    15.             ByVal lParam As Int32) As Boolean
    16.  
    17.     Declare Function EnumChildWindows Lib "user32" ( _
    18.          ByVal hWnd As IntPtr, _
    19.          ByVal lpEnumFunc As EnumWindProc, _
    20.          ByRef lParam As IntPtr) As Int32
    21.     Dim Children As String
    22.  
    23.     Private Function EnumChild( _
    24.          ByVal hWnd As Int32, _
    25.          ByVal lParam As Int32) As Boolean
    26.         Children = Children & "," & hWnd.ToString
    27.         EnumChild = True
    28.     End Function
    29.  
    30.     Private Function EnumWins(ByVal hwnd As Int32, ByVal lParam As Int32) As Boolean
    31.         Dim proc As New EnumWindProc(AddressOf EnumChild)
    32.         Children = String.Empty
    33.         EnumChildWindows(CType(hwnd, IntPtr), proc, IntPtr.Zero)
    34.         MessageBox.Show(hwnd & Convert.ToChar(Keys.Return) & Children)
    35.         EnumWins = True
    36.     End Function
    37.  
    38.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    39.         Dim proc As New EnumWindProc(AddressOf EnumWins)
    40.         EnumWindows(proc, 0)
    41.     End Sub
    42. End Class

    Using process class

    VB Code:
    1. Option Strict On
    2. Option Explicit On
    3.  
    4. Public Class Form1
    5.     Delegate Function EnumWindProc( _
    6.             ByVal hWnd As Int32, _
    7.             ByVal lParam As Int32) As Boolean
    8.  
    9.     Delegate Function EnumChildWindProc( _
    10.             ByVal hWnd As Int32, _
    11.             ByVal lParam As Int32) As Boolean
    12.  
    13.     Declare Function EnumChildWindows Lib "user32" ( _
    14.          ByVal hWnd As IntPtr, _
    15.          ByVal lpEnumFunc As EnumWindProc, _
    16.          ByRef lParam As IntPtr) As Int32
    17.     Dim Children As String
    18.  
    19.     Private Function EnumChild( _
    20.          ByVal hWnd As Int32, _
    21.          ByVal lParam As Int32) As Boolean
    22.         If Children.Length <> 0 Then
    23.             Children = Children & "," & hWnd.ToString
    24.         Else
    25.             Children = hWnd.ToString
    26.         End If
    27.         EnumChild = True
    28.     End Function
    29.  
    30.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    31.         Dim proc As New EnumWindProc(AddressOf EnumChild), i As Int32
    32.         Dim hwnd() As Process = Process.GetProcesses
    33.         For i = 0 To hwnd.GetUpperBound(0)
    34.             Children = String.Empty
    35.             EnumChildWindows(hwnd(i).MainWindowHandle, proc, IntPtr.Zero)
    36.             MessageBox.Show(hwnd(i).ToString & Convert.ToChar(Keys.Return) & Children)
    37.         Next i
    38.     End Sub
    39. End Class
    Please, if i have done anything wrong, correct me!

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Enumerate all windows + children

    Why not use the Children property of a Form?
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  3. #3

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Enumerate all windows + children

    Can you explain what you mean? I am a vb.net noobie

  4. #4
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    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.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  5. #5
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    Re: Enumerate all windows + children

    the code posted here enumerates through all windows running, not just the child forms of the current MDI client.
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  6. #6
    Hyperactive Member csKanna's Avatar
    Join Date
    Dec 2005
    Location
    Tech-Tips-Now.com
    Posts
    339

    Re: Enumerate all windows + children

    Getting error in vb.net 2003
    CType(hwnd, IntPtr)
    Value of type 'Integer' cannot be converted to 'System.IntPtr'.
    Kanna

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width