Using the Wait and Notify Flags

By default, MCI commands return immediately to the application, even if it takes several minutes to complete the action initiated by the command. For example, after a VCR device receives a rewind command, control returns to the sending application before the tape has finished rewinding. You can use either of the following flags to modify this default action:

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.

Using the Notify Flag

The MCI_NOTIFY flag directs MCI to post the MM_MCINOTIFY message when the device completes an action. Your 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. MCI can have only one notification message active 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 a constant specifying the status of the callback. MCI uses the following constants:

MCI_NOTIFY_SUCCESSFUL

MCI_NOTIFY_SUPERSEDED

MCI_NOTIFY_ABORTED

MCI_NOTIFY_FAILURE

When writing the window procedure, you can use these constants to select the appropriate action for the window procedure. These constants have the following definitions:

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 it received another notify request. When MCI sends this constant, it resets the callback conditions to correspond to the notify request of the new command.

MCI_NOTIFY_ABORTED indicates that your application sent a new command that prevented the callback conditions set by a previous command from being satisfied. For example, the stop command cancels a notification pending for the “play to 500” command. If your application interrupts a command and also requests notification, MCI will send only this message and not inform the window procedure of the notify command being superseded.

MCI_NOTIFY_FAILURE indicates a device error occurred while a device was executing the MCI command. For example, MCI posts this message when a hardware error occurs during a play command.

Using the Wait Flag and Break Command Message

When a command message uses the MCI_WAIT flag, MCI returns control to the calling application when the target device completes the command. The user can cancel a wait operation by pressing a break key. If possible, MCI does not interrupt the command associated with the wait flag. For example, breaking the command “play to 500 wait” cancels the wait operation without interrupting the play operation.

By default, MCI defines the break key as CTRL+BREAK. Your application can redefine this key using the MCI_BREAK command message. This message uses the MCI_BREAK_PARMS data structure. MCI_BREAK has the following flags:

Flag Description

MCI_BREAK_KEY Specifies the virtual-key code to be used for the break key.
MCI_BREAK_HWND Indicates a window handle that must be the current window to enable break detection for a particular MCI device (usually the main window of the application).
MCI_BREAK_OFF Disables any existing break key for a particular device.

To set the break key, set the nVirtKey field of the data structure to the virtual-key code. MCI sets the key when you send this value using the MCI_BREAK_KEY flag.

If you want the break key active only when a particular window has the focus, you can combine the MCI_BREAK_HWND flag with the MCI_BREAK_KEY flag. Specify the window by putting its window handle in the hwndBreak field of the data structure.