|
|
|
When the user resizes a form with the mouse or the keyboard, or maximizes it, Windows sends the form a WM_GETMINMAXINFO message, with lParam pointing to a MINMAXINFO structure that the form must fill with information about the minimum and maximum size that it is willing to be resized. Using a subclassing technique you can trap this message and fill the structure yourself, instead of letting VB fill it with default values.
The following example shows how you can prevent a form from being resized larger than 600x400 pixels, and smaller than 300x200 pixels. Moreover, when the form is maximized, it will be centered on the screen: |
Click here to copy the following block |
Const WM_GETMINMAXINFO = &H24 Private Type POINTAPI X As Long Y As Long End Type Private Type MINMAXINFO ptReserved As POINTAPI ptMaxSize As POINTAPI ptMaxPosition As POINTAPI ptMinTrackSize As POINTAPI ptMaxTrackSize As POINTAPI End Type Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, _ source As Any, ByVal numBytes As Long)
Dim WithEvents FormHook As MsgHook
Private Sub Form_Load() Set FormHook = New MsgHook FormHook.StartSubclass hWnd End Sub
Private Sub FormHook_AfterMessage(ByVal uMsg As Long, ByVal wParam As Long, _ ByVal lParam As Long, retValue As Long) If uMsg = WM_GETMINMAXINFO Then Dim mmInfo As MINMAXINFO CopyMemory mmInfo, ByVal lParam, Len(mmInfo) With mmInfo .ptMaxSize.X = 600 .ptMaxSize.Y = 400 .ptMaxPosition.X = ((Screen.Width / Screen.TwipsPerPixelX) - 600) \ _ 2 .ptMaxPosition.Y = ((Screen.Height / Screen.TwipsPerPixelY) - 400) \ _ 2 .ptMinTrackSize.X = 300 .ptMinTrackSize.Y = 200 .ptMaxTrackSize.X = 600 .ptMaxTrackSize.Y = 400 End With CopyMemory ByVal lParam, mmInfo, Len(mmInfo) retValue = 0 End If End Sub |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|