有没有法在没有窗体的程序里调用TIME控件
解决方案 »
- [chenhui530]我也写写博客,希望大家多多支持!200分奉上.
- 初学问题~~
- 如何用VB将JPG或者HTM 文件设置为桌面壁纸????[分不多了,不敢一次放出,帮解决立刻给分]
- 哪里有VB金额大小写的程序?
- 好何一句话改变richtextbox 所有文字的颜色,不要selcolor
- [请教]关于替换问题
- junglerover来领分!
- 各位大侠,赶紧帮忙呀!(一个数据库的问题)^-^thank all!
- vb webbrowser控件怎么取网页中表格(<div> </div>之间)的值?
- vbs写一个程序:输入一串代码,遇到?停止输入。然后计算输入大写字母和小写字母和数字的个数
- 数据库中的字段有小括号
- 下拉列表问题
1、SetTimer,这个函数有个回调,OnTimer事件处理代码就写在回调函数里2、CreateFont
SelectObject yourdc,yourfont
TextOut
DeleteObject yourfont
想直接使用的请到这里下载:http://www.chenoe.com/developer/library/timer.dll标准模块(mTimer):
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
Public TimerColl As New VBA.CollectionPublic Sub TimeProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
Dim Timer As Timer, lpTimer As Long
lpTimer = TimerColl("ID:" & idEvent)
CopyMemory Timer, lpTimer, 4&
Timer.PulseTimer
CopyMemory Timer, 0&, 4&
End Sub类模块(Timer):
Option ExplicitPrivate 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 LongPrivate m_TimerID As Long
Private m_Interval As Long
Private m_Enabled As BooleanPublic Tag As Variant
Public Event Timer()Public Property Get Interval() As Long
Interval = m_Interval
End PropertyPublic Property Let Interval(ByVal Value As Long)
m_Interval = Value
Enabled = m_Enabled
End PropertyPublic Property Get Enabled() As Boolean
Interval = m_Enabled
End PropertyPublic Property Let Enabled(ByVal Value As Boolean)
If Value Then
m_Enabled = StartTimer
Else
Call StopTimer
End If
End PropertyPrivate Function StartTimer() As Boolean
If m_TimerID = 0 Then
If m_Interval > 0 Then
m_TimerID = SetTimer(0, 0, m_Interval, AddressOf TimeProc)
If m_TimerID <> 0 Then
TimerColl.Add ObjPtr(Me), "ID:" & m_TimerID
StartTimer = True
End If
Else
m_Enabled = True
End If
End If
End FunctionFriend Sub PulseTimer()
RaiseEvent Timer
End SubPrivate Sub StopTimer()
If m_TimerID <> 0 Then
KillTimer 0, m_TimerID
TimerColl.Remove "ID:" & m_TimerID
m_TimerID = 0
m_Enabled = False
End If
End SubPrivate Sub Class_Terminate()
Call StopTimer
End Sub使用方法:
Private WithEvents Timer1 As Timer
Private Sub Form_Load()
Set Timer1 = New TimerLib.Timer
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Debug.Print Now
End Sub忘了是谁写的了,呵呵
模块
Private mTimerBack As Long
Public TimerTrue as Boolean
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Declare Function GetTickCount Lib "kernel32" () As Long
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As LongSub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
If TimerTrue Then mTimer GetTickCount,100 '间隔100毫秒
End SubPrivate Sub mTimer(ByVal thenTime As Long,ByVal jTime as long)
If thenTime - mTimerBack > jTime Then
'操作
debug.print thenTime
mTimerBack = thenTime
End If
End Sub
窗体
Private Sub Form_Load()'开始
SetTimer Me.hwnd, 0, 1, AddressOf TimerProcEnd SubPrivate Sub Form_Unload(Cancel As Integer)
'停止
KillTimer Me.hwnd, 0End Sub不知道行不行
SetTimer 0, 0, 1, AddressOf TimerProcEnd SubPrivate Sub mUnload()
'停止
KillTimer 0, 0End Sub复习了一下帖子,,,,,无窗体麻@!