如何循环播放MIDI音乐?必须使用TIMER控件吗?

wiw 2003-05-16 03:38:30
??
...全文
54 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lihonggen0 2003-05-16
  • 打赏
  • 举报
回复
http://www.china-askpro.com/msg35/qa50.shtml
lihonggen0 2003-05-16
  • 打赏
  • 举报
回复
http://www.cad.zju.edu.cn/chinagraph/chinese/specialtopic/virtualreality/vbuse.htm
lihonggen0 2003-05-16
  • 打赏
  • 举报
回复
播放MIDI音乐


'This project needs a Common Dialog box, named 'CDBox'
' (To add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T)
' and select Microsoft Common Dialog control)
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Dim Alias As String
Private Sub Form_Load()

Const PlayTime = 10
'Set the common dialog box' title
CDBox.DialogTitle = "Choose your midi-file"
'Set the filter
CDBox.Filter = "Midi-files (*.mid)|*.mid"
'Show the 'Open File'-dialog
CDBox.ShowOpen
'Extract an alias from the file
Alias = Left$(CDBox.FileTitle, Len(CDBox.FileTitle) - 4)

'play midi
R% = mciSendString("OPEN " + CDBox.filename + " TYPE SEQUENCER ALIAS " + Alias, 0&, 0, 0)
R% = mciSendString("PLAY " + Alias + " FROM 0", 0&, 0, 0)
R% = mciSendString("CLOSE ANIMATION", 0&, 0, 0)

'play midi for 10 secs
t = Timer
Do: DoEvents: Loop Until Timer > t + PlayTime

'stop midi and close it
R% = mciSendString("OPEN " + CDBox.filename + " TYPE SEQUENCER ALIAS " + Alias, 0&, 0, 0)
R% = mciSendString&("STOP " + Alias, 0&, 0, 0)
R% = mciSendString&("CLOSE ANIMATION", 0&, 0, 0)
End Sub

7,764

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧