AdjustWindowRect documentation

AdjustWindowRect documentation

本文关键字:documentation AdjustWindowRect      更新时间:2023-10-16

MSDN 库将 AdjustWindowRect 的 dwStyle 参数记录为:

要计算其所需大小的窗口的窗口样式。请注意,您不能 指定WS_OVERLAPPED样式。

我还没有找到任何解释。他们所说的"不能"是什么意思,为什么我不能这样做?

WS_OVERLAPPED样式定义为零:

#define WS_OVERLAPPED    0x00000000L

AdjustWindowRect() 正在检查提供的样式标志并相应地修改 RECT:

// ...
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;
}
// ...

因此,将 dwStyle 参数设置为 0AdjustWindowRect()不会更改 lpRect,因此不能使用WS_OVERLAPPED

如果要计算顶级框架的大小,可以改用WS_OVERLAPPEDWINDOWWS_CAPTION|WS_THICKFRAME