Has anyone been able to get WinSetTransColor to play nice with Webview2, so mouse events (clicking, hovering) over the non-transparent part of the page doesn't simply fall through?
To illustarte, if I run this
Code: Select all
MyGui := Gui('+AlwaysOnTop')
MyGui.BackColor := "F0F0F0"
MyGui.OnEvent('Close', (*) => (wvc := wv := 0))
MyGui.Show(Format('w{} h{}', A_ScreenWidth * 0.5, A_ScreenHeight * 0.5))
wvc := WebView2.create(MyGui.Hwnd)
wv := wvc.CoreWebView2
wv.NavigateToString('<html><head><style>.square{width: 100px; height: 100px; background: red; margin: auto; font-size: 2em} .square:hover{zoom: 2} body {display:flex;}</style></head><body><div class=square>hover me</div></body></html>')
I get a non-transparent page (with gray background), and if I hover over the red square the red square will double in size. So far, so good.
- image.png (512.8 KiB) Viewed 5185 times
But I want to make everything except the red square transparent. And this I can do by adding this line
Code: Select all
MyGui := Gui('+AlwaysOnTop')
MyGui.BackColor := "F0F0F0"
MyGui.OnEvent('Close', (*) => (wvc := wv := 0))
WinSetTransColor(MyGui.BackColor, MyGui) ; 👈👈👈
MyGui.Show(Format('w{} h{}', A_ScreenWidth * 0.5, A_ScreenHeight * 0.5))
wvc := WebView2.create(MyGui.Hwnd)
wv := wvc.CoreWebView2
wv.NavigateToString('<html><head><style>.square{width: 100px; height: 100px; background: red; margin: auto; font-size: 2em} .square:hover{zoom: 2} body {display:flex;}</style></head><body><div class=square>hover me</div></body></html>')
Now when I run this code, there's only the red square showing on the screen.
- image.png (1.69 MiB) Viewed 5185 times
However, if I click or hover on the red square, nothing happens, and the mouse events simply fall through to whatever window is behind it. But that's not how WinSetTransColor normally works: normally, if the user clicks on a pixel made transparent by WinSetTransColor, the click will fall through, but if the user clicks on a visible pixel, the click will be captured by the window.