Access Form Menu Bar - Hide The Close Button ('X')

R

Ryan

Hello,

I have been reading alot about how to hide the close button on a menu
bar for an access form. So far there seem to be two methods people
have listed:

1) Calling the function ApplicationCloseButtonState:

Const MF_GRAYED = &H1&
Const MF_BYCOMMAND = &H0&
Const SC_CLOSE = &HF060&
Const MF_BYPOSITION = &H400&
Const MF_REMOVE = &H1000&

Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As
Long, ByVal bRevert As Long) As Long

Private Declare Function EnableMenuItem Lib "user32" (ByVal hmenu As
Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long

Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As
Long

Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long)
As Long

Private Declare Function GetMenuItemCount Lib "user32" (ByVal hmenu As
Long) As Long

Private Declare Function RemoveMenu Lib "user32" (ByVal hmenu As Long,
ByVal nPosition As Long, ByVal wFlags As Long) As Long

'Disable the Close Button Option
Sub ApplicationCloseButtonState(boolClose As Boolean)
Dim hwnd As Long
Dim wFlags As Long
Dim hmenu As Long
Dim result As Long

hwnd = Application.hWndAccessApp
hmenu = GetSystemMenu(hwnd, 0)
If Not boolClose Then
wFlags = MF_BYCOMMAND Or MF_GRAYED
Else
wFlags = MF_BYCOMMAND And Not MF_GRAYED
End If

result = EnableMenuItem(hmenu, SC_CLOSE, wFlags)
End Sub

2) Using the following (assume all necessary declarations have been
made):

Private Declare Function RemoveMenu Lib "user32" (ByVal hmenu As Long,
ByVal nPosition As Long, ByVal wFlags As Long) As Long


'Private Sub ClearMenu(hmenu As Long, hwnd As Long)
'Dim lMenuItemCount As Long
'Get handle to our form's system menu
'(Restore, Maximize, Move, close etc.)
' hmenu = GetSystemMenu(Me.hWnd, False)

' If hmenu Then
'Get System menu's menu count
' lMenuItemCount = GetMenuItemCount(hmenu)
' If lMenuItemCount Then
' 'Menu count is based on 0 (0, 1, 2, 3...)
' Call RemoveMenu(hmenu, lMenuItemCount - 1, _
' MF_BYPOSITION Or MF_REMOVE) 'Remove Close
' Call RemoveMenu(hmenu, lMenuItemCount - 2, _
' MF_BYPOSITION Or MF_REMOVE) 'Remove the seperator
' Call DrawMenuBar(hwnd) 'Force caption bar's
refresh. Disabling X button
' End If
' End If
'End Sub


#1 works great for removing the Close button from the application
itself. I cannot figure out how to remove the close button from the
menu bar of the form though. GetSystemMenu seems to just return 0 or
evidently the handle to some other menu when I pass it the forms
handle (form.hwnd). Same is true for GetMenu. Is there anyway to
deactivate the close button without keeping the form in a
pseudo-minimized state or removing all menu bars entirely (and
replacing with toolbars?)

Thanks!
Ryan
 

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