Windows Mobile 消息拦截编程

  
Windows Mobile 消息拦截编程
2007年05月31日 星期四,Eddy_0825
最近在做关于消息截获方面的程序,感觉中文资料很少,结合SDK与 http://hi.baidu.com/mych/blog/item/766e7ad9a6967fe838012f4e.html上的内容总结一下:
短消息拦截编程,分为以下几步:
第一步:首先在智能设备工程中加入下面的引用(头文件):
using Microsoft.WindowsMobile;
using Microsoft.WindowsMobile.PocketOutlook;
using Microsoft.WindowsMobile.PocketOutlook.MessageInterception;
第二步:涉及到关于拦截的两个重要的类:   MessageInterceptor负责拦截,当满足拦截标准的信息到来时产生一个事件)             MessageCondition (消息拦截标准). (
// For SMS Message Interception...
private MessageInterceptor _SMSCatcher = new MessageInterceptor(InterceptionAction.NotifyAndDelete, true);
// For setting up the message filter...
private MessageCondition _SMSFilter = new MessageCondition();
 MessageInterceptor构造函数有两个重要的参数:第一个参数定义拦截动作InterceptionAction(当拦截到信息时what to do);特殊的是,消息不需要directly been seen or stored;因此NotifiyAndDelete能正常的监测拦截(注意NotifiyAndDelete处理完拦截消息后,Pocket Outlook删除原来的消息),第二个参数定义是否使用current form's thread,通常设置为True..
第三步:拦截事件触发后,需要创建处理事件的句柄与方法。即为MessageReceived event of the MessageInterceptor创建一个句柄,生成代码如下:
//SMS Message Interception event handler...
_SMSCatcher.MessageReceived += new MessageInterceptorEventHandler(_SMSCatcher_MessageReceived);
SDK中 MessageInterceptorEventHandler 定义如下:
public delegate void MessageInterceptorEventHandler(
      object sender,
      MessageInterceptorEventArgs e
);
第四步:建立MessageCondition object (关于必要的过滤准则)并赋给MessageInterceptor.
//SMS Message Filter setup...
_SMSFilter.Property = MessageProperty.Body;
_SMSFilter.ComparisonType = MessagePropertyComparisonType.StartsWith;
_SMSFilter.CaseSensitive = true;
_SMSFilter.ComparisonValue = "OutlookMobileDemo";

//Assign the filter to the Interceptor...
_SMSCatcher.MessageCondition = _SMSFilter;

The Property
变量是标识过滤器截获哪部分消息的几个标志之一; 对SMS来说, 消息主体与发送者是经常用到的. The ComparisonType 变量决定消息哪部分被选择处理 (StartsWith, EndsWidth, Contains, Equal or NotEqual) . 这个正是程序需要的.The CaseSensitive 变量用于重新决定选择准则,the ComparisonValue 变量是用于比较的实体.
第五步 现在主要的是编写代码,一定要注意 传递给_SMSCatcher_MessageReceived的MessageInterceptorEventArgs 对象,包含截获的所有消息, By casting this property to an SmsMessage object, you can query all of the SMS message's information.
void _SMSCatcher_MessageReceived(object sender, MessageInterceptorEventArgs e)
{
    //Event args pass the SMS message...
    SmsMessage mySMS = (SmsMessage)e.Message;
    //Show a notification popup...
    this.notifyCustomIncoming.Caption = "New SMS";
    this.notifyCustomIncoming.InitialDuration = 60;
    this.notifyCustomIncoming.Text = "Got the special SMS! - " + mySMS.Body.ToString();
    this.notifyCustomIncoming.Visible = true;
}
关于短信拦截内容 SDK 帮助文档中的位置:
Windows Mobile 5.0 Smartphone SDK Developer’s Reference Managed Code Microsoft Windows CE 5.0
Microsoft.Windows Mobile.PocketOutlook.MessageInterception( 还是蛮难找的 )
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值