Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)If UnloadMode = 0 Then Cancel = 1 End IfEnd Sub
是不是这个!让最大化和最小化按钮消失 声明: 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
TechnoFantasy(www.applevb.com) 对的Public Const MF_BYPOSITION = &H400 Public Const MF_REMOVE = &H1000Public Declare Function DrawMenuBar Lib "user32" _ (ByVal hwnd As Long) As Long
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 '--end block--'Option ExplicitPrivate Sub Form_Load() Dim hMenu As Long Dim menuItemCount As Long 'Obtain the handle to the form's system menu hMenu = GetSystemMenu(Me.hwnd, 0)
If hMenu Then
'Obtain the number of items in the menu menuItemCount = GetMenuItemCount(hMenu)
'Remove the system menu Close menu item. 'The menu item is 0-based, so the last 'item on the menu is menuItemCount - 1 Call RemoveMenu(hMenu, menuItemCount - 1, _ MF_REMOVE Or MF_BYPOSITION)
'Remove the system menu separator line Call RemoveMenu(hMenu, menuItemCount - 2, _ MF_REMOVE Or MF_BYPOSITION)
'Force a redraw of the menu. This 'refreshes the titlebar, dimming the X Call DrawMenuBar(Me.hwnd) End If
End Sub
我有一个很烂的方法不知你是否满意,代码如下: Dim bl_Unload As Boolean '用于标志是否使用退出按钮 Private Sub Command1_Click() '退出按钮事件 bl_Unload = True Unload Me End Sub Private Sub Form_Load() bl_Unload = False End SubPrivate Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If Not bl_Unload Then Cancel = True End Sub
你用Form_QueryUnload该事件把Cancel的值该为1就可以了
VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 3195 ClientLeft = 60 ClientTop = 345 ClientWidth = 4680 LinkTopic = "Form1" ScaleHeight = 3195 ScaleWidth = 4680 StartUpPosition = 3 'Windows Default Begin VB.CommandButton Command2 Caption = "Command2" Height = 735 Left = 2880 TabIndex = 1 Top = 1320 Width = 1335 End Begin VB.CommandButton Command1 Caption = "Command1" Height = 735 Left = 480 TabIndex = 0 Top = 1320 Width = 1335 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False 'API函数的声明。 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 AppendMenu Lib "User32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long Private Declare Function GetMenuString Lib "User32" Alias "GetMenuStringA" (ByVal hMenu As Long, ByVal wIDItem As Long, ByVal lpString As String, ByVal nMaxCount As Long, ByVal wFlag As Long) 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 LongConst WM_NCLBUTTONDBLCLK = &HA3 Const WM_NCLBUTTONDOWN = &HA1 Const HTCAPTION = 2 Const MF_STRING = &H0& Const MF_BYCOMMAND = &H0& Const SC_CLOSE = &HF060 '变量的声明 Private hMenu As Long '记录Close MenuItem的字串 Private CloseStr As String'Command1的Click事件将"关闭"的那一个MenuItem 加回来 Private Sub Command1_Click() Call AppendMenu(hMenu, MF_STRING, SC_CLOSE, CloseStr) '令"×"能出现Enable的颜色 Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&) End Sub'Command2的Click事件去除"关闭"菜单功能。 Private Sub Command2_Click() '取得系统菜单的句柄。 hMenu = GetSystemMenu(Form1.hWnd, 0) CloseStr = String(255, 0) 'SC_CLOSE指的便是"关闭"的那一个MenuItem ID Call GetMenuString(hMenu, SC_CLOSE, CloseStr, 256, MF_BYCOMMAND) '处理数据。 CloseStr = Left(CloseStr, InStr(1, CloseStr, Chr(0)) - 1) '调用函数。 Call DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND) '发送一个信息,使"×"出现Disable颜色。 Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&) End SubPrivate Sub Form_Load() '初始化。 Form1.Caption = "菜单操作" Command1.Caption = "恢复" Command2.Caption = "去除" End Sub '去除窗体中的×关闭功能
[email protected]
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)If UnloadMode = 0 Then
Cancel = 1
End IfEnd Sub
声明:
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
Public Const MF_REMOVE = &H1000Public Declare Function DrawMenuBar Lib "user32" _
(ByVal hwnd As Long) As Long
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
'--end block--'Option ExplicitPrivate Sub Form_Load() Dim hMenu As Long
Dim menuItemCount As Long 'Obtain the handle to the form's system menu
hMenu = GetSystemMenu(Me.hwnd, 0)
If hMenu Then
'Obtain the number of items in the menu
menuItemCount = GetMenuItemCount(hMenu)
'Remove the system menu Close menu item.
'The menu item is 0-based, so the last
'item on the menu is menuItemCount - 1
Call RemoveMenu(hMenu, menuItemCount - 1, _
MF_REMOVE Or MF_BYPOSITION)
'Remove the system menu separator line
Call RemoveMenu(hMenu, menuItemCount - 2, _
MF_REMOVE Or MF_BYPOSITION)
'Force a redraw of the menu. This
'refreshes the titlebar, dimming the X
Call DrawMenuBar(Me.hwnd) End If
End Sub
Dim bl_Unload As Boolean '用于标志是否使用退出按钮
Private Sub Command1_Click() '退出按钮事件
bl_Unload = True
Unload Me
End Sub
Private Sub Form_Load()
bl_Unload = False
End SubPrivate Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If Not bl_Unload Then Cancel = True
End Sub
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command2
Caption = "Command2"
Height = 735
Left = 2880
TabIndex = 1
Top = 1320
Width = 1335
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 735
Left = 480
TabIndex = 0
Top = 1320
Width = 1335
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'API函数的声明。
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 AppendMenu Lib "User32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Private Declare Function GetMenuString Lib "User32" Alias "GetMenuStringA" (ByVal hMenu As Long, ByVal wIDItem As Long, ByVal lpString As String, ByVal nMaxCount As Long, ByVal wFlag As Long) 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 LongConst WM_NCLBUTTONDBLCLK = &HA3
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2
Const MF_STRING = &H0&
Const MF_BYCOMMAND = &H0&
Const SC_CLOSE = &HF060
'变量的声明
Private hMenu As Long
'记录Close MenuItem的字串
Private CloseStr As String'Command1的Click事件将"关闭"的那一个MenuItem 加回来
Private Sub Command1_Click()
Call AppendMenu(hMenu, MF_STRING, SC_CLOSE, CloseStr)
'令"×"能出现Enable的颜色
Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End Sub'Command2的Click事件去除"关闭"菜单功能。
Private Sub Command2_Click()
'取得系统菜单的句柄。
hMenu = GetSystemMenu(Form1.hWnd, 0)
CloseStr = String(255, 0)
'SC_CLOSE指的便是"关闭"的那一个MenuItem ID
Call GetMenuString(hMenu, SC_CLOSE, CloseStr, 256, MF_BYCOMMAND)
'处理数据。
CloseStr = Left(CloseStr, InStr(1, CloseStr, Chr(0)) - 1)
'调用函数。
Call DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)
'发送一个信息,使"×"出现Disable颜色。
Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End SubPrivate Sub Form_Load()
'初始化。
Form1.Caption = "菜单操作"
Command1.Caption = "恢复"
Command2.Caption = "去除"
End Sub
'去除窗体中的×关闭功能