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