You can automate playback in your application by using MCIWndCreate and the MCIWndPlay macro, along with either the MCIWndDestroy or the MCIWndClose macro. To automate playback, specify the MCIWNDF_NOPLAYBAR and MCIWNDF_NOTIFYMODE styles in the MCIWndCreate dwStyle parameter. Specify the MCIWNDF_NOPLAYBAR style to hide the toolbar, and the MCIWNDF_NOTIFYMODE style to issue an appropriate notification message when the device stops playing.
You can play the device or file specified in MCIWndCreate by using MCIWndPlay. The MCIWndPlay macro starts playing the content from its current playback position and continues to its end.
You can destroy or close an MCIWnd window by using the MCIWndDestroy or MCIWndClose macro. The MCIWndDestroy macro closes the device or file and destroys the MCIWnd window by invalidating its handle. If your application can reuse the MCIWnd window, use MCIWndClose to close the device without destroying the window.
Your application can detect when the device stops playing and automatically close the window. To do this, specify the MCIWNDF_NOTIFYMODE style for the dwStyle parameter of MCIWndCreate. This causes the device to send a MCIWNDM_NOTIFYMODE message whenever it changes modes. Your application can trap this message to determine whether the device has stopped playing. When the device stops playing, the application closes the window.