创建消息框/弹出消息

时间:2013-09-14 17:11:24

标签: vbscript hta

请参阅这些消息框图像

1:http://catalinx.homeftp.org/img/Autoiterror1.jpg 2:http://www.exceltrick.com/wp-content/uploads/2013/02/Messagebox-Example-5.png

我可以在记事本中使用vbs创建这样的消息框,如第一张图片所示。但点击按钮就像在第二张图片中。怎么解决?我正在制作一个HTA应用程序。

我问的是如何以新的方式添加特定的按钮组。例如,请参阅2个方法:

MsgBox "Hello", 48

Alert "Hello"

两者都与感叹号显示相同的内容。但是OK按钮的风格是不同的。如果我们使用第二个,它比第一个更漂亮。所以我想在第二种方法中添加一个取消按钮,如下所示

Msgbox "Hello",17

如何?

5 个答案:

答案 0 :(得分:1)

你做不到。 Alert只接受一个参数:要显示的消息。如果您想控制图标和/或按钮,则必须使用MsgBox或构建自己的custom dialog

答案 1 :(得分:1)

X=MsgBox ("hello",48, " ")

说明

X=MsgBox ("your message",(button options) ,"title")

答案 2 :(得分:0)

我知道这篇文章有点旧,但我偶然发现它正在寻找其他东西。因为我在这里......

我保留这个小VBScript随时可以使用msgBox而无法想到我头顶的响应。你想要是/否,确定/取消,中止/重试/取消....?只需将其粘贴到带有记事本的.VBS文件中,以备将来参考。

编辑文件以查看您要查找的按钮语法,或双击VBS以查看每个按钮的工作方式。

享受!

Sample = msgBox("Option codes 0+64." & vbCrLf & vbCrLf & "This is an information situation with OK only",0+64, "Information.")
    Select Case Sample
        Case 1
            wScript.Echo "You acknowledged."
    End Select

Sample = msgBox("Option codes 1+48." & vbCrLf & vbCrLf & "This is a warning situation with OK and Cancel",1+48, "WARNING!")
    Select Case Sample
        Case 1
            wScript.Echo "You chose OK."
        Case 2
            wScript.Echo "You chose Cancel."
    End Select

Sample = msgBox("Option codes 2+16." & vbCrLf & vbCrLf & "This is a critical situation with Abort, Retry, and Ignore",2+16, "CRITICAL!")
    Select Case Sample
        Case 3
            wScript.Echo "You chose Abort."
        Case 4
            wScript.Echo "You chose Retry."
    Case 5
        wScript.Echo "You chose Ignore."
    End Select

Sample = msgBox("Option codes 0+16." & vbCrLf & vbCrLf & "This is a critical error situation with OK only",0+16, "CRITICAL ERROR!")
    Select Case Sample
        Case 1
            wScript.Echo "You acknowledged."
    End Select

Sample = msgBox("Option codes 3+32." & vbCrLf & vbCrLf & "This is a question situation with Yes, No, or Cancel",3+32, "Question?")
    Select Case Sample
        Case 6
            wScript.Echo "You said Yes."
        Case 7
            wScript.Echo "You said No."
        Case 2
            wScript.Echo "You clicked Cancel."
    End Select

Sample = msgBox("Option codes 4+32." & vbCrLf & vbCrLf & "This is a question situation with Yes or No only",4+32, "Question?")
    Select Case Sample
        Case 6
            wScript.Echo "You said Yes."
        Case 7
            wScript.Echo "You said No."
    End Select

Sample = msgBox("Option codes 5+16." & vbCrLf & vbCrLf & "This is a critical error situation with Retry or Cancel",5+16, "CRITICAL ERROR!")
    Select Case Sample
        Case 4
            wScript.Echo "You clicked Retry."
        Case 2
            wScript.Echo "You clicked Cancel."
    End Select

答案 3 :(得分:0)

HTA文件可通过VBS文件创建然后删除:

Set fso = CreateObject("Scripting.FileSystemObject") 

sHtml = "<div>Value 1 " & _
    "<input id='txt1' style='width: 100px'>" & _
  "</div>" & _
  "<div>Value 2 " & _
    "<select id='txt2' style='width: 100px'>" & _
      "<option value='A'>A</option>" & _
      "<option value='B'>B</option>" & _
      "<option value='C'>D</option>" & _
    "</select>" & _
  "</div>" & _
  "<p align=center>" & _
    "<input type='button' value='Send' onclick='Send()'> " & _
    "<input type='button' value='Close' onclick='self.Close()'>" & _
  "</p>"

  Set oRet = OpenDialog(sHtml, "txt1,txt2", 300, 200, "Dialog 1")
  MsgBox "Value 1: " & oRet("txt1") & ", Value 2: " & oRet("txt2")

'==================================
Function OpenDialog(sHtml, sFields,iWidth,iHeight, sTitle)
  sHtaFilePath = Wscript.ScriptFullName & ".hta"

  CreateHtaFile sHtaFilePath, sHtml, sFields,iWidth,iHeight,sTitle

  Set f = fso.GetFile(sHtaFilePath)
  f.attributes = f.attributes + 2 'Hidden

  Dim oShell: Set oShell = CreateObject("WScript.Shell")

  oShell.Run """" & sHtaFilePath & """", 1, True

  If fso.FileExists(sHtaFilePath) Then
    fso.DeleteFile sHtaFilePath
  End If

  Set oRet = CreateObject("Scripting.Dictionary")

  'Load return data from XML File
  If fso.FileExists(sHtaFilePath & ".xml") Then
      Set oXml = CreateObject("Microsoft.XMLDOM")
      oXML.async = False
      oXML.load sHtaFilePath & ".xml"

      For each sField In Split(sFields,",")
        oRet.Add trim(sField), oXML.SelectSingleNode("/root/" & trim(sField)).text
      Next

      fso.DeleteFile sHtaFilePath & ".xml"
  End If

  Set OpenDialog = oRet
End Function

Sub CreateHtaFile(sHtaFilePath, sHtml, sFields, iWidth, iHeight, sTitle)
  Set f = fso.CreateTextFile(sHtaFilePath, True)
  f.WriteLine "<html><title>FL Reporting</title><head><HTA:APPLICATION ID=oHTA SINGLEINSTANCE=""yes"" SCROLL=""no""/></head>"
  f.WriteLine "<script language=""vbscript"">"
  f.WriteLine "Window.ResizeTo " & iWidth & ", " & iHeight
  f.WriteLine "Set fso = CreateObject(""Scripting.FileSystemObject"")"
  f.WriteLine ""
  f.WriteLine "Sub Send()"
  f.WriteLine " Dim sFilePath: sFilePath = Replace(location.href,""file:///"","""")"
  f.WriteLine " sFilePath = Replace(sFilePath,""/"",""\"")"
  f.WriteLine " sFilePath = Replace(sFilePath,""%20"","" "")"
  f.WriteLine " Set oXml = CreateObject(""Microsoft.XMLDOM"")"
  f.WriteLine " Set oRoot = oXml.createElement(""root"")"
  f.WriteLine " oXml.appendChild oRoot"

  For each sField In Split(sFields,",")
    f.WriteLine " AddXmlVal oXml, oRoot, """ & sField & """, GetVal(" & sField & ")"
  Next

  f.WriteLine " oXml.Save sFilePath & "".xml"""
  f.WriteLine " self.Close()"
  f.WriteLine "End Sub"
  f.WriteLine ""
  f.WriteLine "Sub AddXmlVal(oXml, oRoot, sName, sVal)"
  f.WriteLine " Set oNode = oXml.createElement(sName)"
  f.WriteLine " oNode.Text = sVal"
  f.WriteLine " oRoot.appendChild oNode"
  f.WriteLine "End Sub"
  f.WriteLine ""
  f.WriteLine "Function GetVal(o)"
  f.WriteLine " GetVal = o.value"
  f.WriteLine " If o.Type = ""checkbox"" Then"
  f.WriteLine "   If o.checked = False Then"
  f.WriteLine "     GetVal = """""
  f.WriteLine "   End If"
  f.WriteLine " End If"
  f.WriteLine "End Function"  
  f.WriteLine "</script>"
  f.WriteLine "<body>"
  f.WriteLine sHtml
  f.WriteLine "</body></html>"
  f.Close
End Sub

答案 4 :(得分:0)

这是直接从 vbsedit.com 上撕下来的:

intButton = object.Popup(strText,[nSecondsToWait],[strTitle],[nType])