.HTA Secrets Revealed (of course, free of charge :)
Covered in this blog: chromeless HTA window drag, minimize, launching Window’s default browser and using JavaScript and VBScript in the same document.
Section 1 of 4
Various pieces of following information contain code and material discovered to work across all current versions of Windows as of February 2010. While some snippets are pseudo hacks and function properly as described, there isn’t any documentation from Microsoft about future support.
In 2009 I delved deep into the uncharted territory of chromeless HTAs, pushing it’s application powers to the limit. In the beginning stages of design I noticed that there were a few items of functionality unavailable to the HTA. The first one I noticed was the inability to window drag a chromeless HTA. Surely I had to be mistaken. Nonetheless, anyone running into the ‘access denied’ error while attempting to write a drag function knows full well where I’m coming from. After a little investigation it’s not hard to find that for security purposes, Microsoft has disabled such functionality. After further investigation, I noticed that the Internet’s popular HTA apps didn’t have the traditional mousedown / drag / release feature in their windows. Instead, they all had awkward work-arounds. Better yet, I couldn’t find a single instance of a chromeless HTA with a MINIMIZE button, nor access to the platform’s default browser. While I initially assumed this to be the case, I declined to believe it until I could prove it.
After countless hours of research and testing, I verified what I had previously refused to believe. Still desirous of harnessing the power of the HTA, I decided to spend some quality time on real, viable solutions to these issues.
As any decent developer worth his salt knows, the best solution is always the simplest one. Complex work-arounds rarely function smoothly in the end. Below is the smooth and correct way to implement these functionalities into your HTA.
.HTA Window MINIMIZE Instructions
Download example, documentation and instructions
[http://www.quio.me/_devbin/minimize.zip]
Download example, documentation and instructions
[http://www.quio.me/_devbin/minimize.zip]
1. Create the following object just before the closing </body> tag of the document you wish to be able to minimize:
<object Id="MyObj" CLASSID="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<param NAME="command" VALUE="minimize">
</object>
2. Create a JS function to reference the object
function minWin(){
MyObj.Click();
};
3. Create an element with an onclick event (click, up or down):
<span onmouseup="minWin()">
Click to minimize this window
</span>
<object Id="MyObj" CLASSID="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<param NAME="command" VALUE="minimize">
</object>
2. Create a JS function to reference the object
function minWin(){
MyObj.Click();
};
3. Create an element with an onclick event (click, up or down):
<span onmouseup="minWin()">
Click to minimize this window
</span>
Notes:
One of the most fascinating aspects of this set of code is that it’s undocumented (until now). From the Scripting Guy [http://blogs.technet.com/heyscriptingguy/], to the ends of the Internet; while I was researching how to minimize a chromeless HTA, I continually ran into dead ends. Not only was I told by various sources that it was impossible, all the reasonable work-arounds didn’t fit any respectable programmers mantra of the simplest solution being the right solution.
The key to this solution is the inherent minimize Windows CLSID [WIKI link: http://en.wikipedia.org/wiki/CLSID], ubiquitous throughout Microsoft’s OS functionality. Why this isn’t more widely disseminated, I’ll never know. It’s seemingly obvious to anyone in need.
Testing: I’ve found the code, in this example, to work on every Windows version to date; from Win98 – Win7.
While the above code is relatively small in scale, it entails several days of investigation and know-how. If this helps you, your staff, or others complete a project, please feel free to donate to the cause.
One of the most fascinating aspects of this set of code is that it’s undocumented (until now). From the Scripting Guy [http://blogs.technet.com/heyscriptingguy/], to the ends of the Internet; while I was researching how to minimize a chromeless HTA, I continually ran into dead ends. Not only was I told by various sources that it was impossible, all the reasonable work-arounds didn’t fit any respectable programmers mantra of the simplest solution being the right solution.
The key to this solution is the inherent minimize Windows CLSID [WIKI link: http://en.wikipedia.org/wiki/CLSID], ubiquitous throughout Microsoft’s OS functionality. Why this isn’t more widely disseminated, I’ll never know. It’s seemingly obvious to anyone in need.
Testing: I’ve found the code, in this example, to work on every Windows version to date; from Win98 – Win7.
While the above code is relatively small in scale, it entails several days of investigation and know-how. If this helps you, your staff, or others complete a project, please feel free to donate to the cause.
Stay tuned for our next blog on chromless HTA window drag…(due Monday 03/01/10)