在VB類模組中使用計時器

2021-06-01 11:17:34 字數 3741 閱讀 7691

private declare sub copymemory lib "kernel32" alias "rtlmovememory" (destination as any, _

source as any, byval length as long)

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

dim m_idtimer as long

dim m_enabled as boolean

dim m_interval as long

dim m_ltimerproc as long

public event timer()

private sub class_initialize()

m_interval = 0

m_ltimerproc = getclassprocaddr(8)

end sub

private sub class_terminate()

if m_idtimer <> 0 then killtimer 0, m_idtimer

end sub

public property get interval() as long

interval = m_interval

end property

public property let interval(byval new_value as long)

if new_value >= 0 then m_interval = new_value

end property

public property get enabled() as boolean

enabled = m_enabled

end property

public property let enabled(byval new_value as boolean)

m_enabled = new_value

if m_idtimer <> 0 then killtimer 0, m_idtimer

if new_value and m_interval > 0 then

m_idtimer = settimer(0, 0, m_interval, m_ltimerproc)

end if

end property

private function getclassprocaddr(byval index as long, optional paramcount as long = 4, optional hasreturnvalue as boolean) as long

static lreturn as long, preturn as long

static asmcode(50) as byte

dim i as long, pthis as long, pvtbl as long, pfunc as long

pthis = objptr(me)

copymemory pvtbl, byval pthis, 4

copymemory pfunc, byval pvtbl + (6 + index) * 4, 4

preturn = varptr(lreturn)

for i = 0 to ubound(asmcode)

asmcode(i) = &h90

next

asmcode(0) = &h55

asmcode(1) = &h8b: asmcode(2) = &hec

asmcode(3) = &h53

asmcode(4) = &h56

asmcode(5) = &h57

if hasreturnvalue then

asmcode(6) = &hb8

copymemory asmcode(7), preturn, 4

asmcode(11) = &h50

end if

for i = 0 to paramcount - 1

asmcode(12 + i * 3) = &hff

asmcode(13 + i * 3) = &h75

asmcode(14 + i * 3) = (paramcount - i) * 4 + 4

next

i = i * 3 + 12

asmcode(i) = &hb9

copymemory asmcode(i + 1), pthis, 4

asmcode(i + 5) = &h51

asmcode(i + 6) = &he8

copymemory asmcode(i + 7), pfunc - varptr(asmcode(i + 6)) - 5, 4

if hasreturnvalue then

asmcode(i + 11) = &hb8

copymemory asmcode(i + 12), preturn, 4

asmcode(i + 16) = &h8b

asmcode(i + 17) = &h0

end if

asmcode(i + 18) = &h5f

asmcode(i + 19) = &h5e

asmcode(i + 20) = &h5b

asmcode(i + 21) = &h8b: asmcode(i + 22) = &he5

asmcode(i + 23) = &h5d

asmcode(i + 24) = &hc3

getclassprocaddr = varptr(asmcode(0))

end function

private sub timerproc(byval hwnd as long, byval umsg as long, byval idevent as long, byval dwtime as long)

raiseevent timer

'debug.print "類模板中的計時器:", umsg, idevent, dwtime

end sub

'使用option explicit

public withevents timer as clstimer

private sub form_load()

set timer = new clstimer

end sub

private sub form_unload(cancel as integer)

set timer = nothing

end sub

private sub command1_click()

timer.interval = 1000

timer.enabled = true

end sub

private sub command2_click()

timer.enabled = false

end sub

private sub timer_timer()

debug.print "timer 事件"

end sub

Arduino 禁止中斷之後,如何使用計時器

在arduino裡,關閉中斷是為了更好的完成當前任務。但是如果當前任務裡需要計時器怎麼辦?我的處理辦法是 關閉中斷以後,沒有了millis 但是還有micros 只不過micros 被復位0,並且只能在0 2000之內迴圈 2毫秒 所以我們在關閉之前必須處理好micros 的環境準備,比如某些與mi...

15電氣 齊振昊 實驗名稱 在VB中製作計時器

實驗名稱 在 vb中製作計時器 實驗步驟 在桌面中雙擊 vb6.0 開啟程式。在工具箱視窗找到計時器 timer 的圖示,單擊圖示並在窗體中建立計時器。在窗體中雙擊計時器圖示,在彈出的對話方塊中輸入 螢幕 1.caption time 然後關閉視窗。選定計時器 timer 在屬性視窗中找到 inte...

UWP 在XAML設計器中使用設計時資料

1.功能解釋 有些布局沒有資料很難進行視覺化。在本文件中,我們將審查從事桌面專案的開發人員可在 xaml 設計器中模擬資料的一種方法。此方法是使用現有可忽略的 d 命名空間來實現的。利用這種方法,可快速將設計時資料新增到頁面或控制項中,而無需建立完整的模擬檢視模型,或者只需測試屬性更改會如何影響應用...