您的位置:首页 > 其它

Customizing the Windows CE .NET User Interface, Part 2

2005-07-04 10:24 561 查看

CustomizingtheWindowsCE.NETUserInterface,Part2

MikeHall
MicrosoftCorporation

SteveMaillet
EntelechyConsulting

May1,2002

下载Ieshell.exe.

下载theIESHELL.exesamplefile.(217KB)

LastmonthwetookalookatcustomizingcertainuserinterfacefeaturesoftheMicrosoft®Windows®CE.NEToperatingsystem.ThismonthweextendthistocoverbuildingacustomshellusingtheMicrosoft®WindowsCEInternetExplorer.Ofcourse,thesameprocesscouldbeusedtocreateacustomshellusingastand-aloneapplication.

定制shells

TheExplorershellprovidedwithPlatformBuilderisagoodgeneral-purposeshellthatallowsusersagreatdealofflexibility,whilemaintainingagenerallyfamiliarlookandfeel.Manyembeddeddevicesrequireamoretightlycontrolleduserexperience;forexample,HMIindustrialcontrollers,self-serviceKiosks,orpossiblyeventhecontrolsystemofthetrainI'mridinginasIwritethis.Thesetypesofsystemsrequireacustomshellthatlimitsthedevicetoaparticularfunctionorsetoffunctionsitwasdesignedfor.Fortunately,WindowsCEwasdesignedwiththisinmind,andallowsyoutouseanyapplicationyouwantastheshell.

Let'slookatsomeofthefunctionalityacustomshellmightneed:

1.在系统启动时运行.

2.向用户提供一个界面(接口).

·接受用户收入(,并响应).

·向用户显示响应.

·显示某些操作的当前状态.

3.Changemodes/Tasks.

在系统启动时运行shell

在系统启动时运行shell是非常简单的,只需要一个注册表项.Thefollowingextractfromtheregistryshowshowthestandardshell(explorer.exeisloaded):

[HKEY_LOCAL_MACHINE\init]
"Launch50"="explorer.exe"
"Depend50"=hex:14,00,1e,00

内核初始化之后,将扫描Initkey寻找"LaunchXX"形式的key,然后以数字顺序装载列在里面的应用程序.DependXXvaluesspecifytheXXvalueofanapplicationloadedbythekernelasbinaryvaluesintheregistry.(The"hex:"syntaxisusedinREGfilesforvaluesoftypeREG_BINARY.)ThedataforthisregistryvalueisasetofDWORDvaluescorrespondingtotheLaunchvaluesofotherapplicationstheprogramdependson.

NoteThedataisdefinedasasequenceofbytes,soyoumusttakeintoaccountthattheoperatingsystemexpectsthedatainlittle-endian顺序.

Sotheexampletranslatesto:

运行explorer.exeafterwhateverapplicationislistedas"Launch20"andtheapplicationlistedas"Launch30."(ThesehappentobeDevice.exeandGwes.exe.)

这里有一个catch机制.Thedependencyisdesignedforoperatingsystemdependentservices.ThedevicemanagerandGWESmustactuallyhaveinitializedtoapointwheretheycanbeusedbeforetheshellcanstartusingthem.Therefore,theoperatingsystemcan'tjustlaunchtheapplicationsrandomly.(Well,actuallyitcould,butthatwouldleaveeachapplicationtocreateitsownmechanismforindicatingitwasreadyforuse—creatinggeneralhavocfordeveloperstheworldover.)幸运的是,theWindowsCEarchitectsconsideredthisandcreatedastandardmechanismforindicatingthatanapplicationisreadyforuse.WindowsCEusesthismechanismtodeterminewhenitshouldlaunchthedependentapplications.任何在Initkey下装载的应用程序都必须调用函数SignalStarted(),并把命令行参数转换为一个长整数传进去:

SignalStarted(_wtol(lpCmdLine));

这个调用告诉操作系统:程序已经自身初始化到了可以被其他应用程序放心调用的地方了。

使用浏览器作为shell

Onceyouhavegottenyourapplicationtoloadatboottimeinplaceoftheshell,it'stimetogetbusywiththeUIcoding.Typically,aUIinembeddeddevicesdoesn'tresemblethetraditionalWindowsapplication,withitsmainwindowandmenu,toolbars,statusbar,andsoon.Instead,anembeddeddeviceUIisusuallyquitevisual,andoftenbestcreatedbyprofessionalgraphicsdesigners.(Mostengineersdon'tevencomeclosetothat!)Soit'softendesirablefortheprogrammerandgraphicsdesignertoworktogether.SuchameetingofmindsisprovingverysuccessfulinWebdevelopmentanddesign.Fairlyrich,visuallypleasinginterfacesaregeneratedalmostdailyonthegreatWWW.WhynotusethatmodelinyourembeddedsystemUIdesign?WindowsCE.NETincludesabrowsercomponentthatlet'syoudojustthat.

WindowsCE.NET下的浏览器组件是Microsoft®InternetExplorer5.5浏览器控件桌面版的一个子集.这个组件是一个MicrosoftActiveX®控件,可以支持所有browsingandrenderingfunctionalityinonereusablepackage.有一个叫做IESAMPLE的样例程序(一会我们将使用它。)

TheIESAMPLEapplication,whichhoststheInternetExplorerbrowsercontrol,providesafamiliarInternetExplorerbrowserinterfacecompletewithmenus,toolbars,andstatusbar.However,aspreviouslymentioned,thisisn'tdesirableinmostembeddedsystems.Whatweneedtohaveisanapplicationthatcanusethebrowserina"FullScreen"mode.WellitjustsohappensthatthegoodfolksatMicrosoftthoughtofthat,too.(Although,theyfailedtomentionitinthedocumentation!)TheIESAMPLEapplicationincludesanumberof#ifteststoenableordisablethemenus,statusbar,andfavorites.SoyouonlyneedtomakeafewminormodificationstothebuildofIESAMPLEtogetwhatyouneedforabrowser-basedshell.

SettingUptheProject

//其实在下载下来的程序里,下面改动和设置大部分已经做好了.需要做的我在后面标识

首先,使用文章顶部的连接下载这个工程的源码IESHELL.exe.

TheIESAMPLEapplicationislocatedin_WINCEROOT\public\InternetExplorer\oak\IESAMPLE.Aswe'vediscussedinpreviousarticles,it'sgenerallynotagoodideatomodifytheMicrosoftprovidedcodeofftheCOMMONdirectoryoranyofthestandardconfigurations.SoyoucancopytheIESAMPLEfilestoafolderunderyourplatform'sworkspacefolder(thatis,_WINCEROOT\MyDevice\IESHELL).IESAMPLEissetuptobuildusingaSOURCESfile.YoucancreateanewblankPlatformBuilderprojectandaddthefilesintheIESHELLfolderyoucopiedeverythinginto.Theeasiestwaytodothisistoright-clickontheprojectinthefileviewandclickAddfilestoproject.(Addeverythingexceptthe'SOURCES'and'MAKEFILE'andoptions.cpp.Besuretousethe*.*filteringwhenaddingfilestotheprojecttogetthevariousresourcefilesaswell.)

BecausetheprojectwasoriginallycreatedusingaSOURCESfile,therearesomeextrasettingsyouwillneedtomaketotheprojectbeforeitwillbuildcorrectly.

First,youwillneedtoaddthepathtotheATLheadersontheC/C++tabunderthePreprocessorcategory.(BesuretoclickAllConfigurationssothatthesettingsapplytoeachoftheprojectconfigurations.)




Figure1.加上ATL库


FromthesametabintheProjectSsettingsdialog,clickthePrecompiledHeaderscategoryandclicktheIESHELLprojectintheleftsidetreeview.Thiswillchangethesettingsforallfilesintheproject.TheprecompiledheaderisPRECOMP.H,soallfilesshouldbesettouseit.




Figure2.设置预编译头


Next,clickthestdafx.cppfileinthetreeviewtoalteritssettingstogeneratethepre-compiledheaderinformationthroughprecomp.h.




Figure3.Settingtheprecompiledheaderforstdafx.cpp


Next,clicktheIESHELLprojectinthetreeandthenclicktheLinktab.Youwillneedtoaddthefollowinglibrariestotheinputlibraries(notethattheyareseparatedbyaspace):

ole32.liboleaut32.libcommctrl.libuuid.libwininet.libwinsock.lib





Figure4.加上所需的附加库


Then,ontheLinktab,clicktheOutputcategory,andsettheentrypointtoWinMain,theStacksizeto0x20000,andthecommitsizeto0x1000.




Figure5.设置保留和提交大小


TheSOURCESfileusestheRCADDNULLoption,whichaddsa'\0'totheendofallresourcestrings,sotheycanbeuseddirectlywithLoadString().Unfortunately,therearen'tanysettingsoptionsforthatdirectlyintheIDE,soyouwillneedtoadjusttheresourcecompilersettingstousethe/nparametermanuallyintheProjectOptions.ClicktheResourcestab,andclicktheIESHELLprojectinthetree,sothatthesettingsaremadeprojectwideforallRCfiles.TheProjectOptionsfieldisonlyeditablewhenyouhaveasingleconfigurationselected,soyouwillneedtomakethisadjustmentforeachconfiguration.




Figure6.调整资源编译器设置


在PRECOMP.H文件中加入下列语句:

#defineNO_FAVORITES
#defineNOCOMMANDBAR
#defineNOSTATUSBAR
#defineNOOFFLINE
#defineNOFIND
#defineNOOPTIONS
#include"defines.h"

defines.hisneededtomakesuresomedefinitionsareavailableeveniftheotherheadersandfeaturesaredisabledbytheNOxxxxdefines.TheNOxxxxdefinescouldbesetintheprojectsettingsdialogasanotheroption.Youmustalsocommentoutorremovethe#include<pkfuncs.h>(Line44),asitisnotactuallyneeded.

You'llneedtomakesomechangesinMainWnd.cppaswell:

1.ReplacealloccurrencesofIESAMPLEwithIESHELL.

2.Replacethelines190-193withthefollowingcodetohandletheSignalStarted()call:

3.//allowlaunchingwithcommandlinearg
4.//fordevelopmentpurposes.Whenloaded
5.//fromtheinitkeyinitSignalwillbenonzero
6.intinitSignal=_wtol(lpCmdLine);
7.if(initSignal!=0)
8.{
9.SignalStarted(initSignal);
10.if(HandleNewWindow2(_T(""),NULL))
11.{
12.gotoCleanup;
13.}
14.}
15.else
16.if(HandleNewWindow2(lpCmdLine,NULL))
17.{
18.gotoCleanup;
19.}

20.AtthetopofCMainWnd::~CMainWnd(),placean#ifdefblockaroundthecommandbarsupport.

21.#ifndefNOCOMMANDBAR
22.if(_himlCmdBand)
23.ImageList_Destroy(_himlCmdBand);
24.#endif

25.InCMainWnd::MainWndProc(),movethe#endif//NOCOMMANDBARdowntoencloseboththeWM_COMMANDandtheWM_NOTIFYmessage.

26.在CMainWnd::Close()函数的底部,enclosethecommandbarcodeinan#ifdefNOCOMMANDBARblockasfollows:

27.#ifndefNOCOMMANDBAR
28.if(_himlCmdBand)
29.{
30.ImageList_Destroy(_himlCmdBand);
31._himlCmdBand=NULL;
32.}
33.#endif//NOCOMMANDBAR

Next,youwillneedtoaddsomebuildactionstogetthingsgoing.YoucanuseanyHTMLandimagefilesyouneedforyourownUI.We'veprovidedasimplesampleofwhataWebPhonedevicemightlooklike.Atthispointitwouldbeappropriatetoremindyouthatit'sraretofindasoftwareengineerwhoisalsoagoodgraphicsdesigner.(Thissampleisnoexception!)Themajoradvantageofusingthebrowserastheshellofadedicateddeviceistheseparationofpresentationfromfunctionality.TheDHTMLcancontainActiveXobjectsthatimplementthecorefunctionalityofthedeviceandaremanipulatedbyMicrosoftJScript®codetoconnecttheUItotheprimarydevicefunctionality.

Tosettheactionsforthesample,fromtheFeatureView,youwillneedtoright-clicktheIESHELL.PBPandselectsettingsfromthepopupmenu.ClickAllConfigurationsandPre-MakeImagefortheBuildStep.点击NewtocreateanewactiontocopyC:\WINCE400\PUBLIC\MyPad\IESHELL\Files\IESHELL.regtothe$(_FLATRELEASEDIR).

IntheMakeImagestep,addanenvironmentvariableIMGIESHELLandsetitto1.

Theregistryfilewillbecopiedtothereleasedirectoryandprocessedbythemakeimgtool.IESHELL.REGissetuptotestfortheEnvironmentvariableIMGIESHELL,conditionallyincludethesettingstolaunchIESHELL.EXEastheshell,andtospecifythedefaulthomepage.





Figure7.复制IESHELL注册表文件到_FLATRELEASEDIR目录


ClicktheBIBInfotab.Addanyfile;youcanthenedittheentryinthedialogto$(_FLATRELEASEDIR)\IESHELL.EXE,butbesureit'sintheModulessectionandisnotcompressed.ThenaddeachofthefileslistedbelowasuncompressedintheFilessection.Thesearetheimagesandhomepage(shell.htm)fortheHTML-basedshell:

//需要手工加一下

BKG.jpg
Button0.jpg
Button1.jpg
Button2.jpg
Button3.jpg
Button4.jpg
Button5.jpg
Button6.jpg
Button7.jpg
Button8.jpg
Button9.jpg
ButtonPOUND.jpg
ButtonSTAR.jpg
default.htm
dir.txt
homelogo.gif
IESHELL.BIB
IESHELL.reg
Shell.htm




Figure8.加文件到BIBInfo

Makingthestartpageandtheelementsitloadsuncompressedhelpsthepagetoloadfaster.

Onceyouhaveallofthechangesandsettingstakencareof,youcanbuildtheprojectandseetheresult.Itshouldlooklikethefollowing:




Figure9.最后的结果:一个IEshellforWindowsCE


Itdoesn'treallydoanythingparticularlyuseful,butitdoesshowhowtosetupaUIbasedonthebrowser.Youcanfurtherenhancethefunctionalitytosupportasetofnavigationbuttonsforthemini-browserwindow,andevenincludeanaddressbar.Ifyouarereallyambitious,youcanenhanceittoutilizethesupportavailableinWindowsCE.NETforVoiceoverIPandReal-TimeCommunications.

//OK,这里是用IE来做为SHELL的.那其实用自己的程序来shell的话当然原理一样.

新建一个application项目:



在Main函数里加上必须有的一句:

SignalStarted(_wtol(lpCmdLine));




修改注册表的Init项,把IESHELL.EXE换成Test.EXE



然后就大功告成了!

GetEmbedded

MikeHallisaProductManagerintheMicrosoftEmbeddedandAppliancePlatformGroup(EAPG).MikehasbeenworkingwithWindowsCEsince1996—indevelopersupport,EmbeddedSystemEngineering,andtheEmbeddedproductgroup.Whennotattheoffice,Mikecanbefoundwithhisfamily,workingonSkunkprojects,orridingaHondaST1100.

SteveMailletistheFounderandSeniorConsultantforEntelechyConsulting.StevehasprovidedtrainingandhasdevelopedWindowsCEsolutionsforclientssince1997,whenCEwasfirstintroduced.SteveisafrequentcontributortotheMicrosoftWindowsCEdevelopmentnewsgroups.Whenhe'snotathiscomputerburningupthekeys,Stevecanbefoundjumpingoutofairplanesatthenearestdropzone.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: