VB6.0 SetTimer 구현 타이머 호출

11425 단어 timer
Timer.bas:

    
      
Option Explicit

Declare Function SetTimer Lib " user32 " ( ByVal hwnd As Long , ByVal nIDEvent As Long , ByVal uElapse As Long , ByVal lpTimerFunc As Long ) As Long
Declare Function KillTimer Lib " user32 " ( ByVal hwnd As Long , ByVal nIDEvent As Long ) As Long

Public Sub TimerProc( ByVal hwnd As Long , ByVal uMsg As Long , ByVal idEvent As Long , ByVal dwTime As Long )
MsgBox Now()
End Sub

창 코드:

    
      
Option Explicit

Dim lngTimerID As Long
Dim BlnTimer As Boolean

Private Sub Form_Load()
BlnTimer
= False
Command1.Caption
= " "
End Sub

Private Sub Form_Unload(Cancel As Integer )
KillTimer
0 , lngTimerID
End Sub

Private Sub Command1_Click()
If BlnTimer = False Then
' 5
lngTimerID = SetTimer( 0 , 0 , 5000 , AddressOf TimerProc)
BlnTimer
= True
Command1.Caption
= " "
Else
KillTimer
0 , lngTimerID
BlnTimer
= False
Command1.Caption
= " "
End If
End Sub

설명:
TimerProc 함수 정의는 bas 모듈 파일에 넣어야 합니다. 그렇지 않으면 "lngTimerID = SetTimer(0, 0, 5000, AddressOf TimerProc)"실행 코드가 잘못됩니다.
팁: 작업자 AddressOf 가 올바르지 않습니다.

좋은 웹페이지 즐겨찾기