|
Module EntryPoint
Private Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
Private Declare Auto Function GetWindowText Lib "user32" (ByVal hwnd As IntPtr, _
ByVal lpString As String, _
ByVal cch As Integer) As Integer
Private Const lpClassName = "Winamp v1.x"
Private Const strTtlEnd = " - Winamp"
Private Function GetWinampSong() As String
Dim hwnd As IntPtr = FindWindow(lpClassName, vbNullString)
If hwnd.Equals(IntPtr.Zero) Then Return "Not running"
Dim lpText As New String(Chr(0), 100)
Dim intLength As Integer = GetWindowText(hwnd, lpText, lpText.Length)
If (intLength <= 0) OrElse (intLength > lpText.Length) Then Return "Unknown"
Dim strTitle As String = lpText.Substring(0, intLength)
Dim intName As Integer = strTitle.IndexOf(strTtlEnd)
Dim intLeft As Integer = strTitle.IndexOf("[")
Dim intRight As Integer = strTitle.IndexOf("]")
If (intName >= 0) AndAlso (intLeft >= 0) AndAlso (intName < intLeft) AndAlso _
(intRight >= 0) AndAlso (intLeft + 1 < intRight) Then _
Return strTitle.Substring(intLeft + 1, intRight - intLeft - 1)
If (strTitle.EndsWith(strTtlEnd)) AndAlso (strTitle.Length > strTtlEnd.Length) Then _
strTitle = strTitle.Substring(0, strTitle.Length - strTtlEnd.Length)
Dim intDot As Integer = strTitle.IndexOf(".")
If (intDot > 0) AndAlso (IsNumeric(strTitle.Substring(0, intDot))) Then _
strTitle = strTitle.Remove(0, intDot + 1)
Return strTitle.Trim
End Function
Public Sub Main()
Console.WriteLine(GetWinampSong())
Console.ReadLine()
End Sub
End Module
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.