Using Notify and Wait Flags

Normally, MCI commands return to the user immediately, even if it takes several minutes to complete the action initiated by the command. For example, after a VCR device receives a rewind command, the command returns when the tape starts to rewind and it does not wait for the tape to finish rewinding. You can use either of the following required MCI flags to modify this default behavior:

Flag Description

notify Directs the device to post an MM_MCINOTIFY message to a specified window when the requested action is complete.
wait Directs the device to wait until the requested action is complete before returning to the application.

Using the Notify Flag

The notify flag directs the device to post an MM_MCINOTIFY message when the device completes an action. Your application must have a window procedure to process the MM_MCINOTIFY message for notification to have any effect. The Programmer's Workbook includes examples of window procedures that process the MM_MCINOTIFY message.

While the results of a notification are application dependant, the application's window procedure can act upon four possible conditions associated with the notify message:

The notification will occur when the notification conditions are satisfied.

The notification can be superseded.

The notification can be aborted.

The notification can fail.

A successful notification occurs when the conditions required for initiating the callback are satisfied and the command completed without interruption.

A notification is superseded when the device has a notification pending and you send it another notify request. When a notification is superseded, MCI resets the callback conditions to correspond to the notify request of the new command.

A notification is aborted when you send a new command that prevents the callback conditions set by a previous command from being satisfied. For example, sending the stop command cancels a notification pending for the “play to 500 notify” command. If your command interrupts a command that has a notification pending, and your command also requests notification, MCI will abort the first notification immediately and respond to the second notification normally.

A notification fails if a device error occurs while a device is executing the MCI command. For example, a notification fails when a hardware error occurs during a play command.

Using the Wait Flag and Break Command

When a command uses the wait flag, MCI returns control to the calling application when the target device completes the command. You can cancel a wait operation by pressing a break key. By default, MCI defines this key as CTRL+BREAK. (You can redefine this key with the break command.) When you cancel the wait operation, if possible, MCI returns control to the application and 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.