Date: 02-16-2022
Return to Index
created by gbSnippets
'Credit: Jose Roca
'DDT's SLEEP or DOEVENTS don't process the messages to the WebBrowser control.
'Therefore, loading of the page is never completed, ReadyState will never
'return %READYSTATE_COMPLETE and the DO/LOOP will run for ever, locking
'your application. AfxPumpMessages works well with both SDK and DDT.
'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_GetText = 1002
Function PBMain
Local hDlg As Dword, pWindow As IWindow
Dialog New Pixels, 0, "WebBrowser", , , 300, 200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_GetText, "Get Text", 10,10,75,20
pWindow = Class "CWindow"
pWindow.AddWebBrowserControl(hDlg, %IDC_WEBBROWSER, "",Nothing, 0, 40, 600,350)
Dialog Show Modal hDlg, Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local pIWebBrowser2 As IWebBrowser2, vURL As Variant, fName$, HTMLText$
Local hBrowser As Dword, pIHTMLDocument As IHTMLDocument2
Select Case CbMsg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_GetText
hBrowser = GetDlgItem(Cb.Hndl,%IDC_WebBrowser)
pIWebBrowser2 = OC_GetDispatch(hBrowser) 'reference to webbrowser control default interface
fName$ = Dir$("*.htm")
While Len(fName$)
vURL = "file:///" + Exe.Path$ + fName$
pIWebBrowser2.Navigate2 vURL
Do
AfxPumpMessages
If pIWebBrowser2.ReadyState = %READYSTATE_COMPLETE Then Exit Do
Loop
pIHTMLDocument = pIWebBrowser2.Document
HTMLText$ = HTMLText$ + $CrLf + pIHTMLDocument.body.innerText
fName$ = Dir$(Next)
Wend
? HTMLText$
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_01308
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm