Process WM_GETMINMAXINFO to Constrain Window Size

Last reviewed: November 2, 1995
Article ID: Q67166
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) versions 3.0 and 3.1
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.5 and 3.51
        - Microsoft Windows 95 version 4.0
    

SUMMARY

Microsoft Windows sends a WM_GETMINMAXINFO message to a window to determine the maximized size or position for the window, and the maximum or minimum tracking size for the window. An application can change these parameters by processing the WM_GETMINMAXINFO message.

Each window type has an absolute minimum size. If an application changes any of the values associated with WM_GETMINMAXINFO to a value smaller than the minimum, Windows will override the values specified by the application and use the minimum size. This minimum window size restriction has been removed from Windows version 3.1.

Note that Windows can send a WM_GETMINMAXINFO message to a window prior to sending a WM_CREATE message. Therefore, any processing for the WM_GETMINMAXINFO message must be independent of processing done for the WM_CREATE message.

MORE INFORMATION

An application can use the WM_GETMINMAXINFO message to constrain the size of a window. For example, the application can prevent the user from changing a window's width while allowing the user to affect its height, or vice versa. The following code demonstrates fixing the width:

  int width;
  LPPOINT lppt;
  RECT rect;

  case WM_GETMINMAXINFO:
      lppt = (LPPOINT)lParam;   // lParam points to array of POINTs

      GetWindowRect(hWnd, &rect);   // Get current window size
      width = rect.right - rect.left + 1;

      lppt[3].x = width   // Set minimum width to current width
      lppt[4].x = width   // Set maximum width to current width

      return DefWindowProc(hWnd, message, wParam, lParam);

The modifications required to fix the height are quite straightforward.

For more information on the array of POINT structures that accompanies the WM_GETMINMAXINFO message, please refer to the "Microsoft Windows Software Development Kit Reference."


Additional reference words: 3.00 3.10 3.50 3.51 4.00 95
KBCategory: kbui
KBSubcategory: UsrWndw


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 2, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.