Skip to content

Commit 15004a0

Browse files
authored
021-ModernSidebarUI.au3
1 parent ba659ab commit 15004a0

1 file changed

Lines changed: 90 additions & 0 deletions

File tree

examples/021-ModernSidebarUI.au3

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
; https:
2+
;----------------------------------------------------------------------------------------
3+
; Title...........: 021-ModernSidebarUI.au3
4+
; Description.....: Injects a high-performance, Chromium-based Sidebar into a Win32 GUI using WebView2.
5+
; This method bypasses GDI/Win32 rendering limitations, allowing for full CSS3 animations,
6+
; Vector (SVG) icons, and 100% Color Emoji support.
7+
; AutoIt Version..: 3.3.18.0 Author: ioa747 Script Version: 0.1
8+
; Note............: Testet in Windows 11 Pro 25H2
9+
;----------------------------------------------------------------------------------------
10+
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
11+
#include <GUIConstantsEx.au3>
12+
#include <WindowsConstants.au3>
13+
#include "..\NetWebView2Lib.au3"
14+
15+
; 021-ModernSidebarUI.au3
16+
17+
Global $g_idMemo
18+
19+
_Example()
20+
21+
;---------------------------------------------------------------------------------------
22+
Func _Example()
23+
Local $hGui = GUICreate("Modern Sidebar UI", 550, 410)
24+
GUISetBkColor(0x252526) ; Dark Background
25+
26+
$g_idMemo = GUICtrlCreateEdit("", 160, 10, 370, 390, $WS_VSCROLL, 0)
27+
GUICtrlSetFont(-1, 11, 400, 0, "Courier New")
28+
GUICtrlSetColor(-1, 0xF0F0F0)
29+
GUICtrlSetBkColor(-1, 0x333333)
30+
31+
; We create ONE WebView2 for the entire sidebar
32+
Local $oWebV2M = _NetWebView2_CreateManager()
33+
Local $oBridge = _NetWebView2_GetBridge($oWebV2M, "JS_Events_")
34+
35+
; Initialize on the left side (0, 0, 140, 450)
36+
_NetWebView2_Initialize($oWebV2M, $hGui, @ScriptDir & "\UserData", 0, 0, 140, 410, True)
37+
38+
; Constructing the HTML with all the buttons
39+
Local $sHTML = _GenerateSidebarHTML()
40+
_NetWebView2_NavigateToString($oWebV2M, $sHTML)
41+
42+
GUISetState(@SW_SHOW)
43+
44+
While 1
45+
Switch GUIGetMsg()
46+
Case $GUI_EVENT_CLOSE
47+
ExitLoop
48+
EndSwitch
49+
WEnd
50+
51+
_NetWebView2_CleanUp($oWebV2M, $oBridge)
52+
EndFunc ;==>_Example
53+
;---------------------------------------------------------------------------------------
54+
Func _GenerateSidebarHTML() ; The function that creates the "Menu"
55+
Local $sCSS = "body { margin: 0; background: #252526; font-family: 'Segoe UI', sans-serif; overflow: hidden; padding: 10px; }" & _
56+
".btn { " & _
57+
" width: 100%; padding: 12px; margin-bottom: 8px; border: none; border-radius: 6px; " & _
58+
" background: #333; color: white; text-align: left; cursor: pointer; font-size: 15px; " & _
59+
" transition: 0.2s; display: flex; align-items: center; " & _
60+
"} " & _
61+
".btn:hover { background: #444; transform: translateX(5px); } " & _
62+
".btn span { margin-right: 10px; font-size: 18px; }"
63+
64+
Local $sHTML = "<html><head><style>" & $sCSS & "</style></head><body>"
65+
66+
Local $aLabels[7] = ["🏆 Trophy", "🎯 Target", "⚠️ Warning", "😎 Cool", "👉 Select", "🌏 World", "🚧 Work"]
67+
68+
For $i = 0 To 6
69+
$sHTML &= "<button class='btn' onclick='window.chrome.webview.postMessage(""BTN_CLICKED:" & $i & """)'>" & _
70+
"<span>" & StringLeft($aLabels[$i], 2) & "</span>" & StringTrimLeft($aLabels[$i], 2) & "</button>"
71+
Next
72+
73+
$sHTML &= "</body></html>"
74+
Return $sHTML
75+
EndFunc ;==>_GenerateSidebarHTML
76+
;---------------------------------------------------------------------------------------
77+
Volatile Func JS_Events_OnMessageReceived($oWebV2M, $hGui, $sMessage) ; The Bridge that "catches" clicks
78+
#forceref $oWebV2M, $hGui
79+
If StringLeft($sMessage, 12) = "BTN_CLICKED:" Then
80+
Local $sIndex = StringTrimLeft($sMessage, 12)
81+
; Here you can call any AutoIt function
82+
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83+
MemoWrite("Index button pressed: " & $sIndex)
84+
EndIf
85+
EndFunc ;==>JS_Events_OnMessageReceived
86+
;---------------------------------------------------------------------------------------
87+
Func MemoWrite($sMessage) ; Write a line to the memo control
88+
GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
89+
EndFunc ;==>MemoWrite
90+
;---------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)