Nathaniel said:
I googled and found :
http://www.vbaccelerator.com/home/vb/code/Libraries/Windows/Enumerating_Windows/article.asp
But still have no idea what do.
Should it be something like this?
Public Declare Function EnumWindows Lib "user32" ( _
ByVal lpEnumFunc As Long, _
ByVal lparam As Long _
) As Long ???
hWnd = FindWindow("CLASS NAME", EnumWindowsLong)
When you call EnumWindows, it will call the lpEnumFunc that you provide
for every window. You must implement this function and inside it you
can check if the hWnd is of the classname that you want and react
accordingly.
Here is some code from
www.pinvoke.net, translated to VB:
Imports System.Runtime.InteropServices
Imports System.Text
Public Class Form1
Public Delegate Function CallBackPtr(ByVal hwnd As IntPtr, ByVal
lParam As Integer) As Boolean
Declare Auto Function EnumWindows Lib "user32.dll" (ByVal callPtr
As CallBackPtr, ByVal lPar As Integer) As Integer
Declare Auto Sub GetClassName Lib "user32.dll" (ByVal hWnd As
IntPtr, ByVal className As StringBuilder, ByVal maxCount As Integer)
Private sb As StringBuilder
Public Function Report(ByVal hWnd As IntPtr, ByVal lParam As
Integer) As Boolean
Dim className As New StringBuilder("", 256)
GetClassName(hWnd, className, 256)
sb.AppendFormat("Window Handle: {0,-15} Class Name: {1}" &
vbCrLf, hWnd, className.ToString)
Return True
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
sb = New StringBuilder()
EnumWindows(AddressOf Report, 0)
If sb.Length > 0 Then
MessageBox.Show(sb.ToString)
End If
End Sub
End Class
In other words, when you call EnumWindows, for each window handle,
Windows will call your function (Report). Inside that function, you
use the GetClassName function to get the name of the window class. You
can then compare the class name with another string and react
accordingly.
Hope this helps.