Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Const SC_CLOSE As Long = &HF060
Private Sub Form_Load()
hMenu = GetSystemMenu(Me.hWnd, 0)
DeleteMenu hMenu, SC_CLOSE, 0&
End Sub
Private Declare Function getsystemmenu Lib "user32" (ByVal hwnd As Long, ByVal brevert As Long) As Long
Private Declare Function deletemenu Lib "user32" (ByVal hmenu As Long, ByVal nposition As Long, ByVal wflags As Long) As Long
Private Declare Function getmenuitemcount Lib "user32" (ByVal hmenu As Long) As Long
Private Const mf_byposition = &H400&
'使用:
Private Sub form_load()
Dim hwndmenu As Long
Dim c As Long
hwndmenu = getsystemmenu(Me.hwnd, 0)
c = getmenuitemcount(hwndmenu)
deletemenu hwndmenu, c - 1, mf_byposition
c = getmenuitemcount(hwndmenu)
deletemenu hwndmenu, c - 1, mf_byposition
End Sub
Private Declare Function GetSystemMenu Lib "User32" (ByVal hwnd As Long, ByVal bRevert 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 Declare Function GetMenuItemCount Lib "User32" (ByVal hMenu As Long) As Long
Private Const MF_BYPOSITION = &H400&
Private Sub Command1_Click()
DisableClose Me
End Sub
Private Sub DisableClose(Frm As Form)
Dim hMenu As Long, nCount As Long
'获取系统菜单的句柄
hMenu = GetSystemMenu(Frm.hwnd, 0)
'得到系统菜单的菜单项目
nCount = GetMenuItemCount(hMenu)
'将关闭按钮置为无效
Call RemoveMenu(hMenu, nCount - 1, MF_BYPOSITION)
'重画系统菜单
DrawMenuBar Frm.hwnd
End Sub
Private Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal b As Boolean, lpMenuItemInfo As MENUITEMINFO) As Long
Private Declare Function SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal bool As Boolean, lpcMenuItemInfo As MENUITEMINFO) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const xMenuID = 10&
Private Sub Command1_Click()
Dim hMenu As Long, MII As MENUITEMINFO