Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
%Unicode = 1
%UseWebBrowser = 1 ' // Use the WebBrowser control
#Include Once "CWindow.inc" ' // CWindow class
Enum Equates Singular
IDC_WebBrowser = 1000
IDC_NewThread
IDC_InsertTitleText
IDC_InsertBodyText
IDC_InsertImage
IDC_PressOk
End Enum
Function PBMain
Local hDlg As Dword, bstrURL As WString, pWindow As IWindow
Dialog New Pixels, 0, "WebBrowser Search Test", , , 800, 1000, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_NewThread, "New Thread", 10,10,85,20
Control Add Button, hDlg, %IDC_InsertTitleText, "Insert Title", 105,10,85,20
Control Add Button, hDlg, %IDC_InsertBodyText, "Insert Body", 200,10,85,20
Control Add Button, hDlg, %IDC_InsertImage, "Insert Image", 295,10,85,20
Control Add Button, hDlg, %IDC_PressOK, "Press OK", 390,10,85,20
pWindow = Class "CWindow"
bstrURL = "http://www.powerbasic.com/support/pbforums/forumdisplay.php?f=23"
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 As IHTMLElement
Local temp$,tmp$$, V As Variant, i,j,k,iCount,iResult As Long
Local oEnum As IEnumVARIANT
Select Case CbMsg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_NewThread
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
For i = 0 To Elems.Length - 1 'zero based element count
V = i
pIWebBrowser2 = Elems.item(ByVal V, ByVal V)
E = pIWebBrowser2
tmp$$ = E.toString
If InStr(tmp$$,"newthread") Then
temp$ = temp$ + $CrLf + tmp$$
E.click
Exit For
End If
Next i
Case %IDC_InsertTitleText
hBrowser = GetDlgItem(Cb.Hndl,%IDC_WebBrowser)
pIWebBrowser2 = OC_GetDispatch(hBrowser) 'reference to webbrowser control default interface
pIHTMLDocument2 = pIWebBrowser2.Document
Elems = pIHTMLDocument2.all 'get links collection
For i = 0 To Elems.Length - 1 'zero based element count
V = i
pIWebBrowser2 = Elems.item(ByVal V, ByVal V)
E = pIWebBrowser2
tmp$$ = E.classname
If E.classname = "bginput" Then
If E.value = "subject" Then
temp$ = temp$ + $CrLf + tmp$$
End If
End If
Next i
? "Tags: " + Str$(Elems.Length) + $CrLf + temp$
Case %IDC_InsertBodyText
hBrowser = GetDlgItem(Cb.Hndl,%IDC_WebBrowser)
pIWebBrowser2 = OC_GetDispatch(hBrowser) 'reference to webbrowser control default interface
pIHTMLDocument2 = pIWebBrowser2.Document
tmp$$ = "sbutton"
pIHTMLDocument3 = pIHTMLDocument2
Elems = pIHTMLDocument3.GetElementsByName(tmp$$)
For i = 0 To Elems.Length - 1 'zero based element count
V = i
pIWebBrowser2 = Elems.item(ByVal V, ByVal V)
E = pIWebBrowser2
tmp$$ = E.toString
temp$ = temp$ + $CrLf + tmp$$
Next i
? "Tags: " + Str$(Elems.Length) + $CrLf + temp$
Case %IDC_PressOK
hBrowser = GetDlgItem(Cb.Hndl,%IDC_WebBrowser)
pIWebBrowser2 = OC_GetDispatch(hBrowser) 'reference to webbrowser control default interface
pIHTMLDocument2 = pIWebBrowser2.Document
Elems = pIHTMLDocument2.all 'get links collection
For i = 0 To Elems.Length - 1 'zero based element count
V = i
pIWebBrowser2 = Elems.item(ByVal V, ByVal V)
E = pIWebBrowser2
tmp$$ = E.classname
If E.classname = "bginput" Then temp$ = temp$ + $CrLf + tmp$$
If E.classname = "bg" Then temp$ = temp$ + $CrLf + tmp$$
If E.classname = "button" Then temp$ = temp$ + $CrLf + tmp$$
Next i
? "Tags: " + 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
'gbs_01430
'Date: 10-17-2014
http://www.garybeene.com/sw/gbsnippets.htm