Date: 02-16-2022
Return to Index
created by gbSnippets
'The MCISendString API can be used to play MIDI files.
'Primary Code:
'Two examples are given. They differ only in the specifics of the commands.
'Both use the MCISendString API.
'Example#1
'Credit: Danny Faris
'Play
MCISendString "open type midiaudio", ByVal 0, 0, 0
MCISendString "PLAY dust.mid", ByVal 0, 0, 0
'Stop
MCISendString "STOP dust.mid", ByVal 0, 0, 0
MCISendString "CLOSE type midiaudio", ByVal 0, 0, 0
'Example#2
'Credit: Microsoft
'Play
ret = mciSendString( "open dust.mid type sequencer alias dust", ByVal 0, 0, 0)
ret = mciSendString("play dust", ByVal 0, 0, 0) ' "play dust wait"
'Stop
ret = mciSendString("close dust", ByVal 0, 0, 0)
'Note: When a MIDI file has spaces in it, enclose the filename like this:
mcisendstring("open " + $DQ + $MusicFile + $DQ ,AudioDevice,0,0)
'Compilable Example: (Jose Includes)
'Includes both of the examples from above.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"StartA", 50,10,100,20
Control Add Button, hDlg, 200,"StopA", 50,40,100,20
Control Add Button, hDlg, 300,"StartB", 50,70,100,20
Control Add Button, hDlg, 400,"StopB", 50,100,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
MCISendString "open type midiaudio", ByVal 0, 0, 0
MCISendString "PLAY dust.mid", ByVal 0, 0, 0
End If
If CB.Msg = %WM_Command AND CB.Ctl = 200 AND CB.Ctlmsg = %BN_Clicked Then
'To stop the midi AND Free the MIDI out device:
MCISendString "STOP dust.mid", ByVal 0, 0, 0
MCISendString "CLOSE type midiaudio", ByVal 0, 0, 0
End If
If CB.Msg = %WM_Command AND CB.Ctl = 300 AND CB.Ctlmsg = %BN_Clicked Then
'Play
mciSendString( "open dust.mid type sequencer alias dust", ByVal 0, 0, 0)
mciSendString("play dust", ByVal 0, 0, 0) ' "play dust wait"
End If
If CB.Msg = %WM_Command AND CB.Ctl = 400 AND CB.Ctlmsg = %BN_Clicked Then
'Stop
mciSendString("close dust", ByVal 0, 0, 0)
End If
End Function
'gbs_00207
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm