|
-
Jan 26th, 2008, 03:46 PM
#7
Re: Help, Getting All the ClassNames in a Window
using EnumWindows in .NET is easy, but you must consider that you can't use the AddressOf in the same way as in vb6, so you need to assign a Delegate to handle it.
here's an example i quickly put together for you, it basically grabs all the windows & lists there names & window text ( if they have window text ) in this case in a listview.
Code:
Public Class Form1
'/// modify the 1st arguement of EnumWindows to ByVal lpEnumFunc As winproc
Private Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As winproc, ByVal lParam As Int32) As Int32
Private Declare Function GetWindow Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal wCmd As Int32) As IntPtr
Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hwnd As IntPtr, ByVal lpClassName As System.Text.StringBuilder, ByVal nMaxCount As Int32) As Int32
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As IntPtr, ByVal lpString As System.Text.StringBuilder, ByVal cch As Int32) As Int32
'/// this will handle the AddressOf issues when using .NET...
Private Delegate Function winproc(ByVal hwnd As IntPtr, ByVal lparam As Int32) As Int32
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim proc As New winproc(AddressOf ReturnEnumProc)
EnumWindows(proc, &H0)
End Sub
Private Function ReturnEnumProc(ByVal hwnd As IntPtr, ByVal lparam As Int32) As Int32
Dim sBuilderName As New System.Text.StringBuilder(255)
Dim sBuilderText As New System.Text.StringBuilder(255)
GetClassName(hwnd, sBuilderName, 255)
GetWindowText(hwnd, sBuilderText, 255)
Dim lvi As New ListViewItem(sBuilderName.ToString)
lvi.SubItems.Add(sBuilderText.ToString)
ListView1.Items.Add(lvi)
Return 1
End Function
End Class
hope it helps
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|