Posts tagged WM_GETMINMAXINFO

How to disable maximizing the dialog from Task manager?

5

Its not mandatory for every windows citizen to have maximize button. :D For instance, Windows calculator. But do you know that via taskmgr we could maximize any dialogs? Even you can maximize the dialog which doesn’t have maximize style. Its a master piece of QA team to make the dialog look weired. Well how to prevent it?


You can do it by handling – WM_GETMINMAXINFO message. Before resizing, this message is fired to the dialog to get the minimum and maximum window dimensions. Since, we don’t need to change our dimensions, we have to set the max dimensions as current window dimension. Have a look at the code snippet.

// Message map
BEGIN_MESSAGE_MAP(CRabbitDlg, CDialog)
    ...
    ON_WM_GETMINMAXINFO()
END_MESSAGE_MAP()

void CRabbitDlg::OnGetMinMaxInfo( MINMAXINFO FAR* pMinMaxInfo )
{
    // Window rect.
    RECT rect = { 0 };
    GetWindowRect( &rect );
    CRect WindowRect( &rect );

    // Set the maximum size. Used while maximizing.
    pMinMaxInfo->ptMaxSize.x = WindowRect.Width();
    pMinMaxInfo->ptMaxSize.y = WindowRect.Height();

    // Set the x,y position after maximized.
    pMinMaxInfo->ptMaxPosition.x = rect.left;
    pMinMaxInfo->ptMaxPosition.y = rect.top;
}


There is one small known issue – if we maximize via taskmgr, the window remains same, but the title bar will be painted like maximized.


Targeted Audience – Intermediate.

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

0


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.

Go to Top