Windows provides a mciwnd window class to facilitate multimedia operations in a VC window.
When mciwnd is used, the source file must contain the header file VFW. H. In project> Settings> link> Object/libray module, add vfw32.lib to the database.
1. Create mciwnd
The mciwnd subwindow can be created using the mciwndcreate function:
Hwnd mciwndcreate (
Hwnd hwndparent, // parent window handle
Hinstance, // application instance handle
DWORD dwstyle, // display style
Lpstr szfile // multimedia file name
);
The returned hwnd can be saved for future use or not.
This function creates a subwindow in its parent window, similar to creating a console, such as a button or a list box.
This subwindow occupies a certain space in the parent window and can contain playback buttons, progress bars, and menu buttons.
Figure 3.3.1 mciwnd subwindow
Example:
(1) Create an MFC application with multiple documents.
(2) Add a variable to the header file of the View class:
Hwnd m_mciwnd;
(3) Use classwizard to reload the oninitialupdate function in the View class.
(4) Add the code to this function:
M_mciwnd = mciwndcreate (m_hwnd, AfxGetInstanceHandle (), mciwndf_showall | mciwndf_record, getdocument ()-> getpathname ());
Here, m_hwnd is the hwnd of this view window,
AfxGetInstanceHandle () can obtain the instance handle of this application,
Mciwndf_flag determines whether to add the play button, recording button, menu button, progress bar, and other controls to the subwindow,
Getdocument ()-> getpathname () can get the file name obtained by opening the file dialog box.
(5) Compile and run the program.
(6) you can open a multimedia file in a running program for playback. For example,. wav,. Avi, And. mid files.
2. Use of mciwnd
If the mciwnd subwindow contains controls such as play button, recording button, menu button, and progress bar, you can use them to operate multimedia.
If the hwnd returned by the mciwndcreate function is saved as in the preceding example, you can use the mciwndxxxx function to operate multimedia without controls in the window.
(7) Add a menu item or toolbar button with the ID id_new, id_open, id_play, id_playreverse, id_record, id_save, id_stop, and id_close in the above program.
(8) add the following to the Message response function of id_new:
Mciwndnew (m_mciwnd, "waveaudio ");
The mciwnd subwindow can create a new audio multimedia file.
(9) add the following to the Message response function of id_open:
Mciwndopen (m_mciwnd, "C: \ mywav.wav", 0 );
The mciwnd subwindow can open an existing multimedia file.
(10) add the following to the Message response function of id_play:
Mciwndplay (m_mciwnd );
The mciwnd subwindow can play multimedia files.
(11) add the following to the Message response function of id_playreverse:
Mciwndplayreverse (m_mciwnd );
The mciwnd sub-window can play back the video multimedia files.
(12) add the following to the Message response function of id_record:
Mciwndrecord (m_mciwnd );
The mciwnd subwindow can be used to record audio and multimedia files.
(13) add the following to the Message response function of id_save:
Mciwndsave (m_mciwnd, "C: \ mywav.wav ");
The mciwnd subwindow can save the recorded audio and multimedia files.
(14) add the following to the Message response function of id_stop:
Mciwndstop (m_mciwnd );
In the mciwnd subwindow, you can stop multimedia files that are being played or recorded.
(15) add the following to the Message response function of id_close:
Mciwndclose (m_mciwnd );
The mciwnd subwindow can close the current multimedia file. To use it again, you must open it again.
(16) Compile and run the program.
//////////////////////////////////////// //////////////////////////////////////// ///////////////
How to respond to messages:
Use the mciwndf_policymode attribute when creating a playback window.
Then perform a message ing.
On_message (mciwndm_policymode, onmcinotify)
Then, in the onmcinotify () function, determine whether to receive the stop message (the message will be received after broadcasting) and play the next one.
The related code is as follows:
. H
Afx_msg void onmcinotify (wparam, lparam );
. Cpp
On_message (mciwndm_policymode, onmcinotify)
Bool myvideodlg: oninitdialog ()
{
......
M_hwndvideo = mciwndcreate (
This-> getsafehwnd (),
AfxGetInstanceHandle (),
Ws_child | ws_visible | ws_border |
Mciwndf_noplaybar |
Mciwndf_nomenu | mciwndf_policymode,
M_sfilename.getbuffer (10 ));
Mciwndplay (m_hwndvideo );
......
}
Void myvideodlg: onmcinotify (wparam, lparam)
{
If (lparam = mci_mode_stop)
{
Play next
}
}
//////////////////////////////////////// //////////////////////////////////////// ///////////////
MCi (media control interface) Knowledge
Media control interface (MCI) media control interface is a set of standard interfaces for multimedia devices and files provided by Mircrosoft, its advantage is that it can easily control the vast majority of multimedia devices, including audio, video, album, video and other multimedia devices, without the need to know their internal working conditions. But the ancient saying goes: success and failure. Although it seems to be a great deal, it is far from enough for some advanced applications.
Control Mode of MCI:
Generally, programmers can use two functions to deal with MCI:
Mcierror mcisendcommand (mcideviceid wdeviceid, uint umsg, DWORD dwflags, DWORD dwparam );
The command string method sends control commands in a way similar to everyday terms. It is suitable for advanced programming, such as VB and Toolbook.
Mcierror mcisendstring (lpctstr lpszcommand, lptstr lpszreturnstring, uint cchreturn, handle hwndcallback );
The command message method uses professional syntax to send control messages. It is applicable to programming in VC and other languages. This method is used to directly deal with the MCI device.
For mcisendcommand, the first parameter specifies the device identifier, which will be provided by the system when the programmer opens the MCI device. The second parameter specifies how to control the device. For details, refer to the "MCI command" column. The third parameter is the access identifier, and the fourth parameter is generally a data structure, which identifies some information required by the program to access the MCI. For more information, see the CD.
For mcisendstring, the first parameter is a control string. The system fills in the returned information with the second parameter. The third parameter specifies the maximum length of the returned information, if the "Y" flag is set for the MCI device, enter the fourth parameter to return the window handle.
Example:
Mcisendcommand (DeviceID, mci_close, null, null); // closes an MCI device.
Mcisendstring ("Open AAA. Avi", 0, 0, 0); // open the file "AAA. Avi"
The device type of MCI:
Device description string description
Mci_all_device_id all devices
Mci_devtype_animationanimation animation Device
Mci_devtype_cd_audiocdaudiocd audio
Mci_devtype_datdat Digital Audio
Mci_devtype_digital_videodigitalvideo Digital Video
Mci_devtype_otherother undefined Device
Mci_devtype_overlayoverlay overlapping video
Mci_devtype_scanner.pdf Scanner
Mci_devtype_sequencersequencer MIDI sequencer
Mci_devtype_vcrvcr video recorder
Mci_devtype_videodiscvideodisc laser disk
Mci_devtype_waveform_audiowaveaudio wave audio
For an MCI device that is not defined above, you can view the [MCI] section in the system. ini file, for example:
[MCI]
Cdaudio = mcicda. DRV
Sequencer = mciseq. DRV
Waveaudio = mciwave. DRV
Avivideo = mciavi. DRV
Videodisc = mcipionr. DRV
VCR = mcivisca. DRV
Activemovie = mciqtz. DRV
Qtwvideo = mciqtw. DRV
Mpegvideo = c: \ progra ~ 1 \ Xing \ xingmp ~ 1 \ xmdrv95.dll
The last two sentences respectively indicate Apple's QuickTime device, which is named "qtwvidio" and MPEG image device, and the device name is "mpegvideo ".
//------------------------------
// Ad time:
// Welcome to C ++ builder research-http://www.ccrun.com
//------------------------------
In MCI Programming, you can either describe a device as a device name or describe a string as a device name. One extreme lazy way is that programmers do not specify a device name in the program, windows automatically identifies the device type based on the file extension.
For example, there are three methods to open a multimedia file:
[1]: Automatic Identification: open a "WAV" File
Mci_open_parms mciopen;
Mciopen. lpstrdevicetype = 0;
Mciopen. lpstrelementname = "aaa.wav ";
Mcisendcommand (null, mci_open, mci_open_element, (DWORD) & mciopen );
[2]: Specify the device Description: enable the CD player.
Mci_open_parms mciopen;
Mciopen. lpstrdevicetype = (lpstr) mci_devtype_cd_audio;
Mcisendcommand (null, mci_open, mci_open_type | mci_open_type_id, (DWORD) & mciopen );
[3]: Specify the description string: open an AVI file
Mci_open_parms mciopen;
Mciopen. lpstrdevicetype = "avivideo ";
Mciopen. lpstrelementname = "AAA. Avi ";
Mcisendcommand (null, mci_open, mci_open_type | mci_open_element, (DWORD) & mciopen );
Note the difference between the third parameter of the function in the three open methods, which will be discussed later.
MCI command
Mci_break: Specifies the interrupt key. The default value is Ctrl + break"
Mci_capture captures the current frame and saves it to a specified file. It is only used for digital videos.
Mci_close
The mci_configure pop-up configuration dialog box is only used for digital videos.
Mci_copy copy data to clipboard
Mci_cue delayed playback or recording
Mci_cut delete data
Mci_delete delete data
Mci_escape is only used for laser videos
Mci_freeze will show frozen
Mci_getdevcaps: Get device information
Whether or not mci_index is displayed on the current screen. It is only used for VCR devices.
Mci_info
Mci_list: gets the number of input devices. It supports digital videos and VCR devices.
Mci_load load a file
Mci_mark cancels or makes a mark to match mci_seek
Mci_mark cancels or makes a mark to match mci_seek
Mci_monitor specifies a report device for a digital video
Mci_open open the device
Mci_paste paste data
Mci_pause: Pause the current action
Mci_play
Mci_put: Set the source, destination, and border rectangle.
Mci_quality defines the default Device Quality
Mci_record start recording
Mci_reserve allocating hard disk space
Mci_restore: copy a BMP file to the frame buffer.
Mci_resume enables a paused device to restart
Mci_save save data
Mci_seek
Mci_set
Mci_setaudio
Mci_settimecode enable or cancel the time code of the VCR Device
Mci_settuner: set vcr device channels
Mci_setvideo
Mci_signal: Set the specified space in the Workspace
Mci_status
Mci_step enables the playback device to frame
Mci_stop
Mci_sysinfo
Mci_undo cancel Operation
Mci_unfreeze restores motion using the mci_unfreeze video buffer
Mci_update: update the display area
Mci_where: Get the trim rectangle of the device.
Mci_window specifies the window and window features of a graphic device.
Commonly used Commands include mci_open, mci_close, mci_play, mci_stop, mci_pause, and mci_status.