Private Target As String
' Ask Windows for the list of tasks.
Public Sub MaximizeTask(app_name As String)
Target = app_name
EnumWindows AddressOf EnumCallback, 0
End Sub
' Check a returned task to see if we should
' maximize it.
Public Function EnumCallback(ByVal app_hWnd As Long, ByVal _
param As Long) As Long
Dim buf As String * 256
Dim title As String
Dim length As Long
' Get the window's title.
length = GetWindowText(app_hWnd, buf, Len(buf))
title = Left$(buf, length)
' See if this is the target window.
If InStr(title, Target) <> 0 Then
' Maximize the window.
SendMessage app_hWnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0
BringWindowToTop app_hWnd
' Stop searching.
EnumCallback = 0
Else
' Continue searching.
EnumCallback = 1
End If
End Function
|