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

本文涉及的产品
容器镜像服务 ACR,镜像仓库100个 不限时长
简介:
原文链接: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;
}
复制代码

原文链接: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;
}
复制代码
目录
相关文章
|
3月前
|
Kubernetes Docker Python
Docker 与 Kubernetes 容器化部署核心技术及企业级应用实践全方案解析
本文详解Docker与Kubernetes容器化技术,涵盖概念原理、环境搭建、镜像构建、应用部署及监控扩展,助你掌握企业级容器化方案,提升应用开发与运维效率。
761 109
|
3月前
|
运维 监控 数据可视化
小白也能部署应用,3个免费的容器化部署工具测评
本文对比了三款容器化部署工具:Docker Compose、Portainer 和 Websoft9。Docker Compose 适合开发者编排多容器应用,Portainer 提供图形化管理界面,而 Websoft9 则面向中小企业和非技术人员,提供一键部署与全流程运维支持,真正实现“开箱即用”。三款工具各有定位,Websoft9 更贴近大众用户需求。
小白也能部署应用,3个免费的容器化部署工具测评
|
1月前
|
监控 Kubernetes 安全
还没搞懂Docker? Docker容器技术实战指南 ! 从入门到企业级应用 !
蒋星熠Jaxonic,技术探索者,以代码为笔,在二进制星河中书写极客诗篇。专注Docker与容器化实践,分享从入门到企业级应用的深度经验,助力开发者乘风破浪,驶向云原生新世界。
还没搞懂Docker? Docker容器技术实战指南 ! 从入门到企业级应用 !
|
4月前
|
存储 监控 Java
如何对迁移到Docker容器中的应用进行性能优化?
如何对迁移到Docker容器中的应用进行性能优化?
338 59
|
4月前
|
缓存 Java Docker
如何对应用代码进行优化以提高在Docker容器中的性能?
如何对应用代码进行优化以提高在Docker容器中的性能?
283 1
|
5月前
|
设计模式 开发者 UED
123. [HarmonyOS NEXT 实战案例一:SideBarContainer] 侧边栏容器实战:新闻阅读应用侧边栏布局 基础篇
在现代移动应用和平板应用中,侧边栏导航已经成为一种常见且实用的UI设计模式。HarmonyOS NEXT提供了专门的`SideBarContainer`组件来实现这一功能,它能够轻松创建可显示和隐藏的侧边栏布局,非常适合新闻阅读、电子商务、文件管理等应用场景。
137 3
123. [HarmonyOS NEXT 实战案例一:SideBarContainer] 侧边栏容器实战:新闻阅读应用侧边栏布局 基础篇
|
5月前
|
数据可视化 API UED
126. [HarmonyOS NEXT 实战案例二:SideBarContainer] 侧边栏容器实战:电商应用商品筛选侧边栏 进阶篇
在基础篇中,我们已经实现了电商应用商品筛选侧边栏的基本布局和功能。在本篇教程中,我们将深入探讨如何通过状态管理和数据绑定,实现更加复杂的交互功能,提升用户体验。
100 2
126. [HarmonyOS NEXT 实战案例二:SideBarContainer] 侧边栏容器实战:电商应用商品筛选侧边栏 进阶篇
|
5月前
|
UED 容器
125.[HarmonyOS NEXT 实战案例二:SideBarContainer] 侧边栏容器实战:电商应用商品筛选侧边栏 基础篇
在现代电商应用中,商品筛选功能是提升用户购物体验的关键元素。HarmonyOS NEXT提供的`SideBarContainer`组件非常适合实现这类功能,它可以创建一个可显示和隐藏的侧边栏,用于放置各种筛选条件,帮助用户快速找到心仪的商品。
144 1
125.[HarmonyOS NEXT 实战案例二:SideBarContainer] 侧边栏容器实战:电商应用商品筛选侧边栏 基础篇
|
5月前
|
UED 容器
124.[HarmonyOS NEXT 实战案例一:SideBarContainer] 侧边栏容器实战:新闻阅读应用侧边栏布局 进阶篇
在基础篇中,我们学习了如何使用HarmonyOS NEXT的`SideBarContainer`组件创建新闻阅读应用的基本侧边栏布局。本篇教程将深入探讨如何为新闻阅读应用添加更多交互功能和状态管理,提升用户体验。
121 1
124.[HarmonyOS NEXT 实战案例一:SideBarContainer] 侧边栏容器实战:新闻阅读应用侧边栏布局 进阶篇
|
8月前
|
存储 监控 对象存储
ACK 容器监控存储全面更新:让您的应用运行更稳定、更透明
ACK 容器监控存储全面更新:让您的应用运行更稳定、更透明
245 0
ACK 容器监控存储全面更新:让您的应用运行更稳定、更透明