⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 emlplayerdlg.cpp

📁 DShow player based on wince 6.0 vs2005
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// EMLplayerDlg.cpp : implementation file
//

#include "stdafx.h"
#include "EMLplayer.h"
#include "EMLplayerDlg.h"
#include <streams.h>


#pragma comment (lib,"Ole32.lib")
#pragma comment (lib,"Strmiids.lib")




#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define RELEASE(i) {if (i) i->Release(); i = NULL;}

#define JIF(x) if (FAILED(hr=(x))) \
    {RETAILMSG(1, (TEXT("FAILED(0x%x) ") TEXT(#x) TEXT("\n"), hr)); goto CLEANUP;}

#define LIF(x) if (FAILED(hr=(x))) \
    {RETAILMSG(1, (TEXT("FAILED(0x%x) ") TEXT(#x) TEXT("\n"), hr)); }

#define HANDLE_EC(c)                                         \
    case c:                                                  \
        OutputDebugString(TEXT("  ") TEXT(#c) TEXT("\r\n")); \
        break;

#define ISBLANK(x) \
    (((x) == TEXT(' ')) || ((x) == TEXT('\t')) || \
     ((x) == TEXT('\r')) || ((x) == TEXT('\n')))

#define countof(a)    (sizeof(a)/sizeof(*(a)))

DWORD WINAPI PlayThreadFunc(LPVOID lparam);

#if 1
static	IGraphBuilder  *pGB;
static	IMediaControl  *pMC;
static	IMediaSeeking  *pMS;
static	IMediaPosition *pMP;
static	IVideoWindow   *pVW;
static	IBasicVideo    *pBV;
static	IBasicAudio    *pBA;
static	IMediaEvent    *pME;
static	IQualProp      *pQP;
static	IBaseFilter    *pBF_OvM;
static	IBaseFilter    *psfasd;

#endif

/////////////////////////////////////////////////////////////////////////////
// CEMLplayerDlg dialog

CEMLplayerDlg::CEMLplayerDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CEMLplayerDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CEMLplayerDlg)
		// NOTE: the ClassWizard will add member initialization here
	pGB = NULL;
	pMC = NULL;
	pMS = NULL;
	pMP = NULL;
	pVW = NULL;
	pBV = NULL;
	pME = NULL;
	pQP = NULL;
	pBF_OvM = NULL;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CEMLplayerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEMLplayerDlg)
	DDX_Text(pDX, IDC_EDTRECV, m_strRecv);
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CEMLplayerDlg, CDialog)
	//{{AFX_MSG_MAP(CEMLplayerDlg)
	ON_BN_CLICKED(IDC_OPEN, OnOpen)
	ON_BN_CLICKED(IDC_PLAY, OnPlay)
	ON_BN_CLICKED(IDC_CLOSE, OnClose)
	ON_BN_CLICKED(IDC_STEP, OnStep)
	ON_BN_CLICKED(IDC_STOP, OnStop)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEMLplayerDlg message handlers

BOOL CEMLplayerDlg::OnInitDialog()
{
	CButton *pButton;
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

    pWnd = GetDlgItem(IDC_PLAY_WND);
    m_Hwnd = pWnd->m_hWnd;

	// TODO: Add extra initialization here
	pButton = (CButton*)GetDlgItem(IDC_PLAY);
	pButton->EnableWindow(FALSE);
	pButton = (CButton*)GetDlgItem(IDC_STOP);
	pButton->EnableWindow(FALSE);
	pButton = (CButton*)GetDlgItem(IDC_STEP);
	pButton->EnableWindow(FALSE);

	m_Start=FALSE;

	m_strParity	= _T("NONE");

	m_portNo   = 1;
    m_baud     = 9600;
    m_parity   = _wtoi(m_strParity);
    m_databits = 8;
    m_stopbits = 1;
	m_RecvLen  = 0;

	CString name = "COM unConneted!";
	this->SetWindowText(name);

	OpenCOM();

	return TRUE;  // return TRUE  unless you set the focus to a control
}



void CEMLplayerDlg::OnOpen() 
{
	// TODO: Add your control notification handler code here
#if 0
	CString  sz_FileFilter=  _T(
		"Movie File(*.wmv)|*.wmv|"
		"Movie File(*.mov)|*.mov|"
		"Media File(*.mmm)|*.mmm|"
		"Wma File(*.wma)|*.wma|"
		"Video File(*.dat)|*.dat|"
		"Wave File(*.wav)|*.wav|"
		"Mid File(*.mid;*,rmi)|*.mid;*.rmi|"
		"MPEG File(*.mpeg)|*.mpeg|"
		"Mp3 File(*.mp3)|*.mp3|"
		"AVI File(*.avi)|*.avi|"
		"All File(*.*)|*.*||");
#else
		CString sz_FileFilter= _T("*.wmv");
#endif
/*
	CFileDialog  dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,sz_FileFilter);
	
	if(dlg.DoModal()==IDOK)
	{   
		CString LPathName=dlg.GetPathName();
		SPathName = LPathName;
	}	
*/
		CString LPathName =_T("\\my documents\\sobachkatruk.wmv");//
		SPathName = LPathName;

	CButton *pButton = (CButton*)GetDlgItem(IDC_PLAY);
	pButton->EnableWindow(TRUE);
}

void CEMLplayerDlg::OnPlay() 
{
	m_hPlayThread = CreateThread(NULL,0,PlayThreadFunc,this,0,&m_dwPlayThreadID);
}

HRESULT CEMLplayerDlg::GetInterfaces(void)
{
    HRESULT hr = S_OK;

    JIF(CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IGraphBuilder, (void **)&pGB));
    JIF(pGB->QueryInterface(IID_IMediaControl,  (void **)&pMC));
    JIF(pGB->QueryInterface(IID_IMediaSeeking,  (void **)&pMS));
    JIF(pGB->QueryInterface(IID_IMediaPosition, (void **)&pMP));
    JIF(pGB->QueryInterface(IID_IVideoWindow,   (void **)&pVW));
    JIF(pGB->QueryInterface(IID_IBasicVideo,    (void **)&pBA));
    JIF(pGB->QueryInterface(IID_IBasicAudio,    (void **)&pBV));
    JIF(pGB->QueryInterface(IID_IMediaEventEx,  (void **)&pME));

    //JIF(pGB->QueryInterface(IID_IAudioControl,  (void **)&pAC));
    //JIF(pGB->QueryInterface(IID_IVideoControl,  (void **)&pVC));
    //JIF(pGB->QueryInterface(IID_ISeekingControl,(void **)&pSeek));

    return S_OK;

CLEANUP:
    CleanupInterfaces();
    return(hr);
}

void CEMLplayerDlg::CleanupInterfaces(void)
{
    RELEASE(pGB);
    RELEASE(pMC);
    RELEASE(pMS);
    RELEASE(pMP);
    RELEASE(pVW);
    RELEASE(pBV);
    RELEASE(pME);
    RELEASE(pBF_OvM);
}

HRESULT CEMLplayerDlg::AddWindowlessRendererToGraph(IGraphBuilder *pGB)
{
    HRESULT hr;
    TCHAR buf[256];

    hr = CoCreateInstance( CLSID_OverlayMixer, NULL, 
		                  CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **) &pBF_OvM);
   /* if (FAILED(hr)) {
        wsprintf(buf, TEXT("Failed(%08lx) in CoCreateInstance <CLSID_OverlayMixer>!\r\n"),
            hr);
        MessageBox(buf, _T("INFO"), MB_OK);
        return hr;
    }
*/
    hr = pGB->AddFilter(pBF_OvM, L"Windowless Video Renderer");
   /* if (FAILED(hr)) {
        wsprintf(buf, TEXT("Failed(%08lx) in AddFilter <Windowless Video Renderer>!\r\n"),
            hr);
        MessageBox(buf, _T("INFO"), MB_OK);
        return hr;
    }
*/
//CLEANUP:
    return hr;
}

HRESULT CEMLplayerDlg::PlayMedia(void)
{
    HRESULT hr = S_OK;
    TCHAR buf[256];

	CComBSTR s(SPathName); //在头文件#include <atlbase.h>中被定义
    //CString name = "Mplayer--" + SPathName;
	//this->SetWindowText(name);

    JIF(AddWindowlessRendererToGraph(pGB));

    // Allow DirectShow to create the FilterGraph for this media file
    hr = pGB->RenderFile(s, 0);
    /*if (FAILED(hr)) {
        wsprintf(buf, TEXT("Failed(%08lx) in RenderFile(%s)!\r\n"),
            hr, s);
        MessageBox(buf, _T("INFO"), MB_OK);
        return hr;
    }
*/
	hr = pVW->put_Owner((OAHWND)m_Hwnd);
   /* if (FAILED(hr))
    {
        wsprintf(buf, TEXT("Failed(%08lx) in put_Owner(%s)!\r\n"),
            hr, s);
        MessageBox(buf, _T("INFO"), MB_OK);
	}
*/
    // Set the message drain of the video window to point to our hidden
    // application window.  This allows keyboard input to be transferred
    // to our main window for processing.
    //
    // If this is an audio-only or MIDI file, then put_MessageDrain will fail.
    hr = pVW->put_MessageDrain((OAHWND) m_Hwnd);
  /*  if (FAILED(hr))
    {
        // Show the main hidden window for keyboard control
        //ShowCurrentAudioFile(lpszMovie);

        //ShowWindow(g_hwndMain, SW_SHOWNORMAL);
        //g_bShowingMainWindow = TRUE;
        //g_bAudioOnly = TRUE;
        //SetForegroundWindow(g_hwndMain);
        //SetFocus(g_hwndMain);
    }
    else
    {
        //ShowCurrentVideoFile(lpszMovie);
    }
*/
	OnRun();
	/*
	if (FAILED(hr))
    {
		return hr;
	}
	*/
	m_Complete = FALSE;
	m_Start    = TRUE;

CLEANUP:
    return hr;
}

void CEMLplayerDlg::OnClose() 
{
	// TODO: Add your control notification handler code here
	ClosePlayThread();
	CloseCOM();

	CDialog::OnOK();
}

void CEMLplayerDlg::OnStep() 
{
	// TODO: Add your control notification handler code here
	
}

void CEMLplayerDlg::OnStop() 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -