#include <WinTen.h>
#include <Windows.h>
#include <MMSystem.h>
#include <ClipApi.h>

CLIPPER AUXGETVOL()
{
  DWORD vol=0;

	_retni( auxGetVolume( _parni(1), &vol ) );

	_stornl(LOWORD(vol),2);
	_stornl(HIWORD(vol),3);
}


CLIPPER AUXSETVOL()
{
	DWORD vol;

	vol = _parni(3);
	vol = vol<<16;
	vol = vol + _parni(2);

	_retni( auxSetVolume( _parni(1), vol ) );

}


CLIPPER AUXGETCAPS()
{
		AUXCAPS CapDev;

    _retni( auxGetDevCaps( _parni(1), &CapDev, sizeof(AUXCAPS) )  );

		_storni(CapDev.wMid,2,1);
		_storni(CapDev.wPid,2,2);
		_storni(CapDev.vDriverVersion,2,3);
		_storc(CapDev.szPname,2,4);
		_storni(CapDev.wTechnology,2,5);
		_stornl(CapDev.dwSupport,2,6);
}

//----------------------------------------------------------------------------//
CLIPPER AUXGETDEV()
{
   _retni( auxGetNumDevs() ); // Number of Auxiliary devices.
}


//----------------------------------------------------------------------------//
CLIPPER MCISENDSTR()       // STRING()
{
   BYTE bBuffer[ 200 ];

   _retnl( mciSendString( ( LPSTR) _parc( 1 ),      // The MCI String Command
                          ( LPSTR ) bBuffer,         // Return Value
                           200,
                           _parni( 3 ))  );   // CallBack-Window Handle
   _storc( bBuffer, 2 );
}

//----------------------------------------------------------------------------//

CLIPPER MCISENDCOM()       // MAND()
{
   _retnl( mciSendCommand( _parni( 1 ),      // Device ID
                           _parni( 2 ),      // Command Message
                           _parnl( 3 ),      // Flags
                           ( DWORD ) _parc( 4 ) ) );   // Parameter Block
}

//----------------------------------------------------------------------------//

CLIPPER MCIGETERRO()  // RSTRING()
{
   BYTE bBuffer[ 200 ];

   _retl( mciGetErrorString( _parnl( 1 ),       // Error Code
                             ( LPSTR ) bBuffer,
                             200 ) );
   _storc( bBuffer, 2 );
}

//----------------------------------------------------------------------------//

CLIPPER nMciOpen()
{
   MCI_OPEN_PARMS mciOpenParms;
   DWORD dwFlags = 0;

   mciOpenParms.lpstrDeviceType = _parc( 1 );
   dwFlags = MCI_OPEN_ELEMENT;

   if( ISCHAR( 2 ) )
   {
      mciOpenParms.lpstrElementName = _parc( 2 );
      dwFlags |= MCI_OPEN_TYPE;
   }

   _retnl( mciSendCommand( 0, MCI_OPEN, dwFlags,
                           ( DWORD ) ( LPMCI_OPEN_PARMS ) &mciOpenParms ) );

   _storni( mciOpenParms.wDeviceID, 3 );
}

//----------------------------------------------------------------------------//

CLIPPER nMciPlay()
{
   MCI_PLAY_PARMS mciPlayParms;
   DWORD dwFlags = 0;

   if( _parnl( 2 ) )
   {
      mciPlayParms.dwFrom = _parnl( 2 );
      dwFlags |= MCI_FROM;
   }

   if( _parnl( 3 ) )
   {
      mciPlayParms.dwTo = _parnl( 3 );
      dwFlags |= MCI_TO;
   }

   if( _parni( 4 ) )
   {
      mciPlayParms.dwCallback = ( DWORD ) ( LPVOID ) _parni( 4 );
      dwFlags |= MCI_NOTIFY;
   }

   _retnl( mciSendCommand( _parni( 1 ),         // Device ID
                           MCI_PLAY, dwFlags,
                           ( DWORD ) ( LPMCI_PLAY_PARMS ) &mciPlayParms ) );
}

//----------------------------------------------------------------------------//

CLIPPER nMciWindow()
{
   MCI_ANIM_WINDOW_PARMS mciWindowParms;
   MCI_ANIM_RECT_PARMS mciRectParms;
   HWND hWnd = _parni( 2 );

   mciWindowParms.hWnd = hWnd;

   mciSendCommand( _parni( 1 ), MCI_WINDOW, MCI_ANIM_WINDOW_HWND,
                   ( LONG ) ( LPMCI_ANIM_WINDOW_PARMS ) &mciWindowParms );

   GetWindowRect( hWnd, &mciRectParms.rc );

   mciRectParms.rc.right  = mciRectParms.rc.right - mciRectParms.rc.left;
   mciRectParms.rc.bottom = mciRectParms.rc.bottom - mciRectParms.rc.top;
   mciRectParms.rc.top    = 0;
   mciRectParms.rc.left   = 0;

   _retnl( mciSendCommand( _parni( 1 ), MCI_PUT,
              MCI_ANIM_RECT | MCI_ANIM_PUT_DESTINATION,
              ( LONG ) ( LPMCI_ANIM_RECT_PARMS ) &mciRectParms ) );
}

//----------------------------------------------------------------------------//
