I’m planning for some time to write an article about Windows Vista SideShow. I was busy lately (actualy I still am) so I’ll just write a few introductory stuff, to get you started.

I assume you know what Vista SideShow is. If you don’t know, maybe you should read about it here. On short: Windows Vista SideShow gives the user the possibility to send data from Windows Vista to an auxiliary device, like a laptop lid or a remote control.

 

 

I’m going to show you how easy it is to write an application that takes advantage of this technology and how can you write an application (a gadget) that works with Windows Vista SideShow.

 

First of all, because I don’t have a SideShow-enabled device, I’ll have to download a SideShow simulator. You can find one in Windows Vista SDK (or you can download it directly from here). After you install the SDK, you have to register a SideShow Simulator on your machine. To do this, open a command prompt as Administrator (Start->Programs->Accessories, right click on Command Prompt, left click on Run as Administrator), navigate to C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin\ (or to C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin\x64 if you’re running the 64 bit version of Vista) and write

 

WindowsSideShowVirtualDevice.exe -regserver

 

To open the simulator, just run C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin\VirtualSideShow.exe (for both Vista x86 and Vista x64). After doing so, you should see the following image:

 

Navigate to Control Panel and click the Windows SideShow icon. You’ll get a window where you can install and uninstall gadgets for your devices. The only device in my list will be the simulator. But if you have more devices attached to your computer, they will appear in the list.

 

 

If you want to install the Windows Media Player gadget, simply check it in the Control Panel and it will immediately appear on your device.

 

 

You can use the buttons on the device to navigate between gadgets and to interact with them. For example, the Windows Media Player gadget lets you see and play the music on your PC.

 

 

But how can you write a gadget for SideShow? All you have to do is download the Windows Vista Sideshow .NET Framework Components 1.0 (they are in beta-version, so you have an excuse if you use them in a presentation and it doesn’t work). After installing this, you’ll get a library (you can find it in C:\Program Files (x86)\Reference Assemblies\Microsoft\Windows SideShow\v1.0\Microsoft.SideShow.dll and it is named Microsoft.SideShow.dll) containing the classes you’ll need to develop gadgets.

 

First you’ll have to add a reference in a Visual Studio application to this library. Every SideShow gadget has an unique ID. You can generate an ID for your gadget using a tool from the Windows Vista SDK (C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin\GuidGen.exe).

 

 

Use the following code to declare a gadget:

        private static Guid GadgetId = new Guid("385FC1BA-0D70-400b-9088-012F496B2017");

        private ScfSideShowGadget g = new ScfSideShowGadget(GadgetId);

 

Of course, you’ll use your own GUID. To use the gadget, you’ll have to register it first:

 

GadgetRegistration.Register(false, //just for me

                                        g.GadgetId, //gadget guid

                                        ScfSideShowGadget.ScfEndpointId, //Scf endpoint

                                        "Hello World", //friendly name

                                        null, //no command line arguments

                                        null, //no icon

                                        false, //works when machine is off

                                        GadgetCachePolicies.KeepNewest, //cache policy

                                        null); //no proprety page

 

Now let’s send some content to the device using our gadget. To send glace content, use the following method:

g.AddGlanceContent("Hello!" + Environment.NewLine + DateTime.Now.ToString());

 

To send notifications, you’ll use this method:

g.ShowNotification(100, "Hello! notification", "Hello! text", null, new TimeSpan(1,0,0));

 

To send pages to your device:


       private void button5_Click(object sender, EventArgs e)

        {

            string pagesAsXML; //reuse this variable to hold the XML

 

            //add menu

            pagesAsXML = this.MenuPage();

            g.AddContent(pagesAsXML);

 

            //add normal page

            pagesAsXML = this.NormalPage();

            g.AddContent(pagesAsXML);

 

            //add dialog page

            pagesAsXML = this.DialogPage();

            g.AddContent(pagesAsXML);

        }

 

        private string MenuPage()

        {

            string scfResult;

           

            scfResult = File.ReadAllText("page1.xml");

            //scfResult = Scf.Body(

            //                Scf.Menu(1, "Menu", ScfSelectAction.Target,

            //                    Scf.Item(2, "Menu"),

            //                    Scf.Div(),

            //                    Scf.Item(3, "Click 2")

            //                )

            //            );

 

            return scfResult;

        }

 

        private string NormalPage()

        {

            string scfResult;

            scfResult = File.ReadAllText("page2.xml");

            return scfResult;

        }

 

        private string DialogPage()

        {

            string scfResult;

            scfResult = File.ReadAllText("page3.xml");

            return scfResult;

  }

 

As you can see from the code, I am using a Windows Form application to send data to the device. When I push a button on the form (button5 click) some pages are sent to the device. The code for one of the pages:

page1.xml

 

<body>

      <menu id="1" title="Menu text">

            <item targer="2">Menu</item>

            <div />

            <item target="3">Click 2</item>

      </menu>

</body>

 

As you can see, each page has an ID. The ID lets you navigate from one page to another. You can also see a comment in the above code . You can use the commented code insted of the XML page, it will have the same effect. The data is sent to the device using Simple Content Format.

After you execute the above code, you’ll find your gadget in the Control Panel  Windows SideShow list of gadgets. Check the box coresponding to your gadget to install it on your device. Go to the device and play with the gadget. Pretty cool, isn’t it?

 

 

You can find more about Windows Vista SideShow here:
 

Technorati tags: ,