Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 12: Dialog-Based Windows Visual C++ and MFC Fundamentals


BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

cs.style &= ~WS_MINIMIZEBOX;

return TRUE;
}

In the same way, you can remove the system maximize button.

If you allow the system buttons, the user can minimize and maximize the window at will.
To do this, besides using the system buttons, the user can also double-click the title bar of
the window or click its Maximize menu item either from the window's system icon or
after right-clicking its button on the Taskbar. When the window is maximized, the frame
is resized to occupy the whole monitor area, starting from the top-left corner as the
origin.

When the user decides to maximize a window, the frame sends a
WM_GETMINMAXINFO message which appears like "The user wants to maximize
me. What should I do?". This message produces the OnGetMinMaxInfo() event. If the
application does not give any specific instruction, the window gets maximized. If you
want to do something before the window is formally maximized, you can intercept
OnGetMinMaxInfo() event. Remember that, if you want to prevent the window from
being minimized or maximized, you should remove the Minimize
(WS_MINIMIZEBOX) or the Maximize (WS_MAXIMIZEBOX) buttons from its
style.

If you want to control the minimum and/or maximum size that a window can have when
the user wants to maximize it, set the desired size in the OnGetMinMaxInfo() event. It
syntax is:

afx_msg void OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI);

The information pertinent to a window's maximized size, including the maximum size it
can have, is stored in a structure called MINMAXINFO. The MINMAXINFO structure is
defined as follows:

typedef struct tagMINMAXINFO {
POINT ptReserved;
POINT ptMaxSize;
POINT ptMaxPosition;
POINT ptMinTrackSize;
POINT ptMaxTrackSize;
} MINMAXINFO;

A variable of MINMAXINFO type is passed to the OnGetMinMaxInfo() event.

The ptReserved member variable is reserved and never used.

The ptMaxSize value is the maximum width and the maximum height. To specify this
value, you can call the x member variable of the point value of ptMaxSize and assign the
desired value. Here is an example:
Free download pdf