Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleRestrict a form's minimum and maximum width and height
DescriptionThis example shows how to restrict a form's minimum and maximum width and height in Visual Basic 6. It subclasses and looks for WM_WINDOWPOSCHANGING messages.
Keywordsfile times, last access time, file creation time, lastmodified time
CategoriesControls, API
 
The program subclasses the form and looks for WM_WINDOWPOSCHANGING messages. When the program finds one, it ensures that the form's width and height are within bounds.
 
Public Function NewWindowProc(ByVal hwnd As Long, ByVal msg _
    As Long, ByVal wParam As Long, lParam As WINDOWPOS) As _
    Long
' Size bounds in pixels.
Const MIN_WIDTH = 200
Const MAX_WIDTH = 500
Const MIN_HEIGHT = 100
Const MAX_HEIGHT = 300

    ' Keep the dimensions in bounds.
    If msg = WM_WINDOWPOSCHANGING Then
        If lParam.cx < MIN_WIDTH Then lParam.cx = MIN_WIDTH
        If lParam.cx > MAX_WIDTH Then lParam.cx = MAX_WIDTH
        If lParam.cy < MIN_HEIGHT Then lParam.cy = _
            MIN_HEIGHT
        If lParam.cy > MAX_HEIGHT Then lParam.cy = _
            MAX_HEIGHT
    End If
    
    ' Continue normal processing. VERY IMPORTANT!
    NewWindowProc = CallWindowProc( _
        OldWindowProc, hwnd, msg, wParam, _
        lParam)
End Function
 

Warning

Subclassing is dangerous. The debugger does not work well when a new WindowProc is installed. If you halt the program instead of unloading its forms, it will crash and so will the Visual Basic IDE. Save your work often! Don't say you weren't warned.

 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated