Disable close buttons

G

Guest

How do I disable the close and minimize/maximize buttons in the application
title bar?

I don’t want the user to shut my application down by accident – there is a
regular close button on the main form.
 
J

Jeff Conrad

in message:
How do I disable the close and minimize/maximize buttons in the application
title bar?

I don't want the user to shut my application down by accident - there is a
regular close button on the main form.

Hi Diane,

Here are some techniques that should help.

Take your pick based on version.

ACC: How to Disable the Close Button (X) on the Access
Application Window (95/97)
http://support.microsoft.com/?id=258049

ACC2000: How to Disable the Close Button (X) on the Access
Application Window
http://support.microsoft.com/?id=245746

ACC2002: How to Disable the Close Button (X) on the Access
Application Window and the Exit Command on the File Menu
http://support.microsoft.com/?id=300688

Alternatively, take a look here:

http://www.mvps.org/access/general/gen0005.htm

or here:

http://www.datapigtechnologies.com/flashfiles/preventcloseform.html

And some ready made code from MVP Terry Kreft:paste the following code into a module, then call it with
Call Buttons(false)

To turn them off and
Call Buttons(True)

to turn them on



' ********** Code Start *************
Option Explicit

Private Const GWL_STYLE = (-16)
Private Const WS_CAPTION = &HC00000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_SYSMENU = &H80000


Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOZORDER = &H4
Public Const SWP_FRAMECHANGED = &H20

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 SetWindowPos _
Lib "user32" ( _
ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long _
) As Long
' **************************************************
'

Function AccessTitleBar(Show As Boolean) As Long
Dim hwnd As Long
Dim nIndex As Long
Dim dwNewLong As Long
Dim dwLong As Long
Dim wFlags As Long

hwnd = hWndAccessApp
nIndex = GWL_STYLE
wFlags = SWP_NOSIZE + SWP_NOZORDER + SWP_FRAMECHANGED + SWP_NOMOVE

dwLong = GetWindowLong(hwnd, nIndex)

If Show Then
dwNewLong = (dwLong Or WS_CAPTION)
Else
dwNewLong = (dwLong And Not WS_CAPTION)
End If

Call SetWindowLong(hwnd, nIndex, dwNewLong)
Call SetWindowPos(hwnd, 0&, 0&, 0&, 0&, 0&, wFlags)
End Function


Function Buttons(Show As Boolean) As Long
Dim hwnd As Long
Dim nIndex As Long
Dim dwNewLong As Long
Dim dwLong As Long

hwnd = hWndAccessApp
nIndex = GWL_STYLE

Const wFlags = SWP_NOSIZE + SWP_NOZORDER + SWP_FRAMECHANGED + SWP_NOMOVE
Const FLAGS_COMBI = WS_MINIMIZEBOX Or WS_MAXIMIZEBOX Or WS_SYSMENU

dwLong = GetWindowLong(hwnd, nIndex)

If Show Then
dwNewLong = (dwLong Or FLAGS_COMBI)
Else
dwNewLong = (dwLong And Not FLAGS_COMBI)
End If

Call SetWindowLong(hwnd, nIndex, dwNewLong)
Call SetWindowPos(hwnd, 0&, 0&, 0&, 0&, 0&, wFlags)
End Function
' ********** Code End *************
[/QUOTE][/QUOTE][/QUOTE]

Hope that helps,
 
G

Guest

Hi Jeff,

maybe you see this... I finally got around to try out the Terry Kreft code.

It works well - but with one problem:

Once the buttons are not shown, the window converts to "floating" - i.e. not
maximized, and can be moved by pulling the title bar.

How do I keep it maximized and "anchored"?
--
Diane


Jeff Conrad said:
in message:


Hi Diane,

Here are some techniques that should help.

Take your pick based on version.

ACC: How to Disable the Close Button (X) on the Access
Application Window (95/97)
http://support.microsoft.com/?id=258049

ACC2000: How to Disable the Close Button (X) on the Access
Application Window
http://support.microsoft.com/?id=245746

ACC2002: How to Disable the Close Button (X) on the Access
Application Window and the Exit Command on the File Menu
http://support.microsoft.com/?id=300688

Alternatively, take a look here:

http://www.mvps.org/access/general/gen0005.htm

or here:

http://www.datapigtechnologies.com/flashfiles/preventcloseform.html

And some ready made code from MVP Terry Kreft:
Paste the following code into a module, then call it with
Call Buttons(false)

To turn them off and
Call Buttons(True)

to turn them on



' ********** Code Start *************
Option Explicit

Private Const GWL_STYLE = (-16)
Private Const WS_CAPTION = &HC00000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_SYSMENU = &H80000


Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOZORDER = &H4
Public Const SWP_FRAMECHANGED = &H20

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 SetWindowPos _
Lib "user32" ( _
ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long _
) As Long
' **************************************************
'

Function AccessTitleBar(Show As Boolean) As Long
Dim hwnd As Long
Dim nIndex As Long
Dim dwNewLong As Long
Dim dwLong As Long
Dim wFlags As Long

hwnd = hWndAccessApp
nIndex = GWL_STYLE
wFlags = SWP_NOSIZE + SWP_NOZORDER + SWP_FRAMECHANGED + SWP_NOMOVE

dwLong = GetWindowLong(hwnd, nIndex)

If Show Then
dwNewLong = (dwLong Or WS_CAPTION)
Else
dwNewLong = (dwLong And Not WS_CAPTION)
End If

Call SetWindowLong(hwnd, nIndex, dwNewLong)
Call SetWindowPos(hwnd, 0&, 0&, 0&, 0&, 0&, wFlags)
End Function


Function Buttons(Show As Boolean) As Long
Dim hwnd As Long
Dim nIndex As Long
Dim dwNewLong As Long
Dim dwLong As Long

hwnd = hWndAccessApp
nIndex = GWL_STYLE

Const wFlags = SWP_NOSIZE + SWP_NOZORDER + SWP_FRAMECHANGED + SWP_NOMOVE
Const FLAGS_COMBI = WS_MINIMIZEBOX Or WS_MAXIMIZEBOX Or WS_SYSMENU

dwLong = GetWindowLong(hwnd, nIndex)

If Show Then
dwNewLong = (dwLong Or FLAGS_COMBI)
Else
dwNewLong = (dwLong And Not FLAGS_COMBI)
End If

Call SetWindowLong(hwnd, nIndex, dwNewLong)
Call SetWindowPos(hwnd, 0&, 0&, 0&, 0&, 0&, wFlags)
End Function
' ********** Code End *************
[/QUOTE]

Hope that helps,[/QUOTE]
 
J

Jeff Conrad

in message:
Hi Jeff,

maybe you see this... I finally got around to try out the Terry Kreft code.

It works well - but with one problem:

Once the buttons are not shown, the window converts to "floating" - i.e. not
maximized, and can be moved by pulling the title bar.

How do I keep it maximized and "anchored"?

Hi Diane,

Are you talking about keeping the Access application window itself
from being able to be moved using Terry's code?
Humm...I do not think this is possible using Terry's code, but I will
do some testing and see if I can find anything.
 
G

Guest

Yes, that is exactly the problem. Once I use Terry's code to turn off the
Access min/max/close buttons, the application window can suddenly be moved
around by dragging the title bar.

With the buttons present I cant move the Access application window. The
scenario is:
Turn buttons off -> app-window can move -> turn buttons on -> app-window
cant move any more (keeps the position it was moved to)
 
G

Guest

Hi Jeff,

anything new on this subject...?

Briefly looked at your web-site - but nothing seemed to touch this issue.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top