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:
  1. Private Declare Function GetActiveWindow Lib "user32" () As Long
  2. Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
  3. Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
  4.  
  5. Private Sub Form_Load()
  6.     Timer1.Interval = 5000
  7.     Timer1.Enabled = True
  8. End Sub
  9.  
  10. Private Sub Timer1_Timer()
  11.     Dim lWnd As Long
  12.     Dim strName As String
  13.    
  14.     lWnd = GetActiveWindow
  15.     strName = String(GetWindowTextLength(lWnd) + 1, Chr$(0))
  16.     GetWindowText lWnd, strName, Len(strName)
  17.     Debug.Print strName
  18.  
  19. 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