Article ID: 185733 - Last Review: July 1, 2004 - Revision: 3.1 How To Limit a Window's Minimum and Maximum SizeThis article was previously published under Q185733 On This PageSUMMARY
By default, Visual Basic allows a form to be resized to any size you want
provided the BorderStyle is set appropriately. At times, it may be
desirable or necessary to limit the range of a window's size (such that it
cannot be smaller or larger than a predetermined size).
For example, the Windows accessory, Microsoft Paint, prevents its window from being sized below a certain point. This is done to allow the user to always see at least part of the image they are editing. With the aid of Windows API functions, you can achieve this same functionality within your Visual Basic application. MORE INFORMATION
WARNING: ANY USE BY YOU OF THE SAMPLE CODE PROVIDED IN THIS ARTICLE IS AT
YOUR OWN RISK. Microsoft provides this sample code "as is" without warranty
of any kind, either express or implied, including but not limited to the
implied warranties of merchantability and/or fitness for a particular
purpose.
Below are steps to create a sample application that demonstrate the behavior discussed above. To achieve this functionality, a concept known as subclassing must be used to detect when the WM_GETMINMAXINFO message occurs. This message occurs when an attempt is made to resize the window. For more information on subclassing, please see the following article in the Microsoft Knowledge Base: 168795
(http://support.microsoft.com/kb/168795/EN-US/
)
: How To Hook Into a Window's Messages Using AddressOf
Failure to unhook a window before its destruction results in application errors, Invalid Page Faults, and data loss. This problem can occur when the new WindowProc function being pointed to no longer exists, but the window has not been notified of the change. Always unhook the subclassed window upon unloading the subclassed form or exiting the application. This is especially important while debugging an application that uses this technique within the Microsoft Visual Basic Development Environment. Clicking the End button or, on the Run menu, clicking End, without unhooking causes an Invalid Page Fault and closes Microsoft Visual Basic. Steps to Create a Sample Application
REFERENCES
For additional information, please see the following article(s) in the
Microsoft Knowledge Base:
168795
(http://support.microsoft.com/kb/168795/EN-US/
)
: How To Hook Into a Window's Messages Using AddressOf
APPLIES TO
| Article Translations
|

Back to the top
