让最大化和最小化按钮消失 声明: Private Declare Function SetWindowLong Lib "user32" _ Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal _ nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Declare Function GetWindowLong Lib "user32" _ Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal _ nIndex As Long) As Long Const WS_MINIMIZEBOX = &H20000 Const WS_MAXIMIZEBOX = &H10000 Const GWL_STYLE = (-16) 使用: Private Sub Form_Load() Dim lWnd As Long lWnd = GetWindowLong(Me.hwnd, GWL_STYLE)lWnd = lWnd And Not (WS_MINIMIZEBOX) lWnd = lWnd And Not (WS_MAXIMIZEBOX) lWnd = SetWindowLong(Me.hwnd, GWL_STYLE, lWnd) End Sub
使关闭、最大、最小化不可用 声明: Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As LongPublic Const MF_BYPOSITION = &H400& Public Const MF_REMOVE = &H1000& 使用: Private Sub Form_Load() Dim hSysMenu As Long Dim nCnt As Long Me.Show hSysMenu = GetSystemMenu(Me.hwnd, False) If hSysMenu Then ' 取得系统菜单中的数量 nCnt = GetMenuItemCount(hSysMenu)If nCnt Then ' 编号 (0, 1, 2, 3...) RemoveMenu hSysMenu, nCnt - 1, MF_BYPOSITION Or MF_REMOVE '去掉 关闭 按钮 RemoveMenu hSysMenu, nCnt - 2, MF_BYPOSITION Or MF_REMOVE ' 去掉一个下划线 '注意下面的语句, 请根据不同 Form 类别具体情况进行调试, ' 没个语句将关闭不同的功能!! 'RemoveMenu hSysMenu, nCnt - 3, MF_BYPOSITION Or MF_REMOVE 'RemoveMenu hSysMenu, nCnt - 4, MF_BYPOSITION Or MF_REMOVE 'RemoveMenu hSysMenu, nCnt - 5, MF_BYPOSITION Or MF_REMOVE DrawMenuBar Me.hwnd ' 重画 End If End If End Sub 方法二: Const MF_REMOVE = &H1000& Const SC_CLOSE = &HF060 Const SC_MAXIMIZE = &HF030 并在 Sub Form_Load()中加入: RemoveMenu GetSystemMenu(hwnd, 0), SC_CLOSE, MF_REMOVE 这样就可以使关闭按钮无效。同样加入 RemoveMenu GetSystemMenu(hwnd, 0), SC_MAXIMIZE, MF_REMOVE
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal _
nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal _
nIndex As Long) As Long
Const WS_MINIMIZEBOX = &H20000
Const WS_MAXIMIZEBOX = &H10000
Const GWL_STYLE = (-16)
使用:
Private Sub Form_Load()
Dim lWnd As Long
lWnd = GetWindowLong(Me.hwnd, GWL_STYLE)lWnd = lWnd And Not (WS_MINIMIZEBOX)
lWnd = lWnd And Not (WS_MAXIMIZEBOX)
lWnd = SetWindowLong(Me.hwnd, GWL_STYLE, lWnd)
End Sub
Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As LongPublic Const MF_BYPOSITION = &H400&
Public Const MF_REMOVE = &H1000&
使用:
Private Sub Form_Load()
Dim hSysMenu As Long
Dim nCnt As Long
Me.Show
hSysMenu = GetSystemMenu(Me.hwnd, False)
If hSysMenu Then
' 取得系统菜单中的数量
nCnt = GetMenuItemCount(hSysMenu)If nCnt Then
' 编号 (0, 1, 2, 3...)
RemoveMenu hSysMenu, nCnt - 1, MF_BYPOSITION Or MF_REMOVE
'去掉 关闭 按钮
RemoveMenu hSysMenu, nCnt - 2, MF_BYPOSITION Or MF_REMOVE
' 去掉一个下划线
'注意下面的语句, 请根据不同 Form 类别具体情况进行调试,
' 没个语句将关闭不同的功能!!
'RemoveMenu hSysMenu, nCnt - 3, MF_BYPOSITION Or MF_REMOVE
'RemoveMenu hSysMenu, nCnt - 4, MF_BYPOSITION Or MF_REMOVE
'RemoveMenu hSysMenu, nCnt - 5, MF_BYPOSITION Or MF_REMOVE
DrawMenuBar Me.hwnd
' 重画
End If
End If
End Sub
方法二:
Const MF_REMOVE = &H1000&
Const SC_CLOSE = &HF060
Const SC_MAXIMIZE = &HF030
并在 Sub Form_Load()中加入:
RemoveMenu GetSystemMenu(hwnd, 0), SC_CLOSE, MF_REMOVE
这样就可以使关闭按钮无效。同样加入
RemoveMenu GetSystemMenu(hwnd, 0), SC_MAXIMIZE, MF_REMOVE
用GetSystemMenu得到系统菜单
再用DeleteMenu删除菜单向(系统菜单项是以SC_开头的常数(如SC_Close))去掉按钮:
用SetWindowLong设置窗口风格