The information in this article applies to:
SUMMARYTo modify an item in the Visual Basic Control menu (also known as the System menu), you need to call the API functions GetSystemMenu and ModifyMenu. This article describes how to disable the Close command in the Control menu. MORE INFORMATION
If you do not want the user to be able to choose the Close command from
the Control menu or to be able to double-click the Control-menu box to end
the application, you can disable the Close command. GetSystemMenu returns
the handle to the Control menu. That handle can be used by ModifyMenu to
change the control menu.
Notes on the Use of ModifyMenu() in the CodeThe code listed above uses the ModifyMenu() function, but the EnableMenuItem() may be more appropriate in your particular situation.Here's the syntax for ModifyMenu():
Here's the syntax for EnableMenuItem():
Both functions work. However it appears that Visual Basic re-enables the
menu item whose ID is SC_CLOSE. This is why it may appear as if the
ModifyMenu() or EnableMenuItem() function failed.
To work around this problem in the code listed above, the second to last argument (idNewItem%) is set to -10 (0 would also work):
This works because Visual Basic looks for a menu item with ID SC_CLOSE to
re-enable and cannot find one because it has been changed to 0 or -10. So
Visual Basic can't re-enable the Close menu item.
However, because of this workaround, another limitation is introduced. The problem is that the ID of the Close menu item is changed to -10. If you want the program to be able to re-enable the Close item, you'll need to use this alternative version:
This is a good workaround to Visual Basic's re-enabling of Close. Don't use
0 because menu separators also have the ID 0 and you will run into problems
when you try to re-enable Close. 0xFFFF is a good ID to use.
Another alternative solution is to use DeleteMenu to remove Close and the separator above it, and use InsertMenu to add the Close and the separator. REFERENCES
"Microsoft Windows Programmer's Reference Book and Online Resource"
(Visual Basic Add-on kit number 1-55615-413-5) Q184686 : HOWTO: Disable the Close Option on Control Menu of a VB Form Additional query words: control box controlbox
Keywords : kbVBp kbVBp300 |
Last Reviewed: June 8, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |