Reputation: 6675
Which is the preferred development language for Windows 7 gadgets?
I know that a gadget uses Xml, Html, CSS and Script(Java/VB) but I need some advanced features such as:
For the above tasks, I will need to use the Windows API or, if possible, .NET. Is it possible to have the above features in a Gadget?
Upvotes: 2
Views: 2973
Reputation: 344537
There are various COM objects available to JScript using the ActiveXObject
class. You can write your own interop assembly using .NET but this introduces several problems:
If you decide you really need to write an assembly. I would advise that if you are writing your own assembly for a gadget that it is an extension to the basic functionality of your gadget and that you ensure the gadget has features available should the user be unable to use the assembly.
My company has an as-of-yet unreleased solution to the above issues which we are planning on making available to all Windows Desktop Gadget developers in the near future (ie after more testing).
As for the advanced features you specified, these can all be done using some built-in Windows COM objects, which are already registered and aren't distributed with your gadget so they don't suffer the same issues noted above. As an answer to your specific requirements, examples of these are:
FileSystemObject
Writing/Reading files can be done using FileSystemObject. A basic example of FileSystemObject for reading files is:
var ForReading = 1, ForWriting = 2, ForAppending = 8;
var oFSO = new ActiveXObject("Scripting.FileSystemObject");
var oFile = oFSO.OpenTextFile(System.Gadget.path+"\\test.txt", ForReading, true);
var sText = oFile.ReadAll();
window.prompt("", sText);
Windows Management Instrumentation (WMI)
WMI has an enourmous range of purposes. Certain parts of it will require administrative rights, though (which must be applied to sidebar.exe). One of the classes within WMI is Win32_Process which can be used to iterate through running processes. Note that it's much more difficult to use WMI in JScript than it is in VBScript and most examples you find on the internet are for VBScript (which makes porting the code a pain).
Windows Script Host Shell The WshShell Object provides another great extension to the limitations of Windows Desktop Gadgets, including the SendKeys method. Although the method cannot be used to send a key to an application specifically, it's possible to activate the application with the AppActivate method and then use SendKeys to emulate keystrokes in the activated application.
I hope that helps :-)
Upvotes: 4