davidrobin
Jun 5th, 2003, 07:42 AM
Credit for this code goes to crptcblade
The following code can be used to enable or disable the X button on the control box of a form.
The following form goes 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 Declare Function DrawMenuBar Lib "user32" (ByVal hwnd _
As Long) As Long
Private Const MF_BYCOMMAND = &H0&
Private Const SC_CLOSE = &HF060&
Public Sub SetXState(frm As Form, blnState As Boolean)
Dim hMenu As Long
hMenu = GetSystemMenu(frm.hwnd, blnState)
Call RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)
Call DrawMenuBar(frm.hwnd)
End Sub
The enabling and disabling is performed like so
Private Sub Command1_Click()
If opt(0).Value = True Then
SetXState Me, True 'enable the X button
ElseIf opt(1).Value = True Then
SetXState Me, False 'disable the X button
End If
End Sub
The following code can be used to enable or disable the X button on the control box of a form.
The following form goes 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 Declare Function DrawMenuBar Lib "user32" (ByVal hwnd _
As Long) As Long
Private Const MF_BYCOMMAND = &H0&
Private Const SC_CLOSE = &HF060&
Public Sub SetXState(frm As Form, blnState As Boolean)
Dim hMenu As Long
hMenu = GetSystemMenu(frm.hwnd, blnState)
Call RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)
Call DrawMenuBar(frm.hwnd)
End Sub
The enabling and disabling is performed like so
Private Sub Command1_Click()
If opt(0).Value = True Then
SetXState Me, True 'enable the X button
ElseIf opt(1).Value = True Then
SetXState Me, False 'disable the X button
End If
End Sub