VBS Replace message box instead of place on top

試著忘記壹切 提交于 2019-12-02 04:23:47

问题


I have this VBS script to create a message box.

x=msgbox("The message" ,6, "Title")

But if i run another script with a different message it puts it on top. The vbs is been called from a batch file with this code:

@echo off & %temp%\message.vbs

My question is how do i make it so it replaces the message rather than putting it on top.


回答1:


VBScript allows replacing the text in the window, even from different scripts. Uses HTA, no temp files.

showmessage "Time is " & now

sub showmessage(text)
    ' source http://forum.script-coding.com/viewtopic.php?pid=75356#p75356
    dim shellwnd, proc, wnd
    on error resume next
    for each shellwnd in createobject("Shell.Application").windows
        set wnd = shellwnd.getproperty("messagewindow")
        if err.number = 0 then
            wnd.document.body.innerhtml = text
            exit sub
        end if
        err.clear
    next
    do
        set proc = createobject("WScript.Shell").exec("mshta ""about:<html><head><script>moveTo(-32000,-32000);</script><hta:application id=app border=dialog minimizebutton=no maximizebutton=no scroll=no showintaskbar=yes contextmenu=no selection=no innerborder=no /><object id='shellwindow' classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'><param name=RegisterAsBrowser value=1></object><script>shellwindow.putproperty('messagewindow',document.parentWindow);</script></head></html>""")
        do
            if proc.status > 0 then exit do
            for each shellwnd in createobject("Shell.Application").windows
                set wnd = shellwnd.getproperty("messagewindow")
                if err.number = 0 then
                    with wnd
                        .document.title = "Message"
                        .document.body.style.background = "buttonface"
                        .document.body.style.fontfamily = "verdana"
                        .document.body.style.fontsize = "0.7em"
                        .document.body.innerhtml = text
                        .resizeto 300, 150
                        .moveto 200, 200
                    end with
                    exit sub
                end if
                err.clear
            next
        loop
    loop
end sub



回答2:


VBScript doesn't allow replacing the text in message boxes, not even from the same script.



来源:https://stackoverflow.com/questions/22477468/vbs-replace-message-box-instead-of-place-on-top

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