-
Notifications
You must be signed in to change notification settings - Fork 534
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
How to use MONITORINFOEX with GetMonitorInfoA? #1837
Comments
Hi @SageSudo, pass in |
Hi @riverar, thank you for answering! I did give that a try when I was experimenting with the function previously but I realized that the When I tried
Is that expected because I only passed in |
That's likely because you didn't initialize the use windows::{Win32::Foundation::*, Win32::Graphics::Gdi::*};
fn main() {
unsafe {
EnumDisplayMonitors(None, std::ptr::null(), Some(callback), LPARAM(0));
}
}
extern "system" fn callback(handle: HMONITOR, _: HDC, _: *mut RECT, _: LPARAM) -> BOOL {
unsafe {
let mut info = MONITORINFOEXA::default();
info.monitorInfo.cbSize = std::mem::size_of::<MONITORINFOEXA>() as _;
GetMonitorInfoA(handle, &mut info.monitorInfo);
let slice = std::slice::from_raw_parts(info.szDevice.as_ptr() as _, info.szDevice.len());
println!("{}", std::str::from_utf8_unchecked(slice));
BOOL(1)
}
} And here's what I get:
Check the docs for https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmonitorinfoa |
Yes, I must have done something wrong, I rewrote what I had and followed both your suggestions and that worked. Thank you for the example Kenny, and thank you both for the help. |
Hi,
According to the Microsoft documentation for GetMonitorInfo, the function's second parameter can be either a MONITORINFO or MONITORINFOEX, however, in the windows-rs documentation for GetMonitorInfoA, the function only accepts MONITORINFO as a second parameter.
Is there something I have to do to make MONITORINFOEX work with GetMonitorInfoA?
This is how I've went about trying GetMonitorInfoA:
The text was updated successfully, but these errors were encountered: