码迷,mamicode.com
首页 > 其他好文 > 详细

directX播放程序

时间:2014-09-20 10:06:07      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:style   color   io   os   ar   strong   for   sp   log   



enum PLAYSTATE {Stopped, Paused, Running, Init};
PLAYSTATE g_Current=Init;


HWND      ghApp;
HINSTANCE ghInst;
HRESULT   hr;
LONG      evCode;
LONG      evParam1;
LONG      evParam2;


 //HRESULT  hr;
IGraphBuilder *pigb  = NULL;
IMediaControl *pimc  = NULL;
IMediaEventEx *pimex = NULL;
IVideoWindow  *pivw  = NULL;
IMediaSeeking  *pims  = NULL;
   
void CTestDlg::OnPlay() 
{
//    WCHAR wFile[MAX_PATH];
if(g_Current == Init)
    {
CoInitialize(NULL);
hr = CoCreateInstance(CLSID_FilterGraph,
 NULL,
 CLSCTX_INPROC_SERVER,
 IID_IGraphBuilder,
 (void **)&pigb);
  pigb->QueryInterface(IID_IMediaControl, (void **)&pimc);
  pigb->QueryInterface(IID_IMediaEventEx, (void **)&pimex);
       pigb->QueryInterface(IID_IMediaSeeking, (void **)&pims);
  pigb->QueryInterface(IID_IVideoWindow, (void **)&pivw);
 // hr = pigb->RenderFile(L"d:\\temp\\ff.mpg", NULL);//VIDEOC1600.264
   hr = pigb->RenderFile(L"d:\\temp\\bmw.MPG", NULL);//
//   pimex->SetNotifyWindow((OAHWND)ghApp, IDC_BUTTON1, 0);
   
  //
// m_Screen.ModifyStyle(0, WS_CLIPCHILDREN);
HWND m_hwndScreen = m_Screen.GetSafeHwnd();


RECT rc;
// m_hwndScreen = GetSafeHwnd();
//  hr = pivw->put_Caption(L"123");
hr = pivw->put_Owner((OAHWND)m_hwndScreen);
// hr = pivw->put_Owner((OAHWND)this->GetSafeHwnd());
hr = pivw->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN);
m_Screen.GetClientRect(&rc);
//GetClientRect(&rc);
hr = pivw->SetWindowPosition(0, 0, (rc.right), (rc.bottom));
}


if((g_Current == Init)||(g_Current == Paused))
{
hr = pimc->Run();
g_Current=Running;
SetTimer(1,100,NULL);


}

}


void CTestDlg::OnPaused() 
{
// TODO: Add your control notification handler code here


if(g_Current == Running)
    {
        if (SUCCEEDED(pimc->Pause()))
            g_Current = Paused;
KillTimer(1);
    }


// 释放所有接口
/* pimc->Release();
pimex->Release();
pigb->Release();
CoUninitialize();
*/
}

void CTestDlg::OnStop() 
{
// TODO: Add your control notification handler code here
if((g_Current == Running)||(g_Current == Stopped))
{
   hr = pimc->Stop();
KillTimer(1);
g_Current = Init;
pimc->Release();
pimex->Release();
pigb->Release();
CoUninitialize();
}


}


void CTestDlg::OnSetRate() 
{   
if (pims)
{    
rate++;
if(rate==4)
{
rate=1;

}
pims->SetRate(rate);
CString str;
str.Format("快进>> X %d",rate);
(GetDlgItem(IDC_BUTTON2))->SetWindowText(str);
}


// pivw->GetCurrentImage(&lpCurrImage) ;
}


void CTestDlg::OnSavePic() 
{
// TODO: Add your control notification handler code here
IBasicVideo *mBasicVideo = 0;
if (pigb)
{
pigb->QueryInterface(IID_IBasicVideo, (void **)&mBasicVideo);
}
    


if (mBasicVideo)
{
long bitmapSize = 0;
if (SUCCEEDED(mBasicVideo->GetCurrentImage(&bitmapSize, 0)))
{
bool pass = false;
unsigned char * buffer = new unsigned char[bitmapSize];
if (SUCCEEDED(mBasicVideo->GetCurrentImage(&bitmapSize, (long *)buffer)))
{
BITMAPFILEHEADER hdr;
LPBITMAPINFOHEADER lpbi;

lpbi = (LPBITMAPINFOHEADER)buffer;

int nColors = 1 << lpbi->biBitCount;
if (nColors > 256)
nColors = 0;

hdr.bfType = ((WORD) (‘M‘ << 8) | ‘B‘); //always is "BM"
hdr.bfSize = bitmapSize + sizeof( hdr );
hdr.bfReserved1 = 0;
hdr.bfReserved2 = 0;
hdr.bfOffBits = (DWORD) (sizeof(BITMAPFILEHEADER) + lpbi->biSize +
nColors * sizeof(RGBQUAD));

CFile bitmapFile("C:\\TEST.BMP", CFile::modeReadWrite | CFile::modeCreate | CFile::typeBinary);
bitmapFile.Write(&hdr, sizeof(BITMAPFILEHEADER));
bitmapFile.Write(buffer, bitmapSize);
bitmapFile.Close();
pass = true;
}
delete [] buffer;
WinExec("C:\\Program Files\\ACDSee\\ACDSee.exe C:\\TEST.BMP",SW_SHOW);
// return pass;
}
}
}


void CTestDlg::OnFullScreen() 
{
// TODO: Add your control notification handler code here
if (pivw)
{
pivw->put_FullScreenMode(-1);
}
}




void CTestDlg::OnButton8() //属性
{
// TODO: Add your control notification handler code here
IEnumFilters* pEnum;
HRESULT hr ;
if (pigb)
{
hr = pigb-> EnumFilters(&pEnum);
if (FAILED(hr)) 
{
return ;
}

     

IBaseFilter* pFilter = NULL;
while (pEnum->Next(1, &pFilter, NULL) == S_OK) 
{
// Check for required interface
IUnknown* pUnk;//查找Filter接口,只有一个?
HRESULT hrQuery = pFilter->QueryInterface(IID_IVideoWindow, (void**)&pUnk);
if (SUCCEEDED(hrQuery)) 
{
pUnk->Release();
pEnum->Release();
break ;
}
// pFilter->Release();
}
 //  pEnum->Release();
//
ISpecifyPropertyPages *pProp = NULL;//查询接口
hr = pFilter->QueryInterface(IID_ISpecifyPropertyPages, (void **)&pProp);
if (SUCCEEDED(hr)) 
{
// Get the filter‘s name and IUnknown pointer.
FILTER_INFO FilterInfo;
hr = pFilter->QueryFilterInfo(&FilterInfo); 
IUnknown *pFilterUnk;
pFilter->QueryInterface(IID_IUnknown, (void **)&pFilterUnk);
//
CString str(FilterInfo.achName);//显示Filter名称
MessageBox(str);

// Show the page. 
CAUUID caGUID;

pProp->GetPages(&caGUID);
pProp->Release();
OleCreatePropertyFrame(
this->GetSafeHwnd(),                   // Parent window
0, 0,                                 // Reserved
FilterInfo.achName,     //L"MAOMAO" // Caption for the dialog box 
1,                      // Number of objects (just the filter)
&pFilterUnk,            // Array of object pointers. 
caGUID.cElems,          // Number of property pages
caGUID.pElems,          // Array of property page CLSIDs
0,                      // Locale identifier
0, NULL                 // Reserved
);

// Clean up.
pFilterUnk->Release();
FilterInfo.pGraph->Release(); 
CoTaskMemFree(caGUID.pElems);
}
}
}

directX播放程序

标签:style   color   io   os   ar   strong   for   sp   log   

原文地址:http://blog.csdn.net/mao0514/article/details/39429137

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!