zoukankan      html  css  js  c++  java
  • directX播放程序 分类: DirectX 2014-09-20 08:49 499人阅读 评论(0) 收藏



    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);
    }
    }
    }

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    PTA —— 基础编程题目集 —— 函数题 —— 61 简单输出整数 (10 分)
    PTA —— 基础编程题目集 —— 函数题 —— 61 简单输出整数 (10 分)
    练习2.13 不用库函数,写一个高效计算ln N的C函数
    练习2.13 不用库函数,写一个高效计算ln N的C函数
    练习2.13 不用库函数,写一个高效计算ln N的C函数
    迷宫问题 POJ 3984
    UVA 820 Internet Bandwidth (因特网带宽)(最大流)
    UVA 1001 Say Cheese(奶酪里的老鼠)(flod)
    UVA 11105 Semiprime Hnumbers(H半素数)
    UVA 557 Burger(汉堡)(dp+概率)
  • 原文地址:https://www.cnblogs.com/mao0504/p/4706515.html
Copyright © 2011-2022 走看看