Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
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-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated