native-windows-gui2 0.1.1

A rust library to develop native GUI applications on the desktop for Microsoft Windows. Native-windows-gui wraps the native win32 window controls in a rustic API
Documentation
/*!
    Low level tabs utility
*/
use super::window::build_sysclass;
use crate::NwgError;
use std::ptr;
use winapi::shared::minwindef::{LPARAM, LRESULT, UINT, WPARAM};
use winapi::shared::windef::HWND;

pub const TAB_CLASS_ID: &'static str = "NWG_TAB";

/// Create the NWG tab classes
pub fn create_tab_classes() -> Result<(), NwgError> {
    use winapi::shared::windef::HBRUSH;
    use winapi::um::libloaderapi::GetModuleHandleW;
    use winapi::um::winuser::COLOR_BTNFACE;

    let hmod = unsafe { GetModuleHandleW(ptr::null_mut()) };
    if hmod.is_null() {
        return Err(NwgError::initialization("GetModuleHandleW failed"));
    }

    build_sysclass(
        hmod,
        TAB_CLASS_ID,
        Some(tab_proc),
        Some(COLOR_BTNFACE as HBRUSH),
        None,
    )?;

    Ok(())
}

extern "system" fn tab_proc(hwnd: HWND, msg: UINT, w: WPARAM, l: LPARAM) -> LRESULT {
    use winapi::um::winuser::DefWindowProcW;
    use winapi::um::winuser::WM_CREATE;

    let handled = match msg {
        WM_CREATE => Some(0),
        _ => None,
    };

    if let Some(result) = handled {
        result
    } else {
        unsafe { DefWindowProcW(hwnd, msg, w, l) }
    }
}