Date: 02-16-2022
Return to Index
created by gbSnippets
'Credit: Jose Roca and Dominic Mitchell
'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 Links", 10,10,140,20
pWindow = Class "CWindow"
bstrURL = "http://www.powerbasic.com/support/pbforums/showthread.php?t=40946"
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 Elems As IHTMLElementCollection
Local E As IHTMLElement
Local temp$,tmp$$, V As Variant, i,iCount As Long
Local oEnum As IEnumVariant
Select Case CbMsg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_FindLinks
hBrowser = GetDlgItem(Cb.Hndl,%IDC_WebBrowser)
pIWebBrowser2 = OC_GetDispatch(hBrowser) 'reference to webbrowser control default interface
pIHTMLDocument2 = pIWebBrowser2.Document
Elems = pIHTMLDocument2.links 'get links collection
oEnum = Elems.newEnum
Do
oEnum.Next 1, V, iCount
If iCount = 0 Then Exit Do
E = V
tmp$$ = E.toString
temp$ = temp$ + $CrLf + tmp$$
Loop
? "Links: " + Str$(Elems.Length) + $CrLf + temp$
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
Interface IEnumVARIANT $IID_IENUMVARIANT
Inherit IUnknown
Method Next(In ByVal celt As Dword, In ByRef rgvar As Variant, Out ByRef pceltFetched As Dword) As Long
Method Skip(In ByVal celt As Dword) As Long
Method Reset() As Long
Method Clone(Out ByRef ppenum As IEnumVARIANT) As Long
End Interface
'gbs_01321
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm