WM_GETMINMAXINFO

Kyle Marsh

Microsoft Developer Network Technology Group

Created: March 20, 1992

ABSTRACT

The MicrosoftÒ WindowsÔ graphical environment provides the WM_GETMINMAXINFO message for applications to control the maximized size and position, the maximum tracking size, and the minimum tracking size of a window.

MAXIMIZED SIZE AND POSITION

The maximized size of a window is the size when the window is maximized. By default, this size equals the size of the screen, plus twice the sum of the window border width, plus one in both the vertical and the horizontal direction. For example, on a 640-by-480 VGA screen with a sizable window border 3 pixels wide, the maximized window size is 648 pixels wide by 488 pixels high (640 + ((3+1)*2)) by (480 + ((3+1)*2)). The maximized size for a window with a thin border is 644 pixels wide by 484 pixels high (640 + ((1+1)*2)) by (480 + ((1+1)*2)).

The default position for a maximized window is the window border width above and to the left of the upper-left corner of the screen. Thus, with the default sizable border width of 3, the maximized position of a window is (–4, –4). If the window has a thin border instead of a sizable border, the maximized position is (–1, –1).

MAXIMUM TRACKING SIZE

The maximum tracking size is the largest size a window can obtain when the user sizes the window with either the mouse or the keyboard. The maximum tracking size has no effect if a window has a thin border because the window cannot be sized with either the keyboard or the mouse. By default, the maximum tracking size of a window is the same as the maximized size.

MINIMUM TRACKING SIZE

The minimum tracking size is the smallest size a window can obtain when the user sizes the window with either the mouse or the keyboard. The minimum tracking size has no effect if a window has a thin border because the window cannot be sized with either the keyboard or the mouse.

Rules for Minimum Window Size

Several factors determine the default minimum size of a window and how to change it. These factors are discussed separately for the MicrosoftÒ WindowsÔ graphical environment versions 3.0 and 3.1 below.

Windows version 3.0

If the window does not have a caption:

Width is the window border size. The window can be any size.

Height is the window border size. The window can be any size.

If the window has a caption and a system menu, minimize box, or maximize box:

Width is five times the average width of a character in the system font, plus twice the sum of the border width plus one, plus three times the width of the system menu bitmap (which is the same size as the minimize bitmap and the maximize bitmap).

The window cannot be narrower than this default value. Width is always sufficient for all three bitmaps even if only one bitmap is on the window. The width is always available to show about five characters in the caption.

Height is the height of the caption plus twice the height of the border.

The window cannot be shorter than this default value.

If the window has a caption but no system menu, minimize box, or maximize box:

Width is five times the average width of a character in the system font, plus twice the width of the border plus one, plus three times the width of the system menu bitmap (which is the same size as the minimize bitmap and the maximize bitmap).

The window can be narrower than this default value (as if it had no caption).

Height is the height of the caption plus twice the height of the border.

The window can be shorter than this default value (as if it had no caption).

Windows version 3.1

If the window does not have a caption:

Width is the window border size. The window can be as narrow as twice the sum of the border width plus one.

Height is the window border size. The window can be as narrow as twice the sum of the border width plus one.

If the window has a caption and a system menu, minimize box, or maximize box:

Width is five times the average width of a character in the system font, plus twice the width of the border plus one, plus three times the width of the system menu bitmap (which is the same size as the minimize bitmap and the maximize bitmap).

The window can be sized down to twice the sum of the window border width plus one, plus the width of any bitmap actually on the window. If a window has only a system menu, the window can be narrow enough to hold only the system menu bitmap. The Window does not have to have any room for the window caption. (Windows version 3.0 always leaves room for about five characters.)

Height is the height of the caption plus twice the height of the border.

The window cannot be shorter than this default value.

If the window has a caption but no system menu, minimize box, or maximize box:

Width is five times the average width of a character in the system font, plus twice the width of the border plus one, plus three times the width of the system menu bitmap (which is the same size as the minimize bitmap and the maximize bitmap).

The window can be sized down to twice the sum of the window border width plus one. The window does not have to have any room for the window caption. (Windows version 3.0 always leaves room for about five characters.)

Height is the height of the caption plus twice the height of the border. The window cannot be shorter than this default value.

How to Use WM_GETMINMAXINFO

Windows sends a WM_GETMINMAXINFO message to a window when:

An overlapped window or a window that has a sizable frame is created. Windows sends this message to the window before it sends the WM_NCCREATE message to the window.

A window is minimized.

A window is maximized. If the window has a sizable frame or is an overlapped window, it receives two WM_GETMINMAXINFO messages when it is maximized.

A window is moved. Windows sends the WM_GETMINMAXINFO message before the move occurs.

A window is sized. Windows sends a WM_GETMINMAXINFO message before and after the window is sized.

A minimized window (icon) is arranged with an arrange icons command, either on the desktop or as a multiple document interface (MDI) child window in an MDI application.

Windows sends a pointer to a group of point values with each WM_GETMINMAXINFO message. An application changes the values at the location pointed to by the supplied pointer to change the maximized size, maximized position, maximum tracking size, or minimum tracking size for a window.

The Windows version 3.0 Software Development Kit (SDK) Reference—Volume 1 manual describes the lParam parameter sent to a window with the WM_GETMINMAXINFO message as follows.

Parameter Description  

lParam Points to an array of five POINT data structures that contain the following information:  

  Value Meaning
  apt[0] This value is reserved for internal use.
  apt[1] Specifies the maximized width (point.x) and the maximized height (point.y) of the window.
  apt[2] Specifies the position of the left side of the maximized window (point.x) and the position of the top of the maximized window (point.y).
  apt[3] Specifies the minimum tracking width (point.x) and the minimum tracking height (point.y) of the window.
  apt[4] Specifies the maximum tracking width (point.x) and the maximum tracking height (point.y) of the window.

The Windows version 3.1 WINDOWS.H file defines the following structure:

// Structure pointed to by WM_GETMINMAXINFO lParam

typedef struct tagMINMAXINFO

{

POINT ptReserved;

POINT ptMaxSize;

POINT ptMaxPosition;

POINT ptMinTrackSize;

POINT ptMaxTrackSize;

} MINMAXINFO;

An application can use either the array of values technique or the structure technique in either version of Windows. If the application is developed with the Windows version 3.0 WINDOWS.H file, the application must define the MINMAXINFO typedef. For convenience, this article refers to the structure method. The following table shows how to use each technique to set the MINMAXINFO values.

Array of values Structure

switch (Msg) {

.

.

.

case WM_GETMINMAXINFO:

{

LPPOINT lpPoints;

lpPoints = (LPPOINT)lParam;

lpPoints[1].x = 200;

lpPoints[1].y = 200;

}

.

.

.

}

switch (Msg) {

.

.

.

case WM_GETMINMAXINFO:

{

MINMAXINFO *lpMinMax;

lpMinMax=(MINMAXINFO *

)lParam;

lpMinMax.MaxSize.x = 200;

lpMinMax.MaxSize.y = 200;

}

.

.

.

}


Each time Windows sends a WM_GETMINMAXINFO message to a window, it fills the structure with the default values listed above. These values are calculated each time a WM_GETMINMAXINFO message is sent. If the user changes the border width value from Control Panel, this new value is reflected the next time Windows sends a WM_GETMINMAXINFO message to a window.

Windows version 3.1 uses a window’s previous maximized position as the default maximized position if the window has been maximized and either minimized or restored to its normal state. The maximized position can be a result of a value that the application sets, or a non-full-screen maximized window can be moved to the new position. Windows version 3.1 uses the last position of the maximized window, no matter how it was positioned there.

Because Windows sends a WM_GETMINMAXINFO message each time Windows is about to use a value from the MINMAXINFO structure and because Windows recalculates the default values each time it sends the message, the application must store and set the MINMAXINFO structure values each time Windows sends it a WM_GETMINMAXINFO message. The example program shows how the user- specified values and the default values change each time an application receives a WM_GETMINMAXINFO message.