Windows Mobile 6.5中Widgets開發(fā)初體驗
Widgets開發(fā)環(huán)境
好了,我們先要看一下,如何為Windows Mobile 6.5開發(fā)一個Widgets控件。首先,我們需要下載Windows Mobile 6.5的DTK,下載鏈接為:
Windows Mobile 6.5的DTK需要與Windows Mobile 6 SDK配合使用,Windows Mobile 6 SDK的下載地址:
由于很多Widgets都需要聯(lián)網(wǎng),所以測試環(huán)境也需要ActiveSync的支持。Vista應(yīng)該使用Windows Mobile Device Center 6.1,下載地址:
http://www.microsoft.com/windowsmobile/en-us/help/synchronize/device-center-download.mspx
編寫Widgets
接下來,我們就可以來進(jìn)行一個Widgets開發(fā)了。首先創(chuàng)建一個WidgetDemo的文件夾,創(chuàng)建一個叫做widget.htm的文件,將下面的HTML代碼拷貝到文件中:
- <html>
 - <head>
 - <title>Cool Widget!</title>
 - </head>
 - <body>
 - I'm a cool windows mobile 6.5 widget
 - <!-- Search Google -->
 - <form method="get" action="http://www.google.cn/custom" target="google_window">
 - <table bgcolor="#ffffff">
 - <tr><td nowrap="nowrap" valign="top" align="left" height="32">
 - <a href="http://www.google.com/">
 - <img src="http://www.google.com/logos/Logo_25wht.gif" border="0" alt="Google" align="middle"></img></a>
 - <label for="sbi" style="display: none">????????</label></tr>
 - <tr>
 - <input type="text" name="q" size="31" maxlength="150" value="" id="sbi"></input>
 - <label for="sbb" style="display: none">??????</label>
 - <input type="submit" name="sa" value="??" id="sbb"></input>
 - <input type="hidden" name="client" value="pub-9289651901062754"></input>
 - <input type="hidden" name="forid" value="1"></input>
 - <input type="hidden" name="ie" value="UTF-8"></input>
 - <input type="hidden" name="oe" value="UTF-8"></input>
 - <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>
 - <input type="hidden" name="hl" value="zh_CN"></input>
 - </td></tr></table>
 - </form>
 - <!-- Search Google -->
 - </body>
 - </html>
 
這個Widget就是調(diào)用Google的搜索頁面。原來的Widget Demo沒有Google搜索的代碼,我從網(wǎng)上找了一個示例加了進(jìn)去。接下來,創(chuàng)建一個叫做config.xml的文件,將下列代碼拷貝到文件中
這是一個描述性的XML文件,結(jié)構(gòu)非常清晰,不需要多做解釋了。注意content,icon和access network三個節(jié)點。Content的src就是我們剛編寫的widget.htm, 允許Widget訪問網(wǎng)絡(luò),icon則是顯示在Windows Mobile開始菜單里的圖標(biāo)。

現(xiàn)在有了三個文件,我們使用WinZip將其壓縮成一個ZIP文件。特別需要指出的是,我們不能壓縮這三個文件所在的文件夾,必須選中所有文件之后進(jìn)行壓縮。然后我們將WidgetDemo.zip的擴(kuò)展名改為WidgetDemo.wgt。
部署Widget
到這里,Widget開發(fā)就完成了。通過ActiveSync或者共享目錄,將Widget拷貝到Windows Mobile 6.5的模擬器中。
 
我們使用File Explorer來找到這個Widget文件,點擊之后,會提示是否安裝并運行這個Widget。
安裝Widget之后,會自動運行,Google的圖標(biāo)來源于網(wǎng)絡(luò),所以可能會顯示慢一些。如果Google圖標(biāo)沒有顯示出來,則說明網(wǎng)絡(luò)連接不通:


輸入關(guān)鍵字,點擊button,Widget會自動啟動IE Mobile,顯示搜索結(jié)果。
在使用時,我們可以在開始菜單里找到相應(yīng)的圖標(biāo),可以打開Widget。還需要說明的是,如何卸載這個Widget。
在開始菜單 - Setting – System - Remove Programs里,可以看到我們的Widget,與卸載普通的應(yīng)用程序沒有區(qū)別。

我們的Widget被安裝在\Program Files\Widgets\User\7的目錄里,目錄的序號與安裝順序有關(guān),比如1里就是內(nèi)置的Live Search。
寫在最后
寫到這里,Widget開發(fā)就完成了,怎么樣?簡單吧。Widget開發(fā)的簡單性,正是它未來可能締造輝煌的主要優(yōu)勢。任何熟悉HTML和JavaScript的人都可以開發(fā)出功能豐富的Widget,而Widget又可以像普通應(yīng)用程序一樣使用。
雖然不像Palm的WebOS那樣具有顛覆性,但是依托于目前的技術(shù),才能獲得大多數(shù)開發(fā)者的支持?,F(xiàn)在只有Windows Mobile 6.5支持Widget,但其他移動設(shè)備是否有可能支持Widget呢?一切皆有可能。
總之,一句話,大有可為!
【編輯推薦】
- Windows Mobile 6.5將在5月推出
 - 微軟稱已完成Windows Mobile6.5開發(fā)
 - 微軟開始組織開發(fā)大型Windows Mobile應(yīng)用程序
 - 微軟將推出Windows Mobile應(yīng)用軟件商店
 - Windows Mobile上實現(xiàn)自動拼寫和匹配
 
- <?xml version="1.0" encoding="utf-8" ?>
 - <widget version="1.0"
 - xmlns="http://www.w3.org/ns/widgets"
 - id="">
 - <name>My first widget</name>
 - <content src="widget.htm" type="text/html" />
 - <access network="true" />
 - <icon src="icon.png"/>
 - <description>This is my first widget,
 - it won't make a lot of money on the
 - marketplace but at least is cute!</description>
 - </widget>
 















 
 
 
 
 
 
 