TXT

commcih-interface-for-the-commci-class-

By Rebecca Rose,2014-10-02 04:39
17 views 0
commcih-interface-for-the-commci-class-

    // commci.h: interface for the commci class. //

    //////////////////////////////////////////////////////////////////////

#if !defined(AFX_COMMCI_H__90CEFD04_CC96_11D1_94F8_0000B431BBA1__INCLUDED_)

    #define AFX_COMMCI_H__90CEFD04_CC96_11D1_94F8_0000B431BBA1__INCLUDED_

#if _MSC_VER >= 1000

    #pragma once

    #endif // _MSC_VER >= 1000

//#include

    #include

class COMMCI

    {

    private:

     HWND hOwer; //窗口的拥有者

     MCI_OPEN_PARMS mciOpen;

public:

     COMMCI();

     ~COMMCI() {Close(); }

     MCIERROR Open(LPCSTR DeviceType,LPCSTR filename); //通过描述字符串打开设备

     MCIERROR Open(int DeviceType,LPCSTR filename); //通过设备类型打开设备

     MCIERROR Open(LPCSTR filename); //自动检测设备

     void Play(HWND hWnd); //播放MCIhWnd为回调窗口句柄

     void Close(void); //关闭设备

     void Stop(void); //停止设备

     void Pause(void); //暂停设备

     DWORD Query(); //检测设备

    };

/////////////////////////////////////////////////////////

    // COMMCI.CPP 中使用到的结构

    /////////////////////////////////////////////////////////

    //typedef struct tagMCI_OPEN_PARMS { // DWORD dwCallback;

    // MCIDEVICEID wDeviceID;

    // WORD wReserved0;

    // LPCSTR lpstrDeviceType;

    // LPCSTR lpstrElementName;

    // LPCSTR lpstrAlias;

//} MCI_OPEN_PARMS, FAR *LPMCI_OPEN_PARMS;

//typedef struct tagMCI_PLAY_PARMS {

    // DWORD dwCallback;

    // DWORD dwFrom;

    // DWORD dwTo;

    //} MCI_PLAY_PARMS, *PMCI_PLAY_PARMS, FAR *LPMCI_PLAY_PARMS;

//typedef struct tagMCI_STATUS_PARMS {

    // DWORD dwCallback;

    // DWORD dwReturn;

    // DWORD dwItem;

    // DWORD dwTrack;

    //} MCI_STATUS_PARMS, *PMCI_STATUS_PARMS,

     FAR * LPMCI_STATUS_PARMS;

    ////////////////////////////////////////////////////////// // mci 初始化方式

    ////////////////////////////////////////////////////////// //COMMCI.Open("waveaudio",filename); wave ; *.wav , //COMMCI.Open("sequencer",filename); midi ; *.mid , *.rmi //COMMCI.Open("reelmagic",filename); vcd ; *.mpg , //COMMCI.Open("avivideo",filename); avi ; *.avi ,

    ///////////////////////////////////////////////////////// // mci 状态返回值

    ///////////////////////////////////////////////////////// // case MCI_MODE_NOT_READY:

    // case MCI_MODE_STOP:

    // case MCI_MODE_PLAY:

    // case MCI_MODE_RECORD:

    // case MCI_MODE_SEEK:

    // case MCI_MODE_PAUSE:

    // case MCI_MODE_OPEN:

#endif // !defined(AFX_COMMCI_H__90CEFD04_CC96_11D1_94F8_0000B431BBA1__INCLUDED_)

    // commci.cpp: implementation of the commci class. //

    //////////////////////////////////////////////////////////////////////

#include "stdafx.h"

    //#include "mcitest.h"

    #include "commci.h"

#ifdef _DEBUG

    #undef THIS_FILE

    static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW

    #endif

//////////////////////////////////////////////////////////////////////

    // Construction/Destruction

    //////////////////////////////////////////////////////////////////////

COMMCI::COMMCI()

    {

     memset(this,0,sizeof(COMMCI)); }

MCIERROR COMMCI::Open(LPCSTR DeviceType,LPCSTR filename)

    {

     //如果有打开的设备就关闭

    if (mciOpen.wDeviceID) Close();

     //初始化MCI_OPEN_PARMS结构

    mciOpen.lpstrDeviceType=DeviceType;

     mciOpen.lpstrElementName=filename; //除了打开设备设备代码为0;下面的任何mciSendCommand语句都要指定设 //备代码。

     if ( mciSendCommand(NULL,MCI_OPEN,

     MCI_OPEN_TYPE | MCI_OPEN_ELEMENT,

     (DWORD)&mciOpen))

     return FALSE;

     return TRUE;

    }

    MCIERROR COMMCI::Open(LPCSTR filename) {

     if (mciOpen.wDeviceID) Close();

     mciOpen.lpstrElementName=filename;

     if ( mciSendCommand(NULL,MCI_OPEN,

     /*MCI_OPEN_TYPE |*/ MCI_OPEN_ELEMENT,

     (DWORD)&mciOpen))

     return FALSE;

     return TRUE;

    }

    MCIERROR COMMCI::Open(int DeviceType,LPCSTR filename) {

     if (mciOpen.wDeviceID) Close();

     mciOpen.lpstrDeviceType=(LPCSTR)DeviceType;

     mciOpen.lpstrElementName=filename;

     return mciSendCommand(NULL,MCI_OPEN,

     MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID ,(DWORD)&mciOpen); }

void COMMCI::Play(HWND hWnd)

    {

     MCI_PLAY_PARMS mciPlay;

     hOwer=hWnd; //回调窗口句柄

     //MCI_PLAY_PARMS结构只需要设定回调窗口句柄

     mciPlay.dwCallback=(WORD)hOwer;

     mciSendCommand(mciOpen.wDeviceID,MCI_PLAY,MCI_NOTIFY,

     (DWORD)&mciPlay); }

void COMMCI::Close(void)

    {

     if (mciOpen.wDeviceID)

     mciSendCommand(mciOpen.wDeviceID,MCI_CLOSE,NULL,NULL);

     memset(this,0,sizeof(COMMCI));

    }

void COMMCI::Stop(void)

    {

     if (mciOpen.wDeviceID)

     mciSendCommand(mciOpen.wDeviceID,MCI_STOP,NULL,NULL); }

void COMMCI::Pause(void)

    {

     if (mciOpen.wDeviceID)

     mciSendCommand(mciOpen.wDeviceID,MCI_PAUSE,NULL,NULL); }

DWORD COMMCI::Query()

    {

     MCI_STATUS_PARMS mciStatus;

     mciStatus.dwItem=MCI_STATUS_MODE;

     mciSendCommand(mciOpen.wDeviceID,MCI_STATUS,

     MCI_STATUS_ITEM,(LPARAM)&mciStatus);

     return mciStatus.dwReturn;

    };

Report this document

For any questions or suggestions please email
cust-service@docsford.com