(宣告:魏滔序原創,轉貼請註明出處。)
用這個類可以替代vb自帶的timer控制項,這樣就不用在無窗體的專案中僅為了使用timer而多加乙個窗體了。我一般用在activex exe中用來分離系統控制權,用timer的好處是避免控制權死鎖,這樣也就模擬出了多執行緒(實際上是多程序),能給使用者更好的體驗。**如下:
標準模組(mtimer):
option
explicit
private
declare
subcopymemory
lib"
kernel32.dll
"alias
"rtlmovememory"(
byref
destination
asany,
byref
source
asany,
byval
length
aslong
)public
timercoll
asnew
vba.collection
public
subtimeproc(
byval
hwnd
aslong
, byval
umsg
aslong
, byval
idevent
aslong
, byval
dwtime
aslong
)dim
timer
astimer, lptimer
aslong
lptimer
=timercoll(
"id:"&
idevent)
copymemory timer, lptimer, 4&
timer.pulsetimer
copymemory timer, 0&
, 4&end sub
類模組(timer):
option
explicit
private
declare
function
settimer
lib"
user32"(
byval
hwnd
aslong
, byval
nidevent
aslong
, byval
uelapse
aslong
, byval
lptimerfunc
aslong
) as
long
private
declare
function
killtimer
lib"
user32"(
byval
hwnd
aslong
, byval
nidevent
aslong
) as
long
private
m_timerid
aslong
private
m_interval
aslong
private
m_enabled
asboolean
public
tag
asvariant
public
event
timer()
public
property
getinterval()
aslong
interval
=m_interval
end property
public
property
let interval(
byval
value
aslong
)m_interval
=value
enabled
=m_enabled
end property
public
property
getenabled()
asboolean
interval
=m_enabled
end property
public
property
let enabled(
byval
value
asboolean)if
value
then
m_enabled
=starttimer
else
call
stoptimer
endif
end property
private
function
starttimer()
asboolean
ifm_timerid =0
then
ifm_interval
>
0then
m_timerid
=settimer(0,
0, m_interval,
addressof
timeproc)
ifm_timerid
<>
0then
timercoll.add objptr(
me),
"id:"&
m_timerid
starttimer
=true
endif
else
m_enabled
=true
endif
endif
end function
friend
subpulsetimer()
raiseevent
timer
end sub
private
substoptimer()
ifm_timerid
<>
0then
killtimer
0, m_timerid
timercoll.remove
"id:"&
m_timerid
m_timerid =0
m_enabled
=false
endif
end sub
private
subclass_terminate()
call
stoptimer
end sub
使用方法:
private
withevents
timer1
astimer
private
subform_load()
settimer1
=new
timerlib.timer
timer1.interval
=1000
timer1.enabled
=true
end sub
private
subtimer1_timer()
debug.print now
end sub
用這個類可以替代VB自帶的Timer控制項
用這個類可以替代vb自帶的timer控制項,這樣就不用在無窗體的專案中僅為了使用timer而多加乙個窗體了。我一般用在activex exe中用來分離系統控制權,用timer的好處是避免控制權死鎖,這樣也就模擬出了多執行緒 實際上是多程序 能給使用者更好的體驗。如下 標準模組 mtimer opti...
用這個類可以替代VB自帶的Timer控制項
用這個類可以替代vb自帶的timer控制項,這樣就不用在無窗體的專案中僅為了使用timer而多加乙個窗體了。我一般用在activex exe中用來分離系統控制權,用timer的好處是避免控制權死鎖,這樣也就模擬出了多執行緒 實際上是多程序 能給使用者更好的體驗。如下 標準模組 mtimer opti...
VB 和timer控制項功能相同的函式
利用api函式實現定時器功能 模組中 option explicit public ltimerid as long private declare function settimer lib user32 byval hwnd as long,byval nidevent as long,byva...