dotnet-Snippets.com
Snippets: 57 | Registered User: 27 | Visitors online: 4
Main Menu

Home
Random Snippet
FAQs
Contact Us
Imprint
RSS Feeds

Rss All languages
Rss C#
Rss VB.NET
Rss C++
Rss J#
Rss ASP.NET
Google Ads

Sri Lanka .NET 
                Forum Member
Windows Live Messenger "Now Playing"

Author: Tim Hartwig
Programming Language: VB.NET Rating:
not yet rated

Views: 783

Description:

This class allows you to send a string to Windows Live Messenger to let other users see what you are just listening, like Windows Media Player.



Visual Basic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Imports System.Runtime.InteropServices

Public 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 Function
End Class


This Snippets could be interesting for you:
No results available

Poor Excellent
1 2 3 4 5 6 7 8 9 10
Sign in to vote for this snippet.

Comments:
(Please log in to wrtite an comment.)