Struct winsafe::HWND[][src]

#[repr(C)]
pub struct HWND { /* fields omitted */ }
Expand description

Handle to a window.

Implementations

The null, invalid handle.

This constant is common to all handle types.

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.

Consumes the handle into an option, which is None if the handle pointer is 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.

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

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.

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

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.

GetClassName method.

GetClientRect method.

GetDC method.

Note: Must be paired with an HWND::ReleaseDC call.

GetDesktopWindow static method.

GetDlgCtrlID method.

GetDlgItem method.

GetFocus static method.

GetForegroundWindow static method.

GetMenu method.

GetParent method.

GetScrollInfo method.

GetScrollPos method.

GetShellWindow static method.

GetSystemMenu method.

GetTopWindow method.

GetUpdateRgn method.

GetWindow method.

GetWindowDC method.

Note: Must be paired with an HWND::ReleaseDC call.

GetWindowInfo method.

GetWindowRect method.

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

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.

IsChild method.

IsIconic method.

IsWindow method.

IsZoomed method.

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

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

RedrawWindow method.

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

SetFocus method.

SetMenu method.

SetParent method.

SetScrollInfo method.

SetScrollPos method.

SetTimer method.

SetWindowPos method.

SetWindowRgn method.

SetWindowText method.

ShellExecute method.

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

UpdateWindow method.

ValidateRect method.

ValidateRgn method.

WindowFromPhysicalPoint static method.

WindowFromPoint static method.

WinHelp method.

Trait Implementations

Formats the value using the given formatter.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter.

Formats the value using the given formatter.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Formats the value using the given formatter.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.