Jump to content

Messenger Now Playing Script


Dug

Recommended Posts

Hi there,I have this code that in theory should grab and display the currently playing song from Windows Live Messenger:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer   Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer   Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer   Public Function VarPtr(ByVal o As Object) As Integer       Dim GC As System.Runtime.InteropServices.GCHandle = System.Runtime.InteropServices.GCHandle.Alloc(o, System.Runtime.InteropServices.GCHandleType.Pinned)       Dim ret As Integer = GC.AddrOfPinnedObject.ToInt32       GC.Free()       Return ret   End Function   Private Structure COPYDATASTRUCT       Dim dwData As Integer       Dim cbData As Integer       Dim lpData As Integer   End Structure   Private Const WM_COPYDATA As Short = &H4AS   Public Sub SetMusicInfo(ByRef r_sArtist As String, ByRef r_sAlbum As String, ByRef r_sTitle As String, Optional ByRef r_sWMContentID As String = vbNullString, Optional ByRef r_sFormat As String = "{1} - {0}", Optional ByRef r_bShow As Boolean = True)       Dim udtData As COPYDATASTRUCT       Dim sBuffer As String       Dim hMSGRUI As Integer       'Total length can not be longer then 256 characters!       'Any longer will simply be ignored by Messenger.       sBuffer = "\0Music\0" & System.Math.Abs(CInt(r_bShow)) & "\0" & r_sFormat & "\0" & r_sArtist & "\0" & r_sTitle & "\0" & r_sAlbum & "\0" & r_sWMContentID & "\0" & vbNullChar       udtData.dwData = &H547S       udtData.lpData = VarPtr(sBuffer)       udtData.cbData = Len(sBuffer) * 2       Do           hMSGRUI = FindWindowEx(0, hMSGRUI, "MsnMsgrUIManager", vbNullString)           If (hMSGRUI > 0) Then               Call SendMessage(hMSGRUI, WM_COPYDATA, 0, VarPtr(udtData))           End If       Loop Until (hMSGRUI = 0)   End Sub

and then to change or clear whatever is being sent to Messenger:

'Displays song info   Call SetMusicInfo("Artist", "Album", "Song")   'Clear song info   Call SetMusicInfo("", "", "", , , False)

What I want to do is display the currently playing song on Messenger in the Page_Load bit of an ASP.NET page. I've tried lblMessage.Text = SetMusicInfo, however I keep getting the error:

Argument not specified for parameter 'r_sAlbum' of 'Public Sub SetMusicInfo(ByRef r_sArtist As String, ByRef r_sAlbum As String, ByRef r_sTitle As String, [byRef r_sWMContentID As String = Nothing], [byRef r_sFormat As String = "{1} - {0}"], [byRef r_bShow As Boolean = True])'.
It works fine without the lblMessage.Text bit, it just doesn't display anything. Any help would be appreciated.CheersDug
Link to comment
Share on other sites

Hi there,Here is my entire script for the ASP.NET page:

<script runat="server">	Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer	Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer	Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer	Private Const WM_COPYDATA As Short = &H4AS		Public Function VarPtr(ByVal o As Object) As Integer		Dim GC As System.Runtime.InteropServices.GCHandle = System.Runtime.InteropServices.GCHandle.Alloc(o, System.Runtime.InteropServices.GCHandleType.Pinned)		Dim ret As Integer = GC.AddrOfPinnedObject.ToInt32		GC.Free()		Return ret	End Function	Private Structure COPYDATASTRUCT		Dim dwData As Integer		Dim cbData As Integer		Dim lpData As Integer	End Structure	Public Sub SetMusicInfo(ByRef r_sArtist As String, ByRef r_sAlbum As String, ByRef r_sTitle As String, Optional ByRef r_sWMContentID As String = vbNullString, Optional ByRef r_sFormat As String = "{1} - {0}", Optional ByRef r_bShow As Boolean = True)		Dim udtData As COPYDATASTRUCT		Dim sBuffer As String		Dim hMSGRUI As Integer		'Total length can not be longer then 256 characters!		'Any longer will simply be ignored by Messenger.		sBuffer = "Music\" & System.Math.Abs(CInt(r_bShow)) & "\" & r_sFormat & "\" & r_sArtist & "\" & r_sTitle & "\" & r_sAlbum & "\" & r_sWMContentID & "\" & vbNullChar		udtData.dwData = &H547S		udtData.lpData = VarPtr(sBuffer)		udtData.cbData = Len(sBuffer) * 2		Do			hMSGRUI = FindWindowEx(0, hMSGRUI, "MsnMsgrUIManager", vbNullString)			If (hMSGRUI > 0) Then				Call SendMessage(hMSGRUI, WM_COPYDATA, 0, VarPtr(udtData))			End If		Loop Until (hMSGRUI = 0)	End Sub		sub Page_Load(obj as object, e as eventargs)		'Displays song info (MSN Messenger)Call SetMusicInfo(My.Settings.CurrentArtistPlaying, "Not Passed", My.Settings.CurrentSongPlaying)'Clear song infoCall SetMusicInfo("", "", "", , , False)	lblMessage.Text = SetMusicInfo		end sub	</script>

After looking over this again, it seems like this script may just send info to Messenger to update the status or something like that. A bit confused here!Dug

Link to comment
Share on other sites

Now I'm getting:

'Settings' is not a member of 'My'
in reference to:
'Displays song info (MSN Messenger)Call SetMusicInfo(My.Settings.CurrentArtistPlaying, "Not Passed", My.Settings.CurrentSongPlaying)

Link to comment
Share on other sites

you cannoy assign a function to a string

lblMessage.Text = SetMusicInfo

If SetMusicInfo returns a string you can do something like

lblMessage.Text = SetMusicInfo(your, params, here)

Link to comment
Share on other sites

Hi,Thanks for the reply. I've concluded that the code I originally had in this post won't do what I'm looking for... I've found the following code snippet:

Imports System.Runtime.InteropServicesPublic Class MSNStatusMessage	Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _		ByVal hWnd1 As Integer, _		ByVal hWnd2 As Integer, _		ByVal lpsz1 As String, _		ByVal lpsz2 As String) _	As Integer	Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _		ByVal Hwnd As Integer, _		ByVal wMsg As Integer, _		ByVal wParam As Integer, _		ByVal lParam As Integer) _	As Integer	Private Const WM_COPYDATA As Short = 74	Private Structure COPYDATASTRUCT		Public dwData As Integer		Public cbData As Integer		Public lpData As Integer	End Structure	Public Enum EnumCategory As Integer		Music = 0		Games = 1		Office = 2	End Enum	Public Shared Sub SendStatusMessage(ByVal Enable As Boolean, ByVal Category As EnumCategory, Optional ByVal Message As String = "")		Dim Data As COPYDATASTRUCT		Dim Buffer As String = "\0" & Category.ToString + "\0" & IIf(Enable, "1", "0") & "\0{0}\0" & Message & "\0\0\0\0" & Chr(0) & ""		Dim Handle As Integer = 0		Data.dwData = 1351		Data.lpData = VarPtr(Buffer)		Data.cbData = Buffer.Length * 2		Handle = FindWindowEx(0, Handle, "MsnMsgrUIManager", Nothing)		If Handle > 0 Then			SendMessage(Handle, WM_COPYDATA, 0, VarPtr(Data))		End If	End Sub	Private Shared Function VarPtr(ByVal e As Object) As Integer		Dim GC As GCHandle = GCHandle.Alloc(e, GCHandleType.Pinned)		Dim GC2 As Integer = GC.AddrOfPinnedObject.ToInt32		GC.Free()		Return GC2	End FunctionEnd Class

I've been trying various things with this one as well. How would you go about getting the result of this to appear in an lblMessage.Text string?ThanksDug

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...