仅仅只是针对MSGBOX的动态修改演示效果。非技术和实用性讨论- 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
复制代码
|