pub struct HWND(/* private fields */);
user
only.Expand description
Handle to a window.
Implementations§
Source§impl HWND
impl HWND
Sourcepub unsafe fn DefSubclassProc<M>(&self, msg: M) -> M::RetTypewhere
M: MsgSend,
Available on crate feature comctl
only.
pub unsafe fn DefSubclassProc<M>(&self, msg: M) -> M::RetTypewhere
M: MsgSend,
comctl
only.DefSubclassProc
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.
Sourcepub fn InitializeFlatSB(&self) -> HrResult<()>
Available on crate feature comctl
only.
pub fn InitializeFlatSB(&self) -> HrResult<()>
comctl
only.InitializeFlatSB
function.
Sourcepub fn RemoveWindowSubclass(
&self,
subclass_func: SUBCLASSPROC,
subclass_id: usize,
) -> SysResult<()>
Available on crate feature comctl
only.
pub fn RemoveWindowSubclass( &self, subclass_func: SUBCLASSPROC, subclass_id: usize, ) -> SysResult<()>
comctl
only.RemoveWindowSubclass
function.
Sourcepub unsafe fn SetWindowSubclass(
&self,
subclass_proc: SUBCLASSPROC,
subclass_id: usize,
ref_data: usize,
) -> SysResult<()>
Available on crate feature comctl
only.
pub unsafe fn SetWindowSubclass( &self, subclass_proc: SUBCLASSPROC, subclass_id: usize, ref_data: usize, ) -> SysResult<()>
comctl
only.Sourcepub fn TaskDialog(
&self,
window_title: Option<&str>,
main_instruction: Option<&str>,
content: Option<&str>,
common_buttons: TDCBF,
icon: IconRes<'_>,
) -> HrResult<DLGID>
Available on crate feature comctl
only.
pub fn TaskDialog( &self, window_title: Option<&str>, main_instruction: Option<&str>, content: Option<&str>, common_buttons: TDCBF, icon: IconRes<'_>, ) -> HrResult<DLGID>
comctl
only.TaskDialog
function.
If you need more customization, see the
TaskDialogIndirect
function.
§Examples
An information message with just an OK button:
use winsafe::{self as w, prelude::*, co};
let hwnd: w::HWND; // initialized somewhere
hwnd.TaskDialog(
Some("Operation successful"),
None,
Some("The operation completed successfully."),
co::TDCBF::OK,
w::IconRes::Info,
)?;
Prompt the user to click OK or Cancel upon a question:
use winsafe::{self as w, prelude::*, co};
let hwnd: w::HWND; // initialized somewhere
let answer = hwnd.TaskDialog(
Some("My app name"),
Some("File modified"),
Some("The file has been modified.\nProceed closing the application?"),
co::TDCBF::OK | co::TDCBF::CANCEL,
w::IconRes::Warn,
)?;
if answer == co::DLGID::OK {
println!("User clicked OK.");
}
Sourcepub fn UninitializeFlatSB(&self) -> HrResult<()>
Available on crate feature comctl
only.
pub fn UninitializeFlatSB(&self) -> HrResult<()>
comctl
only.UninitializeFlatSB
function.
Source§impl HWND
impl HWND
Sourcepub fn DwmExtendFrameIntoClientArea(
&self,
margins_inset: &MARGINS,
) -> HrResult<()>
Available on crate feature dwm
only.
pub fn DwmExtendFrameIntoClientArea( &self, margins_inset: &MARGINS, ) -> HrResult<()>
dwm
only.DwmExtendFrameIntoClientArea
function.
Sourcepub fn DwmInvalidateIconicBitmaps(&self) -> HrResult<()>
Available on crate feature dwm
only.
pub fn DwmInvalidateIconicBitmaps(&self) -> HrResult<()>
dwm
only.DwmInvalidateIconicBitmaps
function.
Sourcepub fn DwmSetIconicLivePreviewBitmap(
&self,
hbmp: HBITMAP,
pt_client: Option<POINT>,
sit_flags: Option<DWM_SIT>,
) -> HrResult<()>
Available on crate feature dwm
only.
pub fn DwmSetIconicLivePreviewBitmap( &self, hbmp: HBITMAP, pt_client: Option<POINT>, sit_flags: Option<DWM_SIT>, ) -> HrResult<()>
dwm
only.DwmSetIconicLivePreviewBitmap
function.
Sourcepub fn DwmSetIconicThumbnail(
&self,
hbmp: HBITMAP,
sit_flags: Option<DWM_SIT>,
) -> HrResult<()>
Available on crate feature dwm
only.
pub fn DwmSetIconicThumbnail( &self, hbmp: HBITMAP, sit_flags: Option<DWM_SIT>, ) -> HrResult<()>
dwm
only.DwmSetIconicThumbnail
function.
Source§impl HWND
impl HWND
Sourcepub fn RegisterDragDrop(&self, drop_target: &IDropTarget) -> HrResult<()>
Available on crate feature ole
only.
pub fn RegisterDragDrop(&self, drop_target: &IDropTarget) -> HrResult<()>
ole
only.RegisterDragDrop
function.
Note that if you don’t call OleInitialize
before this function, you’ll receive an
ERROR::OUTOFMEMORY
error.
Sourcepub fn RevokeDragDrop(&self) -> HrResult<()>
Available on crate feature ole
only.
pub fn RevokeDragDrop(&self) -> HrResult<()>
ole
only.RevokeDragDrop
function.
Source§impl HWND
impl HWND
Sourcepub fn DragAcceptFiles(&self, accept: bool)
Available on crate feature shell
only.
pub fn DragAcceptFiles(&self, accept: bool)
shell
only.DragAcceptFiles
function.
Source§impl HWND
impl HWND
Sourcepub const unsafe fn from_ptr(p: *mut c_void) -> Self
pub const unsafe fn from_ptr(p: *mut c_void) -> Self
Constructs a new handle object by wrapping a pointer.
This method can be used as an escape hatch to interoperate with other libraries.
§Safety
Be sure the pointer has the correct type and isn’t owned by anyone else, otherwise you may cause memory access violations.
Sourcepub const unsafe fn raw_copy(&self) -> Self
pub const unsafe fn raw_copy(&self) -> Self
Returns a raw copy of the underlying handle pointer.
§Safety
As the name implies, raw_copy
returns a raw copy of the
handle, so closing one of the copies won’t close the others.
This means a handle can be used after it has been closed, what
can lead to errors and undefined behavior. Even worse: sometimes
Windows reuses handle values, so you can call a method on a
completely different handle type, what can be catastrophic.
However, in some cases the Windows API demands a copy of the
handle – raw_copy
is an escape hatch to fill this gap.
Sourcepub const unsafe fn as_mut(&mut self) -> &mut *mut c_void
pub const unsafe fn as_mut(&mut self) -> &mut *mut c_void
Returns a mutable reference to the underlying raw pointer.
This method can be used as an escape hatch to interoperate with other libraries.
§Safety
This method exposes the raw pointer used by raw Windows calls. It’s an opaque pointer to an internal Windows structure, and no dereferencings should be attempted.
Sourcepub const fn ptr(&self) -> *mut c_void
pub const fn ptr(&self) -> *mut c_void
Returns the underlying raw pointer.
This method exposes the raw pointer used by raw Windows calls. It’s an opaque pointer to an internal Windows structure, and no dereferencings should be attempted.
This method can be used as an escape hatch to interoperate with other libraries.
Source§impl HWND
impl HWND
Sourcepub const BROADCAST: HWND
pub const BROADCAST: HWND
Represents all top-level windows in
HWND::PostMessage
and
HWND::SendMessage
.
Sourcepub const DESKTOP: HWND
pub const DESKTOP: HWND
Represents the desktop window in HWND::GetDC
.
Sourcepub fn hinstance(&self) -> HINSTANCE
pub fn hinstance(&self) -> HINSTANCE
Calls
HWND::GetWindowLongPtr
to retrieve
the window HINSTANCE
.
Sourcepub fn is_dialog(&self) -> bool
pub fn is_dialog(&self) -> bool
Calls
HWND::GetClassLongPtr
to retrieve the
class atom and check
whether the window was created from a dialog resource.
Sourcepub fn set_style(&self, style: impl Into<WS>)
pub fn set_style(&self, style: impl Into<WS>)
Calls
HWND::SetWindowLongPtr
to set the
window styles.
Sourcepub fn set_style_ex(&self, ex_style: impl Into<WS_EX>)
pub fn set_style_ex(&self, ex_style: impl Into<WS_EX>)
Calls HWND::SetWindowLongPtr
to set
the extended window styles.
Sourcepub fn style(&self) -> WS
pub fn style(&self) -> WS
Calls HWND::GetWindowLongPtr
to
retrieve the window styles.
Sourcepub fn style_ex(&self) -> WS_EX
pub fn style_ex(&self) -> WS_EX
Calls HWND::GetWindowLongPtr
to
retrieve the extended window styles.
Sourcepub fn ArrangeIconicWindows(&self) -> SysResult<u32>
pub fn ArrangeIconicWindows(&self) -> SysResult<u32>
ArrangeIconicWindows
function.
Sourcepub fn BeginPaint(&self) -> SysResult<EndPaintGuard<'_>>
pub fn BeginPaint(&self) -> SysResult<EndPaintGuard<'_>>
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
Sourcepub fn BringWindowToTop(&self) -> SysResult<()>
pub fn BringWindowToTop(&self) -> SysResult<()>
BringWindowToTop
function.
Sourcepub fn ChildWindowFromPoint(&self, pt: POINT) -> Option<HWND>
pub fn ChildWindowFromPoint(&self, pt: POINT) -> Option<HWND>
ChildWindowFromPoint
function.
Sourcepub fn ClientToScreen(&self, pt: POINT) -> SysResult<POINT>
pub fn ClientToScreen(&self, pt: POINT) -> SysResult<POINT>
ClientToScreen
function.
If you need to convert a RECT
, see the
HWND::ClientToScreenRc
function.
Sourcepub fn ClientToScreenRc(&self, rc: RECT) -> SysResult<RECT>
pub fn ClientToScreenRc(&self, rc: RECT) -> SysResult<RECT>
ClientToScreen
method for a
RECT
.
Sourcepub fn CloseWindow(&self) -> SysResult<()>
pub fn CloseWindow(&self) -> SysResult<()>
CloseWindow
function.
Note that this method will actually minimize the window, not destroy it.
Sourcepub 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>
pub 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 child controls is 8 to 57,343.
Sourcepub unsafe fn DefWindowProc<M>(&self, msg: M) -> M::RetTypewhere
M: MsgSend,
pub 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.
Sourcepub fn DestroyWindow(&self) -> SysResult<()>
pub 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.
Sourcepub fn DragDetect(&self, pt: POINT) -> bool
pub fn DragDetect(&self, pt: POINT) -> bool
DragDetect
function.
Sourcepub fn DrawCaption(
&self,
hdc: &HDC,
rect: RECT,
flags: Option<DC>,
) -> SysResult<()>
pub fn DrawCaption( &self, hdc: &HDC, rect: RECT, flags: Option<DC>, ) -> SysResult<()>
DrawCaption
function.
Sourcepub fn DrawMenuBar(&self) -> SysResult<()>
pub fn DrawMenuBar(&self) -> SysResult<()>
DrawMenuBar
function.
Sourcepub fn EnableScrollBar(&self, sb_flags: SBB, arrows: ESB) -> SysResult<()>
pub fn EnableScrollBar(&self, sb_flags: SBB, arrows: ESB) -> SysResult<()>
EnableScrollBar
function.
Sourcepub fn EnableWindow(&self, enable: bool) -> bool
pub fn EnableWindow(&self, enable: bool) -> bool
EnableWindow
function.
Sourcepub fn EnumChildWindows<F>(&self, func: F)
pub 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
});
Sourcepub fn FindWindow(
class_name: Option<AtomStr>,
title: Option<&str>,
) -> SysResult<Option<HWND>>
pub fn FindWindow( class_name: Option<AtomStr>, title: Option<&str>, ) -> SysResult<Option<HWND>>
FindWindow
function.
Sourcepub fn FindWindowEx(
&self,
hwnd_child_after: Option<&HWND>,
class_name: AtomStr,
title: Option<&str>,
) -> SysResult<Option<HWND>>
pub fn FindWindowEx( &self, hwnd_child_after: Option<&HWND>, class_name: AtomStr, title: Option<&str>, ) -> SysResult<Option<HWND>>
FindWindowEx
function.
Sourcepub fn GetActiveWindow() -> Option<HWND>
pub fn GetActiveWindow() -> Option<HWND>
GetActiveWindow
function.
Sourcepub fn GetAltTabInfo(
&self,
item: Option<u32>,
ati: &mut ALTTABINFO,
sz_item_text: Option<u32>,
) -> SysResult<String>
pub 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.
Sourcepub fn GetAncestor(&self, flags: GA) -> Option<HWND>
pub fn GetAncestor(&self, flags: GA) -> Option<HWND>
GetAncestor
function.
Sourcepub fn GetCapture() -> Option<HWND>
pub fn GetCapture() -> Option<HWND>
GetCapture
function.
Sourcepub fn GetClassLongPtr(&self, index: GCLP) -> usize
pub 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.
Sourcepub fn GetClassName(&self) -> SysResult<String>
pub fn GetClassName(&self) -> SysResult<String>
GetClassName
function.
Sourcepub fn GetClientRect(&self) -> SysResult<RECT>
pub fn GetClientRect(&self) -> SysResult<RECT>
GetClientRect
function.
Sourcepub fn GetDC(&self) -> SysResult<ReleaseDCGuard<'_>>
pub fn GetDC(&self) -> SysResult<ReleaseDCGuard<'_>>
Sourcepub fn GetDCEx(
&self,
hrgn_clip: &HRGN,
flags: DCX,
) -> SysResult<ReleaseDCGuard<'_>>
pub fn GetDCEx( &self, hrgn_clip: &HRGN, flags: DCX, ) -> SysResult<ReleaseDCGuard<'_>>
GetDCEx
function.
Sourcepub fn GetDesktopWindow() -> HWND
pub fn GetDesktopWindow() -> HWND
GetDesktopWindow
function.
Sourcepub fn GetDialogDpiChangeBehavior(&self) -> SysResult<DDC>
pub fn GetDialogDpiChangeBehavior(&self) -> SysResult<DDC>
GetDialogDpiChangeBehavior
function.
Sourcepub fn GetDlgCtrlID(&self) -> SysResult<u16>
pub fn GetDlgCtrlID(&self) -> SysResult<u16>
GetDlgCtrlID
function.
Sourcepub fn GetDlgItem(&self, ctrl_id: u16) -> SysResult<HWND>
pub fn GetDlgItem(&self, ctrl_id: u16) -> SysResult<HWND>
GetDlgItem
function.
Sourcepub fn GetDpiForWindow(&self) -> u32
pub fn GetDpiForWindow(&self) -> u32
GetDpiForWindow
function.
Sourcepub fn GetForegroundWindow() -> Option<HWND>
pub fn GetForegroundWindow() -> Option<HWND>
GetForegroundWindow
function.
Sourcepub fn GetLastActivePopup(&self) -> Option<HWND>
pub fn GetLastActivePopup(&self) -> Option<HWND>
GetLastActivePopup
function.
Sourcepub fn GetMenuBarInfo(
&self,
obj_id: OBJID,
item_id: u32,
mbi: &mut MENUBARINFO,
) -> SysResult<()>
pub fn GetMenuBarInfo( &self, obj_id: OBJID, item_id: u32, mbi: &mut MENUBARINFO, ) -> SysResult<()>
GetMenuBarInfo
function.
Sourcepub fn GetMenuItemRect(&self, hmenu: &HMENU, item_pos: u32) -> SysResult<RECT>
pub fn GetMenuItemRect(&self, hmenu: &HMENU, item_pos: u32) -> SysResult<RECT>
GetMenuItemRect
function.
Sourcepub fn GetNextDlgGroupItem(
&self,
hwnd_ctrl: &HWND,
previous: bool,
) -> SysResult<HWND>
pub fn GetNextDlgGroupItem( &self, hwnd_ctrl: &HWND, previous: bool, ) -> SysResult<HWND>
GetNextDlgGroupItem
function.
Sourcepub fn GetNextDlgTabItem(
&self,
hwnd_ctrl: &HWND,
previous: bool,
) -> SysResult<HWND>
pub fn GetNextDlgTabItem( &self, hwnd_ctrl: &HWND, previous: bool, ) -> SysResult<HWND>
GetNextDlgTabItem
function.
Sourcepub fn GetScrollInfo(&self, bar: SBB, si: &mut SCROLLINFO) -> SysResult<()>
pub fn GetScrollInfo(&self, bar: SBB, si: &mut SCROLLINFO) -> SysResult<()>
GetScrollInfo
function.
Sourcepub fn GetScrollPos(&self, bar: SBB) -> SysResult<i32>
pub fn GetScrollPos(&self, bar: SBB) -> SysResult<i32>
GetScrollPos
function.
Sourcepub fn GetShellWindow() -> Option<HWND>
pub fn GetShellWindow() -> Option<HWND>
GetShellWindow
function.
Sourcepub fn GetSystemMenu(&self, revert: bool) -> Option<HMENU>
pub fn GetSystemMenu(&self, revert: bool) -> Option<HMENU>
GetSystemMenu
function.
Sourcepub fn GetTopWindow(&self) -> SysResult<Option<HWND>>
pub fn GetTopWindow(&self) -> SysResult<Option<HWND>>
GetTopWindow
function.
Sourcepub fn GetUpdateRect(&self, erase: bool) -> Option<RECT>
pub fn GetUpdateRect(&self, erase: bool) -> Option<RECT>
GetUpdateRect
function.
Sourcepub fn GetUpdateRgn(&self, hrgn: &HRGN, erase: bool) -> SysResult<REGION>
pub fn GetUpdateRgn(&self, hrgn: &HRGN, erase: bool) -> SysResult<REGION>
GetUpdateRgn
function.
Sourcepub fn GetWindowDC(&self) -> SysResult<ReleaseDCGuard<'_>>
pub fn GetWindowDC(&self) -> SysResult<ReleaseDCGuard<'_>>
GetWindowDC
function.
Sourcepub fn GetWindowDisplayAffinity(&self) -> SysResult<WDA>
pub fn GetWindowDisplayAffinity(&self) -> SysResult<WDA>
GetWindowDisplayAffinity
function.
Sourcepub fn GetWindowDpiHostingBehavior(&self) -> DPI_HOSTING_BEHAVIOR
pub fn GetWindowDpiHostingBehavior(&self) -> DPI_HOSTING_BEHAVIOR
GetWindowDpiHostingBehavior
function.
Sourcepub fn GetWindowInfo(&self, wi: &mut WINDOWINFO) -> SysResult<()>
pub fn GetWindowInfo(&self, wi: &mut WINDOWINFO) -> SysResult<()>
GetWindowInfo
function.
Sourcepub fn GetWindowLongPtr(&self, index: GWLP) -> isize
pub 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
.
Sourcepub fn GetWindowModuleFileName(&self) -> String
pub fn GetWindowModuleFileName(&self) -> String
GetWindowModuleFileName
function.
Sourcepub fn GetWindowPlacement(&self, wp: &mut WINDOWPLACEMENT) -> SysResult<()>
pub fn GetWindowPlacement(&self, wp: &mut WINDOWPLACEMENT) -> SysResult<()>
GetWindowPlacement
function.
Sourcepub fn GetWindowRect(&self) -> SysResult<RECT>
pub fn GetWindowRect(&self) -> SysResult<RECT>
GetWindowRect
function.
Sourcepub fn GetWindowRgn(&self, hrgn: &HRGN) -> SysResult<REGION>
pub fn GetWindowRgn(&self, hrgn: &HRGN) -> SysResult<REGION>
GetWindowRgn
function.
Sourcepub fn GetWindowRgnBox(&self) -> SysResult<(RECT, REGION)>
pub fn GetWindowRgnBox(&self) -> SysResult<(RECT, REGION)>
GetWindowRgnBox
function.
Sourcepub fn GetWindowText(&self) -> SysResult<String>
pub 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);
Sourcepub fn GetWindowTextLength(&self) -> SysResult<i32>
pub 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.
Sourcepub fn GetWindowThreadProcessId(&self) -> (u32, u32)
pub fn GetWindowThreadProcessId(&self) -> (u32, u32)
GetWindowThreadProcessId
function.
Returns thread ID and process ID, respectively.
Sourcepub fn HiliteMenuItem(
&self,
hmenu: &HMENU,
id_or_pos: IdPos,
hilite: bool,
) -> bool
pub fn HiliteMenuItem( &self, hmenu: &HMENU, id_or_pos: IdPos, hilite: bool, ) -> bool
HiliteMenuItem
function.
Sourcepub fn InheritWindowMonitor(&self, hwnd_inherit: &HWND) -> SysResult<()>
pub fn InheritWindowMonitor(&self, hwnd_inherit: &HWND) -> SysResult<()>
InheritWindowMonitor
function.
Sourcepub fn InvalidateRect(&self, rc: Option<&RECT>, erase: bool) -> SysResult<()>
pub 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)?;
Sourcepub fn InvalidateRgn(&self, hrgn: &HRGN, erase: bool)
pub fn InvalidateRgn(&self, hrgn: &HRGN, erase: bool)
InvalidateRgn
function.
Sourcepub fn IsDialogMessage(&self, msg: &mut MSG) -> bool
pub fn IsDialogMessage(&self, msg: &mut MSG) -> bool
IsDialogMessage
function.
Sourcepub fn IsWindowEnabled(&self) -> bool
pub fn IsWindowEnabled(&self) -> bool
IsWindowEnabled
function.
Sourcepub fn IsWindowUnicode(&self) -> bool
pub fn IsWindowUnicode(&self) -> bool
IsWindowUnicode
function.
Sourcepub fn IsWindowVisible(&self) -> bool
pub fn IsWindowVisible(&self) -> bool
IsWindowVisible
function.
Sourcepub fn KillTimer(&self, event_id: usize) -> SysResult<()>
pub 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.
Sourcepub fn LockWindowUpdate(&self) -> SysResult<()>
pub 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()?;
Sourcepub fn LogicalToPhysicalPoint(&self, pt: *mut POINT) -> SysResult<()>
pub fn LogicalToPhysicalPoint(&self, pt: *mut POINT) -> SysResult<()>
LogicalToPhysicalPoint
function.
Sourcepub fn MapDialogRect(&self, rc: RECT) -> SysResult<RECT>
pub fn MapDialogRect(&self, rc: RECT) -> SysResult<RECT>
MapDialogRect
function.
Sourcepub fn MapWindowPoints(
&self,
hdest: &HWND,
points: PtsRc<'_>,
) -> SysResult<(i16, i16)>
pub 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),
)?;
Sourcepub fn MessageBox(
&self,
text: &str,
caption: &str,
flags: MB,
) -> SysResult<DLGID>
pub 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)?;
Sourcepub fn MonitorFromWindow(&self, flags: MONITOR) -> HMONITOR
pub fn MonitorFromWindow(&self, flags: MONITOR) -> HMONITOR
MonitorFromWindow
function.
Sourcepub fn MoveWindow(&self, pos: POINT, size: SIZE, repaint: bool) -> SysResult<()>
pub fn MoveWindow(&self, pos: POINT, size: SIZE, repaint: bool) -> SysResult<()>
MoveWindow
function.
Sourcepub fn OpenClipboard(&self) -> SysResult<CloseClipboardGuard<'_>>
pub 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::*, co};
let hwnd: w::HWND; // initialized somewhere
let hclip = hwnd.OpenClipboard()?;
let data = hclip.GetClipboardData(co::CF::TEXT)?;
You can also open the clipboard without an HWND
owner:
use winsafe::{self as w, prelude::*, co};
let hclip = w::HWND::NULL.OpenClipboard()?;
let data = hclip.GetClipboardData(co::CF::TEXT)?;
Sourcepub unsafe fn PostMessage<M>(&self, msg: M) -> SysResult<()>
pub 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.
Sourcepub fn RealChildWindowFromPoint(
&self,
pt_parent_client_coords: POINT,
) -> Option<HWND>
pub fn RealChildWindowFromPoint( &self, pt_parent_client_coords: POINT, ) -> Option<HWND>
RealChildWindowFromPoint
function.
Sourcepub fn RealGetWindowClass(&self) -> SysResult<String>
pub fn RealGetWindowClass(&self) -> SysResult<String>
RealGetWindowClass
function.
Sourcepub fn RedrawWindow(
&self,
rc_update: RECT,
hrgn_update: &HRGN,
flags: RDW,
) -> SysResult<()>
pub fn RedrawWindow( &self, rc_update: RECT, hrgn_update: &HRGN, flags: RDW, ) -> SysResult<()>
RedrawWindow
function.
Sourcepub fn RegisterHotKey(
&self,
id: i32,
modifiers: MOD,
vkey_code: VK,
) -> SysResult<()>
pub fn RegisterHotKey( &self, id: i32, modifiers: MOD, vkey_code: VK, ) -> SysResult<()>
RegisterHotKey
function.
Sourcepub fn ScreenToClient(&self, pt: POINT) -> SysResult<POINT>
pub fn ScreenToClient(&self, pt: POINT) -> SysResult<POINT>
ScreenToClient
function.
If you need to convert a RECT
, see the
HWND::ScreenToClientRc
function.
Sourcepub fn ScreenToClientRc(&self, rc: RECT) -> SysResult<RECT>
pub fn ScreenToClientRc(&self, rc: RECT) -> SysResult<RECT>
ScreenToClient
method for a
RECT
.
Sourcepub 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>
pub 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.
Sourcepub fn SendCommand(&self, cmd: AccelMenuCtrl)
pub fn SendCommand(&self, cmd: AccelMenuCtrl)
SendMessage
function, specialized to send a wm::Command
message.
Unlike the general SendMessage
, sending a
command is safe.
§Examples
use winsafe::{self as w, prelude::*, msg};
let hwnd: w::HWND; // initialized somewhere
const ID_MENU_FILE_OPEN: u16 = 103;
hwnd.SendCommand(
w::AccelMenuCtrl::Menu(ID_MENU_FILE_OPEN),
);
Sourcepub unsafe fn SendMessage<M>(&self, msg: M) -> M::RetTypewhere
M: MsgSend,
pub 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::with(12, 20),
},
)
};
Sourcepub unsafe fn SendMessageTimeout<M>(
&self,
msg: M,
flags: SMTO,
timeout_ms: u32,
) -> SysResult<M::RetType>where
M: MsgSend,
pub 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.
Sourcepub fn SetActiveWindow(&self) -> SysResult<HWND>
pub fn SetActiveWindow(&self) -> SysResult<HWND>
SetActiveWindow
function.
Sourcepub fn SetCapture(&self) -> ReleaseCaptureGuard<'_>
pub fn SetCapture(&self) -> ReleaseCaptureGuard<'_>
SetCapture
function.
Sourcepub fn SetDialogDpiChangeBehavior(
&self,
mask: DDC,
values: DDC,
) -> SysResult<()>
pub fn SetDialogDpiChangeBehavior( &self, mask: DDC, values: DDC, ) -> SysResult<()>
SetDialogDpiChangeBehavior
function.
Sourcepub fn SetForegroundWindow(&self) -> bool
pub fn SetForegroundWindow(&self) -> bool
SetForegroundWindow
function.
Sourcepub fn SetLayeredWindowAttributes(
&self,
transparency_color_key: COLORREF,
alpha: u8,
flags: LWA,
) -> SysResult<()>
pub fn SetLayeredWindowAttributes( &self, transparency_color_key: COLORREF, alpha: u8, flags: LWA, ) -> SysResult<()>
SetLayeredWindowAttributes
function.
Sourcepub fn SetScrollInfo(&self, bar: SBB, si: &SCROLLINFO, redraw: bool) -> i32
pub fn SetScrollInfo(&self, bar: SBB, si: &SCROLLINFO, redraw: bool) -> i32
SetScrollInfo
function.
Sourcepub fn SetScrollPos(&self, b: SBB, pos: i32, redraw: bool) -> SysResult<i32>
pub fn SetScrollPos(&self, b: SBB, pos: i32, redraw: bool) -> SysResult<i32>
SetScrollPos
function.
Sourcepub fn SetScrollRange(
&self,
bar: SBB,
min_pos: i32,
max_pos: i32,
redraw: bool,
) -> SysResult<()>
pub fn SetScrollRange( &self, bar: SBB, min_pos: i32, max_pos: i32, redraw: bool, ) -> SysResult<()>
SetScrollRange
function.
Sourcepub fn SetTimer(
&self,
event_id: usize,
elapse_ms: u32,
timer_func: Option<TIMERPROC>,
) -> SysResult<usize>
pub 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.
Sourcepub fn SetWindowDisplayAffinity(&self, affinity: WDA) -> SysResult<()>
pub fn SetWindowDisplayAffinity(&self, affinity: WDA) -> SysResult<()>
SetWindowDisplayAffinity
function.
Sourcepub unsafe fn SetWindowLongPtr(&self, index: GWLP, new_long: isize) -> isize
pub 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.
Sourcepub fn SetWindowPlacement(&self, wp: &WINDOWPLACEMENT) -> SysResult<()>
pub fn SetWindowPlacement(&self, wp: &WINDOWPLACEMENT) -> SysResult<()>
SetWindowPlacement
function.
Sourcepub fn SetWindowPos(
&self,
hwnd_insert_after: HwndPlace,
pos: POINT,
size: SIZE,
flags: SWP,
) -> SysResult<()>
pub 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::with(10, 10),
w::SIZE::default(),
co::SWP::NOZORDER | co::SWP::NOSIZE,
)?;
Sourcepub fn SetWindowRgn(&self, hrgn: &HRGN, redraw: bool) -> SysResult<()>
pub fn SetWindowRgn(&self, hrgn: &HRGN, redraw: bool) -> SysResult<()>
SetWindowRgn
function.
Sourcepub fn SetWindowText(&self, text: &str) -> SysResult<()>
pub fn SetWindowText(&self, text: &str) -> SysResult<()>
SetWindowText
function.
Sourcepub fn ShowOwnedPopups(&self, show: bool) -> SysResult<()>
pub fn ShowOwnedPopups(&self, show: bool) -> SysResult<()>
ShowOwnedPopups
function.
Sourcepub fn ShowWindow(&self, show_cmd: SW) -> bool
pub fn ShowWindow(&self, show_cmd: SW) -> bool
ShowWindow
function.
Sourcepub fn ShowWindowAsync(&self, show_cmd: SW) -> SysResult<()>
pub fn ShowWindowAsync(&self, show_cmd: SW) -> SysResult<()>
ShowWindowAsync
function.
Sourcepub fn ShutdownBlockReasonCreate(&self, reason: &str) -> SysResult<()>
pub fn ShutdownBlockReasonCreate(&self, reason: &str) -> SysResult<()>
ShutdownBlockReasonCreate
function.
Sourcepub fn ShutdownBlockReasonDestroy(&self) -> SysResult<()>
pub fn ShutdownBlockReasonDestroy(&self) -> SysResult<()>
ShutdownBlockReasonDestroy
function.
Sourcepub fn ShutdownBlockReasonQuery(&self) -> SysResult<String>
pub fn ShutdownBlockReasonQuery(&self) -> SysResult<String>
ShutdownBlockReasonQuery
function.
Sourcepub fn TileWindows(
&self,
how: MDITILE,
rect: Option<RECT>,
kids: &[&HWND],
) -> SysResult<u16>
pub fn TileWindows( &self, how: MDITILE, rect: Option<RECT>, kids: &[&HWND], ) -> SysResult<u16>
TileWindows
function.
Sourcepub fn TranslateAccelerator(
&self,
haccel_table: &HACCEL,
msg: &mut MSG,
) -> SysResult<()>
pub fn TranslateAccelerator( &self, haccel_table: &HACCEL, msg: &mut MSG, ) -> SysResult<()>
TranslateAccelerator
function.
Sourcepub fn UnregisterHotKey(&self, id: i32) -> SysResult<()>
pub fn UnregisterHotKey(&self, id: i32) -> SysResult<()>
UnregisterHotKey
function.
Sourcepub 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<()>
pub 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.
Sourcepub fn UpdateWindow(&self) -> SysResult<()>
pub fn UpdateWindow(&self) -> SysResult<()>
UpdateWindow
function.
Sourcepub fn ValidateRect(&self, rc: Option<RECT>) -> SysResult<()>
pub fn ValidateRect(&self, rc: Option<RECT>) -> SysResult<()>
ValidateRect
function.
Sourcepub fn ValidateRgn(&self, hrgn: &HRGN) -> SysResult<()>
pub fn ValidateRgn(&self, hrgn: &HRGN) -> SysResult<()>
ValidateRgn
function.
Sourcepub fn WindowFromPhysicalPoint(pt: POINT) -> Option<HWND>
pub fn WindowFromPhysicalPoint(pt: POINT) -> Option<HWND>
WindowFromPhysicalPoint
function.
Sourcepub fn WindowFromPoint(pt: POINT) -> Option<HWND>
pub fn WindowFromPoint(pt: POINT) -> Option<HWND>
WindowFromPoint
function.
Source§impl HWND
impl HWND
Sourcepub fn OpenThemeData(&self, class_list: &str) -> Option<CloseThemeDataGuard>
Available on crate feature uxtheme
only.
pub fn OpenThemeData(&self, class_list: &str) -> Option<CloseThemeDataGuard>
uxtheme
only.OpenThemeData
function.
Sourcepub fn SetWindowTheme(
&self,
sub_app_name: &str,
sub_id_list: Option<&str>,
) -> HrResult<()>
Available on crate feature uxtheme
only.
pub fn SetWindowTheme( &self, sub_app_name: &str, sub_id_list: Option<&str>, ) -> HrResult<()>
uxtheme
only.SetWindowTheme
function.
Source§impl HWND
impl HWND
Sourcepub fn AddPrinterConnection2(
&self,
name: &str,
connection_info: &PRINTER_CONNECTION_INFO_1<'_>,
) -> SysResult<()>
Available on crate feature winspool
only.
pub fn AddPrinterConnection2( &self, name: &str, connection_info: &PRINTER_CONNECTION_INFO_1<'_>, ) -> SysResult<()>
winspool
only.AddPrinterConnection2
function.
Sourcepub fn AdvancedDocumentProperties(
&self,
hprinter: &HPRINTER,
device_name: &str,
mode_input: &DEVMODE,
) -> SysResult<DEVMODE>
Available on crate feature winspool
only.
pub fn AdvancedDocumentProperties( &self, hprinter: &HPRINTER, device_name: &str, mode_input: &DEVMODE, ) -> SysResult<DEVMODE>
winspool
only.AdvancedDocumentProperties
function.
Sourcepub fn PrinterProperties(&self, hprinter: &HPRINTER) -> SysResult<()>
Available on crate feature winspool
only.
pub fn PrinterProperties(&self, hprinter: &HPRINTER) -> SysResult<()>
winspool
only.PrinterProperties
function.
Trait Implementations§
Source§impl Handle for HWND
impl Handle for HWND
Source§const NULL: Self
const NULL: Self
kernel
only.0
.Source§const INVALID: Self
const INVALID: Self
kernel
only.-1
. Read moreSource§unsafe fn from_ptr(p: *mut c_void) -> Self
unsafe fn from_ptr(p: *mut c_void) -> Self
kernel
only.Source§unsafe fn raw_copy(&self) -> Self
unsafe fn raw_copy(&self) -> Self
kernel
only.Source§unsafe fn as_mut(&mut self) -> &mut *mut c_void
unsafe fn as_mut(&mut self) -> &mut *mut c_void
kernel
only.