Gadget creation program for windows 7. Creating your own gadgets

The guide below is based on preview versions new operating system from Microsoft Corporation - Windows Vista. This means that some features of gadget creation may change or may not be included in the final product due to marketing, technical or other reasons. We will make every effort to update this article if such changes occur.

Brief introduction to Microsoft gadgets
Windows Vista includes many new features, and one of the most needed and most anticipated is undoubtedly the Windows Sidebar. Sidebar is an area of ​​the screen that is reserved specifically for gadgets in the same way as the panel was previously made quick launch- especially for important shortcuts. Gadgets are miniprograms, they take up little space and can do nothing more. less than that, what the creator realizes in them. For example, Windows Vista now includes several gadgets: a small calculator, a program RSS readers ribbons and a couple of others. It won't take you long to understand how convenient it is to use gadgets.

But let's be honest: the world is filled with things that not all people can do. But with the advent of gadgets, the situation changes radically. This is what makes gadgets really interesting to us: new technologies were developed for people who write scripts. Don't get us wrong: yes, gadgets can have cutting-edge interfaces and perform some very complex tasks, but they still turn out to be nothing more than miniature HTML pages containing small code VBScript (including WMI code) or Java Script. A little effort and you will make your first gadget.

Learning to develop in any programming language is not as difficult as it might seem. For example, in this video https://itvdn.com/ru/video/php_start you can easily study PHP basics and then write your first code.

Let's start creating
Many people have criticized Microsoft for the fact that many of the corporation's products were apparently designed for use by robots or the inhabitants of the planet Omicron IV; in any case they were not designed for human use. Now such expressions have no place, because Everyone can create gadgets. Although, if you suddenly are a robot or an inhabitant of the planet Omicron IV, rest assured that you can easily create a gadget.

To create a gadget, you only need two things:

1) Manifest file named Gadget.xml. This file contains all the settings for your device, including the gadget name, author and copyright information, information about HTML page, which makes up the actual code for the gadget.
2) HTML file (for example, Test.htm). Gadgets are really nothing more than HTML files. You simply create an HTML file, add the appropriate tags and code, and you will see the gadget.
Yes, we know that you have no idea what we mean by "relevant attributes and code". Relax; this is the focus of the rest of the article.
This is the only thing required to create a gadget. But we also need graphic file, for example icon.png. This will be the logo of your gadget.

From theory to practice
1. Place all files in the gadget folder.
Attention: place all the files in the folder and you will receive a gadget. No compilation required, no .95 compilers, nothing more tedious or technical. Simply copy files to the specified folder.
Just in case you suddenly want to send us .95, we will be very happy :).

Special folder for gadgets
First, let's go to the folder with pre-installed gadgets from Microsoft.
Press Windows + R and in the window that appears, enter:

%userprofile %\appdata\local\microsoft\windows sidebar\gadgets

Note: if you are using Windows Sidebar, ported to Windows XP from Windows Vista build 5342, downloaded from the site then enter:

%program files%\Windows Sidebar\Gadgets

Still with us? Great. Next comes the long-awaited practice/
In this folder create new folder. Give this folder any name, but be sure to include .gadget at the end of the name (for example, Test.gadget). Obviously, it will be more convenient for you if the name of the folder has some similarity with the functions of the gadget. However, the operating system simply uses this folder to identify the files contained within it; The gadget name will be derived from the information found in the gadget.xml file, not from the folder name.

All you have to do now is create the Gadget.xml and Test.htm files in the folder. This means that you now have a Microsoft gadget.

gadget.xml file
This file is written in XML language, you can immediately guess this because of the .xml extension. In fact, gadget.xml is a special manifest file, but at the same time simple text file, which contains the gadget configuration.
Here's the gadget.xml code we're referring to (use it first):


My First Gadget
The Microsoft Scripting Guys
2006 Microsoft Corporation
Sample gadget that returns the name of the installed operating system.

icon.png



html
full
test.htm


Before you ask me, is it possible to just copy this file and use it in to a large extent as is - yes, only by doing necessary changes in several tags. (And don't forget, you must name the file Gadget.xml.)
These are the tags:


The name of the gadget that appears in the Add Gadgets dialog box.


The name or nickname of the person who wrote the gadget. You will see the author, copyright, and description of the gadget in the add gadgets window


Brief description of the gadget (what it does, etc.).


Name of the image file (gadget logo). For more information, see Creating a Logo in the next subsection of this document.


Probably not the most intuitive tag name in the world, but it is the name of the HTML file that makes up your gadget.


Well, no comments here. Gadget developer website.

For people who have not yet fully understood the gadget.xml code, here is a complete Russian translation of this file (when creating gadgets, use only the gadget.xml file on English language):



My First Gadget
The Microsoft guys
2006 Microsoft Corporation
An example of a gadget.xml file that returns the name of the installed operating system.

icon.png



html
full
test.htm
www.microsoft.com/technet/scriptcenter

t;

html
full
test.htm
www.microsoft.com/technet/scriptcenter

Creating an icon
Of course, you decide what the gadget logo will be, but if you do not want to create an image (in the gadget.xml file, do not fill in the tag), and Windows Sidebar will provide you with a default image. Absolutely free.

If you do decide to make a logo, keep in mind that the "icon" is just a name, given to the file with image; these are not true windows images, and the graphics that must be created using a special software(the translator sincerely and with the best intentions recommends using great app MSPAINT.EXE, which has been included with Windows since 1994 to create the logo). The logo is only an image file in GIF, JPG, or PNG format. All logos of Microsoft gadgets included in Sidebar are made in PNG format; this is probably because PNG graphics allow for transparency, giving you the ability to make very beautiful pictures. (You will, of course, have the necessary talent.) However, you can use JPG files. They are significantly smaller in size than PNG, but decide for yourself, because... it all depends on the specific situation.
Good question: what size should your logo be? Optimal size- 64x64 pixels. Larger files such as 128x128 will be downsized by Sidebar to 64x64 with possible loss of quality.

For example, here is the icon we used:

Mark. You may have noticed that, in the gadget.xml file, the tag is nested inside the tag:


icon.png

This means that you can add additional images to the gadget.xml file, although to be honest, we're not sure what you would use the other additional images for.

HTML file
The HTML file that makes up the gadget itself is actually no different from any web page that uses dynamic HTML; to create HTML simply use any valid HTML markings (including CSS styles) plus script code. We will show you a sample HTML page. Before we do that, let's take a quick look at the WMI code.

Working with WMI
If you System Administrator, then you are used to writing scripts that use WMI. This is understandable, after all, WMI is a technology that helps you manage everything from printers, disk drives to mice and monitors. Using WMI is very convenient. For example, suppose you want to know the name of the operating system installed on your local computer. No problem; Here's the WMI code that will return this information for you:

StrComputer = "."

Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\cimv2")

For Each objItem in colItems
Msgbox objItem.Caption
Next

If you are planning to create gadgets for system administration, then we have bad news for you: the WMI scripts that you are used to writing will not work in gadgets. (Wait, don't do anything drastic, we will try to fix this problem, we promise.) Because, at heart, a gadget is nothing more than a Web page, and, due to security reasons, Web pages are not able to use GetObject . If you put the previous code into the gadget, you will see this error message:

ActiveX component cannot create object: 'GetObject'

Hmm yeah.
But don't panic. You can still use WMI code within the gadget; You just can't use GetObject and winmgmts. Instead, you must use CreateObject to create a WbemScripting.SWbemLocator object, then use the ConnectServer method to connect to the WMI service. In other words, this is what you should write as a result:

StrComputer = "."

Set colItems = objWMIService.ExecQuery("Select * From Win32_OperatingSystem")

For Each objItem in colItems
Msgbox objItem.Caption
Next

It's clear? As we said, there is no reason to panic. (Although, in all fairness, it was probably our fault that you panicked at first) / The only difference is between a script that directly uses WMI and a script that uses ConnectServer to connect to the WMI service in the connection. You're used to making a connection that uses a single line of code:

Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\cimv2")

Now you must use two lines of code to make the connection (yes, doubling your workload!) You create a WbemScripting.WbemLocator object, and use the ConnectServer method to contact the WMI service. Note that we pass two parameters to ConnectServer - this is the name of the computer to connect to, represented by the strComputer variable and the WMI namespace we want to connect to in this case root\cimv2):

Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objLocator.ConnectServer(strComputer, "root\cimv2")

Do you understand? Fine. Now let's get back to our planned topic.

Creating an HTML File
As we've already noted, the gadget is just an HTML file. This means that any elements, including dynamic ones, you can use in the HTML page can also be used in the gadget. Since you've probably already figured out that the gadget also composes VBScript code; Although most of the early gadgets on the Microsoft Gadgets Website are made in JavaScript, it is easier to work with VBScript in the beginning than with Java Script.

We've already shown you the WMI code that returns the name of the operating system installed on the computer; let's see if we can turn that code into a gadget. We will start very simple, creating a device that consists of a single button, when clicked on it we will see the name of the operating room in a message box. Here is the HTML code for our first gadget:


My First Gadget


body(width:120;height:160)

Sub RunSub
strComputer = "."

Set objLocator = CreateObject("WbemScripting.SwbemLocator")
Set objWMIService = objLocator.ConnectServer(strComputer, "root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * From Win32_OperatingSystem")

For Each objItem in colItems
Msgbox objItem.Caption
Next
End Sub



As you can see, there is nothing complicated about this code; it's rudimentary HTML that doesn't do much more than display a single button on the page. When the button is clicked, the subroutine called RunSub is executed; This routine uses WMI to determine the name of the operating system installed on the computer.

Mark. Okay, maybe this is basic HTML for some people, but what if you have nothing to do with HTML? Then read the HTML documentation, believe me, learning HTML is very easy. Pay special attention to the sections devoted to tags and .

The only tag we need to make a special note on is the . As we begin to create more complex gadgets, we will discuss the tag in detail; for now, however, we'll just specify that we use this tag to form the height and width of our gadget:


body(width:120;height:160)

This tag simply says that we want our gadget to be 120 pixels wide (the Windows Sidebar itself is about 130 pixels wide) and 160 pixels high. For this particular gadget, 160 pixels in length will be too much, so we can simply assign a custom length, for example 50 pixels:


body(width:120;height:50)

Agree, this gadget looks much better.

When you click on the Run button, a window appears telling us the version of the operating system!

Relax or show off to your friends by telling them about your gadget.

Showing data in a tag
So far we have created a simple gadget, and besides, it only works when we click on a button. There is nothing wrong with this, and there will probably be times when your gadget will return so much information that it will only fit in the message box. Internet window Explorer, or some other location. On the other hand, sooner or later you will also create a gadget where displaying information in a message window does not make sense, and clicking a button will be unnecessary. For example, suppose you decide to create a clock for the Windows Sidebar. Imagine knowing what time it is every time you press a button, and at the same time the time will pop up in a message box. Surely the planet Omicron IV loves such things. But people find it a bit tedious, not to mention downright stupid.

In other words, we need the ability to create gadgets that can:
1) Show data directly within the boundaries of the gadget.
2) Display data automatically, without requiring user interaction with the gadget.
3) Update information periodically. For example, a gadget that shows free RAM computer (we will create such a gadget later) must constantly update information.

It won't be easy to figure it out right away, so we'll learn these skills one at a time. Let's first look at the first point using a tag - simple and easy way show information directly within the boundaries of the gadget.

Here is a revised version of our HTML file. In this new gadget, you still click the Run button to call the RunSub routine, however, this time the name of the operating system will not appear in a message box, but within the boundaries of the gadget.


My First Gadget

body(width:120;height:160)

Sub RunSub
strComputer = "."

Set objLocator = CreateObject("WbemScripting.SwbemLocator")
Set objWMIService = objLocator.ConnectServer(strComputer, "root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * From Win32_OperatingSystem")

For Each objItem in colItems

Next
End Sub





Everything works as we wanted. Cool!

Added bonus: a first-class gadget background
Let's talk more about creating fancy-looking gadgets. We'll tell you a few simple methods creating such a gadget. Why is this necessary? The gadget will look original and you will be able to sell it for more money :). For example, let's say you have a picture (let's call it background.jpg) that will good background for a gadget. In this case, all you have to do is insert the following line into your HTML file after the tag:

This code forces the background.jpg file to be used as the gadget's background:
Just make sure that background.jpg is saved in your gadget folder.

Alternative. You can create a gadget with a different background color; just now after the tag insert this line:

Will we get a gadget with a bright red background? Hey, why not?

Finally, you can do gradient background for your gadget when using one of Microsoft's Web Filters. Here's what we'll change in the style of this gadget:
1) Let's make the font white, specifically Arial 8pt.
2) Add a gradient filter.

Here's the finished code:


My Gadget

body(width:120;height:160;font:8 pt Arial;color:white;
filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=1, StartColorStr="#000000",
EndColorStr="#0000FF"))

Sub RunSub
strComputer = "."
Set objLocator = CreateObject("WbemScripting.SwbemLocator")

Set colItems = objWMIService.ExecQuery("Select * From Win32_OperatingSystem")
For Each objItem in colItems
DataArea.InnerHTML = objItem.Caption
Next
End Sub



Of course, what we got is not a work of art, but it looks better than a white rectangle.

Creating a gadget that displays data automatically
Having a gadget that displays information within its borders rather than in a message box is certainly good. However, we still have to click the button to get the information. Of course there must be a way to collect information automatically and display it immediately when the gadget is loaded.

Don't argue, friends, there really is a way.
Well, according to established tradition :) the code of our gadget, which will show the name of the installed operating system without clicking on the button:


My First Gadget

body(width:120;height:160)

Sub Window_OnLoad
RunSub
End Sub

Sub RunSub
strComputer = "."

Set objLocator = CreateObject("WbemScripting.SwbemLocator")
Set objWMIService = objLocator.ConnectServer(strComputer, "root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * From Win32_OperatingSystem")

For Each objItem in colItems
DataArea.InnerHTML = objItem.Caption
Next
End Sub



It's easy to see that this code is very similar to our previous one. In fact, there are only two differences:
1) We have removed the button from the gadget. This means that you no longer have to click the button (though there is nothing else to click).
2) We added the Window_OnLoad subroutine.

Many people know that the Window_Onload routine included in a Web page is designed to control the loading or refresh time of a Web page. This subroutine functions in exactly the same way in our gadget: it automatically controls the time when it is loaded. We simply create a subroutine called Window_OnLoad and place the code we want to control below.

For this particular gadget, our Window_OnLoad routine looks like this:

Sub Window_OnLoad
RunSub
End Sub

You can see everything we do in this subroutine - the second subroutine request: RunSub. We placed our WMI code in a separate routine, although it was possible to place the WMI script in the Window_OnLoad routine. So why did we create a second extra routine? It's simple: this will help us easily move on to creating the next gadget.

Creating a gadget that will periodically update information
A gadget must be useful, otherwise, why is it needed? You can implement a lot in a gadget useful features. With the combination of small code sizes and the ability to use graphics, you can create incredible useful tools to monitor your network or computer. We will make a gadget that will show us the free RAM of the computer. Of course, it will be a gadget with constantly updated information. As a result, you should get something similar to this code:


My Gadget

body(width:120;height:40")

Sub Window_Onload
GetMemory

End Sub

Sub GetMemory
Set objLocator = CreateObject("WbemScripting.SwbemLocator")
Set objWMIService = objLocator.ConnectServer(".", "root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_OperatingSystem")
For Each objItem in colItems

Next
End Sub



Before we discuss how this gadget works, we note that it does not show the name of the operating system installed on the computer. Why didn't we make an example of defining a computer's operating system? We believe that monitoring available memory might be a little more realistic than monitoring the name of the installed operating system.

Routine for determining the current amount of available memory (routine named GetMemory):

Sub GetMemory
Set objLocator = CreateObject("WbemScripting.SwbemLocator")
Set objWMIService = objLocator.ConnectServer(".", "root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_OperatingSystem")
For Each objItem in colItems
DataArea.InnerHTML = objItem.FreePhysicalMemory
Next
End Sub

But we are more interested not in the GetMemory subroutine, but in the Window_OnLoad subroutine:

Sub Window_Onload
GetMemory
iTimerID = window.SetInterval("GetMemory", 10000)
End Sub

You will notice that we are doing two things in this subroutine. First, we run the GetMemory subroutine - this is to ensure that after loading our gadget, the available memory will be immediately shown. The second thing we do is a little more interesting:
iTimerID = window.SetInterval("GetMemory", 10000)

Here we use the SetInterval method to create a timer. This timer will run the GetMemory routine every 10 seconds (10,000 milliseconds). This is how we force the gadget to automatically update the information: every 10 seconds the gadget runs the GetMemory routine, which means that after 10 seconds the gadget will use WMI to get the current amount of available memory and then display this data in the body of the gadget. If 10 seconds is too much for you, change the 10000 parameter to a smaller number, for example, the number 5000 will cause the gadget to update data every 5 seconds (5000 milliseconds). Likewise, changing 10000 to larger number, the update interval will be longer.

We never said it was a work of art. But now that you understand the basics of creating gadgets (gadgets are especially interesting to system administrators), we hope you will create works of art. In the next part we will talk about merging graphics with gadgets and many new useful features.

Finally - " Homework". Next comes a little (emphasis on the word a little) more complex gadget code that does two things: it controls available memory and also when the Information button is clicked, it shows in the Web page detailed information about the system. Needless to say, this gadget is not an example of all the capabilities of gadgets, but the example does show you the range of abilities that can be included in one gadget at the same time. Here's the actual code:

Translator's note: Attention, when I saved this code and launched the gadget (I did this in Windows XP with a ported Sidebar from build 5342), the system froze and I had to re-translate half of the article! So be careful. Although I think this won't happen in the original Sidebar from Windows Vista, I haven't tested it! After the code there are additional links on the topic.


My Gadget

body(width:120;height:80)

Sub Window_Onload
GetMemory
iTimerID = window.SetInterval("GetMemory", 10000)
End Sub

Sub GetMemory
Set objLocator = CreateObject("WbemScripting.SwbemLocator")
Set objWMIService = objLocator.ConnectServer(".", "root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_OperatingSystem")
For Each objItem in colItems
DataArea.InnerHTML = objItem.FreePhysicalMemory
Next
End Sub

Set objLocator = CreateObject("WbemScripting.SwbemLocator")
Set objWMIService = objLocator.ConnectServer(".", "root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * From Win32_ComputerSystem")
For Each objItem in colItems
strHTML = "Computer Name: " & objItem.Name & "
"
strHTML = strHTML & "User Name: " & objItem.UserName & "

"
Next

Set colItems = objWMIService.ExecQuery("Select * From Win32_OperatingSystem")
For Each objItem in colItems
strHTML = strHTML & " Operating System: " & objItem.Caption & "
"
strHTML = strHTML & " Service Pack: " & objItem.ServicePackMajorVersion & "

"
Next

Set colItems = objWMIService.ExecQuery("Select * From Win32_Processor")
For Each objItem in colItems
strHTML = strHTML & "Processor: " & objItem.Caption & "

"
Next

Set colItems = objWMIService.ExecQuery_
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem in colItems
strHTML = strHTML & objItem.Caption & "
"
For Each strAddress in objItem.IPAddress
strHTML = strHTML & "IP Address: " & strAddress & "
"
Next
Next

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
objIE.Toolbar = 0
objIE.StatusBar = 0
Set objDoc = objIE.Document.Body
objDoc.InnerHTML = strHTML
objIE.Visible = True
End Sub



AppWidget, or simply “widget”, is one of the most impressive and convenient user interface elements in the operating room Android system, which can be added to the desktop for quick access to certain functions of the corresponding application. In this article we will figure out how to create your own widget.

What is a widget structurally? A widget is needed to display certain information related to the application to which it belongs, or to quickly interact with this application directly through the desktop. The simplest example is a clock on a desktop. Naturally, widgets can be easily added or removed from desktops.

High-quality widgets significantly optimize interaction with the device. Moreover, very often the most convenient widgets take up the least space on the desktop, and at the same time are the most informative. Almost any user will try to place on the desktop of his Android gadget maximum amount information, and important point is that space is limited.

Let's start creating the widget with the design. Fortunately, Google has provided very useful UI Guidelines for software developers, which describe in detail the design creation process and the basic principles of ergonomics. There is also a separate official instructions for creating widgets, which can be found at the link: http://developer.android.com/guide/practices/ui_guidelines/widget_design.html.

A widget that occupies one “cell” on the desktop has a resolution of 80x100 pixels, respectively, to create an oblong widget 4 cells long and one cell high, you need, respectively, 320x100 pixels. We will take this size as the basis for the widget we create.

Now the widget needs to be drawn. In principle, a widget may well not have any graphic part, and display only text or controls, without a background or frame, but, naturally, a beautiful and pleasing to the eye widget simply must have a high-quality design. So let's draw the background. Let's take the background from the above-mentioned UI Guideline as a basis. Open the template available to us in Photoshop or another graphic editor and do whatever we want, after which we save the resulting image in .png format. The format we need is PNG-24, with 8-bit color and transparent background. So the basis for our widget is ready.

Now let's move on to creating the software part. The widget may not have a software part. Simply put, it will be in the add widgets menu, but not in the main application menu. We will create exactly this type of widget. We create new project, and for convenience we call it so that the main class is named widget.java.

Editing AndroidManifest. xml. We declare our widget:

Now let's edit widget.java. Here you need to describe how the widget will react to various conditions. The AppWidgetProvider class has the following methods:

onUpdate – the method is called when the widget is created, as well as after a specified time. Time is set in configuration file of this widget. Note that it is used most often.

onDeleted – the method is executed when a widget is deleted from the desktop.

onEnabled – the method is called when the widget is activated for the first time. But if another exactly the same widget is added, this method no longer executed.

onDisabled – the method is executed when it is removed latest copy widget from the desktop. Accordingly, this method is the reverse of onEnabled.

onReceive – the method is called simultaneously with all others. Often not used at all.

Go deep into software part We won’t create a widget, and therefore we won’t overfill our example with any handlers, but will simply implement all the functionality using Layouts. You must declare the AppWidgetProvider class as follows:

package com.example.widget;

import android.appwidget.AppWidgetProvider;

public class widget extends AppWidgetProvider(

}

Next, we describe our widget - this is necessary in order to mobile device understood what he was dealing with. To do this you need to create a folder xml in folder res. In it we create a file with the name widget_ info. xml. Open the created file and write the following code into it:

Let's give short description specified parameters:

minWidth – the minimum width required for the widget to work.

minHeight – the minimum height required for the widget to work.

updatePeriodMillis – the period during which the widget is updated, specified in milliseconds. The parameter is very useful, since after the specified time period has passed, the onUpdate method of the AppWidgetProvider object is triggered.

initialLayout – the parameter points to a resource describing the interface of our widget.

The formula for calculating the size of a widget is as follows: (number of cells * 74) - 2.

Let's start describing the interface of the widget we are creating. This is where the previously created background comes in handy. Import the background image into the folder dwawable(or in all three folders drawable for different screen resolutions). In folder layout create a file named widget. xml. The interface is described as for regular Activity, but there are some limitations. The following elements are allowed for use:

Let's create a LinearLayout, to which we will apply the created background image and add AnalogClock for example. The watch itself won’t fit into the frame, but how? clear example will do just fine. So:

That's basically it. After installing the widget on your Android device or emulator, you can install it on one of your desktops. After adding, we will contemplate the following.

Recently I needed to create a gadget for Windows Sidebar. I didn’t have any skills in this, so after googling a little and reading the documentation, let’s get started.

I'll show you what I ended up with right away.


The gadget will receive information from the site in xml form, parse and, in fact, display. The gadget will also check for new versions, and if they are present, refuse to work :)
Initially, for the sake of gaining experience, I wanted to write a gadget entirely in VBScript (since I had not dealt with it yet), but in the end I had to make inserts in JavaScript.
Let's move directly to the code. I will not review the entire code here, I will only show the main points. The link to the finished gadget is at the end of the article.
The main file of a gadget is its manifest - the Gadget.xml file. It should be called exactly that and located in the root of our archive (the gadget is nothing more than ZIP archive with extension .gadget).

Weather from Info.Denms.Ru 1.0.1232 Full Weather Widget (Info.Denms.Ru)

Let's look at it in more detail.
The element must contain an apiVersion equal to 1.0.0 (at this moment), and src attribute, which indicates main file our gadget;
Permissions for the gadget. Set equal to full;
Minimum version of Windows Sidebar. Currently – 1.0;
Parameters - gadget name, - version, - information about the author, - link to the page with the gadget, - gadget icon and will be displayed on the panel of installed gadgets.

The main.html file is normal html file, I will not give it in full, I will only dwell on some points.
The g:background element is used to set the background of the gadget. Let's make it transparent.

The gadget can be in two states – docked (on the left in the screen above), and undocked (on the right). We will store the current state of the gadget in JavaScript variable docked.

We will need the isDocked wrapper function in the future to find out the current state of the gadget from VBScript (no matter how hard I tried, I couldn’t implement this in pure VBScript). One more note - the scripts work correctly in this order, i.e. First we describe VBScript scripts, then JavaScript.

The remaining elements in main.html are presented DIV elements with absolute positioning. Subsequently, from scripts we will access them by their id.

WITH using JavaScript let's set the docked and undocked states for the gadget, and also specify the settings file (main.js)

System.Gadget.onDock = resize; System.Gadget.onUndock = resize; System.Gadget.settingsUI = "settings.html"; System.Gadget.onSettingsClosed = SettingsClosed; docked=0; //initial state of the gadget resize(); //initialization

As you can see from the listing above, when the gadget states change, the resize() function will be called.

Function resize() ( bd = document.body.style; System.Gadget.beginTransition(); if (System.Gadget.docked) ( // small state bd.width=148; // set the gadget size bd.height=201 ; docked = 1; bd.background="url(images/gadget.png) no-repeat"; //set the background //then follows the transfer of values ​​from the undocked state to docked and zeroing the elements for the undocked state document.getElementById("small_needupdate ").innerHTML = document.getElementById("big_needupdate").innerHTML; document.getElementById("big_needupdate").innerHTML = ""; //... ) else ( // big state bd.width=230; bd. height=160; bd.background="url(images/gadgeth.png) no-repeat"; docked=0; //transfer values ​​from docked to undocked and reset elements for docked state document.getElementById("big_needupdate"). innerHTML = document.getElementById("small_needupdate").innerHTML; document.getElementById("small_needupdate").innerHTML = ""; //... ) System.Gadget.endTransition(System.Gadget.TransitionType.morph,1); )

You can also describe the function of saving settings. My gadget doesn’t have them, but as an example I’ll show you how it’s done.

Function SettingsClosed(event) ( if (event.closeAction == event.Action.commit) ( //alert System.Gadget.Settings.readString("test"); ) )

ReadString – reads a previously saved string, writeString, respectively, writes.
Methods System.Gadget.beginTransition(); and System.Gadget.endTransition(); needed for “smooth” resizing of the gadget. IN Windows Seven they are ignored, but I still left them for backward compatibility.

As mentioned above, the server provides us with weather information in xml format.

1.7 41 cloudy snow 87 South-West 5 -3 -1 -1 26 1 -9 41 0 …

We will download and parse xml using VBScript.

Sub DownloadXML2 Set objXML = CreateObject("Microsoft.XmlHttp") objXML.Open "GET", "http://info.kovonet.ru/weather.xml", True objXML.OnReadyStateChange = GetRef("objXML_onreadystatechange") objXML.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" objXML.Send iTimeoutID = window.SetTimeout("mySleep", 1000) End Sub

The mySleep function will check our connection for a timeout.

Sub mySleep if bRespReceived = "false" then "response not yet received iTimeout = iTimeout + 1 if (iTimeout > 30) then "timeout timerFirstRun = window.SetTimeout("Update", 60000) "attempt re-update in a minute else "the timeout has not yet been reached, we continue to count the seconds iTimeoutID = window.SetTimeout("mySleep", 1000) end if end if End Sub

If the download is successful, objXML.readyState will be equal to four, and status (objXML.status) will return the value 200.

Function objXML_onreadystatechange() If (objXML.readyState = 4) Then "msgbox objXML.statusText If (objXML.status = 200) Then bRespReceived=true SaveFile(objXML.responseText) else timerFirstRun = window.SetTimeout("Update", 60000) " attempt to update again in a minute End If End If End Function

In this case, save the file to a temporary Windows folder

Function SaveFile(what) Set fso = CreateObject("Scripting.FileSystemObject") tempFolder = fso.GetSpecialFolder(2) filepath = tempFolder+"\weather.xml" Dim fso1, tf Set fso1 = CreateObject("Scripting.FileSystemObject") Set tf = fso1.CreateTextFile(filepath, True, True) "rewrite, unicode tf.Write(what) tf.Close ParseXML End Function

And we begin to parse the file.

Sub ParseXML Set fso = CreateObject("Scripting.FileSystemObject") tempFolder = fso.GetSpecialFolder(2) filepath = tempFolder+"\weather.xml" Set xmlDoc = CreateObject("Msxml2.DOMDocument") xmlDoc.async="false" xmlDoc. load(filepath) "main node - in our case Set currNode = xmlDoc.documentElement "days of the week - Set dayNode = currNode.firstChild While Not dayNode Is Nothing Set currNode = dayNode.firstChild While Not currNode Is Nothing if currNode.parentNode.getAttribute( "id") = "today" then "today if currNode.nodeName = "temp" then document.getElementById(prefix+"maintemp").innerHTML = currNode.childNodes(0).text+Chr(176) "display the remaining elements Else "not today, display more finely"... end If Set currNode = currNode.nextSibling Wend Set dayNode = dayNode.nextSibling Wend End Sub

Checking for new versions is done in exactly the same way.
Don't forget to create a settings file - settings.html, the existence of which we announced above.

Settings

That's all, actually. I would be glad if my (first :)) article was useful to someone.

Used sources.

Gadgets (Widgets) are one of the most controversial features in a windowed OS. Some users install them and don’t even imagine how they can fully use their PC without their help. Others don’t even know what it is, and cope quite successfully. Are there gadgets for Windows 10, what are they and how to install them? We will discuss the answer to these questions in detail later in the article.

Why did widgets disappear from Windows 10?

With the arrival of first 8 and then the tenth version, this issue was resolved because Microsoft decided to completely remove the function from the system for some reasons:

  • As unnecessary. A big emphasis in the new systems has been on live tiles, which, in some ways, work the same way as widgets. They display useful information, are updated in real time and look more relevant;
  • For security reasons. Here the developers, rather, said without any particular reason. Because it is hard to imagine that such a small component of the system as a widget can greatly influence security, and parts of its code can be used by attackers. Although this may have affected performance. You can check this by returning the functionality and .

Now gadgets for Windows 10 cannot be found on the official website.

However, there are no more widgets and the reasons are given. Most users simply agreed and started using tiles, but there are also those who do not want to deprive themselves of such a convenient opportunity and wondered how to install gadgets on Windows 10. For their sake, we tried third party developers, who have created software that copies the functionality of widgets as closely as possible and tells you how to install gadgets on the desktop in Windows 10.

How to install gadgets on your desktop Windows table 10 using 8GadgetPack programs
  • Media center;
  • Movie Maker;
  • .NetFramework;
  • DirectX 9 versions and much more.

It is likely that, by rummaging around on the Internet, you can find other lesser-known solutions, but is this necessary, given that the ones described above allow you to return the functionality that was in 7 and even more.

If you are looking for ways to remove gadgets on Windows 10, then this is done by adding them to the OS.

Basic Steps

Here are some basic steps when creating and placing gadgets.

  • Create a gadget specification in text editor, and then save it to a public web server.
  • Add the gadget to a container, for example iGoogle or Orkut. Container is an application or website that gadgets can perform.
  • Gadget structure

    Once you understand how to modify and publish gadgets, you can begin to include more advanced features in gadget specifications. The gadget XML specification consists of 3 main parts.

    • Contents section. The section is where the real work of your gadget happens. Here you should indicate the type of gadget, programming logic, and often HTML elements that determine its appearance.
    • User settings. The section defines functions that give users the opportunity to choose gadget settings. For example, in a gadget personal greeting there may be a text field in which users should indicate their name.
    • Gadget settings. A section of the XML file specifies the characteristics of the gadget (for example, name, author, preferred size, etc.).

    When creating a gadget, you should start with the section.

    Content Definition

    The section represents the “brain” of the gadget. A section defines the type of content and contains the content itself or links to external content. A section is a place where gadget attributes and custom settings are combined with programming logic and formatting information into a working gadget.

    The simplest way create a gadget - simply place HTML (and possibly JavaScript or Flash) in the section. Experienced web developers can read about other access control options, remote hosting, use of other scripting languages ​​and much more. Here is a simple example of a gadget. This gadget contains a photo that you need to click to open the photo album on new page HTML:

    Defining custom settings

    Some gadgets should allow users to enter information about themselves. For example, a gaming gadget may support input of a preferred difficulty level. The user settings () section of the XML file provides input fields user information, which appear in the interface of the user who launched the gadget. User settings are saved permanently.

    For example, in this gadget, the personal greeting changes depending on the time of day. In this case, users can provide the following information.

    • The name used in the greeting. This name is also written in the title line.
    • Background color.
    • Do I need to show a photo?

    Here's what the gadget looks like when the user clicks edit to change user settings:

    In the specification XML format controls are defined in the interface of the included gadget, which are responsible for user settings.





    Please note the following:

    Here's the entire gadget, along with the JavaScript code that displays the welcome text for the gadget.

    For a list of attributes, see .

    Custom settings can be called from your gadget using special JavaScript APIs, for example:

    var prefs = new gadgets.Prefs(); var someStringPref = prefs.getString("StringPrefName"); var someIntPref = prefs.getInt("IntPrefName"); var someBoolPref = prefs.getBool("BoolPrefName");

    List of all JavaScript functions see in.

    Variable Substitution for Custom Settings

    You can use variable substitution of the format __UP_ userpref __ in sections or where userpref matches the name of the Customizing attribute. After launching the gadget string value the corresponding custom setting is substituted for the variable, without translation. For example, in this snippet, the user-supplied run-time value for the projects custom setting is substituted for __UP_projects__ in the title_url line:

    Below is a general guide to using variable substitution for custom settings.

    • For the title attribute use __UP_ name __. This translated to HTML.
    • For title_url attribute use __UP_ name __. This translated to HTML.
    • In HTML in section use __UP_ name __. This is translated into HTML.
    • IN JavaScript code in the section, use the gadgets.Prefs() function.
    Sharing user settings

    Using the shareable-prefs function, you can give multiple users the ability to change gadget settings. This way, users can share the gadget and see who changed what. For example, family members can have a common gadget with a shopping list and each person can add their favorite products. User settings data is part of the gadget state stored on iGoogle. additional information about custom settings can be found in .

    In order for a gadget's custom settings to be shared among multiple users, the gadget must contain a line in the section. For example, this gadget uses a custom setting with to populate a shopping list:

    Here is the gadget code:

    ]]>

    By adding a gadget that supports sharing settings to iGoogle, you can make it available to sharing in the following way.

    Step 1: Click the triangle on the gadget you want to share sharing, and select Share this gadget.

    Step 2: If you use Gmail, select the friends you want to share the gadget with or enter their email addresses.

    Step 3: Decide whether friends can edit the gadget's content or only view it on their iGoogle pages.

    • When you select View and edit content, friends will be able to edit the gadget's custom settings. Their changes will be reflected in your version of the gadget and in all other shared versions of that gadget.
    • If you select View content, friends will not be able to change both the gadget itself and its copies on own pages. Only you can change the gadget, and your changes will be applied to all shared versions of the gadget.

    Click Send invitations. Friends will receive an email from you inviting them to add the gadget to their iGoogle pages.

    Friends you allow to modify a gadget can edit custom settings and publish changes to all shared versions of the gadget.

    Defining gadget settings

    A section of the XML file specifies the characteristics of the gadget (for example, name, author, preferred size, etc.). For example: