更改标题颜色和背景
Change the title color and background
如何使用参数设置 HTA 的标题颜色和背景?
类似于:
List.hta "ColorBG" "ColorTitle"
标题:
<font color="#FFFFFF" Times New Roman" size="13"><center><B>List</b></center></font>
.
我的完整代码:
<html>
<head>
<title>My List</title>
<HTA:Application
Border= "thin"
Application="/md/input"
Scoll="NO"
Singleinstance="Yes"
SysMenu=NO
Icon="%Windir%\System32\wscript.exe">
ShowInTaskbar="Yes"
Caption="Yes">
<script type="text/vbscript">
Option Explicit
Window.resizeTo 373,610
Const csFSpec = "List.txt"
Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject")
Sub Window_OnLoad()
Dim objFile
If goFS.FileExists(csFSpec) Then
SET objFile = goFS.GetFile(csFSpec)
If objFile.Size > 0 Then
document.all.DataArea.value = goFS.OpenTextFile(csFSpec).ReadAll()
document.all.DataArea.value = document.all.DataArea.value
Else
document.all.DataArea.value =""
End If
Else
self.close
End If
End Sub
Sub SaveFile()
Dim objMM
Dim objFSOO
If document.all.DataArea.value = "" Then
Set objFSOO = CreateObject("Scripting.FileSystemObject")
Set objMM = objFSOO.CreateTextFile("List.txt")
self.close
Else
document.all.DataArea.value = Replace(document.all.DataArea.value, "\", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "/", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, ":", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "*", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "?", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, """", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "<", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, ">", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "|", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "&", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "!", "_")
goFS.CreateTextFile(csFSpec).Write document.all.DataArea.value
DIM objFSO
DIM objFile
DIM STRLINE
DIM STRNEWCONTENTS
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("List.txt", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.Readline
strLine = Trim(strLine)
If Len(strLine) > 0 Then
strNewContents = strNewContents & strLine & vbCrLf
End If
Loop
objFile.Close
Set objFile = objFSO.OpenTextFile("List.txt", ForWriting)
objFile.Write strNewContents
objFile.Close
document.all.DataArea.value = goFS.OpenTextFile(csFSpec).ReadAll()
document.all.DataArea.value = Replace(document.all.DataArea.value, vbcrlf,"|")
document.all.DataArea.value = left(document.all.DataArea.value,len(document.all.DataArea.value)-1)
document.all.DataArea.value = Replace(document.all.DataArea.value,"|",vbcrlf)
goFS.CreateTextFile(csFSpec).Write document.all.DataArea.value
self.close
End if
End Sub
Sub QuitEdit()
self.close
End Sub
Sub Redefine()
document.all.DataArea.value ="CD" & vbcrlf & "DISC" & vbcrlf & "MUSIC" & vbcrlf & "ALBUM"
End Sub
Sub Clean()
document.all.DataArea.value = ""
End Sub
</script>
</head>
<body style="overflow:hidden" bgColor="#000080"></body>
<caption></caption><hr></hr>
<font color="#FFFFFF" Times New Roman" size="13"><center><B>List</b></center></font>
<caption></caption><hr></hr>
<TR><td>
<input style="background-color:#F0F0F0; color: #000000; border: 2px transparent; float: left;" type="BUTTON" value="Clean" class="btn" id="btna" onclick="Clean" onmouseover="btna.style.background = '#808080'" onmouseout="btna.style.background = '#F0F0F0'">
<input style="background-color:#F0F0F0; color: #000000; border: 2px transparent; float: right;" type="BUTTON" value="Redefine" class="btn" id="btnb" onclick="Redefine" onmouseover="btnb.style.background = '#808080'" onmouseout="btnb.style.background = '#F0F0F0'">
</TR></td>
<Table border="3" style="width:100%; text-align: center" BORDERCOLOR=#F0F0F0>
<TR><td>
<form>
<textarea name="DataArea" rows="23" cols=37></textarea> </Table>
<TR><td>
<p>
<div align="right"><input style="background-color:#F0F0F0; color: #000000; border: 2px transparent" type="BUTTON" value=" OK " class="btn" id="btnc" onclick="SaveFile" onmouseover="btnc.style.background = '#808080'" onmouseout="btnc.style.background = '#F0F0F0'">
<input style="background-color:#F0F0F0; color: #000000; border: 2px transparent" type="BUTTON" value="Cancel" class="btn" id="btnd" onclick="QuitEdit" onmouseover="btnd.style.background = '#808080'" onmouseout="btnd.style.background = '#F0F0F0'">
</div>
</td></TR>
</form>
</body>
</html>
<title>
和 </title>
之间的文本无法设置样式。它用于在 caption/title 栏中设置 Internet Explorer 的 Window 标题。您输入的任何文字都将按字面意思处理。
Windows 控制所有标题栏的外观。您可以在控制面板中 Display/Personalization 小程序的 "Appearance" 或 "Windows Color" 部分中(全局)配置它们。例如,"Active Title Bar" 控制 Windows 用于 currently-active window 的字体和颜色。
编辑:
我重读了你的问题,听起来你的 "title" 可能不是页面标题 (<title>
),而只是你在页面顶部附近显示的一些文本(你重新呼叫您的 "title").
您可以将参数传递给 HTA,但解析它们有点棘手。 HTA 只有 CommandLine
属性,其中 returns 是完整的命令行,包括您的 HTA 的完整路径。为了使事情变得更简单,大多数人选择将他们的参数括在引号中,因此您的命令行可能如下所示:
"c:\my folder\test.hta" "#ddd" "#f00"
在这里,我们将两个参数(HTML 颜色)传递给 HTA。要检索它们,我们可以在引号 (Chr(34)
) 上拆分 CommandLine
属性,我们将得到以下内容:
a = Split(myhta.CommandLine, Chr(34))
a(0) = <blank>
a(1) = "c:\my folder\test.hta"
a(2) = " "
a(3) = "#ddd"
a(4) = " "
a(5) = "#f00"
a(6) = <blank>
因此,a(3)
成为您的第一个参数,a(5)
成为您的第二个参数。现在您可以将这些值分配给 HTML 元素的 style.backgroundColor
和 style.color
属性。
这是一个例子:
<head>
<HTA:APPLICATION
ID="htatest"
APPLICATIONNAME="HTA Test"
>
</head>
<body>
<span id="mytitle">This is a title</span>
</body>
<script language="VBScript">
Sub Window_OnLoad()
a = Split(htatest.CommandLine, Chr(34))
mytitle.style.backgroundcolor = a(3)
mytitle.style.color = a(5)
End Sub
</script>
如何使用参数设置 HTA 的标题颜色和背景?
类似于:
List.hta "ColorBG" "ColorTitle"
标题:
<font color="#FFFFFF" Times New Roman" size="13"><center><B>List</b></center></font>
.
我的完整代码:
<html>
<head>
<title>My List</title>
<HTA:Application
Border= "thin"
Application="/md/input"
Scoll="NO"
Singleinstance="Yes"
SysMenu=NO
Icon="%Windir%\System32\wscript.exe">
ShowInTaskbar="Yes"
Caption="Yes">
<script type="text/vbscript">
Option Explicit
Window.resizeTo 373,610
Const csFSpec = "List.txt"
Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject")
Sub Window_OnLoad()
Dim objFile
If goFS.FileExists(csFSpec) Then
SET objFile = goFS.GetFile(csFSpec)
If objFile.Size > 0 Then
document.all.DataArea.value = goFS.OpenTextFile(csFSpec).ReadAll()
document.all.DataArea.value = document.all.DataArea.value
Else
document.all.DataArea.value =""
End If
Else
self.close
End If
End Sub
Sub SaveFile()
Dim objMM
Dim objFSOO
If document.all.DataArea.value = "" Then
Set objFSOO = CreateObject("Scripting.FileSystemObject")
Set objMM = objFSOO.CreateTextFile("List.txt")
self.close
Else
document.all.DataArea.value = Replace(document.all.DataArea.value, "\", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "/", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, ":", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "*", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "?", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, """", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "<", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, ">", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "|", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "&", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "!", "_")
goFS.CreateTextFile(csFSpec).Write document.all.DataArea.value
DIM objFSO
DIM objFile
DIM STRLINE
DIM STRNEWCONTENTS
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("List.txt", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.Readline
strLine = Trim(strLine)
If Len(strLine) > 0 Then
strNewContents = strNewContents & strLine & vbCrLf
End If
Loop
objFile.Close
Set objFile = objFSO.OpenTextFile("List.txt", ForWriting)
objFile.Write strNewContents
objFile.Close
document.all.DataArea.value = goFS.OpenTextFile(csFSpec).ReadAll()
document.all.DataArea.value = Replace(document.all.DataArea.value, vbcrlf,"|")
document.all.DataArea.value = left(document.all.DataArea.value,len(document.all.DataArea.value)-1)
document.all.DataArea.value = Replace(document.all.DataArea.value,"|",vbcrlf)
goFS.CreateTextFile(csFSpec).Write document.all.DataArea.value
self.close
End if
End Sub
Sub QuitEdit()
self.close
End Sub
Sub Redefine()
document.all.DataArea.value ="CD" & vbcrlf & "DISC" & vbcrlf & "MUSIC" & vbcrlf & "ALBUM"
End Sub
Sub Clean()
document.all.DataArea.value = ""
End Sub
</script>
</head>
<body style="overflow:hidden" bgColor="#000080"></body>
<caption></caption><hr></hr>
<font color="#FFFFFF" Times New Roman" size="13"><center><B>List</b></center></font>
<caption></caption><hr></hr>
<TR><td>
<input style="background-color:#F0F0F0; color: #000000; border: 2px transparent; float: left;" type="BUTTON" value="Clean" class="btn" id="btna" onclick="Clean" onmouseover="btna.style.background = '#808080'" onmouseout="btna.style.background = '#F0F0F0'">
<input style="background-color:#F0F0F0; color: #000000; border: 2px transparent; float: right;" type="BUTTON" value="Redefine" class="btn" id="btnb" onclick="Redefine" onmouseover="btnb.style.background = '#808080'" onmouseout="btnb.style.background = '#F0F0F0'">
</TR></td>
<Table border="3" style="width:100%; text-align: center" BORDERCOLOR=#F0F0F0>
<TR><td>
<form>
<textarea name="DataArea" rows="23" cols=37></textarea> </Table>
<TR><td>
<p>
<div align="right"><input style="background-color:#F0F0F0; color: #000000; border: 2px transparent" type="BUTTON" value=" OK " class="btn" id="btnc" onclick="SaveFile" onmouseover="btnc.style.background = '#808080'" onmouseout="btnc.style.background = '#F0F0F0'">
<input style="background-color:#F0F0F0; color: #000000; border: 2px transparent" type="BUTTON" value="Cancel" class="btn" id="btnd" onclick="QuitEdit" onmouseover="btnd.style.background = '#808080'" onmouseout="btnd.style.background = '#F0F0F0'">
</div>
</td></TR>
</form>
</body>
</html>
<title>
和 </title>
之间的文本无法设置样式。它用于在 caption/title 栏中设置 Internet Explorer 的 Window 标题。您输入的任何文字都将按字面意思处理。
Windows 控制所有标题栏的外观。您可以在控制面板中 Display/Personalization 小程序的 "Appearance" 或 "Windows Color" 部分中(全局)配置它们。例如,"Active Title Bar" 控制 Windows 用于 currently-active window 的字体和颜色。
编辑:
我重读了你的问题,听起来你的 "title" 可能不是页面标题 (<title>
),而只是你在页面顶部附近显示的一些文本(你重新呼叫您的 "title").
您可以将参数传递给 HTA,但解析它们有点棘手。 HTA 只有 CommandLine
属性,其中 returns 是完整的命令行,包括您的 HTA 的完整路径。为了使事情变得更简单,大多数人选择将他们的参数括在引号中,因此您的命令行可能如下所示:
"c:\my folder\test.hta" "#ddd" "#f00"
在这里,我们将两个参数(HTML 颜色)传递给 HTA。要检索它们,我们可以在引号 (Chr(34)
) 上拆分 CommandLine
属性,我们将得到以下内容:
a = Split(myhta.CommandLine, Chr(34))
a(0) = <blank>
a(1) = "c:\my folder\test.hta"
a(2) = " "
a(3) = "#ddd"
a(4) = " "
a(5) = "#f00"
a(6) = <blank>
因此,a(3)
成为您的第一个参数,a(5)
成为您的第二个参数。现在您可以将这些值分配给 HTML 元素的 style.backgroundColor
和 style.color
属性。
这是一个例子:
<head>
<HTA:APPLICATION
ID="htatest"
APPLICATIONNAME="HTA Test"
>
</head>
<body>
<span id="mytitle">This is a title</span>
</body>
<script language="VBScript">
Sub Window_OnLoad()
a = Split(htatest.CommandLine, Chr(34))
mytitle.style.backgroundcolor = a(3)
mytitle.style.color = a(5)
End Sub
</script>