pub fn create_window_class(
name: &Vec<u16>,
window_procedure: WNDPROC,
) -> (WNDCLASSW, HINSTANCE)Expand description
Create WNDCLASSW and handle to it with custom name and WNDPROC.
window_procedure - A callback function, which you define in your application, that processes messages sent to a window.
Read more:
WNDCLASSW - https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-wndclassw
WNDPROC - https://learn.microsoft.com/en-us/windows/win32/api/winuser/nc-winuser-wndproc
Example:
fn main() {
let class_name = wide_null("My app window Class");
let window_name = wide_null("My app window");
let (window_class, h_instance) = create_window_class(&class_name, window_procedure);
let window_handle = create_window_handle(&window_class, &class_name, &window_name, h_instance);
create_window(window_handle);
}Procedure example:
pub unsafe extern "system" fn window_procedure(hwnd: HWND, msg: UINT, w_param: WPARAM, l_param: LPARAM,) -> LRESULT {
match msg {
WM_NCCREATE => {
println!("NC Create");
let createstruct: *mut CREATESTRUCTW = l_param as *mut _;
if createstruct.is_null() {
return 0;
}
let boxed_i32_ptr = (*createstruct).lpCreateParams;
SetWindowLongPtrW(hwnd, GWLP_USERDATA, boxed_i32_ptr as LONG_PTR);
return 1;
}
WM_CREATE => println!("WM Create"),
WM_CLOSE => drop(DestroyWindow(hwnd)),
WM_DESTROY => {
let ptr = GetWindowLongPtrW(hwnd, GWLP_USERDATA) as *mut i32;
drop(Box::from_raw(ptr));
println!("Cleaned up the box.");
PostQuitMessage(0);
}
WM_ERASEBKGND => return 1,
WM_PAINT => your_paint_func(hwnd),
_ => return DefWindowProcW(hwnd, msg, w_param, l_param),
}
0
}