pub struct WindowHandle { /* private fields */ }
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
impl WindowHandle
Sourcepub fn get_console_window() -> Option<Self>
pub fn get_console_window() -> Option<Self>
Returns the console window associated with the current process, if there is one.
Sourcepub fn get_foreground_window() -> Option<Self>
pub fn get_foreground_window() -> Option<Self>
Returns the current foreground window, if any.
Sourcepub fn get_desktop_window() -> Result<Self>
pub fn get_desktop_window() -> Result<Self>
Returns the ‘desktop’ window.
Sourcepub fn get_toplevel_windows() -> Result<Vec<Self>>
pub fn get_toplevel_windows() -> Result<Vec<Self>>
Returns all top-level windows of desktop apps.
pub fn is_visible(&self) -> bool
Sourcepub fn get_caption_text(&self) -> String
pub fn get_caption_text(&self) -> String
Returns the window caption text, converted to UTF-8 in a potentially lossy way.
Sourcepub fn set_caption_text(&self, text: &str) -> Result<()>
pub fn set_caption_text(&self, text: &str) -> Result<()>
Sets the window caption text.
Sourcepub fn set_as_foreground(&self) -> Result<()>
pub fn set_as_foreground(&self) -> Result<()>
Brings the window to the foreground.
Sourcepub fn set_as_active(&self) -> Result<()>
pub fn set_as_active(&self) -> Result<()>
Sets the window as the currently active (selected) window.
Sourcepub fn set_show_state(&self, state: WindowShowState) -> Result<()>
pub fn set_show_state(&self, state: WindowShowState) -> Result<()>
Changes the window show state.
Sourcepub fn get_placement(&self) -> Result<WindowPlacement>
pub fn get_placement(&self) -> Result<WindowPlacement>
Returns the window’s show state and positions.
Sourcepub fn set_placement(&self, placement: &WindowPlacement) -> Result<()>
pub fn set_placement(&self, placement: &WindowPlacement) -> Result<()>
Sets the window’s show state and positions.
Sourcepub fn get_class_name(&self) -> Result<String>
pub fn get_class_name(&self) -> Result<String>
Returns the class name of the window’s associated WindowClass
.
Sourcepub fn send_command(&self, action: WindowCommand) -> Result<()>
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.
Sourcepub fn flash(&self)
pub fn flash(&self)
Flashes the window using default flash settings.
Same as Self::flash_custom
using Default::default
for all parameters.
Sourcepub fn flash_custom(
&self,
element: FlashElement,
duration: FlashDuration,
frequency: FlashInterval,
)
pub fn flash_custom( &self, element: FlashElement, duration: FlashDuration, frequency: FlashInterval, )
Flashes the window, allowing various customization parameters.
Sourcepub fn flash_stop(&self)
pub fn flash_stop(&self)
Stops the window from flashing.
Sourcepub fn get_creator_thread_id(&self) -> ThreadId
Available on crate feature process
only.
pub fn get_creator_thread_id(&self) -> ThreadId
process
only.Returns the thread ID that created this window.
Sourcepub fn get_creator_process_id(&self) -> ProcessId
Available on crate feature process
only.
pub fn get_creator_process_id(&self) -> ProcessId
process
only.Returns the process ID that created this window.
Sourcepub fn get_nonchild_windows(thread_id: ThreadId) -> Vec<Self>
Available on crate feature process
only.
pub fn get_nonchild_windows(thread_id: ThreadId) -> Vec<Self>
process
only.Returns all top-level (non-child) windows created by the thread.
Sourcepub fn set_monitor_power(&self, level: MonitorPower) -> Result<()>
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>
impl<WML> AsMut<WindowHandle> for Window<'_, '_, WML>
Source§fn as_mut(&mut self) -> &mut WindowHandle
fn as_mut(&mut self) -> &mut WindowHandle
Source§impl<WML> AsRef<WindowHandle> for Window<'_, '_, WML>
impl<WML> AsRef<WindowHandle> for Window<'_, '_, WML>
Source§fn as_ref(&self) -> &WindowHandle
fn as_ref(&self) -> &WindowHandle
Source§impl Debug for WindowHandle
impl Debug for WindowHandle
Source§impl From<&WindowHandle> for HWND
impl From<&WindowHandle> for HWND
Source§fn from(value: &WindowHandle) -> Self
fn from(value: &WindowHandle) -> Self
Returns the underlying raw window handle used by [windows
].
Source§impl From<WindowHandle> for HWND
impl From<WindowHandle> for HWND
Source§fn from(value: WindowHandle) -> Self
fn from(value: WindowHandle) -> Self
Returns the underlying raw window handle used by [windows
].