I'm just use directshow for some days, I directly use MPC-BE filters.
After input file name,then click play button:
void CAFPlayerDlg::OnBnClickedButtonPlay()
{
HRESULT hr = NOERROR;
CString fileName;
m_edtFileName.GetWindowTextW(fileName);
if(fileName.GetLength() <= 0)
return;
hr = m_pGraph->RenderFile(fileName.GetBuffer(), NULL);
fileName.ReleaseBuffer();
if(FAILED(hr))
return;
hr = m_pME->SetNotifyWindow((OAHWND)this->GetSafeHwnd(), WM_GRAPHNOTIFY, 0);
SetDisplayWindow(m_stcVideoWindow.GetSafeHwnd());
if(SUCCEEDED(hr)) {
m_pMC->Run();
}
}
SetDisplayWindow function is:
bool CAFPlayerDlg::SetDisplayWindow( HWND displayWindow )
{
if(m_pVideoWindow) {
m_pVideoWindow->put_Visible(OAFALSE);
m_pVideoWindow->put_Owner((OAHWND)displayWindow);
RECT rect;
::GetClientRect(displayWindow, &rect);
m_pVideoWindow->put_Left(0);
m_pVideoWindow->put_Top(0);
m_pVideoWindow->put_Width(rect.right - rect.left);
m_pVideoWindow->put_Height(rect.bottom - rect.top);
m_pVideoWindow->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
m_pVideoWindow->put_MessageDrain((OAHWND)displayWindow);
if(displayWindow) {
m_pVideoWindow->put_Visible(OATRUE);
} else {
m_pVideoWindow->put_Visible(OAFALSE);
}
return true;
}
return false;
}
I has add some code for refreshing:
BOOL CAFPlayerDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
m_stcVideoWindow.ModifyStyle(0, WS_CLIPCHILDREN);
CoInitialize(NULL);
return TRUE;
}
BOOL CAFPlayerDlg::OnEraseBkgnd(CDC* pDC)
{
CRect rc;
m_stcVideoWindow.GetWindowRect(&rc);
ScreenToClient(&rc);
pDC->ExcludeClipRect(&rc);
return CDialog::OnEraseBkgnd(pDC);
}
void CAFPlayerDlg::PreSubclassWindow()
{
CDialog::PreSubclassWindow();
this->ModifyStyle( 0, WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0 );
}
Now I can play mp4 file, I can hear music sound, but display is not normal.
Please see image:
[
https://drive.google.com/file/d/0BwyCt3NztyAPZFdkM2N3ZnoyczQ/edit?usp=sharing[
^]]