📜 ⬆️ ⬇️

Windows client-side JavaScript applications

I want to tell you about one interesting way to create JavaScript applications with native Windows GUI.

In general, there are a lot of different options for writing Windows applications in JavaScript:
  1. HTA and WSH - HTML Applications and Windows Script Host are probably the most well-known technologies. HTA is actually an HTML page with extended rights in the system - the ability to surf the web, crap into the registry, file system and connect ActiveX to these cases. With the use of HTA, many components of Windows are made.
  2. .NET Framework - this is generally on the drum, on what you write, if only the result was MSIL. Perhaps JScript.NET along with Windows.Forms can cause someone to have a sense of the native Windows interface. Personally, they do not please me at all - either visually or by speed.
  3. Mozilla's XULRunner framework offers Gecko instead of IE, XpCOM instead of COM / ActiveX. This is just over 20 megabytes of overhead.
  4. wxJavascript - the well-known cross-platform wxWidgets library is now also for JavaScript. All this thanks to the JS-engine SpiderMonkey from Mozilla and the efforts of one Belgian. By the way, the same respected - the author of mod_js for Apache.

In view of the fact that all of the above is sad, cumbersome and requires study, I propose to consider another option - WSO .

Quoting the author :
WindowSystemObject (WSO) is a universal software package for providing access to the Windows subsystem based on COM architecture, for creating window interfaces in programs written in scripting languages, as well as in programs written in other languages ​​and in other programming systems . With WSO, you can easily create window interfaces in JScript, VBScript, Perl, Python.

After these words, nothing but a huge human thanks to Alexander Borisovich Veretennikov, and you will not say.

Again a quote about WSO features:
  • WSO provides full access to all window system features, including drawing in windows and support for all built-in Windows controls.
  • WSO supports the use of any ActiveX controls, such as Internet Explorer or Windows Media Player.
  • WSO supports work with all popular graphic file formats.
  • WSO is available from any programming language that supports COM automation interfaces.
  • Access to the WSO is accomplished using the intuitive object model described in this document. Programmers familiar with window programming for Windows will quickly find that they do not need to learn anything new.
  • WSO provides full support for handling events from window elements.
  • WSO allows you to use the symbolic names of constants , adopted in windowing Windows, and not suffer with their numeric values.
  • WSO works in any modern version of Windows, namely: 98SE, ME, NT 4, 2000, XP and 2003.


All just great! Now the only thing that separates us from the native JavaScript GUI is the registration of the WSO component. As you know, Windows requires registration in the registry of COM / ActiveX components before using them. This is a serious limitation, as we need administrator rights. However, Redmond has already encountered this problem and, starting with XP SP2, it suffices to describe the interfaces of all ActiveX in a manifest application.
So, what we need to build a standalone JavaScript + WSO program:
  1. WSO.dll itself. We download and use even in commercial applications free of charge, but giving praise to Alexander Borisovich.
  2. Program code in JavaScript. Examples here .
  3. The app.exe loader , which connects MS ScriptControl to interpret JS (in fact, is an analogue of wscript.exe). You need to write it yourself or take it ready at the end of the article. In my version it is ten lines on Delphi - a copywriter from an article about ScriptControl.
  4. The application manifest app.exe.manifest is a manifest where you need to specify the dependency on the WSO component, other ActiveX components (if needed) and at the same time enable support for XP themes. Made by hand as follows:
    ')
     <? xml version = "1.0" encoding = "UTF-8" standalone = "yes"?>
     <assembly xmlns = "urn: schemas-microsoft-com: asm.v1" manifestVersion = "1.0">
     <assemblyIdentity
       type = "win32"
       name = "client"
       version = "1.0.0.0" />
       <dependency>
       <! - connect WSO ->
               <dependentAssembly>
                   <assemblyIdentity
                       type = "win32"
                       name = "WSO.sxs"
                       version = "1.0.0.0" />
               </ dependentAssembly>
       </ dependency>
       <dependency>
       <! - support for skins XP ->
    	 <dependentAssembly>
    		 <assemblyIdentity
    		   type = "win32"
    		   name = "Microsoft.Windows.Common-Controls"
    		   version = "6.0.0.0"
    		   publicKeyToken = "6595b64144ccf1df"
    		   language = "*"
    		   processorArchitecture = "x86" />
    	   </ dependentAssembly>
       </ dependency>
     </ assembly>
    

  5. Manifest for WSO - WSO.sxs.manifest, describing the interfaces of the ActiveX component. This manifest is generated by the great regsvr42.exe program. It intercepts all entries that are made to the registry when the component is registered, and saves them as manifest. A similar operation must be done for all external components that you want to use.

Here's what I got: WSO_demo.zip (573 Kb) slil.ru | onlinedisk.ru | rapidshare.de .
The demo.exe loader creates a global WSO object and starts the main () function from the main.js file.
You can, of course, rename the executable (without forgetting about its manifest) and insert the icon with any resource manager.

Source: https://habr.com/ru/post/52027/


All Articles