Chris
Nov 8th, 1999, 09:12 PM
Anybody know how to disabled/enabled the maximized/minimized button of a form at runtime?
Aaron Young
Nov 8th, 1999, 09:35 PM
You can use the SetWindowLong API, eg.
In a Module..
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)..
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
aarony@redwingsoftware.com
adyoung@win.bright.net
clefus
Nov 12th, 1999, 09:13 AM
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...
QWERTY
Nov 12th, 1999, 09:15 AM
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).]