我的.NET生活

活着便精彩!
随笔 - 41, 评论 - 680, 引用 - 66

导航

关于

标签

每月存档

最新留言

广告

 

在用.NET CF开发Smartphone/Pocket PC应用时,我们经常需要给应用程序增加提醒功能,比如在下午两点时提醒用户去开会,或者在手持设备和PC通过ActiveSync连接时提醒用户同步某项重要数据。目前,实现提醒功能主要有以下几种方式:

 

  1. Windows CE .NET提供了CeSetUserNotification(CE 2.11版本及以后又增加了CeSetUserNotificationEx)这一API,可用于创建或修改提醒。该方法适用于SmartphonePocket PC
  2. Windows CE .NET还提供了另外一条APISHNotificationAdd,也可以完成提醒的工作。该提醒是以Pocket PC中的气泡方式显示的,在Smartphone上不予处理。
  3. Windows CE .NET中内置了Pocket Outlook,并提供了POOM (Pocket Outlook Object Model)以便二次开发。该方法适用于SmartphonePocket PC

 

以上三种方法在开发时,均不同程度地要用到平台调用 (Platform Invoke) COM互操作,这对开发人员的技术要求非常高,同时也不利于提高开发速度。因此,适当的封装是非常有必要的。幸运的是,目前OpenNETCF.org (http://www.opennetcf.org) 已经完成了前两项的工作,在由OpenNETCF开发并免费发放的SDF (Smart Device Framework) 中已经把上述前两项API封装为managed API,从而极大地减少了开发人员的二次开发难度。同时,InTheHand公司 (http://www.inthehand.com) 也提供了一款非常棒的组件——Pocket Outlook,用managed code封装了底层的COM互操作,从而使开发人员从细琐的底层细节摆脱出来。不过,InTheHand这款组件只免费提供测试版,如需要在商业环境中使用还需支付费用。

 

下面我就通过一系列实例来说明上面几种方法的应用。

 

1. OpenNETCF.Win32.Notify

OpenNetCF.orgSDF中的OpenNETCF.Win32.Notify命名空间下封装了CESetUserNotification(以及相应的一套API),使用后只需要短短几行代码就能实现简单的提醒功能,如下例,可以在Smartphone/ Pocket PC 2003上设置一个1分钟后弹出的提醒对话框(需要增加对OpenNETCF.dll的引用):

 

UserNotification notification = new UserNotification();

notification.Action = NotificationAction.Dialog;

notification.Title = "我的提醒";

notification.Text = "别忘了锻炼!";

 

Notify.SetUserNotification("", DateTime.Now.AddMinutes(1), notification);

 

实现效果如下:

 

 

1: Smartphone上应用OpenNETCF.Win32.Notify的效果

 

 

2: Pocket PC上应用OpenNETCF.Win32.Notify的效果

 

如果想修改某项提醒,只需调用Notify.GetUserNotificationHandles返回所有当前系统存储着的提醒的句柄(handle),然后根据其中特定的句柄调用Notify.GetUserNotification就可获得相应的提醒对象,调用Notify.SetUserNotification)来修改该提醒。比如下例,就把刚才设置的提醒内容做了更改:

 

// 获取提醒对象 (UserNotificationInfoHeader类型)

UserNotificationInfoHeader infoHeader =? Notify.GetUserNotification(handle);

// 取出UserNotification部分并做更改

UserNotification notification = infoHeader.UserNotification;

if (notification != null)

{

notification.Text = "别忘了开会!";

Notify.SetUserNotification(handle,"", DateTime.Now.AddSeconds(18), notification);

}

 

2. OpenNETCF.Notification

以上方法对Smartphone 2003Pocket PC 2003同样生效。而对于Pocket PC 2003而言,还有另外一种设置提醒的方式——弹出气泡。该方法对应的操作系统APISHNotificationAdd,在SDF中该API被封装在OpenNETCF.Notification命名空间下。下述代码演示了这种用法(需要增加对OpenNETCF.Notification.dll的引用):

 

Notification notification = new Notification();

notification.Duration = 10;

notification.Flags = NotificationFlags.ForceMessage;

notification.HTML = "Hello Windows Mobile";

notification.Title = "Hi";

 

NotificationEngine engine = new NotificationEngine(OpenNETCF.Security.Cryptography.NativeMethods.Guid.NewGuid());

engine.Add(notification);

 

注意,这里是通过调用NotificationEngine.Add()方法来把一个气泡提醒增加到拖盘(tray)中。

 

 

3: Pocket PC上应用NotificationEngine.Add的效果

 

同样,我们可以通过调用NotificationEngine.Remove来删除某项提醒,NotificationEngine.Update来更新提醒,NotificationEngine.GetData方法来获取提醒内容。它们所封装的系统API分别是SHNotificationRemoveSHNotificationUpdateSHNotificationGetData

 

3. InTheHand.PocketOutlook

 

通过InTheHand封装好的PocketOutlook dll,我们可以非常方便地利用Pocket Outlook所提供的强大功能。比如下面的例子演示如何通过几行代码来在本机的Pocket Outlook中增加一项约会,你可以利用类似的方法来增加联系人、日程信息等等(需要增加对InTheHand.Interop.dllInTheHand.PocketOutlook.dll的引用):

 

using (OutlookApplication oApp = new OutlookApplication())

{

using (Appointment oAptmt = oApp.CreateAppointment())

{

oAptmt.Subject = "提醒";

oAptmt.Body = "别忘了锻炼!";

oAptmt.Start = DateTime.Now.AddHours(1);

oAptmt.BusyStatus = BusyStatus.OutOfOffice;

oAptmt.Save();

}

}

 

实现效果如下:

 

 

4: Smartphone上应用Pocket Outlook增加约会

 

 

5: Pocket PC上应用Pocket Outlook增加约会

 

 

打印 | 张贴于 2004-09-26 13:17:00 | Tag:暂无标签

留言反馈

#回复: 在Smartphone/Pocket PC 2003上设置提醒 编辑
现在找手机操作系统方面书籍的作者。如果您有兴趣的话,可以和我联系,qq:157210787,邮箱:huangzhuhong6354@yahoo.com.cn
手机:13811726940
2007-02-03 11:56:00 | [匿名:xingzhiyun]
#回复: 在Smartphone/Pocket PC 2003上设置提醒 编辑
站长;第二个实现方式,你用的是opennetcf的什么版本啊?我用的是2.0,1,4,都没有找到OpenNETCF.Notification.dll和OpenNETCF.Notification命名空间啊.可以指点一二吗?
我的MSN: zlj23852588@hotmail.com
2007-01-31 17:32:00 | [匿名:zlj]
#回复: 在Smartphone/Pocket PC 2003上设置提醒 编辑
没法使用 InTheHand.PocketOutlook.OutlookApplication
请教怎么可以正常使用!

开发语言 C# .Net 1.1

Dopod 566 Windows Mobile 2003 Second Edition for Smartphone简体中文版
2007-01-05 14:16:00 | [匿名:橙子]
#re: 在Smartphone/Pocket PC 2003上设置提醒 编辑
晕。。。还是不行,一旦使用到含有InTheHand.WindowsMobile.Pocket的函数就立即报错,错误信息还是

TypeLoadException
无法从程序集
InTheHand.WindowsMobile.Pocke
Version=1.7.50922.0,
Culture=neutral,
PublickKeyToken=EA38CAA273134
加载类型
InTheHand.WindowsMobile.Pocke

为什么呢?~请指教!
2006-06-29 12:26:00 | [匿名:巢皮]
#re: 在Smartphone/Pocket PC 2003上设置提醒 编辑
啊~~解决了,原来用
using (OutlookApplication oApp = new OutlookApplication())

这种结构就可以了
请问这种结构和直接用OutlookApplication oApp = new OutlookApplication()有什么不同呢
2006-06-29 09:42:00 | [匿名::)]
#re: 在Smartphone/Pocket PC 2003上设置提醒 编辑
站长你好!
本人初学VS2005内的VC#和SP2003的开发,看了你那篇“在Smartphone/Pocket PC 2003上设置提醒”,就试着去做了,找来了InTheHand的DLL:InTheHand.Interop.dll和InTheHand.PocketOutlook.dll,成功在VC#引用中添加了,也在使用到的C#源文件中加入了
using InTheHand.WindowsMobile.PocketOutlook;
写好代码,程序也正常编译,但是一到SP2003 SE仿真机上运行就提示:

TypeLoadException
无法从程序集
InTheHand.WindowsMobile.Pocke
Version=1.7.50922.0,
Culture=neutral,
PublickKeyToken=EA38CAA273134
加载类型
InTheHand.WindowsMobile.Pocke

但我检查过用到的两个DLL都已经自动复制到仿真机上的和程序同一个位置的目录上了。请问这是什么原因呢?请求大侠的帮忙?
2006-06-29 09:22:00 | [匿名:巢皮]
#re: 在Smartphone/Pocket PC 2003上设置提醒 编辑
OpennetCF1.4中在 opennetcf.windowsce.forms.dll里有Notification
2006-06-13 17:18:00 | [匿名:Jason]
#re: 在Smartphone/Pocket PC 2003上设置提醒 编辑
我是一个新手,现在在CAB包中有一个文件,其中那些数据需要搞清楚,可看了半天就是弄不懂,希望高手指点。
cLaunch
1204
1855
180
2
0
6
1
1
53
1
1
1
1


0
1
1
0
0
1855
8
19
常用程序
1
1
1
1
1
1
1
16
1
73
1
20

0




\Windows\“开始”菜单\程序
15
联系人
\Windows\“开始”菜单\联系人.lnk


0
便笺
\Windows\“开始”菜单\程序\便笺.lnk


0
SIM卡管理
\Windows\“开始”菜单\程序\SIM卡管理器.lnk


0
资源管理器
\Windows\“开始”菜单\资源管理器.lnk


0
日程表
\Windows\“开始”菜单\日历.lnk


0
图片
\Windows\“开始”菜单\程序\图片.lnk


0
任务
\Windows\“开始”菜单\程序\任务.lnk


0
照相机
\Windows\“开始”菜单\程序\相机.lnk


0
计算器
\Windows\“开始”菜单\程序\计算器.lnk


0
查看内存
\windows\ctlpnl.exe
cplmain.cpl,4

0
关闭程序
\Windows\ctlpnl.exe
cplmain.cpl,4,2

0
STK服务
\Windows\“开始”菜单\程序\STK服务.lnk


0
备份
\Windows\“开始”菜单\程序\备份.lnk


0
相册
\Windows\“开始”菜单\程序\相册.lnk


0
SIM卡短信
\Windows\“开始”菜单\程序\SIM卡短信.lnk


0
江西PDA
1
1
1
1
1
1
1
16
1
73
1
20

0




\Windows\Start Menu
12
报汛站雨情
\Storage\PDA\Smart_YQ.exe


0
水情查询
\Storage\PDA\Smart_SQ.exe


0
台风路径
\Storage\PDA\Smart_TF.exe


0
卫星云图
\Storage\PDA\Smart_YT.exe


0
天气预报
\Storage\PDA\Smart_TQ.exe


0
警报接收
\Storage\PDA\Smart_JB.exe


0
防汛法规
\Storage\PDA\Smart_FG.exe


0
防汛通讯录
\Storage\PDA\Smart_TXL.exe


0
防汛专简报
\Storage\PDA\Smart_ZJB.exe


0
水工程资料
\Storage\PDA\Smart_SG.exe


0
相关资料
\Storage\PDA\Smart_ZL.exe


0
使用帮助
\Storage\PDA\Smart_BZ.exe


0

0
1
1
1
1
1
1
16
1
70
1
14

0





0
商务娱乐
1
1
1
1
1
1
1
16
1
73
1
20

0




\Windows\“开始”菜单
12
Pocket Word
\Windows\“开始”菜单\程序\Pocket Word.lnk


0
Pocket Excel
\Windows\“开始”菜单\程序\Pocket Excel.lnk


0
Windows Media
\Windows\“开始”菜单\程序\Windows Media.lnk


0
Jawbreaker
\Windows\“开始”菜单\程序\游戏\Jawbreaker.lnk


0
纸牌
\Windows\“开始”菜单\程序\游戏\纸牌.lnk


0
凌云壮志
\Windows\“开始”菜单\程序\游戏\凌云壮志.lnk


0
MSN
\Windows\“开始”菜单\程序\MSN Messenger.lnk


0
电话
\Windows\“开始”菜单\电话.lnk


0
百宝箱
\Windows\“开始”菜单\程序\百宝箱.lnk


0
短信备份
\Windows\“开始”菜单\程序\短信备份.lnk


0
金山词霸
\Windows\“开始”菜单\程序\金山词霸.lnk


0
移动证券
\Windows\“开始”菜单\程序\移动证券.lnk


0
Utils
0
1
1
1
1
1
1
16
0
70
0
14

0




\Windows\Start Menu
0
Music
0
1
1
1
1
1
1
16
0
70
0
14

0




\Windows\Start Menu
0
eBooks
0
1
1
1
1
1
1
16
0
70
0
14

0




\Windows\Start Menu
0
Misc
0
1
1
1
1
1
1
16
0
70
0
14

0




\Windows\Start Menu
0
2006-05-17 10:43:00 | [匿名:新手]
#re: 在Smartphone/Pocket PC 2003上设置提醒 编辑
OpenNETCF.Desktop.Communication如何安装?
我运行那个RAPICSharp.exe,显示说mscorees.dll无法被执行,请重新安装.Net Framework。可我用别的.Net的程序很正常啊
2006-03-01 18:39:00 | [匿名:Kevin]
#re: 在Smartphone/Pocket PC 2003上设置提醒 编辑
我是想在接收到短信息时给出提示,系统中截获了发生的消息,所以我提示总是不能出来,直到停止接收才可以,请问有什么好办法吗?
2006-01-10 17:40:00 | [匿名:jennifer]
#re: 在Smartphone/Pocket PC 2003上设置提醒 编辑
OpenNETCF.Notification命名空间下。下述代码演示了这种用法(需要增加对OpenNETCF.Notification.dll的引用)
--------------------------------------------------------------
我装了opennetcf,但是没有找到这个OpenNETCF.Notification.dll,难道是版本不一样嘛?
我的opennetcf中包括的dll有:opennetcf.dll, opennetcf.Data.dll, opennetcf.Drawing.dll,
opennetcf.net.dll, opennetcf.phone.dll, opennetcf.visualBisic.dll, opennetcf.web.service2.dll, opennetcf.windowsce.forms.dll. opennetcf.xml.dll.
还有其他的吗?
我的opennetcf frameword 是1.4版本。
2005-12-28 16:20:00 | [匿名:kaola]
#re: 在Smartphone/Pocket PC 2003上设置提醒 编辑
请问evc4.0可以做到上面的哪一种提醒方法?
2005-09-06 09:43:00 | [匿名:ashadeng]
#re: 在Smartphone/Pocket PC 2003上设置提醒 编辑
说是CF2中包含了POOM可是我在beta2中没找到
不是daxia找到没有
2005-05-02 22:22:00 | [匿名:3188]
#在Smartphone/Pocket PC 2003上设置提醒 编辑
Ping Back来自:blog.csdn.net
2005-03-05 12:19:00 | [匿名:mobilechannel]
#re: 在Smartphone/Pocket PC 2003上设置提醒 编辑
Vibrate 属性好象对mobile无效
2004-09-28 13:48:00 | [匿名:hchlee]
#re: 在Smartphone/Pocket PC 2003上设置提醒 编辑
@tinyfool:

谢谢鼓励,呵呵:) 最近因为在创业,实在是太忙,一直没完整的时间去写东西,不过我还是每天都“严重”关注博客堂的:B

NotificationAction这个枚举对象中有Vibrate,可以让你的PPC振动起来,这样就不会叫不醒了吧,呵呵:)
2004-09-27 18:09:00 | [匿名:musicland]
#re: 在Smartphone/Pocket PC 2003上设置提醒 编辑
总算又看到你更新blog了,呵呵。

郁闷在于我的ppc从来叫不醒我,所以每天的唤醒服务还是由我的7650承担。
2004-09-27 17:54:00 | [匿名:tinyfool]
#re: 在Smartphone/Pocket PC 2003上设置提醒 编辑
不错,晚上回去试试~~
2004-09-27 14:46:00 | [匿名:qiuji]
#re: 在Smartphone/Pocket PC 2003上设置提醒 编辑
我也是认为第一种比较不错~~,我在家里各个都试了一下;)
2004-09-27 10:31:00 | [匿名:cmsoft]
#re: 在Smartphone/Pocket PC 2003上设置提醒 编辑
Pocket Outlook的功能的确很强大,而且默认也提供了通过ActiveSync与PC同步的接口,可以很方便地与PC进行数据同步。不过如果只需用到简单的提醒功能的话,第一种是不错的选择。
2004-09-27 10:27:00 | [匿名:musicland]
#re: 在Smartphone/Pocket PC 2003上设置提醒 编辑
还是第三种方法好,便于与PC同步。
2004-09-27 09:04:00 | [匿名:Ninputer]
#JoyCode 编辑
JoyCode
2004-09-27 00:11:00 | [匿名:]
对不起,目前本随笔不允许发表新评论.

Powered by: Joycode.MVC引擎 0.5.2.0