Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
%Unicode = 1
%UseWebBrowser = 1 '
#Include Once "CWindow.inc" 'Jose Roca includes
%IDC_WebBrowser = 1001
%IDC_FindLinks = 1002
Function PBMain
Local hDlg As Dword, bstrURL As WString, pWindow As IWindow
Dialog New Pixels, 0, "WebBrowser Search Test", , , 600, 400, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_FindLinks, "Find Tags", 10,10,140,20
pWindow = Class "CWindow"
bstrURL = "file:///" + Exe.Path$ + "test.htm"
pWindow.AddWebBrowserControl(hDlg, %IDC_WEBBROWSER, bstrURL, Nothing, 0, 40, 600,350)
Dialog Show Modal hDlg, Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local hBrowser As Dword
Local pIWebBrowser2 As IWebBrowser2
Local pIHTMLDocument2 As IHTMLDocument2
Local pIHTMLDocument3 As IHTMLDocument3
Local Elems As IHTMLElementCollection
Local E,pSelected As IHTMLElement
Local S As IHTMLStyle
Local temp$,tmp$$, i,iResult As Long
Local pIHTMLSelectionObject As IHTMLSelectionObject
Local pDispatch As IDispatch
Local pIHTMLTxtRangeE As IHTMLTxtRange
Local pIHTMLTxtRangeS As IHTMLTxtRange
Select Case CbMsg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_FindLinks
tmp$$ = "td" 'in this example, find anchor tags
hBrowser = GetDlgItem(Cb.Hndl,%IDC_WebBrowser)
pIWebBrowser2 = OC_GetDispatch(hBrowser) 'reference to webbrowser control default interface
pIHTMLDocument2 = pIWebBrowser2.Document
pIHTMLDocument3 = pIHTMLDocument2
Elems = pIHTMLDocument3.GetElementsByTagName(tmp$$)
pIHTMLSelectionObject = pIHTMLDocument2.selection
pIHTMLTxtRangeS = pIHTMLSelectionObject.createRange 'used to store initial selection text trange
pIHTMLTxtRangeE = pIHTMLSelectionObject.createRange 'used for element text ranges
For i = 0 To Elems.Length - 1 'zero based element count
pDispatch = Elems.item(i,i)
E = pDispatch
S = E.Style
tmp$$ = Variant$$(S.fontSize)
If tmp$$ <> "14pt" Then Iterate For
pIHTMLTxtRangeE.moveToElementText(E)
iResult = pIHTMLTxtRangeE.compareEndPoints("EndToEnd", pIHTMLTxtRangeS)
If iResult = 1 Then pIHTMLTxtRangeE.select : Exit For
Next i
End Select
Case %WM_Size
If Cb.WParam <> %Size_Minimized Then
Local w,h As Long
Dialog Get Client Cb.Hndl To w,h
Control Set Size Cb.Hndl, %IDC_WebBrowser, w, h-40
End If
End Select
End Function
'gbs_01333
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm