Ability to access the underlaying HWND
Is your feature request related to a problem? Please describe. Although the current provided API has a wide coverage to more common use cases, some low-level operations via Win32 API are still mandatory from time to time. In this case, the ability to get the actual HWND for the webview would be necessary.
Describe the solution you'd like
Add the hwnd() or any variant to the WebView type to get the hwnd inside the InnerWebView.
Describe alternatives you've considered
Current there's no other way to get the HWND as far as I can tell. Since the webview does not have a title, the FindWindowW function cannot be used to retrieve the handle for webview window. Also, the hwnd itself has been hidden behind the InnerWebView and WebView is only served as a proxy to work with the inner one.
The WebView2 library makes it intentionally hard to get the hwnd, i think this is this bs we do to get it: https://github.com/tauri-apps/wry/blob/9ff1b66b52d14681711403d8c7d41347c46dc741/src/webview2/drag_drop.rs#L51-L61
The hwnd you see in the InnerWebView is the hwnd of the parent window that you provide yourself.
Sorry for the late reply. I've tried this method after I opened the issue, but more than one HWND was reported (4 in my case, The parent HWND is the winit window created by bevy). How do I ensure which one is the one for the webview and manipulate it without accidentally tweaking others?
I've managed to do this in a somewhat quirky way.
- Build the webview by passing the bevy's
HWND - Use
EnumChildWindowsto iterate through the hierarchy. - Use
GetWindowLongPtrW(hwnd, GWLP_WNDPROC)in the function passed into step 2. - The first
HWNDreturned non-zero value seems to be the one.
There're actually 2 windows returning non-zero, I'm just assuming the first one is the one by using subclass and print out the message it received.