EnumWindows Help

DKZ

Member
Joined
Aug 29, 2010
Messages
10
Programming Experience
1-3
Hi people,

I have this code for check EnumWindows:
VB.NET:
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
        ListBox1.Items.Add(sSave)


        If sSave.Trim <> "" Then
            ListBox1.Items.Remove("")
        End If

        Return 1 'continue enumeration        
    End Function
Its work with a "button" for refresh, but i like convert it to array and adding a items to array every time iam open a new window. Its possible? if yes, can you help me please?

Best Regards,
 
Last edited by a moderator:
You code needs to be prompted by something to be run. At the moment, you're using a Button Click event. There may be some way to be notified by the OS when a new top-level window opens but, if there is, I'm not aware of it. Failing that, your application would have do it itself. As it doesn't when a new window will open, it will just have to poll regularly. Yes, that is what you'd use a Timer for.
 
Back
Top