Programming Windows Sidebar Gadgets

by Milad 2. May 2010 22:38

It’s been a long time since Windows Vista is introduced to the IT World(And how much we are thankful for Windows 7 being introduced!)

One of the remarkable things about Post-XP Windows, is the cute Gadgets floating around our desktops!

This posts tells you how you can make your own Gadgets for Windows Sidebar*

What is a .gadget file?

If you are a curious Mac user(or possibly Yahoo Widget Engine user.) you may already know the answer to this question.
A .gadget file is just an archive file(.ZIP file.) wrapping a bunch of stuff together and making them ready for running under Sidebar.exe.

What is in a .gadget file?

A simple gadget, must have 2 files:

  • gadget.xml
  • An HTML Startup Page

A more complicated one, can have these files too:

  • CSS Files for Styling
  • Javascript Codes (Interacting with Sidebar APIs)
  • A bunch of Images

Gadget.xml:

The manifest of your Gadget. Everything that sidebar should know about your gadget is stored in this file.
This is a general form of a gadget.xml file:


<?xml version="1.0" encoding="utf-8" ?>
<gadget>
        <name>Sample Gadget</name>
        <namespace>windows.sdk</namespace>
        <version>1.0.0.0</version>
        <author name="Microsoft">
                <info url="msdn.microsoft.com" />
                <logo src="logo.png" />
        </author>
        <copyright>&amp;#169; Microsoft Corporation.</copyright>
        <description>Sidebar gadget sample.</description>
        <icons>
                <icon height="48" width="48" src="icon.png" />
        </icons>
        <hosts>
                <host name="sidebar">                         <!-- New autoscaleDPI node -->
                        <autoscaleDPI>true</autoscaleDPI>                         <base type="HTML" apiVersion="1.0.0" src="sample.html" />
                        <permissions>Full</permissions>
                        <platform minPlatformVersion="1.0" />
                        <defaultImage src="icon.png" />
                </host>
        </hosts>
</gadget>

HTML Startup page:

A really simple page containing your gadget.

Sidebar.exe APIs

Well nobody like a static gadget!
Fortunately, you can spice up your gadgets with some APIs provided by Sidebar.exe. For example you can access Power Information of the machine your gadget is running on. Or the information about machine’s Total Memory and Available Memory or available networks in wireless range etc.

Here is a sample Javascript:
(this code uses Sidebar.exe APIs to get Machine Power Status)


function OnPageLoad() {
    System.Machine.PowerStatus.powerLineStatusChanged = GetPowerStatus;

    GetPowerStatus();
}

function GetPowerStatus() {  
    var sMachineInfo;
    // Get the machine details.
    if (System.Machine.PowerStatus.isPowerLineConnected == true) {
        sMachineInfo += "Connected to External Power." + "<br/>";       
    } else {
        var percent = System.Machine.PowerStatus.batteryPercentRemaining;       
        sMachineInfo += "Power Percent Remaining: " + percent.toString() + "%<br/>";
    }

    // Initialize the gadget content.
    var s = document.getElementById("gadgetContent");
    s.InnerHTML = sMachineInfo;
}

Deploying your gadgets:

In order to deploy your gadgets, you should select it’s files and put them into a .ZIP archive. Then change the extension of the file from .ZIP to .Gadget in order to make it visible to Sidebar.exe

Where to now?

http://msdn.microsoft.com/en-us/library/dd370867(VS.85).aspx#development
http://www.codeproject.com/KB/gadgets/InsideBar.aspx

And I really recommend this book (for a quick review, check the book’s source codes.):
Cover image for product 047017661X

And you know the most accurate reference for Microsoft APIs, is MSDN.

* You can use all of these resources for Windows Sideshow Gadget development.

Tags: ,

Computer | Internet | Programming

A simple HTMLHelper for displaying Gravatars

by Milad 2. November 2009 20:44

Practically, The whole world knows about Gravatar(Globally Recognized Avatar).
I wanted to use this awesome service in one of my ASP.NET MVC applications, So I went to it’s documentation to see what should I do. [Well there is a great HTMLHelper in order to perform this, but I have a point!]

The big thing in constructing a Gravatar URL is how to get a string’s hexadecimal MD5 Hash. [as you may or may not know, you can do lots of stuff with MD5 Hash of anything!]
So … This is the answer to this question:

Function GetHash(ByVal text As String) As String
        Dim myhash As MD5CryptoServiceProvider = New MD5CryptoServiceProvider()

        Dim hashed = _
            myhash.ComputeHash(System.Text.UTF8Encoding.UTF8.GetBytes(text))

        Dim sb As StringBuilder = New StringBuilder()

        For Each b In hashed
            sb.Append(b.ToString("x2"))
        Next

        Return sb.ToString()
End Function

Tags: , , ,

ASP.net | Computer | Internet | Programming

Anti Spam

by MiladKDZ 26. September 2009 11:44

This Blog is now Protected with Akismet Anti Comment Spam System. [as I think Keyvan's weagis is down.]

Thanks to CodeThinked for Aksimet BlogEngine.net Extension.

Tags: ,

BlogEngine.NET | Internet

To share an interesting experience!

by MiladKDZ 25. May 2008 09:25

When I bought my Qtek S200(HTC Prophet), It came with a simple WM5.0 ROM. I wasn't thinking of upgrading the ROM for many reasons(for example I had lots of Short Messages that I wanted to keep, and I wasn't sure that my Contacts would Sync this easy!) plus that the upgrading guide on XDA-Developers website was so confusing and I wasn't sure I can make it!

Yesterday when I was checking out XDA-Developers website looking for a way to overclock my CPU, I saw this new method for upgrading and flashing Prophet(Qtek S200) ROM.

I checked out ROM List for my device and I chose Cloudyfa's [wm6.1]Prophet ShadoW 2.0 Touch Edition . (I also downloaded [wm6.1]Prophet S4V.19701.01 (UC))

I backed up all of my stuff(using a bunch of tools like Jayo Mobile Extender) and I flashed my ROM. This ROM is so gorgeous and has no stupid bugs like the original shipped one! Cloudyfa is the best I think ;)

Now I have WM6.1 on Qtek S200! ;)

PS: Here are some useful links about prophet:

Prophet Wiki on XDA-Developers

How to dump ROM and restore

Complete Overclock Guide for Prophet and also [I Overclocked up to 228MHz and my device was stable with both Originally shipped ROM and ShadoW one.]

Tags: , , ,

Computer | Internet | PPCPE | Windows Mobile

Fibonacci

by MiladKDZ 11. May 2008 20:00

فیبوناچی بازرگان هم بوده!

علم یا ثروت؟!

Tags: , , ,

General | Personal | Language: Persian | Internet

Old Google!

by MiladKDZ 30. January 2008 01:11

Look and Look!

There are awesome things on this website! Check it out ;)

Tags: ,

Daily Link | Internet

Public Function myNetSurf() as InternetAdress

by MiladKDZ 13. January 2008 11:18

' Link to a free game offer by VALVE!

Dim myObj as new InternetAdress _
("http://digg.com/pc_games/A_free_sampler_of_Portal_for_NVIDIA_GeForce_owners")

myObj.WTF = "a free game offer by VALVE!"

Return myObj

End Function

If you r not a VB fan, just clicking on the link would take you to the offer page! ;) 

Tags: , , ,

General | Daily Link | Internet | PC Game