How to set a minimum and maximum size of a window in Win32 API?

Posted on 2005-04-17
Last Modified: 2013-12-03
How do you set a minimum and maximum size of a window (form) in Win32 API? So far I know that the window WindowProc() method should be listening for WM_GETMINMAXINFO message .. after that, I am lost. Please help.

Question by:krupini
    LVL 86

    Expert Comment

    You should do that when handling WM_SIZE, e.g. like

    case WM_SIZE:

    #define HEIGHT_MAX 200
    #define WIDTH_MAX 200

    WORD fwSizeType = wParam;      // resizing flag
    int nWidth = LOWORD(lParam);  // width of client area
    int nHeight = HIWORD(lParam); // height of client area

    if ( nHeight > HEIGHT_MAX) nHeight = HEIGHT_MAX;
    if ( nWidth > WIDTH_MAX) nWidth = WIDTH_MAX;

    return DefWindowProc(hWnd, msg, (WPARM) fwSizeType, MAKELPARAM(nHeight,nWidth)):

    LVL 86

    Expert Comment

    Sorry, that line should end with a ';':

    return DefWindowProc(hWnd, msg, (WPARM) fwSizeType, MAKELPARAM(nHeight,nWidth));
    LVL 86

    Expert Comment

    ...and it actually should read

    return DefWindowProc(hWnd, msg, (WPARAM) fwSizeType, MAKELPARAM(nHeight,nWidth));
    LVL 9

    Expert Comment

    Respond to this window message: WM_GETMINMAXINFO (lParam points to a MINMAXINFO structure).

    Windows sends this message to a window whose size or position is about to change. For example, the message is sent when the user clicks Move or Size from the window menu or clicks the sizing border or title bar; the message is also sent when an application calls SetWindowPos to move or size the window.

    LVL 9

    Accepted Solution

    If you want to limit the window size to between a minimum size and a maximum size, set the ptMinTrackSize and ptMaxTrackSize to the desired width/height and return 0.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
    Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now