ClsRmvmenuitem




Option Explicit
Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, ByVal bRevert 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 RemoveMenu Lib "user32" _
(ByVal hMenu As Long, ByVal nPosition As Long, _
ByVal wFlags As Long) As Long
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 UpdateWindow Lib "user32" _
(ByVal hwnd As Long) As Long
Public Enum SysMnu
mnuSIZE = &HF000
mnuMOVE = &HF010
mnuMINIMIZE = &HF020
mnuMAXIMIZE = &HF030
mnuCLOSE = &HF060
mnuRESTORE = &HF120
End Enum
Private Const GWL_STYLE = (-16)
Private Const MF_BYCOMMAND = &H0&
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private bFormSet As Boolean
Private m_Form As Form
'_________________________________________________________


Public Property Set Frm(f As Form)
On Error GoTo err_SetForm
Set m_Form = f
bFormSet = True
Exit Property
err_SetForm:
bFormSet = False
End Property
'_________________________________________________________


Public Property Get Frm() As Form
Set Frm = m_Form
End Property
'_________________________________________________________


Public Sub RemoveMenuItem(mnu As SysMnu)
Dim lhSysMenu As Long
Dim lRetVal As Long
Dim lWindowStyle As Long
Dim hWind As Long
'-----------------------

On Error Resume Next
If bFormSet Then
hWind = m_Form.hwnd
If mnu = mnuMAXIMIZE Then
lWindowStyle = GetWindowLong(hWind, GWL_STYLE)
' Now disable Maximize box

lWindowStyle = lWindowStyle Xor WS_MAXIMIZEBOX
If lWindowStyle Then
lRetVal = SetWindowLong(hWind, GWL_STYLE, lWindowStyle)
End If
End If
If mnu = mnuMINIMIZE Then
lWindowStyle = GetWindowLong(hWind, GWL_STYLE)
' Now disable Minimize box

lWindowStyle = lWindowStyle Xor WS_MINIMIZEBOX
If lWindowStyle Then
lRetVal = SetWindowLong(hWind, GWL_STYLE, lWindowStyle)
End If
End If
lhSysMenu = GetSystemMenu(hWind, False)
lRetVal = RemoveMenu(lhSysMenu, mnu, MF_BYCOMMAND)
DoEvents
lRetVal = UpdateWindow(hWind)
Else
MsgBox "Must specify Form!", vbOKOnly + vbCritical, "cRemoveMenu"
End If
End Sub











( clsrmvmenuitem.html )- by Paolo Puglisi - Modifica del 17/12/2023