Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleLet the user minimize, maximize, and restore a form, but not resize it
Keywordsresize, minimize, maximize
CategoriesTips and Tricks, API
 
Subclass and read the form's Windows messages. Ignore any WM_SYSCOMMAND message with the SC_SIZE command.
 
Public Function NewWindowProc(ByVal hwnd As Long, ByVal msg _
    As Long, ByVal wParam As Long, lParam As WINDOWPOS) As _
    Long
Const WM_NCDESTROY = &H82
Const WM_SYSCOMMAND = &H112
Const SC_SIZE = &HF000&

    ' If we're being destroyed,
    ' restore the original WindowProc.
    If msg = WM_NCDESTROY Then
        SetWindowLong _
            hwnd, GWL_WNDPROC, _
            OldWindowProc
    End If

    ' See if this is a WM_SYSCOMMAND message.
    If msg = WM_SYSCOMMAND Then
        ' This is a WM_SYSCOMMAND message.
        ' If the command is SC_SIZE, ignore it.
        If (wParam And &HFFF0) = SC_SIZE Then Exit Function
    End If

    ' Continue normal processing. VERY IMPORTANT!
    NewWindowProc = CallWindowProc( _
        OldWindowProc, hwnd, msg, wParam, _
        lParam)
End Function
 
For more information on subclassing including important precautions, see Tutorial: Subclassing.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated