Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- 'Displays song info
- SetMusicInfo("Artist", "Album", "Song")
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- 'Clear song info
- Call SetMusicInfo("", "", "", , , False)
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment