批处理之家's Archiver

Nsqs 发表于 2016-5-16 17:08

VBS针对MSGBOX的动态修改

[color=Red]仅仅只是针对MSGBOX[/color]的动态修改演示效果。[color=Red]非技术和实用性讨论[/color][code]option explicit
Dim Msg,t
set Msg=new Message
Msg string(13,chr(8)),64,"test"        '设定窗口定长字串
t=10
do
        msg.Change t & "秒后自动退出..."        '动态修改窗口
        wsh.Sleep 1000
        t=t-1
loop until t=0 or not Msg.Exist        '计时器结束或窗口不存在
Msg.Enter        '按下确定
class Message
        dim api,m(1),h
        dim WM_SETTEXT,BM_CLICK,WM_GETTEXT
        Public Default sub Show(byval var,byval dflags,byval title)
        dim wsc,p,i
        set api=CreateObject("VBScript.API")
        set wsc=CreateObject("wscript.shell")
        WM_SETTEXT = &HC:BM_CLICK = &HF5
        WM_GETTEXT = &HD
        if title=empty then        title=wsh.scriptfullname
        if instr(title,"\") then _
                title=mid(title,instrrev(title,"\")+1)
        wsc.run "mshta vbscript:""<script language=vbs>msgbox "_
        &string(2,chr(34))&var&string(2,chr(34))&",64,"_
        &string(2,chr(34))&title&string(2,chr(34))_
        &":self.close</script>""",0
        set wsc=nothing
                do
                h=api.findwindow(vbnullstring,title)
                loop until api.iswindow(h)>0
                p=api.enumsubhwnd(h,"","*")
                for each i in p
                        select case ucase(api.getclassname(i))
                                case "BUTTON"
                                        m(1)=i
                                case "STATIC"
                                        m(0)=i
                        end select
                next
        End Sub
        public Sub Change(byval var)
                dim result
                api.sendmessagestring m(0),WM_SETTEXT,0,var
        end sub
        public sub Enter
                api.SetForegroundWindow m(1)
                api.sendmessagelong m(1),BM_CLICK,0,0
        end sub
        public Function Exist
                exist=api.iswindow(h)
        end Function
        Private Sub Class_Terminate
        set api=nothing
    End Sub
end class[/code]

9zhmke 发表于 2016-5-31 10:06

在WIN10中测试未通过,17行不能创建对象。 不使用外置程序应该也能实现吧?直接另外生成个VBS并运行显示内容,每秒杀掉并重新显示。

Nsqs 发表于 2016-12-11 10:20

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=186347&ptid=40441]2#[/url] [i]9zhmke[/i] [/b]


    我测试win 7 8 10都可以,说明不是我的问题是你自己不会弄

czjt1234 发表于 2017-5-25 18:13

同2楼

没有这个对象CreateObject("VBScript.API")

win7x64
看了注册表,没有这个对象
哦,有附件,看下

老刘1号 发表于 2017-6-30 10:59

类库很丰富啊
常用的API都封装起来了
好评好评

Nsqs 发表于 2017-6-30 13:35

vbsedit可以查看方法,至于说明如何使用,这个要百度。使用方法就不举例了,千万行都写不完!

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.