Struct winsafe::HWND [−][src]
#[repr(C)]pub struct HWND { /* fields omitted */ }
Expand description
Handle to a window.
Implementations
Creates a new handle instance by wrapping a pointer.
This method is common to all handle types.
Consumes the handle returning the underlying raw pointer.
This method is common to all handle types.
Tells if the handle is invalid (null).
This method is common to all handle types.
Represents all top-level windows in
HWND::PostMessage
and
HWND::SendMessage
.
GetWindowLongPtr
wrapper to retrieve
the window HINSTANCE
.
ArrangeIconicWindows
method.
BeginPaint
method.
Note: Must be paired with an
HWND::EndPaint
call.
Examples
BeginPaint
is usually called inside a
WM_PAINT
event to paint
the window client area:
use winsafe::{gui, PAINTSTRUCT};
let my_main: gui::WindowMain; // initialized somewhere
my_main.on().wm_paint({
let my_main = my_main.clone();
move || {
let mut ps = PAINTSTRUCT::default();
let hdc = my_main.hwnd().BeginPaint(&mut ps)?;
// paint the HDC...
my_main.hwnd().EndPaint(&ps);
Ok(())
}
});
BringWindowToTop
method.
ChildWindowFromPoint
method.
ClientToScreen
method.
ClientToScreen
method for a
RECT
.
CloseWindow
method.
Note that this method will actually minimize the window, not destroy it.
CreateWindowEx
static method.
DefSubclassProc
method.
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.
DefWindowProc
method.
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.
DestroyWindow
method.
DrawMenuBar
method.
EnableWindow
method.
EndPaint
method.
EnumChildWindows
method.
Examples
use winsafe::HWND;
let my_hwnd: HWND; // initialized somewhere
my_hwnd.EnumChildWindows(|hchild: HWND| -> bool {
println!("Child HWND: {}", hchild);
true
});
FindWindow
static method.
FindWindowEx
method.
GetActiveWindow
static method.
pub fn GetAltTabInfo(
self,
item: Option<u32>,
ati: &mut ALTTABINFO,
sz_item_text: Option<u32>
) -> WinResult<String>
pub fn GetAltTabInfo(
self,
item: Option<u32>,
ati: &mut ALTTABINFO,
sz_item_text: Option<u32>
) -> WinResult<String>
GetAltTabInfo
method.
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.
GetAncestor
method.
GetCapture
static method.
GetClassLongPtr
method.
GetClassName
method.
GetClientRect
method.
GetDC
method.
Note: Must be paired with an
HWND::ReleaseDC
call.
GetDesktopWindow
static method.
GetDlgCtrlID
method.
GetDlgItem
method.
GetForegroundWindow
static method.
GetLastActivePopup
method.
pub fn GetMenuBarInfo(
self,
obj_id: OBJID,
item_id: u32,
mbi: &mut MENUBARINFO
) -> WinResult<()>
pub fn GetMenuBarInfo(
self,
obj_id: OBJID,
item_id: u32,
mbi: &mut MENUBARINFO
) -> WinResult<()>
GetMenuBarInfo
method.
GetMenuItemRect
method.
GetNextDlgGroupItem
method.
GetNextDlgTabItem
method.
GetScrollInfo
method.
GetScrollPos
method.
GetShellWindow
static method.
GetSystemMenu
method.
GetTopWindow
method.
GetUpdateRgn
method.
GetWindowDC
method.
Note: Must be paired with an
HWND::ReleaseDC
call.
GetWindowDisplayAffinity
method.
GetWindowInfo
method.
GetWindowLongPtr
method.
GetWindowPlacement
method.
GetWindowRect
method.
GetWindowRgn
method.
GetWindowRgnBox
method.
GetWindowText
method.
use winsafe::HWND;
let my_hwnd: HWND; // initialized somewhere
let text = my_hwnd.GetWindowText()?;
println!("Text: {}", text);
GetWindowTextLength
method. Does not count the terminating null.
GetWindowThreadProcessId
method.
HiliteMenuItem
method.
InvalidateRect
method.
Examples
Most of the time you’ll just want update the entire client area:
use winsafe::HWND;
let my_hwnd: HWND; // initialized somewhere
my_hwnd.InvalidateRect(None, true)?;
InvalidateRgn
method.
IsDialogMessage
method.
IsWindowEnabled
method.
IsWindowUnicode
method.
IsWindowVisible
method.
LogicalToPhysicalPoint
method.
MapDialogRect
method.
MessageBox
method.
Consider using the more modern TaskDialog
method.
Examples
A modal message box, which blocks its parent:
use winsafe::{co, HWND};
let my_hwnd: HWND; // initialized somewhere
my_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 retrieving the desktop handle:
HWND::GetDesktopWindow()
.MessageBox("Hello, world", "Title", co::MB::ICONEXCLAMATION)?;
MonitorFromWindow
method.
MoveWindow
method.
OpenClipboard
method.
Note: Must be paired with a
CloseClipboard
call.
OpenThemeData
method.
Note: Must be paired with an
HTHEME::CloseThemeData
call.
PostMessage
method. Note that this method is asychronous.
Examples
Programatically closing a window:
use winsafe::{HWND, msg::wm};
let my_hwnd: HWND; // initialized somewhere
my_hwnd.PostMessage(wm::Close {})?;
Sending a message to all top-level windows:
use winsafe::{HWND, msg::wm};
HWND::BROADCAST.PostMessage(
wm::ExitMenuLoop { is_shortcut: false },
)?;
RealChildWindowFromPoint
method.
RealGetWindowClassW
method.
RedrawWindow
method.
pub fn RemoveWindowSubclass(
self,
subclass_func: SUBCLASSPROC,
subclass_id: usize
) -> WinResult<()>
pub fn RemoveWindowSubclass(
self,
subclass_func: SUBCLASSPROC,
subclass_id: usize
) -> WinResult<()>
RemoveWindowSubclass
method.
ScreenToClient
method.
ScreenToClient
method for a
RECT
.
SendMessage
method.
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.
Examples
Sending a lvm::SetItem
list view message,
which demands a reference to an LVITEM
object:
use winsafe::{co, HWND, LVITEM, msg::lvm};
let my_hwnd: HWND; // initialized somewhere
let mut lvi = LVITEM::default(); // object to be sent
lvi.mask = co::LVIF::IMAGE;
lvi.iImage = 3;
my_hwnd.SendMessage(lvm::SetItem {
lvitem: &lvi,
});
SetCapture
method.
Note: Must be paired with a
ReleaseCapture
call.
SetForegroundWindow
method.
SetScrollInfo
method.
SetScrollPos
method.
SetScrollRange
method.
SetTimer
method.
SetWindowDisplayAffinity
method.
SetWindowLongPtr
method.
SetWindowPlacement
method.
SetWindowPos
method.
SetWindowRgn
method.
pub fn SetWindowSubclass(
self,
subclass_proc: SUBCLASSPROC,
subclass_id: usize,
ref_data: usize
) -> WinResult<()>
pub fn SetWindowSubclass(
self,
subclass_proc: SUBCLASSPROC,
subclass_id: usize,
ref_data: usize
) -> WinResult<()>
SetWindowSubclass
method.
SetWindowText
method.
ShellExecute
method.
ShowWindow
method.
TaskDialog
method.
If you need more customization, consider the
TaskDialogIndirect
function.
Examples
An information message with just an OK button:
use winsafe::{co, HWND, IdTdicon};
let my_hwnd: HWND; // initialized somewhere
my_hwnd.TaskDialog(
None,
Some("My app name"),
Some("Operation successful"),
Some("The operation completed successfully."),
co::TDCBF::OK
IdTdicon::Tdicon(co::TD_ICON::INFORMATION),
)?;
Prompt the user to click OK or Cancel upon a question:
use winsafe::{co, HWND, IdTdicon};
let my_hwnd: HWND; // initialized somewhere
let answer = my_hwnd.TaskDialog(
None,
Some("My app name"),
Some("File modified"),
Some("The file has been modified.\nProceed closing the application?"),
co::TDCBF::OK | co::TDCBF::CANCEL,
IdTdicon::Tdicon(co::TD_ICON::WARNING),
)?;
if answer == co::DLGID::OK {
println!("User clicked OK.");
}
TranslateAccelerator
method.
UpdateWindow
method.
ValidateRect
method.
ValidateRgn
method.
WindowFromPhysicalPoint
static method.
WindowFromPoint
static method.
Trait Implementations
Auto Trait Implementations
Blanket Implementations
Mutably borrows from an owned value. Read more