I only want the user to be able to close the program with my exit or log out buttons within the database forms. Does anyone know how to get this to work? Thanks.
Add the following code in a module and use fActivateControlBox(False) in the open event of the startup form to remove the close button
Code:
Option Compare Database
Option Explicit
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
'Enable = False 'added by me
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
'Enable = False 'added by me
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