On 28 Jun 2006 07:59:11 -0700, "PamelaDV" <pd******@us.ibm.com> wrote:
I am wondering if there is a way to disable the "X" used to close the
Access application window? I know how to disable it for individual
forms, but I would like to disable it for the application in general
and force users to use a button on the switchboard to close (because I
run important code on the close of the database from that button).
Any ideas are always appreciated.
Thanks!
Paste the following code into a standard module.
In a startup form use -
fActivateCloseBox(False)
You can play around with the other functions to remove max/min buttons and the
control box.
'source 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