Solved

controling the termination of a form

Posted on 2000-02-24
4
118 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
Comment Utility
"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
Comment Utility
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
Comment Utility
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
Comment Utility
I can also set the form property ControlBox to False
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now