VB Code:
Public Declare Function GetMenuItemCount _ Lib "user32" (ByVal hMenu As Long) As _ Long Public Declare Function GetSystemMenu Lib _ "user32" (ByVal hwnd As Long, ByVal _ bRevert As Long) As Long Public Declare Function RemoveMenu Lib _ "user32" (ByVal hMenu As Long, ByVal _ nPosition As Long, ByVal wFlags As Long) _ As Long Public Declare Function DrawMenuBar Lib _ "user32" (ByVal hwnd As Long) As Long Public Const MF_REMOVE = &H1000& Public Const MF_INSERT = &H0& Public Const MF_ENABLED = &H0& Public Const MF_BYPOSITION = &H400& Public Sub DisableX(frm As Form, blnDisabled As Boolean) Dim hMenu As Long Dim nCount As Long If blnDisabled = True Then hMenu = GetSystemMenu(frm.hwnd, 0) nCount = GetMenuItemCount(hMenu) Call RemoveMenu(hMenu, nCount - 1, MF_REMOVE Or MF_BYPOSITION) Call RemoveMenu(hMenu, nCount - 2, MF_REMOVE Or MF_BYPOSITION) DrawMenuBar frm.hwnd Else hMenu = GetSystemMenu(frm.hwnd, True) DrawMenuBar frm.hwnd End If End Sub




Reply With Quote