Remove Unwanted System Menu Options

Remove Unwanted System Menu Options

You’ve probably wanted to limit the normal operations of a form, such as resizing it, preventing it from being minimized or maximized, or allowing it to be closed only when you say so. The trick is to remove the control menu that corresponds to the functionality you want to limit. For example, when you remove the Size menu from the Control menu, the user won’t be able to resize your form. The same goes for Minimize, Maximize, and Move. Add this code to a BAS module:

 ' declarations necessary to work with the Control ' Box menusPrivate Declare Function RemoveMenu Lib _	"User32" (ByVal hMenu As Long, _	ByVal nPosition As Long, ByVal wFlags _	As Long) As LongPrivate Declare Function GetSystemMenu Lib _	"User32" (ByVal hWnd As Long, ByVal revert _	As Long) As LongPrivate Declare Function GetWindowLong Lib _	"User32" Alias "GetWindowLongA" (ByVal hWnd _	As Long, ByVal lIndex As Long) As LongPrivate Declare Function SetWindowLong Lib _	"User32" Alias "SetWindowLongA" (ByVal hWnd _	As Long, ByVal lIndex As Long, _	ByVal dwNewLong As Long) As LongPrivate Const MF_BYPOSITION = &H400Private Const MAXIMIXE_BUTTON = &HFFFEFFFFPrivate Const MINIMIZE_BUTTON = &HFFFDFFFFPrivate Const GWL_STYLE = (-16)' enumeration used when calling VBRemoveMenuPublic Enum RemoveMenuEnum	rmMove = 1	rmSize = 2	rmMinimize = 3	rmMaximize = 4	rmClose = 6End EnumPublic Sub VBRemoveMenu(ByVal TargetForm _	As Form, ByVal MenuToRemove As RemoveMenuEnum)	' VBRemoveMenu	' this routine removes the specified menu item 	' from the control menu and the corresponding 	' functionality from the form	'	' Parameters	'	TargetForm - the form to perform the 	'	operation on	'	MenuToRemove - Enum specifying which menu 	'	to remove	Dim hSysMenu As Long	Dim lStyle As Long	hSysMenu = GetSystemMenu(TargetForm.hWnd, 0&)	RemoveMenu hSysMenu, MenuToRemove, _		MF_BYPOSITION	Select Case MenuToRemove		Case rmClose			' when removing the Close menu, also 			' remove the separator over it			RemoveMenu hSysMenu, MenuToRemove - 1, _				MF_BYPOSITION		Case rmMinimize, rmMaximize			' get the current window style			lStyle = GetWindowLong( _				TargetForm.hWnd, GWL_STYLE)			If MenuToRemove = rmMaximize Then				' turn off bits for Maximize arrow 				' button				lStyle = lStyle And MAXIMIXE_BUTTON			Else				' turn off bits for Minimize arrow 				' button				lStyle = lStyle And MINIMIZE_BUTTON			End If			' set the new window style			SetWindowLong TargetForm.hWnd, _				GWL_STYLE, lStyle	End SelectEnd Sub

Then, when you load your form, call VBRemoveMenu with one of the menu enumerations:

 	VBRemoveMenu Me, rmMaximize

Not only will the menu be removed from the Control menu, but the corresponding functionality of the form will be removed as well. Because the menus are removed by ordinal position, remove them in descending order if you want to remove more than one. For example:

 Private Sub Form_Load()	Call VBRemoveMenu(Me, rmClose)	Call VBRemoveMenu(Me, rmMaximize)End Sub
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes