Skip to content

Commit cc55149

Browse files
authored
Update 2-Html_Gui.au3
1 parent 54e4d7a commit cc55149

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

examples/2-Html_Gui.au3

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Global $sFilePath = @ScriptDir & "\messages.csv"
1212
Global $hGUI
1313

1414
Main()
15+
Exit
1516

1617
Func Main()
1718
; Create GUI with resizing support
@@ -26,14 +27,14 @@ Func Main()
2627
GUICtrlSetFont(-1, 12, Default, $GUI_FONTUNDER, "Segoe UI")
2728
GUICtrlSetColor(-1, 0xFF0000)
2829

29-
; Get the WebView2 Manager object and register events
30-
$_g_oWeb = _NetWebView2_CreateManager("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0", "Manager_", "--allow-file-access-from-files") ; 👈
30+
; Create WebView2 Manager object and register events
31+
$_g_oWeb = _NetWebView2_CreateManager("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0", "__MyEVENTS_Manager_", "--allow-file-access-from-files")
3132

3233
; initialize browser - put it on the GUI
3334
Local $sProfileDirectory = @TempDir & "\NetWebView2Lib-UserDataFolder"
3435
_NetWebView2_Initialize($_g_oWeb, $hGUI, $sProfileDirectory, 0, 50, 500, 400, True, False, False, 1.1)
3536

36-
; Get the bridge object and register events
37+
; Create bridge object and register events
3738
Local $oBridge = _NetWebView2_GetBridge($_g_oWeb, "__MyEVENTS_Bridge_")
3839
#forceref $oBridge
3940

@@ -47,25 +48,25 @@ Func Main()
4748
While 1
4849
Switch GUIGetMsg()
4950
Case $GUI_EVENT_CLOSE
50-
$_g_oWeb.Cleanup()
51-
Exit
51+
_NetWebView2_CleanUp($_g_oWeb, $oBridge)
52+
ExitLoop
5253

5354
Case $idBlue
5455
; Update CSS variables dynamically via JavaScript
55-
$_g_oWeb.ExecuteScript("document.documentElement.style.setProperty('--accent-color', '#4db8ff');")
56-
$_g_oWeb.ExecuteScript("document.documentElement.style.setProperty('--btn-color', '#0078d7');")
56+
_NetWebView2_ExecuteScript($_g_oWeb, "document.documentElement.style.setProperty('--accent-color', '#4db8ff');")
57+
_NetWebView2_ExecuteScript($_g_oWeb, "document.documentElement.style.setProperty('--btn-color', '#0078d7');")
5758

5859
Case $idRed
5960
; Update CSS variables dynamically via JavaScript
60-
$_g_oWeb.ExecuteScript("document.documentElement.style.setProperty('--accent-color', '#ff4d4d');")
61-
$_g_oWeb.ExecuteScript("document.documentElement.style.setProperty('--btn-color', '#d70000');")
61+
_NetWebView2_ExecuteScript($_g_oWeb, "document.documentElement.style.setProperty('--accent-color', '#ff4d4d');")
62+
_NetWebView2_ExecuteScript($_g_oWeb, "document.documentElement.style.setProperty('--btn-color', '#d70000');")
6263
EndSwitch
6364
WEnd
6465

6566
EndFunc ;==>Main
6667

6768
; Handles data received from the WebView2 Manager
68-
Func __MyEVENTS_OnMessageReceived($sMessage)
69+
Func __MyEVENTS_Manager_OnMessageReceived($sMessage)
6970
; Local error handler for COM objects
7071
Local $oMyError = ObjEvent("AutoIt.Error", __HtmlGUI_ErrFunc)
7172
#forceref $oMyError
@@ -77,7 +78,7 @@ Func __MyEVENTS_OnMessageReceived($sMessage)
7778
$_g_oWeb.NavigateToString($sHTML)
7879
GUISetState(@SW_SHOW, $hGUI)
7980
EndIf
80-
EndFunc ;==>__MyEVENTS_OnMessageReceived
81+
EndFunc ;==>__MyEVENTS_Manager_OnMessageReceived
8182

8283
; Handles data received from the JavaScript 'postMessage'
8384
Func __MyEVENTS_Bridge_OnMessageReceived($sMessage)

0 commit comments

Comments
 (0)