Sometimes (for example, in a pc-lock program, or error dialog where a decision must be made) you will not want your users to be able to close a window simply by pressing the X button. This code disables the X button, and also the Close item on the system menu that is displayed when you right-click on the title bar)
Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long,
ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal
bRevert As Long) As Long
Private Const MF_BYPOSITION = &H400&
Private Sub Form_Load()
'// remove the close menu (which then disables the close
button)
RemoveMenus
End Sub
Private Sub RemoveMenus()
Dim hMenu As Long
' Get the form's system menu handle.
hMenu = GetSystemMenu(hWnd, False)
DeleteMenu hMenu, 6, MF_BYPOSITION
End Sub
Comments