Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" ( _
ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
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" ( _
Destination As Any, _
Source As Any, _
ByVal Length As Long)
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 m_Hook As Boolean
Private m_hWnd As Long
Private m_PrevWndProc As Long
Public Sub SetSubClass(lpHwnd As Long)
If Not m_Hook Then
m_hWnd = lpHwnd
m_PrevWndProc = SetWindowLong(lpHwnd, GWL_WNDPROC, AddressOf WindowProc)
m_Hook = True
End If
End Sub
Public Sub Restore()
If m_Hook Then
Call SetWindowLong(m_hWnd, GWL_WNDPROC, m_PrevWndProc)
m_Hook = False
End If
End Sub
Private Function WindowProc(ByVal hw As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Dim mmiInfo As MINMAXINFO
Select Case uMsg
Case WM_GETMINMAXINFO
Call CopyMemory(mmiInfo, ByVal lParam, Len(mmiInfo))
mmiInfo.ptMinTrackSize.x = 300 '最小尺寸: 300相素
mmiInfo.ptMinTrackSize.y = 300 '最小尺寸: 300相素
Call CopyMemory(ByVal lParam, mmiInfo, Len(mmiInfo))
Case Else
WindowProc = CallWindowProc(m_PrevWndProc, hw, uMsg, wParam, lParam)
End Select
End Function
'==========================================
'在窗体中:
'==========================================
Private Sub Form_Load()
Call SetSubClass(Me.hwnd)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call Restore
End Sub