Consider this:
Re-arranged a few things...Code:Option Explicit On Option Strict On Imports System Imports System.Collections.Generic Imports System.Collections.ObjectModel Imports System.Text Public Class Form1 Private Function Display(ByVal cs As Collection(Of String)) As String Dim builder As New StringBuilder For Each item As String In cs builder.Append(item & vbCrLf) Next item Return builder.ToString End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim windowText As String = "" GetActiveWindows windowText = Display(ActiveWindows) 'Breakpoint here... does AcvtiveWinows have what you expect? RichTextBox1.Text = windowText 'Breakpoint here, does windowText have what you expect? End Sub ' CallBack delegate Public Delegate Function CallBack(ByVal hWnd As IntPtr, ByVal lParam As Integer) As Boolean ' Imports Public Declare Function EnumWindows Lib "user32" (ByVal Adress As CallBack, ByVal y As Integer) As Integer Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As IntPtr) As Boolean Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As System.IntPtr, ByVal lpWindowText As String, ByVal cch As Integer) As Integer ' /Imports Private ActiveWindows As New Collection(Of String) Public Sub GetActiveWindows() ActiveWindows.Clear() EnumWindows(AddressOf Enumerator, 0) End Function Private Function Enumerator(ByVal hwnd As IntPtr, ByVal lParam As Integer) As Boolean Dim text As String = Space(Int16.MaxValue) GetWindowText(hwnd, text, Int16.MaxValue) If IsWindowVisible(hwnd) Then ActiveWindows.Add(text) End If Return True End Function End Class
-tg




Reply With Quote