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 
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Runtime.InteropServices

Namespace MsnFloatingText
Public Class MsnFloatingTextForm
Inherits System.Windows.Forms.Form
Private txtText As System.Windows.Forms.TextBox
Private btnAction As System.Windows.Forms.Button
Private label1 As System.Windows.Forms.Label
Private btnLTR As System.Windows.Forms.RadioButton
Private btnRTL As System.Windows.Forms.RadioButton
Private btnAbout As System.Windows.Forms.Button
Private cbIcon As System.Windows.Forms.ComboBox
Private timer1 As System.Windows.Forms.Timer
Private numericUpDown1 As System.Windows.Forms.NumericUpDown
Private label2 As System.Windows.Forms.Label
Private label3 As System.Windows.Forms.Label
Private notifyIcon1 As System.Windows.Forms.NotifyIcon
Private components As System.ComponentModel.IContainer

Public Sub New()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If components IsNot Nothing Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
<stathread()> _
Private Shared Sub Main()
Application.EnableVisualStyles()
Application.Run(New MsnFloatingTextForm())
End Sub


#region Variables
Private temptext As String
#endregion

#region MSN object Declaretions

<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

#endregion

#region MSN Functions

Public Function VarPtr(ByVal e As Object) As Integer
Dim GC As GCHandle = GCHandle.Alloc(e, GCHandleType.Pinned)
Dim gc As Integer = GC.AddrOfPinnedObject().ToInt32()
GC.Free()
Return gc
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

#endregion

#region Button Events
Private Sub btnAbout_Click(ByVal sender As Object, ByVal e As System.EventArgs)
MessageBox.Show("FC MsnFloatingText", "About", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information)
End Sub
Private Sub btnAction_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If txtText.Text.Trim() <> "" Then
If Not timer1.Enabled Then
temptext = txtText.Text + " "
timer1.Enabled = True
btnAction.Text = "Stop"
Else
btnAction.Text = "Start"
timer1.Enabled = False
SendMSNMessage(False, "Office", "")
End If
End If
End Sub

#endregion

#region Load Form
Private Sub MsnFloatingTextForm_Load(ByVal sender As Object, ByVal e As System.EventArgs)
cbIcon.SelectedIndex = 0
End Sub

#endregion

#region TimerTick Events
Private Sub timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
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
#endregion

#region NotifyIcon Events
Private Sub MsnFloatingTextForm_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs)
Try
If Me.WindowState = FormWindowState.Minimized Then
Me.notifyIcon1.Visible = True
Me.Visible = False
End If
Catch err As Exception
MessageBox.Show(err.Message)
End Try
End Sub

Private Sub notifyIcon1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Me.Visible = True
Me.WindowState = FormWindowState.Normal
Me.notifyIcon1.Visible = False
End Sub
#endregion
End Class
End Namespace



this is the translation i made using a webpage to convert C# to vb.net but even after cleaning the code it doesnt work. please help
GeneralRe: Translation Pin
LegionFX13-Jun-07 0:20
LegionFX13-Jun-07 0:20 
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.