Windows 批处理文件启动带有按钮的 gui
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34867023/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows Batch file launch a gui with buttons
提问by Zombie Waffles
How can I create a window with multiple buttons in which do not go away apon clicking them. I'm trying to make a simple Windowed Box with buttons that can open programs. I've been using WBox.exe for my gui, however it closes the window before the program launches when you press any button. HTML crossed my mind, but I don't know how to make buttons or even know if it can launch a program on click.
如何创建一个带有多个按钮的窗口,单击这些按钮不会消失。我正在尝试使用可以打开程序的按钮制作一个简单的窗口框。我一直在为我的 gui 使用 WBox.exe,但是当您按下任何按钮时,它会在程序启动之前关闭窗口。HTML 出现在我的脑海中,但我不知道如何制作按钮,甚至不知道它是否可以通过单击启动程序。
回答by Aacini
You may do that in a relatively simple way via a Batch-HTA hybrid file; this is an example:
您可以通过 Batch-HTA混合文件以相对简单的方式执行此操作;这是一个例子:
<!-- :: Batch section
@echo off
setlocal
echo Select an option:
for /F "delims=" %%a in ('mshta.exe "%~F0"') do set "HTAreply=%%a"
echo End of HTA window, reply: "%HTAreply%"
goto :EOF
-->
<HTML>
<HEAD>
<HTA:APPLICATION SCROLL="no" SYSMENU="no" >
<TITLE>HTA Buttons</TITLE>
<SCRIPT language="JavaScript">
window.resizeTo(374,100);
function closeHTA(reply){
var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.GetStandardStream(1).WriteLine(reply);
window.close();
}
</SCRIPT>
</HEAD>
<BODY>
<button onclick="closeHTA(1);">First option</button>
<button onclick="closeHTA(2);">Second option</button>
<button onclick="closeHTA(3);">Third option</button>
</BODY>
</HTML>
Save this code in a file with .BAT extension. Perhaps you would need to adjust the values in window.resizeTo(374,100);
line in order to match the resolution of your screen. This example is simple enough so you may understand it even if you know nothing about .HTA files. For further details and links on this matter, see this post.
将此代码保存在扩展名为 .BAT 的文件中。也许您需要在线调整这些值window.resizeTo(374,100);
以匹配您的屏幕分辨率。这个例子很简单,所以即使你对 .HTA 文件一无所知,你也可以理解它。有关此问题的更多详细信息和链接,请参阅此帖子。
回答by npocmaka
You can dynamically set the number of the buttons with radioButtons.bat
您可以使用radioButtons.bat动态设置按钮的数量
@echo off
::call radioButtons.bat "one" "two" "three"
for /f "tokens=* delims=" %%# in ('
radioButtons.bat "one" "two" "three"
') do (
set "selected=%%#"
)
echo selected button number: %selected%