Syntax
WebViewWidget = CreateWebView(x, y, Width, Height, URL$="", Flags=#Null)
Description
Creates a specialized ProGUI widget that embeds a native WebView2 control (Microsoft Edge Chromium). This allows displaying web content directly within a ProGUI application. It requires the WebView2 Runtime to be installed on the system.
Parameters
x, y, Width, Height
Initial position and ideal size hints (in DIPs), similar to
CreateWidget(). The layout engine will determine the final size and
position.
URL$ (optional)
The initial URL to navigate to when the WebView is created.
Default is "" (blank page).
Flags (optional)
Standard widget flags (e.g., #PG_Widget_Hide).
Default is #Null.
Return Value
Returns a handle to the newly created WebView wrapper widget object if successful, or #Null
if creation failed (e.g., WebView2 Runtime not found).
Remarks
This widget relies on the Microsoft Edge WebView2 Runtime. Ensure the runtime is installed on the target machine. ProGUI uses graphics capture (specifically Windows.Graphics.Capture) to integrate the WebView2 rendering into its own drawing pipeline, allowing it to be placed and layered like any other ProGUI widget. Use WebViewNavigate() to change the displayed URL after creation. The widget automatically handles resizing and visibility changes internally.
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
; Example: Navigate to a different page after a delay (using animation timer)
Procedure DelayedNavHandler(Widget, EventType, *EventData.PG_EventAnimate, URL$)
If EventType = #PG_Event_Animate And *EventData\state = #PG_Event_Animate_End
Debug "Navigating to: " + URL$
WebViewNavigate(Widget, URL$)
EndIf
EndProcedure
MyWindow = CreateWindow(0, 0, 800, 600, "WebView2 Example")
RootLayout = WindowGetLayout(MyWindow)
LayoutSetType(RootLayout, #PG_Layout_Type_Flex)
LayoutSetPadding(RootLayout, 10)
If MyWindow
; Create the WebView widget, initially loading the ProGUI website
MyWebView = CreateWebView(0, 0, #PG_Widget_FitContent, #PG_Widget_FitContent, "https://www.progui.co.uk/")
If MyWebView
WidgetSetMinWidth(MyWebView, 400) ; Give it a minimum size
WidgetSetMinHeight(MyWebView, 400)
WidgetSetMargin(MyWebView, 5)
Debug "WebView created."
AddEventHandler(MyWebView, #PG_Event_Animate, @DelayedNavHandler(), "https://www.google.com")
StartAnimation(MyWebView, 1, 5000) ; ID 1, Delay 5000ms before navigating
Else
Debug "Failed to create WebView. Is WebView2 Runtime installed?"
EndIf
WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()
See Also
WebViewNavigate, CreateWidget, CreateOsWidget
Supported OS
Windows (Requires WebView2 Runtime)