Click here to Skip to main content
15,890,512 members
Articles / Programming Languages / C#
Article

MSN Floating Personal Message

Rate me:
Please Sign up or sign in to vote.
2.90/5 (10 votes)
31 Aug 2005CPOL 87.6K   1.2K   33   12
Showing floating text message on the MSN Messenger as a personal message
Sample Image - MSNFloatingText.jpg

Introduction

This application gives the ability of writing floating text messages to the Personal Message of the MSN Messenger.

The application has speed, direction, and icon options. The user can select the speed of float as a value of milliseconds. Moreover, the user can select the direction of the movement, Left to Right or Right to Left. There are three icon options: Office, Games, and Music. When the Music icon option is selected, the text became as a textlink.

The application must be open during the making of the floating text message. When the application is minimized, it is shown as a trayicon. It will not be seen on the taskbar.

MSN Object Declarations

C#
[DllImport("user32", EntryPoint="SendMessageA")]
private static extern int SendMessage(int Hwnd, int wMsg, int wParam, int lParam);

[DllImport("user32", EntryPoint="FindWindowExA")]
private static extern int FindWindowEx(int hWnd1, int hWnd2, string lpsz1, string lpsz2);
private const short WM_COPYDATA = 74;

public struct COPYDATASTRUCT
{
  public int dwData;
  public int cbData;
  public int lpData;
}
public COPYDATASTRUCT data;

Function that Makes Interop to MSN Messenger

C#
public int VarPtr(object e)
{
  GCHandle GC = GCHandle.Alloc(e, GCHandleType.Pinned);
  int gc = GC.AddrOfPinnedObject().ToInt32();
  GC.Free();
  return gc;
}

private void SendMSNMessage(bool enable, string category, string message)
{
  string buffer = "\\0" + category + "\\0" + (enable ? "1" : "0") + 
				"\\0{0}\\0" + message + "\\0\\0\\0\\0\0";
  int handle = 0;

    data.dwData = 0x0547;
    data.lpData = VarPtr(buffer);
    data.cbData = buffer.Length * 2;

    handle = FindWindowEx(0, handle, "MsnMsgrUIManager", null);
    if (handle > 0) 
        SendMessage(handle, WM_COPYDATA, 0, VarPtr(data));
}

History

  • 31st August, 2005: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Turkey Turkey
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 2 Pin
egothic31-Mar-10 10:43
professionalegothic31-Mar-10 10:43 
Generalbad word filter to protect my kids. with [***********] 's Pin
ZUPERKOOL7-Feb-10 7:55
ZUPERKOOL7-Feb-10 7:55 
GeneralVarPtr Pin
Mikael Svenson26-Nov-09 21:08
Mikael Svenson26-Nov-09 21:08 
GeneralLive Messenger 2009 Pin
Alain Raza4-Mar-09 8:48
Alain Raza4-Mar-09 8:48 
GeneralMore icons Pin
Jhonmiller@qatar.net.qa6-Sep-07 8:22
Jhonmiller@qatar.net.qa6-Sep-07 8:22 
QuestionHELP Pin
young geek26-Jul-07 5:23
young geek26-Jul-07 5:23 
GeneralTranslation Pin
LegionFX11-Jun-07 1:22
LegionFX11-Jun-07 1:22 
GeneralRe: Translation Pin
LegionFX11-Jun-07 1:29
LegionFX11-Jun-07 1:29 
GeneralRe: Translation Pin
LegionFX13-Jun-07 0:20
LegionFX13-Jun-07 0:20 
never mind. solved. i used your controls but it this code. its easy.

<stathread()> _
Private Shared Sub Main()
Application.EnableVisualStyles()
Application.Run(New Form1())
End Sub



Private temptext As String


<dllimport("user32", entrypoint:="SendMessageA" )=""> _
Private Shared Function SendMessage(ByVal Hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function

<dllimport("user32", entrypoint:="FindWindowExA" )=""> _
Private Shared Function FindWindowEx(ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
End Function

Private Const WM_COPYDATA As Short = 74

Public Structure COPYDATASTRUCT
Public dwData As Integer
Public cbData As Integer
Public lpData As Integer
End Structure
Public data As COPYDATASTRUCT


Public Function VarPtr(ByVal e As Object) As Integer
Dim GC As GCHandle = GCHandle.Alloc(e, GCHandleType.Pinned)
Dim gcc As Integer = GC.AddrOfPinnedObject().ToInt32()
GC.Free()
Return gcc
End Function

Private Sub SendMSNMessage(ByVal enable As Boolean, ByVal category As String, ByVal message As String)
Dim buffer As String = "\0" + category + "\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 Sub timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles timer1.Tick
If btnRTL.Checked Then
temptext = temptext.Substring(1) + temptext.Substring(0, 1)
Else
temptext = temptext.Substring(temptext.Length - 1) + temptext.Substring(0, temptext.Length - 1)
End If
SendMSNMessage(True, cbIcon.SelectedItem.ToString(), temptext)

End Sub
Private Sub numericUpDown1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs)
timer1.Interval = Convert.ToInt16(numericUpDown1.Value)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

cbIcon.SelectedIndex = 0

End Sub
GeneralGrr Pin
MatijaSakoman21-Feb-07 10:10
MatijaSakoman21-Feb-07 10:10 
GeneralTo make it run in 64 bit system Pin
treeleung28-Jun-06 14:46
treeleung28-Jun-06 14:46 
GeneralRe: To make it run in 64 bit system Pin
Zonakusu.NET3-Mar-09 8:17
Zonakusu.NET3-Mar-09 8:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.