Reputation: 199
How to minimize window?
I am making HTA application and I want replace window title bar with my custom one. I've disabled it by HTA's "caption=no" option and placed my own minimize/maximize/close buttons.
I found two ways to minimize window:
So I could send this shortcuts to window using WScript.Shell's SendKeys method.
WsShell = new ActiveXObject("WScript.Shell")
WsShell.SendKeys("% n")
But the first one can't be used because there is no title bar, and the second because WinKey doesn't work with SendKeys.
I found MinimizeAll() method of Shell.Application, but it's alone.
Is there any other way to minimize the window? May be another activeX object or shortcut?
Upvotes: 4
Views: 2608
Reputation: 4116
I came up with exact the same issue. This is the solution that worked for me:
Place in the <head> section:
<object id="HHCtrlMinimizeWindowObject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<param name="command" value="minimize" />
</object>
<script type="text/javascript">
function _jsMinWin( ) {
try {
HHCtrlMinimizeWindowObject.Click( );
}
catch ( err ) {
alert( err.message );
}
}
</script>
Then on <body> section something like:
<input type="button" value="Minimize Window" name="MinimizeWindow" id="MinimizeWindow" onclick="javascript:_jsMinWin();" />
Upvotes: 3
Reputation: 170
Well, you can use Tasks property of Microsoft Word Application object. First instantiate Microsoft Word Application object by passing the ProgID "Word.Application" to the new ActiveXObject
command:
var word = new ActiveXObject("Word.Application");
Then, find your HTA window among the Tasks collection:
var win = word.Tasks.Item(document.title);
As you can see, you should pass the title of your HTA to the Item method to find your HTA's window. But there is a problem... What if an another unwanted window has the same title as your HTA? This leads to a window confusion. To work around this problem, I recommend you to set a special and unique title for your HTA before you find your HTA window among the Tasks collection. This complicates things:
document.title = "window" + Math.random();
win = word.Tasks.Item(document.title);
document.title = "My HTA";
Please note that you should set your own desired title after you find your HTA window. Also note that this code should run when window.onload
event occurs. Because that's when your HTA generates its window.
Then, whenever you need to minimize your HTA window, set the WindowState
property of win
object to 2
:
win.WindowState = 2;
Edit: On the other hand, this way has two disadvantages:
1. It runs properly provided that the user has Microsoft Office Word installed on his computer.
2. Instantiating Microsoft Word Application object takes a few seconds because this object runs in an out-of-process server. So this may slow down your HTA.
Upvotes: 1
Reputation: 101616
If the Microsoft scripting guy doesn't know how to do it then it might not be possible.
Even if you could go all the way around with ActiveXObject("shell.application").Windows.Item(x)
and get your own InternetExplorer object, there doesn't seem to be a way to minimize yourself programmatically.
My only suggestion is to use something like for (var k in obj) WScript.Echo(k)
on every window related object you can get your hands on and look for undocumented methods/properties...
Upvotes: 1