Native Windows GUI: Raw handles
Native windows controls handle are public and always accessible using the field
handle
.
For example, here's the definition of
ControlHandle
and the Window control:
#[derive(Default)]
pub struct Window {
pub handle: ControlHandle
}
pub enum ControlHandle {
NoHandle,
Hwnd(HWND),
/// (Parent menu / Menu).
/// Parent menu must be there as WINAPI does not have any function to fetch the parent
Menu(HMENU, HMENU),
/// (Parent window / Menu).
PopMenu(HWND, HMENU),
/// (Parent menu / Unique ID).
MenuItem(HMENU, u32),
/// Notice control
Notice(HWND, u32),
/// Timer control
Timer(HWND, u32),
/// System tray control
SystemTray(HWND)
}
Unwrapping window handles
Assuming you know the handle on the control and want to directly access it's content, the ControlHandle object has those methods:
pub fn hwnd(&self) -> Option<HWND>
pub fn hmenu(&self) -> Option<(HMENU, HMENU)>
pub fn pop_hmenu(&self) -> Option<(HWND, HMENU)>
pub fn hmenu_item(&self) -> Option<(HMENU, u32)>
pub fn timer(&self) -> Option<(HWND, u32)>
pub fn notice(&self) -> Option<(HWND, u32)>
pub fn tray(&self) -> Option<HWND>
Wrapping external handles
Wrapping external handles should only be done on a
Window
as it only control that doesn't expose
window class specific functions. Wrapping external handles should be considered unsafe.
pub fn wrap_extern_window(hwnd: HWND) -> nwg::Window {
nwg::Window {
handle: nwg::ControlHandle::Hwnd(hwnd)
}
}