在VB中,如何让msgbox 弹出的对话框不显示右上角的关闭按钮,就是那个叉叉?或者成不可用状态也可以。

2024-12-13 16:16:57
推荐回答(4个)
回答1:

加一个定时器控件
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 Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Private Const MB_OK = &H0&
Dim MsgTitle As String
Private Sub Command1_Click()
MsgTitle = "你真好"
Timer1.Enabled = True: Timer1.Interval = 1
MessageBox Me.hwnd, "哈哈哈哈,你真好~", MsgTitle, MB_OK
End Sub

Private Sub Timer1_Timer()
h = FindWindow(vbNullString, MsgTitle)
If h > 0 Then Call DisableX(h): Timer1.Enabled = False
End Sub

Private Sub DisableX(ByVal hwnd As Long)
Dim hMenu As Long, nCount As Long
hMenu = GetSystemMenu(hwnd, 0)
nCount = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
DrawMenuBar hwnd
End Sub

回答2:

不行的,不然你就用窗口来代替
或者你获取msgbox的返回值,如果按下了关闭,再重新弹出

回答3:

将msgbox改成form,当需要信息时,不用弹出对话框,直接显示另一个FORM窗口。

回答4:

自己新建一个窗口当msgbox 选择无边框窗口