VB.NET code to find active window title.
Hi All,
I am looking for VB.NET code which can help me get the active window (the one user has got focus to) title. I know you can do this using Win 32 API like this:
VB Code:
Private Declare Function GetActiveWindow Lib "user32" () As Long
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 Form_Load()
Timer1.Interval = 5000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim lWnd As Long
Dim strName As String
lWnd = GetActiveWindow
strName = String(GetWindowTextLength(lWnd) + 1, Chr$(0))
GetWindowText lWnd, strName, Len(strName)
Debug.Print strName
End Sub
but I want to use, Managed code and not API calls.
Do you know of way of achieving the same in Managed code?
Also, is there any event which tells me that Active window has been changed by user??
JD