Export (0) Print
Expand All
GUI
Expand Minimize

The ABCs of HTAs: Scripting HTML Applications

HTAs

Create an HTA Without a Title Bar

One of the great things about HTAs is the fact that it allows you to work in a real window: a window with a title bar, with maximize and minimize buttons, and with all the other things that make a window a window. As a scripter – previously mired in the world of Wscript.Echo statements – it’s everything you could have ever dreamed of.

On the other hand, one of the other great things about HTAs is that they give you incredible flexibility to make things look the way you want them to look. After all, there might be times when you don’t want your HTA to look like a real window; for example, you might want to remove the title bar and close buttons and all those other accoutrements:

Window Without a Title Bar


This kind of window is particularly useful for things like splash screens and progress bars; best of all, it’s also very easy to script. All you have to do is set the Caption property of your HTA to no. In other words:



<HTA:APPLICATION 
     ID="objNoTitleBar"
     APPLICATIONNAME="Window Without a Title Bar"
     SCROLL="auto"
     SINGLEINSTANCE="yes"
     CAPTION="no"
>



Of course, there is one catch here. Without a title bar – and without a close button – there’s no obvious way to get rid of this HTA; in fact, unless you add some additional coding the only way to get rid of it is to kill the mshta.exe process. If you create a window without a title bar make sure you provide some way for users to close the thing. (Or include a timer that automatically terminates the HTA after a set amount of time. For information about how to add a timer to an HTA, read “AutoRefresh an HTA Using a Timer.”)

Here’s one way close a caption-less window; this HTA code includes a subroutine named CloseWindow that will close the HTA:



Sub CloseWindow
   self.close
End Sub



So how do we execute this subroutine? Well, we could do it through a button click, but we thought we’d show you a different approach, just for the heck of it. Note the <BODY> tag in the code:



<body onkeypress='CloseWindow'>
Press any key to close this window.

</body>



As you can see, we’ve added the onkeypress event to the <BODY> tag. This simply says, “Hey, any time someone presses a key on the keyboard – any key – run the subroutine CloseWindow.” Because the CloseWindow subroutine we defined terminates the HTA that means we can dismiss the window any time we want merely by pressing any key on the keyboard. Slick, huh?

Here’s the HTA code:



<html>
<head>
<title>Window Without a Title Bar</title>
<HTA:APPLICATION 
     ID="objNoTitleBar"
     APPLICATIONNAME="Window Without a Title Bar"
     SCROLL="auto"
     SINGLEINSTANCE="yes"
     CAPTION="no"
>
</head>
<SCRIPT LANGUAGE="VBScript">

    Sub CloseWindow
       self.close
    End Sub

</SCRIPT>

<body onkeypress='CloseWindow'>
Press any key to close this window.

</body>
</html>



Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft