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
#[cfg(not(feature = "high-dpi"))]
#[deprecated(
    note = "Specifying the default process DPI awareness via API is not recommended. Use the '<dpiAware>true</dpiAware>' setting in the application manifest. https://docs.microsoft.com/ru-ru/windows/win32/hidpi/setting-the-default-dpi-awareness-for-a-process"
)]
pub unsafe fn set_dpi_awareness() {}

#[cfg(feature = "high-dpi")]
#[deprecated(
    note = "Specifying the default process DPI awareness via API is not recommended. Use the '<dpiAware>true</dpiAware>' setting in the application manifest. https://docs.microsoft.com/ru-ru/windows/win32/hidpi/setting-the-default-dpi-awareness-for-a-process"
)]
pub unsafe fn set_dpi_awareness() {
    use winapi::um::winuser::SetProcessDPIAware;
    unsafe {
        SetProcessDPIAware();
    }
}

#[cfg(not(feature = "high-dpi"))]
pub fn scale_factor() -> f64 {
    return 1.0;
}

#[cfg(feature = "high-dpi")]
pub fn scale_factor() -> f64 {
    use winapi::um::winuser::USER_DEFAULT_SCREEN_DPI;
    let dpi = dpi();
    f64::from(dpi) / f64::from(USER_DEFAULT_SCREEN_DPI)
}

#[cfg(not(feature = "high-dpi"))]
pub fn logical_to_physical(x: i32, y: i32) -> (i32, i32) {
    (x, y)
}

#[cfg(feature = "high-dpi")]
pub fn logical_to_physical(x: i32, y: i32) -> (i32, i32) {
    use muldiv::MulDiv;
    use winapi::um::winuser::USER_DEFAULT_SCREEN_DPI;
    let dpi = dpi();
    let x = x.mul_div_round(dpi, USER_DEFAULT_SCREEN_DPI).unwrap_or(x);
    let y = y.mul_div_round(dpi, USER_DEFAULT_SCREEN_DPI).unwrap_or(y);
    (x, y)
}

#[cfg(not(feature = "high-dpi"))]
pub fn physical_to_logical(x: i32, y: i32) -> (i32, i32) {
    (x, y)
}

#[cfg(feature = "high-dpi")]
pub fn physical_to_logical(x: i32, y: i32) -> (i32, i32) {
    use muldiv::MulDiv;
    use winapi::um::winuser::USER_DEFAULT_SCREEN_DPI;
    let dpi = dpi();
    let x = x.mul_div_round(USER_DEFAULT_SCREEN_DPI, dpi).unwrap_or(x);
    let y = y.mul_div_round(USER_DEFAULT_SCREEN_DPI, dpi).unwrap_or(y);
    (x, y)
}

pub fn dpi() -> i32 {
    use winapi::um::wingdi::GetDeviceCaps;
    use winapi::um::wingdi::LOGPIXELSX;
    use winapi::um::winuser::GetDC;
    let screen = unsafe { GetDC(std::ptr::null_mut()) };
    let dpi = unsafe { GetDeviceCaps(screen, LOGPIXELSX) };
    dpi
}