by Karthikeyan (187 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Sat 17th February 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Get the window which has got focus using GetFocus API
API Declarations
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Sub Timer1_Timer()
Dim wnd As Long, wntxt As String, txtlen As Long
wnd = GetFocus()
txtlen = GetWindowTextLength(wnd) + 1
wntxt = Space(txtlen)
txtlen = GetWindowText(wnd, wntxt, txtlen)
Label1.Caption = Left(wntxt, txtlen) & " has the focus now."
End Sub
'Visit my Homepage at
'http://www.geocities.com/marskarthik
'http://marskarthik.virtualave.net
'Email: [email protected]