Nix the X

Nix the X

Sometimes, you want to show a form that you don’t want users to be able to cancel by clicking on the X-it might not make sense for your app. The best VB solution is to cancel the unload in the form’s QueryUnload event. However, this allows users to do something wrong, for which you then have to handle and scold them. If you do nothing, it looks as if the form has a bug and won’t cancel. Add this routine to a standard BAS module:

 Private Declare Function GetSystemMenu Lib "user32" _	(ByVal hWnd As Long, ByVal bRevert As Long) As LongPrivate Declare Function RemoveMenu Lib "user32" _	(ByVal hMenu As Long, ByVal nPosition As Long, _	ByVal wFlags As Long) As LongPrivate Const MF_BYPOSITION = &H400&Public Sub RemoveCancelMenuItem(frm As Form)	Dim hSysMenu As Long	'get the system menu for this form	hSysMenu = GetSystemMenu(frm.hWnd, 0)	'remove the close item	Call RemoveMenu(hSysMenu, 6, MF_BYPOSITION)	'remove the separator that was over the close item	Call RemoveMenu(hSysMenu, 5, MF_BYPOSITION)End Sub

Then call the routine from any form as it loads:

 	Private Sub Form_Load()		RemoveCancelMenuItem Me	End Sub

After this call, the Close menu item in the system menu and the option to cancel [X] will be disabled. Note that if you’re doing other things with the system menu, you might have to adjust the position number in the RemoveMenu call.

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