pub struct Window(/* private fields */);
Expand description
A wrapper around a platform-specific window. This struct provides a cross-platform interface to interact with window properties.
Implementations§
Source§impl Window
impl Window
Sourcepub fn new(inner: PlatformWindow) -> Self
pub fn new(inner: PlatformWindow) -> Self
Creates a new Window
instance from a platform-specific window.
§Notes
You can get a Window
instance by using the get_window
function
or get_windows
function so you don’t need to create it manually
in most use cases.
Sourcepub fn platform_window(&self) -> &PlatformWindow
pub fn platform_window(&self) -> &PlatformWindow
Retrieves the underlying platform-specific window.
Sourcepub fn into_platform_window(self) -> PlatformWindow
pub fn into_platform_window(self) -> PlatformWindow
Consumes the Window
and returns the underlying platform-specific window.
Examples found in repository?
examples/windows_various_rect.rs (line 9)
7fn main() {
8 for window in window_getter::get_windows().unwrap() {
9 let window = window.into_platform_window();
10
11 println!("\n{:?} ({:?})", window.title(), window.hwnd());
12 println!("\tGetWindowRect: {:?}", window.rect());
13 println!(
14 "\tDwmGetWindowAttribute with DWMWA_EXTENDED_FRAME_BOUNDS: {:?}",
15 window.extended_frame_bounds()
16 );
17 }
18}
Sourcepub fn title(&self) -> Result<Option<String>, Error>
pub fn title(&self) -> Result<Option<String>, Error>
Returns the title of the window.
§Platform-specific
- Windows: If you don’t have permission to access the title,
it will return
Error::PermissionDenied
. - macOS: It will always return
Ok
. Apple’s documentation does not explicitly state this, but it returnsNone
when the permission is not granted.
Examples found in repository?
More examples
examples/get_window.rs (line 11)
3fn main() {
4 let raw = std::env::var("WINDOW_ID")
5 .expect("`WINDOW_ID` environment variable not set")
6 .parse::<u32>()
7 .expect("`WINDOW_ID` must be a valid `u32`");
8 let id = WindowId::from(raw);
9
10 if let Some(window) = window_getter::get_window(id).unwrap() {
11 println!("title: {:?}", window.title());
12 } else {
13 println!("No window found with the given ID.");
14 };
15}
Sourcepub fn owner_name(&self) -> Result<Option<String>, Error>
pub fn owner_name(&self) -> Result<Option<String>, Error>
Returns the name of the process that owns the window.
§Platform-specific
- Windows: If you don’t have permission to access the owner name,
it will return
Error::PermissionDenied
. Also, it will return the name of the executable file when owner name is available. - macOS: It will always return
Ok
.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Window
impl RefUnwindSafe for Window
impl Send for Window
impl Sync for Window
impl Unpin 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
Mutably borrows from an owned value. Read more