Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
790 views
in Technique[技术] by (71.8m points)

user interface - Windows Batch file launch a gui with buttons

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You may do that in a relatively simple way via a Batch-HTA hybrid file; this is an example:

<!-- :: 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...