【译】用于多媒体应用的无窗口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;
}
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;
}
{
// 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;
}
{
// 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;
}
作者:洞庭散人
出处:http://phinecos.cnblogs.com/
本博客遵从Creative Commons Attribution 3.0 License,若用于非商业目的,您可以自由转载,但请保留原作者信息和文章链接URL。
posted on 2009-03-04 14:20 Phinecos(洞庭散人) 阅读(3719) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述