Struct WindowHandle

Source
pub struct WindowHandle { /* private fields */ }
Available on crate feature ui only.
Expand description

A (non-null) handle to a window.

§Multithreading

This handle is not Send and Sync because if the window was not created by this thread, then it is not guaranteed that the handle continues pointing to the same window because the underlying handles can get invalid or even recycled.

§Mutability

Even though various functions on this type are mutating, they all take non-mut references since it would be too hard to guarantee exclusive references when window messages are involved. The problem in that case is that the windows API will call back into Rust code and that code would then need exclusive references, which would at least make the API rather cumbersome. If an elegant solution to this problem is found, this API may change.

Implementations§

Source§

impl WindowHandle

Source

pub fn get_console_window() -> Option<Self>

Returns the console window associated with the current process, if there is one.

Source

pub fn get_foreground_window() -> Option<Self>

Returns the current foreground window, if any.

Source

pub fn get_desktop_window() -> Result<Self>

Returns the ‘desktop’ window.

Source

pub fn get_toplevel_windows() -> Result<Vec<Self>>

Returns all top-level windows of desktop apps.

Source

pub fn is_window(&self) -> bool

Checks if the handle points to an existing window.

Source

pub fn is_visible(&self) -> bool

Source

pub fn get_caption_text(&self) -> String

Returns the window caption text, converted to UTF-8 in a potentially lossy way.

Source

pub fn set_caption_text(&self, text: &str) -> Result<()>

Sets the window caption text.

Source

pub fn set_as_foreground(&self) -> Result<()>

Brings the window to the foreground.

Source

pub fn set_as_active(&self) -> Result<()>

Sets the window as the currently active (selected) window.

Source

pub fn set_show_state(&self, state: WindowShowState) -> Result<()>

Changes the window show state.

Source

pub fn get_placement(&self) -> Result<WindowPlacement>

Returns the window’s show state and positions.

Source

pub fn set_placement(&self, placement: &WindowPlacement) -> Result<()>

Sets the window’s show state and positions.

Source

pub fn get_class_name(&self) -> Result<String>

Returns the class name of the window’s associated WindowClass.

Source

pub fn send_command(&self, action: WindowCommand) -> Result<()>

Sends a command to the window, same as if one of the symbols in its top right were clicked.

Source

pub fn flash(&self)

Flashes the window using default flash settings.

Same as Self::flash_custom using Default::default for all parameters.

Source

pub fn flash_custom( &self, element: FlashElement, duration: FlashDuration, frequency: FlashInterval, )

Flashes the window, allowing various customization parameters.

Source

pub fn flash_stop(&self)

Stops the window from flashing.

Source

pub fn get_creator_thread_id(&self) -> ThreadId

Available on crate feature process only.

Returns the thread ID that created this window.

Source

pub fn get_creator_process_id(&self) -> ProcessId

Available on crate feature process only.

Returns the process ID that created this window.

Source

pub fn get_nonchild_windows(thread_id: ThreadId) -> Vec<Self>

Available on crate feature process only.

Returns all top-level (non-child) windows created by the thread.

Source

pub fn set_monitor_power(&self, level: MonitorPower) -> Result<()>

Turns the monitor on or off.

Windows requires this command to be sent through a window, e.g. using WindowHandle::get_foreground_window.

Trait Implementations§

Source§

impl<WML> AsMut<WindowHandle> for Window<'_, '_, WML>

Source§

fn as_mut(&mut self) -> &mut WindowHandle

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<WML> AsRef<WindowHandle> for Window<'_, '_, WML>

Source§

fn as_ref(&self) -> &WindowHandle

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Debug for WindowHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&WindowHandle> for HWND

Source§

fn from(value: &WindowHandle) -> Self

Returns the underlying raw window handle used by [windows].

Source§

impl From<WindowHandle> for HWND

Source§

fn from(value: WindowHandle) -> Self

Returns the underlying raw window handle used by [windows].

Source§

impl PartialEq for WindowHandle

Source§

fn eq(&self, other: &WindowHandle) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<HWND> for WindowHandle

Source§

fn try_from(value: HWND) -> Result<Self, Self::Error>

Returns a new window handle from a raw handle if it is non-null.

Source§

type Error = TryFromHWNDError

The type returned in the event of a conversion error.
Source§

impl Eq for WindowHandle

Source§

impl StructuralPartialEq for WindowHandle

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V