Programming » Visual Basic 6 » Visual Basic 6 Code » Forms » ");?>
Disables the X of a form and removes the close option in the control menu.
Public Declare Function GetSystemMenu Lib "user32" _
        (ByVal hwnd As Long, _
        ByVal bRevert As LongAs Long
Public Declare Function GetMenuItemCount Lib "user32" _
        (ByVal hMenu As Long) _
        As Long
Public Declare Function RemoveMenu Lib "user32" _
        (ByVal hMenu As LongByVal _
        nPosition As LongByVal wFlags As LongAs Long
Public Declare Function DrawMenuBar Lib "user32" _
        (ByVal hwnd As LongAs Long
Public Const MF_BYPOSITION = &H400&
Public Const MF_REMOVE = &H1000&

Public Sub DisableX(Frm As Form)
    Dim hMenu As Long
    Dim nCount As Long
    hMenu = GetSystemMenu(Frm.hwnd, 0)
    nCount = GetMenuItemCount(hMenu)
    'Get rid of the Close menu and its separator
    Call RemoveMenu(hMenu, nCount - 1, MF_REMOVE Or MF_BYPOSITION)
    Call RemoveMenu(hMenu, nCount - 2, MF_REMOVE Or MF_BYPOSITION)
    'Make sure the screen updates
    'our change
    DrawMenuBar Frm.hwnd
End Sub