VBA禁用窗体的关闭按钮

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
                                       (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal myHwnd 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 GetSystemMenu Lib "user32" _
                                       (ByVal myHwnd As Long, ByVal bRevert As Long) As Long
Private Sub UserForm_Initialize()
    Dim myHwnd As Long
    Dim hMenu As Long
    Dim myRc As Long
    Dim myClassName As String
    Dim SC_CLOSE As Long
    SC_CLOSE = &HF060
    myClassName = "ThunderDFrame"
    myHwnd = FindWindow(myClassName, Me.Caption)
    hMenu = GetSystemMenu(myHwnd, 0&)
    myRc = DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)
    myRc = DrawMenuBar(myHwnd)
End Sub 

 

你可能感兴趣的:(VBA)