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_Button = 1002
Global hDlg, hBrowser As Dword
Function PBMain
Local hDlg As Dword, pWindow As IWindow, bstrURL As WString
Dialog New Pixels, 0, "WebBrowser", , , 600, 400, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button, "Go",10,10,50,20
pWindow = Class "CWindow"
bstrURL = "MSHTML:<HTML><BODY>This is a line of text</BODY></HTML>"
hBrowser = pWindow.AddWebBrowserControl(hDlg, %IDC_WEBBROWSER, bstrURL, Nothing, 0, 40, 600,360)
Dialog Show Modal hDlg, Call DlgProc
End Function
CallBack Function DlgProc() As Long
If Cb.Msg = %WM_Command And Cb.Ctl = %IDC_Button Then
Local WB As IWebBrowser2, vVar As Variant, temp$$
temp$$ = "<HTML><BODY>Unsupported file type!</BODY></HTML>"
vVar = temp$$
WB = OC_GetDispatch(hBrowser)
Local hr As Long
Local pHTMLText As Dword
Local pStream As IStream
Local pHtmlDocument2 As IHtmlDocument2
Local pPersistStreamInit As IPersistStreamInit
pHTMLText = GlobalAlloc(%GPTR, Len(temp$$) * 2)
If pHTMLText Then
CopyMemory pHTMLText, StrPtr(temp$$), Len(temp$$) * 2
hr = CreateStreamOnHGlobal(pHTMLText, %TRUE, pStream)
If IsObject(pStream) Then
pHtmlDocument2 = WB.Document
If IsObject(pHtmlDocument2) Then
pPersistStreamInit = pHtmlDocument2
If IsObject(pPersistStreamInit) Then
hr = pPersistStreamInit.InitNew
If SUCCEEDED(hr) Then pPersistStreamInit.Load(pStream)
pPersistStreamInit = Nothing
End If
pHtmlDocument2 = Nothing
End If
pStream = Nothing
End If
GlobalFree(pHTMLText)
End If
End If
End Function
'gbs_01334
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm