Obtener en WinAmp el título o la ruta del archivo de la canción actual.
PD: Son códigos de VB6 que convertí a .NET (no todo...) con algo de ayuda.
PD: Son códigos de VB6 que convertí a .NET (no todo...) con algo de ayuda.
Código (vbnet) [Seleccionar]
#Region " WinAmp Info"
' [ WinAmp Info ]
'
' // By Elektro H@cker
'
' Examples:
' MsgBox(WinAmp.Get_Title) ' Result: Artist - Title
' MsgBox(WinAmp.Get_FileName) ' Result: C:\Title.ext
Public Class WinAmp
Private Const WinampClassName As String = "Winamp v1.x"
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 Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, ByRef lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByRef lpBuffer As Byte, ByVal nSize As Long, ByRef lpNumberOfBytesRead As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Shared Function Get_Title() As String
Dim hwnd As IntPtr = FindWindow(WinampClassName, vbNullString)
Dim lpText As String = String.Empty
Dim strTitle As String = String.Empty
Dim intLength As Integer = 0
Dim intName As Integer = 0
Dim intLeft As Integer = 0
Dim intRight As Integer = 0
Dim intDot As Integer = 0
If hwnd.Equals(IntPtr.Zero) Then Return "WinAmp is not running"
lpText = New String(Chr(0), 100)
intLength = GetWindowText(hwnd, lpText, lpText.Length)
If (intLength <= 0) _
OrElse (intLength > lpText.Length) _
Then Return "Unknown"
strTitle = lpText.Substring(0, intLength)
intName = strTitle.IndexOf(" - Winamp")
intLeft = strTitle.IndexOf("[")
intRight = 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(" - Winamp")) _
AndAlso (strTitle.Length > " - Winamp".Length) _
Then strTitle = strTitle.Substring(0, strTitle.Length - " - Winamp".Length)
intDot = strTitle.IndexOf(".")
If (intDot > 0) _
AndAlso (IsNumeric(strTitle.Substring(0, intDot))) _
Then strTitle = strTitle.Remove(0, intDot + 1)
Return strTitle.Trim
End Function
Public Shared Function Get_FileName() As String
Dim lp As Long, lpWinamp As Long, iIndex As Long, PID As Long, bRet As Long, dwRead As Long
Dim Buffer(260) As Byte
Dim hWndWinamp As IntPtr = FindWindow(WinampClassName, vbNullString)
If hWndWinamp = 0 Then Return Nothing
iIndex = SendMessage(hWndWinamp, &H400, 0, 125)
lp = SendMessage(hWndWinamp, &H400, iIndex, 211)
If lp = 0 Then Return Nothing
Call GetWindowThreadProcessId(hWndWinamp, PID)
lpWinamp = OpenProcess(&H10, 0, PID)
If lpWinamp = 0 Then Return Nothing
bRet = ReadProcessMemory(lpWinamp, lp, Buffer(0), 260, dwRead)
Call CloseHandle(lpWinamp)
Return System.Text.UnicodeEncoding.Default.GetString(Buffer)
End Function
End Class
#End Region