Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
TitleFind an application using its title and maximize it
Keywordsmaximize, application, SendMessage, BringWindowToTop
CategoriesSoftware Engineering, API
 
This program uses the EnumWindows API function to examine all of the running windows with GetWindowText. When it finds the target, it uses the SendMessage and BringWindowToTop API functions to maximize the window and bring it to the top.
 
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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated