473,379 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

How to disable the "Exit" button ?

I need to disable the exit button in the form .
However, the min. and max. button need to keep it

How ?
Thanks a lot
From Agnes
Nov 20 '05 #1
24 4812
* "Agnes" <ag***@dynamictech.com.hk> scripsit:
I need to disable the exit button in the form .
However, the min. and max. button need to keep it


\\\
Private Declare Auto Function GetSystemMenu Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal bRevert As Int32 _
) As IntPtr

Private Declare Auto Function GetMenuItemCount Lib "user32.dll" ( _
ByVal hMenu As IntPtr _
) As Int32

Private Declare Auto Function DrawMenuBar Lib "user32.dll" ( _
ByVal hWnd As IntPtr _
) As Int32

Private Declare Auto Function RemoveMenu Lib "user32.dll" ( _
ByVal hMenu As IntPtr, _
ByVal nPosition As Int32, _
ByVal wFlags As Int32 _
) As Int32

Private Const MF_BYPOSITION As Int32 = &H400
Private Const MF_REMOVE As Int32 = &H1000

Private Sub RemoveCloseButton(ByVal frmForm As Form)
Dim hMenu As IntPtr, n As Int32
hMenu = GetSystemMenu(frmForm.Handle, 0)
If Not hMenu.Equals(IntPtr.Zero) Then
n = GetMenuItemCount(hMenu)
If n > 0 Then
RemoveMenu(hMenu, n - 1, MF_BYPOSITION Or MF_REMOVE)
RemoveMenu(hMenu, n - 2, MF_BYPOSITION Or MF_REMOVE)
DrawMenuBar(frmForm.Handle)
End If
End If
End Sub
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
Agnes wrote:
I need to disable the exit button in the form .


You can, but in 99% of applications you shouldn't. It's about
the same as mounting a brick under a car's brake pedal to make
sure it always goes fast enough.

That X isn't an exit button, it's a close button (it closes a
window). Most VB applications do exit indeed when their last
window is closed.

When you click it, the "Closing" event is fired in the code
belonging to that form. You can cancel it through the event
arguments: set e.cancel = true; but *NEVER* do so without asking
the user for confirmation.

If not handled properly (i.e. a plain dumb "e.cancel=true"), it
will effectively make it impossible for a user to log off or to
shut down his system without first killing your app through task
manager. Most of them will just reach for the power or reset
button instead.
In either case, your app won't be able to exit cleanly.

Nov 20 '05 #3
* "Agnes" <ag***@dynamictech.com.hk> scripsit:
I need to disable the exit button in the form .
However, the min. and max. button need to keep it


\\\
Private Declare Auto Function GetSystemMenu Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal bRevert As Int32 _
) As IntPtr

Private Declare Auto Function GetMenuItemCount Lib "user32.dll" ( _
ByVal hMenu As IntPtr _
) As Int32

Private Declare Auto Function DrawMenuBar Lib "user32.dll" ( _
ByVal hWnd As IntPtr _
) As Int32

Private Declare Auto Function RemoveMenu Lib "user32.dll" ( _
ByVal hMenu As IntPtr, _
ByVal nPosition As Int32, _
ByVal wFlags As Int32 _
) As Int32

Private Const MF_BYPOSITION As Int32 = &H400
Private Const MF_REMOVE As Int32 = &H1000

Private Sub RemoveCloseButton(ByVal frmForm As Form)
Dim hMenu As IntPtr, n As Int32
hMenu = GetSystemMenu(frmForm.Handle, 0)
If Not hMenu.Equals(IntPtr.Zero) Then
n = GetMenuItemCount(hMenu)
If n > 0 Then
RemoveMenu(hMenu, n - 1, MF_BYPOSITION Or MF_REMOVE)
RemoveMenu(hMenu, n - 2, MF_BYPOSITION Or MF_REMOVE)
DrawMenuBar(frmForm.Handle)
End If
End If
End Sub
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
"Agnes" <ag***@dynamictech.com.hk> schrieb
I need to disable the exit button in the form .
However, the min. and max. button need to keep it


Look at the answer to "Re: Hiding a form's Close ControlBox button" from
today.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5
"Agnes" <ag***@dynamictech.com.hk> schrieb
I need to disable the exit button in the form .
However, the min. and max. button need to keep it


Look at the answer to "Re: Hiding a form's Close ControlBox button" from
today.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6
* lucvdv <na**@null.net> scripsit:
I need to disable the exit button in the form .


You can, but in 99% of applications you shouldn't. It's about
the same as mounting a brick under a car's brake pedal to make
sure it always goes fast enough.

That X isn't an exit button, it's a close button (it closes a
window). Most VB applications do exit indeed when their last
window is closed.


Did you ever install MSDN? I remember, for some seconds, even the close
button is disabled. There are certain cases where this makes sense.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #7
* lucvdv <na**@null.net> scripsit:
I need to disable the exit button in the form .


You can, but in 99% of applications you shouldn't. It's about
the same as mounting a brick under a car's brake pedal to make
sure it always goes fast enough.

That X isn't an exit button, it's a close button (it closes a
window). Most VB applications do exit indeed when their last
window is closed.


Did you ever install MSDN? I remember, for some seconds, even the close
button is disabled. There are certain cases where this makes sense.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8
Hi Herfried,
I need to disable the exit button in the form .


You can, but in 99% of applications you shouldn't. It's about
the same as mounting a brick under a car's brake pedal to make
sure it always goes fast enough.

That X isn't an exit button, it's a close button (it closes a
window). Most VB applications do exit indeed when their last
window is closed.


Did you ever install MSDN? I remember, for some seconds, even the close
button is disabled. There are certain cases where this makes sense.


What is the addition in this message from you, you write the same as lucvdv?

Cor
Nov 20 '05 #9
Hi Herfried,
I need to disable the exit button in the form .


You can, but in 99% of applications you shouldn't. It's about
the same as mounting a brick under a car's brake pedal to make
sure it always goes fast enough.

That X isn't an exit button, it's a close button (it closes a
window). Most VB applications do exit indeed when their last
window is closed.


Did you ever install MSDN? I remember, for some seconds, even the close
button is disabled. There are certain cases where this makes sense.


What is the addition in this message from you, you write the same as lucvdv?

Cor
Nov 20 '05 #10
On 02 May 2004 21:17:56 +0200, hi***************@gmx.at (Herfried K.
Wagner [MVP]) wrote:
* lucvdv <na**@null.net> scripsit:
I need to disable the exit button in the form .


You can, but in 99% of applications you shouldn't. It's about
the same as mounting a brick under a car's brake pedal to make
sure it always goes fast enough.

That X isn't an exit button, it's a close button (it closes a
window). Most VB applications do exit indeed when their last
window is closed.


Did you ever install MSDN? I remember, for some seconds, even the close
button is disabled. There are certain cases where this makes sense.


I was just trying to warn Agnes that overzealous use of it can have
undesired side effects, especially users inventing their own way to
exit the application without giving it an opportunity to shut down
cleanly.

Also keep in mind that removing or disabling the close button doesn't
prevent the user from stopping it. If an application really should
run all the time, it can be better to split it up into a worker core
and a user interface, and let the core run as service.
As always there are exceptions - you just don't want to interrupt some
things (such as flashing new firmware into a piece of hardware).
Some of my own projects run as shell on XP Embedded, exiting them at
any time would be quite undesirable, but still I built in a hidden way
to do it.

Even the shell instance of Windows Explorer has always had an exit
mechanism. At first sight it has little or no use, but it used to
provide the fastest way to repair the damage if the ShellIconCache got
corrupted.

Nov 20 '05 #11
On 02 May 2004 21:17:56 +0200, hi***************@gmx.at (Herfried K.
Wagner [MVP]) wrote:
* lucvdv <na**@null.net> scripsit:
I need to disable the exit button in the form .


You can, but in 99% of applications you shouldn't. It's about
the same as mounting a brick under a car's brake pedal to make
sure it always goes fast enough.

That X isn't an exit button, it's a close button (it closes a
window). Most VB applications do exit indeed when their last
window is closed.


Did you ever install MSDN? I remember, for some seconds, even the close
button is disabled. There are certain cases where this makes sense.


I was just trying to warn Agnes that overzealous use of it can have
undesired side effects, especially users inventing their own way to
exit the application without giving it an opportunity to shut down
cleanly.

Also keep in mind that removing or disabling the close button doesn't
prevent the user from stopping it. If an application really should
run all the time, it can be better to split it up into a worker core
and a user interface, and let the core run as service.
As always there are exceptions - you just don't want to interrupt some
things (such as flashing new firmware into a piece of hardware).
Some of my own projects run as shell on XP Embedded, exiting them at
any time would be quite undesirable, but still I built in a hidden way
to do it.

Even the shell instance of Windows Explorer has always had an exit
mechanism. At first sight it has little or no use, but it used to
provide the fastest way to repair the damage if the ShellIconCache got
corrupted.

Nov 20 '05 #12
* "Cor Ligthert" <no**********@planet.nl> scripsit:
I need to disable the exit button in the form .

You can, but in 99% of applications you shouldn't. It's about
the same as mounting a brick under a car's brake pedal to make
sure it always goes fast enough.

That X isn't an exit button, it's a close button (it closes a
window). Most VB applications do exit indeed when their last
window is closed.


Did you ever install MSDN? I remember, for some seconds, even the close
button is disabled. There are certain cases where this makes sense.


What is the addition in this message from you, you write the same as lucvdv?


It's a real-world example.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #13
* Lucvdv <re**********@null.net> scripsit:
I need to disable the exit button in the form .

You can, but in 99% of applications you shouldn't. It's about
the same as mounting a brick under a car's brake pedal to make
sure it always goes fast enough.

That X isn't an exit button, it's a close button (it closes a
window). Most VB applications do exit indeed when their last
window is closed.
Did you ever install MSDN? I remember, for some seconds, even the close
button is disabled. There are certain cases where this makes sense.


I was just trying to warn Agnes that overzealous use of it can have
undesired side effects, especially users inventing their own way to
exit the application without giving it an opportunity to shut down
cleanly.


OK.
Also keep in mind that removing or disabling the close button doesn't
prevent the user from stopping it. If an application really should
run all the time, it can be better to split it up into a worker core
and a user interface, and let the core run as service.
A service for some simple work that should not be cancelled by the user?
As always there are exceptions - you just don't want to interrupt some
things (such as flashing new firmware into a piece of hardware).
Some of my own projects run as shell on XP Embedded, exiting them at
any time would be quite undesirable, but still I built in a hidden way
to do it.


;-)

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #14
Herfried K. Wagner [MVP] wrote:
A service for some simple work that should not be cancelled by the user?


It depends on the application.

All through this thread, a similar question that someome once
asked in one of the MS newsgroups kept coming back to memory: his
boss had asked him to write a program to log all applications
that were used on a system, and he needed a way to prevent users
from shutting down the logger.

Nov 20 '05 #15
* lucvdv <na**@null.net> scripsit:
A service for some simple work that should not be cancelled by the user?


It depends on the application.

All through this thread, a similar question that someome once
asked in one of the MS newsgroups kept coming back to memory: his
boss had asked him to write a program to log all applications
that were used on a system, and he needed a way to prevent users
from shutting down the logger.


In this case, I would write a service ;-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #16
Hi Lucvdv

That cannot be done in this way.
You can use the cancel in the taskmanager.

This kind of things have a simpler approach.

You set the start date and the end date in the log.

And tell that you check that with the payment system.

Cor
Nov 20 '05 #17
* "Cor Ligthert" <no**********@planet.nl> scripsit:
That cannot be done in this way.
You can use the cancel in the taskmanager.


You can start the service in the admin account, so the simple user
doesn't have the rights to stop it.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #18
> You can start the service in the admin account, so the simple user
doesn't have the rights to stop it.


In windows W98 or in windows ME?

Cor
Nov 20 '05 #19
* "Cor Ligthert" <no**********@planet.nl> scripsit:
You can start the service in the admin account, so the simple user
doesn't have the rights to stop it.


In windows W98 or in windows ME?


Both of them are history...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #20
> >> You can start the service in the admin account, so the simple user
doesn't have the rights to stop it.


In windows W98 or in windows ME?


Both of them are history...


Full supported as far as it are no W2000 classes by the NET the same as VB

History?

Cor
Nov 20 '05 #21
* "Cor Ligthert" <no**********@planet.nl> scripsit:
You can start the service in the admin account, so the simple user
doesn't have the rights to stop it.

In windows W98 or in windows ME?


Both of them are history...


Full supported as far as it are no W2000 classes by the NET the same as VB

History?


Mhm... I don't know anybody who is still using Windows 98 and Windows Me.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #22
> >>> In windows W98 or in windows ME?

Both of them are history...


Full supported as far as it are no W2000 classes by the NET the same as VB
History?


Mhm... I don't know anybody who is still using Windows 98 and Windows Me.


And you could not say that to Microsoft, they still are supporting W98 and
Windows Me and you do not know anybody who is still using it.

:-))))

Cor
Nov 20 '05 #23
My fiance uses WinME...

Just because I'm too broke to buy another license of XP =(
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:c7***********@ID-208219.news.uni-berlin.de...
* "Cor Ligthert" <no**********@planet.nl> scripsit:
> You can start the service in the admin account, so the simple user
> doesn't have the rights to stop it.

In windows W98 or in windows ME?

Both of them are history...


Full supported as far as it are no W2000 classes by the NET the same as VB
History?


Mhm... I don't know anybody who is still using Windows 98 and Windows Me.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #24
* "Cor Ligthert" <no**********@planet.nl> scripsit:
> In windows W98 or in windows ME?

Both of them are history...

Full supported as far as it are no W2000 classes by the NET the same as
VB

History?


Mhm... I don't know anybody who is still using Windows 98 and Windows Me.


And you could not say that to Microsoft, they still are supporting W98 and
Windows Me and you do not know anybody who is still using it.


If my customers don't use it, why design applications for it?

;-)))

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #25

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: s-galit | last post by:
im using "Error Provider" in my form , the problem is that when im trying to exit the program by the exit button on the title bar im getting disturbed by the error provider so i cant exit the...
7
by: Brett | last post by:
What is the C# equivalent of VB.NET's Exit Sub? Thanks, Brett
1
by: Agnes | last post by:
I need to disable the exit button in the form . However, the min. and max. button need to keep it How ? Thanks a lot From Agnes
19
by: ern | last post by:
Right now I'm using exit(0) to terminate my program. My program is a console .exe application. After the "exit(0)" line of code is encountered, the console application waits for an enter press,...
2
by: Serious_Practitioner | last post by:
Good day, and thank you in advance for any assistance. I'm having trouble with something that I'm trying for the first time. Using Access 2000 - I want to run a function either on the click of a...
0
by: Pete | last post by:
Hi All, I'm new to this so please correct me if I'm wrong. I have written a small program which holds details for task information. the program holds an email address, i created a button which...
13
by: Vincent Delporte | last post by:
Hi I'm a Python newbie, and would like to rewrite this Perl scrip to be run with the Asterisk PBX: http://www.voip-info.org/wiki/view/Asterisk+NetCID Anyone knows if those lines are...
1
by: JEJE | last post by:
To All, What is the difference between the following Exit code?? Exit (0)?? Exit(1)?? Exit (2)??
2
by: dstork | last post by:
Anyone know how to rename the "Exit Access" command at the bottom of the Office menu. I'd like to rename it to "Exit" as I had done in previous versions of Access. I know I can disable it with ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.