What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Plug-Ins » how to catch the MessengerPlus_DisplayToast in VB.NET or C#?

how to catch the MessengerPlus_DisplayToast in VB.NET or C#?
Author: Message:
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
RE: how to catch the MessengerPlus_DisplayToast in VB.NET or C#?
It took me a while to figure out how to do this with C#, but with help from MSND and of course with raceprouk's code, it finally worked!

Here it is:

code:
// For the dll import
using System.Runtime.InteropServices;

// Filter function delegate
public delegate int HookProc(int code, IntPtr wParam, IntPtr lParam);

// Hook Types 
public enum HookType : int
{
   WH_JOURNALRECORD = 0,
   WH_JOURNALPLAYBACK = 1,
   WH_KEYBOARD = 2,
   WH_GETMESSAGE = 3,
   WH_CALLWNDPROC = 4,
   WH_CBT = 5,
   WH_SYSMSGFILTER = 6,
   WH_MOUSE = 7,
   WH_HARDWARE = 8,
   WH_DEBUG = 9,
   WH_SHELL = 10,
   WH_FOREGROUNDIDLE = 11,
   WH_CALLWNDPROCRET = 12,
   WH_KEYBOARD_LL = 13,
   WH_MOUSE_LL = 14
}

// The CWPSTRUCT structure
public struct CWPSTRUCT
{
   public IntPtr lParam;
   public IntPtr wParam;
   public uint message;
   public IntPtr hwnd;
}

// the MSG structure
struct MSG
{
   public Int32 hwnd;
   public Int32 message;
   public Int32 wParam;
   public Int32 lParam;
   public Int32 time;
   public Point pt;
}


// Win32: SetWindowsHookEx()
[DllImport("user32.dll")]
protected static extern IntPtr SetWindowsHookEx(HookType code,
   HookProc func,
   IntPtr hInstance,
   int threadID);

// Win32: UnhookWindowsHookEx()
[DllImport("user32.dll")]
protected static extern int UnhookWindowsHookEx(IntPtr hhook);

// Win32: CallNextHookEx()
[DllImport("user32.dll")]
protected static extern int CallNextHookEx(IntPtr hhook,
   int code, IntPtr wParam, IntPtr lParam);

// Win32: RegisterWindowMessage()
[DllImport("user32.dll")]
protected static extern uint RegisterWindowMessage(string lpString);

// Variable declares
IntPtr cwp;
IntPtr gmp;
uint msgID;

public void Initialize()
{
      HookProc hCallWndProc = new HookProc(CallWndProc);
      cwp = SetWindowsHookEx(HookType.WH_CALLWNDPROC, hCallWndProc, IntPtr.Zero, AppDomain.GetCurrentThreadId());
      HookProc hGetMsgProc = new HookProc(GetMsgProc);
      gmp = SetWindowsHookEx(HookType.WH_GETMESSAGE, hGetMsgProc, IntPtr.Zero, AppDomain.GetCurrentThreadId());

      msgID = RegisterWindowMessage("MessengerPlus_DisplayToast");
}

int CallWndProc(int code, IntPtr wParam, IntPtr lParam)
{
   if (code >= 0)
   {
       CWPSTRUCT msg = (CWPSTRUCT)Marshal.PtrToStructure(lParam, typeof(CWPSTRUCT));
       if (msg.message == msgID)
       {
           // Do something here
       }
   }
   return CallNextHookEx(cwp, code, wParam, lParam);
}

int GetMsgProc(int code, IntPtr wParam, IntPtr lParam)
{
   if (code >= 0)
   {
       MSG msg = (MSG)Marshal.PtrToStructure(lParam, typeof(MSG));
       if (msg.message == msgID)
       {
           // Do something here
       }
   }
   return CallNextHookEx(cwp, code, wParam, lParam);
}

void Uninitialize()
{
   UnhookWindowsHookEx(cwp);
   UnhookWindowsHookEx(gmp);
}

edit: forgot to include the "using" statement

This post was edited on 06-06-2006 at 03:21 PM by J-Thread.
06-06-2006 03:17 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
how to catch the MessengerPlus_DisplayToast in VB.NET or C#? - by guojivip on 06-02-2006 at 03:15 AM
RE: how to induce the MessengerPlus_DisplayToast in VB.NET or C# - by J-Thread on 06-02-2006 at 06:07 AM
RE: how to catch the MessengerPlus_DisplayToast in VB.NET or C# - by guojivip on 06-02-2006 at 07:08 AM
RE: how to catch the MessengerPlus_DisplayToast in VB.NET or C#? - by J-Thread on 06-02-2006 at 11:44 AM
RE: how to catch the MessengerPlus_DisplayToast in VB.NET or C#? - by guojivip on 06-02-2006 at 12:23 PM
RE: how to catch the MessengerPlus_DisplayToast in VB.NET or C#? - by RaceProUK on 06-03-2006 at 09:05 PM
RE: RE: how to catch the MessengerPlus_DisplayToast in VB.NET or C#? - by J-Thread on 06-05-2006 at 04:15 PM
RE: how to catch the MessengerPlus_DisplayToast in VB.NET or C#? - by RaceProUK on 06-06-2006 at 12:01 PM
RE: how to catch the MessengerPlus_DisplayToast in VB.NET or C#? - by J-Thread on 06-06-2006 at 03:17 PM
RE: how to catch the MessengerPlus_DisplayToast in VB.NET or C#? - by RaceProUK on 06-07-2006 at 02:16 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On