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§
impl Copy for Window
impl Eq for Window
impl Send for Window
impl StructuralPartialEq for Window
Auto Trait Implementations§
impl !Sync for Window
impl Freeze for Window
impl RefUnwindSafe 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