vb中如何屏蔽标题栏中系统关闭按钮?
vb中如何屏蔽标题栏中系统关闭按钮?
[解决办法]
窗体属性里面的ControlBox设置为false
[解决办法]
orm.controlbox=false
不过这样有个缺陷
就是最大,最小,按钮都没有了
那你也可以这样
把标题栏全去掉 (flat ) 然后自己在做两幅小图片 模仿最大化 最小化按钮的图形,在每幅图片所在picturebox 或image控件的click 事件中 写代码 当然还可以自己设计标题栏 这样设计的界面还算好看点。
还有api 函数可以实现
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 DrawMenuBar Lib "user32 " (ByVal hwnd 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 Const MF_BYPOSITION = &H400&
private Const MF_REMOVE = &H1000&
private Const SC_CLOSE = &HF060
private Const SC_MAXIMIZE = &HF030
private Const SC_MINIMIZE = &HF020
Private Sub Form_Load()
Dim hSysMenu As Long
Dim n As Long
hSysMenu = GetSystemMenu(Me.hwnd, False)
If hSysMenu Then
' 取得系统菜单中的数量
n = GetMenuItemCount(hSysMenu)
If n Then
RemoveMenu hSysMenu, n - 1, MF_BYPOSITION Or MF_REMOVE
'去掉 关闭 按钮
RemoveMenu hSysMenu, n - 2, MF_BYPOSITION Or MF_REMOVE
DrawMenuBar Me.hwnd
End If
End If
End Sub
其实可以不要去掉的,你可以在关程序的事件中加代码判断的,比如::
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = 3 Then
Cancel = True
Exit Sub
End If
UnloadMode表示关程序的原因:
0 在窗体是点了“关闭”按钮
1 程序内部的unload语句
2 window的关机
3 任务管理器中的结束
4 mdi只窗体关闭
5 上级窗体关闭
[解决办法]
Option Explicit
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 Const MF_BYCOMMAND = &H0&
Private Const MF_BYPOSITION = &H400&
Private Const SC_CLOSE = &HF060&
Private Const WM_CLOSE = &H10
Private Sub Form_Load()
Dim hMenu As Long
hMenu = GetSystemMenu(Me.hwnd, 0)
Call DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)
End Sub