Then, I saw this request in SO site where the user wants to show something similar to a part of a web page and "get input" from it into a Batch file. I remembered that "HTA files are similar to web pages" and that is possible to write a Batch-HTA hybrid script, so I googled for this topic and found this MS site that explains the details about .HTA files. After some research I wrote the program below that, in my opinion, is the first useful example of a Batch-HTA hybrid script.
Code: Select all
<!-- :: 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>
Code: Select all
<!-- :: 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 Radio Buttons</TITLE>
<SCRIPT language="JavaScript">
window.resizeTo(440,170);
var reply = "No button selected";
function closeHTA(){
var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.GetStandardStream(1).WriteLine(reply);
window.close();
}
</SCRIPT>
</HEAD>
<BODY>
<p>Which prize do you prefer?</p>
<label><input type="radio" name="prize" onclick="reply=this.value" value="House">House</label>
<label><input type="radio" name="prize" onclick="reply=this.value" value="Money">$1 million</label>
<label><input type="radio" name="prize" onclick="reply=this.value" value="None">No prize thanks, I'm already happy <b>:)</b></label>
<br><br>
<button onclick="closeHTA();">Submit</button>
</BODY>
</HTML>
I wrote the text file below in order to subdivide the image in parts using the format allowed by my TextToHtml.bat program (http://www.dostips.com/forum/viewtopic.php?f=3&t=5016):
Code: Select all
=
[img border="0"]Inicio.png
[url="1,1"]rect=0,0,252,124[/url]
[url="1,2"]rect=252,0,508,124[/url]
[url="1,3"]rect=508,0,636,124[/url]
[url="1,4"]rect=636,0,760,124[/url]
[url="2,1"]rect=0,124,252,252[/url]
[url="2,2"]rect=252,124,508,252[/url]
[url="2,3"]rect=508,124,636,252[/url]
[url="2,4"]rect=636,124,760,252[/url]
[url="3,1"]rect=0,252,252,380[/url]
[url="3,2"]rect=252,252,508,380[/url]
[url="3,3"]rect=508,252,760,380[/url]
[url="4,1"]rect=0,380,252,504[/url]
[url="4,2"]rect=252,380,508,504[/url]
[url="4,3"]rect=508,380,760,504[/url]
[/img]
Code: Select all
<!-- :: Batch section
@echo off
setlocal EnableDelayedExpansion
set i=0
for %%a in ("Escritorio Calendario Explorer Tienda"
"Correo Fotos Mapas SkyDrive"
"Contactos Finanzas Deportes"
"Mensajes ElTiempo Noticias") do (
set /A i+=1, j=0
for %%b in (%%~a) do (
set /A j+=1
set "option[!i!,!j!]=%%b"
)
)
cls
echo Get options from an image subdivided in rectangular areas.
:nextOption
echo/
for /F "delims=" %%a in ('mshta.exe "%~F0"') do set "HTAreply=%%a"
echo Option selected: "!option[%HTAreply%]!"
if "%HTAreply%" equ "4,3" goto endProg
pause
goto nextOption
:endProg
echo End of example
goto :EOF
-->
<HTML>
<HEAD>
<HTA:APPLICATION SCROLL="no" SYSMENU="no" >
<TITLE>Select an option ("Noticias" to end)</TITLE>
<SCRIPT language="JavaScript">
window.resizeTo(802,576);
function closeHTA(reply){
var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.GetStandardStream(1).WriteLine(reply);
window.close();
}
</SCRIPT>
</HEAD>
<BODY>
<map name="map2">
<area shape="rect" coords="0,0,252,124" onClick="closeHTA('1,1')">
<area shape="rect" coords="252,0,508,124" onClick="closeHTA('1,2')">
<area shape="rect" coords="508,0,636,124" onClick="closeHTA('1,3')">
<area shape="rect" coords="636,0,760,124" onClick="closeHTA('1,4')">
<area shape="rect" coords="0,124,252,252" onClick="closeHTA('2,1')">
<area shape="rect" coords="252,124,508,252" onClick="closeHTA('2,2')">
<area shape="rect" coords="508,124,636,252" onClick="closeHTA('2,3')">
<area shape="rect" coords="636,124,760,252" onClick="closeHTA('2,4')">
<area shape="rect" coords="0,252,252,380" onClick="closeHTA('3,1')">
<area shape="rect" coords="252,252,508,380" onClick="closeHTA('3,2')">
<area shape="rect" coords="508,252,760,380" onClick="closeHTA('3,3')">
<area shape="rect" coords="0,380,252,504" onClick="closeHTA('4,1')">
<area shape="rect" coords="252,380,508,504" onClick="closeHTA('4,2')">
<area shape="rect" coords="508,380,760,504" onClick="closeHTA('4,3')">
</map>
<img border="0" usemap="#map2" src="Inicio.png" name="img1">
</BODY>
</HTML>
These are just a couple examples of the use of this technique. The method may be used in a simpler way and with a wider range of "input form elements" if Batch/JScript/HTA routines are written in order to receive just the minimum essential parameters and then calculate all the values required to show the "input form" in a pleasant standard layout, in a way similar of the "default values + modifiers" provided by my TextToHtml.bat conversion program.
Antonio
PS - A subsequent application that makes good use of this same idea is Drawing HTA "canvas" graphics in Batch files