精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● VB和Basic>>VB中禁止窗口的关闭按钮的函数

主题:VB中禁止窗口的关闭按钮的函数
发信人: lynsing(流星)
整理人: winsy(2003-05-03 19:19:18), 站内信件
'禁止关闭按钮的API声明:
Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Public Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long

Public Const MF_BYPOSITION = &H400&
Public Const MF_REMOVE = &H1000&

'禁止关闭按钮的函数
Public Sub DisableClose(hwnd As Long, Optional ByVal MDIChild As Boolean)
    Dim hSysMenu As Long
    Dim nCnt As Long
    Dim cID As Long
    
    hSysMenu = GetSystemMenu(hwnd, False)
    If hSysMenu = 0 Then Exit Sub
    
    nCnt = GetMenuItemCount(hSysMenu)
    
    If MDIChild Then
        cID = 3
    Else
        cID = 1
    End If
    If nCnt Then
        RemoveMenu hSysMenu, nCnt - cID, MF_BYPOSITION Or MF_REMOVE
        RemoveMenu hSysMenu, nCnt - cID - 1, MF_BYPOSITION Or MF_REMOVE
    End If

End Sub




----
关于光盘刻录、VB/C编程、网页制作等技术
欢迎到【一路路发论坛】逛游  

[关闭][返回]