examples/10-WindowOptions.ps1
|
# 10 - Window options: an icon, a fixed position, a minimum size, always on top - and which engine showed the page. # Run it with -Verbose to see the engine line; -Engine BrowserApp shows the same page in an Edge/Chrome app window. param([ValidateSet("Auto", "WebView2", "WebKitGTK", "WKWebView", "BrowserApp", "DefaultBrowser")] [string] $Engine = "Auto") if (-not (Get-Command Show-NativeWebView -ErrorAction Ignore)) { Import-Module NativeWebView -ErrorAction Stop } $Html = @' <!doctype html> <html><head><style> body { font-family: Verdana, 'Segoe UI', Arial, sans-serif; font-size: 13px; color: #454545; padding: 24px; background: #F9F9F9; } h2 { color: #154363; font-size: 18px; } button { padding: 8px 18px; background: #095495; color: white; border: 0; border-radius: 4px; font: inherit; } #out { color: #4F8035; font-weight: bold; } </style></head> <body> <h2>Always on top</h2> <p>This window has its own icon, opens at 80, 60, cannot be made smaller than 360 x 240 and stays above other windows.</p> <p>Engine: <span id="out">-</span></p> <button id="done">Close</button> <script> kHost.call("engine").then(function (name) { document.getElementById("out").textContent = name; }); document.getElementById("done").onclick = function () { kHost.close("closed by the button"); }; </script> </body></html> '@ $Why = Show-NativeWebView -Html $Html -Title "Window options" -Width 480 -Height 300 -MinWidth 360 -MinHeight 240 ` -Icon (Join-Path $PSScriptRoot "icon.png") -Position 80, 60 -TopMost -Engine $Engine -OnMessage { param($Message, $Window) if ($Message.action -eq "engine") { $Window.Engine() } } Write-Host ("Window ended: " + $Why) |