Attribute VB_Name = "WindowHandling" Option Explicit Private Declare Function GetWindow Lib "user32" (ByVal hwnd _ As Long, ByVal wCmd As Long) As Long Private Declare Function GetWindowTextLength Lib "user32" _ Alias "GetWindowTextLengthA" (ByVal hwnd 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 SendMessage Lib "user32.dll" Alias _ "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, lParam As Any) As Long Private Declare Function IsWindowVisible Lib "user32" (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 Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function IsZoomed Lib "user32" (ByVal hwnd As Long) As Long Private Const WM_SYSCOMMAND As Long = &H112 Private Const SC_CLOSE As Long = &HF060 Private Const SC_MAXIMIZE As Long = &HF030 Private Const SC_MINIMIZE As Long = &HF020 Private Const SC_RESTORE As Long = &HF120 Const GW_HWNDFIRST = 0 Const GW_HWNDNEXT = 2 Const WM_CLOSE = &H10 Public Function FindWindowHandle(OwnHandle As Long, Buzzword As String) As Long Dim hwnd As Long, Result As Long, Title As String ' hwnd = GetWindow(OwnHandle, GW_HWNDFIRST) Do Result = GetWindowTextLength(hwnd) + 1 Title = Space$(Result) Result = GetWindowText(hwnd, Title, Result) Title = Left$(Title, Len(Title) - 1) If InStr(LCase(Title), LCase(Buzzword)) > 0 Then FindWindowHandle = hwnd Exit Function End If hwnd = GetWindow(hwnd, GW_HWNDNEXT) Loop Until hwnd = 0 End Function Public Function CloseWindow(WindowHandle As Long) SendMessage WindowHandle, WM_CLOSE, ByVal 0&, ByVal 0& End Function Public Sub MinimizeWindow(Handle As Long) If CBool(IsIconic(Handle)) Then PostMessage Handle, WM_SYSCOMMAND, SC_RESTORE, 0 Else PostMessage Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0 End If End Sub Public Sub MaximizeWindow(Handle As Long) If CBool(IsZoomed(Handle)) Then PostMessage Handle, WM_SYSCOMMAND, SC_RESTORE, 0 Else PostMessage Handle, WM_SYSCOMMAND, SC_MAXIMIZE, 0 End If End Sub Public Sub CloseWindowPost(Handle As Long) PostMessage Handle, WM_SYSCOMMAND, SC_CLOSE, 0 End Sub Public Function CheckWindowVisible(ByVal Handle As Long) As Boolean If IsWindowVisible(Handle) = 1 Then CheckWindowVisible = True Else CheckWindowVisible = False End If End Function