The Multimedia MCI control manages the recording and playback of multimedia files on Media Control Interface (MCI) devices. Conceptually, this control is a set of push buttons that issues MCI commands to devices such as audio boards, MIDI sequencers, CD-ROM drives, audio CD players, videodisc players, and videotape recorders and players. The MCI control also supports the playback of Video for Windows (*.avi) files.
The following example demonstrates how to create a registration-free instance of the Microsoft Multimedia MCI Control using my OLE Container (OLECON.INC) to host it.
Registration-free means that you don't need to register the control to be able to use it. To use this registration-free version, you must copy MCI32.OCX in the application folder, as if it was an standard DLL.
For using a registered version of the control, change the following code in the example:
GetClientRect hWnd, rc
cp.clsid = $CLSID_MMControl
cp.riid = $IID_Imci
cp.szLicKey = $RTLKEY_MMControl
cp.szLibName = EXE.Path$ & "mci32.ocx"
hCtl = CreateWindowEx(0, $OC_CLASSNAME, "", _
%WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR %WS_TABSTOP, _
0, 0, rc.nRight - rc.nLeft, rc.nBottom - rc.nTop, _
hWnd, %IDC_MCI, GetModuleHandle(BYVAL %NULL), cp)
to:
' Create an instance of the control
hCtl = CreateWindowEx(0, $OC_CLASSNAME, _
"MCI.MMControl.1;RTLKEY:" & $RTLKEY_MMControl, _
%WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP, 0, 0, 0, 0, _
hWnd, %IDC_MCI, GetModuleHandle(BYVAL %NULL), BYVAL %NULL)
Full example code (SDK version)
' ########################################################################################
' Creates an instance of a MCI control and opens a .wav file.
' ########################################################################################
#COMPILE EXE
#DIM ALL
#INCLUDE ONCE "OLECON.INC"
#INCLUDE ONCE "MCI32.INC"
%IDC_MCI = 101
' ========================================================================================
' Main
' ========================================================================================
FUNCTION WINMAIN (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG
LOCAL hWndMain AS DWORD
LOCAL hFont AS DWORD
LOCAL wcex AS WNDCLASSEX
LOCAL szClassName AS ASCIIZ * 80
LOCAL rc AS RECT
LOCAL szCaption AS ASCIIZ * 255
LOCAL nLeft AS LONG
LOCAL nTop AS LONG
LOCAL nWidth AS LONG
LOCAL nHeight AS LONG
OC_WinInit ' // Initialize the Ole Container
hFont = GetStockObject(%ANSI_VAR_FONT)
' Register the window class
szClassName = "MCIControl"
wcex.cbSize = SIZEOF(wcex)
wcex.style = 0 '%CS_HREDRAW OR %CS_VREDRAW
wcex.lpfnWndProc = CODEPTR(WndProc)
wcex.cbClsExtra = 0
wcex.cbWndExtra = 0
wcex.hInstance = hInstance
wcex.hCursor = LoadCursor (%NULL, BYVAL %IDC_ARROW)
wcex.hbrBackground = %COLOR_3DFACE + 1
wcex.lpszMenuName = %NULL
wcex.lpszClassName = VARPTR(szClassName)
wcex.hIcon = LoadIcon (%NULL, BYVAL %IDI_APPLICATION) ' Sample, if resource icon: LoadIcon(hInst, "APPICON")
wcex.hIconSm = LoadIcon (%NULL, BYVAL %IDI_APPLICATION) ' Remember to set small icon too..
RegisterClassEx wcex
' Window caption
szCaption = "Multimedia MCI Control Example"
' Retrieve the size of the working area
SystemParametersInfo %SPI_GETWORKAREA, 0, BYVAL VARPTR(rc), 0
' Calculate the position and size of the window
nWidth = (((rc.nRight - rc.nLeft)) + 2) * 0.50 ' 55% of the client screen width
nHeight = (((rc.nBottom - rc.nTop)) + 2) * 0.15 ' 15% of the client screen height
nLeft = ((rc.nRight - rc.nLeft) \ 2) - nWidth \ 2
nTop = ((rc.nBottom - rc.nTop) \ 2) - (nHeight \ 2)
' Create a window using the registered class
hWndMain = CreateWindowEx(%WS_EX_CONTROLPARENT, _ ' extended style
szClassName, _ ' window class name
szCaption, _ ' window caption
%WS_OVERLAPPEDWINDOW OR _
%WS_CLIPCHILDREN, _ ' window style
nLeft, _ ' initial x position
nTop, _ ' initial y position
nWidth, _ ' initial x size
nHeight, _ ' initial y size
%NULL, _ ' parent window handle
0, _ ' window menu handle
hInstance, _ ' program instance handle
BYVAL %NULL) ' creation parameters
' Show the window
ShowWindow hWndMain, nCmdShow
UpdateWindow hWndMain
' Message handler loop
LOCAL uMsg AS tagMsg
WHILE GetMessage(uMsg, %NULL, 0, 0)
' This control doesn't support message forwarding
' IF ISFALSE OC_ForwardMessage(GetFocus, uMsg) THEN
IF IsDialogMessage(hWndMain, uMsg) = 0 THEN
TranslateMessage uMsg
DispatchMessage uMsg
' END IF
END IF
WEND
FUNCTION = uMsg.wParam
END FUNCTION
' ========================================================================================
' ========================================================================================
' Main Window procedure
' ========================================================================================
FUNCTION WndProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
LOCAL hr AS LONG
LOCAL hCtl AS DWORD
LOCAL rc AS RECT
LOCAL pMci AS IMci
LOCAL cp AS OC_CREATEPARAMS
STATIC pMciEvents AS DmciEventsImpl
SELECT CASE wMsg
CASE %WM_CREATE
' Create an instance of the MMControl
GetClientRect hWnd, rc
cp.clsid = $CLSID_MMControl
cp.riid = $IID_Imci
cp.szLicKey = $RTLKEY_MMControl
cp.szLibName = EXE.Path$ & "mci32.ocx"
hCtl = CreateWindowEx(0, $OC_CLASSNAME, "", _
%WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR %WS_TABSTOP, _
0, 0, rc.nRight - rc.nLeft, rc.nBottom - rc.nTop, _
hWnd, %IDC_MCI, GetModuleHandle(BYVAL %NULL), cp)
' Get a reference to the Imci interface
pMci = OC_GetDispatch(hCtl)
IF ISOBJECT(pMci) THEN
' Connect to the events fired by the control
pMciEvents = CLASS "CDmciEvents"
EVENTS FROM pMci CALL pMciEvents
' Set properties needed by MCI to open
pMci.Notify = %VARIANT_FALSE
pMci.Wait = %VARIANT_TRUE
pMci.Shareable = %VARIANT_FALSE
pMci.DeviceType = UCODE$("WaveAudio")
pMci.FileName = UCODE$("C:\WINDOWS\MEDIA\TADA.WAV") ' --> change as needed
' Open the MCI WaveAudio device.
pMci.Command = UCODE$("Open")
pMci = NOTHING
END IF
CASE %WM_SIZE
IF wParam <> %SIZE_MINIMIZED THEN
GetClientRect hWnd, rc
MoveWindow GetDlgItem(hWnd, %IDC_MCI), 0, 0, rc.nRight - rc.nLeft, rc.nBottom - rc.nTop, %TRUE
END IF
CASE %WM_COMMAND
SELECT CASE LO(WORD, wParam)
CASE %IDCANCEL
IF HI(WORD, wParam) = %BN_CLICKED THEN
SendMessage hWnd, %WM_CLOSE, 0, 0
EXIT FUNCTION
END IF
END SELECT
CASE %WM_SYSCOMMAND
' Capture this message and send a WM_CLOSE message
IF (wParam AND &HFFF0) = %SC_CLOSE THEN
SendMessage hWnd, %WM_CLOSE, 0, 0
EXIT FUNCTION
END IF
CASE %WM_DESTROY
' Get a reference to the Imci interface
pMci = OC_GetDispatch(hCtl)
IF ISOBJECT(pMci) THEN
' Close MCI
pMci.Command = UCODE$("Close")
pMci = NOTHING
END IF
' Disconnect events and quit
IF ISOBJECT(pMciEvents) THEN EVENTS END pMciEvents
PostQuitMessage 0
EXIT FUNCTION
END SELECT
FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)
END FUNCTION
' ========================================================================================
' ########################################################################################
' Class CDmciEvents
' Interface name = DmciEvents
' IID = {C1A8AF27-1257-101B-8FB0-0020AF039CA3}
' Event interface for MCI Control
' Attributes = 4224 [&H1080] [Nonextensible] [Dispatchable]
' Code generated by the TypeLib Browser 4.0.13 (c) 2008 by José Roca
' Date: 18 dic 2008 Time: 00:05:45
' ########################################################################################
CLASS CDmciEvents GUID$("{738E225D-DA6F-4829-A9D0-C5B78934578A}") AS EVENT
INTERFACE DmciEventsImpl GUID$("{C1A8AF27-1257-101B-8FB0-0020AF039CA3}") AS EVENT
INHERIT IDispatch
' =====================================================================================
METHOD Done <38> ( _
BYREF NotifyCode AS INTEGER _ ' *NotifyCode VT_I2 <Integer>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD BackClick <1> ( _
BYREF iCancel AS INTEGER _ ' *Cancel VT_I2 <Integer>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD PrevClick <2> ( _
BYREF iCancel AS INTEGER _ ' *Cancel VT_I2 <Integer>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD NextClick <3> ( _
BYREF iCancel AS INTEGER _ ' *Cancel VT_I2 <Integer>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD PlayClick <4> ( _
BYREF iCancel AS INTEGER _ ' *Cancel VT_I2 <Integer>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD PauseClick <5> ( _
BYREF iCancel AS INTEGER _ ' *Cancel VT_I2 <Integer>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD StepClick <6> ( _
BYREF iCancel AS INTEGER _ ' *Cancel VT_I2 <Integer>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD StopClick <7> ( _
BYREF iCancel AS INTEGER _ ' *Cancel VT_I2 <Integer>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD RecordClick <8> ( _
BYREF iCancel AS INTEGER _ ' *Cancel VT_I2 <Integer>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD EjectClick <9> ( _
BYREF iCancel AS INTEGER _ ' *Cancel VT_I2 <Integer>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD PrevGotFocus <10>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD PrevLostFocus <11>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD NextGotFocus <12>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD NextLostFocus <13>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD PlayGotFocus <14>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD PlayLostFocus <15>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD PauseGotFocus <16>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD PauseLostFocus <17>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD BackGotFocus <18>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD BackLostFocus <19>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD StepGotFocus <20>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD StepLostFocus <21>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD StopLostFocus <22>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD StopGotFocus <23>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD RecordGotFocus <24>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD RecordLostFocus <25>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD EjectGotFocus <26>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD EjectLostFocus <27>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD StatusUpdate <28>
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD NextCompleted <29> ( _
BYREF Errorcode AS LONG _ ' *Errorcode VT_I4 <Long>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD PlayCompleted <30> ( _
BYREF Errorcode AS LONG _ ' *Errorcode VT_I4 <Long>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD PauseCompleted <31> ( _
BYREF Errorcode AS LONG _ ' *Errorcode VT_I4 <Long>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD BackCompleted <32> ( _
BYREF Errorcode AS LONG _ ' *Errorcode VT_I4 <Long>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD StepCompleted <33> ( _
BYREF Errorcode AS LONG _ ' *Errorcode VT_I4 <Long>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD StopCompleted <34> ( _
BYREF Errorcode AS LONG _ ' *Errorcode VT_I4 <Long>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD RecordCompleted <35> ( _
BYREF Errorcode AS LONG _ ' *Errorcode VT_I4 <Long>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD EjectCompleted <36> ( _
BYREF Errorcode AS LONG _ ' *Errorcode VT_I4 <Long>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD PrevCompleted <37> ( _
BYREF Errorcode AS LONG _ ' *Errorcode VT_I4 <Long>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD OLEStartDrag <1550> ( _
BYREF pData AS IDispatch _ ' [in][out] **Data DataObject <coclass>
, BYREF AllowedEffects AS LONG _ ' [in][out] *AllowedEffects VT_I4 <Long>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD OLEGiveFeedback <1551> ( _
BYREF Effect AS LONG _ ' [in][out] *Effect VT_I4 <Long>
, BYREF DefaultCursors AS INTEGER _ ' [in][out] *DefaultCursors VT_BOOL <Integer>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD OLESetData <1552> ( _
BYREF pData AS IDispatch _ ' [in][out] **Data DataObject <coclass>
, BYREF DataFormat AS INTEGER _ ' [in][out] *DataFormat VT_I2 <Integer>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD OLECompleteDrag <1553> ( _
BYREF Effect AS LONG _ ' [in][out] *Effect VT_I4 <Long>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD OLEDragOver <1554> ( _
BYREF pData AS IDispatch _ ' [in][out] **Data DataObject <coclass>
, BYREF Effect AS LONG _ ' [in][out] *Effect VT_I4 <Long>
, BYREF iButton AS INTEGER _ ' [in][out] *Button VT_I2 <Integer>
, BYREF iShift AS INTEGER _ ' [in][out] *Shift VT_I2 <Integer>
, BYREF X AS SINGLE _ ' [in][out] *X VT_R4 <Single>
, BYREF Y AS SINGLE _ ' [in][out] *Y VT_R4 <Single>
, BYREF iState AS INTEGER _ ' [in][out] *State VT_I2 <Integer>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
' =====================================================================================
METHOD OLEDragDrop <1555> ( _
BYREF pData AS IDispatch _ ' [in][out] **Data DataObject <coclass>
, BYREF Effect AS LONG _ ' [in][out] *Effect VT_I4 <Long>
, BYREF iButton AS INTEGER _ ' [in][out] *Button VT_I2 <Integer>
, BYREF iShift AS INTEGER _ ' [in][out] *Shift VT_I2 <Integer>
, BYREF X AS SINGLE _ ' [in][out] *X VT_R4 <Single>
, BYREF Y AS SINGLE _ ' [in][out] *Y VT_R4 <Single>
) ' void
' *** Insert your code here ***
OutputDebugString FUNCNAME$
END METHOD
' =====================================================================================
END INTERFACE
END CLASS