Microsoft KB Archive/99898

= VB3 How to Play MIDI Files Using API Calls from Visual Basic =

Article ID: 99898

Article Last Modified on 11/18/2003

-

APPLIES TO


 * Microsoft Visual Basic 1.0 Standard Edition
 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q99898



SUMMARY
This article demonstrates how to play a MIDI (.MID) file from Visual Basic using Windows version 3.1 APIs.

If you have the Professional Edition of Visual Basic version 2.0 or 3.0, or if you have the Professional Toolkit for Visual Basic version 1.0, you can use the MCI control to play a MIDI file. You don't need to use the APIs



Step by Step to an Application that Plays an .MID file
 Start Visual Basic, or if Visual Basic is already running, choose New Project from the File menu (ALT, F, N). Form1 is created by default. Add a Command Button (Command1) to Form1.  Add the following code to the Command1_Click event of Form1: DIM ret as Integer

'*** The following will open the sequencer with the CANYON.MID '*** file. Canyon is the device_id. Enter the entire statement on one, '*** single line. ret = mciSendString(&quot;open CANYON.MID type sequencer alias canyon&quot;,     0&, 0, 0)

'*** The wait tells the MCI command to complete before returning control '*** to the application. Ret = mciSendString(&quot;play canyon wait&quot;, 0&, 0, 0)

'*** Close CANYON.MID file and sequencer device Ret = mciSendString(&quot;close canyon&quot;, 0&, 0, 0)

  Add the following code to the general declarations section of Form1: ' Enter the following Declare statement on one, single line:

Declare Function mciSendString Lib &quot;mmsystem&quot; (ByVal lpstrCommand$,     ByVal lpstrReturnStr As Any, ByVal wReturnLen%, ByVal hCallBack%) As Long

 From the Run menu, choose Start (ALT, R, S) or press F5 to run the program.

More information about mciSendString can be found in:


 * The MultiMedia Programmer's Reference on page 3-26.
 * Command strings described on pages 7-23 to 7-93 and in the WIN31MWH.HLP file shipped with the Windows 3.1 Software Development Kit (SDK).

Additional query words: 2.00 3.00

Keywords: kbwndw KB99898

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.