使用MCI播放媒体文件

#include<stdio.h>
#include<mmsystem.h>
#pragma comment(lib,"winmm.lib")

bool MCI_Play(LPCTSTR file)
{
//use mciSendCommand
  MCI_OPEN_PARMS mciOpen = {0};
  mciOpen.lpstrElementName = file;
  MCIERROR mciError = mciSendCommand(0,MCI_OPEN, MCI_OPEN_ELEMENT ,(DWORD)&mciOpen);
  if(mciError)
  {
    char buf[128];
    mciGetErrorString(mciError,buf,128);
    CString mess_str;
    mess_str.Format("send MCI_OPEN command failed:%s/n",buf);
    AfxMessageBox(mess_str);
    return(false);
  }
 
  MCI_PLAY_PARMS mciPlay;
  mciError = mciSendCommand(mciOpen.wDeviceID,MCI_PLAY,0 ,(DWORD)&mciPlay);
  if(mciError)
  {
    mciSendCommand(mciOpen.wDeviceID, MCI_CLOSE, 0, NULL);
    AfxMessageBox("send MCI_PLAY command failed/n");
    return(false);
  }

  return(true);
}

 

 

你可能感兴趣的:(File,command,null)