Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

GUI + INIwrite + FileInclude


  • Please log in to reply
9 replies to this topic
Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
Here's a ready script that will show three functions:

1. GUI (using HTA).
2. INI writing (from GUI) and utilising it in script.
3. Including another file in script (without FileInstall) and generating it during output.

Posted Image

This script does not need any outside file. It also shows a way that I've discovered, to include and generate a file from a script without using FileAppend for 'every' line (its used just once!). This method of including file will only work with uncompiled scripts... for compiled ones, use fileinstall.

SetWinDelay, 0
SetBatchlines, 10ms


; a file has been attached at the end of the script
; more files can be attached by changing 'a' to b, c ....
sec = a
Loop, Read, %a_scriptfullpath%, GUI.hta
{
	IfInString, A_LoopReadLine, %sec%*/, setenv, log, no
	IfEqual, log, yes, FileAppend, %A_LoopReadLine%`n
	IfInString, A_LoopReadLine, /*%sec%, setenv, log, yes
	
	;*/ this line is just to correct syntax highlighting
}


;now run the generated hta file
run, GUI.hta
WinWait, GUI Window
WinMove, GUI Window, ,,, 300, 300
WinWaitClose, GUI Window

;read output
IniRead, ainput, options.ini, Section, ainput
IniRead, Selection, options.ini, Section, selection
IniRead, check1, options.ini, Section, check1
IniRead, check2, options.ini, Section, check2
IniRead, check3, options.ini, Section, check3

;show output
msgbox,0, GUI output, Input = %ainput%`nSelection = %selection%`nCheckBox1 = %check1%`nCheckBox2 = %check2%`nCheckBox3 = %check3%

;cleanup
FileDelete, GUI.hta
FileDelete, Options.ini



;File sections below
;more files can be attached by changing 'a' to b, c ....

/*a
<HTML>
<HEAD>
   <TITLE>GUI Window</TITLE>

   <HTA:APPLICATION
   BORDER = "thin"
   CAPTION = "yes"
   ICON = "app.ico"
   SHOWINTASKBAR = "yes"
   SINGLEINSTANCE = "yes"
   SYSMENU = "yes"
   WINDOWSTATE = "normal"
   SCROLL = "no"
   SCROLLFLAT = "yes"
   INNERBORDER = "yes"
   SELECTION = "no"
   MAXIMIZEBUTTON = "yes"
   MINIMIZEBUTTON = "yes"
   NAVIGABLE = "no"
   CONTEXTMENU = "yes"
   BORDERSTYLE = "normal"
   >

   <STYLE>
      BODY { background:buttonface;
             border:0px }
   </STYLE>
</HEAD>

<script>
fso = new ActiveXObject("Scripting.FileSystemObject");
function ini(source){
   frm=document.main;
   Selection=frm.Selection[frm.Selection.selectedIndex].value
   if(frm.Ainput.value==""){
       alert("Please input something");
   }else if(Selection==""){
       alert("Please select something");
   }else{
       //The next line deletes original Options.ini, and creates a new one
       file=fso.CreateTextFile("Options.ini",1);
       file.WriteLine("[Section]");
       file.WriteLine("Ainput="+frm.Ainput.value);
       file.WriteLine("Selection="+Selection);
       file.WriteLine("Check1="+(frm.Check1.checked?frm.Check1.value:""));
       file.WriteLine("Check2="+(frm.Check2.checked?frm.Check2.value:""));
       file.WriteLine("Check3="+(frm.Check3.checked?frm.Check3.value:""));
       file.close();
       window.close();
   }
}
</SCRIPT>

<BODY>
<FORM ONSUBMIT="return false" NAME="main">

<p align="center"><font size="5" face="Tahoma">GUI in HTA</font></p>
<p align="center"><font face="Tahoma">Input <INPUT TYPE="text" NAME="Ainput" SIZE="10">



<SELECT NAME="Selection">
   <OPTION VALUE="">Please select
   <OPTION VALUE="1">Option1
   <OPTION VALUE="2">Option2
   <OPTION VALUE="3">Option3
</SELECT>



CheckBox1 <INPUT TYPE="checkbox" VALUE="yes" NAME="Check1" UNCHECKED>

CheckBox2 <INPUT TYPE="checkbox" VALUE="yes" NAME="Check2" UNCHECKED>

CheckBox3 <INPUT TYPE="checkbox" VALUE="yes" NAME="Check3" UNCHECKED>



<INPUT TYPE="button" VALUE="Submit" ONCLICK="ini()"> </font></p>

</FORM>
</BODY>
</HTML>
a*/

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Wow, that's amazing, especially for anyone who already knows how to script HTA things.

Maybe there's some way to use PostMessage or some of the Control commands to avoid the use of an intermediate INI file?

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
Are u testing me Chris? :D

we both know that's not a REAL window... even window spy fails to detect any control on it... its basically just a (modified) webpage!

so till now ini functions is all we have... whether with HTA or with Larry's Au3GUI that's easier for complex windows, and more advanced.

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I didn't know, it was just an idea :)

JonTheNiceGuy
  • Members
  • 22 posts
  • Last active: Oct 03 2013 01:33 PM
  • Joined: 22 Apr 2004
Forgive me for sounding stupid... how would you replace the FileAppend with FileInstall?

Thanks,

Jon

JonTheNiceGuy
  • Members
  • 22 posts
  • Last active: Oct 03 2013 01:33 PM
  • Joined: 22 Apr 2004
A hint I just picked up while tweaking this script... if you want to find the selected radio button, you can't use frm.radiogroup.value... you need to do the following...

<script>
fso = new ActiveXObject("Scripting.FileSystemObject");
function ini(source){
   frm=document.main;
   Server=frm.Server[frm.Server.selectedIndex].value
   //The next line deletes original Options.ini, and creates a new one
   file=fso.CreateTextFile("Options.ini",1);
   file.WriteLine("[Section]");
   file.WriteLine("Username="+frm.Username.value);
   file.WriteLine("Password="+frm.Password.value);
   file.WriteLine("Server="+Server);
   file.WriteLine("Task="+selectedRadioValue());
   file.close();
   window.close();
}

function selectedRadioValue()
{
	var radioButtons = document.forms[0].elements['task'];
	for (var i = 0; i < radioButtons.length; i++)
	{
		if (radioButtons[i].checked == true)
		{
			return radioButtons[i].value;
		}
	}
	return "";
}
</SCRIPT>

Hope this helps anyone :)

  • Guests
  • Last active:
  • Joined: --
i've yet to try ur script...

but to replace fileappend with fileinstall is easy... just take the section from to and put it in different file called anything.hta

then just run that instead.

u'll have to tweak the script to remove the file reading loop.... hope u can do that easily. i'd have done that but i'm short of time.

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
made that universal mistake... the above post was by me!

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Let me know if you're having any trouble with the forum's auto-logon feature (which uses cookies I believe).

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
no problem of that kind... i used another pc and forgot logging on!

:roll:

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat