Changing The Control Box Menu

You can turn off the minimize and maximize menu options by changing properties, but what if you’re doing something critical in your VB program that should not be interrupted and you need to remove the “close” option?

Make the following declares

Declare Function GetSystemMenu Lib "User" (ByVal hWnd As Integer, ByVal bRevert As Integer) As Integer
Declare Function RemoveMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
Global Const MF_BYPOSITION=&H400

Use the following in your code to remove the “close” option:

SystemMenu% = GetSystemMenu (hWnd, 0) 
Res% = RemoveMenu(SystemMenu%,6, MF_BYPOSITION)
Res% = RemoveMenu(SystemMenu%,6, MF_BYPOSITION) 'also remove the separator line

Check out the GetMenuID and InsertMenu API functions to do more complicated tasks.

 


Discover more from dotNetTips.com

Subscribe to get the latest posts sent to your email.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.