Article ID: 149488
Article Last Modified on 7/13/2004
Private Sub Query_Unload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = vbFormControlMenu Then
Cancel = True
End If
End Sub
Option Explicit
Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hWnd As Long, _
ByVal bRevert As Long) As Long
Private Declare Function ModifyMenu Lib "user32" _
Alias "ModifyMenuA" _
(ByVal hMenu As Long, _
ByVal nPosition As Long, _
ByVal wFlags As Long, _
ByVal wIDNewItem As Long, _
ByVal lpString As Any) As Long
Private Declare Function GetMenuItemID Lib "user32" _
(ByVal hMenu As Long, _
ByVal nPos As Long) As Long
Const MF_BYPOSITION = &H400&
Const MF_GRAYED = &H1&
Const MF_BYCOMMAND = &H0&
Sub Command1_click()
' Disables the Close button by calling a user-defined function.
Dim hwndParent As Long
hwndParent = Me.hWnd
DisableItem hwndParent, "&Close", 6
End Sub
Sub DisableItem(hWnd As Long, _
sMenuCaption As String, _
iMenuPos As Integer)
'User-defined function to disable the Close button on the
'MDI Child Form toolbar.
Dim hMenu As Long
Dim hItem As Long
hMenu = GetSystemMenu(hWnd, 0)
hItem = GetMenuItemID(hMenu, iMenuPos)
ModifyMenu hMenu, _
hItem, _
MF_BYCOMMAND Or MF_GRAYED, _
-9, _
sMenuCaption
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Me.Show
Combo1.AddItem "first item"
Command1.Caption = "Disable Close Button"
Command2.Caption = "Unload MDI Child Form"
End Sub
Additional query words: kbide kbVBp kbdsd kbDSupport kbVBp400bug kbVBp500fix kbControl
Keywords: kbbug kbfix kbvbp500fix kbctrl KB149488