Windows Mobile 6.5中Widgets開發初體驗
Widgets開發環境
好了,我們先要看一下,如何為Windows Mobile 6.5開發一個Widgets控件。首先,我們需要下載Windows Mobile 6.5的DTK,下載鏈接為:
Windows Mobile 6.5的DTK需要與Windows Mobile 6 SDK配合使用,Windows Mobile 6 SDK的下載地址:
由于很多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代碼拷貝到文件中:
- <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就是調用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的模擬器中。
我們使用File Explorer來找到這個Widget文件,點擊之后,會提示是否安裝并運行這個Widget。
安裝Widget之后,會自動運行,Google的圖標來源于網絡,所以可能會顯示慢一些。如果Google圖標沒有顯示出來,則說明網絡連接不通:
輸入關鍵字,點擊button,Widget會自動啟動IE Mobile,顯示搜索結果。
在使用時,我們可以在開始菜單里找到相應的圖標,可以打開Widget。還需要說明的是,如何卸載這個Widget。
在開始菜單 - Setting – System - Remove Programs里,可以看到我們的Widget,與卸載普通的應用程序沒有區別。
我們的Widget被安裝在\Program Files\Widgets\User\7的目錄里,目錄的序號與安裝順序有關,比如1里就是內置的Live Search。
寫在最后
寫到這里,Widget開發就完成了,怎么樣?簡單吧。Widget開發的簡單性,正是它未來可能締造輝煌的主要優勢。任何熟悉HTML和JavaScript的人都可以開發出功能豐富的Widget,而Widget又可以像普通應用程序一樣使用。
雖然不像Palm的WebOS那樣具有顛覆性,但是依托于目前的技術,才能獲得大多數開發者的支持。現在只有Windows Mobile 6.5支持Widget,但其他移動設備是否有可能支持Widget呢?一切皆有可能。
總之,一句話,大有可為!
【編輯推薦】
- Windows Mobile 6.5將在5月推出
- 微軟稱已完成Windows Mobile6.5開發
- 微軟開始組織開發大型Windows Mobile應用程序
- 微軟將推出Windows Mobile應用軟件商店
- Windows Mobile上實現自動拼寫和匹配
- <?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>