Set MINMAXINFO in WM_GETMINMAXINFO: No Effect?

Laurie Stearn 91 Reputation points
2021-01-10T05:24:12.687+00:00

Hi, the code handled in this message shows that mmi is updated, yet during sizing, the structure reverts to the defaults, understandably so by the way it's processed:

case WM_GETMINMAXINFO:  
{  
    // myWidth, myheight initialised e.g 250, 150  
    MINMAXINFO* mmi = reinterpret_cast<MINMAXINFO*>(lParam);  
    // mmi reset with Windows default values  
    static POINT defDims;  
    if (inputReady)  
    {  
        defDims.x = 2 * myWidth;  
        defDims.y = 2 * myheight;  
    }  
    // mmi is updated with new values here  
    mmi->ptMinTrackSize = defDims;  
    return (LRESULT)FALSE;  
}  

All of the code in this message is similar to that Googled which from all accounts, performed well enough. For a yet to be determined reason, the code out there "works" because somehow Windows tells the compiler to inspect our locally instantiated struct mmi and work windowed wonders with it.
See attached message log, in most cases WM_GETMINMAXINFO comes after WM_SIZING. Does anything in there explain why the internal MINMAXINFO is always reset to default, and our window's size smaller than the values set in ptMinTrackSize?
Thanks.
54899-messages.txt

Windows development | Windows API - Win32
Developer technologies | C++
{count} votes

Accepted answer
  1. Drake Wu - MSFT 996 Reputation points
    2021-01-11T05:55:11.297+00:00

    Hi, @Laurie Stearn

    Does anything in there explain why the internal MINMAXINFO is always reset to default?

    Yes, According to the WM_GETMINMAXINFO documentation:

    lParam is A pointer to a MINMAXINFO structure that contains the default maximized position and dimensions, and the default minimum and maximum tracking sizes.

    You can temporarily override this default value but cannot modify it. The message will be sent to a window when the size or position of the window is about to change, and you will need to process this message every time.

    and our window's size smaller than the values set in ptMinTrackSize

    I cannot reproduce it, I can set the ptMinTrackSize and the window minimum tracking size is correct.

    Could a minimal sample includes how you set the inputReady and is there any other place that set the defDims?

    Update:
    Minimal code snip:

    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)  
    {  
        static int inputReady = true;  
        switch (message)  
        {  
        case WM_GETMINMAXINFO:  
        {  
            // myWidth, myheight initialised e.g 250, 150  
            MINMAXINFO* mmi = reinterpret_cast<MINMAXINFO*>(lParam);  
            // mmi reset with Windows default values  
            static POINT defDims;  
            if (inputReady)  
            {  
                defDims.x = 2 * 250;  
                defDims.y = 2 * 150;  
                inputReady = false;  
            }  
            // mmi is updated with new values here  
            mmi->ptMinTrackSize = defDims;  
            return (LRESULT)FALSE;  
        }  
        case WM_DESTROY:  
            PostQuitMessage(0);  
            break;  
        default:  
            return DefWindowProc(hWnd, message, wParam, lParam);  
        }  
        return 0;  
    }  
    int APIENTRY wWinMain(_In_ HINSTANCE hInstance,  
        _In_opt_ HINSTANCE hPrevInstance,  
        _In_ LPWSTR    lpCmdLine,  
        _In_ int       nCmdShow)  
    {  
        WNDCLASSEXW wcex = { 0 };  
      
        wcex.cbSize = sizeof(WNDCLASSEX);  
      
        wcex.style = CS_HREDRAW | CS_VREDRAW;  
        wcex.lpfnWndProc = WndProc;  
        wcex.hInstance = hInstance;  
        wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);  
        wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);  
        wcex.lpszClassName = L"Window_Class";  
      
        if (!RegisterClassExW(&wcex))  
        {  
            std::cout << "RegisterClassExW error:   " << GetLastError() << std::endl;  
            return 0;  
        }  
        HWND hWnd = CreateWindowW(wcex.lpszClassName, L"Title", WS_OVERLAPPEDWINDOW,  
            CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);  
        if (!hWnd)  
        {  
            std::cout << "CreateWindowW error:   " << GetLastError() << std::endl;  
            return 0;  
        }  
        ShowWindow(hWnd, nCmdShow);  
        UpdateWindow(hWnd);  
      
        MSG msg;  
        // Main message loop:  
        while (GetMessage(&msg, nullptr, 0, 0))  
        {  
            TranslateMessage(&msg);  
            DispatchMessage(&msg);  
        }  
      
        return (int)msg.wParam;  
    }  
    

    (I assume you only use inputReady once)


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.