HTA文件保存对话框而不是打开对话框 [英] HTA file save dialog instead of open dialog

查看:145
本文介绍了HTA文件保存对话框而不是打开对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用文件输入来打开保存对话框而不是打开对话框。这将允许用户给出输出位置。在我的应用程序。

我的HTA代码是

 < html> 
< head>
< title> HTA Test< / title>
< HTA:APPLICATION
ID =objTest
APPLICATIONNAME =HTATest
SCROLL =yes
SINGLEINSTANCE =yes
> ;

< script>
function sync()
{
var InputTextbox = document.getElementById('InputTextbox');
var OutputTextbox = document.getElementById('OutputTextbox');
OutputTextbox.value = InputTextbox.value;
}
< / script>

< / head>

< SCRIPT LANGUAGE =VBScript>

Sub TestSub
Set Shell = CreateObject(WScript.Shell)
Shell.runh:\ tools \ffmpeg\bin\ffmpeg.exe - 我& InputTextbox.Value& & OutputTextbox.Value
End Sub

< / SCRIPT>



< body bgcolor =buttonface>
< p>< font face =verdanacolor =red> VOB to MP4 Converter< / font>< / p>
< p>
输入:< input type =filename =InputTextboxsize =30>< P>
输出:< input type =textname =OutputTextboxsize =30
>< font>请将文件扩展名更改为所需格式< / font>< br>

< / p>
< / body>

提前感谢

解决方案

没有本机Windows脚本宿主界面的另存为对话框从我读过的。我发现生成对话框最简单的方法就是从.NET中借用。 PowerShell很容易与.NET对象一起使用。这里有一个批量/ PowerShell混合脚本,它将打开另存为对话框,强制扩展一个.mp4:


$ b

 <$ c $ > 
@exit / b
:结束批处理/开始PowerShell#$批处理部分
@powershell -noprofileiex($ {%〜f0} | out- >
add-type -as System.windows.forms
$ save = New-Object Windows.Forms.SaveFileDialog
$ save.initialDirectory = $ pwd.path
$ save.filter =MP4文件(* .mp4)| * .mp4
$ save.ShowHelp = $ true
[void] $ save.ShowDialog()
$ save.filename

考虑到这一点,您可以将脚本写入%temp%并使用 Shell.Exec()为了捕获HTA中的STDOUT脚本功能。脚本完成后,可以删除临时批处理文件。请参阅以下示例中的 saveDlg()函数。 $ b

 < HTML> 
< head>
< title> HTA Test< / title>
< HTA:APPLICATION
ID =objTest
APPLICATIONNAME =HTATest
SCROLL =yes
SINGLEINSTANCE =yes
> ;
< / head>

< textarea style =display:noneid =save_bat>
@#批处理部分
@powershell -noprofile -window隐藏iex($ {%〜f0} | out-string)
@exit
:结束批处理/开始PowerShell#>
add-type -as System.windows.forms
$ save = New-Object Windows.Forms.SaveFileDialog
$ save.initialDirectory = $ pwd.path
$ save.filter =MP4文件(* .mp4)| * .mp4
$ save.ShowHelp = $ true
[void] $ save.ShowDialog()
$ save.filename
< / textarea的>

< script language =JavaScript>
函数saveDlg(){
var fso = new ActiveXObject(Scripting.FileSystemObject),
shell = new ActiveXObject(WScript.Shell),
temp = shell。 Environment(Process)(temp),
batfile = fso.createTextFile(temp +\\save.bat,true),
saveLoc;

batfile.write(document.getElementById(save_bat).value);
batfile.close();

var proc = shell.Exec(temp +\\save.bat);
while(!proc.Status&&!saveLoc){
saveLoc = proc.StdOut.ReadLine();
proc.Terminate();
}
fso.DeleteFile(temp +\\save.bat,1);
返回saveLoc;


函数goBabyGo(){
var shell = new ActiveXObject(Wscript.Shell);
shell.run(h:\\ tools \\ffmpeg \\\\\\\\\\\\\\\\\\ $
+ document.getElementById(InputTextbox)。值
+''
+ document.getElementById('OutputTextbox')。value
);
}
< / script>

< body bgcolor =buttonface>
< p>< font face =verdanacolor =red> VOB to MP4 Converter< / font>< / p>
< p>
输入:< input type =fileid =InputTextboxsize =30/>
< / p>
< p>
输出:< input type =textid =OutputTextboxsize =30readonly />
< button onclick =document.getElementById('OutputTextbox')。value = saveDlg()>另存为...< / button>
< / p>
< p>
< input id = runbutton type =buttonvalue =转换! name =run_buttononClick =goBabyGo()/>
< / p>
< / body>
< / html>


I want to use a file input to open a save dialog instead of a open dialog. This will allow the user to give output locations. in my application.

My HTA code is

<html>
<head>
<title>HTA Test</title>
<HTA:APPLICATION 
     ID="objTest" 
     APPLICATIONNAME="HTATest"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>

<script>
function sync()
{
  var InputTextbox = document.getElementById('InputTextbox');
  var OutputTextbox = document.getElementById('OutputTextbox');
  OutputTextbox.value = InputTextbox.value;
}
</script>

</head>

<SCRIPT LANGUAGE="VBScript">

    Sub TestSub
        Set Shell = CreateObject("WScript.Shell")
        Shell.run "h:\tools\ffmpeg\bin\ffmpeg.exe -i "& InputTextbox.Value & " " & OutputTextbox.Value
    End Sub

</SCRIPT>



<body bgcolor="buttonface">
<p><font face="verdana" color="red">VOB to MP4 Converter</font></p>
 <p>
    Input : <input type="file" name="InputTextbox" size="30"><P>
    Output: <input type="text" name="OutputTextbox" size="30"
    ><font>Please change file extention to required format</font><br>

    <input id=runbutton  type="button" value="Convert!" name="run_button"  onClick="TestSub">
</p>
</body>

Thank in Advance

解决方案

There's no native Windows Scripting Host interface for the "Save As" dialog from what I've read. Easiest way I've found to produce the dialog is to borrow from .NET. PowerShell works with .NET objects pretty easily. Here's a Batch / PowerShell hybrid script that will open the Save As dialog, forcing a .mp4 extension:

<# : batch portion
@powershell -noprofile "iex (${%~f0} | out-string)"
@exit /b
: end batch / begin PowerShell #>
add-type -as System.windows.forms
$save = New-Object Windows.Forms.SaveFileDialog
$save.initialDirectory = $pwd.path
$save.filter = "MP4 files (*.mp4)|*.mp4"
$save.ShowHelp = $true
[void]$save.ShowDialog()
$save.filename

With this in mind, you can write the script to %temp% and execute it using Shell.Exec() in order to capture the STDOUT within your HTA script functions. Once the script is completed, the temporary batch file can be deleted. See the saveDlg() function in the following example.

<html>
<head>
<title>HTA Test</title>
<HTA:APPLICATION 
     ID="objTest" 
     APPLICATIONNAME="HTATest"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>
</head>

<textarea style="display: none" id="save_bat">
<# : batch portion
@powershell -noprofile -window hidden "iex (${%~f0} | out-string)"
@exit
: end batch / begin PowerShell #>
add-type -as System.windows.forms
$save = New-Object Windows.Forms.SaveFileDialog
$save.initialDirectory = $pwd.path
$save.filter = "MP4 files (*.mp4)|*.mp4"
$save.ShowHelp = $true
[void]$save.ShowDialog()
$save.filename
</textarea>

<script language="JavaScript">
function saveDlg() {
    var fso = new ActiveXObject("Scripting.FileSystemObject"),
        shell = new ActiveXObject("WScript.Shell"),
        temp = shell.Environment("Process")("temp"),
        batfile = fso.createTextFile(temp + "\\save.bat", true),
        saveLoc;

    batfile.write(document.getElementById("save_bat").value);
    batfile.close();

    var proc = shell.Exec(temp + "\\save.bat");
    while (!proc.Status && !saveLoc) {
        saveLoc = proc.StdOut.ReadLine();
        proc.Terminate();
    }
    fso.DeleteFile(temp + "\\save.bat", 1);
    return saveLoc;
}

function goBabyGo() {
    var shell = new ActiveXObject("Wscript.Shell");
    shell.run("h:\\tools\\ffmpeg\\bin\\ffmpeg.exe -i "
        + document.getElementById("InputTextbox").value
        + ' '
        + document.getElementById('OutputTextbox').value
    );
}
</script>

<body bgcolor="buttonface">
<p><font face="verdana" color="red">VOB to MP4 Converter</font></p>
 <p>
    Input : <input type="file" id="InputTextbox" size="30" />
</p>
<p>
    Output: <input type="text" id="OutputTextbox" size="30" readonly />
    <button onclick="document.getElementById('OutputTextbox').value = saveDlg()">Save As...</button>
</p>
<p>
    <input id=runbutton type="button" value="Convert!" name="run_button"  onClick="goBabyGo()" />
</p>
</body>
</html>

这篇关于HTA文件保存对话框而不是打开对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆