Windows Mobile 6.5中Widgets开发初体验

移动开发
Windows Mobile 6.5的DTK终于发布了,其中最吸引人的是两个功能:Widgets和Gesture API。Widgets是近来非常流行的一项技术,用于显示一些常用信息,比如天气、股票、新闻和体育等。Google Android和Symbian上已经有了类似的技术,可以说,Widgets是很好地结合了移动设备与互联网的技术。虽然Widgets开发简单,但很有可能改变移动互联网的未来格局。

Widgets开发环境

好了,我们先要看一下,如何为Windows Mobile 6.5开发一个Widgets控件。首先,我们需要下载Windows Mobile 6.5的DTK,下载链接为:

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=20686a1d-97a8-4f80-bc6a-ae010e085a6e

Windows Mobile 6.5的DTK需要与Windows Mobile 6 SDK配合使用,Windows Mobile 6 SDK的下载地址:

http://www.microsoft.com/downloads/details.aspx?familyid=06111a3a-a651-4745-88ef-3d48091a390b&displaylang=en

由于很多Widgets都需要联网,所以测试环境也需要ActiveSync的支持。Vista应该使用Windows Mobile Device Center 6.1,下载地址:

http://www.microsoft.com/windowsmobile/en-us/help/synchronize/device-center-download.mspx

编写Widgets

接下来,我们就可以来进行一个Widgets开发了。首先创建一个WidgetDemo的文件夹,创建一个叫做widget.htm的文件,将下面的HTML代码拷贝到文件中:

  1. <html> 
  2. <head>   
  3. <title>Cool Widget!</title>   
  4. </head>   
  5. <body>   
  6. I'm a cool windows mobile 6.5 widget   
  7. <!-- Search Google --> 
  8. <form method="get" action="http://www.google.cn/custom" target="google_window"> 
  9. <table bgcolor="#ffffff"> 
  10. <tr><td nowrap="nowrap" valign="top" align="left" height="32"> 
  11. <a href="http://www.google.com/"> 
  12. <img src="http://www.google.com/logos/Logo_25wht.gif" border="0" alt="Google" align="middle"></img></a> 
  13. <label for="sbi" style="display: none">????????</label></tr> 
  14. <tr> 
  15. <input type="text" name="q" size="31" maxlength="150" value="" id="sbi"></input> 
  16. <label for="sbb" style="display: none">??????</label> 
  17. <input type="submit" name="sa" value="??" id="sbb"></input> 
  18. <input type="hidden" name="client" value="pub-9289651901062754"></input> 
  19. <input type="hidden" name="forid" value="1"></input> 
  20. <input type="hidden" name="ie" value="UTF-8"></input> 
  21. <input type="hidden" name="oe" value="UTF-8"></input> 
  22. <input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:1"></input> 
  23. <input type="hidden" name="hl" value="zh_CN"></input> 
  24. </td></tr></table> 
  25. </form> 
  26. <!-- Search Google --> 
  27. </body>   
  28. </html> 

这个Widget就是调用Google的搜索页面。原来的Widget Demo没有Google搜索的代码,我从网上找了一个示例加了进去。接下来,创建一个叫做config.xml的文件,将下列代码拷贝到文件中

 

这是一个描述性的XML文件,结构非常清晰,不需要多做解释了。注意content,icon和access network三个节点。Content的src就是我们刚编写的widget.htm, 允许Widget访问网络,icon则是显示在Windows Mobile开始菜单里的图标。

项目结构

现在有了三个文件,我们使用WinZip将其压缩成一个ZIP文件。特别需要指出的是,我们不能压缩这三个文件所在的文件夹,必须选中所有文件之后进行压缩。然后我们将WidgetDemo.zip的扩展名改为WidgetDemo.wgt。

部署Widget

到这里,Widget开发就完成了。通过ActiveSync或者共享目录,将Widget拷贝到Windows Mobile 6.5的模拟器中。

Widgets页面1 Widgets页面2

我们使用File Explorer来找到这个Widget文件,点击之后,会提示是否安装并运行这个Widget。

安装Widget之后,会自动运行,Google的图标来源于网络,所以可能会显示慢一些。如果Google图标没有显示出来,则说明网络连接不通:

手机草图Widgets页面

输入关键字,点击button,Widget会自动启动IE Mobile,显示搜索结果。

在使用时,我们可以在开始菜单里找到相应的图标,可以打开Widget。还需要说明的是,如何卸载这个Widget。

在开始菜单 - Setting – System - Remove Programs里,可以看到我们的Widget,与卸载普通的应用程序没有区别。

第一个Widgets项目

 

我们的Widget被安装在\Program Files\Widgets\User\7的目录里,目录的序号与安装顺序有关,比如1里就是内置的Live Search。

写在最后

写到这里,Widget开发就完成了,怎么样?简单吧。Widget开发的简单性,正是它未来可能缔造辉煌的主要优势。任何熟悉HTML和JavaScript的人都可以开发出功能丰富的Widget,而Widget又可以像普通应用程序一样使用。

虽然不像Palm的WebOS那样具有颠覆性,但是依托于目前的技术,才能获得大多数开发者的支持。现在只有Windows Mobile 6.5支持Widget,但其他移动设备是否有可能支持Widget呢?一切皆有可能。

总之,一句话,大有可为!

【编辑推荐】

  1. Windows Mobile 6.5将在5月推出
  2. 微软称已完成Windows Mobile6.5开发
  3. 微软开始组织开发大型Windows Mobile应用程序
  4. 微软将推出Windows Mobile应用软件商店
  5. Windows Mobile上实现自动拼写和匹配

  1. <?xml version="1.0" encoding="utf-8" ?>   
  2. <widget version="1.0"   
  3. xmlns="http://www.w3.org/ns/widgets"   
  4. id="">   
  5. <name>My first widget</name>   
  6. <content src="widget.htm" type="text/html" />   
  7. <access network="true" />   
  8. <icon src="icon.png"/>   
  9. <description>This is my first widget,   
  10. it won't make a lot of money on the   
  11. marketplace but at least is cute!</description>   
  12. </widget> 
责任编辑:彭凡 来源: cnblogs
相关推荐

2010-05-23 10:29:29

Widget开发

2009-03-12 08:34:54

2011-09-08 10:18:09

Windows MobWidgets

2011-09-08 10:04:07

Windows MobWidget

2011-04-25 16:40:21

开发环境搭建Windows Mob

2012-05-16 10:50:17

Windows Pho

2009-05-18 09:06:37

微软WMWindows Mob

2009-08-10 09:46:06

中国移动Mobile

2009-02-22 09:04:51

WM 6.5SoftKey改进

2009-05-19 10:44:23

微软Windows mob移动OS

2011-04-25 17:17:55

Gesture APIWindows Mob

2009-06-04 14:18:44

Windows Mob工具包

2011-09-15 15:03:10

2009-06-01 08:48:44

微软Windows Mob移动OS

2009-04-28 09:47:44

WM6.5Windows Mob智能手机

2010-03-26 09:13:00

Windows Mob系统更新

2009-02-17 10:41:38

Windows Mob操作高清照片

2010-02-02 17:04:38

Windows MobWindows Mob下载

2013-07-19 15:05:04

2012-08-01 14:12:43

Windows Ser
点赞
收藏

51CTO技术栈公众号