Showing posts with label Tutorials. Show all posts
Showing posts with label Tutorials. Show all posts
Friday, 11 July 2014
First Website using Servlets in J2EE

This is a step-by-step tutorial to show how to create your first website in J2EE. Some people also call it as Advanced Java. We have a .JSP page to display the website and a Java class i.e. a Action Servlet to handle the request generated in the .JSP page.

NOTE :- To create this website, you must have installed the IDE i.e. NetBeans with Apache Tomcat Server.

Here are the steps :-

Step 1 :- Create a new project.

File->New Project->Java Web->Web Application

Step 2:- 

Give it a name.

 

Step 3:- Choose the server

Please choose Apache Tomcat. If your IDE is not showing  it, then you have to reinstall the IDE and make sure that during re-installation, you customize the installation of by choosing the server. After choosing the server, click FINISH.

Step 4:-

After clicking finish button, your IDE will look like this. It means your project has been created.


Step 5:- 

Now next you have to do is edit the code in .JSP file i.e. index.jsp file.

CODE:-

    <body>
        <form action="ActionServlet" method="POST">
            <input type="text" name="text" value="" />
            <input type="submit" value="Ok" />
        </form>
    </body>

Step 6:- Create a new servlet.

Just right click the project -> New -> Servlet


Step 7:-

Give the name of servlet. THe name of the servlet must be same as you have set the value of action attribute in form. We have used " <form action="ActionServlet" method="POST"> ", so name of the servlet should be ActionServlet.


Step 8:- Configuration of Servlet Deployment

Remember to check the checkbox saying "Add information to deployment descriptor(Web.xml). It will add the information of the Servlet in Web.xml file for mapping. After that click FINISH.

Step 9:- 

Now your servlet will be created. Please change your servlet code as following.




Now your website is done. All you have to do is run your project and see your output.

Download the sample project :- Click Here

Please do comment if you have any queries. We value your comments.
Friday, 11 April 2014
Make Windows Bootable Using Commands

In this tutorial, I will show you how to make Windows Bootable using simple Commands in command prompt. Please follow the following steps :

 1. Run the command prompt [i.e. cmd] in Administrotor mode.


2. Type the first command :
diskpart

3. Find the available disks in your system:
list disk

4. Select the disk for your pen drive:
select disk 1

5. The very next command is to clean the drive :
clean

6. After that we have to divide the disk into partitions :
create partition primary

7. The first partition of disk must be selected :
select partition 1
8. activate the selected partition:
active

9. Assign the activated partition using the command:
assign
The moment you execute the assign command, a pop up will come. This pop up will ask you to format the disk.
NOTE:- If this doesn't com, Please follow the steps from beginning.

10. Format the disk in NTFS mode.

11.exit the diskpart mode:
exit


12. Copy the path of /boot/ folder of the Windows 7.

13. Change the working directory of cmd to the boot folder of the OS.
cd G:\boot
G:

14. execute the final command to install the bootcode in the pen drive:
bootsect.exe /nt60 i:
here i: is the label of pendrive.

If the output of the final command comes like shown in the above image, then your pen drive is made bootable successfully. Now you have to copy the files from the Windows folder and paste in your pen drive. That's it.

If you have any queries regarding the above post, write the comments or contact us.
Wednesday, 26 March 2014
WCF Step by Step Tutorial


Definition of WCF

Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF we can build secure, reliable, transacted solutions that integrate across platforms.

WCF is a unified framework which provides :
      1. NET Remoting 
      2.Distributed Transactions 
      3.Message Queues and 
      4.Web Services 
into a single service-oriented programming model for distributed computing.

WCF interoperate between WCF-based applications and any other processes that communicate via SOAP (Simple Object Access Protocol) messages.

Features of WCF

    -Service Orientation
    -Interoperability
    -Multiple Message Patterns
    -Service Metadata
    -Data Contracts
    -Security
    -Multiple Transports and Encodings
    -Reliable and Queued Messages
    -Durable Messages
    -Transactions
    -AJAX and REST Support
    -Extensibility

To know more about features of WCF see: http://msdn.microsoft.com/en-us/library/ms733103.aspx

Terms of WCF

A WCF service is exposed to the outside world as a collection of endpoints.
      1. Endpoint: Endpoint is a construct at which messages are sent or received (or both). Endpoint comprises of ABC’s       
        What are ABC’s of WCF ? 
        A. Address - Address is a location that defines where messages can be sent
       B. Binding - Binding is a specification of the communication mechanism (a binding) that described how messages should be sent
       C. Contract - Contract is a definition for a set of messages that can be sent or received (or both) at that location (a service contract) that describes what message can be sent.
    2. Service: A construct that exposes one or more endpoints, with each endpoint exposing one or more service operations.
    3. Contracts: A contract is a agreement between two or more parties for common understanding and it is a is a platform-neutral and standard way of describing what the service does. In WCF, all services expose contracts.

           Types of Contracts:

           1) Operation Contract: An operation contract defines the parameters and return type of an operation.   
[OperationContract]
double Add(double i, double j);


           2) Service Contract: Ties together multiple related operations contracts into a single functional unit.
[ServiceContract] //System.ServiceModel
public interface IMath
{
    [OperationContract]
    double Add(double i, double j);
    [OperationContract]
    double Sub(double i, double j);
    [OperationContract]
    Complex AddComplexNo(Complex i, Complex j);
    [OperationContract]
    Complex SubComplexNo(Complex i, Complex j);
}

          3) Data Contract: The descriptions in metadata of the data types that a service uses. 
// Use a data contract
[DataContract] //using System.Runtime.Serialization
public class Complex
{
    private int real;
    private int imaginary;
 
    [DataMember]
    public int Real { get; set; }
 
    [DataMember]
    public int Imaginary { get; set; }
}

WCF Step by Step Tutorial

This is the Basic WCF Tutorial ‘wcfMathSerLib’ will be created in a step by step approach. This ‘wcfMathSerLib’ will be tested by ‘ConsoleMathClient’ and with ‘WCF Test Client’

Steps for creating wcfMathSerLib

1. Create a new project.
      a. Open Visual Studio 2010 and File->NewProject
      b.select WCF in ‘Recent Templates’
      c.select ‘WCF Service Library’
      d.Give Name as wcfMathServiceLibrary
      e.Click OK

2. Delete IService1.cs and Service1.cs
3. Add IMath.cs and MathService.cs and add the code listed below

IMath.cs

using System.Runtime.Serialization;
using System.ServiceModel;
 
namespace WcfMathServLib
{
    [ServiceContract] //System.ServiceModel
    public interface IMath
    {
        [OperationContract]
        double Add(double i, double j);
        [OperationContract]
        double Sub(double i, double j);
        [OperationContract]
        Complex AddComplexNo(Complex i, Complex j);
        [OperationContract]
        Complex SubComplexNo(Complex i, Complex j);
    }
 
    // Use a data contract
    [DataContract] //using System.Runtime.Serialization
    public class Complex
    {
        private int real;
        private int imaginary;
 
        [DataMember]
        public int Real { get; set; }
 
        [DataMember]
        public int Imaginary { get; set; }
    }
}

MathService.cs

namespace WcfMathServLib
{
    public class MathService : IMath
    {
 
        public double Add(double i, double j)
        {
            return (i + j);
        }
 
        public double Sub(double i, double j)
        {
            return (i - j);
        }
 
        public Complex AddComplexNo(Complex i, Complex j)
        {
            Complex result = new Complex();
            result.Real = i.Real + j.Real;
            result.Imaginary = i.Imaginary + j.Imaginary;
            return result;
        }
 
        public Complex SubComplexNo(Complex i, Complex j)
        {
            Complex result = new Complex();
            result.Real = i.Real - j.Real;
            result.Imaginary = i.Imaginary - j.Imaginary;
            return result;
        }
    }
}

4.Modify the App.config file as shown
App.config

<configuration>
 
  <system .web="">
    <compilation debug="true">
  </compilation></system>
 
  <system .servicemodel="">
    <services>
      <service name="WcfMathServLib.MathService">
 
        <host>
          <baseaddresses>
            <add baseaddress="http://localhost:8732/Design_Time_Addresses/WcfMathServLib/MathService/">
          </add></baseaddresses>
        </host>
 
        <!-- Service Endpoints -->
        <endpoint address="" binding="wsHttpBinding" contract="WcfMathServLib.IMath">
          <identity>
            <dns value="localhost">
          </dns></identity>
        </endpoint>
 
        <!-- Metadata Endpoints -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
      </endpoint></service>
    </services>
    <behaviors>
 
      <servicebehaviors>
        <behavior>
           <servicemetadata httpgetenabled="True">
          <servicedebug includeexceptiondetailinfaults="False">
        </servicedebug></servicemetadata></behavior>
      </servicebehaviors>
    </behaviors>
 
  </system>
 
</configuration>

Result Using WCF Test Client


1. Run the WcfMathServLib project you will get the ‘WCF Test Client’
2. Select each method say ‘AddComplexNo’ Give the values in ‘Request’
3. Click on Invoke button
4. See the results in “Response”

Steps for creating ConsoleMathClient

1. Create a new C# project
     a. Open Visual Studio 2010 and File->NewProject
     b. select Visual C#->Windows in ‘Installed Templates’
     c. select ‘Console Application’
     d. Give Name as ConsoleMathClient
     e. Click OK



2. Go to ‘Solution Explorer’ Right click on ConsoleMathClient -> Select ‘Add Service
Reference’ the below dialog will be displayed
    a. Click on Discover button
    b. Give namespace as ‘MathServiceReference’ and click OK

The service reference will be added now modify the program.cs as shown below.

Program.cs

using System;
using ConsoleMathClient.MathServiceReference;
 
namespace ConsoleMathClient
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Press <Enter> to run the client....");
            Console.ReadLine();
 
            MathClient math = new MathClient();
            Console.WriteLine("Add of 3 and 2 = {0}", math.Add(3, 2));
            Console.WriteLine("Sub of 3 and 2 = {0}", math.Sub(3, 2));
 
            Complex no1 = new Complex();
            no1.Real = 3;
            no1.Imaginary = 3;
 
            Complex no2 = new Complex();
            no2.Real = 2;
            no2.Imaginary = 2;
 
            Complex result = new Complex();
            result = math.AddComplexNo(no1, no2);
            Console.WriteLine("Add of 3+3i and 2+2i = {0}+{1}i", result.Real, result.Imaginary);
 
            result = math.SubComplexNo(no1, no2);
            Console.WriteLine("Sub of 3+3i and 2+2i = {0}+{1}i", result.Real, result.Imaginary);
 
            Console.ReadLine();
        }
    }
} 

Result

Compile and Run the project to see the Result

Keep in touch for more updates. Contact Us for any queries.

You may also like:

Developing a Gadget for Windows Sidebars (Gadgets) : Click here
Sunday, 16 March 2014
Developing a Gadget for Windows Sidebar Part 3



The last of three overviews that describe how to create a basic gadget for the Windows Sidebar. In this overview, we explain the difference between Settings (or Options as specified in the gadget context menu) and Flyout functionality and demonstrate how to incorporate both into a gadget.
  • Introduction
  • The Settings Dialog
  • The Flyout
  • For Further Reference

Introduction

The gadget object model defines two user interface (UI) extensions to the basic gadget UI. The gadget's Settings dialog (System.Gadget.Settings) enables a user to make configuration changes to a gadget while the gadget's Flyout (System.Gadget.Flyout) enables a user to view additional detail or information about a gadget UI.

The Settings Dialog


Settings functionality is exposed by the System.Gadget.Settings and System.Gadget.Settings.ClosingEvent scripting elements. The Settings dialog possesses its own Document Object Model (DOM) and requires its own HTML file (specified by assigning the path of an HTML file to the settingsUI property), Microsoft JScript, and other supporting files. Assigning a value to the settingsUI property results in the display of a "wrench" icon which appears when the mouse pointer hovers over the gadget or the gadget has focus. Clicking this icon or selecting Options from the gadget context menu will display the Settings dialog.



The following example demonstrates how to use the settingsUI property to enable the gadget Settings dialog box.
// Enable the gadget settings functionality. 
System.Gadget.settingsUI = "Example.html";

The primary purpose of the Settings dialog is to allow the user to select and modify gadget configuration values (or settings). These values are persistent for the entire session of a particular gadget and unique for each gadget instance. For example, a stock tracking gadget can enable a user to specify a data provider and the stock information display preferences in the gadget and subsequent modification in the Settings dialog.
A Settings value is stored by using write or writeString with a key/value pair. A Settings value is retrieved by using read or readString with the key declared when the value was stored. There is a 1024 character limit for Settings keys and a 2048 character limit for Settings values; values longer than these limits will be truncated.
Note  To limit type conversion errors, the use of writeString and readString is recommended.


The following example demonstrates how to store a Settings value when the user clicks OK in the Settings dialog.
// Delegate for the settings closing event. 
System.Gadget.onSettingsClosing = SettingsClosing;

// --------------------------------------------------------------------
// Handle the Settings dialog closing event.
// Parameters:
// event - event arguments.
// --------------------------------------------------------------------
function SettingsClosing(event)
{
    // Save the settings if the user clicked OK.
    if (event.closeAction == event.Action.commit)
    {
        System.Gadget.Settings.write(
            "settingsSelectionIndex", selUserEntry.selectedIndex);
    }
    // Allow the Settings dialog to close.
    event.cancel = false;
}
The following example demonstrates how to read values from controls in the Settings dialog.
var userEntry = "";

System.Gadget.onSettingsClosed = SettingsClosed;

// --------------------------------------------------------------------
// Handle the Settings dialog closed event.
// event = System.Gadget.Settings.ClosingEvent argument.
// --------------------------------------------------------------------
function SettingsClosed(event)
{
    // User hits OK on the settings page.
    if (event.closeAction == event.Action.commit)
    {
        userEntry = 
            System.Gadget.Settings.readString("settingsUserEntry");
        SetContentText(userEntry);
    }
    // User hits Cancel on the settings page.
    else if (event.closeAction == event.Action.cancel)
    {
        SetContentText("Cancelled");
    }
}
Note  A Settings dialog is modal and does not disappear if it or the parent gadget loses focus. The user must select Ok or Cancel to dismiss the dialog.

The Flyout

Flyout functionality is exposed by the System.Gadget.Flyout scripting element. Flyouts also require their own HTML and JScript files and, as such, possess their own DOM. Communication between the Flyout and the main gadget can be accomplished through the use of the parentWindow property of the System.Gadget.document and System.Gadget.Flyout.document objects. The Flyout file is specified by setting System.Gadget.Flyout.file to the path of an HTML file.
Note   Since a Flyout can disappear at any time, unpredictable behavior or errors may result from attempting to communicate with a Flyout from the main gadget.
The following example demonstrates how to set the gadget Flyout UI from the gadget script file and listen for the Flyout events.
var oGadgetDocument = System.Gadget.document;
System.Gadget.Flyout.onShow = showFlyout;
System.Gadget.Flyout.onHide = hideFlyout;

// --------------------------------------------------------------------
// Initialize the gadget.
// --------------------------------------------------------------------
function Init()
{
    // Specify the Flyout root.
    System.Gadget.Flyout.file = "example.html";
    
    // Initialize the Flyout state display.
    if (!System.Gadget.Flyout.show)
    {
        sFlyoutFeedback.innerText = "Flyout hidden.";
    }
}

// --------------------------------------------------------------------
// Display the Flyout state in the gadget.
// --------------------------------------------------------------------
function showFlyout()
{
    oGadgetDocument.getElementById("strFlyoutFeedback").innerText = "Flyout visible.";
}

// --------------------------------------------------------------------
// Hide the flyout and display the Flyout state in the gadget.
// --------------------------------------------------------------------
function hideFlyout()
{
    oGadgetDocument.getElementById("strFlyoutFeedback").innerText = "Flyout hidden.";
    System.Gadget.Flyout.show = false;
}

A Flyout is typically spawned on an event in the main gadget UI such as a mouseover or click; setting show to true displays the Flyout and false hides the Flyout. This state should be queried before any communication is attempted. Flyouts can be used to display anything but are generally used to display more detail or information about the event target.
The Flyout location is determined by the user's display, the position of the gadget, the size of the Flyout (which has no intrinsic limit), and the location of the Sidebar should the gadget be docked. For example, the Flyout could be displayed to the left or right, above or below the gadget.
The following image shows a gadget Flyout that displays stock ticker details.

The following image shows a gadget Flyout that allows a user to select stock symbols of interest.


Note  A Flyout closes when it loses focus. As a result, only one Flyout can be displayed at any time.

Similar posts : 

Developing a Gadget for Windows Sidebar Part 2

In this overview, we demonstrate how to declare a background image and add some simple text and graphics to a gadget using the three presentation elements in the Sidebar g namespace (g:background, g:image, and g:text) and the native Sidebar image protocol (gimage).
  • Introduction
  • Background Images and the G:BACKGROUND Element
  • The G:TEXT and G:IMAGE Elements
  • The GIMAGE Protocol
    • Sizing

Introduction

The Sidebar presentation elements expose their functionality through qualified HTML elements in the Sidebar g namespace and the gadget presentation APIs. These elements, along with all standard HTML elements, are exposed through the gadget Document Object Model (DOM) and are accessible from gadget script.
The Sidebar supports JPEG, bitmap (BMP), Graphics Interchange Format (GIF), and Portable Network Graphics (PNG) image types. Only PNG supports alpha channel transparency.
Note   The Sidebar presentation elements are not available in standard HTML documents and do not render in external browsers such as Windows Internet Explorer.

Background Images and the G:BACKGROUND Element

There are a number of methods that can be used to declare a gadget background element and specify its image source. Generally, the background object and its image source are declared in the gadget HTML file using the g:background element:
<body>
    <g:background id="imgBackground" src="images/background.png">
        <span id="gadgetContent">Hello World!</span>
    </g:background>
</body>
An alternative is to declare the g:background as previously described, but specify the image source in Microsoft JScript:
<html>
    <head>
        <title>Hello World</title>
        <script type="text/jscript" language="jscript">
            function init()
            {
                var oBackground = document.getElementById("imgBackground");
                oBackground.src = "url(images/background.png)";
            }
        </script>
    </head>
    
    <body onload="init()">
        <g:background id="imgBackground">
            <span id="gadgetContent">Hello World!</span>
        </g:background>
    </body>
</html>
Caution  When using background images with alpha channel transparency the following two methods can result in unpredictable rendering, such as transparent pixels replaced with magenta, and limitations in functionality. As such, they are presented here for information purposes only and are not recommended.
Important  For Windows 7, when the new <autoscaleDPI> element of the gadget manifest is set to true (for high-DPI support) and the following methods are used, rendering issues can increase significantly.
The following example uses the background property to declare the gadget background image:
<html>
    <head>
        <title>Hello World</title>
        <script type="text/jscript" language="jscript">
        function init()
        {
            System.Gadget.background = "images\\background.png";
        }
        </script>
    </head>
    
    <body onload="init()">
        <g:background id="imgBackground">
            <span id="gadgetContent">Hello World!</span>
        </g:background>
    </body>
</html>
A similar method uses Cascading Style Sheets (CSS) to update the backgroundImage Property as shown in the following example:
<html>
    <head>
        <title>Hello World</title>
        <script type="text/jscript" language="jscript">
        function init()
        {
            with(document.body.style)
                backgroundImage = "images\\background.png"; 
        }
        </script>
    </head>
    
    <body onload="init()">
        <g:background id="imgBackground">
            <span id="gadgetContent">Hello World!</span>
        </g:background>
    </body>
</html>
Finally, just like a standard Web page, the gadget background can simply be declared as an attribute of the <body> tag and modified with CSS. However, this does not expose the background as a g:background scripting element.
<html>
    <head>
        <style>
            body{width:120;height:160;font:8 pt Arial;color:white;
            filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=1, StartColorStr="#000000",
            EndColorStr="#0000FF")}
        </style>
    </head>
    <body bgcolor="red" background="background.jpg">
    ...
    </body>
</html>

When one background image needs to be swapped for another of different size, such as when a gadget is docked or undocked, it is recommended that the width of the background element be set to 0. This forces the platform to recalculate the size of the image and refresh appropriately.
See the onUndock or onDock topics for an example.

The G:TEXT and G:IMAGE Elements

The g:text and g:image elements expose gadget text and image functionality respectively.
Note   The g:text and g:image elements can be declared in the gadget HTML file but it is highly recommended that you use the addImageObject and addTextObject methods from JScript instead. This will ensure the element is exposed through the gadget DOM.
The following example demonstrates how to add images and text to the background layer of a gadget. These objects will appear at the top of the z-order for the background layer, but below any user interface (UI) controls.
Caution  Other than g:background, avoid images that render to the absolute edges of a gadget. In high-DPI, rounding errors can cause a magenta fringe around the border of the gadget.
// Initialize the gImage object
// DEFAULT_IMG_PATH: the default image path.
function initImage()
{
    // Check if the user has already selected an image file to use. If not use default.
    if (System.Gadget.Settings.read("imageFile") == "")
    {
        System.Gadget.Settings.write("imageFile", DEFAULT_IMG_PATH);
    }
    imageFile = System.Gadget.Settings.read("imageFile");
    
    // Create the image object
    oImage = document.getElementById("background").addImageObject("", 0, 0);
}

// Initialize the gText object
function initText()
{
    oText = document.getElementById("background").addTextObject("", "Verdana", 10, "blue", 0, 0);
}

function showImage()
{
    oImage.src = System.Gadget.Settings.read("imageFile");
}

function showText(newValue)
{
    oText.value = newValue;
}
g:image and g:text objects can also be added to the gadget DOM by declaring them in the gadget HTML file:
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=Unicode" />
    <link href="css/Graphic.css" rel="stylesheet" type="text/css" />
    <script language="javascript" src="js/graphic.js" type="text/javascript"></script>
</head>
<body>
<g:background 
id="imgBackground" 
src="images\background.png">
<g:text id="txtTest" blur="20">test</g:text>
<g:image id="imgTest" src="images\aerologo.png"/></div>
</g:background>
</body>
</html>
Note   This method does not expose the objects as g:image or g:text elements. You can locate and assign the objects using the document.getElementById("...") method, but the g:image or g:text methods and properties are not available.

The GIMAGE Protocol

This protocol is useful for adding images to the gadget DOM more efficiently than the standard HTML <img> tag. This efficiency results from improved thumbnail handling and image caching (it will attempt to use thumbnails from the Windows cache if the requested size is smaller than 256 pixels by 256 pixels) when compared with requesting an image using the file:// or http:// protocols. An added benefit of the gimage protocol is that any file other than a standard image file can be specified as a source, and the icon associated with that file's type is displayed.
Note   When the gimage protocol is specified, the requested file must be on the local machine and must not contain a server reference.
Despite its name, the gimage protocol is unrelated to the g:image element. The image, or associated icon, is returned as a bytestream and, as such, is not exposed to gadget script as a g:image element. However, the <img> object is still a member of the gadget DOM and is exposed through standard JScript members.
function findGIMAGE()
{
    var oGIMAGE = document.getElementById("imgGIMAGE");
    
    // Get a standard JScript <img> object property.
    var srcValue = oGIMAGE.src;
    
    // Undefined G:IMAGE property.
    var opacityValue = oGIMAGE.opacity;
}

...

<img id="imgGIMAGE" 
src="gimage:///C:\Users\user\AppData\Local\Microsoft\Windows Sidebar\Gadgets\SDK_Graphic.gadget\js\graphic.js" />

Sizing

As stated previously, one of the benefits of the gimage protocol is enhanced thumbnail handling and image sizing. Typically, you would supply the image height and width as a querystring appended to the src attribute value or as an inline style.
// --------------------------------------------------------------------
// Add an image to the gadget DOM using the gimage protocol.
// --------------------------------------------------------------------
function addGIMAGE()
{
    var heightWidthLoad = "?width=25&height=25";
    var oImage = document.createElement("img");
    oImage.src = "gimage:///" + System.Gadget.path + "\\images\\aerologo.png" + heightWidthLoad;
    oImage.id = "imgGIMAGEx";
    document.body.appendChild(oImage);
}

// --------------------------------------------------------------------
// Switch an image using the gimage protocol.
// --------------------------------------------------------------------
function switchGIMAGE(file)
{
    // Specify the height, width, and interpolation method.
    imgGIMAGE.style.height = 25;
    imgGIMAGE.style.width = 25;
    imgGIMAGE.style.msInterpolationMode = "bicubic";
    imgGIMAGE.src = "gimage:///" + System.Gadget.path + "\\images\\aerologo.png";
}

<!--
Specify gimage details from script.
-->
<img id="imgGIMAGE" src="images/blank.png" height="0" width="0" />

If only one of the height and width is specified, the image is scaled proportionally; if neither the height or width is specified, the image is scaled proportionally to 120 pixels by 120 pixels. In either case, any unfilled areas are rendered as transparent.


Similar posts : 

Developing a Gadget for Windows Sidebar Part 1

The first of three overviews that describe how to create a basic gadget for the Windows Sidebar. In this overview, we demonstrate a simple "Hello World" gadget and the steps required to install and display it in the Sidebar.
  • Introduction
  • The Files
  • The Steps
  • The Example
  • For Further Reference

Introduction

Gadgets are lightweight HTML and script-based applications that provide the abillity to derive and present information or functionality from a variety of sources, such as local applications and controls, or websites and services. Developers with experience authoring webpages will find the process of creating a gadget very familiar.

The Files

A basic gadget consists of two files:
  1. Gadget.xml - The manifest, an XML file that contains general configuration and presentation information for the gadget.
  2. name.html - An HTML file, where name is specified in the <name> tag of the associated gadget manifest, that provides the shell for the gadget UI and contains the core functionality for the gadget.
Important  
It is highly recommended that all gadget HTML and script files be saved with UTF-8 character encoding.
The following steps can be taken to ensure the encoding of these files:
  1. Open the file in Notepad.
  2. On the File menu, click Save as...
  3. In the Save as dialog box, confirm that the value in the Encoding drop-down is UTF-8.
If the value in the Encoding drop-down is not UTF-8:
  1. In the Encoding drop-down, select UTF-8.
  2. Click Save to overwrite the existing file.
Repeat this process for all gadget HTML and script files.
A more robust gadget implementation may require other files not detailed here. For the purposes of this overview, however, the discussion is limited to these two core files.

The Steps

In general, the steps for creating a gadget are:
Create a development folder to contain the gadget files. It is generally good practice to give the development folder the same name as the gadget it hosts, with the added extension of .gadget. For example, if your gadget's name is "Test" then the development folder should be named "Test.gadget". This reduces naming confusion later when it comes time to install the gadget. However, the development folder can have any name you wish.
Similarly, the development folder can be located anywhere. However, during development and testing it is typically more efficient to place the folder in one of the system folders associated with the Sidebar:
  • %USERPROFILE%\AppData\Local\Microsoft\Windows Sidebar\Gadgets (for user gadgets)
  • %SYSTEM_ROOT%\Program Files\Windows Sidebar\Gadgets (for global gadgets)
The following image shows a gadget development folder in the %USER_DATA%\Local\Microsoft\Windows Sidebar\Gadgets folder.

  1. Create the manifest file and save it to the development folder. For more information on the gadget manifest, see Gadgets for Windows Sidebar Manifest.
    <?xml version="1.0" encoding="utf-8" ?>
    <gadget>
      <name>SDK Shell</name>
      <version>1.0.0.0</version>
      <hosts>
        <host name="sidebar">
          <base type="HTML" apiVersion="1.0.0" src="Shell.html" />
          <permissions>Full</permissions>
          <platform minPlatformVersion="1.0" />
        </host>
      </hosts>
    </gadget>
    
    
    
  2. Create the core .html file and save it to the development folder.
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=Unicode" />
        </head>
        
        <body>
            <div id="gadgetContent">
            </div>
        </body>
    </html>
    
    
  3. Install the gadget, if necessary. Depending on where you created your development folder, you may need to copy the folder or its content to one of the two previously identified Sidebar system folders. Alternatively, you may want to package the gadget for general distribution and test the gadget installation process. For more information on installing and updating a gadget, see Gadgets for Windows Sidebar Updating and Refreshing.
  4. Test the gadget and make revisions as necessary.

The Example

The following is a step-by-step example for creating a simple "Hello World" gadget.
  1. To open the Sidebar, click the Start button, point to All Programs, then to Accessories, and then click Windows Sidebar. You can also click the Start button, click Run..., and then type "sidebar" in the Open text field and press ENTER.
  2. Locate and open your gadgets folder. Click the Start button, and then click Run.... In the Open text box, type: %USERPROFILE%\AppData\Local\Microsoft\Windows Sidebar\Gadgets
  3. In your Gadgets folder, create a new folder named HelloWorld.gadget.
  4. Copy and paste the following code into Notepad or a similar editor that allows you to create an HTML file. Name the file HelloWorld.html, and save it in your HelloWorld.gadget folder.
    Important  If font information is specified for the gadget UI in HTML or Cascading Style Sheets (CSS), the font size must be included and it must be an absolute measure in pixels.
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=Unicode" />
            <title>Hello World</title>
            <style type="text/css">
            body
            {
                margin: 0;
                width: 130px;
                height: 75px;
                font-family: verdana;
                font-weight: bold;
                font-size: 20px;
            }
            #gadgetContent
            {
                margin-top: 20px;
                width: 130px;
                vertical-align: middle;
                text-align: center;
                overflow: hidden;
            }
            </style>
            <script type="text/jscript" language="jscript">
                // Initialize the gadget.
                function init()
                {
                    var oBackground = document.getElementById("imgBackground");
                    oBackground.src = "url(images/background.png)";
                }
            </script>
        </head>
     
        <body onload="init()">
            <g:background id="imgBackground">
                <span id="gadgetContent">Hello World!</span>
            </g:background>
        </body>
    </html>
    
    
  5. Create a new folder called images under the HelloWorld.gadget folder.
  6. Create a new background image at least 130 pixels wide and 75 pixels high and save it to the images folder.
  7. Create the gadget manifest by copying and pasting the following code into a new file. Save this file with the file name gadget.xml and UTF-8 encoding.
    <?xml version="1.0" encoding="utf-8" ?>
    <gadget>
      <name>SDK Hello World</name>
      <version>1.0.0.0</version>
      <author name="Microsoft">
        <info url="msdn.microsoft.com" />
      </author>
      <copyright>&#169; Microsoft Corporation.</copyright>
      <description>"HelloWorld" Sidebar gadget sample.</description>
      <hosts>
        <host name="sidebar">
          <base type="HTML" apiVersion="1.0.0" src="HelloWorld.html" />
          <permissions>Full</permissions>
          <platform minPlatformVersion="1.0" />
        </host>
      </hosts>
    </gadget>
    
    
    
  8. Click the "+" symbol at the top of the Sidebar to display the Gadget Gallery.


    9. In the Gadget Gallery, the "SDK Hello World" gadget should be visible.
    10. To install the gadget in the Sidebar, double-click the icon for the "SDK Hello World" gadget or drag and drop it to the Sidebar.
    Note  
    Unlike a standard Windows icon, a gadget icon is nothing more than a Web-based image file (.gif, .jpg, or .png). The image can be created using Microsoft Paint or similar image editing tool. If a custom icon isn't specified in the manifiest, Sidebar provides a generic icon for the gadget.
    When creating custom icons, it is recommended that they be 64 pixels wide by 64 pixels high. The gadget picker reserves a space of that size and resizes the icon accordingly. 

    Similar posts :