HOWTO: Process WM_GETMINMAXINFO to Constrain Window Size

ID: Q67166


The information in this article applies to:


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."


Keywords          : kbNTOS kbGrpUser kbWinOS kbWndw kbWndwMsg 
Version           : 
Platform          : 
Issue type        : kbhowto 

Last Reviewed: March 6, 1999