10

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.

Zombie Waffles
  • 175
  • 1
  • 2
  • 12
  • 1
    This is one of the only times I will ever recommend PowerShell on a question that has the [batch-file] tag. – SomethingDark Jan 19 '16 at 01:36
  • How can I use PowerShell? and what is it? – Zombie Waffles Jan 19 '16 at 02:07
  • If you need a GUI and want to use it from some scripting environment, then [PowerShell](https://msdn.microsoft.com/en-us/powershell/mt173057.aspx) really is a viable option. It provides access to the .NET framework, including [Windows Forms](https://msdn.microsoft.com/en-us/library/dd30h2yb.aspx). Writing an [HTML Application (HTA)](https://msdn.microsoft.com/en-us/library/ms536496.aspx) may be another option. – IInspectable Jan 19 '16 at 02:07
  • @ZombieWaffles - there's way, _way_ too much information to fit in a comment, or even an answer. PowerShell is basically a replacement command line environment that Microsoft is pushing really hard to replace batch (although I've found that batch is fine unless you want to do stuff with GUIs or math involving numbers that aren't integers less than 2^32). Google "making a GUI in PowerShell" and play around with the tutorials that you find. – SomethingDark Jan 19 '16 at 02:13

2 Answers2

21

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.

Aacini
  • 65,180
  • 12
  • 72
  • 108
1

You can dynamically set the number of the buttons with 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%
npocmaka
  • 55,367
  • 18
  • 148
  • 187