Waiting Bar in HTA and CSS

淺唱寂寞╮ 提交于 2020-01-11 07:44:30

问题


I got a little code to simulate a waiting bar that uses HTML and CSS, so I had the idea to add in a HTA to generate after dynamically with a vbscript. If any of you can give me a hand for good display scrolling text with the waiting bar. Thank you in advance !

The original code in question => VBScript script progress notification

My modified code in a HTA :

<HTML>
<HEAD>
<Title>Recherche dans le contenu des fichiers de type texte (Version modifié © Hackoo)</Title>
<HTA:APPLICATION
ICON = "magnify.exe" 
BORDER="THIN" 
INNERBORDER="NO" 
MAXIMIZEBUTTON="NO" 
MINIMIZEBUTTON="NO" 
SCROLL="NO" 
SYSMENU="NO" 
SELECTION="NO" 
SINGLEINSTANCE="YES">
<style type="text/css">
* {
  //font-size: 1px;
  margin: 1px;
}
div {
  position: absolute;
  left: 28%;
  top: 50%;
}
marquee {
  border: 1px solid;
  height: 25px;
  width: 200px;
}
marquee span {
  height: 20px;
  width: 20px;
  background: Red;
  float: left;
}
.handle-0 { filter: alpha(opacity=20); -moz-opacity: 0.20; }
.handle-1 { filter: alpha(opacity=40); -moz-opacity: 0.40; }
.handle-2 { filter: alpha(opacity=60); -moz-opacity: 0.6; }
.handle-3 { filter: alpha(opacity=80); -moz-opacity: 0.8; }
.handle-4 { filter: alpha(opacity=100); -moz-opacity: 1; }
</style>
</HEAD>
<BODY text="white"><CENTER><DIV><SPAN ID="ProgressBar"></SPAN>
<span><marquee DIRECTION="LEFT" SCROLLAMOUNT="3" BEHAVIOR=ALTERNATE><font face="Comic sans MS">Veuillez patienter.la recherche du mot <FONT COLOR='yellow'><B>"Wscript"</B></FONT> est en cours...</font></marquee></span></DIV></CENTER></BODY></HTML>
<div>
<marquee direction="right" scrollamount="8" scrolldelay="100">
  <span class="handle-0"></span>
  <span class="handle-1"></span>
  <span class="handle-2"></span>
  <span class="handle-3"></span>
  <span class="handle-4"></span>
</marquee>
</div>
<SCRIPT LANGUAGE="VBScript"> 
Set ws = CreateObject("wscript.Shell")
Temp = WS.ExpandEnvironmentStrings("%Temp%")
Sub window_onload()
    CenterWindow 480,120
    Self.document.bgColor = "orange" 
 End Sub
 Sub CenterWindow(x,y)
    Dim iLeft,itop
    window.resizeTo x,y
    iLeft = window.screen.availWidth/2 - x/2
    itop = window.screen.availHeight/2 - y/2
    window.moveTo ileft,itop
End Sub
</script>

回答1:


I solved my problem like this example in Vbscript that generate the Waiting bar in HTA :

'Détermination de l'itinéraire vers les URL(s) saisi par l'utilisateur dans l'InputBox avec la commande DOS "Tracert" animé par une barre de progression
'Date de Création le 06/09/2013 © Hackoo
'Mise à jour le 04/05/2014 : Ajout d'un message d'attente animé par la balise <marquee>
'*********************************Déclaration des variables globales*******************************
Option Explicit
Dim oExec,fso,ws,Temp,Voice,Copyright,Title
Copyright = " Hackoo © 2014"
Set ws = CreateObject("wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject") 
Temp = ws.ExpandEnvironmentStrings("%Temp%")
Set Voice = CreateObject("SAPI.SpVoice")
'**************************************************************************************************
'Appel au programme principal ou on peut intégrer la barre de progression
Call MonProgramme() 
'**************************************************************************************************
Sub MonProgramme()
    Dim Command,Command2,Res,LogFile,StrCommand,Argum,startlog,MsgTitre,Titre,MsgAttente,StartTime,DurationTime
    MsgTitre = "Traceroute d'une URL © Hackoo © 2014"
    StrCommand = "Tracert"
    Argum = InputBox("Taper l'adresse d'une URL pour déterminer son itinéraire avec la commande DOS "& DblQuote("Tracert"),MsgTitre,"www.stackoverflow.com")
    LogFile = StrCommand & "Log.txt"
    If fso.FileExists(LogFile) Then fso.DeleteFile LogFile
    Command = "Cmd /c "& StrCommand & " " & Argum &" >> "&LogFile&""
    Titre = "La traceroute vers "& DblQuote(Argum) &" est en cours..."
    Title = Titre + Copyright
    MsgAttente = Titre
    Call CreateProgressBar(Titre,MsgAttente)'Creation de barre de progression
    Voice.Speak "Please Wait a While !"
    Call LancerProgressBar()'Lancement de la barre de progression
    StartTime = Timer'Début du Compteur Timer
    Res = Ws.Run(Command,0,True)'Exécution de la Commande
    DurationTime = FormatNumber(Timer - StartTime, 0) & " seconds."'La durée de l'exécution du script
    Call Formater(LogFile)'Pour formater et remplacer les caractères spéciaux unicode dans le LogFile
    Call FermerProgressBar()'Fermeture de barre de progression
    Voice.Speak "Process of TraceRoute finished in "& DurationTime &" !"
    ws.popup "La TraceRoute vers "& DblQuote(Argum) &" est terminée dans "& vbcr & DurationTime,"2",MsgTitre,64
    ws.popup Formater(LogFile),"5",MsgTitre,64
    Command2 = "Cmd /c Start "&LogFile&""
    startlog = Ws.Run(Command2,0,False)
End Sub
'****************************************************************************************************
Sub CreateProgressBar(Titre,MsgAttente)
    Dim ws,fso,f,f2,ts,ts2,Ligne,i,fread,LireTout,NbLigneTotal,Temp,PathOutPutHTML,fhta,oExec
    Set ws = CreateObject("wscript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Temp = WS.ExpandEnvironmentStrings("%Temp%")
    PathOutPutHTML = Temp & "\Barre.hta"
    Set fhta = fso.OpenTextFile(PathOutPutHTML,2,True)
    fhta.WriteLine "<HTML>"
    fhta.WriteLine "<HEAD>"
    fhta.WriteLine "<Title>  " & Title & "</Title>"
    fhta.WriteLine "<HTA:APPLICATION"
    fhta.WriteLine "ICON = ""magnify.exe"" "
    fhta.WriteLine "BORDER=""THIN"" "
    fhta.WriteLine "INNERBORDER=""NO"" "
    fhta.WriteLine "MAXIMIZEBUTTON=""NO"" "
    fhta.WriteLine "MINIMIZEBUTTON=""NO"" "
    fhta.WriteLine "SCROLL=""NO"" "
    fhta.WriteLine "SYSMENU=""NO"" "
    fhta.WriteLine "SELECTION=""NO"" "
    fhta.WriteLine "SINGLEINSTANCE=""YES"">"
    fhta.WriteLine "<style type=""text/css"">"
    fhta.WriteLine "div {left: 2%; top: 50%;}"
    fhta.WriteLine "marquee { height: 25px; width: 450px;}"
    fhta.WriteLine "marquee span {height: 20px; width: 20px; background: Red;float: left;}"
    fhta.WriteLine ".handle-0 { filter: alpha(opacity=20); -moz-opacity: 0.20; }"
    fhta.WriteLine ".handle-1 { filter: alpha(opacity=40); -moz-opacity: 0.40; }"
    fhta.WriteLine ".handle-2 { filter: alpha(opacity=60); -moz-opacity: 0.60; }"
    fhta.WriteLine ".handle-3 { filter: alpha(opacity=80); -moz-opacity: 0.80; }"
    fhta.WriteLine ".handle-4 { filter: alpha(opacity=100); -moz-opacity: 1; }"
    fhta.WriteLine "</style>"
    fhta.WriteLine "</HEAD>"
    fhta.WriteLine "<BODY text=""white""><CENTER><DIV><SPAN ID=""ProgressBar""></SPAN>"
    fhta.WriteLine "<span><marquee DIRECTION=""LEFT"" SCROLLAMOUNT=""3"" BEHAVIOR=ALTERNATE><font face=""Comic sans MS"">" & MsgAttente &"</font></marquee></span></DIV></CENTER></BODY></HTML>"
    fhta.WriteLine "<div>"
    fhta.WriteLine "<marquee direction=""right"" scrollamount=""10"" BEHAVIOR=ALTERNATE>"
    fhta.WriteLine "<span class=""handle-0""></span>"
    fhta.WriteLine "<span class=""handle-1""></span>"
    fhta.WriteLine "<span class=""handle-2""></span>"
    fhta.WriteLine "<span class=""handle-3""></span>"
    fhta.WriteLine "<span class=""handle-4""></span>"
    fhta.WriteLine "</marquee>"
    fhta.WriteLine "</div>"
    fhta.WriteLine "<SCRIPT LANGUAGE=""VBScript""> "
    fhta.WriteLine "Set ws = CreateObject(""wscript.Shell"")"
    fhta.WriteLine "Temp = WS.ExpandEnvironmentStrings(""%Temp%"")"
    fhta.WriteLine "Sub window_onload()"
    fhta.WriteLine "    CenterWindow 480,110"
    fhta.WriteLine "    Self.document.bgColor = ""DarkOrange"" "
    fhta.WriteLine " End Sub"
    fhta.WriteLine " Sub CenterWindow(x,y)"
    fhta.WriteLine "    Dim iLeft,itop"
    fhta.WriteLine "    window.resizeTo x,y"
    fhta.WriteLine "    iLeft = window.screen.availWidth/2 - x/2"
    fhta.WriteLine "    itop = window.screen.availHeight/2 - y/2"
    fhta.WriteLine "    window.moveTo ileft,itop"
    fhta.WriteLine "End Sub"
    fhta.WriteLine "</script>"
    fhta.close
End Sub
'**********************************************************************************************
Sub LancerProgressBar()
    Set oExec = Ws.Exec("mshta.exe " & Temp & "\Barre.hta")
End Sub
'**********************************************************************************************
Sub FermerProgressBar()
    oExec.Terminate
End Sub
'**********************************************************************************************
'Fonction pour ajouter les doubles quotes dans une variable
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'**********************************************************************************************
'Fonction pour formater et remplacer les caractères spéciaux unicode dans le LogFile
Function Formater(File)
    Dim fso,fRead,fWrite,Text
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fRead = fso.OpenTextFile(File,1)
    Text = fRead.ReadAll
    fRead.Close
    Set fWrite = fso.OpenTextFile(File,2,True)
    Text = Replace(Text,"‚","é")
    Text = Replace(Text,"ے"," ")
    Text = Replace(Text,"ˆ","ê")
    Text = Replace(Text,"‡","ç")
    Text = Replace(Text,"“","ô")
    Text = Replace(Text,"…","à")
    Text = Replace(Text,"ٹ","è")
    Text = Replace(Text,"ƒ","â")
    Text = Replace(Text,"?"," ")
    fWrite.WriteLine Text
    Formater = Text
End Function
'***********************************************************************************************



回答2:


I use this progress bar, which has been edited from this link

'*******************************************************
'*** Progress bar class
'*******************************************************
'The attributes of the class to create the progress bar as an internet explorer window
'edited from **http://www.northatlantawebdesign.com/index.php/2009/07/16/simple-vbscript-progress-bar/**

Dim pb
Dim percentComplete

Class ProgressBar
    Private m_PercentComplete
    Private m_CurrentStep
    Private m_ProgressBar
    Private m_Title
    Private m_Text
    Private m_StatusBarText
    Public n

'Initialize defaults
Private Sub ProgessBar_Initialize
    m_PercentComplete = 0
    n = 0
    m_CurrentStep = 0
    m_Title = "Progress"
    m_Text = ""
End Sub

Public Function SetTitle(pTitle)
    m_Title = pTitle
End Function

Public Function SetText(pText)
    m_Text = pText
End Function

Public Function Update(percentComplete)
    m_PercentComplete = percentComplete
    UpdateProgressBar()
End Function

Public Function Show()
Set m_ProgressBar = Wscript.CreateObject("InternetExplorer.Application", "IE_")
'the colon acts as a line feed
    m_ProgressBar.navigate2 "about:blank" : m_ProgressBar.width = 315 : m_ProgressBar.height = 200:
    m_ProgressBar.toolbar = false : m_ProgressBar.menubar = false : m_ProgressBar.statusbar = false : m_ProgressBar.visible = true ': m_ProgressBar.Resizable = false 'Resizeable not used, but kept in case needed
    m_ProgressBar.document.write "<body Scroll=no style='margin:0px;padding:0px;'><div style='text-align:center;'><span name='pc' id='pc'>0</span></div>"
    m_ProgressBar.document.write "<div id='statusbar' name='statusbar' style='border:1px solid blue;line-height:10px;height:10px;color:blue;'></div>"
    m_ProgressBar.document.write "<div style='text-align:center'><span id='text' name='text'></span></div> </body>"
End Function

Public Function Close()
    m_ProgressBar.quit
End Function

Private Function UpdateProgressBar()
If m_PercentComplete = 0 Then
    m_StatusBarText = ""
End If
For n = m_CurrentStep to m_PercentComplete - 1
    m_StatusBarText = m_StatusBarText & "|"
    m_ProgressBar.Document.GetElementById("statusbar").InnerHtml = m_StatusBarText
    m_ProgressBar.Document.title = "Progress"
    m_ProgressBar.Document.GetElementById("pc").InnerHtml = n & "% Complete <BR>" & m_Title
    Wscript.sleep 10
Next
    m_ProgressBar.Document.GetElementById("statusbar").InnerHtml = m_StatusBarText
    m_ProgressBar.Document.GetElementById("pc").InnerHtml = m_PercentComplete & "% Complete <BR>"  & m_Title
    m_ProgressBar.Document.GetElementById("text").InnerHtml = m_Text
    m_CurrentStep = m_PercentComplete
    Wscript.sleep 10
End Function

End Class

set it with these statements

Set pb = New ProgressBar
    percentComplete = 0
    pb.SetTitle("Step 1 of 4 - Do Not Close Window!")
    pb.SetText("Starting Program")
    pb.Show()
    pb.Update(percentComplete)

and then updated it as an when necessary

pb.SetTitle("Step 3 of 4 - Do Not Close Window!")
pb.SetText("Copying Files")
percentComplete = 0
pb.Update(percentComplete)

if i am incrementing through a folder, i would first get the number of files in the folder and then use a counter to increment the percentComplete value and then dynamically update the progress bar using

percentComplete = 0
pb.Update(percentComplete)


来源:https://stackoverflow.com/questions/23401151/waiting-bar-in-hta-and-css

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!