Click here to Skip to main content
15,893,161 members
Articles / Programming Languages / C#

Gmail for Windows 7

Rate me:
Please Sign up or sign in to vote.
4.94/5 (42 votes)
24 Jan 2010CPOL15 min read 151.1K   8.5K   111  
A little application to notify you of new Gmail using new Windows 7 features
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.

License

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


Written By
Web Developer
United States United States
I have been developing .NET applications since 2001 and have been working in software development since 1989.

Comments and Discussions