Auto Center Vbs Window

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alanbr00
Posts: 3
Joined: 14 Sep 2019 11:20

Auto Center Vbs Window

#1 Post by alanbr00 » 14 Sep 2019 11:23

Hello to all,

this is script does what i need, i'm just need to know how to do "window auto center", "get the message in the center of the box" and put a "countdown", in this script.

Thanks for any help.

Code: Select all

with HTABox("DodgerBlue", 100, 300, 0, 0)
  .document.title = "Atualizando Sistema"
  .msg.innerHTML = "<font color=red><b>ATUALIZANDO SISTEMA, AGUARDE.<b></font>"
  Timeout = 60000 ' milliseconds
  do until .done.value or (n > TimeOut): wsh.sleep 50 : n=n+50 : loop
  .done.value = true
  .close
end with

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

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

  with CreateObject("WScript.Shell")
    .Run sCmd, 1, False
    do until .AppActivate("javascript:{new ") : 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)
      IE.Quit
      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 14pt Arial Black;" _
             & "border-Style:outset;border-Width:10px'" _
             & "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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Auto Center Vbs Window

#2 Post by aGerman » 15 Sep 2019 05:09

This is not related to Batch. Not even to any console application. And I get a "Permission Denied" error in line 22. So I can't even run your script.

Some hints:
"window auto center"
You need to calculate the values for window.moveTo(). The screen.availWidth properterty contains the width of the screen. Half of it is the center of your screen in x direction. Minus half of the width of your window, and you'll get the x position of the top left corner in x direction for your centered window. Use screen.availHeigth for the y position, respectively.
"get the message in the center of the box"
This has to be done in HTML and CSS. Maybe use a <div> container for your message and set the CSS properties accordingly.
https://stackoverflow.com/questions/986 ... -of-screen
"countdown"
Provided you want to display this contdown in your window, then you need another function that is called using window.setInterval(). Otherwise you won't see any update in the window.

But as I said, this is all quite off topic in this forum.

Steffen

alanbr00
Posts: 3
Joined: 14 Sep 2019 11:20

Re: Auto Center Vbs Window

#3 Post by alanbr00 » 16 Sep 2019 09:52

I'm sorry, this topic can be closed.

Hackoo
Posts: 103
Joined: 15 Apr 2014 17:59

Re: Auto Center Vbs Window

#4 Post by Hackoo » 18 Sep 2019 10:38

You should take a look here :wink:

Post Reply