|
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace GmailForWin7
{
public class WindowsMessageHelper
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern int RegisterWindowMessage(string msgName);
// Custom messages we need
public static int CheckNowMsgId { get; protected set; }
public static int ShowSettingsMsgId { get; protected set; }
static WindowsMessageHelper()
{
CheckNowMsgId = RegisterWindowMessage("GmailForWin7.CheckNow");
ShowSettingsMsgId = RegisterWindowMessage("GmailForWin7.Settings");
}
public static int RegisterMessage(string msgName)
{
return RegisterWindowMessage(msgName);
}
public static void SendMessage(string windowTitle, int msgId)
{
SendMessage(windowTitle, msgId, IntPtr.Zero, IntPtr.Zero);
}
public static bool SendMessage(string windowTitle, int msgId, IntPtr wParam, IntPtr lParam)
{
IntPtr WindowToFind = FindWindow(null, windowTitle);
if (WindowToFind == IntPtr.Zero) return false;
long result = SendMessage(WindowToFind, msgId, wParam, lParam);
if (result == 0) return true;
else return false;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I have been developing .NET applications since 2001 and have been working in software development since 1989.