Option Explicit
' 윈도우를 찾아 핸들값을 반환 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long ' 타이머를 설정 Private Declare Function SetTimer Lib "user32" _ (ByVal hwnd As Long, _ ByVal nIDEvent As Long, _ ByVal uElapse As Long, _ ByVal lpTimerFunc As Long) As Long ' 타이머를 종료 Private Declare Function KillTimer Lib "user32" _ (ByVal hwnd As Long, _ ByVal nIDEvent As Long) As Long ' 메시지를 윈도우에 전송 Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Integer, _ ByVal lParam As Any) As Long
Private strTitle As String Private lngTimerID As Long Sub dhMain() Dim iResult As Integer ' VbMsgBoxResult Dim strPrompt As String Dim sTitle As String Dim lngInterval As Long strPrompt = "버튼을 누르거나" & vbCr & _ "누르지 않더라도 2초 뒤에 이 메시지 상자는 닫힙니다." sTitle = "MagicSheet & 엑사모" '실행할 시간 lngInterval = 2000 StartTimer lngInterval strTitle = sTitle iResult = MsgBox(strPrompt, vbOKCancel + vbInformation, sTitle) EndTimer
End Sub
'아래의 코드는 VBA 877 타이머를 만들려면이란 예제를 참고하라 Function EndTimer() As Boolean If lngTimerID Then lngTimerID = KillTimer(0&, lngTimerID) lngTimerID = 0 EndTimer = True End If End Function
Sub StartTimer(llngInterval As Long) If lngTimerID Then EndTimer End If lngTimerID = SetTimer(0, 0, ByVal llngInterval, AddressOf TimerProc) End Sub
Private Sub TimerProc(ByVal lhwnd As Long, _ ByVal lMsg As Long, _ ByVal lIDEvent As Long, _ ByVal lTime As Long) Const WM_CLOSE = &H10 Dim lHwndMsgbox As Long lHwndMsgbox = FindWindow(vbNullString, strTitle) SendMessage lHwndMsgbox, WM_CLOSE, 0, ByVal 0& End Sub
|