Exit Button Disable?

I know how to disabel the maximize and minimize symbols in the upper right corner of a form.  How can I disable the "X" exit symbol?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can disable it unless you show a form without a titlebar.  What you can do is ignore it...

In the QueryUnload event, do this:

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If UnloadMode = vbFormControlMenu Then Cancel = True
End Sub

The X will now be ignored and the form will stay loaded and visible...

To get rid of the Min and Max buttons, set both the MaxButton and MinButton properties of the form False in design time.
Here is code to disable and grey out the [X] button by removing the Close menu item.  Be sure you have code to end your program if you disable the Close button!

Option Explicit
Private Const MF_BYPOSITION = &H400&
Private Declare Function GetSystemMenu Lib "user32" _
    (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function RemoveMenu Lib "user32" _
    (ByVal hMenu As Long, ByVal nPosition As Long, _
    ByVal wFlags As Long) As Long

Private Sub Form_Load()
    Dim hSysMenu As Long
    hSysMenu = GetSystemMenu(Me.hwnd, 0)
    'Remove the Close menu item
    Call RemoveMenu(hSysMenu, 6, MF_BYPOSITION)
    'Remove the Separator bar (optional)
    Call RemoveMenu(hSysMenu, 5, MF_BYPOSITION)
End Sub
Of course, you could simply set the ControlBox property false.  This will remove the min, max, close, and icon from the titlebar, leaving only the caption.

Go ahead and reject my answer and take Erick37's The API's work SWEET!

Please accept my previous comment(s) as answer.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.