Sixem

.NET MSN/WLM Now Playing Function

Mar 8th, 2013
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.48 KB | None | 0 0
  1.     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
  2.     Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
  3.     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
  4.  
  5.     Public Function VarPtr(ByVal o As Object) As Integer
  6.         Dim GC As System.Runtime.InteropServices.GCHandle = System.Runtime.InteropServices.GCHandle.Alloc(o, System.Runtime.InteropServices.GCHandleType.Pinned)
  7.         Dim ret As Integer = GC.AddrOfPinnedObject.ToInt32
  8.         GC.Free()
  9.         Return ret
  10.     End Function
  11.  
  12.     Private Structure COPYDATASTRUCT
  13.         Dim dwData As Integer
  14.         Dim cbData As Integer
  15.         Dim lpData As Integer
  16.     End Structure
  17.  
  18.     Private Const WM_COPYDATA As Short = &H4AS
  19.  
  20.     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)
  21.  
  22.         Dim udtData As COPYDATASTRUCT
  23.         Dim sBuffer As String
  24.         Dim hMSGRUI As Integer
  25.  
  26.         'Total length can not be longer then 256 characters!
  27.         'Any longer will simply be ignored by Messenger.
  28.         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
  29.  
  30.         udtData.dwData = &H547S
  31.         udtData.lpData = VarPtr(sBuffer)
  32.         udtData.cbData = Len(sBuffer) * 2
  33.  
  34.         Do
  35.             hMSGRUI = FindWindowEx(0, hMSGRUI, "MsnMsgrUIManager", vbNullString)
  36.  
  37.             If (hMSGRUI > 0) Then
  38.                 Call SendMessage(hMSGRUI, WM_COPYDATA, 0, VarPtr(udtData))
  39.             End If
  40.  
  41.         Loop Until (hMSGRUI = 0)
  42.  
  43.     End Sub
  44.  
  45.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  46.  
  47.         'Displays song info
  48.         SetMusicInfo("Artist", "Album", "Song")
  49.  
  50.     End Sub
  51.  
  52.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  53.  
  54.         'Clear song info
  55.         Call SetMusicInfo("", "", "", , , False)
  56.  
  57.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment