10-07-2009, 12:46 PM
Not sure if this is the best forum to learn about VB for programs like that, but I use this.
Code:
Public Class Form1
Dim strin As String = ""
Private Declare Function GetForegroundWindow Lib "user32.dll" () As Int32
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Int32, ByVal lpString As String, ByVal cch As Int32) As Int32
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If strin <> GetActiveWindowTitle() Then
TextBox1.Text = TextBox1.Text & GetActiveWindowTitle() + vbNewLine
strin = GetActiveWindowTitle()
End If
End Sub
Private Function GetActiveWindowTitle() As String
Dim MyStr As String
MyStr = New String(Chr(0), 100)
GetWindowText(GetForegroundWindow, MyStr, 100)
MyStr = MyStr.Substring(0, InStr(MyStr, Chr(0)) - 1)
Return MyStr
End Function
End Class