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 ExplicitPrivate 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_BYPOSITIONEnd SubPrivate Sub Command1_Click() '退出    EndEnd Sub

赶快实际运行,体验一下吧~

更多编程干货
VB编程语言基础知识点总结(转
VB6.0中文简体版安装视频教程!
VB开发的实际项目展示!VB编程就是这么强大!
(0)

相关推荐