Below is the code that I am using. The method called FileZillaServerReloadConfig() is what starts everything.
VB6:
Code: Select all
Option Explicit
Private Const MAX_PATH = 260
Private Const WM_APP = &H8000
Private Const WM_FILEZILLA_RELOADCONFIG = WM_APP
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private mWindowHandlesInfo As String
Public Function GetWindowHandles() As String
On Error GoTo Unexer
mWindowHandlesInfo = vbNullString
Call EnumWindows(AddressOf EnumWindowProc, &H0)
GetWindowHandles = mWindowHandlesInfo
Exit Function
Unexer:
Debug.Print "ERROR (GetWindowHandles): " & Err.Description
End Function
Public Function EnumWindowProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
'working vars
Dim nSize As Long
Dim sTitle As String
Dim sClass As String
Dim pos As Integer
'set up the strings to receive the class and
'window text. You could use GetWindowTextLength,
'but I'll cheat and use MAX_PATH instead.
sTitle = Space$(MAX_PATH)
sClass = Space$(MAX_PATH)
Call GetClassName(hWnd, sClass, MAX_PATH)
Call GetWindowText(hWnd, sTitle, MAX_PATH)
If LenB(mWindowHandlesInfo) <> 0 Then
mWindowHandlesInfo = mWindowHandlesInfo & Chr$(255)
End If
'strip the trailing chr$(0)'s from the strings
'returned above and add the window data to the list
mWindowHandlesInfo = mWindowHandlesInfo & CStr(hWnd) & Chr$(254)
mWindowHandlesInfo = mWindowHandlesInfo & TrimNull(sClass) & Chr$(254)
mWindowHandlesInfo = mWindowHandlesInfo & TrimNull(sTitle)
'to continue enumeration, we must return True
'(in C that's 1). If we wanted to stop (perhaps
'using if this as a specialized FindWindow method,
'comparing a known class and title against the
'returned values, and a match was found, we'd need
'to return False (0) to stop enumeration. When 1 is
'returned, enumeration continues until there are no
'more windows left.
EnumWindowProc = 1
End Function
Private Function TrimNull(item As String)
'remove string before the terminating null(s)
Dim pos As Integer
pos = InStr(item, Chr$(0))
If pos Then
TrimNull = Left$(item, pos - 1)
Else
TrimNull = item
End If
End Function
' mjb 05/20/11
Public Sub FileZillaServerReloadConfig()
Dim WindowHandlesInfo As String
Dim Array1() As String
Dim Ubnd1 As Long
Dim Index1 As Long
Dim Array2() As String
Dim Ubnd2 As Long
Dim Index2 As Long
Dim hWnd As Long
Dim WindowClass As String
Dim WindowText As String
Dim RetVal As Long
On Error GoTo Unexer
' Locate the hwnd for FileZilla Server
WindowHandlesInfo = GetWindowHandles()
Array1 = Split(WindowHandlesInfo, Chr$(255))
Ubnd1 = -1
On Error Resume Next
Ubnd1 = UBound(Array1)
On Error GoTo Unexer
For Index1 = 0 To Ubnd1
Array2 = Split(Array1(Index1), Chr$(254))
hWnd = Val(Array2(0))
WindowClass = CStr(Array2(1))
WindowText = CStr(Array2(2))
If hWnd <> 0 Then
If WindowClass = "FileZilla Server Helper Window" Then
Debug_Print "Posting message to " & CStr(hWnd)
RetVal = PostMessage(hWnd, WM_FILEZILLA_RELOADCONFIG, 0, 0)
Debug_Print "Posted message to " & CStr(hWnd)
End If
End If
Next Index1
Exit Sub
Unexer:
Debug.Print "ERROR (FileZillaServerReloadConfig): " & Err.Description
End Sub