在工程中引用MSHTML库Private Type POINTAPI x As Long y As Long End Type Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As LongPrivate WithEvents objDocument As HTMLDocumentPrivate Sub Form_Load() WebBrowser1.Navigate2 "http://www.baidu.com" End SubPrivate Sub Form_Resize() On Error Resume Next With WebBrowser1 .Move .Left, .Top, ScaleWidth - .Left * 2, ScaleHeight - .Top - .Left End With End SubPrivate Function objDocument_onclick() As Boolean Dim pt As POINTAPI Dim hWnd As Long Dim objDoc As IHTMLDocument2 Dim objElement As IHTMLElement
Set objDoc = objDocument Set objElement = objDoc.elementFromPoint(pt.x, pt.y) If Not objElement Is Nothing Then MsgBox "" & objElement.outerText End If objDocument_onclick = True End FunctionPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant) If Not pDisp Is Nothing Then Set objDocument = pDisp.Document End Sub
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As LongPrivate WithEvents objDocument As HTMLDocumentPrivate Sub Form_Load()
WebBrowser1.Navigate2 "http://www.baidu.com"
End SubPrivate Sub Form_Resize()
On Error Resume Next
With WebBrowser1
.Move .Left, .Top, ScaleWidth - .Left * 2, ScaleHeight - .Top - .Left
End With
End SubPrivate Function objDocument_onclick() As Boolean
Dim pt As POINTAPI
Dim hWnd As Long
Dim objDoc As IHTMLDocument2
Dim objElement As IHTMLElement
GetCursorPos pt
hWnd = WindowFromPoint(pt.x, pt.y)
ScreenToClient hWnd, pt
Set objDoc = objDocument
Set objElement = objDoc.elementFromPoint(pt.x, pt.y)
If Not objElement Is Nothing Then
MsgBox "" & objElement.outerText
End If
objDocument_onclick = True
End FunctionPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If Not pDisp Is Nothing Then Set objDocument = pDisp.Document
End Sub
一般人家用html做界面应该不会使用这个技术的吧?