■ 메시지 박스를 일정 시간 경과 후 닫는 방법을 보여준다.
▶ Module (VB)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
Public Const NV_CLOSEMSGBOX As Long = &H5000& Public MessageTitle As String Declare Function SetForegroundWindow Lib "user32" (ByVal pWindowHandle As Long) As Long Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal strClassName As String, ByVal strWindowName As String) As Long Declare Function SetTimer Lib "user32" (ByVal pWindowHandle As Long, ByVal lIDEvent As Long, ByVal lElapse As Long, ByVal lTimerFunction As Long) As Long Declare Function KillTimer Lib "user32" (ByVal pWindowHandle As Long, ByVal lIDEvent As Long) As Long Public Sub TimerProcedure(ByVal pWindowHandle As Long, ByVal lMessage As Long, ByVal lIDEvent As Long, ByVal lTime As Long) Dim lMessageBoxHandle As Long KillTimer pWindowHandle, lIDEvent lMessageBoxHandle = FindWindow("#32770", MessageTitle) If lMessageBoxHandle Then Call SetForegroundWindow(lMessageBoxHandle) SendKeys "{enter}" End If End Sub |
▶ Form (VB)
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Private Sub Command1_Click() Dim pWindowHandle As Long SetTimer pWindowHandle, NV_CLOSEMSGBOX, 3000, AddressOf TimerProcedure MessageTitle = "메세지박스 자동 종료" MsgBox "3초후 메세지박스가 종료됩니다", vbInformation, MessageTitle End Sub |