Not a Member Yet,
Click here to Register
How do you like the new design?






ID: 163
Viewed: 2499
Added: Apr 29, 2002
Version:
Snippet uploaded by: snippet
Written By: unknown
Demo: Sorry, no demo



User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

Class to Remove menu items

Highlight all by clicking in box
<!---Declaration--->
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

Highlight All
<!---Code--->
none;


No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2017 snippetlibrary.com All Rights Reserved. Conditions