473,418 Members | 5,105 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,418 software developers and data experts.

disabling close button for application

Hi Folk

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

Thank you

- Nicolaas
Dec 11 '05 #1
9 3771

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
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

"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
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
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
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
I can't remember which one of my secretary's buttons to push either,
James.

Dec 12 '05 #8
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ebrahim | last post by:
This message is in reply to a prev 1 . My application refues to close . Some one had suggested that I might have threads running.. but i solved that problem too . The app still refuses to close...
4
by: Steve | last post by:
I have the MDI MFC application ported to .NET. Now this application include mixed managed/unmanaged code. The application displays progress dialog with the cancel button during lenghtly...
7
by: Marco Castro | last post by:
How can I disable and then re-enable the close button on a form? Thanks.
13
by: lightzizo | last post by:
All, How can I disable or remove the close button in the screen. thanks
2
by: Kapil Jain | last post by:
Dear All, I would like to disable back and forward button + Refresh button. Please help in doing this. I want this because i am displaying data from mysql database and on back and forward button...
3
by: Jim Armstrong | last post by:
Hello all - This is driving me crazy. I have a table called tblClients - very simple, has the following fields: taxID (PK) ClientName SalesName The main form of my application allows a...
0
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of...
5
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of...
3
by: priyamtheone | last post by:
Hi, I am trying to work on an application that disables the close button (X) on the upper right hand corner of a window. In order to do that I need to use calls to API methods like GetSystemMenu,...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.