播放背景音乐 声明: Declare Function MCISendString& Lib ″MMSYSTEM″ (ByVal LPSTRCOMMAND$, ByVal LPSTRRETURNSTR As Any, ByVal WRETURNLEN%, ByVal HCALLBACK%) 开始播放: R% = MCISendString&(″OPEN EXAMPLE.MID TYPE SEQUENCER ALIAS NN″, 0&, 0, 0) R% = MCISendString&(″PLAY NN FROM 0″, 0&, 0, 0) R% = MCISendString&(″CLOSE ANIMATION″, 0&, 0, 0) 停止: R% = MCISendString&(″OPEN EXAMPLE.MID TYPE SEQUENCER ALIAS NN″, 0&, 0, 0) R% = MCISendString&(″STOP NN″, 0&, 0, 0) R% = MCISendString&(″CLOSE ANIMATION″, 0&, 0, 0) 其中EXAMPLE.MID 为播放的文件,NN为自定义名称标志。
'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
'这是我去年给自己写的五子棋添加的背景音乐源代码:'声明部分 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'代码部分 Private Sub Form_Load() mciSendString "open D:\WZQ\mp3.mid alias myMIDI", vbNullString, 0, 0 mciSendString "play myMIDI", vbNullString, 0, 0 End Sub
' (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
给我EMAIL:
我给你一个控件吧,原是我打包好专门为播放背景音乐而做的...
[email protected]
注明:背景音乐
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'代码部分
Private Sub Form_Load()
mciSendString "open D:\WZQ\mp3.mid alias myMIDI", vbNullString, 0, 0
mciSendString "play myMIDI", vbNullString, 0, 0
End Sub
偶想 直接生成 单个 exe文件 关键是要生成 单个的exe 文件 ,作为资源导入,如何读取?请高人解答