pub struct Monitor { /* private fields */ }Expand description
Represents a display monitor.
ยงExamples
use windows_capture::monitor::Monitor;
// Primary monitor
let primary = Monitor::primary().unwrap();
println!("Primary: {}", primary.name().unwrap());use windows_capture::monitor::Monitor;
// Enumerate all active monitors
let monitors = Monitor::enumerate().unwrap();
for (i, m) in monitors.iter().enumerate() {
println!("Monitor #{}: {}", i + 1, m.name().unwrap_or_default());
}use windows_capture::monitor::Monitor;
// Select by one-based index (e.g., 2nd monitor)
let m2 = Monitor::from_index(2).unwrap();
println!("Second monitor size: {}x{}", m2.width().unwrap(), m2.height().unwrap());See also: [crate::settings::TryIntoCaptureItemWithDetails].
Implementationsยง
Sourceยงimpl Monitor
impl Monitor
Sourcepub fn from_index(index: usize) -> Result<Self, Error>
pub fn from_index(index: usize) -> Result<Self, Error>
Returns the monitor at the specified index.
ยงErrors
Error::IndexIsLowerThanOnewhenindexis less than 1Error::NotFoundwhen no monitor exists at the specifiedindexError::WindowsErrorwhen monitor enumeration fails
Sourcepub fn index(&self) -> Result<usize, Error>
pub fn index(&self) -> Result<usize, Error>
Returns the one-based index of the monitor.
ยงErrors
Error::FailedToGetMonitorInfowhenGetMonitorInfoWfailsError::FailedToConvertWindowsStringwhen converting the device name from UTF-16 failsError::FailedToParseMonitorIndexwhen parsing the numeric index from the device name fails
Sourcepub fn name(&self) -> Result<String, Error>
pub fn name(&self) -> Result<String, Error>
Returns the friendly name of the monitor.
ยงErrors
Error::WindowsErrorwhen Display Configuration API calls failError::FailedToConvertWindowsStringwhen converting wide strings toStringfailsError::NameNotFoundwhen no matching path/device name is found for this monitor
Sourcepub fn device_name(&self) -> Result<String, Error>
pub fn device_name(&self) -> Result<String, Error>
Returns the device name of the monitor (for example, \\.\DISPLAY1).
ยงErrors
Error::FailedToGetMonitorInfowhenGetMonitorInfoWfailsError::FailedToConvertWindowsStringwhen converting the device name from UTF-16 fails
Sourcepub fn device_string(&self) -> Result<String, Error>
pub fn device_string(&self) -> Result<String, Error>
Returns the device string of the monitor (for example, NVIDIA GeForce RTX 4090).
ยงErrors
Error::FailedToGetMonitorInfowhenGetMonitorInfoWfailsError::FailedToGetMonitorNamewhenEnumDisplayDevicesWfailsError::FailedToConvertWindowsStringwhen converting the device string from UTF-16 fails
Sourcepub fn refresh_rate(&self) -> Result<u32, Error>
pub fn refresh_rate(&self) -> Result<u32, Error>
Returns the refresh rate of the monitor in hertz (Hz).
ยงErrors
Error::FailedToGetMonitorSettingswhenEnumDisplaySettingsWfailsError::FailedToGetMonitorInfowhenGetMonitorInfoWfails while resolving the device nameError::FailedToConvertWindowsStringwhen converting the device name from UTF-16 fails
Sourcepub fn width(&self) -> Result<u32, Error>
pub fn width(&self) -> Result<u32, Error>
Returns the width of the monitor in pixels.
ยงErrors
Error::FailedToGetMonitorSettingswhenEnumDisplaySettingsWfailsError::FailedToGetMonitorInfowhenGetMonitorInfoWfails while resolving the device nameError::FailedToConvertWindowsStringwhen converting the device name from UTF-16 fails
Sourcepub fn height(&self) -> Result<u32, Error>
pub fn height(&self) -> Result<u32, Error>
Returns the height of the monitor in pixels.
ยงErrors
Error::FailedToGetMonitorSettingswhenEnumDisplaySettingsWfailsError::FailedToGetMonitorInfowhenGetMonitorInfoWfails while resolving the device nameError::FailedToConvertWindowsStringwhen converting the device name from UTF-16 fails
Sourcepub fn enumerate() -> Result<Vec<Self>, Error>
pub fn enumerate() -> Result<Vec<Self>, Error>
Returns a list of all available monitors.
ยงErrors
Error::WindowsErrorwhenEnumDisplayMonitorsfails
Sourcepub const fn from_raw_hmonitor(monitor: *mut c_void) -> Self
pub const fn from_raw_hmonitor(monitor: *mut c_void) -> Self
Constructs a Monitor instance from a raw HMONITOR handle.
Sourcepub const fn as_raw_hmonitor(&self) -> *mut c_void
pub const fn as_raw_hmonitor(&self) -> *mut c_void
Returns the raw HMONITOR handle of the monitor.
Trait Implementationsยง
Sourceยงimpl TryInto<GraphicsCaptureItemType> for Monitor
impl TryInto<GraphicsCaptureItemType> for Monitor
impl Copy for Monitor
impl Eq for Monitor
impl Send for Monitor
impl StructuralPartialEq for Monitor
Auto Trait Implementationsยง
impl Freeze for Monitor
impl RefUnwindSafe for Monitor
impl !Sync for Monitor
impl Unpin for Monitor
impl UnsafeUnpin for Monitor
impl UnwindSafe for Monitor
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more