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<()> { ... }
}
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§
sourceconst BROADCAST: HWND = _
const BROADCAST: HWND = _
Represents all top-level windows in
HWND::PostMessage
and
HWND::SendMessage
.
sourceconst DESKTOP: HWND = _
const DESKTOP: HWND = _
Represents the desktop window in
HWND::GetDC
.
Provided Methods§
sourcefn hinstance(&self) -> HINSTANCE
fn hinstance(&self) -> HINSTANCE
Calls
HWND::GetWindowLongPtr
to retrieve the window HINSTANCE
.
sourcefn is_dialog(&self) -> bool
fn is_dialog(&self) -> bool
Calls
HWND::GetClassLongPtr
to
retrieve the class atom
and check whether the window was created from a dialog resource.
sourcefn set_style(&self, style: impl Into<WS>)
fn set_style(&self, style: impl Into<WS>)
Calls
HWND::SetWindowLongPtr
to set the window styles.
sourcefn set_style_ex(&self, ex_style: impl Into<WS_EX>)
fn set_style_ex(&self, ex_style: impl Into<WS_EX>)
Calls
HWND::SetWindowLongPtr
to set the extended window styles.
sourcefn style(&self) -> WS
fn style(&self) -> WS
Calls
HWND::GetWindowLongPtr
to retrieve the window styles.
sourcefn style_ex(&self) -> WS_EX
fn style_ex(&self) -> WS_EX
Calls
HWND::GetWindowLongPtr
to retrieve the extended window styles.
sourcefn ArrangeIconicWindows(&self) -> SysResult<u32>
fn ArrangeIconicWindows(&self) -> SysResult<u32>
ArrangeIconicWindows
function.
sourcefn BeginPaint(&self) -> SysResult<EndPaintGuard<'_, Self>>
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
sourcefn BringWindowToTop(&self) -> SysResult<()>
fn BringWindowToTop(&self) -> SysResult<()>
BringWindowToTop
function.
sourcefn ChildWindowFromPoint(&self, pt: POINT) -> Option<HWND>
fn ChildWindowFromPoint(&self, pt: POINT) -> Option<HWND>
ChildWindowFromPoint
function.
sourcefn ClientToScreen(&self, pt: &mut POINT) -> SysResult<()>
fn ClientToScreen(&self, pt: &mut POINT) -> SysResult<()>
ClientToScreen
function.
If you need to convert a RECT
, see the
HWND::ClientToScreenRc
function.
sourcefn ClientToScreenRc(&self, rc: &mut RECT) -> SysResult<()>
fn ClientToScreenRc(&self, rc: &mut RECT) -> SysResult<()>
ClientToScreen
method for
a RECT
.
sourcefn CloseWindow(&self) -> SysResult<()>
fn CloseWindow(&self) -> SysResult<()>
CloseWindow
function.
Note that this method will actually minimize the window, not destroy it.
sourceunsafe 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 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.
sourceunsafe fn DefWindowProc<M>(&self, msg: M) -> M::RetTypewhere
M: MsgSend,
unsafe fn DefWindowProc<M>(&self, msg: M) -> M::RetTypewhere
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.
sourcefn DestroyWindow(&self) -> SysResult<()>
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.
sourcefn DragDetect(&self, pt: POINT) -> bool
fn DragDetect(&self, pt: POINT) -> bool
DragDetect
function.
sourcefn DrawCaption(
&self,
hdc: &HDC,
rect: &RECT,
flags: Option<DC>
) -> SysResult<()>
fn DrawCaption( &self, hdc: &HDC, rect: &RECT, flags: Option<DC> ) -> SysResult<()>
DrawCaption
function.
sourcefn DrawMenuBar(&self) -> SysResult<()>
fn DrawMenuBar(&self) -> SysResult<()>
DrawMenuBar
function.
sourcefn EnableScrollBar(&self, sb_flags: SBB, arrows: ESB) -> SysResult<()>
fn EnableScrollBar(&self, sb_flags: SBB, arrows: ESB) -> SysResult<()>
EnableScrollBar
function.
sourcefn EnableWindow(&self, enable: bool) -> bool
fn EnableWindow(&self, enable: bool) -> bool
EnableWindow
function.
sourcefn EnumChildWindows<F>(&self, func: F)
fn EnumChildWindows<F>(&self, func: F)
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
});
sourcefn FindWindow(
class_name: Option<AtomStr>,
title: Option<&str>
) -> SysResult<Option<HWND>>
fn FindWindow( class_name: Option<AtomStr>, title: Option<&str> ) -> SysResult<Option<HWND>>
FindWindow
function.
sourcefn FindWindowEx(
&self,
hwnd_child_after: Option<&HWND>,
class_name: AtomStr,
title: Option<&str>
) -> SysResult<Option<HWND>>
fn FindWindowEx( &self, hwnd_child_after: Option<&HWND>, class_name: AtomStr, title: Option<&str> ) -> SysResult<Option<HWND>>
FindWindowEx
function.
sourcefn GetActiveWindow() -> Option<HWND>
fn GetActiveWindow() -> Option<HWND>
GetActiveWindow
function.
sourcefn GetAltTabInfo(
&self,
item: Option<u32>,
ati: &mut ALTTABINFO,
sz_item_text: Option<u32>
) -> SysResult<String>
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.
sourcefn GetAncestor(&self, flags: GA) -> Option<HWND>
fn GetAncestor(&self, flags: GA) -> Option<HWND>
GetAncestor
function.
sourcefn GetCapture() -> Option<HWND>
fn GetCapture() -> Option<HWND>
GetCapture
function.
sourcefn GetClassLongPtr(&self, index: GCLP) -> usize
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.
sourcefn GetClassName(&self) -> SysResult<String>
fn GetClassName(&self) -> SysResult<String>
GetClassName
function.
sourcefn GetClientRect(&self) -> SysResult<RECT>
fn GetClientRect(&self) -> SysResult<RECT>
GetClientRect
function.
sourcefn GetDC(&self) -> SysResult<ReleaseDCGuard<'_, Self>>
fn GetDC(&self) -> SysResult<ReleaseDCGuard<'_, Self>>
sourcefn GetDesktopWindow() -> HWND
fn GetDesktopWindow() -> HWND
GetDesktopWindow
function.
sourcefn GetDialogDpiChangeBehavior(&self) -> SysResult<DDC>
fn GetDialogDpiChangeBehavior(&self) -> SysResult<DDC>
GetDialogDpiChangeBehavior
function.
sourcefn GetDlgCtrlID(&self) -> SysResult<u16>
fn GetDlgCtrlID(&self) -> SysResult<u16>
GetDlgCtrlID
function.
sourcefn GetDlgItem(&self, ctrl_id: u16) -> SysResult<HWND>
fn GetDlgItem(&self, ctrl_id: u16) -> SysResult<HWND>
GetDlgItem
function.
sourcefn GetDpiForWindow(&self) -> u32
fn GetDpiForWindow(&self) -> u32
GetDpiForWindow
function.
sourcefn GetForegroundWindow() -> Option<HWND>
fn GetForegroundWindow() -> Option<HWND>
GetForegroundWindow
function.
sourcefn GetLastActivePopup(&self) -> Option<HWND>
fn GetLastActivePopup(&self) -> Option<HWND>
GetLastActivePopup
function.
sourcefn GetMenuBarInfo(
&self,
obj_id: OBJID,
item_id: u32,
mbi: &mut MENUBARINFO
) -> SysResult<()>
fn GetMenuBarInfo( &self, obj_id: OBJID, item_id: u32, mbi: &mut MENUBARINFO ) -> SysResult<()>
GetMenuBarInfo
function.
sourcefn GetMenuItemRect(&self, hmenu: &HMENU, item_pos: u32) -> SysResult<RECT>
fn GetMenuItemRect(&self, hmenu: &HMENU, item_pos: u32) -> SysResult<RECT>
GetMenuItemRect
function.
sourcefn GetNextDlgGroupItem(
&self,
hwnd_ctrl: &HWND,
previous: bool
) -> SysResult<HWND>
fn GetNextDlgGroupItem( &self, hwnd_ctrl: &HWND, previous: bool ) -> SysResult<HWND>
GetNextDlgGroupItem
function.
sourcefn GetNextDlgTabItem(&self, hwnd_ctrl: &HWND, previous: bool) -> SysResult<HWND>
fn GetNextDlgTabItem(&self, hwnd_ctrl: &HWND, previous: bool) -> SysResult<HWND>
GetNextDlgTabItem
function.
sourcefn GetScrollInfo(&self, bar: SBB, si: &mut SCROLLINFO) -> SysResult<()>
fn GetScrollInfo(&self, bar: SBB, si: &mut SCROLLINFO) -> SysResult<()>
GetScrollInfo
function.
sourcefn GetScrollPos(&self, bar: SBB) -> SysResult<i32>
fn GetScrollPos(&self, bar: SBB) -> SysResult<i32>
GetScrollPos
function.
sourcefn GetShellWindow() -> Option<HWND>
fn GetShellWindow() -> Option<HWND>
GetShellWindow
function.
sourcefn GetSystemMenu(&self, revert: bool) -> Option<HMENU>
fn GetSystemMenu(&self, revert: bool) -> Option<HMENU>
GetSystemMenu
function.
sourcefn GetTopWindow(&self) -> SysResult<Option<HWND>>
fn GetTopWindow(&self) -> SysResult<Option<HWND>>
GetTopWindow
function.
sourcefn GetUpdateRect(&self, erase: bool) -> Option<RECT>
fn GetUpdateRect(&self, erase: bool) -> Option<RECT>
GetUpdateRect
function.
sourcefn GetUpdateRgn(&self, hrgn: &HRGN, erase: bool) -> SysResult<REGION>
fn GetUpdateRgn(&self, hrgn: &HRGN, erase: bool) -> SysResult<REGION>
GetUpdateRgn
function.
sourcefn GetWindowDC(&self) -> SysResult<ReleaseDCGuard<'_, Self>>
fn GetWindowDC(&self) -> SysResult<ReleaseDCGuard<'_, Self>>
GetWindowDC
function.
sourcefn GetWindowDisplayAffinity(&self) -> SysResult<WDA>
fn GetWindowDisplayAffinity(&self) -> SysResult<WDA>
GetWindowDisplayAffinity
function.
sourcefn GetWindowDpiHostingBehavior(&self) -> DPI_HOSTING_BEHAVIOR
fn GetWindowDpiHostingBehavior(&self) -> DPI_HOSTING_BEHAVIOR
GetWindowDpiHostingBehavior
function.
sourcefn GetWindowInfo(&self, wi: &mut WINDOWINFO) -> SysResult<()>
fn GetWindowInfo(&self, wi: &mut WINDOWINFO) -> SysResult<()>
GetWindowInfo
function.
sourcefn GetWindowLongPtr(&self, index: GWLP) -> isize
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
.
sourcefn GetWindowModuleFileName(&self) -> String
fn GetWindowModuleFileName(&self) -> String
GetWindowModuleFileName
function.
sourcefn GetWindowPlacement(&self, wp: &mut WINDOWPLACEMENT) -> SysResult<()>
fn GetWindowPlacement(&self, wp: &mut WINDOWPLACEMENT) -> SysResult<()>
GetWindowPlacement
function.
sourcefn GetWindowRect(&self) -> SysResult<RECT>
fn GetWindowRect(&self) -> SysResult<RECT>
GetWindowRect
function.
sourcefn GetWindowRgn(&self, hrgn: &HRGN) -> SysResult<REGION>
fn GetWindowRgn(&self, hrgn: &HRGN) -> SysResult<REGION>
GetWindowRgn
function.
sourcefn GetWindowRgnBox(&self) -> SysResult<(RECT, REGION)>
fn GetWindowRgnBox(&self) -> SysResult<(RECT, REGION)>
GetWindowRgnBox
function.
sourcefn GetWindowText(&self) -> SysResult<String>
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);
sourcefn GetWindowTextLength(&self) -> SysResult<i32>
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.
sourcefn GetWindowThreadProcessId(&self) -> (u32, u32)
fn GetWindowThreadProcessId(&self) -> (u32, u32)
GetWindowThreadProcessId
function.
Returns thread ID and process ID, respectively.
sourcefn HiliteMenuItem(&self, hmenu: &HMENU, id_or_pos: IdPos, hilite: bool) -> bool
fn HiliteMenuItem(&self, hmenu: &HMENU, id_or_pos: IdPos, hilite: bool) -> bool
HiliteMenuItem
function.
sourcefn InheritWindowMonitor(&self, hwnd_inherit: &HWND) -> SysResult<()>
fn InheritWindowMonitor(&self, hwnd_inherit: &HWND) -> SysResult<()>
InheritWindowMonitor
function.
sourcefn InvalidateRect(&self, rc: Option<&RECT>, erase: bool) -> SysResult<()>
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)?;
sourcefn InvalidateRgn(&self, hrgn: &HRGN, erase: bool)
fn InvalidateRgn(&self, hrgn: &HRGN, erase: bool)
InvalidateRgn
function.
sourcefn IsDialogMessage(&self, msg: &mut MSG) -> bool
fn IsDialogMessage(&self, msg: &mut MSG) -> bool
IsDialogMessage
function.
sourcefn IsWindowEnabled(&self) -> bool
fn IsWindowEnabled(&self) -> bool
IsWindowEnabled
function.
sourcefn IsWindowUnicode(&self) -> bool
fn IsWindowUnicode(&self) -> bool
IsWindowUnicode
function.
sourcefn IsWindowVisible(&self) -> bool
fn IsWindowVisible(&self) -> bool
IsWindowVisible
function.
sourcefn KillTimer(&self, event_id: usize) -> SysResult<()>
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.
sourcefn LockWindowUpdate(&self) -> SysResult<()>
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()?;
sourcefn LogicalToPhysicalPoint(&self, pt: *mut POINT) -> SysResult<()>
fn LogicalToPhysicalPoint(&self, pt: *mut POINT) -> SysResult<()>
LogicalToPhysicalPoint
function.
sourcefn MapDialogRect(&self, rc: &mut RECT) -> SysResult<()>
fn MapDialogRect(&self, rc: &mut RECT) -> SysResult<()>
MapDialogRect
function.
sourcefn MapWindowPoints(
&self,
hdest: &HWND,
points: PtsRc<'_>
) -> SysResult<(i16, i16)>
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),
)?;
sourcefn MessageBox(&self, text: &str, caption: &str, flags: MB) -> SysResult<DLGID>
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)?;
sourcefn MonitorFromWindow(&self, flags: MONITOR) -> HMONITOR
fn MonitorFromWindow(&self, flags: MONITOR) -> HMONITOR
MonitorFromWindow
function.
sourcefn MoveWindow(&self, pos: POINT, size: SIZE, repaint: bool) -> SysResult<()>
fn MoveWindow(&self, pos: POINT, size: SIZE, repaint: bool) -> SysResult<()>
MoveWindow
function.
sourcefn OpenClipboard(&self) -> SysResult<CloseClipboardGuard<'_>>
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
sourceunsafe fn PostMessage<M>(&self, msg: M) -> SysResult<()>
unsafe fn PostMessage<M>(&self, msg: M) -> SysResult<()>
PostMessage
function.
Note that this method is asychronous.
§Safety
Messages manipulate pointers, copies and window states. Improper use may lead to undefined behavior.
sourcefn RealChildWindowFromPoint(
&self,
pt_parent_client_coords: POINT
) -> Option<HWND>
fn RealChildWindowFromPoint( &self, pt_parent_client_coords: POINT ) -> Option<HWND>
RealChildWindowFromPoint
function.
sourcefn RealGetWindowClass(&self) -> SysResult<String>
fn RealGetWindowClass(&self) -> SysResult<String>
RealGetWindowClass
function.
sourcefn RedrawWindow(
&self,
rc_update: &RECT,
hrgn_update: &HRGN,
flags: RDW
) -> SysResult<()>
fn RedrawWindow( &self, rc_update: &RECT, hrgn_update: &HRGN, flags: RDW ) -> SysResult<()>
RedrawWindow
function.
sourcefn RegisterHotKey(
&self,
id: i32,
modifiers: MOD,
vkey_code: VK
) -> SysResult<()>
fn RegisterHotKey( &self, id: i32, modifiers: MOD, vkey_code: VK ) -> SysResult<()>
RegisterHotKey
function.
sourcefn ScreenToClient(&self, pt: &mut POINT) -> SysResult<()>
fn ScreenToClient(&self, pt: &mut POINT) -> SysResult<()>
ScreenToClient
function.
If you need to convert a RECT
, see the
HWND::ScreenToClientRc
function.
sourcefn ScreenToClientRc(&self, rc: &mut RECT) -> SysResult<()>
fn ScreenToClientRc(&self, rc: &mut RECT) -> SysResult<()>
ScreenToClient
method for
a RECT
.
sourcefn 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>
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.
sourceunsafe fn SendMessage<M>(&self, msg: M) -> M::RetTypewhere
M: MsgSend,
unsafe fn SendMessage<M>(&self, msg: M) -> M::RetTypewhere
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),
},
)
};
sourceunsafe fn SendMessageTimeout<M>(
&self,
msg: M,
flags: SMTO,
timeout_ms: u32
) -> SysResult<M::RetType>where
M: MsgSend,
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.
sourcefn SetActiveWindow(&self) -> SysResult<HWND>
fn SetActiveWindow(&self) -> SysResult<HWND>
SetActiveWindow
function.
sourcefn SetCapture(&self) -> ReleaseCaptureGuard<'_, Self>
fn SetCapture(&self) -> ReleaseCaptureGuard<'_, Self>
SetCapture
function.
sourcefn SetDialogDpiChangeBehavior(&self, mask: DDC, values: DDC) -> SysResult<()>
fn SetDialogDpiChangeBehavior(&self, mask: DDC, values: DDC) -> SysResult<()>
SetDialogDpiChangeBehavior
function.
sourcefn SetForegroundWindow(&self) -> bool
fn SetForegroundWindow(&self) -> bool
SetForegroundWindow
function.
sourcefn SetLayeredWindowAttributes(
&self,
transparency_color_key: COLORREF,
alpha: u8,
flags: LWA
) -> SysResult<()>
fn SetLayeredWindowAttributes( &self, transparency_color_key: COLORREF, alpha: u8, flags: LWA ) -> SysResult<()>
SetLayeredWindowAttributes
function.
sourcefn SetScrollInfo(&self, bar: SBB, si: &SCROLLINFO, redraw: bool) -> i32
fn SetScrollInfo(&self, bar: SBB, si: &SCROLLINFO, redraw: bool) -> i32
SetScrollInfo
function.
sourcefn SetScrollPos(&self, b: SBB, pos: i32, redraw: bool) -> SysResult<i32>
fn SetScrollPos(&self, b: SBB, pos: i32, redraw: bool) -> SysResult<i32>
SetScrollPos
function.
sourcefn SetScrollRange(
&self,
bar: SBB,
min_pos: i32,
max_pos: i32,
redraw: bool
) -> SysResult<()>
fn SetScrollRange( &self, bar: SBB, min_pos: i32, max_pos: i32, redraw: bool ) -> SysResult<()>
SetScrollRange
function.
sourcefn SetTimer(
&self,
event_id: usize,
elapse_ms: u32,
timer_func: Option<TIMERPROC>
) -> SysResult<usize>
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.
sourcefn SetWindowDisplayAffinity(&self, affinity: WDA) -> SysResult<()>
fn SetWindowDisplayAffinity(&self, affinity: WDA) -> SysResult<()>
SetWindowDisplayAffinity
function.
sourceunsafe fn SetWindowLongPtr(&self, index: GWLP, new_long: isize) -> isize
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.
sourcefn SetWindowPlacement(&self, wp: &WINDOWPLACEMENT) -> SysResult<()>
fn SetWindowPlacement(&self, wp: &WINDOWPLACEMENT) -> SysResult<()>
SetWindowPlacement
function.
sourcefn SetWindowPos(
&self,
hwnd_insert_after: HwndPlace,
pos: POINT,
size: SIZE,
flags: SWP
) -> SysResult<()>
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,
)?;
sourcefn SetWindowRgn(&self, hrgn: &HRGN, redraw: bool) -> SysResult<()>
fn SetWindowRgn(&self, hrgn: &HRGN, redraw: bool) -> SysResult<()>
SetWindowRgn
function.
sourcefn SetWindowText(&self, text: &str) -> SysResult<()>
fn SetWindowText(&self, text: &str) -> SysResult<()>
SetWindowText
function.
sourcefn ShowOwnedPopups(&self, show: bool) -> SysResult<()>
fn ShowOwnedPopups(&self, show: bool) -> SysResult<()>
ShowOwnedPopups
function.
sourcefn ShowWindow(&self, show_cmd: SW) -> bool
fn ShowWindow(&self, show_cmd: SW) -> bool
ShowWindow
function.
sourcefn ShowWindowAsync(&self, show_cmd: SW) -> SysResult<()>
fn ShowWindowAsync(&self, show_cmd: SW) -> SysResult<()>
ShowWindowAsync
function.
sourcefn TileWindows(
&self,
how: MDITILE,
rect: Option<RECT>,
kids: Option<&[&HWND]>
) -> SysResult<u16>
fn TileWindows( &self, how: MDITILE, rect: Option<RECT>, kids: Option<&[&HWND]> ) -> SysResult<u16>
TileWindows
function.
sourcefn TranslateAccelerator(
&self,
haccel_table: &HACCEL,
msg: &mut MSG
) -> SysResult<()>
fn TranslateAccelerator( &self, haccel_table: &HACCEL, msg: &mut MSG ) -> SysResult<()>
TranslateAccelerator
function.
sourcefn UnregisterHotKey(&self, id: i32) -> SysResult<()>
fn UnregisterHotKey(&self, id: i32) -> SysResult<()>
UnregisterHotKey
function.
sourcefn 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 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<()>
UpdateLayeredWindow
function.
sourcefn UpdateWindow(&self) -> SysResult<()>
fn UpdateWindow(&self) -> SysResult<()>
UpdateWindow
function.
sourcefn ValidateRect(&self, rc: &RECT) -> SysResult<()>
fn ValidateRect(&self, rc: &RECT) -> SysResult<()>
ValidateRect
function.
sourcefn ValidateRgn(&self, hrgn: &HRGN) -> SysResult<()>
fn ValidateRgn(&self, hrgn: &HRGN) -> SysResult<()>
ValidateRgn
function.
sourcefn WindowFromPhysicalPoint(pt: POINT) -> Option<HWND>
fn WindowFromPhysicalPoint(pt: POINT) -> Option<HWND>
WindowFromPhysicalPoint
function.
sourcefn WindowFromPoint(pt: POINT) -> Option<HWND>
fn WindowFromPoint(pt: POINT) -> Option<HWND>
WindowFromPoint
function.