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
 
 
 
 
 
TitleGet the caption of the window that currently has focus
Keywordsfocus window, caption, title
CategoriesControls, Miscellany, Tips and Tricks
 
Use the GetForegroundWindow API function to get the window's handle. Then use GetWindowText to get the caption.
 
Private Sub Timer1_Timer()
Dim foreground_hwnd As Long
Dim txt As String
Dim length As Long

    foreground_hwnd = GetForegroundWindow()

    txt = Space$(1024)
    length = GetWindowText(foreground_hwnd, txt, Len(txt))
    txt = Left$(txt, length)

    lblCaption = txt
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated