hi.
I have finished one:
You can using API function from user32.dll.
This is my code (using VB2005) to obtain all window has caption which has
first 8 chars is "PSS/E - " and last 4 char is ".sav"
'--------------------------------------------------------------
Public Const StringBufferLength As Integer = 255
Public Function FindPSSEWindows() As Boolean
Dim i As Integer
Dim sPSSE As String
Dim str As String
Dim sCaption As String
Dim sClass As String
Dim SplitChar(0) As String
Dim hWndStart As Integer
Dim hChild As Integer
Dim windowText As New StringBuilder(StringBufferLength)
Dim className As New StringBuilder(StringBufferLength)
'Find deskktop window
hWndStart = GetDesktopWindow()
i = 0 'PSS/E window index
hChild = GetWindow(hWndStart, GW_CHILD)
Do While hChild > 0
Win32API.GetWindowText(hChild, windowText, StringBufferLength)
Win32API.GetClassName(hChild, className, StringBufferLength)
sCaption = windowText.ToString
sClass = className.ToString
sPSSE = Mid(sCaption, 1,
SplitChar(0) = "."
str = Strings.Right(sCaption, 4)
If (sPSSE = "PSS/E - ") And (UCase(str) = ".SAV") Then
i = i + 1
' DO YOUR CODE HERE, EXAMPLE:
'MsgBox("Handle: " + windowHandleAr(i).ToString + vbCrLf _
'+ "Class: " + windowClassAr(i).ToString + vbCrLf _
'+ "Caption: " + windowCaptionAr(i).ToString)
End If
hChild = GetWindow(hChild, GW_HWNDNEXT)
Loop
TotalPSSEWindows = i
If TotalPSSEWindows = 0 Then
Return False
Else
Return True
End If
End Function
'---------------------------------------------
'above code can use with vb6: you can replace functions Win32API.xxx with these declares:
Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" _
(ByVal hWndParent As Integer, ByVal lpEnumFunc As System.Delegate, ByVal lParam As Integer) As Boolean
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Integer, ByVal Msg As Integer, ByVal ByValwParam As Integer, ByVal lParam As String) As Integer
Public Declare Function SendChar Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Integer, ByVal Msg As Integer, ByVal ByValwParam As Integer, ByVal lParam As Integer) As Integer
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
Public Declare Auto Function GetWindow Lib "user32" _
(ByVal hWnd As Integer, ByVal uCmd As Integer) As Integer
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _
(ByVal hwnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" _
(ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
'UnhookWindowsHookEx
Public Declare Function GetDesktopWindow Lib "user32" () As Integer
Delegate Function EnumChildWindowsCallBack(ByVal hChild As Integer, ByVal lParam As Integer) As Boolean