microsoft / win32metadata

Tooling to generate metadata for Win32 APIs in the Windows SDK.
Other
1.32k stars 113 forks source link

`AdjustWindowExForDpi` expects `WINDOW_STYLE` and `WINDOW_EX_STYLE`, but `CREATESTRUCTW` only provides `i32` and `u32` respectively #1859

Closed david7a68 closed 6 months ago

david7a68 commented 6 months ago

Summary

I am uncertain if this is a bug per-se since the Windows documentation for AdjustWindowRectExForDpi and CREATESTRUCTW differ.

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
}
kennykerr commented 6 months ago

I'll transfer to the Win32 metadata repo for resolution.