监视来到的短消息例子

来源:互联网 发布:行业应用类软件 编辑:程序博客网 时间:2024/04/29 10:04

监视来到的短消息例子

 

这个例子是按照监视来到的短消息,然后按照提取短消息的内容,我们可以按照里面的内容
让程序做些动作,本个例子是发送你的未读的SMS,MAIL,MMS的数量,由此可以推开得到一些
其他的应用。。

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;
using Microsoft.WindowsMobile.Telephony;
using Microsoft.WindowsMobile.PocketOutlook.MessageInterception;
using Microsoft.WindowsMobile.Status;
//using Microsoft.WindowsMobile.Status.SystemState;

namespace AppDemo
{
public partial class Form1 : Form
{
private OutlookSession AppSession;
private OutlookSession SmsSession;
private AppointmentCollection AppAppts;
private ListViewItem lviAppt;
private ListViewItem smsItem;
private MessageInterceptor interceptor;
public Form1()
{
InitializeComponent();
interceptor
= new MessageInterceptor(InterceptionAction.Notify);
interceptor.MessageReceived
+= new MessageInterceptorEventHandler(interceptor_MessageReceived);
}


private void button1_Click(object sender, EventArgs e)
{
AppSession
= new OutlookSession();
AppAppts
= AppSession.Appointments.Items;
foreach (Appointment appt in AppAppts)
{
lviAppt
= new ListViewItem();
lviAppt.Text
= appt.Start.ToShortDateString();
lviAppt.SubItems.Add(appt.Start.ToShortTimeString());
lviAppt.SubItems.Add(appt.Subject);
lvAppt.Items.Add(lviAppt);
}

AppSession.Dispose();
}


private void button2_Click(object sender, EventArgs e)
{
Phone phone
= new Phone();
try
{
phone.Talk(
13425173242);
}

catch
{
MessageBox.Show(
Can’t Dailing…);
}

}


private void button3_Click(object sender, EventArgs e)
{
SmsSession
= new OutlookSession();

//SmsAccount sms ;
smsItem = new ListViewItem();
smsItem.Text
= (String)SmsSession.SmsAccount.Name;
lvAppt.Items.Add(smsItem);
}


private void button4_Click(object sender, EventArgs e)
{
if (btnActivate.Text.IndexOf(Activate) != -1)
{
interceptor
= new MessageInterceptor(InterceptionAction.Notify);
interceptor.MessageReceived
+= new MessageInterceptorEventHandler(interceptor_MessageReceived);
btnActivate.Text
= Deactivate;
}


if (btnActivate.Text.IndexOf(Deactivate) != -1)
{
interceptor.Dispose();
interceptor
= null;
btnActivate.Text
= Activate;
}

interceptor_MessageReceived((
object)sender ,( MessageInterceptorEventArgs )e );
}




void interceptor_MessageReceived(object sender, MessageInterceptorEventArgs e)
{
SmsMessage sms
= (SmsMessage)e.Message;
string strFrom = sms.From.Address;
string strMessageText = sms.Body.Trim().ToLower();
bool bGotCommand = false;
string strReplyMessage = “”;

switch (strMessageText)
{
case getunreadsms:
strReplyMessage
= Unread SMS: +SystemState.MessagingSmsUnread;
bGotCommand
= true;
break;

case getunreademail:
strReplyMessage
= Unread Email: +SystemState.MessagingTotalEmailUnread;
bGotCommand
= true;
break;

case getunreadmms:
strReplyMessage
= Unread MMS: +SystemState.MessagingMmsUnread;
bGotCommand
= true;
break;
}


if (bGotCommand == true)
{
SmsMessage replySMS
= new SmsMessage();
replySMS.To.Add(
new Recipient(strFrom));
replySMS.Body
= strReplyMessage;
replySMS.Send();
}

}

原创粉丝点击