7,763
社区成员
发帖
与我相关
我的任务
分享
Private Sub Command1_Click()
Timer1.Enabled = True
MsgBox "OK"
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
SendKeys "{ENTER}"
End Sub
' ◆◆◆定时消失的对话框◆◆◆
' 新建标准 EXE工程,添加控件 Command1 、Timer1
' 编译后运行 .exe 文件!
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Const MsgTitle$ = "定时消失的对话框"
Private Sub Command1_Click()
Dim msg As String
If Compiled Then
With Timer1
.Interval = 3000
.Enabled = True
End With
msg = "将会消失在 3 秒后。"
Else
msg = "将会消失在 3 秒后," & vbCrLf & "必须编译后才能看见效果。"
End If
MsgBox msg, 64, MsgTitle
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Me.Caption = MsgTitle
End Sub
Private Sub Timer1_Timer()
Dim hWnd As Long
Timer1.Enabled = False
hWnd = FindWindow(vbNullString, MsgTitle)
If (hWnd) Then Call SendMessage(hWnd, &H10, 0, ByVal 0&)
End Sub
Private Function Compiled() As Boolean
On Error GoTo NotCompiled
Debug.Print 1 / 0
Compiled = True
NotCompiled:
End Function