'在project中加入一个module,然后在其中加入以下代码: option explicit type large_integer lowpart as long highpart as long end type public declare function queryperformancecounter lib "kernel32" _ (lpperformancecount as large_integer) as long public declare function queryperformancefrequency lib "kernel32" _ (lpfrequency as large_integer) as long public declare function timesetevent lib "winmm.dll" (byval udelay as long, byval _ uresolution as long, byval lpfunction as long, byval dwuser as long, _ byval uflags as long) as long public declare function timekillevent lib "winmm.dll" (byval uid as long) as long public declare function gettickcount lib "kernel32" () as long public lmsfreq as long public timercount as single public lmmcount as single public ltimeid as long public acttime1 as long public acttime2 as long public icountstart as single dim icount as single '注释: timesetevent的回调函数 sub timeproc(byval uid as long, byval umsg as long, byval dwuser as long, _ byval dw1 as long, byval dw2 as long) form1.text2.text = format$(lmmcount, "00.00") lmmcount = lmmcount - 0.01 if lmmcount <= 0 then icountstart = 60 lmmcount = 60 timercount = 60 endcount end if end sub sub endcount() icount = icountstart icountstart = 0 timekillevent ltimeid acttime2 = gettickcount - acttime1 with form1 .command1.enabled = true .command2.enabled = false .timer1.enabled = false .text1 = "计数器记时" + format$((60 - icount), "00.00") + " " _ + "实际经过时间" + format$((acttime2 / 1000), "00.00") .text2 = "计数器记时" + format$((60 - lmmcount), "00.00") + " " _ + "实际经过时间" + format$((acttime2 / 1000), "00.00") .text3 = "计数器记时" + format$((60 - timercount), "00.00") + " " _ + "实际经过时间" + format$((acttime2 / 1000), "00.00") end with end sub |