Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
I cannot do this in a dialog since I need to prefill some fields when they get focused and the dialog procedure does not seem to handle an "on focus" event.
What I want to do is not very complex. I need to have the user enter text in MultilineBox [A]. When he gets to MultilineBox [B] (using the mouse or the TAB key), if it is empty, prefill it with the text from [A]. When he gets to [C], if it is empty, prefill it with the text from [B]. If he goes back to [B], since it already contains text, do nothing.
This can easily be done in javascript using an "onfocus" procedure. What I need is to detect that the user has just set focus on a specific MultilineBox. This does not seem to be an event that the DialogProcOptions can recognize.
With the summary of what your focus() needs to do here is my attempt simulate it with Winbatch and DHTML.
; here's a quick example to explain the basics of using DHTML. ; just run the script (it requires NO EXTERNAL FILES) and it'll ; walk you through it as it goes. ; you can then examine the coding. this doesn't cover everything ; but should get you going. there might be different ways to effect ; the same things. ; by Jay Alverson using Winbatch 2004F and MSIE 6 #DefineSubRoutine startMSIE() Browser = ObjectOpen("InternetExplorer.Application") Browser.addressbar = @FALSE Browser.statusbar = @FALSE Browser.menubar = @FALSE Browser.toolbar = @FALSE ; Browser.fullscreen = @true browser.visible = @TRUE url = "c:\RiftsPC-URL.html" ;<--- bad URL doesn't matter... browser.navigate(url) WaitForPageLoad() ; setup the document object... browserDoc = Browser.Document all = browserdoc.all Return(browser) #EndSubRoutine #DefineSubroutine WaitForPageLoad() ; assume Browser While browser.busy || browser.readystate == 1 TimeDelay(0.5) EndWhile While browser.Document.ReadyState != "complete" TimeDelay(0.5) EndWhile return #EndSubroutine GoSub Example1 GoSub Example2 GoSub Example3 Return Exit :Example1 br = startMSIE() ; write the needed spans, inputs for the user... browserdoc.writeln(`<h2 align="center">Click button when ready</h2>`) browserdoc.writeln(`<h3 align="center">Inspect the ONCLICK property for the INPUT when you look at the script</h3>`) browserdoc.writeln(`<center><span id="ButtonSpan"><input class="bigblue" type="submit" name="DoneButton" value="Done" onclick="ButtonChoice.innerText='Button Clicked'"></span></center>`) browserdoc.writeln(`<span class="hidden" id="ButtonChoice"></span>`) ButtonChoice = all.ButtonChoice ;<--- reference the SPAN with the ID of ButtonChoice... While @TRUE Yields(2000) If ButtonChoice.innerText <> "" ;<--- stop looping when something appears in the SPAN... TimeDelay(3) ;<--- give user a few seconds to see the string "Button Clicked" appear within SPAN... Break EndIf EndWhile ObjectClose(ButtonChoice) br.quit Message("Debug", "You clicked the button, so I closed the browser") Return :Example2 br = startMSIE() ; write the needed spans, inputs for the user... browserdoc.writeln(`<style>.hidden {font-size: 1; color: white}</style>`) browserdoc.writeln(`<h2 align="center">That was nice, but lets hide the span so the user can't see it...</h2>`) TimeDelay(3) browserdoc.writeln(`<h2 align="center">Click button when ready</h2>`) browserdoc.writeln(`<center><span id="ButtonSpan"><input class="bigblue" type="submit" name="DoneButton" value="Done" onclick="ButtonChoice.innerText='Button Clicked'"></span></center>`) browserdoc.writeln(`<span class="hidden" id="ButtonChoice"></span>`) ButtonChoice = all.ButtonChoice ;<--- reference the SPAN with the ID of ButtonChoice... While @TRUE Yields(2000) If ButtonChoice.innerText <> "" ;<--- stop looping when something appears in the SPAN... Break EndIf EndWhile ObjectClose(ButtonChoice) br.quit Message("Debug", "You clicked the button, so I closed the browser") Return :Example3 br = startMSIE() ; write the needed spans, inputs for the user... browserdoc.writeln(`<style>.hidden {font-size: 1; color: white}</style>`) browserdoc.writeln(`<h2 align="center">This time you'll need to inspect the while loop in Example 3</h2>`) browserdoc.writeln(`<h2 align="center">Also look at the ONFOCUS property of TextBox1</h2>`) browserdoc.writeln(`<h2 align="center">We added another SPAN to detect when the ONFOCUS was triggered</h2>`) browserdoc.writeln(`<h2 align="center">When the INPUT box shows up make it the focus but don't type anything inside it</h2>`) TimeDelay(7) browserdoc.writeln(`<h2 align="center">Click button when ready</h2>`) browserdoc.writeln(`<center><input class="bigblue" type="text" name="TextBox1" size=10 value="" onfocus="FocusSpan.innerText='Focus'"></center>`) browserdoc.writeln(`<center><span id="ButtonSpan"><input class="bigblue" type="submit" name="DoneButton" value="Done" onclick="ButtonChoice.innerText='Button Clicked'"></span></center>`) browserdoc.writeln(`<span class="hidden" id="ButtonChoice"></span>`) browserdoc.writeln(`<span class="hidden" id="FocusSpan"></span>`) ButtonChoice = all.ButtonChoice ;<--- reference the SPAN with the ID of ButtonChoice... FocusSpan = all.FocusSpan ;<--- reference the SPAN that will hold the FOCUS flag... While @TRUE ; this time we look at both the button and the focus spans before issuing commands... Yields(2000) If ButtonChoice.innerText <> "" ;<--- stop looping when something appears in the SPAN... Break EndIf If FocusSpan.innerText <> "" FocusSpan.innerText = "" ;<--- empty the span for next loop Message("Debug", "TextBox1 has focus") EndIf EndWhile ObjectClose(ButtonChoice) ObjectClose(FocusSpan) br.quit Message("Debug", "You clicked the button, so I closed the browser") Return
Here the result of my little tests. Most of the work is done inside the page through javascript. A neat trick : the buttons and the help line are removed before printing, then brought back!
#DefineSubRoutine startmsie() browser = objectopen("InternetExplorer.Application") browser.addressbar = @false browser.statusbar = @false browser.menubar = @false browser.toolbar = @false ;Browser.fullscreen = @true browser.visible = @false url = "c:\RiftsPC-URL.html" ; <--- bad URL doesn't matter... browser.navigate(url) ;WaitForpageLoad() browserdoc = browser.document all = browserdoc.all Return(browser) #EndSubRoutine null = objecttype("NULL", "") br = startmsie() open_cell = `<TD vAlign=top width=90 height=75><FONT face=ARIAL size=4>` browserdoc.writeln(`<TITLE>DHTML demo</TITLE>`) browserdoc.writeln(`<STYLE>.hidden {font-size: 1; color: white}</STYLE>`) browserdoc.writeln(`<STYLE>.bigblue {FONT-FAMILY:Arial,Helvetica,Sans-serif;FONT-WEIGHT:Normal;FONT-STYLE:Normal;FONT-SIZE:10pt;COLOR: Blue}</STYLE>`) browserdoc.writeln(`<STYLE>input.noborder{border: 0px;}</STYLE>`) browserdoc.writeln(`<center><FONT face=ARIAL size=6>Octobre 2003</FONT><BR><BR>`) browserdoc.writeln(`<TABLE borderColor=#aaaaaa cellSpacing=0 border=1><TR>`) browserdoc.writeln(`<TD align=middle width=90><FONT face=ARIAL size=2><B>Sunday</B></FONT></TD>`) browserdoc.writeln(`<TD align=middle width=90><FONT face=ARIAL size=2><B>Monday</B></FONT></TD>`) browserdoc.writeln(`<TD align=middle width=90><FONT face=ARIAL size=2><B>Tuesday</B></FONT></TD>`) browserdoc.writeln(`<TD align=middle width=90><FONT face=ARIAL size=2><B>Wednesday</B></FONT></TD>`) browserdoc.writeln(`<TD align=middle width=90><FONT face=ARIAL size=2><B>Thursday</B></FONT></TD>`) browserdoc.writeln(`<TD align=middle width=90><FONT face=ARIAL size=2><B>Friday</B></FONT></TD>`) browserdoc.writeln(`<TD align=middle width=90><FONT face=ARIAL size=2><B>Saturday</B></FONT></TD></TR>`) browserdoc.writeln(`<TR><TD> </TD><TD> </TD><TD> </TD>`) browserdoc.writeln(strcat(open_cell, `1</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox1.value=='') {TextBox1.value=TextBox0.value};TextBox1.select()" maxLength=15 size=10 name=TextBox1></TD>`)) browserdoc.writeln(strcat(open_cell, `2</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox2.value=='') {TextBox2.value=TextBox1.value};TextBox2.select()" maxLength=15 size=10 value="" name=TextBox2></TD>`)) browserdoc.writeln(strcat(open_cell, `3</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox3.value=='') {TextBox3.value=TextBox2.value};TextBox3.select()" maxLength=15 size=10 value="" name=TextBox3></TD>`)) browserdoc.writeln(strcat(open_cell, `4</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox4.value=='') {TextBox4.value=TextBox3.value};TextBox4.select()" maxLength=15 size=10 value="" name=TextBox4></TD></TR><TR>`)) browserdoc.writeln(strcat(open_cell, `5</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox5.value=='') {TextBox5.value=TextBox4.value};TextBox5.select()" maxLength=15 size=10 value="" name=TextBox5></TD></TD>`)) browserdoc.writeln(strcat(open_cell, `6</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox6.value=='') {TextBox6.value=TextBox5.value};TextBox6.select()" maxLength=15 size=10 value="" name=TextBox6></TD></TD>`)) browserdoc.writeln(strcat(open_cell, `7</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox7.value=='') {TextBox7.value=TextBox6.value};TextBox7.select()" maxLength=15 size=10 value="" name=TextBox7></TD></TD>`)) browserdoc.writeln(strcat(open_cell, `8</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox8.value=='') {TextBox8.value=TextBox7.value};TextBox8.select()" maxLength=15 size=10 value="" name=TextBox8></TD></TD>`)) browserdoc.writeln(strcat(open_cell, `9</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox9.value=='') {TextBox9.value=TextBox8.value};TextBox9.select()" maxLength=15 size=10 value="" name=TextBox9></TD></TD>`)) browserdoc.writeln(strcat(open_cell, `10</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox10.value=='') {TextBox10.value=TextBox9.value};TextBox10.select()" maxLength=15 size=10 value="" name=TextBox10></TD>`)) browserdoc.writeln(strcat(open_cell, `11</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox11.value=='') {TextBox11.value=TextBox10.value};TextBox11.select()" maxLength=15 size=10 value="" name=TextBox11><BR></TD></TR><TR>`)) browserdoc.writeln(strcat(open_cell, `12</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox12.value=='') {TextBox12.value=TextBox11.value};TextBox12.select()" maxLength=15 size=10 value="" name=TextBox12></TD>`)) browserdoc.writeln(strcat(open_cell, `13</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox13.value=='') {TextBox13.value=TextBox12.value};TextBox13.select()" maxLength=15 size=10 name=TextBox13></TD>`)) browserdoc.writeln(strcat(open_cell, `14</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox14.value=='') {TextBox14.value=TextBox13.value};TextBox14.select()" maxLength=15 size=10 name=TextBox14></TD>`)) browserdoc.writeln(strcat(open_cell, `15</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox15.value=='') {TextBox15.value=TextBox14.value};TextBox15.select()" maxLength=15 size=10 name=TextBox15></TD>`)) browserdoc.writeln(strcat(open_cell, `16</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox16.value=='') {TextBox16.value=TextBox15.value};TextBox16.select()" maxLength=15 size=10 name=TextBox16></TD>`)) browserdoc.writeln(strcat(open_cell, `17</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox17.value=='') {TextBox17.value=TextBox16.value};TextBox17.select()" maxLength=15 size=10 name=TextBox17></TD>`)) browserdoc.writeln(strcat(open_cell, `18</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox18.value=='') {TextBox18.value=TextBox17.value};TextBox18.select()" maxLength=15 size=10 name=TextBox18></TD></TR><TR>`)) browserdoc.writeln(strcat(open_cell, `19</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox19.value=='') {TextBox19.value=TextBox18.value};TextBox19.select()" maxLength=15 size=10 name=TextBox19></TD>`)) browserdoc.writeln(strcat(open_cell, `20</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox20.value=='') {TextBox20.value=TextBox19.value};TextBox20.select()" maxLength=15 size=10 name=TextBox20></TD>`)) browserdoc.writeln(strcat(open_cell, `21</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox21.value=='') {TextBox21.value=TextBox20.value};TextBox21.select()" maxLength=15 size=10 name=TextBox21></TD>`)) browserdoc.writeln(strcat(open_cell, `22</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox22.value=='') {TextBox22.value=TextBox21.value};TextBox22.select()" maxLength=15 size=10 name=TextBox22></TD>`)) browserdoc.writeln(strcat(open_cell, `23</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox23.value=='') {TextBox23.value=TextBox22.value};TextBox23.select()" maxLength=15 size=10 name=TextBox23></TD>`)) browserdoc.writeln(strcat(open_cell, `24</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox24.value=='') {TextBox24.value=TextBox23.value};TextBox24.select()" maxLength=15 size=10 name=TextBox24></TD>`)) browserdoc.writeln(strcat(open_cell, `25</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox25.value=='') {TextBox25.value=TextBox24.value};TextBox25.select()" maxLength=15 size=10 name=TextBox25></TD></TR><TR>`)) browserdoc.writeln(strcat(open_cell, `26</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox26.value=='') {TextBox26.value=TextBox25.value};TextBox26.select()" maxLength=15 size=10 name=TextBox26></TD>`)) browserdoc.writeln(strcat(open_cell, `27</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox27.value=='') {TextBox27.value=TextBox26.value};TextBox27.select()" maxLength=15 size=10 name=TextBox27></TD>`)) browserdoc.writeln(strcat(open_cell, `28</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox28.value=='') {TextBox28.value=TextBox27.value};TextBox28.select()" maxLength=15 size=10 name=TextBox28></TD>`)) browserdoc.writeln(strcat(open_cell, `29</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox29.value=='') {TextBox29.value=TextBox28.value};TextBox29.select()" maxLength=15 size=10 name=TextBox29></TD>`)) browserdoc.writeln(strcat(open_cell, `30</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox30.value=='') {TextBox30.value=TextBox29.value};TextBox30.select()" maxLength=15 size=10 name=TextBox30></TD>`)) browserdoc.writeln(strcat(open_cell, `31</FONT><INPUT class="noborder bigblue" onfocus="if (TextBox31.value=='') {TextBox31.value=TextBox30.value};TextBox31.select()" maxLength=15 size=10 name=TextBox31></TD>`)) browserdoc.writeln(`<TD width=90 height=75> </TD></TR></TABLE>`) browserdoc.writeln(`<SPAN class=hidden id=ButtonChoice></SPAN>`) browserdoc.writeln(`<SPAN id=Buttons_section>`) buttons_data = `<P class=bigblue>Move from cell to cell using the mouse or the TAB key. Type the text you want to print. <br>` buttons_data = strcat(buttons_data, `<INPUT class=bigblue onclick="ButtonChoice.innerText='print'" type=button value=" print " name=print>`) buttons_data = strcat(buttons_data, `<INPUT class=bigblue onclick="ButtonChoice.innerText='quit'" type=button value=" quit " name=quit>`) browserdoc.writeln(buttons_data) browserdoc.writeln(`</SPAN></FONT></CENTER>`) browser.visible = @true buttonchoice = all.buttonchoice ; <--- reference the SPAN with the ID of ButtonChoice... winwaitexist("DHTML demo",10) While @true yields(2000) if !winexist("DHTML demo") break ; The browser has been closed by the user... else choice = buttonchoice.innertext If choice <> "" select @true case choice == "quit" objectclose(buttonchoice) br.quit break case choice == "print" ;delete buttons buttons_section = all.buttons_section buttons_section.innerhtml = "" ;print browser.execwb(18, 0, null, null) ; Clear selection, if any, or this is the only thing that will print. browser.execwb(6, 2, null, null) ; PRINT, no prompt. timedelay(3) ; Needed for the print function to execute properly. ;bring back buttons buttons_section.innerhtml = buttons_data break endselect if choice == "quit" then break buttonchoice.innertext = "" endif endif EndWhile exit
Article ID: W16128
File Created: 2004:08:02:11:23:22
Last Updated: 2004:08:02:11:23:22