VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Get the window which has got focus using GetFocus API

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

Rate Get the window which has got focus using GetFocus API



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]

Download this snippet    Add to My Saved Code

Get the window which has got focus using GetFocus API Comments

No comments have been posted about Get the window which has got focus using GetFocus API. Why not be the first to post a comment about Get the window which has got focus using GetFocus API.

Post your comment

Subject:
Message:
0/1000 characters