建一个COmmand1,Command2。
代码如下。
================
Dim h As Long, l As Long
Private Const MF_BYPOSITION = &H400&
Private Const MF_ENABLED = &H0&
Private Const MF_DISABLED = &H2&
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 EnableMenuItem Lib "user32" (ByVal hMenu As Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
Private Sub Command1_Click()
EnableMenuItem h, l - 1, MF_BYPOSITION + MF_DISABLED
WindowState = 1
WindowState = 0
End Sub
Private Sub Command2_Click()
EnableMenuItem h, l - 1, MF_BYPOSITION + MF_ENABLED
WindowState = 1
WindowState = 0
End Sub
Private Sub Form_Load()
h = GetSystemMenu(hwnd, 0)
l = GetMenuItemCount(h)
End Sub
我只会让关闭按钮变为灰色不可用,不会让关闭按钮由灰色不可用变为可用。
设置关闭窗体不可用
Private Sub Form_Unload(Cancel As Integer)
Cancel = True
End Sub
=。=
直接在窗体的Unload事件中添加判断,如:
Private CanClose As Boolean '//能否关闭,TURE为可以关,FALSE为不可以
Priavate Sub Command1_Click()
CanClose = False
End Sub
Priavate Sub Command2_Click()
CanClose = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
Cancel = IIf(CanClose, 0, 1)
End Sub