利用ATL制作程序多媒体封面组件 (转)

利用ATL制作程序多媒体封面组件 (转)[@more@]COM的优越就不多说,使用ATL开发COM方便而快捷,并且具有Size小,Dependency少的特点。VC++的import 编译支持更是对COM开发的巨大支持。闲话休说,这就开始吧。
  一.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
 D word 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
            项目设置中加入“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。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10790690/viewspace-950945/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10790690/viewspace-950945/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值