Windows GetClientRect返回错误的大小

时间:2019-05-04 14:44:27

标签: c++ windows winapi

对于我的C ++程序,我试图通过WINAPI的GetClientRect()函数查询窗口的大小。但是,它返回的窗口比我最初设置的要小。这是窗口设置的内容:

    //Creation of window
    WNDCLASS WindowProperties {};
    WindowProperties.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; //TODO: Check if OWNDC/HREDRAW/VEDRAW matter
    WindowProperties.lpfnWndProc = Win32::ProgramWindowCallback;
    WindowProperties.hInstance = CurrentProgramInstance;
    WindowProperties.lpszClassName = "MemoWindowClass";

    if (RegisterClass(&WindowProperties))
    {
        HWND window= CreateWindowEx(0, WindowProperties.lpszClassName, "My Program", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
            CW_USEDEFAULT, CW_USEDEFAULT, globalWindowWidth, globalWindowHeight, 0, 0, CurrentProgramInstance, 0);

    //more code

globalWindowWidth / Height都分别设置为1280和720。稍后,在WM_PAINT事件中,我通过此函数获取窗口尺寸,该函数最终调用GetClientRect():

Window_Dimension GetWindowDimension(HWND window)
{
    Window_Dimension Result;

    RECT ClientRect;
    GetClientRect(window, &ClientRect);
    Result.width = ClientRect.right - ClientRect.left;
    Result.height = ClientRect.bottom - ClientRect.top;

    return(Result);
};

被调用时,尽管我想要的值为1280和720,但GetClientRect返回的“正确”值为1264,“底部”值为681。为什么会发生这种情况?

0 个答案:

没有答案