Search code examples
winapigdi

Why does the RECT of a window not change by resizing it through dragging the left/top edge of it?


The following is my WindowProc function:

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 
{
    PAINTSTRUCT ps;
    switch (uMsg)
    {
        case WM_SIZE:
            {

                break;
            }
        case WM_PAINT:
            {
                int height = 50;
                TCHAR buff[256] = { 0 };
                HDC hdc = BeginPaint(hwnd, &ps);
                SetMapMode(hdc, MM_TEXT);
                RECT windowSize;
                RECT logicExtent;
                GetWindowRect(hwnd, &windowSize);
                logicExtent = windowSize;
                DPtoLP(hdc, (LPPOINT)(&logicExtent), 2);
                memset(buff, 0, 256);
                _stprintf_s(buff, TEXT("TEXT MODE:Physical Extent=[%d, %d], Logical Extent=[%d,%d]"), windowSize.right, windowSize.bottom, logicExtent.right, logicExtent.bottom);
                TextOut(hdc,0, height * 0,buff, _tcslen(buff));
                EndPaint(hwnd, &ps);
                break;
            }
        case WM_DESTROY:
            {
                PostQuitMessage(0);
                break;
            }
    }
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

I find a problem which really confuses me, that when I resize the window through dragging the right/bottom edge of it the values printed will change, while the values do not change when I resize the window by dragging the left/top edge of it. Could someone explain to me the reason?


Solution

  • According to RECT structure,

    right

    Specifies the x-coordinate of the lower-right corner of the rectangle.

    bottom

    Specifies the y-coordinate of the lower-right corner of the rectangle.

    Dragging the left/top edge of windows does not change the coordinate of the lower-right corner of it.