gabdube / native-windows-gui

A light windows GUI toolkit for rust
https://gabdube.github.io/native-windows-gui/
MIT License
1.93k stars 125 forks source link

Is there any nwg equivalent for AdjustWindowRectEx? #255

Closed marethyu closed 1 year ago

marethyu commented 1 year ago

I need to calculate the required size for window when menubar is added. C/C++ Win32 API provides this useful function called AdjustWindowRectEx. Does nwg have this such function? I can't find anything relevant in docs.

gabdube commented 1 year ago

NWG doesn't wrap this function, but you can call it yourself by adding winapi to your project.

# Cargo.toml
winapi =  {version = "0.3", features = ["winuser"]}
use winapi::um::winuser::{AdjustWindowRectEx, RECT, WS_CAPTION};

fn adjust_window_rect() -> RECT {
  unsafe {
    let mut out: RECT = ::std::mem::zeroed();
    AdjustWindowRectEx(&mut out, WS_CAPTION, 1, 0);
    out
  }
}
marethyu commented 1 year ago

Thanks in order to make your code work, I had to change the imports to

use winapi::um::winuser::AdjustWindowRectEx;
use winapi::shared::windef::RECT;

because RECT is private.