-
Feb 12th, 2007, 05:14 AM
#1
Thread Starter
Interweb adm/o/distrator
[VB6]: Extracting current WMP song
This just basically tell you if WMP is loaded then if it is playing a song and if it is what song. This might not work with some WMP versions i haven't tested with 11.0 but it might.
VB Code:
Option Explicit
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Function strGetText(lngHwnd As Long) As String
Dim ilngLength As Long
Dim strBuffer As String
ilngLength = SendMessageLong(lngHwnd, &HE, 0, 0)
strBuffer = String$(ilngLength, 0)
SendMessageByString lngHwnd, &HD, ilngLength + 1, strBuffer
strGetText = strBuffer
Exit Function
Resume Next
End Function
Public Function getWMPT() As String
Dim stringtxt As String
Dim wmplng As Long
wmplng = FindWindow("WMPlayerAPP", vbNullString)
If wmplng = 0 Then
getWMPT = "WMP is not loaded currently"
Else
stringtxt = strGetText(wmplng)
If stringtxt = "Windows Media Player" Then
getWMPT = "No Song is currently being played"
Else
stringtxt = wmplng
getWMPT = Trim$(Left$(stringtxt, InStr(1, stringtxt, " - Windows Media Player")))
End If
End If
Exit Function
Resume Next
End Function
-
Feb 27th, 2007, 09:22 AM
#2
Re: [VB6]: Extracting current WMP song
I guess it works, but not for 11.0 at least not the song info. It can detect activity for WMP, but not the song.
-
Mar 24th, 2007, 07:11 AM
#3
Thread Starter
Interweb adm/o/distrator
Re: [VB6]: Extracting current WMP song
It should almost detect the window for any version of windows media player but yes extracting the song title is a problem
-
Jun 21st, 2007, 04:17 AM
#4
Lively Member
Re: [VB6]: Extracting current WMP song
Urgh, I have a problem with this code.
I'm not really sure where to put it :\
Anychance you've got an example project for me darling?
Thanx
Kankerflecken.
-
Jun 23rd, 2007, 03:26 AM
#5
Thread Starter
Interweb adm/o/distrator
-
Jul 26th, 2007, 03:14 PM
#6
Lively Member
Re: [VB6]: Extracting current WMP song
Hey!
Sorry i haven't replied or anything.
I haven't even touched VB in about 9 weeks, it isn't good
I've decided to spend more time on it..get some more apps up and running and whatever ^^
anyway
Back to this, i wacked the code in a module created some txtboxes and told the tb's to read the variables.
AND i get this:
this is my code
Module
vb Code:
Option Explicit
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Function strGetText(lngHwnd As Long) As String
Dim ilngLength As Long
Dim strBuffer As String
ilngLength = SendMessageLong(lngHwnd, &HE, 0, 0)
strBuffer = String$(ilngLength, 0)
SendMessageByString lngHwnd, &HD, ilngLength + 1, strBuffer
strGetText = strBuffer
Exit Function
Resume Next
End Function
Public Function getWMPT() As String
Dim stringtxt As String
Dim wmplng As Long
wmplng = FindWindow("WMPlayerAPP", vbNullString)
If wmplng = 0 Then
getWMPT = "WMP is not loaded currently"
Else
stringtxt = strGetText(wmplng)
If stringtxt = "Windows Media Player" Then
getWMPT = "No Song is currently being played"
Else
stringtxt = wmplng
getWMPT = Trim$(Left$(stringtxt, InStr(1, stringtxt, " - Windows Media Player")))
End If
End If
Exit Function
Resume Next
End Function
and this in my Form1
vb Code:
Private Sub Command1_Click()
Text1.Text = getWMPT
Text2.Text = stringtxt
End Sub
Its probably all wrong, i haven't touched VB for ages..and i wasn't that good at it anyway..so
Don't laugh
^^
THANKS!
Kankerflecken.
-
Sep 19th, 2007, 11:13 AM
#7
Re: [VB6]: Extracting current WMP song
there is no problem with your app, wmp just doesn't allow this anymore (from WMP11) without your app being a plug-in.
i think i'm going to take a try at developing such a thing.
Delete it. They just clutter threads anyway.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|