Struct HWND

Source
pub struct HWND(/* private fields */);
Available on crate feature user only.
Expand description

Handle to a window.

Implementations§

Source§

impl HWND

Source

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

Available on crate feature 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.

Source

pub fn InitializeFlatSB(&self) -> HrResult<()>

Available on crate feature comctl only.

InitializeFlatSB function.

Source

pub fn RemoveWindowSubclass( &self, subclass_func: SUBCLASSPROC, subclass_id: usize, ) -> SysResult<()>

Available on crate feature comctl only.
Source

pub unsafe fn SetWindowSubclass( &self, subclass_proc: SUBCLASSPROC, subclass_id: usize, ref_data: usize, ) -> SysResult<()>

Available on crate feature comctl only.

SetWindowSubclass function.

§Safety

You must provide a subclass procedure.

Source

pub 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.

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.");
}
Source

pub fn UninitializeFlatSB(&self) -> HrResult<()>

Available on crate feature comctl only.
Source§

impl HWND

Source

pub fn DwmExtendFrameIntoClientArea( &self, margins_inset: &MARGINS, ) -> HrResult<()>

Available on crate feature dwm only.
Source

pub fn DwmInvalidateIconicBitmaps(&self) -> HrResult<()>

Available on crate feature dwm only.
Source

pub fn DwmSetIconicLivePreviewBitmap( &self, hbmp: HBITMAP, pt_client: Option<POINT>, sit_flags: Option<DWM_SIT>, ) -> HrResult<()>

Available on crate feature dwm only.
Source

pub fn DwmSetIconicThumbnail( &self, hbmp: HBITMAP, sit_flags: Option<DWM_SIT>, ) -> HrResult<()>

Available on crate feature dwm only.
Source§

impl HWND

Source

pub fn RegisterDragDrop(&self, drop_target: &IDropTarget) -> HrResult<()>

Available on crate feature ole only.

RegisterDragDrop function.

Note that if you don’t call OleInitialize before this function, you’ll receive an ERROR::OUTOFMEMORY error.

Source

pub fn RevokeDragDrop(&self) -> HrResult<()>

Available on crate feature ole only.

RevokeDragDrop function.

Source§

impl HWND

Source

pub fn DragAcceptFiles(&self, accept: bool)

Available on crate feature shell only.

DragAcceptFiles function.

Source

pub fn ShellAbout( &self, title_bar: &str, first_line: Option<&str>, other_stuff: Option<&str>, hicon: Option<&HICON>, ) -> SysResult<()>

Available on crate feature shell only.

ShellAbout function.

Source

pub fn ShellExecute( &self, operation: &str, file: &str, parameters: Option<&str>, directory: Option<&str>, show_cmd: SW, ) -> SysResult<()>

Available on crate feature shell only.

ShellExecute function.

Source§

impl HWND

Source

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.

Source

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.

Source

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.

Source

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

Source

pub const BROADCAST: HWND

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

Source

pub const DESKTOP: HWND

Represents the desktop window in HWND::GetDC.

Source

pub fn hinstance(&self) -> HINSTANCE

Calls HWND::GetWindowLongPtr to retrieve the window HINSTANCE.

Source

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.

Source

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

Calls HWND::SetWindowLongPtr to set the window styles.

Source

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

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

Source

pub fn style(&self) -> WS

Calls HWND::GetWindowLongPtr to retrieve the window styles.

Source

pub fn style_ex(&self) -> WS_EX

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

Source

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

Source

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
Source

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

BringWindowToTop function.

Source

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

Source

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

ClientToScreen function.

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

Source

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

ClientToScreen method for a RECT.

Source

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

CloseWindow function.

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

Source

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.

Source

pub 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

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.

Source

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

DragDetect function.

Source

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

DrawCaption function.

Source

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

DrawMenuBar function.

Source

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

EnableScrollBar function.

Source

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

EnableWindow function.

Source

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

EndDialog function.

Source

pub 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

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

FindWindow function.

Source

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

FindWindowEx function.

Source

pub fn GetActiveWindow() -> Option<HWND>

GetActiveWindow function.

Source

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.

Source

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

GetAncestor function.

Source

pub fn GetCapture() -> Option<HWND>

GetCapture function.

Source

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.

Source

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

GetClassName function.

Source

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

GetClientRect function.

Source

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

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

pub fn GetDCEx( &self, hrgn_clip: &HRGN, flags: DCX, ) -> SysResult<ReleaseDCGuard<'_>>

GetDCEx function.

Source

pub fn GetDesktopWindow() -> HWND

GetDesktopWindow function.

Source

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

Source

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

GetDlgCtrlID function.

Source

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

GetDlgItem function.

Source

pub fn GetDpiForWindow(&self) -> u32

GetDpiForWindow function.

Source

pub fn GetFocus() -> Option<HWND>

GetFocus function.

Source

pub fn GetForegroundWindow() -> Option<HWND>

Source

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

Source

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

GetMenu function.

Source

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

GetMenuBarInfo function.

Source

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

GetMenuItemRect function.

Source

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

Source

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

Source

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

GetParent function.

Source

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

GetScrollInfo function.

Source

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

GetScrollPos function.

Source

pub fn GetShellWindow() -> Option<HWND>

GetShellWindow function.

Source

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

GetSystemMenu function.

Source

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

GetTopWindow function.

Source

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

GetUpdateRect function.

Source

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

GetUpdateRgn function.

Source

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

GetWindow function.

Source

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

GetWindowDC function.

Source

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

Source

pub fn GetWindowDpiHostingBehavior(&self) -> DPI_HOSTING_BEHAVIOR

Source

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

GetWindowInfo function.

Source

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.

Source

pub fn GetWindowModuleFileName(&self) -> String

Source

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

Source

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

GetWindowRect function.

Source

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

GetWindowRgn function.

Source

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

GetWindowRgnBox function.

Source

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);
Source

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.

Source

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

GetWindowThreadProcessId function.

Returns thread ID and process ID, respectively.

Source

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

HideCaret function.

Source

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

HiliteMenuItem function.

Source

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

Source

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)?;
Source

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

InvalidateRgn function.

Source

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

IsChild function.

Source

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

IsDialogMessage function.

Source

pub fn IsIconic(&self) -> bool

IsIconic function.

Source

pub fn IsWindow(&self) -> bool

IsWindow function.

Source

pub fn IsWindowEnabled(&self) -> bool

IsWindowEnabled function.

Source

pub fn IsWindowUnicode(&self) -> bool

IsWindowUnicode function.

Source

pub fn IsWindowVisible(&self) -> bool

IsWindowVisible function.

Source

pub fn IsZoomed(&self) -> bool

IsZoomed function.

Source

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.

Source

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()?;
Source

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

Source

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

MapDialogRect function.

Source

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),
)?;
Source

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)?;
Source

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

Source

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

MoveWindow function.

Source

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)?;
Source

pub 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

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

Source

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

Source

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

RedrawWindow function.

Source

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

RegisterHotKey function.

Source

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

ScreenToClient function.

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

Source

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

ScreenToClient method for a RECT.

Source

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.

Source

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),
);
Source

pub 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::with(12, 20),
        },
    )
};
Source

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.

Source

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

SetActiveWindow function.

Source

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

SetCapture function.

Source

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

Source

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

SetFocus function.

Source

pub fn SetForegroundWindow(&self) -> bool

Source

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

Source

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

SetMenu function.

Source

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

SetParent function.

Source

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

SetScrollInfo function.

Source

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

SetScrollPos function.

Source

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

SetScrollRange function.

Source

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.

Source

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

Source

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.

Source

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

Source

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,
)?;
Source

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

SetWindowRgn function.

Source

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

SetWindowText function.

Source

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

ShowCaret function.

Source

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

ShowOwnedPopups function.

Source

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

ShowWindow function.

Source

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

ShowWindowAsync function.

Source

pub fn ShutdownBlockReasonCreate(&self, reason: &str) -> SysResult<()>

Source

pub fn ShutdownBlockReasonDestroy(&self) -> SysResult<()>

Source

pub fn ShutdownBlockReasonQuery(&self) -> SysResult<String>

Source

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

TileWindows function.

Source

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

Source

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

UnregisterHotKey function.

Source

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<()>

Source

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

UpdateWindow function.

Source

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

ValidateRect function.

Source

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

ValidateRgn function.

Source

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

Source

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

WindowFromPoint function.

Source

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

WinHelp function.

Source§

impl HWND

Source

pub fn OpenThemeData(&self, class_list: &str) -> Option<CloseThemeDataGuard>

Available on crate feature uxtheme only.

OpenThemeData function.

Source

pub fn SetWindowTheme( &self, sub_app_name: &str, sub_id_list: Option<&str>, ) -> HrResult<()>

Available on crate feature uxtheme only.

SetWindowTheme function.

Source§

impl HWND

Source

pub fn AddPrinterConnection2( &self, name: &str, connection_info: &PRINTER_CONNECTION_INFO_1<'_>, ) -> SysResult<()>

Available on crate feature winspool only.
Source

pub fn AdvancedDocumentProperties( &self, hprinter: &HPRINTER, device_name: &str, mode_input: &DEVMODE, ) -> SysResult<DEVMODE>

Available on crate feature winspool only.
Source

pub fn PrinterProperties(&self, hprinter: &HPRINTER) -> SysResult<()>

Available on crate feature winspool only.

Trait Implementations§

Source§

impl Debug for HWND

Source§

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

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

impl Display for HWND

Source§

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

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

impl Handle for HWND

Source§

const NULL: Self

Available on crate feature kernel only.
The null, uninitialized handle; equals to 0.
Source§

const INVALID: Self

Available on crate feature kernel only.
The invalid handle; equals to -1. Read more
Source§

unsafe fn from_ptr(p: *mut c_void) -> Self

Available on crate feature kernel only.
Constructs a new handle object by wrapping a pointer. Read more
Source§

unsafe fn raw_copy(&self) -> Self

Available on crate feature kernel only.
Returns a raw copy of the underlying handle pointer. Read more
Source§

unsafe fn as_mut(&mut self) -> &mut *mut c_void

Available on crate feature kernel only.
Returns a mutable reference to the underlying raw pointer. Read more
Source§

fn ptr(&self) -> *mut c_void

Available on crate feature kernel only.
Returns the underlying raw pointer. Read more
Source§

fn as_opt(&self) -> Option<&Self>

Available on crate feature kernel only.
Returns None if the handle is null or invalid, otherwise returns Some(&self). Read more
Source§

impl Hash for HWND

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl LowerHex for HWND

Source§

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

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

impl PartialEq for HWND

Source§

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

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

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

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

impl UpperHex for HWND

Source§

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

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

impl Eq for HWND

Source§

impl Send for HWND

Source§

impl StructuralPartialEq for HWND

Auto Trait Implementations§

§

impl Freeze for HWND

§

impl RefUnwindSafe for HWND

§

impl !Sync for HWND

§

impl Unpin for HWND

§

impl UnwindSafe for HWND

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.