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
' Internet Explort ... Scripting Object Interfaces http://msdn.microsoft.com/en-us/library/hh801967%28v=vs.85%29.aspx
' IHTMLDocument2 http://msdn.microsoft.com/en-us/library/aa752574%28v=vs.85%29.aspx
' IHTMLDocument3 http://msdn.microsoft.com/en-us/library/aa752541%28v=vs.85%29.aspx
Enum Equates Singular
IDC_WebBrowser = 1000
IDC_NewThread
IDC_InsertTitleText
IDC_InsertBodyText
IDC_PressInsertImage
IDC_InsertImageName
IDC_PressOk
IDC_SubmitNewThread
End Enum
Function PBMain
Local hDlg As Dword, bstrURL As WString, pWindow As IWindow
Dialog Font "Tahoma",9,0
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 Text", 200,10,105,20
Control Add Button, hDlg, %IDC_PressInsertImage, "Press Insert Image", 315,10,120,20
Control Add Button, hDlg, %IDC_InsertImageName, "Insert Image Name", 445,10,120,20
Control Add Button, hDlg, %IDC_PressOK, "Press OK", 575,10,85,20
Control Add Button, hDlg, %IDC_SubmitNewThread, "Submit New Thread", 665,10,120,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 bstrID As WString
Local temp$,tmp$$, i,j,k,iCount,iResult As Long
Local oEnum As IEnumVARIANT
Local vOpt As Variant
vOpt = Error %Disp_E_ParamNotFound
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
pIWebBrowser2 = Elems.item(i,i)
E = pIWebBrowser2
tmp$$ = E.toString
If InStr(tmp$$,"newthread") Then E.click : Exit For
Next i
Case %IDC_InsertTitleText
hBrowser = GetDlgItem(Cb.Hndl,%IDC_WebBrowser)
pIWebBrowser2 = OC_GetDispatch(hBrowser) 'reference to webbrowser control default interface
pIHTMLDocument2 = pIWebBrowser2.Document
pIHTMLDocument3 = pIHTMLDocument2
Elems = pIHTMLDocument3.getElementsbyName("subject")
For i = 0 To Elems.Length - 1 'zero based element count
pIWebBrowser2 = Elems.item(i,i)
E = pIWebBrowser2
E.innerText = "Thank you Jose!"
Next i
Case %IDC_PressInsertImage
hBrowser = GetDlgItem(Cb.Hndl,%IDC_WebBrowser)
pIWebBrowser2 = OC_GetDispatch(hBrowser) 'reference to webbrowser control default interface
pIHTMLDocument2 = pIWebBrowser2.Document
pIHTMLDocument3 = pIHTMLDocument2
E = pIHTMLDocument3.getElementbyID("vB_Editor_001_cmd_insertimage")
E.click
Case %IDC_SubmitNewThread
hBrowser = GetDlgItem(Cb.Hndl,%IDC_WebBrowser)
pIWebBrowser2 = OC_GetDispatch(hBrowser) 'reference to webbrowser control default interface
pIHTMLDocument2 = pIWebBrowser2.Document
pIHTMLDocument3 = pIHTMLDocument2
E = pIHTMLDocument3.getElementbyID("vB_Editor_001_save")
E.click
'======================================================================================================
Case %IDC_InsertBodyText
hBrowser = GetDlgItem(Cb.Hndl,%IDC_WebBrowser)
pIWebBrowser2 = OC_GetDispatch(hBrowser) 'reference to webbrowser control default interface
pIHTMLDocument2 = pIWebBrowser2.Document
pIHTMLDocument3 = pIHTMLDocument2
Elems = pIHTMLDocument3.getElementsByName("message")
? Str$(Elems.length)
For i = 0 To Elems.Length - 1 'zero based element count
pIWebBrowser2 = Elems.item(i,i)
E = pIWebBrowser2
E.innerText = "Jose messageA"
E.innerHTML = "Jose messageB"
E.outerText = "Jose messageC" '<-------- does something
E.outerHTML = "Jose messageD"
Next i
? "pause9"
Elems = pIHTMLDocument2.all
For i = 0 To Elems.Length - 1 'zero based element count
pIWebBrowser2 = Elems.item(i,i)
E = pIWebBrowser2
If E.className = "wysiwyg" Then ? "wysiwyg"
Next i
? "pausea"
Elems = pIHTMLDocument2.all
For i = 0 To Elems.Length - 1 'zero based element count
pIWebBrowser2 = Elems.item(i,i)
E = pIWebBrowser2
If E.className = "wysiwyg" Then E.innerText = "Thank you Jose!"
Next i
? "pauseb"
Elems = pIHTMLDocument3.getElementsbyName("wysiwyg")
For i = 0 To Elems.Length - 1 'zero based element count
pIWebBrowser2 = Elems.item(i,i)
E = pIWebBrowser2
E.innerText = "Thank you Jose!"
E.innerHTML = "Thank you Jose!"
Next i
? "pausec"
Elems = pIHTMLDocument3.getElementsbyTagName("textarea")
? Str$(Elems.length)
For i = 0 To Elems.Length - 1 'zero based element count
pIWebBrowser2 = Elems.item(i,i)
E = pIWebBrowser2
IHTMLDocument_SetElementValueByID( pIHTMLDocument2, E.ID, "Thank you Jose" )
Next i
? "pauseca"
IHTMLDocument_setElementValueByID pIHTMLDocument2, "wysiwyg", "Jose's approach works!"
? "paused"
IHTMLDocument_setElementValueByID pIHTMLDocument2, "vB_Editor_001", "Jose's approach works!"
? "pausee"
IHTMLDocument_setElementValueByID pIHTMLDocument2, "vB_Editor_001_mode", "Jose's approach works!"
? "pausef"
IHTMLDocument_setElementValueByID pIHTMLDocument2, "vB_Editor_001_textarea", "Jose's approach works!"
? "pauseg"
IHTMLDocument_setElementValueByID pIHTMLDocument2, "vB_Editor_001.vBulletin_editor", "Jose's approach works!"
? "pauseh"
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_01431
'Date: 10-17-2014
http://www.garybeene.com/sw/gbsnippets.htm