|
|
Title | Get the caption of the window that currently has focus |
Keywords | focus window, caption, title |
Categories | Controls, 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
|
|
|
|
|
|