MainForm.cs
上传用户:linger1010
上传日期:2008-12-08
资源大小:561k
文件大小:2k
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using Microsoft.WindowsMobile.PocketOutlook;
- using Microsoft.WindowsMobile.PocketOutlook.MessageInterception;
- namespace InterceptingMessages
- {
- public partial class MainForm : Form
- {
- MessageInterceptor m_interceptor;
- StringBuilder m_sbMessages;
- public MainForm()
- {
- InitializeComponent();
- m_interceptor = new MessageInterceptor();
- m_interceptor.MessageReceived += new MessageInterceptorEventHandler(m_onMessageReceived);
- m_sbMessages = new StringBuilder();
- }
- void m_onMessageReceived(object sender, MessageInterceptorEventArgs e)
- {
- if(e.Message is SmsMessage)
- m_receiveSms(e.Message as SmsMessage);
- }
- private void m_receiveSms(SmsMessage smsMessage)
- {
- // From
- m_sbMessages.Append("From:rn");
- m_sbMessages.Append(String.Format("tName: {0}rn", smsMessage.From.Name));
- m_sbMessages.Append(String.Format("tAddress: {0}rn", smsMessage.From.Address));
- // Received
- m_sbMessages.Append("Received:rn");
- m_sbMessages.Append(String.Format("t{0}rn", smsMessage.Received.ToString()));
- // Sent
- m_sbMessages.Append("Sent:rn");
- m_sbMessages.Append(String.Format("t{0}rn", smsMessage.LastModified.ToString()));
- // Body
- m_sbMessages.Append("Message:rn");
- m_sbMessages.Append(String.Format("t{0}rn", smsMessage.Body));
- // refresh
- m_txtMessages.Text = m_sbMessages.ToString();
- // add a new line
- m_sbMessages.Append("rn");
- }
- private void m_mnuClear_Click(object sender, EventArgs e)
- {
- m_sbMessages.Remove(0, m_sbMessages.Length);
- m_txtMessages.Text = m_sbMessages.ToString();
- }
- private void m_mnuExit_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- }
- }