Archive

Archive for the ‘Miscellaneous’ Category

Developing simple Windows 7 Gadget – Part 2

February 24th, 2010 Anuraj P No comments

In my last post I have created a simple Windows 7 Gadget for testing Regular expressions. In this post we look into the Gadget Options dialog and Gadget API, which helps to display the options dialog and save the preferences from the User. The options dialog is a nice feature used in Gadgets to manage the user preferences. It is also an HTML file. Unlike the main Gadget HTML file, which is specified in the XML Definition file, the Options HTML File is specified in the main gadget file or in the main Javascript file, generally in the gadget initialization area of your script. In the RegEx Tester example, I am using the RegEx function flags as customization options.

RegEx Tester Settings

RegEx Tester Settings

So I have created an HTML File with 3 checkboxes and wrote a javascript function to get the user selected options, create the flags variable, and when closing the Options dialog, save the user preferences. To create the settings or options dialog, set the SettingsUI property.

System.Gadget.settingsUI = "settings.html";

After setting the SettingsUI property, the Gadget will display a Options button in the Gadget handle.

Settings Button

Settings Button

The Gadget API also supports various events / callback functions for the Options dialog, like SettingsClosing, SettingsClosed etc, which helps to save the Preferences and Read the preferences in the Gadget.

System.Gadget.onSettingsClosed = settingsClosed;
function settingsClosed(event) {
	//OK Button clicked.
if (event.closeAction == event.Action.commit) {
	//Load settings here.
}
}

Gadget API supports various methods to read and write settings. For writing setting we can use System.Gadget.Settings.write or System.Gadget.Settings.writeString. Both the functions will expects a key/value pair. And for reading can use System.Gadget.Settings.read or System.Gadget.Settings.readString, both of these functions take a key and return a value. If the key does not exist (for instance if it has never been written) both will return a value of undefined. Use System.Gadget.Settings.xxxxString method, if you are working with string values. All the settings are stored in Settings.ini file. And it is available in the “C:\Users\\AppData\Local\Microsoft\Windows Sidebar” location.
Saving the preferences

System.Gadget.Settings.write("RegExOptionsSaved", "true");
System.Gadget.Settings.write("RegExOption", escape(result));

And reading the Preferences 

if (System.Gadget.Settings.read("RegExOptionsSaved")) {
regExOptions = unescape(System.Gadget.Settings.read("RegExOption"));
}

RegEx Object constructor 

var re = new RegEx("Pattern","Flags");

And the Flags are

  1. Global Search – g – The global search flag makes the RegExp search for a pattern throughout the string, creating an array of all occurrences it can find matching the given pattern.
  2. Ignore Case – i – The ignore case flag makes a regular expression case insensitive. For international coders, note that this might not work on extended characters such as å, ü, ñ, æ.
  3. Multiline Input – m – This flag makes the beginning of input (^) and end of input ($) codes also catch beginning and end of line respectively.

Developing simple Windows 7 Gadget – Part 1

February 24th, 2010 Anuraj P No comments

Gadgets are simple and lightweight applications, which can be developed using HTML, Javascript and CSS. Gadgets can also include Image files. In Windows Vista, we can create Gadgets by zipping the files, and rename the it with .Gadget extension. In Windows 7 we can create Gadget by creating the .Gadget folder in C:\Program Files\Windows Sidebar\Gadgets\ folder. This folder contains all the default gadgets from Microsoft.

Creating Simple RegEx Tester Gadget

Regular Expressions are complex but efficient technique for processing text. And the RegEx functions are available in Javascript. So I am to creating simple regex tester gadget using Javascript. You can find a simple RegEx Tester using Javascript here : http://www.regular-expressions.info/javascriptexample.html.

For creating a Gadget we require a XML Definition file, which contains the details about the Gadget File, Links to Icons, and Copyright information. Here is skeleton a XML Definition file.

<?xml version="1.0" encoding="utf-8" ?>
<gadget>
<name>RegExTester</name>
<namespace>dotnetthoughts</namespace>
<version>1.0.0.0</version>
<author name="dotnetthoughts">
<info url="http://dotnetthoughts.net" text="www.dotnetthoughts.net" />
<logo src="logo.png" />
</author>
<copyright>&#0169; 2010</copyright>
<description>For Testing Regular Expressions</description>
<icons>
<icon width="64" height="64" src="icon.png" />
</icons>
<hosts>
<host name="sidebar">
<base type="HTML" apiVersion="1.0.0" src="RegExTester.html" />
<permissions>full</permissions>
<platform minPlatformVersion="0.3" />
</host>
</hosts>
</gadget>

And the Tags details are

name: Title of your gadget.
version: Version number of your gadget.
author: Your name or your company’s name.
info url: Web site address.
info text: Friendly name for your Web site.
logo src: Name of company’s logo image file.
copyright: Copyright notice.
description: Description of the gadget.
icon src: Name of icon image file for the gadget.
base src: Name of gadget’s main HTML file.

Gadget Details.

Gadget Details.

Save this file as Gadget.xml. Next we need to create the RegExTester.html, which is the main file, nothing but simple HTML file with some UI components.


<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/vbscript" src="message.vbs"></script>
<script type="text/javascript" src="regexcheck.js"></script>
<title>RegEx Tester</title>
</head>
<body>
<form>
<table border="1" cellpadding="1" cellspacing="5" bordercolor="red">
<tr><td><b><u>RegEx Tester</u></b></td></tr>
<tr><td><label>Regular Expression</label></td></tr>
<tr><td><textarea id="txtRegExp" cols="25" rows="4"></textarea></td></tr>
<tr><td><label>Subject String</label></td></tr>
<tr><td><textarea id="txtSubject" cols="25" rows="4"></textarea></td></tr>
<tr><td><button onclick="javascript:demoMatchClick();">Test Match</button>&nbsp;&nbsp;
<button onclick="javascript:demoShowMatchClick();">Show Match</button></td></tr> </table>
</form>
</body>
</html>

You may noticed that I have included a message.vbs file, it helps to display alert() boxes from Javascript. I don’t know why alert and prompt functions are not available in Gadgets. Also we don’t need to worry about cross platform compatibility issues in Gadgets, we can write anything supported by Microsoft Internet Explorer.

Here is the code of Message.vbs file.

sub alert(prompt)
MsgBox prompt, 48 , "RegEx Tester"
end sub

And here is the contents of regexcheck.js file.

function demoMatchClick() {
var regExCtrl = document.getElementById("txtRegExp");
var subjectCtrl = document.getElementById("txtSubject");
var re = new RegExp(regExCtrl.value);
if (subjectCtrl.value.match(re)) {
	alert("Successful match");
} else {
	alert("No match");
}
}
function demoShowMatchClick() {
var regExCtrl = document.getElementById("txtRegExp");
var subjectCtrl = document.getElementById("txtSubject");
var re = new RegExp(regExCtrl.value);
var m = re.exec(subjectCtrl.value);
if (m == null) {
	alert("No match");
} else {
	var s = "Match at position " + m.index + ":\n";
	for (i = 0; i < m.length; i++) {
		s = s + m[i] + "\n";
	}
	alert(s);
}
}

Also I added a CSS file for styling the components. Also to specify the Height and Width of the Gadget. In Windows Vista, we need to limit the size of the Gadget, because the Gadget can only place in the Sidebar, but in Windows 7 we can place the Gadget anywhere in the desktop. Also I have added icon.png and logo.png files, as specified in the XML definition file.
The current folder structure is like this.

Folder Structure

Folder Structure

Now using any compression tool, compress the files, and Rename it as RegExTester.Gadget. Double click on the Gadget file, Windows will ask for a confirmation.

Gadget install Confirmation

Gadget install Confirmation

Click Install. It will start the Gadget. Here is the screenshot of RegExTester gadget running on my Windows 7 machine.

RegExTester Running on Windows 7

RegExTester Running on Windows 7

This is an introduction only, I will try to post about Gadget API, Gadget Settings etc in the next post.

Happy Coding :)

GodMode in Windows 7

January 18th, 2010 Anuraj P No comments

Few days before one of my colleague twitted a link about GodMode in Windows 7. I just visited the link and I found it is kind of Easter egg from Microsoft, which gives a list of Program tasks like control panel. The website is also mentioned like it is also available in Windows Vista, but Microsoft is not recommended it in x64 machines. As I am working as part of some Windows application development team, I am using Windows Vista as my dev OS. So I thought of exploring God Mode in Windows Vista.

To enable GodMode, just right click, Select New, Select Folder. Then type “GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}“. Now the Icon will change, and it will become similar to control panel Icon. And on double clicking you can able to see lot of options (in my Windows 7 machine it is giving 279 items). I just created one folder and renamed it. Wow the Icon changed.

Godmode in Window 7

Godmode in Window 7

After that I double clicked it. Windows Explorer crashed :( I was using x86 machine, and my Explorer crashed. But I started explorer again using Task Manager. Then I right clicked and select the Explore option. Yes there is an explore option available in Windows Vista, but it is not available in Windows 7. Then the explorer crashed again :( expected. So I thought I will stop exploring God Mode in Windows Vista, but the sad thing is when ever I start explorer using Task Manager, it is crashing. :(

Then I searched about how to fix this issue, but no one is reported the problem with x86 machines. Based on most of the solutions provided, I deleted this folder using Command line(cmd.exe). Restarted, still the problem exists. Then again I searched, later I found a solution to delete some registry key. I tried it, restarted it and it worked. :)

Solutions to Fix God mode problems in Windows Vista

  1. Delete the God mode directory using CMD tool. Go to the location where you created the God Mode directory, use RmDir Godmode.{ED7BA470-8E54-465E-825C-99712043E01C} to delete it. Restart the machine. Normally it will fix the issue.
  2. If your explorer still crashing, Open RegEdit, Search for {ED7BA470-8E54-465E-825C-99712043E01C}. And delete all instances *. I found only one instance in my Windows Vista machine. Restart. It fix the issue.

Thanks to Jayan for giving me link to GodMode ;)

* Changes made to the Windows registry happen immediately, and no backup is automatically made. Do not edit the Windows registry unless you are confident about doing so.

Microsoft Community Tech Days

October 6th, 2009 Anuraj P No comments

Kerala Microsoft Users Group is organizing the Microsoft Community Tech Day in Trivandrum on 24th Oct 2009.

K-MUG Logo

Agenda

  1. 08:30AM – 09:15AM – Registration
  2. 09:15AM – 09:25AM – Welcome Speech
  3. 09:25AM – 09:45AM – Key Note Session
  4. 09:45AM – 05:00PM – Technical sessions

Technical Sessions

  1. Windows Azure & Clouds
  2. SQL Server tips
  3. Coding for Fun (Twitter, Orkut, Facebook, GTalk etc from .NET C#)
  4. SketchFlow for prototyping
  5. Windows Presentation Foundation (WPF)
  6. LINQ
  7. Writing Secure Code

For more details visit
http://k-mug.org/content/ctd09.aspx

Free Registration either at http://communitytechdays.com/(if you have live id)
or
http://www.eventbrite.com/event/418804656

Note: There can be some changes in Agenda based on the last minute updates

Mini TechEd in Trivandrum

June 11th, 2009 Anuraj P No comments

logo
Kerala Microsoft user’s group (K-MUG) is organizing a Mini-TechEd in Trivandrum. Don’t miss this Free opportunity to learn about Windows 7, Visual Studio 2010 features, WPF, What is new in ASP.NET 4.0, SQL server best practices,SQL logical query execution and optimization tips,Hidden Gems in SQL Server.

Details

Date : 27th June 2009

Venue : Technopark, Trivandrum

Register Now!

Agenda

  1. Visual Studio 2010 Features
  2. What is new in ASP.NET 4.0
  3. Silverlight 3.0
  4. Windows 7 for developers
  5. SQL server best practices
  6. SQL logical query execution and optimization tips
  7. WPF Graphics
  8. Hidden Gems in SQL Server
  9. All about User Experience

Related Links:

Categories: Miscellaneous Tags: ,

Kerala Microsoft Users Group (K-MUG) Launch on 25th Oct 2008

October 14th, 2008 Anuraj P Comments off

Kerala Microsoft Users Group (K-MUG) Launch on 25th Oct 2008

Kerala Microsoft Users Group (K-MUG) Launch on 25th Oct 2008

Kerala Microsoft Users Group (K-MUG) Launch on 25th Oct 2008


Please visit K-MUG site for more details.

Categories: Miscellaneous Tags: