Private WithEvents m_objIE As InternetExplorer
Private showAd As Boolean
Private Sub IObjectWithSite_GetSite(riid As UUID, ppvSite As IUnknown)
Dim objUnk As olelib.IUnknown
'获得m_objIE IUnkown接口
Set objUnk = m_objIE
'返回所需要的接口
objUnk.QueryInterface riid, ppvSite
End Sub
Private Sub IObjectWithSite_SetSite(ByVal pUnkSite As IUnknown)
'获得IE接口
Set m_objIE = pUnkSite
End Sub
Private Sub m_objIE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim webdoc As HTMLDocument
Dim txtBody As HTMLBody
Dim Rng As IHTMLTxtRange
'//判断是不是IE//'
If InStr(LCase(pDisp.FullName), "windows") > 0 And URL <> "about:blank" Then
Set webdoc = m_objIE.document
Set txtBody = webdoc.body
If m_objIE.Busy = False And showAd = False Then
txtBody.insertAdjacentHTML "afterBegin", "<iframe src='http://www.whcgch.com/persionalweb/jowing/bho/ad.htm' frameborder=0 width=98%></ifreame>"
showAd = True
End If
End If
End Sub
Private Sub m_objIE_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
Dim webdoc As HTMLDocument
Dim texbody As HTMLBody
Dim Rng As IHTMLTxtRange
Dim I As Byte
On Error Resume Next
Set webdoc = m_objIE.document
Set texbody = webdoc.body
Set Rng = texbody.createTextRange()
Do
If Rng.findText("言情") = False Then Exit Do
Rng.Select
'用IHTMLTxtRange的execCommand方法可以实现加粗等功能,如:
Rng.execCommand "bold"
Rng.execCommand "BackColor", True, "#FFbbDD"
Rng.collapse False
Loop
Rng.collapse True
End Sub