77.2.6 Using the Wait and Notify Flags

Normally, MCI returns control immediately to the application, even if it takes several seconds to complete the action initiated by the command. For example, after a CD audio device receives a seek command, control returns to the application before the seek operation is complete. You can use the following two flags to request that MCI wait until a command is complete before returning control to the application or that MCI notify the application when the command is complete:

Flag Description

MCI_NOTIFY Directs the device to return control immediately and post the MM_MCINOTIFY message when the requested action is complete.
MCI_WAIT Directs the device to wait until the requested action is complete before returning control to the application.

77.2.6.1 Using the Notify Flag

The MCI_NOTIFY flag directs MCI to post the MM_MCINOTIFY message when the device completes an action. The application specifies the handle to the destination window for the message in the low-order word of the dwCallBack field of the data structure sent with the command message. Every data structure associated with a command message contains this field.

Note:

MCI can have only one pending notification message for each device.

When MCI posts the MM_MCINOTIFY message, it sets the low-order word of lParam parameter of the window procedure to the ID of the device initiating the callback. The wParam parameter of the window procedure contains one of the following constants specifying the notification status of the callback:

Flag Description

MCI_NOTIFY_SUCCESSFUL Indicates the conditions required for initiating the callback are satisfied and the command completed without interruption.
MCI_NOTIFY_SUPERSEDED Indicates MCI had a notification pending and received another notify request. MCI resets the callback conditions to correspond to the notify request of the new command.
MCI_NOTIFY_ABORTED Indicates the application sent a new command that prevented the callback conditions set by a previous command from being satisfied. If an application interrupts a command that requested notification, MCI will not inform the window procedure of the notify command being aborted.
MCI_NOTIFY_FAILURE Indicates a device error occurred while a device was executing the command. For example, MCI posts this message when a hardware error occurs during a play command.

77.2.6.2 Using the Wait Flag and Break Command Message

Specifying the MCI_WAIT flag with a command causes MCI to wait until the command has completed before returning control to the application. Using the wait flag with commands that take a long time to complete will essentially disable a system from receiving any user input until the command is complete.

MCI supports a break key to interrupt the wait operation and return control to the application. The break key does not interrupt the command, but by returning control to the application, allows the application to monitor user input.

By default, MCI defines the break key as CTRL+BREAK. Applications can redefine this key with the MCI_BREAK command. MCI_BREAK uses the MCI_BREAK_PARMS parameter block:

typedef struct {

DWORD dwCallback; /* callback for MCI_NOTIFY */

int nVirtKey; /* virtual key code */

UINT wReserved0; /* reserved */

HWND hwndBreak; /* window handle */

UINT wReserved1; /* reserved */

} MCI_BREAK_PARMS;

The following flags validate fields in the MCI_BREAK_PARMS parameter block:

Flag Description

MCI_BREAK_KEY Validates the nVirtKey field specifying the virtual-key code to be used for the break key.
MCI_BREAK_HWND Validates the hwndBreak field specifying the window that must have focus to enable break detection.
MCI_BREAK_OFF Disables any existing break key.