-
Notifications
You must be signed in to change notification settings - Fork 569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any way to access WindowHandle::get_hwnd on windows? #1505
Comments
There's no direct access because this breaks encapsulation and cross-platform. A better way I think to do that is to expose the handle via https://docs.rs/raw-window-handle/0.3.3; I did that for #1462 on Windows, although it's not published anywhere yet. The code looks like this: unsafe impl HasRawWindowHandle for WindowHandle {
fn raw_window_handle(&self) -> RawWindowHandle {
if let Some(hwnd) = self.0.get_hwnd() {
let handle = raw_window_handle::windows::WindowsHandle {
hwnd: hwnd as *mut libc::c_void,
hinstance: unsafe {
winapi::um::libloaderapi::GetModuleHandleW(0 as winapi::um::winnt::LPCWSTR)
as *mut libc::c_void
},
..raw_window_handle::windows::WindowsHandle::empty()
};
RawWindowHandle::Windows(handle)
} else {
panic!()
}
}
} If this is something the devs are interesting in merging I can make a PR just for that part and rebase my work on top of it. I am curious why you need |
Preventing screenshots of confidential information. A built-in version of opswat or screenwings. The equivalent API in UWP would be IsScreenCaptureEnabled
Given the nature of my use case, it is preferable if the application fails rather than the data leaked. But there should be alternative ways to achieve the same thing under other renderers.
While ideally there wouldn't be any need for it, it is unfeasble to implement all the possible Windows-specific flags/options that need an HWND in a cross-platform way. IMHO allowing the library users to access the unsafe underlying APIs is better than just not being able to do it. |
Actually reading more docs, DWM is always compositing on Windows 10, and I think on 8.1 too. |
I want a principled way of doing these sorts of platform dependent things. I do agree that they're desirable. The thing I keep coming back to is the platform-specific extensions in the rust stdlib, like |
Expose the `HasRawWindowHandle` trait impl of druid-shell for `WindowHandle` into druid itself, so druid users can access it. This is also under a `raw-win-handle` feature, like the druid-shell one. Bug: linebender#1505
Expose the `HasRawWindowHandle` trait impl of druid-shell for `WindowHandle` into druid itself, so druid users can access it. This is also under a `raw-win-handle` feature, like the druid-shell one. Bug: linebender#1505
Expose the `HasRawWindowHandle` trait impl of druid-shell for `WindowHandle` into druid itself, so druid users can access it. This is also under a `raw-win-handle` feature, like the druid-shell one. Bug: linebender#1505
Expose the `HasRawWindowHandle` trait impl of druid-shell for `WindowHandle` into druid itself, so druid users can access it. This is also under a `raw-win-handle` feature, like the druid-shell one. Bug: linebender#1505
Expose the `HasRawWindowHandle` trait impl of druid-shell for `WindowHandle` into druid itself, so druid users can access it. This is also under a `raw-win-handle` feature, like the druid-shell one. Bug: #1505
Hi,
I need a reference to HWND to set display affinity:
Currently, I patched window.rs to access it:
Did I miss a way to access it without patching the library? If not is there a better way that won't break cross-platform features that would allow direct access to HWND under a
#[cfg(target_os = "windows")]
?Or any plans to add a safe wrapper for SetWindowDisplayAffinity?
Thanks.
The text was updated successfully, but these errors were encountered: