This is shorter way to disable the ‘X’ or close button on a form. It also works on MDI Child forms also which I have found most other code does not.
Original Author: Mark Troutwine
Inputs
None.
Assumptions
Just copy and paste it as stated below!
Returns
None.
Side Effects
None.
API Declarations
‘ Place this in a module:
Public Declare Function GetSystemMenu Lib “user32” (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Public Declare Function RemoveMenu Lib “user32” (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Public Const SC_CLOSE = &HF060&
Public Const MF_BYCOMMAND = &H0&
Code
' Place this in the Form Load event of the form you want to disable the 'X':
Dim hSysMenu As Long
hSysMenu = GetSystemMenu(hwnd, False)
RemoveMenu hSysMenu, SC_CLOSE, MF_BYCOMMAND