Trait winsafe::prelude::user_Hwnd

source ·
pub trait user_Hwnd: Handle {
    const BROADCAST: HWND = _;
    const DESKTOP: HWND = _;
Show 132 methods // Provided methods fn hinstance(&self) -> HINSTANCE { ... } fn is_dialog(&self) -> bool { ... } fn set_style(&self, style: impl Into<WS>) { ... } fn set_style_ex(&self, ex_style: impl Into<WS_EX>) { ... } fn style(&self) -> WS { ... } fn style_ex(&self) -> WS_EX { ... } fn ArrangeIconicWindows(&self) -> SysResult<u32> { ... } fn BeginPaint(&self) -> SysResult<EndPaintGuard<'_, Self>> { ... } fn BringWindowToTop(&self) -> SysResult<()> { ... } fn ChildWindowFromPoint(&self, pt: POINT) -> Option<HWND> { ... } fn ClientToScreen(&self, pt: &mut POINT) -> SysResult<()> { ... } fn ClientToScreenRc(&self, rc: &mut RECT) -> SysResult<()> { ... } fn CloseWindow(&self) -> SysResult<()> { ... } unsafe fn CreateWindowEx( ex_style: WS_EX, class_name: AtomStr, title: Option<&str>, style: WS, pos: POINT, size: SIZE, hwnd_parent: Option<&HWND>, hmenu: IdMenu<'_>, hinstance: &HINSTANCE, lparam: Option<isize> ) -> SysResult<HWND> { ... } unsafe fn DefWindowProc<M>(&self, msg: M) -> M::RetType where M: MsgSend { ... } fn DestroyWindow(&self) -> SysResult<()> { ... } fn DragDetect(&self, pt: POINT) -> bool { ... } fn DrawCaption( &self, hdc: &HDC, rect: &RECT, flags: Option<DC> ) -> SysResult<()> { ... } fn DrawMenuBar(&self) -> SysResult<()> { ... } fn EnableScrollBar(&self, sb_flags: SBB, arrows: ESB) -> SysResult<()> { ... } fn EnableWindow(&self, enable: bool) -> bool { ... } fn EndDialog(&self, result: isize) -> SysResult<()> { ... } fn EnumChildWindows<F>(&self, func: F) where F: FnMut(HWND) -> bool { ... } fn FindWindow( class_name: Option<AtomStr>, title: Option<&str> ) -> SysResult<Option<HWND>> { ... } fn FindWindowEx( &self, hwnd_child_after: Option<&HWND>, class_name: AtomStr, title: Option<&str> ) -> SysResult<Option<HWND>> { ... } fn GetActiveWindow() -> Option<HWND> { ... } fn GetAltTabInfo( &self, item: Option<u32>, ati: &mut ALTTABINFO, sz_item_text: Option<u32> ) -> SysResult<String> { ... } fn GetAncestor(&self, flags: GA) -> Option<HWND> { ... } fn GetCapture() -> Option<HWND> { ... } fn GetClassLongPtr(&self, index: GCLP) -> usize { ... } fn GetClassName(&self) -> SysResult<String> { ... } fn GetClientRect(&self) -> SysResult<RECT> { ... } fn GetDC(&self) -> SysResult<ReleaseDCGuard<'_, Self>> { ... } fn GetDesktopWindow() -> HWND { ... } fn GetDialogDpiChangeBehavior(&self) -> SysResult<DDC> { ... } fn GetDlgCtrlID(&self) -> SysResult<u16> { ... } fn GetDlgItem(&self, ctrl_id: u16) -> SysResult<HWND> { ... } fn GetDpiForWindow(&self) -> u32 { ... } fn GetFocus() -> Option<HWND> { ... } fn GetForegroundWindow() -> Option<HWND> { ... } fn GetLastActivePopup(&self) -> Option<HWND> { ... } fn GetMenu(&self) -> Option<HMENU> { ... } fn GetMenuBarInfo( &self, obj_id: OBJID, item_id: u32, mbi: &mut MENUBARINFO ) -> SysResult<()> { ... } fn GetMenuItemRect(&self, hmenu: &HMENU, item_pos: u32) -> SysResult<RECT> { ... } fn GetNextDlgGroupItem( &self, hwnd_ctrl: &HWND, previous: bool ) -> SysResult<HWND> { ... } fn GetNextDlgTabItem( &self, hwnd_ctrl: &HWND, previous: bool ) -> SysResult<HWND> { ... } fn GetParent(&self) -> SysResult<HWND> { ... } fn GetScrollInfo(&self, bar: SBB, si: &mut SCROLLINFO) -> SysResult<()> { ... } fn GetScrollPos(&self, bar: SBB) -> SysResult<i32> { ... } fn GetShellWindow() -> Option<HWND> { ... } fn GetSystemMenu(&self, revert: bool) -> Option<HMENU> { ... } fn GetTopWindow(&self) -> SysResult<Option<HWND>> { ... } fn GetUpdateRect(&self, erase: bool) -> Option<RECT> { ... } fn GetUpdateRgn(&self, hrgn: &HRGN, erase: bool) -> SysResult<REGION> { ... } fn GetWindow(&self, cmd: GW) -> SysResult<HWND> { ... } fn GetWindowDC(&self) -> SysResult<ReleaseDCGuard<'_, Self>> { ... } fn GetWindowDisplayAffinity(&self) -> SysResult<WDA> { ... } fn GetWindowDpiHostingBehavior(&self) -> DPI_HOSTING_BEHAVIOR { ... } fn GetWindowInfo(&self, wi: &mut WINDOWINFO) -> SysResult<()> { ... } fn GetWindowLongPtr(&self, index: GWLP) -> isize { ... } fn GetWindowModuleFileName(&self) -> String { ... } fn GetWindowPlacement(&self, wp: &mut WINDOWPLACEMENT) -> SysResult<()> { ... } fn GetWindowRect(&self) -> SysResult<RECT> { ... } fn GetWindowRgn(&self, hrgn: &HRGN) -> SysResult<REGION> { ... } fn GetWindowRgnBox(&self) -> SysResult<(RECT, REGION)> { ... } fn GetWindowText(&self) -> SysResult<String> { ... } fn GetWindowTextLength(&self) -> SysResult<i32> { ... } fn GetWindowThreadProcessId(&self) -> (u32, u32) { ... } fn HideCaret(&self) -> SysResult<()> { ... } fn HiliteMenuItem( &self, hmenu: &HMENU, id_or_pos: IdPos, hilite: bool ) -> bool { ... } fn InheritWindowMonitor(&self, hwnd_inherit: &HWND) -> SysResult<()> { ... } fn InvalidateRect(&self, rc: Option<&RECT>, erase: bool) -> SysResult<()> { ... } fn InvalidateRgn(&self, hrgn: &HRGN, erase: bool) { ... } fn IsChild(&self, hwnd_possible_child: &HWND) -> bool { ... } fn IsDialogMessage(&self, msg: &mut MSG) -> bool { ... } fn IsIconic(&self) -> bool { ... } fn IsWindow(&self) -> bool { ... } fn IsWindowEnabled(&self) -> bool { ... } fn IsWindowUnicode(&self) -> bool { ... } fn IsWindowVisible(&self) -> bool { ... } fn IsZoomed(&self) -> bool { ... } fn KillTimer(&self, event_id: usize) -> SysResult<()> { ... } fn LockWindowUpdate(&self) -> SysResult<()> { ... } fn LogicalToPhysicalPoint(&self, pt: *mut POINT) -> SysResult<()> { ... } fn MapDialogRect(&self, rc: &mut RECT) -> SysResult<()> { ... } fn MapWindowPoints( &self, hdest: &HWND, points: PtsRc<'_> ) -> SysResult<(i16, i16)> { ... } fn MessageBox( &self, text: &str, caption: &str, flags: MB ) -> SysResult<DLGID> { ... } fn MonitorFromWindow(&self, flags: MONITOR) -> HMONITOR { ... } fn MoveWindow(&self, pos: POINT, size: SIZE, repaint: bool) -> SysResult<()> { ... } fn OpenClipboard(&self) -> SysResult<CloseClipboardGuard<'_>> { ... } unsafe fn PostMessage<M>(&self, msg: M) -> SysResult<()> where M: MsgSend + Send + Copy + 'static { ... } fn RealChildWindowFromPoint( &self, pt_parent_client_coords: POINT ) -> Option<HWND> { ... } fn RealGetWindowClass(&self) -> SysResult<String> { ... } fn RedrawWindow( &self, rc_update: &RECT, hrgn_update: &HRGN, flags: RDW ) -> SysResult<()> { ... } fn RegisterHotKey( &self, id: i32, modifiers: MOD, vkey_code: VK ) -> SysResult<()> { ... } fn ScreenToClient(&self, pt: &mut POINT) -> SysResult<()> { ... } fn ScreenToClientRc(&self, rc: &mut RECT) -> SysResult<()> { ... } fn ScrollWindowEx( &self, dx: i32, dy: i32, client_area_portion: Option<&RECT>, clipping_rect: Option<&RECT>, hrgn_update: Option<&HRGN>, updated_boundaries: Option<&mut RECT>, flags: SCROLLW ) -> SysResult<REGION> { ... } unsafe fn SendMessage<M>(&self, msg: M) -> M::RetType where M: MsgSend { ... } unsafe fn SendMessageTimeout<M>( &self, msg: M, flags: SMTO, timeout_ms: u32 ) -> SysResult<M::RetType> where M: MsgSend { ... } fn SetActiveWindow(&self) -> SysResult<HWND> { ... } fn SetCapture(&self) -> ReleaseCaptureGuard<'_, Self> { ... } fn SetDialogDpiChangeBehavior( &self, mask: DDC, values: DDC ) -> SysResult<()> { ... } fn SetFocus(&self) -> Option<HWND> { ... } fn SetForegroundWindow(&self) -> bool { ... } fn SetLayeredWindowAttributes( &self, transparency_color_key: COLORREF, alpha: u8, flags: LWA ) -> SysResult<()> { ... } fn SetMenu(&self, hmenu: &HMENU) -> SysResult<()> { ... } fn SetParent(&self, hwnd_new_parent: &HWND) -> SysResult<Option<HWND>> { ... } fn SetScrollInfo(&self, bar: SBB, si: &SCROLLINFO, redraw: bool) -> i32 { ... } fn SetScrollPos(&self, b: SBB, pos: i32, redraw: bool) -> SysResult<i32> { ... } fn SetScrollRange( &self, bar: SBB, min_pos: i32, max_pos: i32, redraw: bool ) -> SysResult<()> { ... } fn SetTimer( &self, event_id: usize, elapse_ms: u32, timer_func: Option<TIMERPROC> ) -> SysResult<usize> { ... } fn SetWindowDisplayAffinity(&self, affinity: WDA) -> SysResult<()> { ... } unsafe fn SetWindowLongPtr(&self, index: GWLP, new_long: isize) -> isize { ... } fn SetWindowPlacement(&self, wp: &WINDOWPLACEMENT) -> SysResult<()> { ... } fn SetWindowPos( &self, hwnd_insert_after: HwndPlace, pos: POINT, size: SIZE, flags: SWP ) -> SysResult<()> { ... } fn SetWindowRgn(&self, hrgn: &HRGN, redraw: bool) -> SysResult<()> { ... } fn SetWindowText(&self, text: &str) -> SysResult<()> { ... } fn ShowCaret(&self) -> SysResult<()> { ... } fn ShowOwnedPopups(&self, show: bool) -> SysResult<()> { ... } fn ShowWindow(&self, show_cmd: SW) -> bool { ... } fn ShowWindowAsync(&self, show_cmd: SW) -> SysResult<()> { ... } fn TileWindows( &self, how: MDITILE, rect: Option<RECT>, kids: Option<&[&HWND]> ) -> SysResult<u16> { ... } fn TranslateAccelerator( &self, haccel_table: &HACCEL, msg: &mut MSG ) -> SysResult<()> { ... } fn UnregisterHotKey(&self, id: i32) -> SysResult<()> { ... } fn UpdateLayeredWindow( &self, hdc_dest: Option<&HDC>, pt_dest: Option<&POINT>, size: Option<&SIZE>, hdc_src: Option<&HDC>, pt_src: Option<&POINT>, key: COLORREF, blend: &BLENDFUNCTION, flags: ULW ) -> SysResult<()> { ... } fn UpdateWindow(&self) -> SysResult<()> { ... } fn ValidateRect(&self, rc: &RECT) -> SysResult<()> { ... } fn ValidateRgn(&self, hrgn: &HRGN) -> SysResult<()> { ... } fn WindowFromPhysicalPoint(pt: POINT) -> Option<HWND> { ... } fn WindowFromPoint(pt: POINT) -> Option<HWND> { ... } fn WinHelp(&self, help_file: &str, cmd: HELPW, data: usize) -> SysResult<()> { ... }
}
Available on crate features kernel and user only.
Expand description

This trait is enabled with the user feature, and provides methods for HWND.

Prefer importing this trait through the prelude:

use winsafe::prelude::*;

Provided Associated Constants§

source

const BROADCAST: HWND = _

Represents all top-level windows in HWND::PostMessage and HWND::SendMessage.

source

const DESKTOP: HWND = _

Represents the desktop window in HWND::GetDC.

Provided Methods§

source

fn hinstance(&self) -> HINSTANCE

Calls HWND::GetWindowLongPtr to retrieve the window HINSTANCE.

source

fn is_dialog(&self) -> bool

Calls HWND::GetClassLongPtr to retrieve the class atom and check whether the window was created from a dialog resource.

source

fn set_style(&self, style: impl Into<WS>)

Calls HWND::SetWindowLongPtr to set the window styles.

source

fn set_style_ex(&self, ex_style: impl Into<WS_EX>)

Calls HWND::SetWindowLongPtr to set the extended window styles.

source

fn style(&self) -> WS

Calls HWND::GetWindowLongPtr to retrieve the window styles.

source

fn style_ex(&self) -> WS_EX

Calls HWND::GetWindowLongPtr to retrieve the extended window styles.

source

fn ArrangeIconicWindows(&self) -> SysResult<u32>

source

fn BeginPaint(&self) -> SysResult<EndPaintGuard<'_, Self>>

BeginPaint function.

In the original C implementation, BeginPaint returns a handle which must be passed to EndPaint, as a cleanup operation. Also, you must allocate and pass a PAINTSTRUCT object.

Here, the cleanup is performed automatically, because BeginPaint returns an EndPaintGuard, which stores the PAINTSTRUCT and automatically calls EndPaint when the guard goes out of scope. You must, however, keep the guard alive, otherwise the cleanup will be performed right away.

§Examples
use winsafe::{self as w, prelude::*};

let hwnd: w::HWND; // initialized somewhere

let hdc = hwnd.BeginPaint()?;

// do your hdc painting...

// EndPaint() called automatically

If you don’t use the returned device context handle, you must still keep the guard alive:

use winsafe::{self as w, prelude::*};

let hwnd: w::HWND; // initialized somewhere

let _hdc = hwnd.BeginPaint()?; // keep guard alive

// do your hdc painting...

// EndPaint() called automatically
source

fn BringWindowToTop(&self) -> SysResult<()>

BringWindowToTop function.

source

fn ChildWindowFromPoint(&self, pt: POINT) -> Option<HWND>

source

fn ClientToScreen(&self, pt: &mut POINT) -> SysResult<()>

ClientToScreen function.

If you need to convert a RECT, see the HWND::ClientToScreenRc function.

source

fn ClientToScreenRc(&self, rc: &mut RECT) -> SysResult<()>

ClientToScreen method for a RECT.

source

fn CloseWindow(&self) -> SysResult<()>

CloseWindow function.

Note that this method will actually minimize the window, not destroy it.

source

unsafe fn CreateWindowEx( ex_style: WS_EX, class_name: AtomStr, title: Option<&str>, style: WS, pos: POINT, size: SIZE, hwnd_parent: Option<&HWND>, hmenu: IdMenu<'_>, hinstance: &HINSTANCE, lparam: Option<isize> ) -> SysResult<HWND>

CreateWindowEx function.

§Safety

This method will create raw dynamic windows and controls outside the library safety – it’s up to you to handle all the messages. You must use a properly registered class name and, if creating a custom window, provide its own window procedure.

The usable ID range for dynamic child controls goes from 1 to 19,999. IDs starting from 20,000 are used internally by the library, do not use them.

source

unsafe fn DefWindowProc<M>(&self, msg: M) -> M::RetType
where M: MsgSend,

DefWindowProc function.

The return type is variable, being defined by the RetType associated type of the MsgSend trait. That means each message can define its own return type.

§Safety

Messages manipulate pointers, copies and window states. Improper use may lead to undefined behavior.

source

fn DestroyWindow(&self) -> SysResult<()>

DestroyWindow function.

Usually you don’t need to call this method directly, since it’s automatically called inside the internal message loop. The ordinary way to close a window is sending a wm::Close message.

source

fn DragDetect(&self, pt: POINT) -> bool

DragDetect function.

source

fn DrawCaption( &self, hdc: &HDC, rect: &RECT, flags: Option<DC> ) -> SysResult<()>

DrawCaption function.

source

fn DrawMenuBar(&self) -> SysResult<()>

DrawMenuBar function.

source

fn EnableScrollBar(&self, sb_flags: SBB, arrows: ESB) -> SysResult<()>

EnableScrollBar function.

source

fn EnableWindow(&self, enable: bool) -> bool

EnableWindow function.

source

fn EndDialog(&self, result: isize) -> SysResult<()>

EndDialog function.

source

fn EnumChildWindows<F>(&self, func: F)
where F: FnMut(HWND) -> bool,

EnumChildWindows function.

§Examples
use winsafe::{self as w, prelude::*};

let hwnd: w::HWND; // initialized somewhere

hwnd.EnumChildWindows(|hchild: w::HWND| -> bool {
    println!("Child HWND: {}", hchild);
    true
});
source

fn FindWindow( class_name: Option<AtomStr>, title: Option<&str> ) -> SysResult<Option<HWND>>

FindWindow function.

source

fn FindWindowEx( &self, hwnd_child_after: Option<&HWND>, class_name: AtomStr, title: Option<&str> ) -> SysResult<Option<HWND>>

FindWindowEx function.

source

fn GetActiveWindow() -> Option<HWND>

GetActiveWindow function.

source

fn GetAltTabInfo( &self, item: Option<u32>, ati: &mut ALTTABINFO, sz_item_text: Option<u32> ) -> SysResult<String>

GetAltTabInfo function.

If item is None, the item text is not retrieved.

The sz_item_text is the maximum number of expected chars for the item text. If None, defaults to 100.

source

fn GetAncestor(&self, flags: GA) -> Option<HWND>

GetAncestor function.

source

fn GetCapture() -> Option<HWND>

GetCapture function.

source

fn GetClassLongPtr(&self, index: GCLP) -> usize

GetClassLongPtr function.

If you just want to check whether the window is a dialog, prefer using HWND::is_dialog method.

source

fn GetClassName(&self) -> SysResult<String>

GetClassName function.

source

fn GetClientRect(&self) -> SysResult<RECT>

GetClientRect function.

source

fn GetDC(&self) -> SysResult<ReleaseDCGuard<'_, Self>>

GetDC function.

§Examples

Retrieving the device context of the desktop window:

use winsafe::{self as w, prelude::*};

let hdc_desktop = w::HWND::DESKTOP.GetDC()?;
source

fn GetDesktopWindow() -> HWND

GetDesktopWindow function.

source

fn GetDialogDpiChangeBehavior(&self) -> SysResult<DDC>

source

fn GetDlgCtrlID(&self) -> SysResult<u16>

GetDlgCtrlID function.

source

fn GetDlgItem(&self, ctrl_id: u16) -> SysResult<HWND>

GetDlgItem function.

source

fn GetDpiForWindow(&self) -> u32

GetDpiForWindow function.

source

fn GetFocus() -> Option<HWND>

GetFocus function.

source

fn GetForegroundWindow() -> Option<HWND>

source

fn GetLastActivePopup(&self) -> Option<HWND>

source

fn GetMenu(&self) -> Option<HMENU>

GetMenu function.

source

fn GetMenuBarInfo( &self, obj_id: OBJID, item_id: u32, mbi: &mut MENUBARINFO ) -> SysResult<()>

GetMenuBarInfo function.

source

fn GetMenuItemRect(&self, hmenu: &HMENU, item_pos: u32) -> SysResult<RECT>

GetMenuItemRect function.

source

fn GetNextDlgGroupItem( &self, hwnd_ctrl: &HWND, previous: bool ) -> SysResult<HWND>

source

fn GetNextDlgTabItem(&self, hwnd_ctrl: &HWND, previous: bool) -> SysResult<HWND>

source

fn GetParent(&self) -> SysResult<HWND>

GetParent function.

source

fn GetScrollInfo(&self, bar: SBB, si: &mut SCROLLINFO) -> SysResult<()>

GetScrollInfo function.

source

fn GetScrollPos(&self, bar: SBB) -> SysResult<i32>

GetScrollPos function.

source

fn GetShellWindow() -> Option<HWND>

GetShellWindow function.

source

fn GetSystemMenu(&self, revert: bool) -> Option<HMENU>

GetSystemMenu function.

source

fn GetTopWindow(&self) -> SysResult<Option<HWND>>

GetTopWindow function.

source

fn GetUpdateRect(&self, erase: bool) -> Option<RECT>

GetUpdateRect function.

source

fn GetUpdateRgn(&self, hrgn: &HRGN, erase: bool) -> SysResult<REGION>

GetUpdateRgn function.

source

fn GetWindow(&self, cmd: GW) -> SysResult<HWND>

GetWindow function.

source

fn GetWindowDC(&self) -> SysResult<ReleaseDCGuard<'_, Self>>

GetWindowDC function.

source

fn GetWindowDisplayAffinity(&self) -> SysResult<WDA>

source

fn GetWindowDpiHostingBehavior(&self) -> DPI_HOSTING_BEHAVIOR

source

fn GetWindowInfo(&self, wi: &mut WINDOWINFO) -> SysResult<()>

GetWindowInfo function.

source

fn GetWindowLongPtr(&self, index: GWLP) -> isize

GetWindowLong function (x32) or GetWindowLongPtr function (x64).

If you just want to retrieve the window HINSTANCE, prefer using HWND::hinstance.

If you just want to retrieve the window styles, prefer using HWND::style and HWND::style_ex.

source

fn GetWindowModuleFileName(&self) -> String

source

fn GetWindowPlacement(&self, wp: &mut WINDOWPLACEMENT) -> SysResult<()>

source

fn GetWindowRect(&self) -> SysResult<RECT>

GetWindowRect function.

source

fn GetWindowRgn(&self, hrgn: &HRGN) -> SysResult<REGION>

GetWindowRgn function.

source

fn GetWindowRgnBox(&self) -> SysResult<(RECT, REGION)>

GetWindowRgnBox function.

source

fn GetWindowText(&self) -> SysResult<String>

GetWindowText function.

Calls GetWindowTextLength and performs all necessary allocations, returning an ordinary String.

use winsafe::{self as w, prelude::*};

let hwnd: w::HWND; // initialized somewhere

let text = hwnd.GetWindowText()?;
println!("Text: {}", text);
source

fn GetWindowTextLength(&self) -> SysResult<i32>

GetWindowTextLength function.

Does not count the terminating null.

You usually don’t need to call this method directly, since GetWindowText returns a String, performing all necessary allocations.

source

fn GetWindowThreadProcessId(&self) -> (u32, u32)

GetWindowThreadProcessId function.

Returns thread ID and process ID, respectively.

source

fn HideCaret(&self) -> SysResult<()>

HideCaret function.

source

fn HiliteMenuItem(&self, hmenu: &HMENU, id_or_pos: IdPos, hilite: bool) -> bool

HiliteMenuItem function.

source

fn InheritWindowMonitor(&self, hwnd_inherit: &HWND) -> SysResult<()>

source

fn InvalidateRect(&self, rc: Option<&RECT>, erase: bool) -> SysResult<()>

InvalidateRect function.

§Examples

Most of the time you’ll just want update the entire client area:

use winsafe::{self as w, prelude::*};

let hwnd: w::HWND; // initialized somewhere

hwnd.InvalidateRect(None, true)?;
source

fn InvalidateRgn(&self, hrgn: &HRGN, erase: bool)

InvalidateRgn function.

source

fn IsChild(&self, hwnd_possible_child: &HWND) -> bool

IsChild function.

source

fn IsDialogMessage(&self, msg: &mut MSG) -> bool

IsDialogMessage function.

source

fn IsIconic(&self) -> bool

IsIconic function.

source

fn IsWindow(&self) -> bool

IsWindow function.

source

fn IsWindowEnabled(&self) -> bool

IsWindowEnabled function.

source

fn IsWindowUnicode(&self) -> bool

IsWindowUnicode function.

source

fn IsWindowVisible(&self) -> bool

IsWindowVisible function.

source

fn IsZoomed(&self) -> bool

IsZoomed function.

source

fn KillTimer(&self, event_id: usize) -> SysResult<()>

KillTimer function.

This function ends the timer calls for the given timer ID. If you don’t call this function, the timer calls will continue until the window is destroyed – at this point, any remaining timers will be automatically cleared.

source

fn LockWindowUpdate(&self) -> SysResult<()>

LockWindowUpdate function.

§Examples
use winsafe::{self as w, prelude::*};

let hwnd: w::HWND; // initialized somewhere

// Lock the window – only one window can be locked at a time.
hwnd.LockWindowUpdate()?;

// After all operations, unlock the currently locked window.
w::HWND::NULL.LockWindowUpdate()?;
source

fn LogicalToPhysicalPoint(&self, pt: *mut POINT) -> SysResult<()>

source

fn MapDialogRect(&self, rc: &mut RECT) -> SysResult<()>

MapDialogRect function.

source

fn MapWindowPoints( &self, hdest: &HWND, points: PtsRc<'_> ) -> SysResult<(i16, i16)>

MapWindowPoints function.

This method can convert either a series of POINT structs or a single RECT.

§Examples
use winsafe::{self as w, prelude::*};

let hwnd: w::HWND; // initialized somewhere
let hwnd_dest: w::HWND;

let mut points = vec![w::POINT::default(), w::POINT::default()];

hwnd.MapWindowPoints(
    &hwnd_dest,
    w::PtsRc::Pts(&mut points),
)?;
source

fn MessageBox(&self, text: &str, caption: &str, flags: MB) -> SysResult<DLGID>

MessageBox function.

Consider using the more modern HWND::TaskDialog method.

§Examples

A modal message box, which blocks its parent:

use winsafe::{self as w, prelude::*, co};

let hwnd: w::HWND; // initialized somewhere

hwnd.MessageBox("Hello, world", "title",
    co::MB::OKCANCEL | co::MB::ICONINFORMATION)?;

Usually the message box has a valid parent window, however, if for some reason you don’t have a window to serve as parent, you still can show a non-modal, parent-less message box by using the null window handle:

use winsafe::{self as w, prelude::*, co};

w::HWND::NULL
    .MessageBox("Hello, world", "Title", co::MB::ICONEXCLAMATION)?;
source

fn MonitorFromWindow(&self, flags: MONITOR) -> HMONITOR

source

fn MoveWindow(&self, pos: POINT, size: SIZE, repaint: bool) -> SysResult<()>

MoveWindow function.

source

fn OpenClipboard(&self) -> SysResult<CloseClipboardGuard<'_>>

OpenClipboard function.

In the original C implementation, you must call CloseClipboard as a cleanup operation.

Here, the cleanup is performed automatically, because OpenClipboard returns a CloseClipboardGuard, which automatically calls CloseClipboard when the guard goes out of scope. You must, however, keep the guard alive, otherwise the cleanup will be performed right away.

§Examples
use winsafe::{self as w, prelude::*};

let hwnd: w::HWND; // initialized somewhere

let _hclip = hwnd.OpenClipboard()?; // keep guard alive

You can also open the clipboard without an HWND owner:

use winsafe::{self as w, prelude::*};

let _hclip = w::HWND::NULL.OpenClipboard()?; // keep guard alive
source

unsafe fn PostMessage<M>(&self, msg: M) -> SysResult<()>
where M: MsgSend + Send + Copy + 'static,

PostMessage function.

Note that this method is asychronous.

§Safety

Messages manipulate pointers, copies and window states. Improper use may lead to undefined behavior.

source

fn RealChildWindowFromPoint( &self, pt_parent_client_coords: POINT ) -> Option<HWND>

source

fn RealGetWindowClass(&self) -> SysResult<String>

source

fn RedrawWindow( &self, rc_update: &RECT, hrgn_update: &HRGN, flags: RDW ) -> SysResult<()>

RedrawWindow function.

source

fn RegisterHotKey( &self, id: i32, modifiers: MOD, vkey_code: VK ) -> SysResult<()>

RegisterHotKey function.

source

fn ScreenToClient(&self, pt: &mut POINT) -> SysResult<()>

ScreenToClient function.

If you need to convert a RECT, see the HWND::ScreenToClientRc function.

source

fn ScreenToClientRc(&self, rc: &mut RECT) -> SysResult<()>

ScreenToClient method for a RECT.

source

fn ScrollWindowEx( &self, dx: i32, dy: i32, client_area_portion: Option<&RECT>, clipping_rect: Option<&RECT>, hrgn_update: Option<&HRGN>, updated_boundaries: Option<&mut RECT>, flags: SCROLLW ) -> SysResult<REGION>

ScrollWindowEx function.

source

unsafe fn SendMessage<M>(&self, msg: M) -> M::RetType
where M: MsgSend,

SendMessage function.

The return type is variable, being defined by the RetType associated type of the MsgSend trait. That means each message can define its own return type.

§Safety

Messages manipulate pointers, copies and window states. Improper use may lead to undefined behavior.

§Examples

Sending a bm::GetImage button message, which demands an image type parameter. Note that this specific message can also return an error, which is handled with ?:

use winsafe::{self as w, prelude::*, co, msg};

let hwnd: w::HWND; // initialized somewhere

let bmp = unsafe {
    hwnd.SendMessage(
        msg::bm::GetImage {
            img_type: co::IMAGE_TYPE::BITMAP,
        },
    )
}?;

Sending an em::CharFromPos edit message, which receives point coordinates and returns two values:

use winsafe::{self as w, prelude::*, msg};

let hwnd: w::HWND; // initialized somewhere

let (char_pos, line_pos) = unsafe {
    hwnd.SendMessage(
        msg::em::CharFromPos {
            coords: w::POINT::new(12, 20),
        },
    )
};
source

unsafe fn SendMessageTimeout<M>( &self, msg: M, flags: SMTO, timeout_ms: u32 ) -> SysResult<M::RetType>
where M: MsgSend,

SendMessageTimeout function.

§Safety

Messages manipulate pointers, copies and window states. Improper use may lead to undefined behavior.

source

fn SetActiveWindow(&self) -> SysResult<HWND>

SetActiveWindow function.

source

fn SetCapture(&self) -> ReleaseCaptureGuard<'_, Self>

SetCapture function.

source

fn SetDialogDpiChangeBehavior(&self, mask: DDC, values: DDC) -> SysResult<()>

source

fn SetFocus(&self) -> Option<HWND>

SetFocus function.

source

fn SetForegroundWindow(&self) -> bool

source

fn SetLayeredWindowAttributes( &self, transparency_color_key: COLORREF, alpha: u8, flags: LWA ) -> SysResult<()>

source

fn SetMenu(&self, hmenu: &HMENU) -> SysResult<()>

SetMenu function.

source

fn SetParent(&self, hwnd_new_parent: &HWND) -> SysResult<Option<HWND>>

SetParent function.

source

fn SetScrollInfo(&self, bar: SBB, si: &SCROLLINFO, redraw: bool) -> i32

SetScrollInfo function.

source

fn SetScrollPos(&self, b: SBB, pos: i32, redraw: bool) -> SysResult<i32>

SetScrollPos function.

source

fn SetScrollRange( &self, bar: SBB, min_pos: i32, max_pos: i32, redraw: bool ) -> SysResult<()>

SetScrollRange function.

source

fn SetTimer( &self, event_id: usize, elapse_ms: u32, timer_func: Option<TIMERPROC> ) -> SysResult<usize>

This method returns the timer ID, to be passed to HWND::KillTimer.

The timer calls – either wm_timer message or callback function – will continuously be executed until you call KillTimer. If you don’t call KillTimer, the timer calls will continue until the window is destroyed – at this point, any remaining timers will be automatically cleared.

§Why not closures?

A common C++ technique to use closures with SetTimer is allocating a closure on the heap and use its pointer as the timer ID. When the callback function is called, the pointer is dereferenced and the closure is then executed.

The problem with this approach is that the closure must be freed after KillTimer, which can be called from anywhere, including from the closure itself – that means you must keep the pointer outside the closure and free it somehow after the closure finishes.

Such approach is, obviously, incredibly unsafe, and only possible within Rust’s rigid ownership rules if we use some sort of garbage-collection, which will free the allocated closure some time after KillTimer is called and the closure itself finishes. Since that would incur in a performance penalty, the current implementation of SetTimer will only accept ordinary function pointers, not closures.

Handling the wm_timer message is simply more practical and efficient, so the use of a callback is discouraged here.

source

fn SetWindowDisplayAffinity(&self, affinity: WDA) -> SysResult<()>

source

unsafe fn SetWindowLongPtr(&self, index: GWLP, new_long: isize) -> isize

SetWindowLongPtr function.

If you just want to set the window styles, prefer using HWND::set_style and HWND::set_style_ex.

§Safety

Changing these values may potentially cause undefined behavior to the window, and passed pointers must be handled correctly.

source

fn SetWindowPlacement(&self, wp: &WINDOWPLACEMENT) -> SysResult<()>

source

fn SetWindowPos( &self, hwnd_insert_after: HwndPlace, pos: POINT, size: SIZE, flags: SWP ) -> SysResult<()>

SetWindowPos function.

§Examples
use winsafe::{self as w, prelude::*, co};

let hwnd: w::HWND; // initialized somewhere

hwnd.SetWindowPos(
    w::HwndPlace::None,
    w::POINT::new(10, 10),
    w::SIZE::default(),
    co::SWP::NOZORDER | co::SWP::NOSIZE,
)?;
source

fn SetWindowRgn(&self, hrgn: &HRGN, redraw: bool) -> SysResult<()>

SetWindowRgn function.

source

fn SetWindowText(&self, text: &str) -> SysResult<()>

SetWindowText function.

source

fn ShowCaret(&self) -> SysResult<()>

ShowCaret function.

source

fn ShowOwnedPopups(&self, show: bool) -> SysResult<()>

ShowOwnedPopups function.

source

fn ShowWindow(&self, show_cmd: SW) -> bool

ShowWindow function.

source

fn ShowWindowAsync(&self, show_cmd: SW) -> SysResult<()>

ShowWindowAsync function.

source

fn TileWindows( &self, how: MDITILE, rect: Option<RECT>, kids: Option<&[&HWND]> ) -> SysResult<u16>

TileWindows function.

source

fn TranslateAccelerator( &self, haccel_table: &HACCEL, msg: &mut MSG ) -> SysResult<()>

source

fn UnregisterHotKey(&self, id: i32) -> SysResult<()>

UnregisterHotKey function.

source

fn UpdateLayeredWindow( &self, hdc_dest: Option<&HDC>, pt_dest: Option<&POINT>, size: Option<&SIZE>, hdc_src: Option<&HDC>, pt_src: Option<&POINT>, key: COLORREF, blend: &BLENDFUNCTION, flags: ULW ) -> SysResult<()>

source

fn UpdateWindow(&self) -> SysResult<()>

UpdateWindow function.

source

fn ValidateRect(&self, rc: &RECT) -> SysResult<()>

ValidateRect function.

source

fn ValidateRgn(&self, hrgn: &HRGN) -> SysResult<()>

ValidateRgn function.

source

fn WindowFromPhysicalPoint(pt: POINT) -> Option<HWND>

source

fn WindowFromPoint(pt: POINT) -> Option<HWND>

WindowFromPoint function.

source

fn WinHelp(&self, help_file: &str, cmd: HELPW, data: usize) -> SysResult<()>

WinHelp function.

Object Safety§

This trait is not object safe.

Implementors§