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

disabling close button for application

P: n/a
Hi Folk

Is there a way to disable the close button for an application?

Thank you

- Nicolaas
Dec 11 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a

Hi cor-travel. The last time I answered this one I got flamed and you
may well do too for asking the question! Anyone who asks a question
like this usually receives a heap of flack about the user being in
control of their own computer never mind how legitimate the reason is.
I'll leave it to a braver soul to supply you with an answer.

Dec 11 '05 #2

P: n/a
On Sun, 11 Dec 2005 16:59:59 +1300, "cor-travel" <co********@xtra.co.nz> wrote:
Hi Folk

Is there a way to disable the close button for an application?

Thank you

- Nicolaas


Post the following into a standard module.
The function you need is fActivateCloseBox

(Author unknown)

Private Declare Function GetWindowLong Lib "User32" _
Alias "GetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong Lib "User32" _
Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Private Declare Function GetSystemMenu _
Lib "User32" _
(ByVal hWnd As Long, _
ByVal bRevert As Long) As Long

Private Declare Function DrawMenuBar _
Lib "User32" _
(ByVal hWnd As Long) As Long

Private Declare Function DeleteMenu _
Lib "User32" _
(ByVal hMenu As Long, _
ByVal nPosition As Long, _
ByVal wFlags As Long) As Long

Private Const MF_BYCOMMAND = &H0&
Private Const SC_CLOSE = &HF060

Private Const WS_SYSMENU = &H80000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000

Private Const GWL_STYLE = (-16)

Public Function fActivateControlBox(Enable As Boolean)
Dim CurStyle As Long
Dim hWnd As Long

hWnd = Access.hWndAccessApp

CurStyle = GetWindowLong(hWnd, GWL_STYLE)
If Enable Then
If Not (CurStyle And WS_SYSMENU) Then
CurStyle = CurStyle Or WS_SYSMENU
End If
Else
If (CurStyle And WS_SYSMENU) = WS_SYSMENU Then
CurStyle = CurStyle - WS_SYSMENU
End If
End If
Call SetWindowLong(hWnd, GWL_STYLE, CurStyle)
Call DrawMenuBar(hWnd)

End Function

Public Function fActivateCloseBox(Enable As Boolean)
Dim hMenu As Long
Dim hWnd As Long

hWnd = Access.hWndAccessApp

If Enable Then
Call GetSystemMenu(hWnd, True)
Else
hMenu = GetSystemMenu(hWnd, False)
If hMenu Then
Call DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)
End If
End If
Call DrawMenuBar(hWnd)

End Function

Public Function fActivateMaximizeBox(Enable As Boolean)
Dim CurStyle As Long
Dim hWnd As Long

hWnd = Access.hWndAccessApp

CurStyle = GetWindowLong(hWnd, GWL_STYLE)
If Enable Then
If Not (CurStyle And WS_MAXIMIZEBOX) Then
CurStyle = CurStyle Or WS_MAXIMIZEBOX
End If
Else
If (CurStyle And WS_MAXIMIZEBOX) = WS_MAXIMIZEBOX Then
CurStyle = CurStyle - WS_MAXIMIZEBOX
End If
End If
Call SetWindowLong(hWnd, GWL_STYLE, CurStyle)
Call DrawMenuBar(hWnd)

End Function

Public Function fActivateMinimizeBox(Enable As Boolean)
Dim CurStyle As Long
Dim hWnd As Long

hWnd = Access.hWndAccessApp

CurStyle = GetWindowLong(hWnd, GWL_STYLE)
If Enable Then
If Not (CurStyle And WS_MINIMIZEBOX) Then
CurStyle = CurStyle Or WS_MINIMIZEBOX
End If
Else
If (CurStyle And WS_MINIMIZEBOX) = WS_MINIMIZEBOX Then
CurStyle = CurStyle - WS_MINIMIZEBOX
End If
End If
Call SetWindowLong(hWnd, GWL_STYLE, CurStyle)
Call DrawMenuBar(hWnd)

End Function

Wayne Gillespie
Gosford NSW Australia
Dec 11 '05 #3

P: n/a

"Wayne" <cq*******@volcanomail.com> schreef in bericht news:11*********************@z14g2000cwz.googlegro ups.com...

Hi cor-travel. The last time I answered this one I got flamed and you
may well do too for asking the question! Anyone who asks a question
like this usually receives a heap of flack about the user being in
control of their own computer never mind how legitimate the reason is.
I'll leave it to a braver soul to supply you with an answer.


Hi Wayne,
I did thank you for the code, you were not flamed, nor was I flamed for asking.
Thread: "Prevent minimising application. Possible?" started by me Dec-1 here

I guess you are referring to another thread and still feel the heat... ?? ;-)

Arno R
Dec 11 '05 #4

P: n/a
How legitimate could the answer be?

Now I'll be accused of not being helpful or being arrogant or whatever,
but about half the original posts I've seen in the past few days might
properly be answered with:

Find another line of work;
Format your hard drive and start over;
You have clients? Take out liability insurance immediately;
Go back to school and get an education; you can't do Access programs if
you know no language, no science, no mathematics, no logic;

Maybe I'm a grumpy old man
or
Maybe it's not doing anyone a service when we suggest band aids for
severed aortas of a body that is described as weighing seven thousand
kilograms, with six legs protruding from four heads, but no liver and
no lungs.

OK, I'll go back and watch television now and shut up.

Dec 11 '05 #5

P: n/a
See this page on my site for lots of options:

http://home.bendbroadband.com/conrad...osebutton.html

--
Jeff Conrad
Access Junkie - MVP
http://home.bendbroadband.com/conrad...essjunkie.html
http://www.access.qbuilt.com/html/articles.html

"cor-travel" wrote in message:
news:Gt*******************@news.xtra.co.nz...
Hi Folk

Is there a way to disable the close button for an application?


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 11 '05 #6

P: n/a
Jeff Conrad wrote:
See this page on my site for lots of options:

http://home.bendbroadband.com/conrad...osebutton.html

--
Jeff Conrad
Access Junkie - MVP
http://home.bendbroadband.com/conrad...essjunkie.html
http://www.access.qbuilt.com/html/articles.html

"cor-travel" wrote in message:
news:Gt*******************@news.xtra.co.nz...
Hi Folk

Is there a way to disable the close button for an application?


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----


I had a situation where a secretary who is not good with computers
sometimes forgot that the X in the top right was for closing the
application and the one below it for closing the window within the
application. The secretary would sometimes hit the wrong one. I found
some code somewhere (perhaps Jeff's site), told the secretary to use
Exit from the File menu and made the code run only for that secretary.
This was for A97:

'modDisableCloseButton
Option Compare Database
Option Explicit

Const MF_BYCOMMAND = &H0&
Const SC_CLOSE = &HF060

Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal
bRevert As Long) As Long
Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal
nPosition As Long, ByVal wFlags As Long) As Long
Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long

Public Sub DisableCloseButton()
Dim lngRet As Long
Dim lngMenuHandle As Long

'Get a handle of Access system menu
lngMenuHandle = GetSystemMenu(hWndAccessApp, 0)

'disable Close Button
lngRet = RemoveMenu(lngMenuHandle, SC_CLOSE, MF_BYCOMMAND)

'redraw
DrawMenuBar hWndAccessApp
Application.RefreshTitleBar

End Sub

James A. Fortune

Dec 12 '05 #7

P: n/a
I can't remember which one of my secretary's buttons to push either,
James.

Dec 12 '05 #8

P: n/a
Almost seven years ago I wrote:

Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function EnableMenuItem Lib "user32" _
(ByVal hMenu As Long, ByVal wIDEnableItem As Long, ByVal wEnable As
Long) As
Long
Private Const MF_BYCOMMAND = &H0&
Private Const MF_ENABLED = &H0&
Private Const MF_GRAYED = &H1&
Private Const SC_CLOSE = &HF060&

Sub EnableCloseButton()
Dim lngSystemMenuHandle As Long
lngSystemMenuHandle = GetSystemMenu(Access.hWndAccessApp, False)
Call EnableMenuItem(lngSystemMenuHandle, SC_CLOSE, MF_BYCOMMAND Or
MF_ENABLED)
End Sub

Sub DisableCloseButton()
Dim lngSystemMenuHandle As Long
lngSystemMenuHandle = GetSystemMenu(Access.hWndAccessApp, False)
Call EnableMenuItem(lngSystemMenuHandle, SC_CLOSE, MF_BYCOMMAND Or
MF_GRAYED)
End Sub
I
It was some of my earliest messing with the API. The original poster
reported that the code worked for his purpose.I felt pretty good.

Dev Ashish posted three messages to the thread part of which are:

1. Why on _earth_ would you want to mess with an MDI app like that,
especially
since it's not yours. I can understand such steps if you were using
CreateWindow or with your own forms etc., but _come on_, not with the
default window of a standard Windows app. Or am I being just plain
stupid
here? And how does one know for a fact (other than looking at the
source)
that Access hasn't put some code behind what-you-just-disabled to
perform
pre-quit-clean-up.

2. Without taking away anything from Lyle's or other's efforts, I would
suggest
instead that you follow more conventional methods of tracking a boolean
variable's state from a form's OnUnload event. My rule of thumb is,
don't
mess with the app itself unless it's absolutely needed and unavoidable.
3. Sorry Lyle, I'm against the idea, not the posts that followed. I
myself
posted similar code long ago I think, but not any more. These days I
have
to point out such UI things to a few people at work quite regularly,
and it
takes it's toll. <g> After all, who knows, next thing you know, folks
will
want to block the three fingure salute, disable app switching,
and-who-knows-what.

I think this was the beginning of my strong belief in "Just let Access
do its thing". It's a belief thats been good for me during all those
years.

Dec 12 '05 #9

P: n/a
Lyle Fairfield wrote:
Almost seven years ago I wrote:

Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function EnableMenuItem Lib "user32" _
(ByVal hMenu As Long, ByVal wIDEnableItem As Long, ByVal wEnable As
Long) As
Long
Private Const MF_BYCOMMAND = &H0&
Private Const MF_ENABLED = &H0&
Private Const MF_GRAYED = &H1&
Private Const SC_CLOSE = &HF060&

Sub EnableCloseButton()
Dim lngSystemMenuHandle As Long
lngSystemMenuHandle = GetSystemMenu(Access.hWndAccessApp, False)
Call EnableMenuItem(lngSystemMenuHandle, SC_CLOSE, MF_BYCOMMAND Or
MF_ENABLED)
End Sub

Sub DisableCloseButton()
Dim lngSystemMenuHandle As Long
lngSystemMenuHandle = GetSystemMenu(Access.hWndAccessApp, False)
Call EnableMenuItem(lngSystemMenuHandle, SC_CLOSE, MF_BYCOMMAND Or
MF_GRAYED)
End Sub
I
It was some of my earliest messing with the API. The original poster
reported that the code worked for his purpose.I felt pretty good.

Dev Ashish posted three messages to the thread part of which are:

1. Why on _earth_ would you want to mess with an MDI app like that,
especially
since it's not yours. I can understand such steps if you were using
CreateWindow or with your own forms etc., but _come on_, not with the
default window of a standard Windows app. Or am I being just plain
stupid
here? And how does one know for a fact (other than looking at the
source)
that Access hasn't put some code behind what-you-just-disabled to
perform
pre-quit-clean-up.

2. Without taking away anything from Lyle's or other's efforts, I would
suggest
instead that you follow more conventional methods of tracking a boolean
variable's state from a form's OnUnload event. My rule of thumb is,
don't
mess with the app itself unless it's absolutely needed and unavoidable.
3. Sorry Lyle, I'm against the idea, not the posts that followed. I
myself
posted similar code long ago I think, but not any more. These days I
have
to point out such UI things to a few people at work quite regularly,
and it
takes it's toll. <g> After all, who knows, next thing you know, folks
will
want to block the three fingure salute, disable app switching,
and-who-knows-what.

I think this was the beginning of my strong belief in "Just let Access
do its thing". It's a belief thats been good for me during all those
years.


I feel that you and Dev have a good point, presented in a civil manner,
about the UI that the OP should consider. But I'm not going to let
that point reduce my joy from my answer. Joy's a commodity in short
supply :-)!

James A. Fortune

Dec 13 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.