سلام
از این کد استفاده کن
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert 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
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Form_Load()
DisableX Me.hwnd
End Sub
'*----------------------------------------------------------*
'* Disables the close button ('X') on form. *
'*----------------------------------------------------------*
Private Sub DisableX(tHwnd As Long)
Dim hMenu As Long, nCount As Long
Const MF_BYPOSITION = &H400&
Const MF_DISABLED = &H2&
'Get handle to system menu
hMenu = GetSystemMenu(tHwnd, 0)
'Get number of items in menu
nCount = GetMenuItemCount(hMenu)
'Remove last item from system menu (last item is 'Close')
RemoveMenu hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION
'Get number of items in menu
nCount = GetMenuItemCount(hMenu)
RemoveMenu hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION
'Redraw menu
DrawMenuBar tHwnd
End Sub