How to set the Minimum and Maximum window size while Resizing?

26 04 2008


In several applications, you might already seen, the dialog won’t resize after a particular limit. In other words those dialogs have a minimum and maximum dialog size even though they supports resizing. So how can we set the minimum – minimum size and maximum – maximum size of a dialog? 😉


You can utilize the message – WM_GETMINMAXINFO. This message is sent to the dialog to get the minimum and maximum window size. Pointer to struct MINMAXINFO is send as message params. We’ve set our required minimum and maximum window sizes in this MINMAXINFO struct. See the code snippet below. For easiness, I’ve implemented it in MFC.

Modify the message map as follows

BEGIN_MESSAGE_MAP(CDialogDlg, CDialog)
	...

    ON_WM_GETMINMAXINFO()
END_MESSAGE_MAP()

Now add a function with the following signature to your dialog class.

void CDialogDlg::OnGetMinMaxInfo( MINMAXINFO FAR* pMinMaxInfo )
{
    // Preferred Maximum X & Y.
    const int MAX_SIZE_X = 750;
    const int MAX_SIZE_Y = 650;

    // Preferred Minimum X & Y.
    const int MIN_SIZE_X = 400;
    const int MIN_SIZE_Y = 350;

    // Set the maximum size. Used while maximizing.
    pMinMaxInfo->ptMaxSize.x = MAX_SIZE_X;
    pMinMaxInfo->ptMaxSize.y = MAX_SIZE_Y;

    // Set the Minimum Track Size. Used while resizing.
    pMinMaxInfo->ptMinTrackSize.x = MIN_SIZE_X;
    pMinMaxInfo->ptMinTrackSize.y = MIN_SIZE_Y;

    // Set the Maximum Track Size. Used while resizing.
    pMinMaxInfo->ptMaxTrackSize.x = MAX_SIZE_X;
    pMinMaxInfo->ptMaxTrackSize.y = MAX_SIZE_Y;
}

Now try to resize your dialog. Wowwww!!!


You can just handle it in the classic message proc also. All you should know is about the struct MINMAXINFO and its members.


Targeted Audience – Beginners.

Advertisements