How can i make an HTA window dependent on another?

淺唱寂寞╮ 提交于 2019-12-11 08:28:54

问题


I need to make an .hta window dependent on the other .hta window. So, basically window A cannot be closed without window B being close first. I have the two window right next to each other and they act as one window when settings is click (it basically displays a popout or extension of the first window that has options for the application).

Second window is executed by:

Sub Settings()
  Set objShell = CreateObject("WScript.Shell")
  objShell.Run "Launcher-Settings.hta"
End Sub 

And the button is:

<input type="button" value="Settings" name="MSG-Button" id="LauncherSettings1" class="LauncherSetting1" onClick="Settings()" />

Both windows are close by:

<input type="button" value="<<    Close" name="CloseButton" id="CloseButton" class="CloseButton" onClick="javascript:Window.close()" />

回答1:


There's a typo in my comment, it should be "unload events are not cancelable...".

You can force window B to be closed just before closing A using WMI, something like this:

top.onbeforeunload = function () {
    var wmiLocator = new ActiveXObject('WbemScripting.SWbemLocator'),
        wmiService = wmiLocator.ConnectServer('.', 'root\\CIMV2'),
        htaProcesses = new Enumerator(wmiService.ExecQuery("Select * from Win32_Process Where name = 'mshta.exe'")),
        htas = [], n;
    while (!htaProcesses.atEnd()) {
        if (htaProcesses.item().CommandLine.indexOf('Launcher-Settings.hta') > -1) {
            htas.push(htaProcesses.item());
        }
        htaProcesses.moveNext();
    }
    for (n = 0; n < htas.length; n++) {
        htas[n].Terminate();
    }
    return;
}


来源:https://stackoverflow.com/questions/22138092/how-can-i-make-an-hta-window-dependent-on-another

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!