Click here to Skip to main content
15,879,326 members
Articles / Programming Languages / C#
Article

Weather Sideshow

Rate me:
Please Sign up or sign in to vote.
4.58/5 (80 votes)
28 Mar 2007CPOL6 min read 122.2K   3.1K   71   8
A SideShow application that communicates with a Weather webservice

SideShowLogo Image

WeatherSideShow Image

Contents

Introduction

This article explains the power of a new Vista feature, the SideShow. The goal of this article is to use the Sideshow, with as few steps as possible. To demonstrate this, I will get data from a web service. After this article, you can use the Gadget Class to retrieve data either from your database or from your program or from the systems, whatever you prefer.

When I developed the article, the framework was in beta.

The environment I used to test it:

  • Windows Vista 5384 (Beta2) Eng.
  • Windows Vista 5600 Eng.
  • Windows Vista Business Ita.

At the end of this document, there are some links that will help you with installing the Microsoft VirtualSideShow.

Background

The Microsoft Windows SideShow Platform is a new feature developed for Microsoft Windows Vista that enables developers to create new applications and extend existing ones specifically for devices with small displays and limited interaction models. Applications designed to work with the platform are referred to as gadgets. The devices supported by the platform include, but are not limited to: displays attached to a laptop, front panel computer displays, displays embedded in keyboards, cell phones, digital picture frames, and other display devices.

Driver and Simulator

To compile the code, you must install the SideShow SDK Beta, which is currently available from Microsoft here.

To run the binary, you need to obtain two files, a driver and an emulator, which shipped with the Vista SDK.

After installation, you will find the emulator driver (WindowsSideShowVirtualDevice.exe) and emulator (VirtualSideShow.exe) in the 'C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin' directory.

Execute windowsSideShowvirtualdevice.exe /regserver first and VirtualSideShow.exe right after.

In the Control Panel, open Windows SideShow, now you can see the Simulator installed as shown in the picture after.

 Control Panel- Windows SideShow Image

The VirtualSideShow.exe has only the default item.

 VirtualSideShow - Delault Image

When you use my demo and click register, it adds a new item to the list. Then you can run the demo program WeatherSideShow.exe, contained in the demo download.

Info: Note that to see the sample run on the SideShow, you must have VirtualSideShow.exe open.

Using the VirtualSideShow

Several options are offered:

 Keypad VirtualSideShow Image

  • the arrow keys to navigate the menu
  • the OK button to enter the gadget and its menu
  • the backspace to go back

Launching and registering WeatherSideShow.exe adds a new item on VirtualSideShow called 'Weather SideShow Gadget'.

The inside menu shows a menu with two items, the first is the data received from WS, the second is the data stored in the application.

Using the Binary

First of all, you must have VirtualSideShow.exe opened as described above.

After this, you have it in the list of simulator. Now you are ready to communicate with the weather gadget.

 Keypad VirtualSideShow Image

  • In the app: You must use the button 'Get Country' to add the country and city using the web services to combobox. It may take a minute depending on your connection speed.
  • Then you can select the country and city you like and see if the data for the selected item is available.

If you want, you can use the timer to refresh automatically and save all selected data.

The SideShow is refreshed every time the 'auto timer' starts and every time you click 'Check weather of saved data'.

Using the Code

I have created this project as a C# windows application.

With this application, you can retrieve all the cities and countries from the web services I used. Select one and test if your city has weather data.

If you like, you can set a timer to refresh the app and the SideShow automatically.

You can save your data and use it in the next session.

The code follows these ideas:

  • MySideShowGadget: a class that communicates with SideShow
  • The registry to save and store data
  • A class for the global weather webservice, and an XML parser to 'translate' data to SideShow
  • A class (GadgetRegistration) to register and unregister the gadget
  • A class (Scf) to download data to the virtual device
  • A timer for automatic refresh

Here, I describe only the calls I used for the SideShow.

Info: I used a free webservice from WebserviceX.NET. If the server is busy and you get the error, "service unavailable", you can see if it's working here.

All the necessary code for the SideShow is in MySideShowGadget. All other classes are used for retrieving data and manipulating it.

I used a Guid m_sGadgetId for registering and unregistering the gadget and more important to create ScfSideShowGadget.

MySideShowGadget uses the ScfSideShowGadget Class to add data into the SideShow pages. I added some methods but the most important ones are:

  • Register:

    To register the gadget, I used the class GadgetRegistration as described below, with comments. With the GadgetRegistration.Register, the new gadget is added to the SideShow list.

    C#
    GadgetRegistration.Register(
    false,                                    //Only for this account
    m_sGadgetId,                              //GUID
    ScfSideShowGadget.ScfEndpointId,          //EndPoint
    m_sGadgetFriendlyName,                    //Name to Display
    null,                                     //command to start
    null,                                     //the ico
    false,                                    //online info
    GadgetCachePolicies.KeepNewest,           //the Cache policy
    null);                                    //the property page
  • Unregister:

    To unregister the gadget, deletes the gadget from the SideShow list.

    C#
    GadgetRegistration.Unregister(false, m_sGadgetId);
  • DefaultContent:

    To display text at a glance. I used the method AddGlanceContent to add content. This method adds a string that can be displayed in the description of the gadget in the SideShow menu. I added "Updated on: {0:D}\n {0:T}", DateTime.Now"

    C#
    m_oScfSideShowGadget.AddGlanceContent("some text do display");
  • DownloadDataToDevice:

    The data stored into the application is copied to the SideShow. This method uses AddGlanceContent and AddContent to add a page to SideShow display.

    C#
    m_oScfSideShowGadget.AddContent(MyXMLPage);

    AddContent adds/modifies a page to the content. This method requires an XML string. You can use an XML page directly or use the scf class. You must use it to add all the pages required for the SideShow. In my case, I used it four times.

    Add Body: This is the first use of Scf class. On first use, the scf requires the body be set with Scf.Body. This method takes as input the menu and items:

    C#
    sContentXml = Scf.Body(
                  Scf.Menu(1, "Weather gadget menu", ScfSelectAction.Target,
                  Scf.Item(2, "See Last weather of " + m_sCity + ", " + 
    
    m_sCountry),
                  Scf.Item(3, "See all the option")));

    Here, you can see that I have added the body, one menu and two items inside the gadget.

    Add pages: the second time you use scf call Scf.Content method with the id that you have inserted in the body. In this example, I've added a picture and more text:

    C#
    Scf.Content(
                2, "Weather of " + m_sCity + ", " + m_sCountry,
                Scf.Txt(ScfAlign.Left, true, Color.Black, m_lblWind + " " + 
    
    m_txtWind),
                Scf.Txt(ScfAlign.Left, true, Color.Black, m_lblVisibility + " " + 
    
    m_txtVisibility),
                Scf.Txt(ScfAlign.Left, true, Color.Black, m_lblSkyCondition + " " + 
    
    m_txtSkyConditions),
                Scf.Txt(ScfAlign.Left, true, Color.Black, m_lblTemperature + " " + 
    
    m_txtTemperature),
                Scf.Txt(ScfAlign.Left, true, Color.Black, m_lblHumidity + " " + 
    
    m_txtHumidity));

    Use this method to add all the pages.

This is the sample I share that copies data to SideShow.

WeatherSideShow Image

This is the result that you can see in your SideShow or VirtualSideShow.

Screenshot - WeatherSideShow2.GIF

That's all!

Points of Interest

I've yet to find code on the internet that runs like the author said. If you have problems in compiling or executing the project, please leave a post.

Microsoft help, installing VirtualSideShow:

MSDN help, Scf Members:

History

  • 28th March, 2007 - Third release, article update
  • 14th March, 2007 - Second release, article update
  • 28th January, 2007 - First release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Welcome Italia spa
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralExcelent Pin
Abhijit Jana17-Jul-09 11:28
professionalAbhijit Jana17-Jul-09 11:28 
GeneralRe: Excelent Pin
Dr.Luiji9-Oct-09 0:18
professionalDr.Luiji9-Oct-09 0:18 
GeneralGood Article! Pin
NizZ82-Mar-08 12:06
NizZ82-Mar-08 12:06 
GeneralRe: Good Article! Pin
Dr.Luiji2-Mar-08 21:26
professionalDr.Luiji2-Mar-08 21:26 
GeneralGood article and gadget Pin
marcasselin1-May-07 2:31
marcasselin1-May-07 2:31 
AnswerRe: Good article and gadget Pin
Dr.Luiji1-May-07 4:13
professionalDr.Luiji1-May-07 4:13 
GeneralDidn't work Pin
JoeIsTheMan14-Mar-07 7:09
JoeIsTheMan14-Mar-07 7:09 
QuestionRe: Didn't work Pin
Dr.Luiji14-Mar-07 9:01
professionalDr.Luiji14-Mar-07 9:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.