| Jonathan's profileJon's Vista Gadgets BlogBlogLists | Help |
|
Jon's Vista Gadgets BlogJune 03 Power Plan GadgetI've recently posted a "Work in Progress" Gadget on AeroXperience, that changes the current Vista Power plan based on currently running processes. I wrote the Gadget because whilst playing Assassins Creed, I noticed Vista was lowering the CPU to 50% - which was dropping the frame rate by around 15FPS. I normally leave the power plan on Balanced to save power, but got fed up having to manually change it to Performance whenever I played AC. Download here. April 24 HOW TO: Debugging GadgetsDebugging Gadgets can be a little frustrating, not only whilst coding; but also when trying to get useful feedback from users who've reported issues. The simplest way to achieve this, is to log debug entries out to a file. In the example below, we check to see if "debug.txt" exists in the Gadget folder and if it does write debugging information to it. The first step is to see if the file exists and open it. In the following code, we create a BOOLEAN variable "bDebug" which we can use later to output more detailed information, beyond simply errors:
It's good practice to get into the habit of wrapping all your functions in a try/catch loop, to prevent Runtime errors from popping up:
It's also a good idea to put in tracking information, so you know where you are in the code. For example:
To enable "debug mode", simply create a blank text file in your Gadget folder called "debug.txt". Personally, I put this code into all Gadgets and leave "debug.txt" out of the Gadget package. When a user reports an issue, I ask them to create the file and eMail it back to me once they've reproduced the problem.
Whilst your developing your code, I'd also advise running Microsoft's Debug View; which will allow you to watch all debug entries as they occur. In a future article, I'll detail how to write out debugging information from VB and C++ ActiveX DLL's. HOW TO: Implementing Drag / Drop in Gadgets
October 03 HOW TO: Skin selectionYou want to provide your users with a visual skin selector in your settings, but don't know where to start. Here's all the code you'll need to do it. The end result will look something like this:
File structure Firstly, create a file structure to support skins. You'll be placing all the skins in subfolders under a themes folder.
This keeps all your skins out of the way, and easy to distinguish from the rest of the Gadget. Each skin subfolder should be named as you'd like the skin name to appear to the user. ie Default, Blue, Black etc. And each folder needs to contain a folder.png file, which should be a screenshot of the Gadget with the skin applied. This image should ideally be scaled and no larger than 100x100 pixels.
Images You'll need some images for the previous/next buttons, so save the following images in the images folder created above.
Settings.html The settings file needs to search the themes subfolder, store the options and select the current skin. Without going into too much detail, it will create an array of the subfolders under themes and using the gSkin stored setting, select the currently selected skin. The only entry you need to change is the default skin name, which is the first line of the script. <html> body{ System.Gadget.onSettingsClosing = settingsClosing; var oFSO = new ActiveXObject("Scripting.FileSystemObject"); var currentSetting = System.Gadget.Settings.readString("gSkin");
The only function not coded above is updateGadget(), which needs to apply the skin to the Gadget. An example would be to reload the Gadget:
Or, call the parent function that loads the skin (see Loading the Gadget skin):
Loading the Gadget skin This is the tricky bit and depends very much on how complicated you want your skins to be. It can also get very complicated if you're supporting docked/undocked states and left/right handed sidebars. For sanity, I've assumed we have only one Gadget state in the following examples. Option 1 - The skin contains graphics only, in which case you just need to update the URL's of your images. eg.
Option 2 - As well as containing images, the skin also has a stylesheet called skin.css. To see this in action, look at Media Player
Note that when applying a stylesheet, due to bugs in Sidebar, several style settings aren't applied. Body background images, body width and body height to name but a few. If you skins change the Gadget size, you'll have to code around this by reading and applying the stylesheet settings yourself.
Option 3 - The skin contains code. To see this in action, look at Spectrum Analyser. This is ironically the easiest option, as you can leave the skin to initialise the Gadget's graphics etc. Simply append the following code immediately before the closing </html> statement in your gadget.html file:
Your skins should then use the skinPath variable for all local file references. September 27 Spectrum Analyser updatedThere's a new version of Spectrum Analyser available on AeroXP. |
|||||||||||||||||||||
|
|