AdjustWindowRect documentation

2020-07-10 08:50发布

The MSDN Library documents the dwStyle argument of AdjustWindowRect as:

The window style of the window whose required size is to be calculated. Note that you cannot specify the WS_OVERLAPPED style.

I haven't found any explanation for this. What do they mean by "cannot" and why can't I do it?

1条回答
Summer. ? 凉城
2楼-- · 2020-07-10 09:09

The WS_OVERLAPPED style is defined as zero:

#define WS_OVERLAPPED    0x00000000L

AdjustWindowRect() is checking the style flags supplied and modifies the RECT accordingly:

// ...
if( dwStyle & WS_BORDER ) {
    const int cx = GetSystemMetrics(SM_CXBORDER);
    const int cy = GetSystemMetrics(SM_CYBORDER);
    lpRect->top -= cy;
    lpRect->left -= cx;
    lpRect->right += cx;
    lpRect->bottom += cy;
}
// ...

Therefore AdjustWindowRect() with the dwStyle parameter set to 0 does not alter the lpRect, hence WS_OVERLAPPED cannot be used.

If you wish to calculate the size for a top-level frame, you can use WS_OVERLAPPEDWINDOW or WS_CAPTION|WS_THICKFRAME instead.

查看更多
登录 后发表回答