libobs_window_helper/
monitor.rs

1use windows::Win32::Graphics::Gdi::{GetMonitorInfoW, HMONITOR, MONITORINFOEXW};
2use anyhow::Result;
3
4use crate::string_conv::ToUtf8String;
5
6pub fn get_monitor_id(monitor: HMONITOR) -> Result<String> {
7    let mut monitor_info = MONITORINFOEXW::default();
8    monitor_info.monitorInfo.cbSize = std::mem::size_of::<MONITORINFOEXW>() as u32;
9
10    unsafe {
11        GetMonitorInfoW(monitor, &mut monitor_info as *mut _ as _).ok()?;
12    }
13
14    Ok(monitor_info.szDevice.to_utf8())
15}