From: Tom Lavedas on
About ten days ago I adapted a Mayayana solution to create a
"chromeless" msgbox replacement. The thread can be found here:
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/5ab6ebda92e63a9c#.

At the time I figured the only thing objectionable about the approach
was that it flashed a large HTA window before it could be adjusted to
the desired size. I asked if anyone might have a solution. Having
received no response, I kept thinking about that problem. I was
pretty sure a fix could be coded into the JavaScript used to create
the HTA in the first place, but couldn't get it to work. Today I had
a 'eureka' moment and after some fiddling got it worked out.

Hear is an example that presents a request for credentials and
provides a simple UID/Password dialog box as an example of its use
(watch for wordwrap) ...

' A simple example of HTABox
-----------' Main -------------
with HTABox("lightgrey", 150, 300, 400, 500)
.document.title = "Credentials"
.msg.innerHTML = "UserID: &nbsp; &nbsp; <input type=text size=20
id=UID>"_
& "<br>Password: <input type=password id=PW
size=22><p>" _
& "<input type=submit value=Submit
onclick='done.value=true'>"
.UID.value = createobject("wscript.network").username
.PW.focus
do until .done.value : wsh.sleep 50 : loop
sUID = .UID.value : sPW = .PW.value
.close
end with

wsh.echo "UID:", sUID, "Password:", sPW
'--------- Main Ends ------------

' Author: Tom Lavedas, June 2010
Function HTABox(sBgColor, h, w, l, t)
Dim IE, HTA

randomize : nRnd = Int(1000000 * rnd)
sCmd = "mshta.exe ""javascript:" _
& "{with (new ActiveXObject(""InternetExplorer.Application""))
{" _
& "PutProperty('" & nRnd & "',window);" _
& "with (GetProperty('" & nRnd & "')){" _
& "resizeTo(" & w & "," & h & ");moveTo(" & l & "," & t &
")}}}"""

with CreateObject("WScript.Shell")
.Run sCmd, 1, False
do until .AppActivate("javascript:{with ") : WSH.sleep 10 : loop
end with ' WSHShell

For Each IE In CreateObject("Shell.Application").windows
If IsObject(IE.GetProperty(nRnd)) Then
set HTABox = IE.GetProperty(nRnd)
HTABox.document.title = "HTABox"
HTABox.document.write _
"<HTA:Application contextMenu=no border=thin " _
& "minimizebutton=no maximizebutton=no sysmenu=no />" _
& "<body scroll=no style='background-color:" _
& sBgColor & ";font:normal 10pt Arial' " _
& "onbeforeunload='vbscript:if not done.value then " _
& "window.event.cancelBubble=true:" _
& "window.event.returnValue=false:" _
& "done.value=true:end if'>" _
& "<input type=hidden id=done value=false>" _
& "<center><span id=msg>&nbsp;</span><center></body>"
Exit Function
End If
Next

' I can't imagine how this line can be reached, but just in case
MsgBox "HTA window not found." : wsh.quit

End Function
' ---------- code ends -------------

I chose to make the dialog box as simple as possible, purposely devoid
of 'bells and whistles'. It merely returns a handle to the HTA window
that is created. It does provided some fundamental features such as
the setting of background color, height, width, left position and top
position. The actual controls for the object are left to the user to
define through the 'msg' object that the routine creates. A user's
intention to continue is signaled via the hidden 'done' control, by
setting its value to True. However, a script is free to close the
window at any time by issuing a 'close' command. The script example
provides some illustrative code and logic.

Enjoy.
_____________________
Tom Lavedas
From: James Whitlow on
"Tom Lavedas" <tglbatch(a)verizon.net> wrote in message
news:b9622e6d-0213-4d67-824c-e3d07fb17416(a)k39g2000yqb.googlegroups.com...
> About ten days ago I adapted a Mayayana solution to create a
> "chromeless" msgbox replacement. The thread can be found here:
> http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/5ab6ebda92e63a9c#.
>
> At the time I figured the only thing objectionable about the approach
> was that it flashed a large HTA window before it could be adjusted to
> the desired size. I asked if anyone might have a solution. Having
> received no response, I kept thinking about that problem. I was
> pretty sure a fix could be coded into the JavaScript used to create
> the HTA in the first place, but couldn't get it to work. Today I had
> a 'eureka' moment and after some fiddling got it worked out.

Nice piece of work, Tom!

I don't really have a need for the message box, per se, but I will likely
be borrowing your technique for some other projects. Having an HTA launched
from a WSF really opens the door to being able to have pseudo multi-threaded
HTA. The entire body of the HTA can be neatly packaged inside of a
<resource> in the WSF.


From: Mayayana on
That works nicely for me. I tried to adjust it
to get a more msgbox-like border, but that
doesn't seem to work. borderstyle=static seems
to be the only thing that has any effect at all,
and that produces a somewhat odd border.



| About ten days ago I adapted a Mayayana solution to create a
| "chromeless" msgbox replacement. The thread can be found here:
|
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/5ab6ebda92e63a9c#.
|
| At the time I figured the only thing objectionable about the approach
| was that it flashed a large HTA window before it could be adjusted to
| the desired size. I asked if anyone might have a solution. Having
| received no response, I kept thinking about that problem. I was
| pretty sure a fix could be coded into the JavaScript used to create
| the HTA in the first place, but couldn't get it to work. Today I had
| a 'eureka' moment and after some fiddling got it worked out.
|
| Hear is an example that presents a request for credentials and
| provides a simple UID/Password dialog box as an example of its use
| (watch for wordwrap) ...
|
| ' A simple example of HTABox
| -----------' Main -------------
| with HTABox("lightgrey", 150, 300, 400, 500)
| .document.title = "Credentials"
| .msg.innerHTML = "UserID: &nbsp; &nbsp; <input type=text size=20
| id=UID>"_
| & "<br>Password: <input type=password id=PW
| size=22><p>" _
| & "<input type=submit value=Submit
| onclick='done.value=true'>"
| .UID.value = createobject("wscript.network").username
| .PW.focus
| do until .done.value : wsh.sleep 50 : loop
| sUID = .UID.value : sPW = .PW.value
| .close
| end with
|
| wsh.echo "UID:", sUID, "Password:", sPW
| '--------- Main Ends ------------
|
| ' Author: Tom Lavedas, June 2010
| Function HTABox(sBgColor, h, w, l, t)
| Dim IE, HTA
|
| randomize : nRnd = Int(1000000 * rnd)
| sCmd = "mshta.exe ""javascript:" _
| & "{with (new ActiveXObject(""InternetExplorer.Application""))
| {" _
| & "PutProperty('" & nRnd & "',window);" _
| & "with (GetProperty('" & nRnd & "')){" _
| & "resizeTo(" & w & "," & h & ");moveTo(" & l & "," & t &
| ")}}}"""
|
| with CreateObject("WScript.Shell")
| .Run sCmd, 1, False
| do until .AppActivate("javascript:{with ") : WSH.sleep 10 : loop
| end with ' WSHShell
|
| For Each IE In CreateObject("Shell.Application").windows
| If IsObject(IE.GetProperty(nRnd)) Then
| set HTABox = IE.GetProperty(nRnd)
| HTABox.document.title = "HTABox"
| HTABox.document.write _
| "<HTA:Application contextMenu=no border=thin " _
| & "minimizebutton=no maximizebutton=no sysmenu=no />" _
| & "<body scroll=no style='background-color:" _
| & sBgColor & ";font:normal 10pt Arial' " _
| & "onbeforeunload='vbscript:if not done.value then " _
| & "window.event.cancelBubble=true:" _
| & "window.event.returnValue=false:" _
| & "done.value=true:end if'>" _
| & "<input type=hidden id=done value=false>" _
| & "<center><span id=msg>&nbsp;</span><center></body>"
| Exit Function
| End If
| Next
|
| ' I can't imagine how this line can be reached, but just in case
| MsgBox "HTA window not found." : wsh.quit
|
| End Function
| ' ---------- code ends -------------
|
| I chose to make the dialog box as simple as possible, purposely devoid
| of 'bells and whistles'. It merely returns a handle to the HTA window
| that is created. It does provided some fundamental features such as
| the setting of background color, height, width, left position and top
| position. The actual controls for the object are left to the user to
| define through the 'msg' object that the routine creates. A user's
| intention to continue is signaled via the hidden 'done' control, by
| setting its value to True. However, a script is free to close the
| window at any time by issuing a 'close' command. The script example
| provides some illustrative code and logic.
|
| Enjoy.
| _____________________
| Tom Lavedas


From: Todd Vargo on
James Whitlow wrote:
> "Tom Lavedas" <tglbatch(a)verizon.net> wrote in message
> news:b9622e6d-0213-4d67-824c-e3d07fb17416(a)k39g2000yqb.googlegroups.com...
>> About ten days ago I adapted a Mayayana solution to create a
>> "chromeless" msgbox replacement. The thread can be found here:
>>
snip...
>>
>> At the time I figured the only thing objectionable about the approach
>> was that it flashed a large HTA window before it could be adjusted to
>> the desired size. I asked if anyone might have a solution. Having
>> received no response, I kept thinking about that problem. I was
>> pretty sure a fix could be coded into the JavaScript used to create
>> the HTA in the first place, but couldn't get it to work. Today I had
>> a 'eureka' moment and after some fiddling got it worked out.
>
> Nice piece of work, Tom!
>
> I don't really have a need for the message box, per se, but I will likely
> be borrowing your technique for some other projects. Having an HTA
> launched from a WSF really opens the door to being able to have pseudo
> multi-threaded HTA. The entire body of the HTA can be neatly packaged
> inside of a <resource> in the WSF.

Yes, nice work Tom. The only thing that bothers me is when run using the
WSCRIPT.EXE host, after the HTA closes and control returns to the script,
the window focus does not return to the running script. In otherwords, any
MsgBox thereafter will be opened as minimized. The only thing that seems to
display the MsgBox in the foreground following the HTA is if the
vbSystemModal flag is used.

--
Todd Vargo

(Post questions to group only. Remove "z" to email personal messages)

From: Pegasus [MVP] on


"Tom Lavedas" <tglbatch(a)verizon.net> wrote in message
news:b9622e6d-0213-4d67-824c-e3d07fb17416(a)k39g2000yqb.googlegroups.com...
> About ten days ago I adapted a Mayayana solution to create a
> "chromeless" msgbox replacement. The thread can be found here:
> http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/5ab6ebda92e63a9c#.
>
> At the time I figured the only thing objectionable about the approach
> was that it flashed a large HTA window before it could be adjusted to
> the desired size. I asked if anyone might have a solution. Having
> received no response, I kept thinking about that problem. I was
> pretty sure a fix could be coded into the JavaScript used to create
> the HTA in the first place, but couldn't get it to work. Today I had
> a 'eureka' moment and after some fiddling got it worked out.
>
> Hear is an example that presents a request for credentials and
> provides a simple UID/Password dialog box as an example of its use
> (watch for wordwrap) ...
>
> ' A simple example of HTABox
> -----------' Main -------------
> with HTABox("lightgrey", 150, 300, 400, 500)
> .document.title = "Credentials"
> .msg.innerHTML = "UserID: &nbsp; &nbsp; <input type=text size=20
> id=UID>"_
> & "<br>Password: <input type=password id=PW
> size=22><p>" _
> & "<input type=submit value=Submit
> onclick='done.value=true'>"
> .UID.value = createobject("wscript.network").username
> .PW.focus
> do until .done.value : wsh.sleep 50 : loop
> sUID = .UID.value : sPW = .PW.value
> .close
> end with
>
> wsh.echo "UID:", sUID, "Password:", sPW
> '--------- Main Ends ------------
>
> ' Author: Tom Lavedas, June 2010
> Function HTABox(sBgColor, h, w, l, t)
> Dim IE, HTA
>
> randomize : nRnd = Int(1000000 * rnd)
> sCmd = "mshta.exe ""javascript:" _
> & "{with (new ActiveXObject(""InternetExplorer.Application""))
> {" _
> & "PutProperty('" & nRnd & "',window);" _
> & "with (GetProperty('" & nRnd & "')){" _
> & "resizeTo(" & w & "," & h & ");moveTo(" & l & "," & t &
> ")}}}"""
>
> with CreateObject("WScript.Shell")
> .Run sCmd, 1, False
> do until .AppActivate("javascript:{with ") : WSH.sleep 10 : loop
> end with ' WSHShell
>
> For Each IE In CreateObject("Shell.Application").windows
> If IsObject(IE.GetProperty(nRnd)) Then
> set HTABox = IE.GetProperty(nRnd)
> HTABox.document.title = "HTABox"
> HTABox.document.write _
> "<HTA:Application contextMenu=no border=thin " _
> & "minimizebutton=no maximizebutton=no sysmenu=no />" _
> & "<body scroll=no style='background-color:" _
> & sBgColor & ";font:normal 10pt Arial' " _
> & "onbeforeunload='vbscript:if not done.value then " _
> & "window.event.cancelBubble=true:" _
> & "window.event.returnValue=false:" _
> & "done.value=true:end if'>" _
> & "<input type=hidden id=done value=false>" _
> & "<center><span id=msg>&nbsp;</span><center></body>"
> Exit Function
> End If
> Next
>
> ' I can't imagine how this line can be reached, but just in case
> MsgBox "HTA window not found." : wsh.quit
>
> End Function
> ' ---------- code ends -------------
>
> I chose to make the dialog box as simple as possible, purposely devoid
> of 'bells and whistles'. It merely returns a handle to the HTA window
> that is created. It does provided some fundamental features such as
> the setting of background color, height, width, left position and top
> position. The actual controls for the object are left to the user to
> define through the 'msg' object that the routine creates. A user's
> intention to continue is signaled via the hidden 'done' control, by
> setting its value to True. However, a script is free to close the
> window at any time by issuing a 'close' command. The script example
> provides some illustrative code and logic.
>
> Enjoy.
> _____________________
> Tom Lavedas

This is great stuff and I have been looking for something like this for
quite some time. It is fairly easy to adapt the code for different
applications even for someone like me who knows nothing at all about HTA and
Java. However, I do have a problem with an application that requires a
banner panel across the top of the screen. Just an informative message, no
OK button. It runs in parallel with some independent process. To close the
panel I replace this line

do until .done.value : wsh.sleep 50 : loop

with something like this:

do until oFSO.FileExists(sSemaphore) : loop

where the semaphore file is created by the parallel process. This works but
here is a snag: The moment the program drops out of the Do loop, IE
generates a dialog box asking if I really want to close the current window.
How can I prevent this box from popping up?

 | 
Pages: 1
Prev: Excel inputfile
Next: A new HTA based message box