好了现在不忙了。告诉你代码吧。
建个模块 mod1
代码如下:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function SetTimer& Lib "user32" (ByVal hWnd&, ByVal nIDEvent&, ByVal uElapse&, ByVal lpTimerFunc&)
Public Declare Function KillTimer& Lib "user32" (ByVal hWnd&, ByVal nIDEvent&)
Public Const WM_CLOSE = &H10
Public Const NV_CLOSEMSGBOX As Long = &H5000&
Public 标题 As String
Sub CloseMsg()
Dim MsgHw As Long
KillTimer hWnd, idEvent
MsgHw = FindWindow(vbNullString, 标题)
SendMessage MsgHw, WM_CLOSE, 0, 0
End Sub
Sub zmzmsgbox(消息 As String, 模式 As Long, 标题 As String, 等待时间 As Long)
SetTimer hWnd, NV_CLOSEMSGBOX, 等待时间, AddressOf CloseMsg
MsgBox 消息, 模式, 标题
End Sub
在窗体中调用代码如下:
'请在外部把标题变量先定义好
Sub Command1_Click()
标题 = "ZMZ"
Call zmzmsgbox("hello", 1, 标题, 2000)
end sub