Microsoft KB Archive/171980: Difference between revisions
(importing KB archive) |
m (Text replacement - """ to """) |
||
Line 72: | Line 72: | ||
ret = mciSendString( _ | ret = mciSendString( _ | ||
"open " & Song & " type sequencer alias canyon", _ | |||
0&, 0, 0) | 0&, 0, 0) | ||
Line 78: | Line 78: | ||
' control to the application. | ' control to the application. | ||
ret = mciSendString( | ret = mciSendString("play canyon wait", 0&, 0, 0) | ||
' Close CANYON.MID file and sequencer device | ' Close CANYON.MID file and sequencer device | ||
ret = mciSendString( | ret = mciSendString("close canyon", 0&, 0, 0) | ||
End Sub | End Sub | ||
Line 88: | Line 88: | ||
</pre></li> | </pre></li> | ||
<li><p>Add the following code to the General Declarations section of Form1.</p> | <li><p>Add the following code to the General Declarations section of Form1.</p> | ||
<pre class="codesample"> Private Declare Function mciSendString Lib | <pre class="codesample"> Private Declare Function mciSendString Lib "winmm.dll" Alias _ | ||
"mciSendStringA" (ByVal lpstrCommand As String, ByVal _ | |||
lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal _ | lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal _ | ||
hwndCallback As Long) As Long | hwndCallback As Long) As Long | ||
' Modify the value of the constant | ' Modify the value of the constant "Song" with your path | ||
' to | ' to "canyon.mid". | ||
Private Const Song As String = | Private Const Song As String = "C:\Windows\Media\Canyon.MID" | ||
</pre></li> | </pre></li> |
Revision as of 11:05, 21 July 2020
Article ID: 171980
Article Last Modified on 7/1/2004
APPLIES TO
- Microsoft Visual Basic 6.0 Learning Edition
- Microsoft Visual Basic 6.0 Professional Edition
- Microsoft Visual Basic 6.0 Enterprise Edition
- Microsoft Visual Basic 5.0 Control Creation Edition
- Microsoft Visual Basic 5.0 Learning Edition
- Microsoft Visual Basic 5.0 Professional Edition
- Microsoft Visual Basic 5.0 Enterprise Edition
This article was previously published under Q171980
SUMMARY
This article demonstrates how to play a MIDI (.MID) file from Visual Basic using the WIN 32 API call named mciSendString.
NOTE: You can use the MCI control to play a MIDI file; you don't need to use the APIs.
MORE INFORMATION
Step-by-Step Example
- Start Visual Basic, or if Visual Basic is already running, click New Standard EXE Project on the File menu (ALT, F, N). Form1 is created by default.
- Add a CommandButton (Command1) to Form1.
Add the following code to the Command1_Click event of Form1:
Private Sub Command1_Click() Dim ret As Integer ' The following will open the sequencer with the CANYON.MID ' file. Canyon is the device_id. ret = mciSendString( _ "open " & Song & " type sequencer alias canyon", _ 0&, 0, 0) ' The wait tells the MCI command to complete before returning ' control to the application. ret = mciSendString("play canyon wait", 0&, 0, 0) ' Close CANYON.MID file and sequencer device ret = mciSendString("close canyon", 0&, 0, 0) End Sub
Add the following code to the General Declarations section of Form1.
Private Declare Function mciSendString Lib "winmm.dll" Alias _ "mciSendStringA" (ByVal lpstrCommand As String, ByVal _ lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal _ hwndCallback As Long) As Long ' Modify the value of the constant "Song" with your path ' to "canyon.mid". Private Const Song As String = "C:\Windows\Media\Canyon.MID"
- On the Run menu, click Start (ALT, R, S) or press the F5 key to run the program.
REFERENCES
Microsoft Developer Network Library, Platform SDK, Reference, Multimedia Commands.
For additional information about playing MIDI files using API calls from Visual Basic 4.0, please see the following article in the Microsoft Knowledge Base:
141756 : How To Play MIDI Files Using API Calls from Visual Basic
Additional query words: kbVBp kbdsd kbDSupport kbVBp500 kbVBp600 KBAPI
Keywords: kbhowto KB171980