VB中如何把左上角的关闭按钮变成灰色

2024年11月18日 04:26
有3个网友回答
网友(1):

左上角没有关闭按钮啊。如果是右上角那个的话,那个是不能变灰的,只能没有。你可以在QueryUnload 事件里写一行 Cancel=1 这样就关不掉了,你也可以这样写

if vbNo=MsgBox("要关闭程序吗?",vbYesNo,"退出") then
Cancel=1
end if

我当然知道用API可以,关键是,LZ知道API是什么东西吗

网友(2):

谁说不能变灰??????

得用API。

'Form1代码

'注意:“关闭”按钮变灰在Form_Load过程中。

Option Explicit
Private Declare Function RemoveMenu Lib "user32.dll" (ByVal hMenu As Long, ByVal _
uPosition As Long, ByVal uFlags As Long) As Long
Private Declare Function GetSystemMenu Lib "user32.dll" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Const MF_BYCOMMAND = &H0
Const SC_MINIMIZE = &HF020
Const SC_MAXIMIZE = &HF030

Private Sub Form_Load()
Dim hSysMenu As Long
hSysMenu = GetSystemMenu(Me.hWnd, 0)
RemoveMenu hSysMenu, SC_MINIMIZE, MF_BYCOMMAND
RemoveMenu hSysMenu, SC_MAXIMIZE, MF_BYCOMMAND
End Sub

网友(3):

Private Declare Function GetSystemMenu Lib "User32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long

Private Declare Function RemoveMenu Lib "User32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long

Private Declare Function DrawMenuBar Lib "User32" (ByVal hwnd As Long) As Long

Private Declare Function GetMenuItemCount Lib "User32" (ByVal hMenu As Long) As Long

Private Const MF_BYPOSITION = &H400&

Private Const MF_DISABLED = &H2&

Private Sub Form_Load()

Call DisableX(Me)

End Sub

Private Sub DisableX(Frm As Form)

Dim hMenu As Long, nCount As Long

hMenu = GetSystemMenu(Frm.hwnd, 0)

nCount = GetMenuItemCount(hMenu)

Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)

DrawMenuBar Frm.hwnd

End Sub