pub struct Monitor { /* private fields */ }展开描述
表示一个显示监视器。
§示例
use windows_capture::monitor::Monitor;
// 主监视器
let primary = Monitor::primary().unwrap();
println!("主监视器: {}", primary.name().unwrap());use windows_capture::monitor::Monitor;
// 枚举所有活动的监视器
let monitors = Monitor::enumerate().unwrap();
for (i, m) in monitors.iter().enumerate() {
println!("监视器 #{}: {}", i + 1, m.name().unwrap_or_default());
}use windows_capture::monitor::Monitor;
// 通过基于 1 的索引选择(例如,第 2 个监视器)
let m2 = Monitor::from_index(2).unwrap();
println!("第二个监视器尺寸: {}x{}", m2.width().unwrap(), m2.height().unwrap());另请参阅:[crate::settings::TryIntoCaptureItemWithDetails]。
实现§
Source§impl Monitor
impl Monitor
Sourcepub fn from_index(index: usize) -> Result<Self, Error>
pub fn from_index(index: usize) -> Result<Self, Error>
返回指定索引处的监视器。
§错误
Error::IndexIsLowerThanOne当index小于 1 时Error::NotFound当指定index处不存在监视器时Error::WindowsError当监视器枚举失败时
Sourcepub fn index(&self) -> Result<usize, Error>
pub fn index(&self) -> Result<usize, Error>
返回监视器的基于 1 的索引。
§错误
Error::FailedToGetMonitorInfo当GetMonitorInfoW失败时Error::FailedToConvertWindowsString当从 UTF-16 转换设备名称失败时Error::FailedToParseMonitorIndex当从设备名称解析数字索引失败时
Sourcepub fn name(&self) -> Result<String, Error>
pub fn name(&self) -> Result<String, Error>
返回监视器的友好名称。
§错误
Error::WindowsError当 Display Configuration API 调用失败时Error::FailedToConvertWindowsString当将宽字符串转换为String失败时Error::NameNotFound当未找到与该监视器匹配的路径/设备名称时
Sourcepub fn device_name(&self) -> Result<String, Error>
pub fn device_name(&self) -> Result<String, Error>
返回监视器的设备名称(例如 \\.\DISPLAY1)。
§错误
Error::FailedToGetMonitorInfo当GetMonitorInfoW失败时Error::FailedToConvertWindowsString当从 UTF-16 转换设备名称失败时
Sourcepub fn device_string(&self) -> Result<String, Error>
pub fn device_string(&self) -> Result<String, Error>
返回监视器的设备字符串(例如 NVIDIA GeForce RTX 4090)。
§错误
Error::FailedToGetMonitorInfo当GetMonitorInfoW失败时Error::FailedToGetMonitorName当EnumDisplayDevicesW失败时Error::FailedToConvertWindowsString当从 UTF-16 转换设备字符串失败时
Sourcepub fn refresh_rate(&self) -> Result<u32, Error>
pub fn refresh_rate(&self) -> Result<u32, Error>
返回监视器的刷新率(以赫兹 Hz 为单位)。
§错误
Error::FailedToGetMonitorSettings当EnumDisplaySettingsW失败时Error::FailedToGetMonitorInfo当GetMonitorInfoW在解析设备名称时失败Error::FailedToConvertWindowsString当从 UTF-16 转换设备名称失败时
Sourcepub fn width(&self) -> Result<u32, Error>
pub fn width(&self) -> Result<u32, Error>
返回监视器的宽度(以像素为单位)。
§错误
Error::FailedToGetMonitorSettings当EnumDisplaySettingsW失败时Error::FailedToGetMonitorInfo当GetMonitorInfoW在解析设备名称时失败Error::FailedToConvertWindowsString当从 UTF-16 转换设备名称失败时
Sourcepub fn height(&self) -> Result<u32, Error>
pub fn height(&self) -> Result<u32, Error>
返回监视器的高度(以像素为单位)。
§错误
Error::FailedToGetMonitorSettings当EnumDisplaySettingsW失败时Error::FailedToGetMonitorInfo当GetMonitorInfoW在解析设备名称时失败Error::FailedToConvertWindowsString当从 UTF-16 转换设备名称失败时
Sourcepub const fn from_raw_hmonitor(monitor: *mut c_void) -> Self
pub const fn from_raw_hmonitor(monitor: *mut c_void) -> Self
从原始 HMONITOR 句柄构造 Monitor 实例。
Sourcepub const fn as_raw_hmonitor(&self) -> *mut c_void
pub const fn as_raw_hmonitor(&self) -> *mut c_void
返回监视器的原始 HMONITOR 句柄。
trait 实现§
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
自动 trait 实现§
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 实现§
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
从拥有的值可变地借用。 了解更多
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>
将
self 转换为 Left 变体的
Either<Self, Self>,
当 into_left 为 true 时;
否则将其转换为
Right 变体的
Either<Self, Self>。
了解更多Source§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
将
self 转换为 Left 变体的
Either<Self, Self>,
当 into_left(&self) 返回 true 时;
否则将其转换为
Right 变体的
Either<Self, Self>。
了解更多