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
%IDC_WebBrowser = 1001
%IDC_HighLight = 1006
%IDC_SearchTerm = 1007
Function PBMain
Local hDlg As Dword, bstrURL As WString
Dialog New Pixels, 0, "WebBrowser", , , 800, 1000, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_HighLight, "Highlight", 10,10,100,20
Control Add TextBox, hDlg, %IDC_SearchTerm, "for site", 120,10,100,20
Local pWindow As IWindow
pWindow = Class "CWindow"
bstrURL = "http://www.garybeene.com"
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 pIWebBrowser2 As IWebBrowser2 'instance of the webbrowser control
Local hBrowser As Dword 'handle to window containing web browser
Local pDisp As IDispatch
Local pIHTMLDocument As IHTMLDocument2
Local pIHTMLSelectionObject As IHTMLSelectionObject
Local pDispatch As IDispatch
Local pIHTMLTxtRange As IHTMLTxtRange
Local i, iRes As Integer, tmp$
Select Case CbMsg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Highlight
hBrowser = GetDlgItem(Cb.Hndl,%IDC_WebBrowser)
pIWebBrowser2 = OC_GetDispatch(hBrowser) 'reference to webbrowser control default interface
pIHTMLDocument = pIWebBrowser2.Document
pIHTMLSelectionObject = pIHTMLDocument.selection
pDispatch = pIHTMLSelectionObject.createRange
pIHTMLTxtRange = pDispatch
Control Get Text Cb.Hndl, %IDC_SearchTerm To tmp$
Dim T(0) As String
ReDim T(ParseCount(tmp$,$Spc)-1) As String 'create array of terms
Parse tmp$, T(), " "
For i = 0 To UBound(T)
' pIHTMLSelectionObject.empty
pIHTMLTxtRange.collapse(%VARIANT_FALSE)
PIHTMLTxtRange.moveStart("character",-10000)
iRes = pIHTMLTxtRange.findText(T(i), &H7FFFFFFF???, %FINDTEXT_WHOLEWORD)
Do While iRes
If iRes Then pIHTMLTxtRange.execCommand("BackColor", %VARIANT_TRUE, "Yellow")
pIHTMLTxtRange.collapse(%VARIANT_FALSE)
iRes = pIHTMLTxtRange.findText(T(i), &H7FFFFFFF???, %FINDTEXT_WHOLEWORD)
Loop
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_01326
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm