Paul M
Feb 12th, 2007, 04:14 AM
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.
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
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