473,652 Members | 2,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3788

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********@xtr a.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 fActivateCloseB ox

(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 fActivateContro lBox(Enable As Boolean)
Dim CurStyle As Long
Dim hWnd As Long

hWnd = Access.hWndAcce ssApp

CurStyle = GetWindowLong(h Wnd, 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(h Wnd, GWL_STYLE, CurStyle)
Call DrawMenuBar(hWn d)

End Function

Public Function fActivateCloseB ox(Enable As Boolean)
Dim hMenu As Long
Dim hWnd As Long

hWnd = Access.hWndAcce ssApp

If Enable Then
Call GetSystemMenu(h Wnd, True)
Else
hMenu = GetSystemMenu(h Wnd, False)
If hMenu Then
Call DeleteMenu(hMen u, SC_CLOSE, MF_BYCOMMAND)
End If
End If
Call DrawMenuBar(hWn d)

End Function

Public Function fActivateMaximi zeBox(Enable As Boolean)
Dim CurStyle As Long
Dim hWnd As Long

hWnd = Access.hWndAcce ssApp

CurStyle = GetWindowLong(h Wnd, 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(h Wnd, GWL_STYLE, CurStyle)
Call DrawMenuBar(hWn d)

End Function

Public Function fActivateMinimi zeBox(Enable As Boolean)
Dim CurStyle As Long
Dim hWnd As Long

hWnd = Access.hWndAcce ssApp

CurStyle = GetWindowLong(h Wnd, 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(h Wnd, GWL_STYLE, CurStyle)
Call DrawMenuBar(hWn d)

End Function

Wayne Gillespie
Gosford NSW Australia
Dec 11 '05 #3

"Wayne" <cq*******@volc anomail.com> schreef in bericht news:11******** *************@z 14g2000cwz.goog legroups.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******** ***********@new s.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******** ***********@new s.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:

'modDisableClos eButton
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 DisableCloseBut ton()
Dim lngRet As Long
Dim lngMenuHandle As Long

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

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

'redraw
DrawMenuBar hWndAccessApp
Application.Ref reshTitleBar

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 EnableCloseButt on()
Dim lngSystemMenuHa ndle As Long
lngSystemMenuHa ndle = GetSystemMenu(A ccess.hWndAcces sApp, False)
Call EnableMenuItem( lngSystemMenuHa ndle, SC_CLOSE, MF_BYCOMMAND Or
MF_ENABLED)
End Sub

Sub DisableCloseBut ton()
Dim lngSystemMenuHa ndle As Long
lngSystemMenuHa ndle = GetSystemMenu(A ccess.hWndAcces sApp, False)
Call EnableMenuItem( lngSystemMenuHa ndle, 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 EnableCloseButt on()
Dim lngSystemMenuHa ndle As Long
lngSystemMenuHa ndle = GetSystemMenu(A ccess.hWndAcces sApp, False)
Call EnableMenuItem( lngSystemMenuHa ndle, SC_CLOSE, MF_BYCOMMAND Or
MF_ENABLED)
End Sub

Sub DisableCloseBut ton()
Dim lngSystemMenuHa ndle As Long
lngSystemMenuHa ndle = GetSystemMenu(A ccess.hWndAcces sApp, False)
Call EnableMenuItem( lngSystemMenuHa ndle, 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
1837
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 . !! Here is the code for one of them !! I call a stop function to disconnect all objects (close ) . I also make a call to Stop in the Dispose() function .
4
4165
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 operation. This progress dialog implemented as modeless to allow user to cancel the lenghtly operation if he wishes. At the same time I disable mainframe window to prevent user from clicking on the menu bar. Here is the segment of the code:
7
2873
by: Marco Castro | last post by:
How can I disable and then re-enable the close button on a form? Thanks.
13
22708
by: lightzizo | last post by:
All, How can I disable or remove the close button in the screen. thanks
2
9573
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 complete logic get failed. Also i would like disable save as option + copy & select all option. Please urgently help me.
3
5165
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 user to select a client and
0
2373
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 the screen. I have been unable to find any way to disable this button in Access 2007 and subsequently I have been forced to find ways to detect and handle the situations after the Access Close button has been clicked. I have been largely...
5
5878
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 the screen. I have been unable to find any way to disable this button in Access 2007 and subsequently I have been forced to find ways to detect and handle the situations after the Access Close button has been clicked. I have been largely...
3
3000
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, EnableMenuItem and RemoveMenu. I can figure out how these methods work but there are certain parameters that these methods have whose values that need to be passed to them as argument is unknown to me. How can I know them. E.G.- for EnableMenuItem,...
0
8283
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8470
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8590
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5620
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4147
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.