VB Code:
  1. 'In a module
  2.     'Call from any form, passing the Form object
  3.     Option Explicit On
  4.  
  5.     Private Const MF_DISABLED = &H2&
  6.     Private Const MF_BYPOSITION = &H400&
  7.  
  8.     Private Declare Function GetSystemMenu Lib "user32.dll" (ByVal hwnd As Int32, ByVal bRevert As Int32) As Int32
  9.     Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Integer) As Integer
  10.     Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
  11.     Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Integer) As Integer
  12.  
  13.     Public Function DisableX(ByRef oForm As System.Windows.Forms.Form)
  14.         '<VB/OUTLOOK GURU 11/09/2004 - REMOVES FORM SYSTEM MENU ITEMS BY POSITIONS>
  15.         Dim hMenu As Int32
  16.         Dim nCount As Integer
  17.         hMenu = GetSystemMenu(oForm.Handle.ToInt32, 0)
  18.         nCount = GetMenuItemCount(hMenu)
  19.         Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
  20.         nCount = GetMenuItemCount(hMenu)
  21.         Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
  22.         Call DrawMenuBar(oForm.Handle.ToInt32)
  23.     End Function