More free advice, perhaps worth its price:
1.) You need the
setTimeout() call because an event handler does not allow window messages (like those created when you change the
cursor style) to be processed until it completes. VB 5/6 programmers will recognize this as a place they might want to insert a DoEvents() call, but IE doesn't provide this function.
2.) You don't need to call
setTimeout as a function unless you plan to use the returned result, i.e. cancel the timer.
3.) You don't need to use the DOM to reference objects in an HTA, IE supports the DHTML Object Model as well. I.e.:
[tt]window.document.getElementById("okButtonId").click()[/tt]
... is overkill. Just use:
[tt]okButtonId.click[/tt]
Or if the button is within a form [tt]frmMain[/tt]:
[tt]frmMain.okButtonId.click[/tt]
Note: No parens follow a subroutine call either! You'll get away with this in some contexts and then it'll bite you in another. Avoid doing this.
4.) You don't need to overqualify objects. The
document object is in the global namespace:
[tt]window.document.body.style.cursor = "default"[/tt]
... is overkill, slower (though that's not too important here), and another place to make a typo. Use:
[tt]document.body.style.cursor = "default"
[/tt]
5.) Eschew <input type=button> elements. Use <button> elements instead. For a <button> element
canHaveHTML = True.
6.) Avoid JavaScript event binding where practical. VBScript event binding is faster and clearer to read, and less error-prone. Instead of:
[tt]<input id=okbutton type="button" value=" OK " name="OK_Button"
onmouseover="OK_Button.style.cursor='hand'" accessKey="o"
onClick="RunScript">[/tt]
... use:
[tt]<input id=okbutton type="button" value=" OK " name="OK_Button"
onmouseover="OK_Button.style.cursor='hand'" accessKey="o">[/tt]
... and name the event handler
okbutton_RunScript.
7.) Don't pad button caption values with blank spaces, Use the
width style with a relative value instead.
8.) Consider disabling UI elements while your long-running process is active. This provides visual feedback and avoids possible reentrancy problems (user clicking the button a second time, etc.).
AccKey.hta
Code:
<HTML>
<HEAD>
<STYLE>
.clsAccKey:first-letter {text-decoration: underline}
BUTTON {width: 15ex}
</STYLE>
<SCRIPT language=VBScript>
Option Explicit
Sub btnClick_onclick()
btnClick.disabled = True
document.body.style.cursor = "wait"
btnClick.style.cursor = "wait"
'Long delay here just to simulate a long
'running process visually for this demo.
setTimeout "HiThere", 2000, "VBScript"
End Sub
Sub HiThere()
document.body.style.cursor = "default"
btnClick.style.cursor = "default"
MsgBox "Hi There!"
btnClick.disabled = False
End Sub
</SCRIPT>
</HEAD>
<BODY>
<BUTTON id=btnClick accessKey=C class=clsAccKey>Click Me</BUTTON>
</BODY>
</HTML>
The MSDN Library (linked above) is one of the best references. Even better if you have the CD version, preferably even a 2001 edition. Even though it will be outdated in places it contains information that seems to be dropped from earlier ones.
You might also try the installable
Windows Platform SDK which has a subset "Internet Development SDK." This can also be ordered on CD for a nominal charge (in any of several versions).
I find that Visual InterDev 6.0 is still one of the best editors for writing HTAs. Though dated now (and never updated by Microsoft), it provides VBScript code colorization and Intellisense in Source View and lots of visual support in Design View as well as an easy test/debug facility in Quick View.
Some people say they've had luck using one of the .Net Express editions (VB.Net 2005? Visual Web Developer?) for editing and testing HTAs. I may have to give it a try.