pub struct Window { /* private fields */ }Expand description
Represents a window that can be captured.
ยงExample
use windows_capture::window::Window;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let window = Window::foreground()?;
println!("Foreground window title: {}", window.title()?);
Ok(())
}Implementationsยง
Sourceยงimpl Window
impl Window
Sourcepub fn foreground() -> Result<Self, Error>
pub fn foreground() -> Result<Self, Error>
Returns the window that is currently in the foreground.
ยงErrors
Error::NoActiveWindowwhen there is no foreground window
Sourcepub fn from_name(title: &str) -> Result<Self, Error>
pub fn from_name(title: &str) -> Result<Self, Error>
Finds a window by its exact title.
ยงErrors
Error::WindowsErrorwhen the underlyingFindWindowWcall failsError::NotFoundwhen no window with the specified title is found
Sourcepub fn from_contains_name(title: &str) -> Result<Self, Error>
pub fn from_contains_name(title: &str) -> Result<Self, Error>
Finds a window whose title contains the given substring.
ยงErrors
Error::WindowsErrorwhen enumerating windows failsError::FailedToConvertWindowsStringwhen converting a window title from UTF-16 failsError::NotFoundwhen no window title contains the specified substring
Sourcepub fn title(&self) -> Result<String, Error>
pub fn title(&self) -> Result<String, Error>
Returns the title of the window.
ยงErrors
Error::FailedToConvertWindowsStringwhen converting the window title from UTF-16 fails
Sourcepub fn process_id(&self) -> Result<u32, Error>
pub fn process_id(&self) -> Result<u32, Error>
Returns the process ID of the window.
ยงErrors
Error::WindowsErrorwhenGetWindowThreadProcessIdreports an error
Sourcepub fn process_name(&self) -> Result<String, Error>
pub fn process_name(&self) -> Result<String, Error>
Returns the name of the process that owns the window.
This function requires the PROCESS_QUERY_INFORMATION and PROCESS_VM_READ permissions.
ยงErrors
Error::WindowsErrorwhen opening the process or querying its base module name failsError::FailedToConvertWindowsStringwhen converting the process name from UTF-16 fails
Sourcepub fn monitor(&self) -> Option<Monitor>
pub fn monitor(&self) -> Option<Monitor>
Returns the monitor that has the largest area of intersection with the window.
Returns None if the window does not intersect with any monitor.
Sourcepub fn rect(&self) -> Result<RECT, Error>
pub fn rect(&self) -> Result<RECT, Error>
Returns the bounding rectangle of the window in screen coordinates.
ยงErrors
Error::WindowsErrorwhenGetWindowRectfails
Sourcepub fn title_bar_height(&self) -> Result<u32, Error>
pub fn title_bar_height(&self) -> Result<u32, Error>
Calculates the height of the windowโs title bar in pixels.
ยงErrors
Error::WindowsErrorwhenDwmGetWindowAttributeorGetClientRectfails
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Checks whether the window is a valid target for capture.
ยงReturns
Returns true if the window is visible, not a tool window, and not a child window.
Returns false otherwise.
Sourcepub fn width(&self) -> Result<i32, Error>
pub fn width(&self) -> Result<i32, Error>
Returns the width of the window in pixels.
ยงErrors
Error::WindowsErrorwhen retrieving the window rectangle fails
Sourcepub fn height(&self) -> Result<i32, Error>
pub fn height(&self) -> Result<i32, Error>
Returns the height of the window in pixels.
ยงErrors
Error::WindowsErrorwhen retrieving the window rectangle fails
Sourcepub const fn from_raw_hwnd(hwnd: *mut c_void) -> Self
pub const fn from_raw_hwnd(hwnd: *mut c_void) -> Self
Constructs a Window instance from a raw HWND handle.
Sourcepub const fn as_raw_hwnd(&self) -> *mut c_void
pub const fn as_raw_hwnd(&self) -> *mut c_void
Returns the raw HWND handle of the window.
Trait Implementationsยง
Sourceยงimpl TryInto<GraphicsCaptureItemType> for Window
impl TryInto<GraphicsCaptureItemType> for Window
impl Copy for Window
impl Eq for Window
impl Send for Window
impl StructuralPartialEq for Window
Auto Trait Implementationsยง
impl Freeze for Window
impl RefUnwindSafe for Window
impl !Sync for Window
impl Unpin for Window
impl UnsafeUnpin for Window
impl UnwindSafe for Window
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
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 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>
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