However, I found it confusing that they do not share the same types WINDOW_STYLE and WINDOW_EX_STYLE. That is to say, when handling WM_CREATE and attempting to use AdjustWindowRectExForDpi, the types of style and dwExStyle disagree with the function's parameters.
It's easy enough to cast-and-wrap, but preserving type safety would be nice here.
Crate manifest
windows = "0.53"
Crate code
fn adjust_size(hwnd: HWND, csw: &CREATESTRUCTW, size: (i32, i32)) -> RECT {
let dpi = unsafe { GetDpiForWindow(hwnd) };
let mut rect = RECT::Default();
unsafe { GetClientRect(hwnd, &mut rect) }.unwrap();
rect.right = rect.left + size.0;
rect.bottom = rect.top + size.1;
unsafe {
AdjustWindowRectExForDpi(
&mut rect,
csw.style, // this fails to typecheck
None,
csw.dwExStyle, // this also fails to typecheck
dpi
)
}
.unwrap();
rect
}
Summary
I am uncertain if this is a bug per-se since the Windows documentation for
AdjustWindowRectExForDpi
andCREATESTRUCTW
differ.However, I found it confusing that they do not share the same types
WINDOW_STYLE
andWINDOW_EX_STYLE
. That is to say, when handlingWM_CREATE
and attempting to useAdjustWindowRectExForDpi
, the types ofstyle
anddwExStyle
disagree with the function's parameters.It's easy enough to cast-and-wrap, but preserving type safety would be nice here.
Crate manifest
windows = "0.53"
Crate code