本帖最后由 wrove 于 2012-12-8 18:53 编辑
- Set hw=New HtmlWindow
- hw.Title="Hello world"
- hw.SetGeometry 500,200,300,200
- hw.Show
- hw.Text="Yes,it's a test!"
- MsgBox hw.Text,vbOKOnly,"Text:"
- MsgBox hw.Title,vbOKOnly,"Title:"
- hw.Close False
- Class HtmlWindow
- Private ws,fso,file,codes,ie,doc
-
- Private Sub Class_Initialize ' 设置 Initialize 事件。
- Set ws=WScript.CreateObject("WScript.Shell")
- Set fso=CreateObject("Scripting.FileSystemObject")
- file=fso.GetAbsolutePathName(fso.GetTempName&".htm")
- Set codes=fso.CreateTextFile(file,True)
- HtmlWindow_Init()
- Set ie=WScript.CreateObject("InternetExplorer.Application")
- ie.AddressBar=False
- ie.ToolBar=False
- codes.Close
- Me.Open file
- End Sub
-
- Private Sub HtmlWindow_Init()
- codes.Write "<HTML>"
- codes.Write "<HEAD>"
- codes.Write "<TITLE id="&Chr(34)&"Title"&Chr(34)&"></TITLE>"
- codes.Write "</HEAD>"
- codes.Write "<BODY>"
- codes.Write "<TEXT id="&Chr(34)&"Text"&Chr(34)&"><TEXT>"
- codes.Write "<BODY>"
- codes.Write "</BODY>"
- End Sub
-
- Public Sub Show()
- ie.Visible=True
- End Sub
-
- Public Sub Refresh()
- codes.Close
- Me.Open file
- End Sub
-
- Public Sub Open(path)
- ie.Navigate fso.GetAbsolutePathName(path)
- Set doc=ie.Document
- End Sub
-
- Public Sub Close(keepHtml)
- Set ws=Nothing
- Set codes=Nothing
- If Not keepHtml Then fso.DeleteFile file
- Set fso=Nothing
- ie.Quit
- End Sub
-
- Public Property Get Left()
- Left=ie.Left
- End Property
- Public Property Let Left(value)
- If TypeName(value)="Long" Or TypeName(value)="Integer" Then
- ie.Left=value
- End If
- End Property
-
- Public Property Get Top()
- Top=ie.Top
- End Property
- Public Property Let Top(value)
- If TypeName(value)="Long" Or TypeName(value)="Integer" Then
- ie.Top=value
- End If
- End Property
-
- Public Property Get Width()
- Width=ie.Width
- End Property
- Public Property Let Width(value)
- If TypeName(value)="Long" Or TypeName(value)="Integer" Then
- ie.Width=value
- End If
- End Property
-
- Public Property Get Height()
- Height=ie.Height
- End Property
- Public Property Let Height(value)
- If TypeName(value)="Long" Or TypeName(value)="Integer" Then
- ie.Height=value
- End If
- End Property
-
- Public Sub SetPosition(Left,top)
- Me.Left=Left
- Me.Top=top
- End Sub
-
- Public Sub SetSize(width,height)
- Me.Width=width
- Me.Height=height
- End Sub
-
- Public Sub SetGeometry(Left,top,width,height)
- Me.SetPosition Left,top
- Me.SetSize width,height
- End Sub
-
- Public Sub Move(Left,top)
- Me.SetPosition Left,top
- End Sub
-
- Public Property Get Text()
- Text=doc.getElementById("Text").InnerText
- End Property
-
- Public Property Let Text(value)
- doc.getElementById("Text").InnerText=CStr(value)
- End Property
-
- Public Property Get Title()
- Title=doc.getElementById("Title").InnerText
- End Property
- Public Property Let Title(value)
- doc.getElementById("Title").InnerText=CStr(value)
- End Property
-
- End Class
复制代码 不过,好像源文件并没有改变,最好的方式是对codes重构,而后Refresh |