Dennis,

Simply exit the function when you recieve the HTMAXBUTTON message. The reason your VB was freezing was because you left out CallWindowProc for every message (hence no messages were processed). This next example should clear things up.

Code:
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
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
Const GWL_WNDPROC = (-4)
Const WM_NCLBUTTONDOWN = &HA1
Const HTMAXBUTTON = 9

Public WndProcOld As Long

Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

    If wMsg = WM_NCLBUTTONDOWN Then
        If wParam = HTMAXBUTTON Then
            MsgBox ("You pressed Maximize")
            Exit Function
        End If
    End If
  
    WindProc = CallWindowProc(WndProcOld&, hwnd, wMsg, wParam, lParam)
    
End Function

Sub SubClassWnd(hwnd As Long)
    WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
End Sub

Sub UnSubclassWnd(hwnd As Long)
    SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
    WndProcOld& = 0
End Sub