VB如何实现禁用程序关闭?
在我们日常编程中,进入VB编程开发界面后,默认的窗体运行后是下图的状态,右上角的关闭按钮是直接可用的状态。
但是在实际开发中,有时候根据实际功能需要,会出现不想让右上角的关闭按钮起作用时的情形,那么应该如何做呢?
代码实现:
标准模块代码:
Option Explicit
Declare Function GetSystemMenu Lib 'User32' (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Declare Function DeleteMenu Lib 'User32' (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Declare Function GetMenuItemCount Lib 'User32' (ByVal hMenu As Long) As Long
Public Const MF_BYPOSITION = &H400&
窗体中代码:
Option Explicit
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 Sub Command1_Click() '退出
End
End Sub
赶快实际运行,体验一下吧~
赞 (0)