【译】用于多媒体应用的无窗口ATL ActiveX控件容器

原文链接:ATL Windowless ActiveX Media Container

      这个ATL activeX框架适用于作为Windows Media Player,Flash以及Sliverlight动画的承载容器。整个框架分布在Windowless文件夹下,共有6个文件。架构如图所示:

使用Adobe Flash Player作为子控件

 

主要代码如下:

class  CMainDlg :  public  CAxWindowlessHost < CMainDlg >


LRESULT CMainDlg::OnInitDialog(UINT 
/* uMsg */ , WPARAM  /* wParam */ , LPARAM  /* lParam */ , BOOL &   /* bHandled */ )
{
    
//  center the dialog on the screen
    CenterWindow();

    
//  set icons
    HICON hIcon  =  (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), 
        IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
    SetIcon(hIcon, TRUE);
    HICON hIconSmall 
=  (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), 
        IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
    SetIcon(hIconSmall, FALSE);

    TCHAR szPath[MAX_PATH] 
=  {  0  };
    
if  ( ::GetModuleFileName(NULL, szPath, MAX_PATH)  >   0  )
    {
// 定位.swf文件
        LPTSTR pszSep  =  _tcsrchr(szPath, TCHAR( ' \\ ' ));
        pszSep
++ ;
        
* pszSep  =   0 ;
        ::StringCchCat(szPath, MAX_PATH, _T(
" Construction.swf " ));
    }

    
//  Initialize Flash Player (Shockwave .swf)
    HRESULT hr;
    ActiveXSite
*  pSite;
    pSite 
=  CAxWindowlessHost < CMainDlg > ::GetControlSite(IDC_SHOCKWAVEFLASH); // 获取flash player子控件
     if  ( pSite  !=  NULL )
    {
        CComQIPtr
< IShockwaveFlash >  spFlash  =  pSite -> ActiveXControl();
        hr 
=  spFlash -> put_WMode( CComBSTR( " Transparent " ) ); // 设置“透明”
        hr  =  spFlash -> put_Movie( CComBSTR(szPath) ); // 设置影片源文件
    }
    
return  TRUE;
}

使用Windows Meida Player作为子控件

 

主要代码如下:

LRESULT CMainDlg::OnInitDialog(UINT  /* uMsg */ , WPARAM  /* wParam */ , LPARAM  /* lParam */ , BOOL &   /* bHandled */ )
{
    
//  center the dialog on the screen
    CenterWindow();

    
//  set icons
    HICON hIcon  =  (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), 
        IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
    SetIcon(hIcon, TRUE);
    HICON hIconSmall 
=  (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), 
        IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
    SetIcon(hIconSmall, FALSE);

    
//  Initialize Windows Media Player
    HRESULT hr;
    ActiveXSite
*  pSite;
    pSite 
=  CAxWindowlessHost < CMainDlg > ::GetControlSite(IDC_WMP11); // 获取Meida Player子控件
     if  ( pSite  !=  NULL )
    {
        pSite
-> SetAllowResize( false ); // 不允许自动调整大小
        CComQIPtr < IWMPCore >  wmp  =  pSite -> ActiveXControl();
        CComQIPtr
< IWMPPlayer4 >  wmp4  =  pSite -> ActiveXControl();
        
//  this can be done manually as well
         if  ( wmp4 ) 
        {
            hr 
=  wmp4 -> put_windowlessVideo( VARIANT_TRUE ); // 无窗口模式
            
// hr = wmp4->put_uiMode( CComBSTR("Full") ); // 填充模式
        }
        
// hr = wmp->put_URL( CComBSTR("c:\\temp\\videofile.wmv") ); // 多媒体文件地址
    }

    
return  TRUE;
}

LRESULT CMainDlg::OnBnClickedBtnBrowse(WORD 
/* wNotifyCode */ , WORD  /* wID */ , HWND  /* hWndCtl */ , BOOL &   /* bHandled */ )
{
// 选择多媒体文件
     static  LPCTSTR pszFilter  =  _T( " Video Files (*.avi;*.mpg;*.wmv)\0*.avi;*.mpg;*.wmv\0\0 " );
    CFileDialog fileOpen(TRUE, _T(
" avi " ), NULL,
        OFN_HIDEREADONLY 
|  OFN_OVERWRITEPROMPT, pszFilter /* , m_hWnd */ );
    
if  ( IDOK  ==  fileOpen.DoModal() )
    {
        ActiveXSite
*  pSite;
        pSite 
=  CAxWindowlessHost < CMainDlg > ::GetControlSite(IDC_WMP11);
        SetDlgItemText(IDC_TXT_FILENAME,  fileOpen.m_szFileName);
        CComQIPtr
< IWMPPlayer4 >  wmp4  =  pSite -> ActiveXControl();
        wmp4
-> close();
        wmp4
-> put_URL( CComBSTR( fileOpen.m_szFileName ) );
    }

    
return   0 ;
}

 使用Sliverlight作为子控件

 

主要代码如下:

LRESULT CMainDlg::OnInitDialog(UINT  /* uMsg */ , WPARAM  /* wParam */ , LPARAM  /* lParam */ , BOOL &   /* bHandled */ )
{
    
//  center the dialog on the screen
    CenterWindow();

    
//  set icons
    HICON hIcon  =  (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), 
        IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
    SetIcon(hIcon, TRUE);
    HICON hIconSmall 
=  (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), 
        IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
    SetIcon(hIconSmall, FALSE);

    
//  Initialize Silverlight Control (this is not windowless but cool anyway)
    HRESULT hr;
    ActiveXSite
*  pSite;
    pSite 
=  CAxWindowlessHost < CMainDlg > ::GetControlSite(IDC_AGCONTROL1); // 获取SliverLight子控件
     if  ( pSite  !=  NULL )
    {
        
//  disable right-click!
        pSite -> SetAllowRClick( false ); // 禁止掉右键
        
//  load from URL
        
// CComBSTR bstrUrl("file: // /c:\\temp\\SortTheFootbars.xap");
        CComBSTR bstrUrl( " http://www.andybeaulieu.com/silverlight/2.0/sortthefoobars/ClientBin/SortTheFoobars.xap " );
        pSite
-> SetUrl(bstrUrl); // 设置多媒体源文件
        CComQIPtr < IXcpControl2 >  slight  =  pSite -> ActiveXControl();
        hr 
=  slight -> put_Source(bstrUrl);
    }
    
return  TRUE;
}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值