Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make HTA script STAY ON TOP ???

Status
Not open for further replies.

Sharpharp

IS-IT--Management
Jun 9, 2009
29
GB
Hi there,

I have this script which displays a timer using a HTA script, but I can't for the life of me work out to make it stay on top of any windows that are clicked on. I need the timer to STAY ON TOP even when a user is using applications etc.

Can anyone help please?

Here's the code:

<html>
<head>
<title>Time Left</title>
<HTA:APPLICATION
APPLICATIONNAME="Time Left"
CAPTION = "no"
BORDER="none"
SCROLL="no"
SINGLEINSTANCE="yes"
SYSMENU= "no"
SHOWINTASKBAR= "no"
WINDOWSTATE="normal"
>
</head>

<script language="VBScript">

' Declare global variable outside the Subs
Dim intMinutes
Dim intSeconds

Sub Window_onLoad
intWidth = 160
intHeight = 27
Me.ResizeTo intWidth, intHeight
Me.MoveTo ((Screen.Width / 3)*2),0
intMinutes = 4
intSeconds = 59
iTimerID = window.setInterval("CloseWindow", 1000)
End Sub

Sub CloseWindow
If intSeconds = 0 Then
If intMinutes = 0 Then
window.close
Else
intMinutes = intMinutes - 1
End If
intSeconds = 59
Else
intSeconds = intSeconds - 1
End If
span_clock.innerHTML = intMinutes & ":" & Right("00" & intSeconds, 2)
End Sub

</script>

<body TOPMARGIN="0" SCROLL="NO" STYLE="font:12 pt arial; color:white;filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=1, StartColorStr='#FFA500', EndColorStr='#EC5727')">
<table width='100%' height = '100%' align='centre' border='0'>
<tr>
<td align="left">
<B>Time Left</B>
</td>
<td>
<span id="span_clock">
4:59
</span>
</td>
</tr>
</table>
</body>
</html>
 
Not so easy with an HTA. Probably the best workaround is to kick off an event on a timer which appactivates the HTA or somehow sends a click to it.
 
[0] I've run the hta for inspecting. The color looks cute. Hence, in return, I can propose to you a solution based on dynamic wrapper.

[1] Add this script section to the existing page. It is based on dynamic wrapper. You've to download and register this activex, say at G Born's site.
[tt]
<script type="text/vbscript" language="vbscript">
'ref setwindowpos 'ref findwindow 'ref hand-on 'ref lpclassname
const bontop=true
sub setontop 'use global constant bontop
const SWP_NOSIZE=&H1
const SWP_NOMOVE=&H2
const HWND_TOPMOST=-1
const HWND_NOTOPMOST=-2
const lpClassName="HTML Application Host Window Class"

dim odw, hwnd
set odw=createobject("DynamicWrapper")
odw.register "user32.dll", "FindWindowA", "i=ss", "f=s", "r=l"
odw.register "user32.dll", "SetWindowPos", "i=lllllll", "f=s", "r=l"
hwnd=odw.FindWindowA(lpClassName, window.document.title)

if bontop then
odw.SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
else
odw.SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
end if

set odw=nothing

end sub

window.onload=getRef("setontop")
</script>
[/tt]
[2] Alternatively, if office suite is available, you can do a api call injection to excel vba component.

[3] I offer no more boring recital on using 3rd party component. You evaluate the neediness and the inconvenience on your own to decide.
 
I've added the code to my script, but which activex do i need to register?
 
Thanks for your help tsuji, however...

I have downloaded and tried to register the activex control, but get an error in Windows 7:

The module "dynwrap.ddl" was loaded but the call to DllregisterServer failed with error code 0x80004005

 
I put in the correct command line regsvr32.exe dynwrap.DLL
but it still comes up with the same message, in the error message it refers to dynwrap.DDL, any suggestions?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top