MM_MCINOTIFY Message

Platforms

Description & Usage

A window receives the MM_MCINOTIFY message in response to the completion of a MCI device's action when the "notify" option is used. This tells the window that the MCI command has finished, whether because of success, failure, or some other event. The MM_MCINOTIFY message is only sent when the "notify" option was originally specified.

Return Value

The MM_MCINOTIFY message should return 0.

Visual Basic-Specific Issues

None.

Parameters

wParam
One of the following flags specifying the result of the original MCI command:
MCI_NOTIFY_ABORTED
The MCI device aborted execution of the command.
MCI_NOTIFY_FAILURE
An error occured while executing the command.
MCI_NOTIFY_SUCCESSFUL
The MCI device successfully executed the command.
MCI_NOTIFY_SUPERSEDED
Another command for the MCI device requested notification, so the window will not receive any notification when the command actually finishes.
lParam
The identifier of the MCI device that sent thge message.

Constant Definitions

Const MM_MCINOTIFY = &H3B9
Const MCI_NOTIFY_ABORTED = &H4
Const MCI_NOTIFY_FAILURE = &H8
Const MCI_NOTIFY_SUCCESSFUL = &H1
Const MCI_NOTIFY_SUPERSEDED = &H2

Example

' This code is licensed according to the terms and conditions listed here.

' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal _
	lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength _
	As Long, ByVal hwndCallback As Long) As Long
Public Const MM_MCINOTIFY = &H3B9
Public Const MCI_NOTIFY_ABORTED = &H4
Public Const MCI_NOTIFY_FAILURE = &H8
Public Const MCI_NOTIFY_SUCCESSFUL = &H1
Public Const MCI_NOTIFY_SUPERSEDED = &H2
Public Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal _
	lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, _
	ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hWnd _
	As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC = (-4)

' When the user pushes button Command1, begin playing a MIDI file.  Do not wait
' for the music to finish, but display a simple message prompt when the end of
' the MIDI file has been reached.  Do this by using the "notify" option of the "play"
' MCI command.  Make sure the device is closed before quitting.

' *** Place the following code inside a module. ***

' Pointer to window Form1's previous window procedure.
Public pOldProc As Long

' Custom window procedure for Form1.
Public Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, _
		ByVal lParam As Long) As Long
	Dim mbtext As String  ' text of message box
	Dim retval As Long    ' return value
	
	' If the notification message is received, tell the user how
	' the playback of the MIDI file concluded.
	Select Case uMsg
	Case MM_MCINOTIFY
		Select Case wParam
		Case MCI_NOTIFY_ABORTED
			mbtext = "Playback of the MIDI file was somehow aborted."
		Case MCI_NOTIFY_FAILURE
			mbtext = "An error occured while playing the MIDI file."
		Case MCI_NOTIFY_SUCCESSFUL
			mbtext = "Playback of the MIDI file concluded successfully."
		Case MCI_NOTIFY_SUPERSEDED
			mbtext = "Another command requested notification from this device."
		End Select
		retval = MsgBox(mbtext, vbOkOnly Or vbInformation)
		WindowProc = 0
	Case Else
		retval = CallWindowProc(pOldProc, hWnd, uMsg, wParam, lParam)
	End Select
End Function

' *** Place the following code inside Form1. ***

Private Sub Command1_Click()
	' Open and start playing a MIDI file.  Have the device notify Form1 once
	' playback has ended.
	Dim retval As Long  ' return value
	
	retval = mciSendString("open C:\Music\song.mid alias music", "", 0, 0)
	retval = mciSendString("play music notify", "", 0, Form1.hWnd)
End Sub

Private Sub Form1_Load()
	' Set up the custom window procedure for use with Form1.
	pOldProc = SetWindowLong(Form1.hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Private Sub Form1_Unload(Cancel As Integer)
	Dim retval As Long  ' return value
	
	' Make sure that the MIDI file is closed.
	retval = mciSendString("close music", "", 0, 0)
	' Restore Form1's original window procedure.
	retval = SetWindowLong(Form1.hWnd, GWL_WNDPROC, pOldProc)
End Sub

Category

Media Control Interface (MCI)

Back to the Function list.
Back to the Reference section.


Last Modified: July 4, 2000
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/m/mm_mcinotify.html