VB6 - Load html as string example
File(s): LoadFromStringBrowser.frm, html\flipCard3D.html
The load html as string demo as the following code in the Form_Load event:
Private Sub Form_Load()
On Error Resume Next
Me.Show
' show on top!
Call SetWindowPos(Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
EdgeWebBrowser.CreateWebView
Form_Resize
End Sub
This creates the WebView2 control via CreateWebView.
Once the WebView2 control is loaded, it will trigger the OnCreateWebViewCompleted event and that's where we handle the rest.
Private Sub EdgeWebBrowser_OnCreateWebviewCompleted(ByVal HResult As Long)
Dim Html As String
Dim TextLine As String
Dim HtmlFile As String
Dim Path As String
' disable right click menu
EdgeWebBrowser.DefaultContextMenusEnabled = False
' No F12 either
EdgeWebBrowser.DevToolsEnabled = False
' Load the html from file flipCard3D.html
Path = strGetVisualBasicDemoPath
HtmlFile = Path & "\html\flipCard3D.html"
Open HtmlFile For Input As #1
Do Until EOF(1)
Line Input #1, TextLine
Html = Html & TextLine
Loop
Close #1
EdgeWebBrowser.NavigateToString Html
End Sub
We disable the right click menu (DefaultContextMenuEnabled) and turn off the developer tools (DevToolsEnabled) so that the user can no longer "peek behind the scenes".
Next up we locate the html file we want to load.
Read that file into a string Html and once that is done, we display the html via NavigateToString.
AntView - The MS Edge WebView2 ActiveX control Date last changed: 09/30/2024