By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,365 Members | 1,360 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,365 IT Pros & Developers. It's quick & easy.

How to disable the "Exit" button ?

P: n/a
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
Share this Question
Share on Google+
24 Replies


P: n/a
* "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

P: n/a
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

P: n/a
* "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

P: n/a
"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

P: n/a
"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

P: n/a
* 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

P: n/a
* 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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
* "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

P: n/a
* 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

P: n/a
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

P: n/a
* 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

P: n/a
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

P: n/a
* "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

P: n/a
> 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

P: n/a
* "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

P: n/a
> >> 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

P: n/a
* "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

P: n/a
> >>> 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

P: n/a
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

P: n/a
* "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 discussion thread is closed

Replies have been disabled for this discussion.