Solved

controling the termination of a form

Posted on 2000-02-24
4
121 Views
Last Modified: 2010-05-02
Hi

How can I disbale user from pressing on the [x] button (on the upper-right side of the form).

Thanks,

Liron Golan
0
Comment
Question by:lirong
  • 2
4 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 5 total points
ID: 2555474
"HOWTO: Disable the Close Option on Control Menu of a VB Form"

http://support.microsoft.com/support/kb/articles/Q184/6/86.ASP
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2555524
Or:

Option Explicit

Const MF_REMOVE = &H1000&
Const MF_BYPOSITION = &H400&

Private Declare Function GetSystemMenu Lib "user32" _
    (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" _
    (ByVal hMenu 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 hMenu As Long
    Dim menuItemCount As Long
    'Obtain the handle to the form's system menu
    hMenu = GetSystemMenu(Me.hwnd, 0)
    If hMenu <> 0 Then
        'Obtain the number of items in the menu
        menuItemCount = GetMenuItemCount(hMenu)
        'Remove the system menu Close menu item.
        'The menu item is 0-based, so the last
        'item on the menu is menuItemCount - 1
        Call RemoveMenu(hMenu, menuItemCount - 1, _
            MF_REMOVE Or MF_BYPOSITION)
        'Remove the system menu separator line
        Call RemoveMenu(hMenu, menuItemCount - 2, _
            MF_REMOVE Or MF_BYPOSITION)
    End If
End Sub

Private Sub Command1_Click()
    Unload Me
End Sub
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2556642
This is to prevent the user from using the control menu or the close button.

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If UnloadMode = vbFormControlMenu Then Cancel = 1
End Sub
0
 
LVL 1

Expert Comment

by:HunterKiller
ID: 2561340
I can also set the form property ControlBox to False
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JSON Response and request in VB6 application 11 784
How does CurrentUser work? 10 41
MsgBox 4 71
Publisher:   Unknown     VB.exe Application 1 31
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

685 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