SetTimer(0&, 0&, 100, AddressOf TimerProc)Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, _ ByVal idEvent As Long, ByVal dwTime As Long) '这里写你的代码就可以了 End Sub
timer控件打包本身就不用带控件文件.
'in module1 Option ExplicitPrivate Declare Function SetWindowText Lib "user32.dll" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As LongPublic Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) SetWindowText hwnd, CStr(Time) End Sub'in Form1 Option ExplicitPrivate Declare Function KillTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long Private Declare Function SetTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As LongPrivate Sub Form_Load() SetTimer Me.hwnd, 0, 1000, AddressOf TimerProc End SubPrivate Sub Form_Unload(Cancel As Integer) KillTimer Me.hwnd, 0 End Sub
Option ExplicitPrivate Sub Form_Load() Me.Show Dim mTime As Long mTime = Timer Do While Timer < mTime + 5 DoEvents Me.Caption = CLng(Timer - mTime) Loop End End Sub
给个我能看懂的简单例子就行,谢谢
//所以 许多功能用api实现 兼容性会比较好。
不明白
ByVal idEvent As Long, ByVal dwTime As Long)
'这里写你的代码就可以了
End Sub
Option ExplicitPrivate Declare Function SetWindowText Lib "user32.dll" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As LongPublic Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
SetWindowText hwnd, CStr(Time)
End Sub'in Form1
Option ExplicitPrivate Declare Function KillTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Private Declare Function SetTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As LongPrivate Sub Form_Load()
SetTimer Me.hwnd, 0, 1000, AddressOf TimerProc
End SubPrivate Sub Form_Unload(Cancel As Integer)
KillTimer Me.hwnd, 0
End Sub
如果连VB内置控件都想自已做,建议转学VC。
VB 常识要了解,否则不如不用。
Me.Show
Dim mTime As Long
mTime = Timer
Do While Timer < mTime + 5
DoEvents
Me.Caption = CLng(Timer - mTime)
Loop
End
End Sub