| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
买学问 - 大牛一对一辅导,有问必答买学问 - 专业的付费知识问答平台
共有 685 人关注过本帖
标题:谁给写一个中断定时50ms精确地程序
只看楼主 加入收藏
chen3bing
Rank: 2
等 级:论坛游民
帖 子:289
专家分:99
注 册:2008-11-12
结帖率:90.59%
  已结贴   问题点数:10  回复次数:15   
谁给写一个中断定时50ms精确地程序
谁给写一个中断定时50ms精确地程序,谢谢!
2019-01-06 15:19
chen3bing
Rank: 2
等 级:论坛游民
帖 子:289
专家分:99
注 册:2008-11-12
  得分:0 
我不会用多媒体定时器,谁教教我
2019-01-06 15:55
chen3bing
Rank: 2
等 级:论坛游民
帖 子:289
专家分:99
注 册:2008-11-12
  得分:0 
用API方式定时举个例子
2019-01-06 16:07
wds1
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:36
帖 子:347
专家分:1840
注 册:2016-3-10
  得分:2 
'延时调用函数
Public Declare Function timeGetTime Lib "winmm.dll" () As Long

call sleep(50)'相当于延时50ms


Public Sub sleep(seconds As Integer)
Dim temp As Variant
temp = timeGetTime
  While timeGetTime - seconds < temp
  DoEvents
  Wend
End Sub
2019-01-06 16:54
wds1
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:36
帖 子:347
专家分:1840
注 册:2016-3-10
  得分:2 
类模块程序
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long

Public Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
    Form1.Print Now()
    DoEvents
End Sub

窗体程序
Public ID1
Dim bz1 As Boolean

Private Sub Form_Load()
    bz1 = False
   Command1.Caption = "定时开始"
End Sub

Private Sub Command1_Click()
    If bz1 = False Then
        '每50ms调用一次函数
        ID1 = SetTimer(0, 0, 50, AddressOf TimerProc)
        bz1 = True
        Command1.Caption = "定时结束"
    Else
        KillTimer 0, ID1
        bz1 = False
        Command1.Caption = "定时开始"
    End If
End Sub

2019-01-06 22:43
chen3bing
Rank: 2
等 级:论坛游民
帖 子:289
专家分:99
注 册:2008-11-12
  得分:0 
回复 5楼 wds1
谢谢!类模块程序有错误
附件: 您没有浏览附件的权限,请 登录注册
2019-01-07 08:40
chen3bing
Rank: 2
等 级:论坛游民
帖 子:289
专家分:99
注 册:2008-11-12
  得分:0 

只有16次,貌似定时不准。
附件: 您没有浏览附件的权限,请 登录注册
2019-01-07 09:00
wds1
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:36
帖 子:347
专家分:1840
注 册:2016-3-10
  得分:2 
用这个吧
mmTimer.ctl
2019-01-07 11:23
chen3bing
Rank: 2
等 级:论坛游民
帖 子:289
专家分:99
注 册:2008-11-12
  得分:0 
回复 8楼 wds1
谢谢,mmt出来了,可是我想放到窗体上,提示错误
附件: 您没有浏览附件的权限,请 登录注册
2019-01-07 11:34
wds1
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:36
帖 子:347
专家分:1840
注 册:2016-3-10
  得分:2 


Private Sub CmdStart_Click()
        mmTimer1.Init 50
        Timer1.Interval = 50
        Timer1.Enabled = True
End Sub

Private Sub CmdStop_Click()
        mmTimer1.Destroy
        Timer1.Enabled = False
End Sub


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        Static cnt As Long
        cnt = cnt + 1
        Text1.Text = cnt
End Sub


Private Sub mmTimer1_Timer()
        Static cnt As Long
        frmMain.Print Now()
        cnt = cnt + 1
        Text1.Text = cnt
End Sub

Private Sub Timer1_Timer()
        Static cnt As Long
        cnt = cnt + 1
        Text2.Text = cnt
End Sub
附件: 您没有浏览附件的权限,请 登录注册
2019-01-07 11:40







关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038289 second(s), 8 queries.
Copyright©2004-2019, BCCN.NET, All Rights Reserved