|
|
Title | Restrict a form's minimum and maximum width and height |
Description | This 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. |
Keywords | file times, last access time, file creation time, lastmodified time |
Categories | Controls, 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.
|
|
|
|
|
|