用這個類可以替代vb自帶的timer控制項,這樣就不用在無窗體的專案中僅為了使用timer而多加乙個窗體了。我一般用在activex exe中用來分離系統控制權,用timer的好處是避免控制權死鎖,這樣也就模擬出了多執行緒(實際上是多程序),能給使用者更好的體驗。**如下:
標準模組(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.collection
public 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 explicit
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 m_timerid as long
private m_interval as long
private m_enabled as boolean
public tag as variant
public event timer()
public property get interval() as long
interval = m_interval
end property
public property let interval(byval value as long)
m_interval = value
enabled = m_enabled
end property
public property get enabled() as boolean
interval = m_enabled
end property
public property let enabled(byval value as boolean)
if value then
m_enabled = starttimer
else
call stoptimer
end if
end property
private 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 function
friend sub pulsetimer()
raiseevent timer
end sub
private 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 sub
private 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
用這個類可以替代VB自帶的Timer控制項
用這個類可以替代vb自帶的timer控制項,這樣就不用在無窗體的專案中僅為了使用timer而多加乙個窗體了。我一般用在activex exe中用來分離系統控制權,用timer的好處是避免控制權死鎖,這樣也就模擬出了多執行緒 實際上是多程序 能給使用者更好的體驗。如下 標準模組 mtimer opti...
可替代VB自帶的Timer控制項的Timer類
宣告 魏滔序原創,轉貼請註明出處。用這個類可以替代vb自帶的timer控制項,這樣就不用在無窗體的專案中僅為了使用timer而多加乙個窗體了。我一般用在activex exe中用來分離系統控制權,用timer的好處是避免控制權死鎖,這樣也就模擬出了多執行緒 實際上是多程序 能給使用者更好的體驗。如下...
用Spring的這個類來讀取配置檔案
在開發中讀取專案中的配置或者靜態檔案是家常便飯的事情,我相信很多同學都從網上找下面的例子來進行檔案載入讀取操作。利用classloader獲取classpath路徑 classloader loader thread.currentthread getcontextclassloader strin...