Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
EnumWindows in vb.net
Author:
Pete Doxtader
Submitted:
8/31/2011
Version:
VB 2005
Compatibility:
VB 2005, VB 2008, VB 2010
Category:
Windows API
Views:
25841
A small module containing all the code you need to do this simple task in vb.net. I searched and struggled for about 2 hours before I was able to put this together... it shouldn't have been that hard. hopefully this will save someone some time. Just create a new module called modEnumWindows in your project and copy this code into it. The function getWindowList does the trick.
Declarations:
'none
Code:
Imports System.Runtime.InteropServices Imports System.Text Module modEnumWindows Private windowList As New ArrayList Private errMessage As String Public Delegate Function MyDelegateCallBack(ByVal hwnd As Integer, ByVal lParam As Integer) As Boolean Declare Function EnumWindows Lib "user32" (ByVal x As MyDelegateCallBack, ByVal y As Integer) As Integer Declare Auto Function GetClassName Lib "user32" _ (ByVal hWnd As IntPtr, _ ByVal lpClassName As System.Text.StringBuilder, _ ByVal nMaxCount As Integer) As Integer Declare Auto Function GetWindowText Lib "user32" _ (ByVal hWnd As IntPtr, _ ByVal lpClassName As System.Text.StringBuilder, _ ByVal nMaxCount As Integer) As Integer Private Function EnumWindowProc(ByVal hwnd As Integer, ByVal lParam As Integer) As Boolean 'working vars Dim sTitle As New StringBuilder(255) Dim sClass As New StringBuilder(255) Try Call GetClassName(hwnd, sClass, 255) Call GetWindowText(hwnd, sTitle, 255) windowList.Add(sClass.ToString & ", " & hwnd & ", " & sTitle.ToString) Catch ex As Exception errMessage = ex.Message EnumWindowProc = False Exit Function End Try EnumWindowProc = True End Function Public Function getWindowList(ByRef wList As ArrayList, Optional errorMessage As String = "") As Boolean windowList.Clear() Try Dim del As MyDelegateCallBack del = New MyDelegateCallBack(AddressOf EnumWindowProc) EnumWindows(del, 0) getWindowList = True Catch ex As Exception getWindowList = False errorMessage = errMessage Exit Function End Try wList.Clear() wList = windowList End Function End Module
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2023 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement