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]