WebView2 ResFile Demo - Loading HTML from VB6 Resource Files
Overview
Demonstrates how to embed HTML content in VB6 resource files (.RES) and load it at runtime via NavigateToString into WebView2. Suitable for single-file distribution without external HTML file dependencies.
Project Structure
Download Source [ Note: Re-register the DLL file in the bin directory ]
Source code is available in the VBMAN2 project's demos/webview2/resFile directory.
resFile/
├── Form1.frm # Main form, containing resource loading logic
├── vbman2_webview2.RES # VB6 resource file (containing embedded INDEX.HTML)
├── vbman2_webview2.vbp # VB6 project file (contains ResFile32 reference)
└── vbman2_webview2.vbw # VB6 workspace fileCore Code Walkthrough
1. Deferred Initialization (Form1.frm)
Dim WithEvents wv As cWebView2Host
Private Sub Form_Load()
Set wv = New cWebView2Host
wv.Initialize Me.hWnd ' Pass only one parameter, don't navigate immediately
End SubPass only the window handle without a URL, deferring navigation to the wv_Ready event.
2. Loading from Resources in Ready Event
Private Sub wv_Ready()
wv.NavigateToString VBMAN2.Res(LoadResData("INDEX.HTML", "WWW")).ReturnString()
End Sub3. Title Synchronization
Private Sub wv_DocumentTitleChanged()
Me.Caption = wv.DocumentTitle
End SubFeature Description
VB6 Resource File Embedding
- HTML is stored in the .RES file's "WWW" custom resource type
- Resource ID is "INDEX.HTML"
- Embedded in the EXE after compilation, no external files needed
NavigateToString
- Loads HTML string directly into WebView2
- Content uses
about:blankas the base URL - Does not support relative path references to external resources
VBMAN2.Res Helper Function
LoadResData("INDEX.HTML", "WWW")loads raw byte dataVBMAN2.Res()performs encoding conversion.ReturnString()converts to string
Deferred Navigation Pattern
- Initialize without URL
- Navigate in wv_Ready event
- Ensures WebView2 is ready before loading content
Technical Notes
LoadResData is a VB6 built-in function for loading custom resource types. Returns a Byte array
VBMAN2.Res().ReturnString() is a helper method provided by the VBMAN2 library that handles byte-to-string encoding conversion (handling UTF-8, etc.)
NavigateToString Limitations:
- Base URL is
about:blank - Cannot use relative paths to reference external CSS/JS/images
- All resources must be inline (base64 images, inline CSS/JS)
- Base URL is
Resource File Editing: Use the VB6 Resource Editor to add custom resources with resource type "WWW" and ID "INDEX.HTML"
Use Cases
- Single-file EXE distribution (all HTML/CSS/JS embedded in resources)
- About dialogs / help pages
- Simple HTML report display
- Offline applications without external file dependencies
Extension Suggestions
- For HTML with external resource references, combine with SetVirtualHostNameToFolderMapping for resource mapping
- Multiple HTML resources can be embedded, dynamically switching display based on conditions
- Resources containing HTML can interact with VB6 via JS (postMessage / BindUI)