form1.vb

来自「清华大学出版社出版的 移动应用开发宝典 张大威(2008)的附书源代码」· VB 代码 · 共 39 行

VB
39
字号
Imports System.Runtime.InteropServices
Imports System.ComponentModel


Public Class Form1
    Implements IMAPIAdviseSink

    Private session As IMAPISession
    Private connection As Integer

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Dim psession As IntPtr
        Dim hresult As Integer = NativeMethods.MAPIInitialize(IntPtr.Zero)
        hresult = NativeMethods.MAPILogonEx(0, Nothing, Nothing, 0, psession)
        Me.session = CType(InTheHand.Runtime.InteropServices.Marshal2.GetTypedObjectForIUnknown(psession, GetType(IMAPISession)), IMAPISession)
        Me.session.Advise(0, Nothing, fnev.ObjectCreated, Me, Me.connection)
    End Sub

    Private Sub Form1_Closing(ByVal sender As Object, ByVal e As CancelEventArgs) Handles Me.Closing
        Me.session.Unadvise(Me.connection)
        NativeMethods.MAPIUninitialize()
    End Sub

    Private Sub OnNotify(ByVal cNotif As UInteger, ByRef lpNotifications As NOTIFICATION) Implements IMAPIAdviseSink.OnNotify
        If (lpNotifications.ulEventType = fnev.ObjectCreated) Then
            Dim entryid As Byte() = New Byte(lpNotifications.newmail.cbEntryID - 1) {}
            Marshal.Copy(lpNotifications.newmail.lpEntryID, entryid, 0, entryid.Length)
            Media.SystemSounds.Asterisk.Play()
            NativeMethods.MailDisplayMessage(entryid, entryid.Length)
        End If
    End Sub

    Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
        Me.Close()

    End Sub

End Class

⌨️ 快捷键说明

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