The Wonderful World of Web Applications: HTML Apps (HTA) | WebReference

The Wonderful World of Web Applications: HTML Apps (HTA)

By Rob Gravelle


[next]

Just as desktop PCs all but replaced mainframes in the eighties, the web application appears to be poised to supersede the traditional desktop application...or is it? The answer may well depend on who you ask. There are those who firmly believe that web apps can never fully replace the desktop application because they can't compare in speed or appearance departments. Yet, as browsers mature and new ones are introduced, web pages are becoming far more interactive and customizable than anyone had previously imagined. Similarly, network speed has been increasing at such a rapid pace, that high quality streaming movies have already become a reality. Could we be witnessing the last throes of the desktop application? It may be a bit premature to say with any certainty, but by looking at what kind of technologies currently exist for creating cutting edge web applications, we can compare them to desktop apps and reach a conclusion as to whether or not web apps may constitute a real threat to the desktop application. Today, we'll be looking at a Microsoft contribution called HTML Apps (HTA).

The Achilles heel of web apps is their restricted permissions on the client machine. By design, any process that runs within a web browser does so with limited access permissions, as to minimize the execution of malicious code. Permission levels can be customized by the user, but they tend to be quite restrictive - especially where untrusted sources are concerned. By-and-large, read, write, and execute rights are not permitted. As web applications have gained popularity, several workarounds have been introduced by vendors. Bill Gates and company have a notable advantage over the competition because they also make the most popular operating system on the planet, that of course being Windows. It should then come as no surprise that they have introduced a means of writing web applications for Internet Explorer that can bypass the usual security restrictions. Their solution is called HTML Applications or HTA for short. It encapsulates web functionality and syntax that web developers are already familiar with, plus some HTA-specific objects that provide control over GUI design and full access to the client system. Sounds promising, to be sure!

To get better acquainted with HTAs, we'll try our hand at writing a few simple ones. Although any good HTML editor will be of great assistance in the writing of HTA files, some IDEs, such as the Antechinus® JavaScript Editor, support HTA development. As such, they can help you to create the initial page template, provide choices for attributes, perform syntax checking, preview program output, and more. Unfortunately, HTA support is found mostly in professional level products. For example, a single license for the Antechinus® JavaScript Editor goes for about $50 USD. One free tool, which I can recommend is Microsoft's HTA Helpomatic program. As if to prove the value of HTA, it is itself an HTA! While it does not produce code for you like the pro editors, it does provide code samples that you can copy and paste into your own HTAs.

Creating a Basic HTA

Running an HTA works just like any executable. Double-click the hta_helpomatic.hta file in Windows Explorer to launch the program. The HTA Elements listbox, on the left, contains a number of page components for including in your HTA. There's even a basic page template to get you started:

  • Select the "Create basic HTA" item. That will bring up a description of the selected element as well as the related HTML code and/or Subroutine (Scripting) code. The latter also brings up the code results in the "Sample" section at the bottom of the screen.
  • Click the "Copy to Clipboard" button on the right to place the code on to the clipboard and paste it in your favorite HTML editor:

Save the file without any changes with the .hta extension and run it by double-clicking the file name in Windows Explorer, just as you did with the HTA Helpomatic program. Figure 1 shows the screen at this point:

Figure 1

The only part of the document that distinguishes an HTA from a regular web page is the <HTA:APPLICATION> tag. It controls the appearance of the HTA window and is optional, as all of its attributes have default values. Here is a list of some of the more commonly-used ones:

  • Application Name: Sets the name of the HTA. This name is used to enforce the SingleInstance property, and is the name that appears in the Windows Task Manager.
  • Border: Sets the type of border used for the HTA window. Values include:
    • thick: Thick window border, plus a size grip and sizing border for resizing the window.
    • dialog: Dialog window border.
    • none: No window border.
    • thin: Thin window border with a caption.
    Thick is the default value.

  • Caption: Yes/No value specifying whether the HTA displays a caption in the title bar. The default value is Yes.
  • Icon: Sets or gets the name and location of the icon for the HTA.
  • MaximizeButton: Yes/No value specifying whether the HTA displays a Maximize button in the title bar. The default value is Yes.
  • MinimizeButton: Yes/No value specifying whether the HTA displays a Minimize button in the title bar. The default value is Yes. 
  • Scroll: Yes/No value specifying whether the HTA will scroll if returned data is larger than the window size. The default value is Yes.
  • ShowInTaskbar: Yes/No value specifying whether the HTA is shown in the Windows taskbar. The default value is Yes. 
  • SingleInstance: Yes/No value specifying whether more than one instance of this HTA can be active at a time. For this property to take effect, you must also specify an ApplicationName. The default value is Yes.
  • SysMenu: Yes/No value specifying whether the HTA displays the System menu in the title bar. The default value is Yes.
  • WindowState: Sets the initial size of the HTA window. Values are Normal, Minimize, and Maximize. By default, the WindowState is set to Normal.


[next]