Tải bản đầy đủ (.pdf) (715 trang)

Sams creating vista gadgets using HTML CSS and javascript with examples in RSS AJAX activex COM and silverlight may 2008 ISBN 0672329689

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (8.11 MB, 715 trang )

CreatingVista®Gadgets:UsingHTML,CSSand
JavaScriptwithExamplesinRSS,Ajax,ActiveX
(COM)andSilverlight™
byRajeshLal
Publisher:Sams
PubDate:May05,2008
PrintISBN-10:0-672-32968-9
PrintISBN-13:978-0-672-32968-5
Pages:360
TableofContents|Index

Overview
Aone-stopresourceforeachaspectofdesigningand
developingSidebargadgets,perfectforanyonewhowantsto
createkillergadgets
ExploresoneofthesupercoolfeaturesnewtoWindows
Vista--theSidebar
Itisaone-stopresourceforeachaspectofdesigningand
developingSidebargadgets,perfectforanyonewhowants
tocreatekillergadgets
Includescompletedesigninstructionsforfournever-beforeseengadgets
WindowsVistaSidebarisapanellocatedonthedesktopofaPC
wheregadgetscanbeplacedforeasyaccessandreference.
Thesegadgetsaresmall,single-purposeapplications,suchas
clocks,calendars,games,RSSnotifiers,searchtools,stock
tickers,etc,thatresideontheWindowsdesktopandonthe
WindowsSidebar.Thebookwillbeatutorialtodesignand
developagadget.Itwillprovideready-to-usesamplesusing
.NET,XML,CSSandAJAX.Afterreadingthebook,aweb
developer/designerwillbeconfidentenoughtostartdeveloping



gadgetsforWindowsVistaSidebar.Thebeginnerportionofthe
bookshowsanoverviewofthesubjectwiththedesignpattern,
thearchitectureandimplementationdetails.Thelatersections
willhavesolidexamplesforinstantresults.Inshort,thebook
willtellhowtodoeverythingwithSidebarGadgetsusingsolid,
uniqueexamples.Briefoutline:"BriefbackgroundonGadgets"
Definearchitecture,designconsiderationandimplementationto
giveaclearviewtothedeveloper"Stepbystep,createa
usefulGadgetsample"MyBlogs""Elaboratethearchitecture
designconstraintandimplementationdetailsforthesample"
Detailthestandardpractices"Recheckthegadgetcreatedfor
standardpractices"ImproviseandImprovewithcompareand
contrast"Addadvancedsampleswith.NET,AJAXandXHTML.


CreatingVista®Gadgets:UsingHTML,CSSand
JavaScriptwithExamplesinRSS,Ajax,ActiveX
(COM)andSilverlight™
byRajeshLal
Publisher:Sams
PubDate:May05,2008
PrintISBN-10:0-672-32968-9
PrintISBN-13:978-0-672-32968-5
Pages:360
TableofContents|Index

Copyright
AbouttheAuthor
Acknowledgement

WeWanttoHearfromYou!
ReaderServices
Introduction
What'sintheBook
SpecialFeaturesandNotations
SupportingWebsite
PartI:TheFoundation
Chapter1.InnovatewithWindowsVistaSidebarGadgets
IntroducingGadgetsandtheVistaSidebar
InnovatewithGadgets
GadgetsinDepth
MultiplePlatformsforGadgets
Chapter2.TheArchitecture
GadgetsOverview
TechnologyBehindGadgetDevelopment
GadgetObjectModel
SidebarGadgets:TheRoadAhead
Chapter3.AnApproachtoDesign


DesignConsiderations
ChallengesfortheUserInterface
VisualThemes
TransparentImagesintheGadget
AboutAccessibility
Chapter4.SellingYourGadget
GadgetRevenueModel
HowGadgetsGiveYouBusiness
SupportingYourGadget
PartII:DevelopingaGadget

Chapter5.CreatingaSimpleGadgetwithRSS/AtomFeed
FeedGadgets
BasicFrameworkoftheMyBlogGadget
HowtheMyBlogGadgetWorks
PartsoftheMyBlogGadget
Chapter6.DesignPatternsandStandardPractices
DesignPatterns
ElementsofDesignPatterns
CommonAssumptions
AddingAccessibility
Chapter7.TheMyBlogGadgetRevisited
RecappingtheMyBlogGadget
TakingtheMyBlogGadgettotheNextLevel
Docked,Undocked,andMiniMeVersion
Chapter8.DebuggingandDeployingaGadget
DebuggingaGadget
DeployingaGadget
DeploymentUsingaCabinetFile
PartIII:AdvancedSamples
Chapter9.SiteStatisticsGadgetwithAjax—AnInformation
Gadget
TheGoal


FeaturesandTechnology
DesignConsiderations
DevelopingtheGadget
Chapter10.MostRecentUsed.NETProjects—AnApplication
Gadget
Recent.NETProjectGadget

FeaturesandTechnology
DesignConsiderations
DevelopingtheGadget
Chapter11.RadioGadgetandYouTubeVideoGadget—Fun
Gadgets
MediaGadgets
TheRadioGadget
TheYouTubeVideoGadget
Chapter12.SilverlightWorldClock—UtilityGadget
TheSilverlightGadget
DesignConsiderations
DevelopingtheGadget
CreatingaSidebarGadgetUsingMicrosoftPopfly
WheretoGofromHere
PartIV:Appendixes
AppendixA.TipsandTricks
AutomaticUpdateandUserTracking
ReadingXML,XHTML,RSS/Atom,HTML,Text,andJSON
Data
GlobalizationandLocalization
GraphicDesign
SecurityandOtherResources
AppendixB.Extras
ReusableFrameworkforCreatingGadgets
SampleGadgetsBasedontheFramework
ShareYourGadgets


Index



Copyright
CreatingVista®Gadgets:UsingHTML,CSSandJavaScript
withExamplesinRSS,AJAX,ActiveX(COM)and
Silverlight™
Copyright©2008bySamsPublishing
Allrightsreserved.Nopartofthisbookshallbereproduced,
storedinaretrievalsystem,ortransmittedbyanymeans,
electronic,mechanical,photocopying,recording,orotherwise,
withoutwrittenpermissionfromthepublisher.Nopatent
liabilityisassumedwithrespecttotheuseoftheinformation
containedherein.Althougheveryprecautionhasbeentakenin
thepreparationofthisbook,thepublisherandauthorassume
noresponsibilityforerrorsoromissions.Norisanyliability
assumedfordamagesresultingfromtheuseoftheinformation
containedherein.
Thismaterialmaybedistributedonlysubjecttothetermsand
conditionssetforthintheOpenPublicationLicense,v1.0or
later(thelatestversionispresentlyavailableat
/>ISBN-13:978-0-672-32968-5
LibraryofCongressCataloging-in-PublicationData

Lal,Rajesh.
CreatingVistagadgets:usinghtml,cssandjavascriptwithexamples
inrss,ajax,activex(com)andsilverlight/RajeshLal.
p.cm.
ISBN978-0-672-32968-5(pbk.)
1.MicrosoftWindows(Computerfile)2.Operatingsystems(Computers)
3.Userinterfaces(Computersystems)I.Title.
QA76.76.O63L35462008

005.4'46--dc22
2008016280


PrintedintheUnitedStatesofAmerica
FirstPrintingApril2008
AssociatePublisher
GregWiegand
AcquisitionsEditor
LorettaYates
DevelopmentEditor
ToddBrakke
ManagingEditor
PatrickKanouse
ProjectEditor
JenniferGallant
CopyEditor
MargoCatts
Indexer
KenJohnson
Proofreader
MikeHenry
TechnicalEditor
MarcClifton
PublishingCoordinator
CindyTeeters
BookDesigner
AnneJones

Trademarks



Alltermsmentionedinthisbookthatareknowntobe
trademarksorservicemarkshavebeenappropriately
capitalized.SamsPublishingcannotattesttotheaccuracyof
thisinformation.Useofaterminthisbookshouldnotbe
regardedasaffectingthevalidityofanytrademarkorservice
mark.

WarningandDisclaimer
Everyefforthasbeenmadetomakethisbookascompleteand
asaccurateaspossible,butnowarrantyorfitnessisimplied.
Theinformationprovidedisonan"asis"basis.Theauthorand
thepublishershallhaveneitherliabilitynorresponsibilitytoany
personorentitywithrespecttoanylossordamagesarising
fromtheinformationcontainedinthisbook.

BulkSales
SamsPublishingoffersexcellentdiscountsonthisbookwhen
orderedinquantityforbulkpurchasesorspecialsales.For
moreinformation,pleasecontact
U.S.CorporateandGovernmentSales
1-800-382-3419

ForsalesoutsideoftheU.S.,pleasecontact
InternationalSales


Dedication
DedicatedtoMom&Dad

ForEverythingIAm


AbouttheAuthor
RajeshLalisanauthor,technologyevangelist,andsolutions
engineerspecializinginwebtechnologies.Hehasreceived
numerousawardsforhisarticlesonWindowsVistaandSidebar
Gadgets.HeisafrequentcontributortoWindowsVista
MagazineandCodeProjectwebsites.Withmorethanadecade
ofexperienceinITindustryinprogressiverolesfromgraphic
designer,softwaredeveloper,architect,teamlead,andproject
leadertoindependentconsultant,Rajeshenjoystakingan
objectiveandpragmaticapproachtodevelopingapplications
usingMicrosofttechnology.Hehasamaster'sdegreein
computerscienceandholdsMCSDandMCADtitles.
ToreadhisVistaGadgetblog,goto
www.innovatewithgadgets.com.


Acknowledgement
Writingisafascinatingjourney.Iwouldliketoextendmy
specialthankstoMarcCliftonToddBrakke,andMargoCatts
whowerealongwithmeonthisjourney.Theycorrected,
annotated,criticized,andhelpedmeateverystep.Thanksalso
toJoshuaHeyer(Shog9)andRamaKrishnaforreviewingthis
bookandfortheirinvaluableadvice.Ialsowanttoaddanote
ofthankstoDr.Luijiforalltheencouragementatthetimes
whenIneededit.
IamdeeplygratefultoLorettaYates,acquisitionseditorat
Sams/QuePublishingforherunmatcheddedicationtoquality

andprogressiveness,withoutwhichthisbookwasnever
possible.ThanksalsotoJenniferGallant,CindyTeeters,and
RosemaryLewisfromPearsonTechnologyGroup.
Iwouldliketoextendmyappreciationtothefolksfrom
Microsoft,fortheirtimeandefforttomakethisbookcomplete
ineverysense,especiallyBrianTeutsch,DanielMoth,and
AnnuskaPerkins.IwouldalsoliketothankRickKingslan,Karen
Wong,andMarkSchmidt.
Lastofall,IwouldliketomentionmybrothersRakeshand
Rajeev,forallthewonderfulthingsIhavelearnedfromthem,
andSimpleandShilpiforjustbeingsowonderful.Andmy
inspirationandmydrivingforceNeelu.


WeWanttoHearfromYou!
Asthereaderofthisbook,youareourmostimportantcritic
andcommentator.Wevalueyouropinionandwanttoknow
whatwe'redoingright,whatwecoulddobetter,whatareas
you'dliketoseeuspublishin,andanyotherwordsofwisdom
you'rewillingtopassourway.
Youcanemailorwritemedirectlytoletmeknowwhatyoudid
ordidn'tlikeaboutthisbook—aswellaswhatwecandoto
makeourbooksstronger.
PleasenotethatIcannothelpyouwithtechnicalproblems
relatedtothetopicofthisbook,andthatduetothehigh
volumeofmailIreceive,Imightnotbeabletoreplytoevery
message.
Whenyouwrite,pleasebesuretoincludethisbook'stitleand
authoraswellasyournameandphoneoremailaddress.Iwill
carefullyreviewyourcommentsandsharethemwiththeauthor

andeditorswhoworkedonthebook.
Email:



Mail:

GregWiegand
AssociatePublisher
SamsPublishing
800East96thStreet
Indianapolis,IN46240USA


ReaderServices
Visitourwebsiteandregisterthisbookatinformit.com/register
forconvenientaccesstoanyupdates,downloads,orerratathat
mightbeavailableforthisbook.


Introduction
WiththebroadesteverworldwidereleaseofaPCoperating
system,in2007WindowsVistaopenedthedoortoaneraof
gadgetdevelopment.Gadgets,whichresideontheWindows
VistaSidebar,aresmall,lightweight,andcanbeveryuseful
applications.TheSidebarisabrandnewplatformforinnovation
anditgivesusersauniquewaytointeractwithinformation.
Thisbookisforpeoplewhowanttocreatefeature-richand
professional-lookingVistaSidebargadgets.It'saguidefor
designers,developers,andanyoneelsewhohasabasic

knowledgeofHTML,CSS,andJavaScriptandwantstoleverage
thisnewandinnovativeplatform.It'sforanyonewhowantsto
createagadgetforhiscompany,orforaprogrammerwitha
greatideatoimplementonaSidebargadgetplatform,oreven
forahobbyistprogrammer,whowantstotryhishandona
gadgetplatform.Thisbookisintendedtogiveyouideasfor
whatyoucandowiththisnewplatformandhowyoucandoit.

What'sintheBook
Thisbookstartswithabriefbackgroundongadgets,andthen
givesabroadandclearviewofthearchitectureofgadget
development.Gadgetdesignconsiderationsareanimportant
partofthisbookandtheygosidebysidewithalmostallthe
chaptersthatdealwithgadgetdevelopment.Onceyou'veread
upontheconceptandscopeofgadgetdevelopment,thebook
helpsyoucreateagadgetcalledMyBlog.Duringthisprocess
thetextelaboratesonthearchitecture,designconstraints,and
implementationdetailsforthegadgetandthendetailssome
standardpracticesapplicabletoallgadgetdevelopment.The
lastsectiondealswithmoreadvancedgadgetexamplesthat
utilize.NET,XML,XHTML,CSS,Ajax,andMicrosoftSilverlight.
Thisbookisdividedintothreebroadsections.

Section1:TheFoundation


Thefourchaptersinthisfirstsectiongiveathorough
backgroundofSidebargadgets.Thesectionexplainsthetypes
ofgadgets,thearchitecture,andthetechnologybehindthe
gadgetdevelopment.The"ApproachtoDesign"chapterhelps

youknowthedifferencebetweenamerelygood-lookinggadget
andaonethatisprofessional,rich,andworththespaceit
takesupontheuser'sdesktop.Thelastchapterdiscussesthe
revenuemodelofthegadget:whatyouneedtoknowtosell
yourgadgets.

Section2:DevelopingaGadget
Thissectionwalksyouthroughthestandarddevelopment
processofagadget.ItdetailsthecreationofthebasicMyBlog
Gadget,whichmakesuseofanRSS/Atomfeed.Italsogoes
throughbestpracticeswiththeuserinterface,design
guidelines,andcommonassumptions.Thelaterchapters
improveonthebasicgadgetbasedonstandardpracticesand
alsodealwithdeployinganddistributingagadget.

Section3:AdvancedSamples
Thesectiondealswithadvancedsamples.Youwillbeableto
createadvancedgadgetssuchasaSiteStatisticsGadget,a
RadioGadget,andaYouTubeVideoGadget.Allthesamples
followstandardpatterns,makingiteasiertoswitchbetweenthe
featuresandfunctionalityyouwant,whenyouwant.Youwill
alsolearnhowtouseActiveXCOMforcreatingautilitygadget
withasample.NetMostRecentUsed(MRU)Gadget.Thefinal
chaptershowsyouhowtocreateagadgetwithMicrosoft
Silverlight.Youwillalsoseehow,injustafewminutes,to
createaSidebargadgetwithMicrosoftPopfly.
Ifyouarearelativelynewgadgetdeveloper,Iwouldsuggest
youtostartwiththefirstsection.Ifyouhavebasicbackground
knowledgeofgadgetsandyoujustwanttostartwiththestepby-steppracticalapproachtogadgetdevelopment,youcan
directlystartwiththesecondsection,"DevelopingaGadget."

Thethirdsection,"AdvancedSamples,"isforpeoplewhohave


developedagadgetandwanttogobeyondthebasicsofgadget
development.Eachchapterinthethirdsectionisactuallyan
advancedsampledealingwithaparticulartypeofgadgetina
scenarioofitsown.


Introduction
WiththebroadesteverworldwidereleaseofaPCoperating
system,in2007WindowsVistaopenedthedoortoaneraof
gadgetdevelopment.Gadgets,whichresideontheWindows
VistaSidebar,aresmall,lightweight,andcanbeveryuseful
applications.TheSidebarisabrandnewplatformforinnovation
anditgivesusersauniquewaytointeractwithinformation.
Thisbookisforpeoplewhowanttocreatefeature-richand
professional-lookingVistaSidebargadgets.It'saguidefor
designers,developers,andanyoneelsewhohasabasic
knowledgeofHTML,CSS,andJavaScriptandwantstoleverage
thisnewandinnovativeplatform.It'sforanyonewhowantsto
createagadgetforhiscompany,orforaprogrammerwitha
greatideatoimplementonaSidebargadgetplatform,oreven
forahobbyistprogrammer,whowantstotryhishandona
gadgetplatform.Thisbookisintendedtogiveyouideasfor
whatyoucandowiththisnewplatformandhowyoucandoit.

What'sintheBook
Thisbookstartswithabriefbackgroundongadgets,andthen
givesabroadandclearviewofthearchitectureofgadget

development.Gadgetdesignconsiderationsareanimportant
partofthisbookandtheygosidebysidewithalmostallthe
chaptersthatdealwithgadgetdevelopment.Onceyou'veread
upontheconceptandscopeofgadgetdevelopment,thebook
helpsyoucreateagadgetcalledMyBlog.Duringthisprocess
thetextelaboratesonthearchitecture,designconstraints,and
implementationdetailsforthegadgetandthendetailssome
standardpracticesapplicabletoallgadgetdevelopment.The
lastsectiondealswithmoreadvancedgadgetexamplesthat
utilize.NET,XML,XHTML,CSS,Ajax,andMicrosoftSilverlight.
Thisbookisdividedintothreebroadsections.

Section1:TheFoundation


Thefourchaptersinthisfirstsectiongiveathorough
backgroundofSidebargadgets.Thesectionexplainsthetypes
ofgadgets,thearchitecture,andthetechnologybehindthe
gadgetdevelopment.The"ApproachtoDesign"chapterhelps
youknowthedifferencebetweenamerelygood-lookinggadget
andaonethatisprofessional,rich,andworththespaceit
takesupontheuser'sdesktop.Thelastchapterdiscussesthe
revenuemodelofthegadget:whatyouneedtoknowtosell
yourgadgets.

Section2:DevelopingaGadget
Thissectionwalksyouthroughthestandarddevelopment
processofagadget.ItdetailsthecreationofthebasicMyBlog
Gadget,whichmakesuseofanRSS/Atomfeed.Italsogoes
throughbestpracticeswiththeuserinterface,design

guidelines,andcommonassumptions.Thelaterchapters
improveonthebasicgadgetbasedonstandardpracticesand
alsodealwithdeployinganddistributingagadget.

Section3:AdvancedSamples
Thesectiondealswithadvancedsamples.Youwillbeableto
createadvancedgadgetssuchasaSiteStatisticsGadget,a
RadioGadget,andaYouTubeVideoGadget.Allthesamples
followstandardpatterns,makingiteasiertoswitchbetweenthe
featuresandfunctionalityyouwant,whenyouwant.Youwill
alsolearnhowtouseActiveXCOMforcreatingautilitygadget
withasample.NetMostRecentUsed(MRU)Gadget.Thefinal
chaptershowsyouhowtocreateagadgetwithMicrosoft
Silverlight.Youwillalsoseehow,injustafewminutes,to
createaSidebargadgetwithMicrosoftPopfly.
Ifyouarearelativelynewgadgetdeveloper,Iwouldsuggest
youtostartwiththefirstsection.Ifyouhavebasicbackground
knowledgeofgadgetsandyoujustwanttostartwiththestepby-steppracticalapproachtogadgetdevelopment,youcan
directlystartwiththesecondsection,"DevelopingaGadget."
Thethirdsection,"AdvancedSamples,"isforpeoplewhohave


developedagadgetandwanttogobeyondthebasicsofgadget
development.Eachchapterinthethirdsectionisactuallyan
advancedsampledealingwithaparticulartypeofgadgetina
scenarioofitsown.


SpecialFeaturesandNotations
Thisbookismeanttobeadefinite,precise,andconcreteguide

forgadgetdevelopment.Bypruningredundantinformationand
filteringandhighlightingtheinformationthatismorecrucial,
wehavetriedtomakeitascomprehensiveaspossible.This
bookincludesvariousfeaturesandconventionsthathelpyou
getthemostoutofthebook.
HTML,CSS,andJavaScriptcodeblockswillbeshownas
follows:
90
<HTML>
CodeinHTML,CSS,andJavaScript
</HTML>

Samplesinglecodelineswilllooklikethis:
90

Statementone;
Statementtwo;

Othercommentswillalsoshowupinthecodewithtwo
backslashes
90

//Commentone


//Commenttwo

Thebookalsousesthefollowingboxesforimportant
information:
Note

ANoteincludesextrainformationtobroadenyour
understandingofatopic.

Tip
ATipprovidesalternative,shortcuts,orinsider
informationofthetopicbeingdiscussed.

Caution
ACautionwarnsyouofpotentialtrapsandpitfalls.


SupportingWebsite
Thebookhasasupportingwebsitewhereyoucandownloadall
thecodesandgadgets.ThewebsitealsohasblogsIhave
writtenonSidebargadgetsandsomeofmypersonalviewson
gadgetdevelopment.Youareinvitedtocheckthatsiteand
contactmepersonally.Youwillalsofinderrataandmost
updatedinformationthere.
Visitwww.innovatewithgadgets.com


PartI:TheFoundation
InThisPart

CHAPTER1InnovatewithWindowsVista
SidebarGadgets





CHAPTER2TheArchitecture
CHAPTER3AnApproachtoDesign
CHAPTER4SellingYourGadget


Chapter1.InnovatewithWindowsVista
SidebarGadgets
"...theonlyreasontoinvestincompaniesinthefutureis
theirabilitytoinnovate...
—JeffreyImmelt,CEO,GE
INTHISCHAPTER
IntroducingGadgetsandtheVistaSidebar
InnovatewithGadgets
GadgetsinDepth
MultiplePlatformsforGadgets

IntroducingGadgetsandtheVista
Sidebar
Formanypeople,Sidebargadgetsarethecoolestnewfeature
intheWindowsVistaoperatingsystem.Gadgetsaresmall,
lightweightapplicationsthatresideontheWindowsVista
SidebarorWindowsVistadesktop.Theyprovideready-to-use
informationandeasyaccesstofrequentlyusedfeaturesand
tools.
Gadgetsofferadiverserangeoffunctionality,fromgivingyou
anat-a-glanceviewofyourupcomingappointments,tolisting
onlinecontacts,todisplayingapictureslideshowofyourFlickr
account,toofferinganeasywaytocontrolyourmediaplayer.
Gadgetscanhaveanynumberofdedicatedpurposes.Asshown
inFigure1.1,theycanbeclocks,calculators,games,sticky

notes,andmore.
Figure1.1.GadgetscanbeplacedanywhereontheVista
desktop,butmostareorganizedontheWindows
Sidebar.


WindowsSidebar
TheWindowsSidebarisapaneonthesideoftheMicrosoft
WindowsVistadesktopandisusedtoplaceandorganizethe
gadgets.YoucaneasilycustomizetheWindowsSidebartosuit
yourpreference:alwaysontoporrestingbelowmaximized
windows.Ifyoudon'twanttokeepyourgadgetsonthe
WindowsSidebar,youcandragthemtoyourdesktopandhide
theSidebar.TheWindowsSidebarcanalsobeactivatedfrom
theiconinthesystemtray.
Gadgetscanhavemultipleinstances,bothintheSidebaras
wellasontheWindowsdesktop,andthesecanbeconfigured
withdifferentsettings.Forexample,youcanhavetwo
instancesofaClockGadget,oneshowingthecurrenttimefor
SanDiego,CaliforniaandtheotheroneforParis,France.
AVistaSidebargadgetconsistsofHTML,CSS,JavaScript,and
imagefiles,allcoordinatedtoaccomplishavarietyoftasks.You
canhostaminiwebpage,callawebservice,integratewitha
businessapplication,orevencalloperatingsystemAPIsto
createacustomapplication.

TechnologyBehindGadgets
Gadgetsaredevelopedusingstandardwebtechnologies,
namelyHTML,CSS,andJavaScript,buttheycanalsouse



×