Archive for the 'SendMessage' Tag

Vb Net - Change MSN Name

This is just a slightly more efficient way to change your MSN name than using SendKeys.

It uses the SendMessage API in order to set the text, rather than SendKeys.

The code is pretty fully commented, and so there is nothing much to explain…

Below is the full source file:

Imports System.Runtime.InteropServices

Public Class Form1

”API

<DllImport(“User32.dll”)> Private Shared Function EnumChildWindows(ByVal WindowHandle As IntPtr, ByVal Callback As EnumWindowProcess, ByVal lParam As IntPtr) As Boolean

End Function

<DllImport(“user32.dll”, CharSet:=CharSet.Auto)> Private Shared Sub GetClassName(ByVal hWnd As System.IntPtr, ByVal lpClassName As System.Text.StringBuilder, ByVal nMaxCount As Integer)

End Sub

<DllImport(“user32.dll”, SetLastError:=True, CharSet:=CharSet.Auto)> Private Shared Function GetWindowText(ByVal hwnd As IntPtr, ByVal lpString As System.Text.StringBuilder, ByVal cch As Integer) As Integer

End Function

<DllImport(“user32.dll”, SetLastError:=True, CharSet:=CharSet.Auto)> Private Shared Function GetWindowTextLength(ByVal hwnd As IntPtr) As Integer

End Function

Private Declare Auto Function SendMessage Lib “user32″ (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wparam As Integer, ByVal lparam As System.Text.StringBuilder) As IntPtr

Private Declare Auto Function SendMessage Lib “user32″ (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr

Private Declare Auto Function FindWindow Lib “user32″ (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

”API Functions

Private Shared Function GetChildWindows(ByVal ParentHandle As IntPtr) As IntPtr()

Dim ChildrenList As New List(Of IntPtr)

Dim ListHandle As GCHandle = GCHandle.Alloc(ChildrenList)

Try

EnumChildWindows(ParentHandle, AddressOf EnumWindow, GCHandle.ToIntPtr(ListHandle))

Finally

If ListHandle.IsAllocated Then ListHandle.Free()

End Try

Return ChildrenList.ToArray

End Function

Private Shared Function EnumWindow(ByVal Handle As IntPtr, ByVal Parameter As IntPtr) As Boolean

Dim ChildrenList As List(Of IntPtr) = GCHandle.FromIntPtr(Parameter).Target

If ChildrenList Is Nothing Then Throw New Exception(“GCHandle Target could not be cast as List(Of IntPtr)”)

ChildrenList.Add(Handle)

Return True

End Function

Public Shared Function GetText(ByVal hWnd As IntPtr) As String

Dim length As Integer

If hWnd.ToInt32 <= 0 Then

Return Nothing

End If

length = GetWindowTextLength(hWnd)

If length = 0 Then

Return Nothing

End If

Dim sb As New System.Text.StringBuilder(“”, length + 1)

GetWindowText(hWnd, sb, sb.Capacity)

Return sb.ToString()

End Function

”Constants

Private Const WM_SETTEXT = &HC

Private Const WM_CHAR = &H102

Private Const WM_KEYDOWN = &H100

Private Const WM_KEYUP = &H101

Private Const WM_SETFOCUS = &H7

”Window Enum Delegate

Private Delegate Function EnumWindowProcess(ByVal Handle As IntPtr, ByVal Parameter As IntPtr) As Boolean

”This function finds the Handle for the MSN Options window

Private Shared Function FindMSN() As IntPtr

FindMSN = FindWindow(vbNullString, “Options”)

End Function

”This function Sends the text to the Options window

Public Shared Function SendText(Optional ByVal Display_Text As String = “”, Optional ByVal Personal_Text As String = “”) As Boolean

”Create the Messenger API

Dim iMessenger As MessengerAPI.Messenger

iMessenger = New MessengerAPI.Messenger

”Show the options window

iMessenger.OptionsPages(0, MessengerAPI.MOPTIONPAGE.MOPT_GENERAL_PAGE)

”Get the options windows handle

Dim handle As IntPtr = FindMSN()

”This will keep looping until the window is found

Do

handle = FindMSN()

Loop Until handle <> 0

”Sleeps the thread while the options window loads

System.Threading.Thread.Sleep(60)

”i is our counter for which control we are on

Dim i As Integer = 0

”Loop through each of the child windows

For Each child As IntPtr In GetChildWindows(handle)

”Gets the class name of the child

Dim sClassName As New System.Text.StringBuilder(“”, 256)

Call GetClassName(child, sClassName, 256)

”Converts it to a readable string

Dim x As String = sClassName.ToString

”If its a textbox

If x = “RichEdit20W” Then

i += 1

”If we are on the first control, the display name box

If i = 1 Then

”If display text is being changed

If Display_Text <> “” Then

”Send the display text to the textbox

Dim sb As New System.Text.StringBuilder(Display_Text)

SendMessage(child, WM_SETTEXT, 0, sb)

SendMessage(child, WM_CHAR, 13, 1)

End If

”If we are on the second control, the personal message box

ElseIf i = 2 Then

”If we are changing the personal text

If Personal_Text <> “” Then

”Send the personal message text to the textbox

Dim sb As New System.Text.StringBuilder(Personal_Text)

SendMessage(child, WM_SETTEXT, 0, sb)

SendMessage(child, WM_CHAR, 13, 1)

End If

End If

”If the child control is the “OK” button

ElseIf GetText(child) = “OK” Then

”Focus the button

SendMessage(child, WM_SETFOCUS, 0, 0)

”Press the Space button, to save changes

SendMessage(child, WM_KEYDOWN, &H20, 390001)

SendMessage(child, WM_CHAR, &H63, 11101)

SendMessage(child, WM_KEYUP, &H20, 390001)

End If

Next

End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

”Create the Messenger API

Dim oMessenger As MessengerAPI.Messenger

oMessenger = New MessengerAPI.Messenger

”Set the status to offline

oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_INVISIBLE

”Change name

SendText(“Mine”)

”Sleep the thread

System.Threading.Thread.Sleep(700)

”Set status to online

oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_ONLINE

”Repeat

oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_INVISIBLE

SendText(“beats”)

System.Threading.Thread.Sleep(700)

oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_ONLINE

oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_INVISIBLE

SendText(“yours”)

System.Threading.Thread.Sleep(700)

oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_ONLINE

oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_INVISIBLE

SendText(“cyb3r”)

System.Threading.Thread.Sleep(700)

oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_ONLINE

oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_INVISIBLE

SendText(“d3m0n”)

System.Threading.Thread.Sleep(700)

oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_ONLINE

End Sub

End Class

You might want to make a function that automates the repeating

Imports System.Runtime.InteropServices
Public Class Form1

”API
<DllImport(”User32.dll”)> Private Shared Function EnumChildWindows(ByVal WindowHandle As IntPtr, ByVal Callback As EnumWindowProcess, ByVal lParam As IntPtr) As Boolean
End Function
<DllImport(”user32.dll”, CharSet:=CharSet.Auto)> Private Shared Sub GetClassName(ByVal hWnd As System.IntPtr, ByVal lpClassName As System.Text.StringBuilder, ByVal nMaxCount As Integer)
End Sub
<DllImport(”user32.dll”, SetLastError:=True, CharSet:=CharSet.Auto)> Private Shared Function GetWindowText(ByVal hwnd As IntPtr, ByVal lpString As System.Text.StringBuilder, ByVal cch As Integer) As Integer
End Function
<DllImport(”user32.dll”, SetLastError:=True, CharSet:=CharSet.Auto)> Private Shared Function GetWindowTextLength(ByVal hwnd As IntPtr) As Integer
End Function

Private Declare Auto Function SendMessage Lib “user32″ (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wparam As Integer, ByVal lparam As System.Text.StringBuilder) As IntPtr
Private Declare Auto Function SendMessage Lib “user32″ (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr
Private Declare Auto Function FindWindow Lib “user32″ (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

”API Functions
Private Shared Function GetChildWindows(ByVal ParentHandle As IntPtr) As IntPtr()
Dim ChildrenList As New List(Of IntPtr)
Dim ListHandle As GCHandle = GCHandle.Alloc(ChildrenList)
Try
EnumChildWindows(ParentHandle, AddressOf EnumWindow, GCHandle.ToIntPtr(ListHandle))
Finally
If ListHandle.IsAllocated Then ListHandle.Free()
End Try
Return ChildrenList.ToArray
End Function
Private Shared Function EnumWindow(ByVal Handle As IntPtr, ByVal Parameter As IntPtr) As Boolean
Dim ChildrenList As List(Of IntPtr) = GCHandle.FromIntPtr(Parameter).Target
If ChildrenList Is Nothing Then Throw New Exception(”GCHandle Target could not be cast as List(Of IntPtr)”)
ChildrenList.Add(Handle)
Return True
End Function
Public Shared Function GetText(ByVal hWnd As IntPtr) As String
Dim length As Integer
If hWnd.ToInt32 <= 0 Then
Return Nothing
End If
length = GetWindowTextLength(hWnd)
If length = 0 Then
Return Nothing
End If
Dim sb As New System.Text.StringBuilder(”", length + 1)
GetWindowText(hWnd, sb, sb.Capacity)
Return sb.ToString()
End Function

”Constants
Private Const WM_SETTEXT = &HC
Private Const WM_CHAR = &H102
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const WM_SETFOCUS = &H7

”Window Enum Delegate
Private Delegate Function EnumWindowProcess(ByVal Handle As IntPtr, ByVal Parameter As IntPtr) As Boolean

”This function finds the Handle for the MSN Options window
Private Shared Function FindMSN() As IntPtr
FindMSN = FindWindow(vbNullString, “Options”)
End Function

”This function Sends the text to the Options window
Public Shared Function SendText(Optional ByVal Display_Text As String = “”, Optional ByVal Personal_Text As String = “”) As Boolean
”Create the Messenger API
Dim iMessenger As MessengerAPI.Messenger
iMessenger = New MessengerAPI.Messenger
”Show the options window
iMessenger.OptionsPages(0, MessengerAPI.MOPTIONPAGE.MOPT_GENERAL_PAGE)
”Get the options windows handle
Dim handle As IntPtr = FindMSN()
”This will keep looping until the window is found
Do
handle = FindMSN()
Loop Until handle <> 0
”Sleeps the thread while the options window loads
System.Threading.Thread.Sleep(60)
”i is our counter for which control we are on
Dim i As Integer = 0
”Loop through each of the child windows
For Each child As IntPtr In GetChildWindows(handle)
”Gets the class name of the child
Dim sClassName As New System.Text.StringBuilder(”", 256)
Call GetClassName(child, sClassName, 256)
”Converts it to a readable string
Dim x As String = sClassName.ToString
”If its a textbox
If x = “RichEdit20W” Then
i += 1
”If we are on the first control, the display name box
If i = 1 Then
”If display text is being changed
If Display_Text <> “” Then
”Send the display text to the textbox
Dim sb As New System.Text.StringBuilder(Display_Text)
SendMessage(child, WM_SETTEXT, 0, sb)
SendMessage(child, WM_CHAR, 13, 1)
End If
”If we are on the second control, the personal message box
ElseIf i = 2 Then
”If we are changing the personal text
If Personal_Text <> “” Then
”Send the personal message text to the textbox
Dim sb As New System.Text.StringBuilder(Personal_Text)
SendMessage(child, WM_SETTEXT, 0, sb)
SendMessage(child, WM_CHAR, 13, 1)
End If
End If
”If the child control is the “OK” button
ElseIf GetText(child) = “OK” Then
”Focus the button
SendMessage(child, WM_SETFOCUS, 0, 0)
”Press the Space button, to save changes
SendMessage(child, WM_KEYDOWN, &H20, 390001)
SendMessage(child, WM_CHAR, &H63, 11101)
SendMessage(child, WM_KEYUP, &H20, 390001)
End If
Next
End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
”Create the Messenger API
Dim oMessenger As MessengerAPI.Messenger
oMessenger = New MessengerAPI.Messenger
”Set the status to offline
oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_INVISIBLE
”Change name
SendText(”Mine”)
”Sleep the thread
System.Threading.Thread.Sleep(700)
”Set status to online
oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_ONLINE

”Repeat
oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_INVISIBLE
SendText(”beats”)
System.Threading.Thread.Sleep(700)
oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_ONLINE
oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_INVISIBLE
SendText(”yours”)
System.Threading.Thread.Sleep(700)
oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_ONLINE
oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_INVISIBLE
SendText(”cyb3r”)
System.Threading.Thread.Sleep(700)
oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_ONLINE
oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_INVISIBLE
SendText(”d3m0n”)
System.Threading.Thread.Sleep(700)
oMessenger.MyStatus = MessengerAPI.MISTATUS.MISTATUS_ONLINE
End Sub
End Class

VB Net - MSN Xfire Personal Message

Imports System.Runtime.InteropServices

Public Class Form1

#Region “APIS+CONST”

”Here are the API Functions needed

<DllImport(“User32.dll”)> Private Shared Function EnumChildWindows(ByVal WindowHandle As IntPtr, ByVal Callback As EnumWindowProcess, ByVal lParam As IntPtr) As Boolean

End Function

<DllImport(“user32.dll”, CharSet:=CharSet.Auto)> Private Shared Sub GetClassName(ByVal hWnd As System.IntPtr, ByVal lpClassName As System.Text.StringBuilder, ByVal nMaxCount As Integer)

End Sub

Private Declare Auto Function FindWindow Lib “user32″ (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

Private Declare Auto Function SendMessage Lib “user32″ (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wparam As Integer, ByVal lparam As System.Text.StringBuilder) As IntPtr

Private Declare Auto Function SendMessage Lib “user32″ (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr

Private Declare Function SendMessage2 Lib “user32.dll” Alias “SendMessageA” (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As IntPtr) As Int32

Private Declare Function FindWindowEx Lib “user32.dll” Alias “FindWindowExA” (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32

Private Const WM_GETTEXT = &HD

Private Const WM_GETTEXTLENGTH As Integer = &HE

Private Const WM_SETTEXT = &HC

Private Structure COPYDATASTRUCT

Public dwData As Int32

Public cbData As Int32

Public lpData As IntPtr

End Structure

Private Const WM_COPYDATA As Int32 = &H4A

#End Region

#Region “Functions/Enums not to edit”

Private Delegate Function EnumWindowProcess(ByVal Handle As IntPtr, ByVal Parameter As IntPtr) As Boolean

Private Enum IconType

Music

Games

Office

End Enum ”This contains the values for the different MSN now playing icons

Private Shared Function GetChildWindows(ByVal ParentHandle As IntPtr) As IntPtr() ”Gets the list of child windows from the parent window

Dim ChildrenList As New List(Of IntPtr)

Dim ListHandle As GCHandle = GCHandle.Alloc(ChildrenList)

Try

EnumChildWindows(ParentHandle, AddressOf EnumWindow, GCHandle.ToIntPtr(ListHandle)) ”Enumerates the windows

Finally

If ListHandle.IsAllocated Then ListHandle.Free()

End Try

Return ChildrenList.ToArray ”Returns the list of windows as a collection on IntPrt, which is then searched in

End Function

Private Shared Function EnumWindow(ByVal Handle As IntPtr, ByVal Parameter As IntPtr) As Boolean

Dim ChildrenList As List(Of IntPtr) = GCHandle.FromIntPtr(Parameter).Target

If ChildrenList Is Nothing Then Throw New Exception(“GCHandle Target could not be cast as List(Of IntPtr)”)

ChildrenList.Add(Handle) ”Adds a list of window handles

Return True

End Function

Private Shared Function FindXfire() As IntPtr

FindXfire = FindWindow(“SkinWnd”, vbNullString) ”Finds handle of the Xfire class window

End Function

Private Shared Function SendText(ByVal Text As String) As Boolean

Shell(“xfire:status?text=” & Text) ”Sets the Xfire status

End Function

Private Shared Function ReadText() As String

ReadText = “”

Dim handle As IntPtr = FindXfire()

If handle = 0 Then ”If the window isnt found

MessageBox.Show(“Xfire window not found.”, “Error:”, MessageBoxButtons.OK, MessageBoxIcon.Error)

Return “Error;”

Exit Function

End If

For Each child As IntPtr In GetChildWindows(handle) ”Loop through list of windows

Dim sClassName As New System.Text.StringBuilder(“”, 256)

Call GetClassName(child, sClassName, 256)

If sClassName.ToString = “Edit” Then ”Reads the class name of the handle

Dim conLength As IntPtr

conLength = SendMessage(child, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero) ”Gets the length of the text

Dim sbText As New System.Text.StringBuilder(conLength.ToInt32 + 1)

Dim ptrRet As IntPtr

ptrRet = SendMessage(child, WM_GETTEXT, conLength.ToInt32 + 1, sbText) ”Reads the text from the handle

If Not sbText.ToString = “” Then

Return sbText.ToString ”returns the text

End If

End If

Next

End Function

Private Shared Sub SetPlayingInfo(ByVal Artist As String, ByVal Album As String, ByVal Title As String, Optional ByVal Icon As IconType = IconType.Music, Optional ByVal WMContentID As String = vbNullString, Optional ByVal Format As String = “{0} - {1}”, Optional ByVal Show As Boolean = True)

”Not my function

Dim mess As String = String.Format(“{0}{1}{2}{3}{4}{5}{6}” & vbNullChar, Icon.ToString, Math.Abs(CInt(Show)), Format, Artist, Title, Album, WMContentID)

Dim lpMess As GCHandle = GCHandle.Alloc(mess, GCHandleType.Pinned)

Dim CD As COPYDATASTRUCT

With CD

.dwData = &H547

.cbData = mess.Length * 2

.lpData = lpMess.AddrOfPinnedObject

End With

Dim lpCD As GCHandle = GCHandle.Alloc(CD, GCHandleType.Pinned)

Dim hMSGRUI As Integer

Do

hMSGRUI = FindWindowEx(0, hMSGRUI, “MsnMsgrUIManager”, vbNullString)

If (hMSGRUI > 0) Then

SendMessage2(hMSGRUI, WM_COPYDATA, 0, lpCD.AddrOfPinnedObject)

End If

Loop Until (hMSGRUI = 0)

lpMess.Free()

lpCD.Free()

End Sub

#End Region

Private Xfolder As IO.FileSystemWatcher = New System.IO.FileSystemWatcher()

Private work As Boolean = True

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim path As String = My.Computer.FileSystem.GetParentPath(My.Computer.FileSystem.GetParentPath(My.Computer.FileSystem.GetParentPath(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData)))

Xfolder.Path = path & “\Xfire”

Xfolder.NotifyFilter = IO.NotifyFilters.Attributes

AddHandler Xfolder.Changed, AddressOf Changed ”Creates the fsw, to the sub Changed

Xfolder.EnableRaisingEvents = True ”Starts watching

End Sub

Private Sub Changed(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)

If e.Name = “status.ini” Then ”If the modified file is status.ini

Dim Str As String = ReadText() ”reads the window text

If Not Str = “Online” Or Str = “(AFK) Away From Keyboard” Then ”if its not a default one

SetPlayingInfo(“Now Playing”, “i__h4x Logger”, ReadText(), IconType.Games) ”Sets the msn pm to the game

If BackgroundWorker1.IsBusy = False Then ”Starts the bgw which sets the personal message (Incase other programs change it)

BackgroundWorker1.RunWorkerAsync()

work = True

End If

End If

End If

End Sub

Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

Do

Dim Str As String = ReadText()

If Not Str = “Online” Or Str = “(AFK) Away From Keyboard” Then

SetPlayingInfo(“Now Playing”, “i__h4x Logger”, ReadText(), IconType.Games)

Else ”Does same as in Changed

SetPlayingInfo(“Now Playing”, “i__h4x Logger”, “Nothing”, IconType.Games)

work = False ”If the game has been closed, then it ends the bgw

End If

System.Threading.Thread.Sleep(200) ”pauses the loop

Loop Until work = False

BackgroundWorker1.WorkerSupportsCancellation = True

BackgroundWorker1.CancelAsync() ”ends the bgw

End Sub

End Class

This will change your MSN personal message to whatever you have in Xfire, you can see it change as you type, expect to see a full project released soon.

VB Net - MSN Nudge Spam

Public Shared Sub NudgeSpam(ByVal count As String, ByVal contact As String)
Dim oMessenger As MessengerAPI.Messenger
oMessenger = New MessengerAPI.Messenger
Dim msncontact As IMessengerContact
Dim msncontacts As IMessengerContacts
msncontacts = oMessenger.MyContacts
For Each msncontact In msncontacts
If msncontact.SigninName = contact Then
Dim times As Integer = 0
Dim wnd As Integer = “0″
wnd = FindWindowByCaption(0, msncontact.FriendlyName & ” - Conversation”)
If wnd = 0 Then
Dim Processes() As System.Diagnostics.Process
Processes = System.Diagnostics.Process.GetProcessesByName(”msnmsgr”)
wnd = Processes(0).MainWindowHandle
End If
Do
times += 1
SendMessage(wnd, WM_COMMAND, CMD_NUDGE, 0)
Loop Until times = count
MessageBox.Show(”Done”, “MSN Nudge Spam”, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
Next
MessageBox.Show(”Error, contact matching that email was not found”, “Error:”, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Sub

Usage: NudgeSpam(100, “spiderman@hotmail.com”)

Note: Need to have a patched MSN that removes nudge timer

VB Net - Change MSN Personal Message

Public Enum IconType
Music
Games
Office
End Enum
Public Declare Function SendMessage Lib “user32.dll” Alias “SendMessageA” (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As IntPtr) As Int32
Public Declare Function FindWindowEx Lib “user32.dll” Alias “FindWindowExA” (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32
Public Structure COPYDATASTRUCT
Public dwData As Int32
Public cbData As Int32
Public lpData As IntPtr
End Structure
Public Const WM_COPYDATA As Int32 = &H4A

Public Shared Sub SetPlayingInfo(ByVal Artist As String, ByVal Album As String, ByVal Title As String, Optional ByVal Icon As IconType = IconType.Music, Optional ByVal WMContentID As String = vbNullString, Optional ByVal Format As String = “{0} - {1}”, Optional ByVal Show As Boolean = True)
Dim mess As String = String.Format(”{0}{1}{2}{3}{4}{5}{6}” & vbNullChar, Icon.ToString, Math.Abs(CInt(Show)), Format, Artist, Title, Album, WMContentID)
Dim lpMess As GCHandle = GCHandle.Alloc(mess, GCHandleType.Pinned)
Dim CD As COPYDATASTRUCT
With CD
.dwData = &H547
.cbData = mess.Length * 2
.lpData = lpMess.AddrOfPinnedObject
End With
Dim lpCD As GCHandle = GCHandle.Alloc(CD, GCHandleType.Pinned)
Dim hMSGRUI As Integer
Do
hMSGRUI = FindWindowEx(0, hMSGRUI, “MsnMsgrUIManager”, vbNullString)
If (hMSGRUI > 0) Then
SendMessage(hMSGRUI, WM_COPYDATA, 0, lpCD.AddrOfPinnedObject)
End If
Loop Until (hMSGRUI = 0)
lpMess.Free()
lpCD.Free()
End Sub