请问哪位大侠有用vfw做一个播放视频文件的例子,不是播放摄像头,是播放视频文件,如*.avi的例子。。

解决方案 »

  1.   

    一.Flash组件
            1.ATL COM AppWizard创建新项目"ATLFlash",选择DLL类型。
            2.加入ATL Object "Flash"
                Insert ->  New ATL Object
                选择Object中的Simple Object,
                Short Name:“FLash”
            3.接口添加Method “Play”
                参数为:[in]BSTR bstrFile,[in]long hInstance,[in]long hWnd
            4.在CFlash类中加入:
                private:
                          HWND m_hWnd;//视频窗口句柄
            5. 实现Play方法。
    STDMETHODIMP CFlash::Play(BSTR bstrFile, long hInstance, long hWnd)
    {
        try{
            m_hMCIWnd=(HWND)hWnd;
            _bstr_t file(bstrFile);
            m_hMCIWnd=::MCIWndCreate((HWND)hWnd,(HINSTANCE)hInstance,
                WS_POPUP¦WS_VISIBLE¦
                MCIWNDF_NOPLAYBAR¦
                MCIWNDF_NOMENU,                
                (char *)file);        RECT rect;
            int sx,sy;
            ::GetWindowRect(m_hMCIWnd,&rect);
            sx=(::GetSystemMetrics(SM_CXSCREEN)
                -rect.right+rect.left)/2;
            sy=(::GetSystemMetrics(SM_CYSCREEN)
                -rect.bottom+rect.top)/2;    
            //窗口居中
            ::SetWindowPos(m_hMCIWnd,HWND_TOPMOST,sx,
                sy,0,0,SWP_SHOWWINDOW¦SWP_NOSIZE);
            
            g_nLength=MCIWndGetLength(m_hMCIWnd);
            MCIWndPlay(m_hMCIWnd);
            SetTimer(m_hMCIWnd,1,50,TimerProc);
            
        }catch(...)
        {
            AtlTrace("error:%ul",::GetLastError()); 
        }
        return S_OK;
    }
      
              6.Flash.cpp中实现TimerProc,用于关闭视频窗口。
    long g_nLength;
    VOID CALLBACK TimerProc(
                HWND hwnd,    // handle of window for timer messages
                UINT uMsg,    // WM_TIMER message
                UINT idEvent,  // timer identifier
                DWORD dwTime  // current system time
                )
    {
        
        long nLength;
        BOOL bEscape=::GetKeyState(VK_ESCAPE)&0x0100;
        nLength=MCIWndGetPosition(hwnd);
                    //视频放完,或点击ESC键,关闭视频窗口
        if((nLength>=g_nLength)¦¦(bEscape)){
            KillTimer(hwnd,idEvent);
            MCIWndEnd(hwnd);
            MCIWndClose(hwnd);
            MCIWndDestroy(hwnd);
        }
    };
            7.stdafx.h中加入
                #include <vwf.h>
                项目设置中加入“vwf32.lib”库,
                打开项目设置中C++,C++language中的Enable Error Handling
                编译,一切OK。
    二,组件的使用。
          1.创建一个MDI或SDI项目"FlashClient"
          2.stdafx.h中加入
              #import “ATLFlash.dll” no_namespace
              FlashCient.cpp中加入
              struct _InitCom{
        _InitCom(){::CoInitialize(NULL);}
        ~_InitCom(){::CoUninitialize(); }
              }__InitCom;
          3.CFlashClientView加入
            private:
        IFlashPtr pFlashServer;
          4.CFlashClent::OnInitialUpdate()加入
        _bstr_t file("Sample.avi");
        pFlashServer->Play(    file,(long)::AfxGetInstanceHandle(),(long)this->GetSafeHwnd());        
          5.编译,一切OK。
    (作者:wurong)
      

  2.   

    大侠,这是vc吗?有delphi代码吗?