• Welcome to Jose's Read Only Forum 2023.
 

Multimedia MCI Control

Started by Frank Brübach, January 10, 2011, 05:01:47 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frank Brübach


http://www.jose.it-berater.org/smfforum/index.php?topic=2953.0

hello. perhaps somebody can check this code example for mci controls. I see no controls after compiling.

' ########################################################################################
' 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 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)

         ' 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
' ========================================================================================


frank

José Roca

First check if you have MCI32.OCX installed and registered in your computer.

Frank Brübach

Quoteregsvr32.exe C:\windows\system32\MCI32.OCX

thanks, I've forgotten to register mci, because never used it before. mci32.ocx was already installed :)

frank