use winapi::shared::windef::HWND;
use winapi::um::winuser::{GetSystemMetrics, MonitorFromWindow, GetMonitorInfoW, MONITORINFO,
SM_CXSCREEN, SM_CYSCREEN, SM_CXVIRTUALSCREEN, SM_CYVIRTUALSCREEN, MONITOR_DEFAULTTONEAREST};
use crate::ControlHandle;
use std::mem;
pub struct Monitor;
impl Monitor {
fn monitor_info_from_window(handle: HWND) -> MONITORINFO {
unsafe {
let m = MonitorFromWindow(handle, MONITOR_DEFAULTTONEAREST);
let mut info: MONITORINFO = mem::zeroed();
info.cbSize = mem::size_of::<MONITORINFO>() as _;
GetMonitorInfoW(m, &mut info);
info
}
}
pub fn width_from_window<H: Into<ControlHandle>>(window: H) -> i32 {
let handle = window.into().hwnd().expect("Window to be a window-like control");
let info = Self::monitor_info_from_window(handle);
(info.rcMonitor.right - info.rcMonitor.left) as _
}
pub fn height_from_window<H: Into<ControlHandle>>(window: H) -> i32 {
let handle = window.into().hwnd().expect("Window to be a window-like control");
let info = Self::monitor_info_from_window(handle);
(info.rcMonitor.bottom - info.rcMonitor.top) as _
}
pub fn monitor_rect_from_window<H: Into<ControlHandle>>(window: H) -> [i32; 4] {
let handle = window.into().hwnd().expect("Window to be a window-like control");
let info = Self::monitor_info_from_window(handle);
let m = info.rcMonitor;
[
m.left,
m.top,
m.right,
m.bottom
]
}
pub fn width() -> i32 {
unsafe {
GetSystemMetrics(SM_CXSCREEN) as _
}
}
pub fn height() -> i32 {
unsafe {
GetSystemMetrics(SM_CYSCREEN) as _
}
}
pub fn virtual_width() -> i32 {
unsafe {
GetSystemMetrics(SM_CXVIRTUALSCREEN) as _
}
}
pub fn virtual_height() -> i32 {
unsafe {
GetSystemMetrics(SM_CYVIRTUALSCREEN) as _
}
}
}