Well I'm trying to make a program that have ListBox1 which when the button1 is pressed the Listbox1 will show all the open windows of notepad, like get notepad.exe and it will show Example the name: Untitled - Notepad nothing else, i have a code right now that i found but it Shows a few things, look at this picture.
http://img37.imageshack.us/img37/1241/getn.png
It says MSCTFIME UI And Default IMe, i don't want that to show...
This is the code i have right now.
Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Lst = Me.ListBox1
EnumWindows(AddressOf EnumWindowsCallBack, 0)
End Sub
Module 1
Private Declare Auto Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hWnd As IntPtr, ByRef ProcessID As Integer) As Integer
Public Lst As ListBox
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
Dim ProcessID As Long
GetWindowThreadProcessId(hwnd, ProcessID)
Dim tempProc As Process = Process.GetProcessById(ProcessID)
Dim processName As String = tempProc.ProcessName
If (processName = "notepad") Then
'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
Lst.Items.Add(sSave)
'Lst.Items.Add(processName)
If sSave.Trim <> "" Then
Debug.WriteLine(sSave)
End If
End If
Return 1 'continue enumeration
End Function