|
Option Explicit
Private Const WM_GETMINMAXINFO = &H24&
Private Const GWL_WNDPROC = (-4)
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
Private Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex _
As Long, ByVal dwNewLong As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias _
"RtlMoveMemory" (ByRef lDestination As Any, ByRef _
pSource As Any, ByVal Length As Long)
Private Declare Function CallWindowProc Lib "user32" Alias _
"CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal _
hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private m_PrevWindowProc As Long
Private m_MinWidth As Long
Private m_MinHeight As Long
Private m_MaxWidth As Long
Private m_MaxHeight As Long
Public Sub LimitWindowSize(ByRef Frm As Form, _
ByVal MinWidth As Long, ByVal MinHeight As Long, _
ByVal MaxWidth As Long, ByVal MaxHeight As Long)
If m_PrevWindowProc <> 0 Then
ReleaseWindowSize Frm
End If
m_MinWidth = MinWidth
m_MinHeight = MinHeight
m_MaxWidth = MaxWidth
m_MaxHeight = MaxHeight
m_PrevWindowProc = SetWindowLong(Frm.hWnd, GWL_WNDPROC, _
AddressOf WindowProc)
End Sub
Public Sub ReleaseWindowSize(ByVal Frm As Form)
If m_PrevWindowProc <> 0 Then
SetWindowLong Frm.hWnd, GWL_WNDPROC, m_PrevWindowProc
m_PrevWindowProc = 0
End If
End Sub
Private Function WindowProc(ByVal hWnd As Long, ByVal uMsg As _
Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim MMI As MINMAXINFO
Select Case uMsg
Case WM_GETMINMAXINFO
CopyMemory MMI, ByVal lParam, Len(MMI)
With MMI
.ptMinTrackSize.X = m_MinWidth
.ptMinTrackSize.Y = m_MinHeight
.ptMaxTrackSize.X = m_MaxWidth
.ptMaxTrackSize.Y = m_MaxHeight
End With
CopyMemory ByVal lParam, MMI, Len(MMI)
WindowProc = 0
Case Else
WindowProc = CallWindowProc(m_PrevWindowProc, _
hWnd, uMsg, wParam, lParam)
End Select
End Function
|
|