Loading a Movie File

To load a movie file, send the MCI_OPEN command message to the MCI Movie Driver using the mciSendCommand function. Because the MCI Movie Driver is a compound device (one that can handle multiple instances), you must set the MCI_OPEN_ELEMENT flag in the dwParam1 parameter of mciSendCommand.

The MCI_OPEN command starts a Movie Player instance and loads the movie file. The playback window is hidden until you send an MCI_PLAY or MCI_WINDOW command message to the driver. When the movie is open, the current position is the first frame. There can be up to eight movie files open simultaneously.

The device name on compound devices like the MCI Movie Driver is the same as the filename. The MCI Movie Driver is a non-shareable device, so subsequent attempts to open an already open movie file will fail.

In the MCI_ANIM_OPEN_PARMS parameter block that you pass with the MCI_OPEN command, specify the name of the movie file you want to load. You can also specify the following playback options using flags and the fields of the MCI_ANIM_OPEN_PARMS structure:

Option Flag Field

Specify filename MCI_OPEN_ELEMENT lpstrElementName
Specify MCI device type MCI_OPEN_TYPE lpstrDeviceType
Use static colors for playback MCI_ANIM_OPEN_NOSTATIC None
Specify playback-window style MCI_ANIM_OPEN_WS dwStyle
Specify parent-window handle MCI_ANIM_OPEN_PARENT hWndParent

The MCI_ANIM_OPEN_PARMS parameter block is defined as follows:

typedef struct {
    DWORD   dwCallback;                 // Callback function to notify
    WORD    wDeviceID;                  // Device ID returned to user
    WORD    wReserved0;
    LPSTR   lpstrDeviceType;            // Device name from SYSTEM.INI
    LPSTR   lpstrElementName;           // Filename of movie file
    LPSTR   lpstrAlias;                 // Optional device alias
    DWORD   dwStyle;                    // Window styles (WS_CHILD, etc.)
    WORD    hWndParent;                 // Handle of parent window
    WORD    wReserved1;
 } MCI_ANIM_OPEN_PARMS;

The MCI device ID is returned in the wDeviceID field. Subsequent commands to the MCI Movie Driver require the MCI device ID. You should always check the return value of the MCI_OPEN command before using this device ID. A nonzero return value indicates an error occurred in opening the device.

Set the lpstrElementName field to point to a string containing the filename of the movie file. The lpstrDeviceType field is optional if the [mci extensions] section in the WIN.INI file has an entry for .MMM, the standard movie filename extension. By default, this entry is automatically created when Windows with Multimedia is installed.

If you specify a device type, you can use “mmmovie,” the device name of the MCI Movie Driver. To specify the device type, you must also set the MCI_OPEN_TYPE flag in the dwParam1 parameter of mciSendCommand.

To specify window styles for the playback window, set the dwStyle field to any valid combination of window-style flags. By default, the MCI Movie Driver creates a pop-up window with a caption, a thick frame, a system menu, and minimize and maximize boxes. If you fill in the dwStyle field, pass the MCI_ANIM_OPEN_WS flag to the dwParam1 parameter of the mciSendCommand function.

Some window styles require a parent window; if you specify such a style, set the hWndParent field of the MCI_ANIM_OPEN_PARMS structure to a valid window handle, and set the MCI_ANIM_OPEN_PARENT flag in the dwParam1 parameter. If you don't specify a parent window handle, the MCI Movie Driver won't be able to create a playback window, and the MCI_OPEN command will fail.