?
Solved

Exit Button Disable?

Posted on 1999-12-04
5
Medium Priority
?
274 Views
Last Modified: 2010-05-02
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?
0
Comment
Question by:donb1
  • 3
  • 2
5 Comments
 
LVL 14

Expert Comment

by:mcrider
ID: 2255005
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...


Cheers!
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2255028
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
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2255102
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.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2255171
donb1,

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

Cheers!
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 200 total points
ID: 2255588
Please accept my previous comment(s) as answer.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question