⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 清华大学出版社出版的 移动应用开发宝典 张大威(2008)的附书源代码
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace COMInterop
{
    internal partial class Form1 : Form, IMAPIAdviseSink 
    {
        IMAPISession session;
        //an id used by the advise method
        int connection;

        public Form1()
        {
            InitializeComponent();
        }

        #region IMAPIAdviseSink Members

        public void OnNotify(uint cNotif, ref NOTIFICATION lpNotifications)
        {
            switch (lpNotifications.ulEventType)
            {
                case fnev.ObjectCreated:
                    byte[] entryid = new byte[lpNotifications.newmail.cbEntryID];
                    Marshal.Copy(lpNotifications.newmail.lpEntryID, entryid, 0, entryid.Length);
                    Chapter14.Media.SystemSounds.Asterisk.Play();
                    NativeMethods.MailDisplayMessage(entryid, entryid.Length);
                    break;
            }
        }

        #endregion

        private void Form1_Load(object sender, EventArgs e)
        {
            int hresult = NativeMethods.MAPIInitialize(IntPtr.Zero);
            IntPtr psession;
            hresult = NativeMethods.MAPILogonEx(0, null, null, 0, out psession);
            //fix for stupid COM implementation
            session = (IMAPISession) InTheHand.Runtime.InteropServices.Marshal2.GetTypedObjectForIUnknown(psession, typeof(IMAPISession));

            session.Advise(0, null, fnev.ObjectCreated, this, out connection);
        }

        private void menuItem1_Click(object sender, EventArgs e)
        { 
            this.Close();
        }

        private void Form1_Closing(object sender, CancelEventArgs e)
        {
            session.Unadvise(connection);
            NativeMethods.MAPIUninitialize();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -