Disable Window Control Box in Access 2007

Cris

Registered User.
Local time
Today, 13:25
Joined
Jun 10, 2009
Messages
35
I'm trying to hide or disable the close, minimize and maximize buttons on Access Window. I have found different ways working with API's but they just work in early versions like Access 2003. When I test them on Access 2007 nothing happens.

Any one knows a way to do it in Access 2007?

Thanks in advance
 
Yes, my application is a trusted location. This is one of the functions I am testing. It disables the three buttons on my Windows application. In Access 2003 I can disable the minimize button and the close button, but in Access 2007 i just get the minimize button hidden. But the close button is still working.


Code:
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

This is how i call the functions

Code:
Call fActivateMinimizeBox(False) 'will disable the minimize button of the Access MDI window title bar.
Call fActivateMaximizeBox(False) ' will disable the maximise button of the Access MDI window title bar.
Call fActivateCloseBox(False) 'will disable the close button of the Access MDI window title bar.


Any other ideas??
 
Hello.

Yes, I am running Windows XP. Thank you for the link. I was already read that article, so I was just hopping to find someone who already have another solution for this problem.

Thanks
 

Users who are viewing this thread

Back
Top Bottom