Results 1 to 4 of 4

Thread: Disabled/Enabled the Max/Min button of a form at runtime.

  1. #1

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Post

    Anybody know how to disabled/enabled the maximized/minimized button of a form at runtime?

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    You can use the SetWindowLong API, eg.

    In a Module..
    Code:
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    
    Private Const SWP_FRAMECHANGED = &H20
    Private Const SWP_NOACTIVATE = &H10
    Private Const SWP_NOMOVE = &H2
    Private Const SWP_NOSIZE = &H1
    Private Const WS_MAXIMIZEBOX = &H10000
    Private Const WS_MINIMIZEBOX = &H20000
    Private Const GWL_STYLE = (-16)
    
    Public Sub MinBox(ByRef oForm As Form, Optional ByVal bEnabled As Boolean = True)
        Dim lStyle As Long
        lStyle = GetWindowLong(oForm.hwnd, GWL_STYLE)
        If bEnabled Then
            lStyle = lStyle Or WS_MINIMIZEBOX
        Else
            lStyle = lStyle Xor WS_MINIMIZEBOX
        End If
        Call SetWindowLong(oForm.hwnd, GWL_STYLE, lStyle)
        Call SetWindowPos(oForm.hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOACTIVATE)
    End Sub
    
    Public Sub MaxBox(ByRef oForm As Form, Optional ByVal bEnabled As Boolean = True)
        Dim lStyle As Long
        lStyle = GetWindowLong(oForm.hwnd, GWL_STYLE)
        If bEnabled Then
            lStyle = lStyle Or WS_MAXIMIZEBOX
        Else
            lStyle = lStyle Xor WS_MAXIMIZEBOX
        End If
        Call SetWindowLong(oForm.hwnd, GWL_STYLE, lStyle)
        Call SetWindowPos(oForm.hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOACTIVATE)
    End Sub
    In the Form, (With 2 Command Buttons)..
    Code:
    Private Sub Command1_Click()
        Static bEnabled As Boolean
        bEnabled = Not bEnabled
        MinBox Me, bEnabled
    End Sub
    
    Private Sub Command2_Click()
        Static bEnabled As Boolean
        bEnabled = Not bEnabled
        MaxBox Me, bEnabled
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  3. #3
    Junior Member
    Join Date
    Nov 1999
    Posts
    27

    Post

    HUH? Aarron isn't that the hard way?
    Maybe I misunderstood but...

    Go to properties of the form...
    There should be a MaxButton and a MinButton.

    If I'm wrong or I misunderstood email me...

  4. #4
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    Clefus you can't change it at run time just like that.

    ------------------
    Visual Basic Programmer (at least I want to be one)
    ------------------
    PolComSoft
    You will hear a lot about it.

    [This message has been edited by QWERTY (edited 11-12-1999).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width