![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
MCI CommandsA program controls multimedia devices by means of MCI commands, a remarkably simple set of commands applicable to all multimedia devices. Although some commands are specific for certain devices, the basic sequence of steps for using a multimedia device usually goes like this:
Lets take a look at some simple MCI commands. To play a WAV fileperhaps CHIMES.WAV, which comes with Windowshere is the first command: Open c:\media\chimes.wav type waveaudio alias chime The Open command opens the desired WAV file, specifies its type (from Table 16.1), so Windows knows which driver to use, and assigns an alias a name you can use in subsequent commands to refer to this device. Opening the device does not actually play the sound. The command for that is: Play chime You use the Play command with the alias assigned to the device. The sound will start playing, and control will pass back to the program. Although CHIMES.WAV is a short sound, you can play longer sounds that continue to play to the end while the program performs other tasks. When you finish with the device, you close it as follows: Close chime The Close command terminates play, so you have to delay its execution until the sound has completed playing. Ill show you how to do this later. The basic MCI commands are listed in Table 16.2, although you will not be exploring them all here. My goal is to show you how to perform the most common multimedia tasks in your Visual Basic program. For more details about multimedia, refer to one of the books published on the topic.
Note that you cannot simply type these commands into Basic code; you have to send them to the MCI. How? Examining the two available methods is the topic for the remainder of this chapter. Sending MCI Commands With mciSendStringOne way to send commands to the MCI is to use the function mciSendString. Not a part of Visual Basic, this function is part of the Windows Applications Programming Interface (API), the huge collection of functions that provides most of Windows capabilities. When a Visual Basic programor one written in any other language, for that matterperforms any operating system-related task, it is actually calling Windows API functions to do the job. When you open a file by writing code in Basic, Visual Basic translates it into the necessary Windows API call to perform the task. Not all API capabilities are included in Visual Basic; but fortunately, when you run into this situation, you can call the API function directlywhich is exactly what you will do here. Before a program can use a Windows API function, you must declare it. The declaration provides the program with certain information about the function, such as its name, the library it is in, and the number and types of its arguments. You can save time by copying API function declarations from the API Text Viewer application (typically installed along with Visual Basic) and pasting them into our code.
Heres the declaration for the mciSendString function: Declare Function mciSendString Lib winmm Alias mciSendStringA _ (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _ ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long This declaration tells you the following:
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this si |