PDA

View Full Version : gettin winamp window title


RogueProtoKol
1st June 2002, 20:51
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 FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long


Private Sub Form_Load()
Dim hwndWinamp As Long
hwndWinamp = FindWindow("Winamp v1.x", vbNullString)

sWindowText = Space(255)
r = GetWindowText(hwndWinamp, sWindowText, 255)
sWindowText = Left(sWindowText, r)

MsgBox sWindowText
End Sub

-------------------------------------------
thats the code i have atm, as far as i can see
that *should* fill swindowtext with the winamp
window title... but it doesn't, i end up with
the length of the title in spaces... but not the title!!

what am i doing wrong ?

Kaboon
4th June 2002, 16:06
I think that you are looking for a returned version number?


Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal WndID As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long

Private hwndWinamp As Long

Const WM_USER = &H400

Private Sub Form_Load()

Dim VersionNum As Long
Dim ReturnVersion As String
hwndWinamp = FindWindow("Winamp v1.x", 0)
VersionNumber = SendMessage(hwndWinamp, WM_USER, 0, 0)

If Len(Hex(VersionNumber)) > 3 Then
ReturnVersion = Left(Hex(VersionNumber), 1) & "."
ReturnVersion = ReturnVersion & Mid(Hex(VersionNumber), 2, 1)
ReturnVersion = ReturnVersion & Right$(Hex(VersionNumber), Len(Hex(VersionNumber)) - 3)
MsgBox ("Winamp " & ReturnVersion)
Else
MsgBox "Unknown version"
End If

End Sub


I hope that you can use this. Just copy/paste into an empty form.

RogueProtoKol
5th June 2002, 07:39
no, i want the window title which will include the current playing track ;)

Kaboon
5th June 2002, 12:23
Well I guess that you could try this code:


' API call's
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 FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Function RunningWinampTitle(lHandle As Long) As String

' This function get's the song
Dim lRet As Long
Dim sTitle As String * 256

lRet = GetWindowText(lHandle, sTitle, Len(sTitle))
RunningWinampTitle = Left(sTitle, InStr(1, sTitle, vbNullChar, vbTextCompare) - 10)

End Function

Private Sub Form_Load()

' Find winamp window
Dim hwndWinamp As Long
hwndWinamp = FindWindow("Winamp v1.x", vbNullString)

' Promt title
MsgBox RunningWinampTitle(hwndWinamp)

End Sub

Just copy and past it into a form again. It should work! :D

RogueProtoKol
15th June 2002, 14:18
thx, sorry for the late reply but ive been busy, the code worked straight away :D